Fields Summary |
---|
protected static final int | ONE_TOUCH_SIZEWidth or height of the divider based on orientation
BasicSplitPaneUI adds two to this. |
protected static final int | ONE_TOUCH_OFFSET |
protected DragController | draggerHandles mouse dragging message to do the actual dragging. |
protected BasicSplitPaneUI | splitPaneUIUI this instance was created from. |
protected int | dividerSizeSize of the divider. |
protected Component | hiddenDividerDivider that is used for noncontinuous layout mode. |
protected JSplitPane | splitPaneJSplitPane the receiver is contained in. |
protected MouseHandler | mouseHandlerHandles mouse events from both this class, and the split pane.
Mouse events are handled for the splitpane since you want to be able
to drag when clicking on the border of the divider, which is not
drawn by the divider. |
protected int | orientationOrientation of the JSplitPane. |
protected JButton | leftButtonButton for quickly toggling the left component. |
protected JButton | rightButtonButton for quickly toggling the right component. |
private Border | borderBorder. |
private boolean | mouseOverIs the mouse over the divider? |
private int | oneTouchSize |
private int | oneTouchOffset |
private boolean | centerOneTouchButtonsIf true the one touch buttons are centered on the divider. |
Methods Summary |
---|
protected javax.swing.JButton | createLeftOneTouchButton()Creates and return an instance of JButton that can be used to
collapse the left component in the split pane.
JButton b = new JButton() {
public void setBorder(Border b) {
}
public void paint(Graphics g) {
if (splitPane != null) {
int[] xs = new int[3];
int[] ys = new int[3];
int blockSize;
// Fill the background first ...
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(),
this.getHeight());
// ... then draw the arrow.
g.setColor(Color.black);
if (orientation == JSplitPane.VERTICAL_SPLIT) {
blockSize = Math.min(getHeight(), oneTouchSize);
xs[0] = blockSize;
xs[1] = 0;
xs[2] = blockSize << 1;
ys[0] = 0;
ys[1] = ys[2] = blockSize;
g.drawPolygon(xs, ys, 3); // Little trick to make the
// arrows of equal size
}
else {
blockSize = Math.min(getWidth(), oneTouchSize);
xs[0] = xs[2] = blockSize;
xs[1] = 0;
ys[0] = 0;
ys[1] = blockSize;
ys[2] = blockSize << 1;
}
g.fillPolygon(xs, ys, 3);
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable() {
return false;
}
};
b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
|
protected javax.swing.JButton | createRightOneTouchButton()Creates and return an instance of JButton that can be used to
collapse the right component in the split pane.
JButton b = new JButton() {
public void setBorder(Border border) {
}
public void paint(Graphics g) {
if (splitPane != null) {
int[] xs = new int[3];
int[] ys = new int[3];
int blockSize;
// Fill the background first ...
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(),
this.getHeight());
// ... then draw the arrow.
if (orientation == JSplitPane.VERTICAL_SPLIT) {
blockSize = Math.min(getHeight(), oneTouchSize);
xs[0] = blockSize;
xs[1] = blockSize << 1;
xs[2] = 0;
ys[0] = blockSize;
ys[1] = ys[2] = 0;
}
else {
blockSize = Math.min(getWidth(), oneTouchSize);
xs[0] = xs[2] = 0;
xs[1] = blockSize;
ys[0] = 0;
ys[1] = blockSize;
ys[2] = blockSize << 1;
}
g.setColor(Color.black);
g.fillPolygon(xs, ys, 3);
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable() {
return false;
}
};
b.setMinimumSize(new Dimension(oneTouchSize, oneTouchSize));
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
|
protected void | dragDividerTo(int location)Messages the BasicSplitPaneUI with dragDividerTo that this instance
is contained in.
splitPaneUI.dragDividerTo(location);
|
protected void | finishDraggingTo(int location)Messages the BasicSplitPaneUI with finishDraggingTo that this instance
is contained in.
splitPaneUI.finishDraggingTo(location);
|
public javax.swing.plaf.basic.BasicSplitPaneUI | getBasicSplitPaneUI()Returns the SplitPaneUI the receiver is currently
in.
return splitPaneUI;
|
public javax.swing.border.Border | getBorder()Returns the border of this component or null if no border is
currently set.
return border;
|
public int | getDividerSize()Returns the size of the divider, that is the width if the splitpane
is HORIZONTAL_SPLIT, or the height of VERTICAL_SPLIT.
return dividerSize;
|
public java.awt.Insets | getInsets()If a border has been set on this component, returns the
border's insets, else calls super.getInsets.
Border border = getBorder();
if (border != null) {
return border.getBorderInsets(this);
}
return super.getInsets();
|
public java.awt.Dimension | getMinimumSize()Returns dividerSize x dividerSize
return getPreferredSize();
|
public java.awt.Dimension | getPreferredSize()Returns dividerSize x dividerSize
// Ideally this would return the size from the layout manager,
// but that could result in the layed out size being different from
// the dividerSize, which may break developers as well as
// BasicSplitPaneUI.
if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
return new Dimension(getDividerSize(), 1);
}
return new Dimension(1, getDividerSize());
|
public boolean | isMouseOver()Returns whether or not the mouse is currently over the divider
return mouseOver;
|
protected void | oneTouchExpandableChanged()Messaged when the oneTouchExpandable value of the JSplitPane the
receiver is contained in changes. Will create the
leftButton and rightButton if they
are null. invalidates the receiver as well.
if (!DefaultLookup.getBoolean(splitPane, splitPaneUI,
"SplitPane.supportsOneTouchButtons", true)) {
// Look and feel doesn't want to support one touch buttons, bail.
return;
}
if (splitPane.isOneTouchExpandable() &&
leftButton == null &&
rightButton == null) {
/* Create the left button and add an action listener to
expand/collapse it. */
leftButton = createLeftOneTouchButton();
if (leftButton != null)
leftButton.addActionListener(new OneTouchActionHandler(true));
/* Create the right button and add an action listener to
expand/collapse it. */
rightButton = createRightOneTouchButton();
if (rightButton != null)
rightButton.addActionListener(new OneTouchActionHandler
(false));
if (leftButton != null && rightButton != null) {
add(leftButton);
add(rightButton);
}
}
revalidate();
|
public void | paint(java.awt.Graphics g)Paints the divider.
super.paint(g);
// Paint the border.
Border border = getBorder();
if (border != null) {
Dimension size = getSize();
border.paintBorder(this, g, 0, 0, size.width, size.height);
}
|
protected void | prepareForDragging()Message to prepare for dragging. This messages the BasicSplitPaneUI
with startDragging.
splitPaneUI.startDragging();
|
public void | propertyChange(java.beans.PropertyChangeEvent e)Property change event, presumably from the JSplitPane, will message
updateOrientation if necessary.
if (e.getSource() == splitPane) {
if (e.getPropertyName() == JSplitPane.ORIENTATION_PROPERTY) {
orientation = splitPane.getOrientation();
setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ?
Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) :
Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
revalidate();
}
else if (e.getPropertyName() == JSplitPane.
ONE_TOUCH_EXPANDABLE_PROPERTY) {
oneTouchExpandableChanged();
}
}
|
private void | revalidate()
invalidate();
if (splitPane != null) {
splitPane.revalidate();
}
|
public void | setBasicSplitPaneUI(javax.swing.plaf.basic.BasicSplitPaneUI newUI)Sets the SplitPaneUI that is using the receiver.
if (splitPane != null) {
splitPane.removePropertyChangeListener(this);
if (mouseHandler != null) {
splitPane.removeMouseListener(mouseHandler);
splitPane.removeMouseMotionListener(mouseHandler);
removeMouseListener(mouseHandler);
removeMouseMotionListener(mouseHandler);
mouseHandler = null;
}
}
splitPaneUI = newUI;
if (newUI != null) {
splitPane = newUI.getSplitPane();
if (splitPane != null) {
if (mouseHandler == null) mouseHandler = new MouseHandler();
splitPane.addMouseListener(mouseHandler);
splitPane.addMouseMotionListener(mouseHandler);
addMouseListener(mouseHandler);
addMouseMotionListener(mouseHandler);
splitPane.addPropertyChangeListener(this);
if (splitPane.isOneTouchExpandable()) {
oneTouchExpandableChanged();
}
}
}
else {
splitPane = null;
}
|
public void | setBorder(javax.swing.border.Border border)Sets the border of this component.
Border oldBorder = this.border;
this.border = border;
|
public void | setDividerSize(int newSize)Sets the size of the divider to newSize . That is
the width if the splitpane is HORIZONTAL_SPLIT , or
the height of VERTICAL_SPLIT .
dividerSize = newSize;
|
protected void | setMouseOver(boolean mouseOver)Sets whether or not the mouse is currently over the divider.
this.mouseOver = mouseOver;
|