FileDocCategorySizeDatePackage
BasicSplitPaneDivider.javaAPI DocJava SE 6 API34692Tue Jun 10 00:26:48 BST 2008javax.swing.plaf.basic

BasicSplitPaneDivider

public class BasicSplitPaneDivider extends Container implements PropertyChangeListener
Divider used by BasicSplitPaneUI. Subclassers may wish to override paint to do something more interesting. The border effect is drawn in BasicSplitPaneUI, so if you don't like that border, reset it there. To conditionally drag from certain areas subclass mousePressed and call super when you wish the dragging to begin.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

version
1.55 04/07/06
author
Scott Violet

Fields Summary
protected static final int
ONE_TOUCH_SIZE
Width or height of the divider based on orientation BasicSplitPaneUI adds two to this.
protected static final int
ONE_TOUCH_OFFSET
protected DragController
dragger
Handles mouse dragging message to do the actual dragging.
protected BasicSplitPaneUI
splitPaneUI
UI this instance was created from.
protected int
dividerSize
Size of the divider.
protected Component
hiddenDivider
Divider that is used for noncontinuous layout mode.
protected JSplitPane
splitPane
JSplitPane the receiver is contained in.
protected MouseHandler
mouseHandler
Handles 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
orientation
Orientation of the JSplitPane.
protected JButton
leftButton
Button for quickly toggling the left component.
protected JButton
rightButton
Button for quickly toggling the right component.
private Border
border
Border.
private boolean
mouseOver
Is the mouse over the divider?
private int
oneTouchSize
private int
oneTouchOffset
private boolean
centerOneTouchButtons
If true the one touch buttons are centered on the divider.
Constructors Summary
public BasicSplitPaneDivider(BasicSplitPaneUI ui)
Creates an instance of BasicSplitPaneDivider. Registers this instance for mouse events and mouse dragged events.



                        
       
        oneTouchSize = DefaultLookup.getInt(ui.getSplitPane(), ui,
                "SplitPane.oneTouchButtonSize", ONE_TOUCH_SIZE);
        oneTouchOffset = DefaultLookup.getInt(ui.getSplitPane(), ui,
                "SplitPane.oneTouchButtonOffset", ONE_TOUCH_OFFSET);
        centerOneTouchButtons = DefaultLookup.getBoolean(ui.getSplitPane(),
                 ui, "SplitPane.centerOneTouchButtons", true);
        setLayout(new DividerLayout());
        setBasicSplitPaneUI(ui);
        orientation = splitPane.getOrientation();
        setCursor((orientation == JSplitPane.HORIZONTAL_SPLIT) ?
                  Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR) :
                  Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
        setBackground(UIManager.getColor("SplitPane.background"));
    
Methods Summary
protected javax.swing.JButtoncreateLeftOneTouchButton()
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.JButtoncreateRightOneTouchButton()
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 voiddragDividerTo(int location)
Messages the BasicSplitPaneUI with dragDividerTo that this instance is contained in.

        splitPaneUI.dragDividerTo(location);
    
protected voidfinishDraggingTo(int location)
Messages the BasicSplitPaneUI with finishDraggingTo that this instance is contained in.

        splitPaneUI.finishDraggingTo(location);
    
public javax.swing.plaf.basic.BasicSplitPaneUIgetBasicSplitPaneUI()
Returns the SplitPaneUI the receiver is currently in.

        return splitPaneUI;
    
public javax.swing.border.BordergetBorder()
Returns the border of this component or null if no border is currently set.

return
the border object for this component
see
#setBorder
since
1.3

        return border;
    
public intgetDividerSize()
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.InsetsgetInsets()
If a border has been set on this component, returns the border's insets, else calls super.getInsets.

return
the value of the insets property.
see
#setBorder

	Border    border = getBorder();

        if (border != null) {
            return border.getBorderInsets(this);
        }
    	return super.getInsets();
    
public java.awt.DimensiongetMinimumSize()
Returns dividerSize x dividerSize

        return getPreferredSize();
    
public java.awt.DimensiongetPreferredSize()
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 booleanisMouseOver()
Returns whether or not the mouse is currently over the divider

return
whether or not the mouse is currently over the divider
since
1.5

        return mouseOver;
    
protected voidoneTouchExpandableChanged()
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 voidpaint(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 voidprepareForDragging()
Message to prepare for dragging. This messages the BasicSplitPaneUI with startDragging.

        splitPaneUI.startDragging();
    
public voidpropertyChange(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 voidrevalidate()

        invalidate();
        if (splitPane != null) {
            splitPane.revalidate();
        }
    
public voidsetBasicSplitPaneUI(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 voidsetBorder(javax.swing.border.Border border)
Sets the border of this component.

since
1.3

        Border         oldBorder = this.border;

        this.border = border;
    
public voidsetDividerSize(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 voidsetMouseOver(boolean mouseOver)
Sets whether or not the mouse is currently over the divider.

param
mouseOver whether or not the mouse is currently over the divider
since
1.5

        this.mouseOver = mouseOver;