< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneDivider.java

Print this page




  37 import javax.swing.border.Border;
  38 import java.beans.*;
  39 import sun.swing.DefaultLookup;
  40 
  41 
  42 
  43 /**
  44  * Divider used by BasicSplitPaneUI. Subclassers may wish to override
  45  * paint to do something more interesting.
  46  * The border effect is drawn in BasicSplitPaneUI, so if you don't like
  47  * that border, reset it there.
  48  * To conditionally drag from certain areas subclass mousePressed and
  49  * call super when you wish the dragging to begin.
  50  * <p>
  51  * <strong>Warning:</strong>
  52  * Serialized objects of this class will not be compatible with
  53  * future Swing releases. The current serialization support is
  54  * appropriate for short term storage or RMI between applications running
  55  * the same version of Swing.  As of 1.4, support for long term storage
  56  * of all JavaBeans&trade;
  57  * has been added to the <code>java.beans</code> package.
  58  * Please see {@link java.beans.XMLEncoder}.
  59  *
  60  * @author Scott Violet
  61  */
  62 @SuppressWarnings("serial") // Same-version serialization only
  63 public class BasicSplitPaneDivider extends Container
  64     implements PropertyChangeListener
  65 {
  66     /**
  67      * Width or height of the divider based on orientation
  68      * {@code BasicSplitPaneUI} adds two to this.
  69      */
  70     protected static final int ONE_TOUCH_SIZE = 6;
  71 
  72     /**
  73      * The offset of the divider.
  74      */
  75     protected static final int ONE_TOUCH_OFFSET = 2;
  76 
  77     /**


 344     /**
 345      * Paints the divider.
 346      */
 347     public void paint(Graphics g) {
 348       super.paint(g);
 349 
 350       // Paint the border.
 351       Border   border = getBorder();
 352 
 353       if (border != null) {
 354           Dimension     size = getSize();
 355 
 356           border.paintBorder(this, g, 0, 0, size.width, size.height);
 357       }
 358     }
 359 
 360 
 361     /**
 362      * Messaged when the oneTouchExpandable value of the JSplitPane the
 363      * receiver is contained in changes. Will create the
 364      * <code>leftButton</code> and <code>rightButton</code> if they
 365      * are null. invalidates the receiver as well.
 366      */
 367     protected void oneTouchExpandableChanged() {
 368         if (!DefaultLookup.getBoolean(splitPane, splitPaneUI,
 369                            "SplitPane.supportsOneTouchButtons", true)) {
 370             // Look and feel doesn't want to support one touch buttons, bail.
 371             return;
 372         }
 373         if (splitPane.isOneTouchExpandable() &&
 374             leftButton == null &&
 375             rightButton == null) {
 376             /* Create the left button and add an action listener to
 377                expand/collapse it. */
 378             leftButton = createLeftOneTouchButton();
 379             if (leftButton != null)
 380                 leftButton.addActionListener(new OneTouchActionHandler(true));
 381 
 382 
 383             /* Create the right button and add an action listener to
 384                expand/collapse it. */


 670             }
 671         }
 672 
 673         /**
 674          * Invoked when the mouse exits a component.
 675          *
 676          * @param e MouseEvent describing the details of the exit event.
 677          * @since 1.5
 678          */
 679         public void mouseExited(MouseEvent e) {
 680             if (e.getSource() == BasicSplitPaneDivider.this) {
 681                 setMouseOver(false);
 682             }
 683         }
 684     }
 685 
 686 
 687     /**
 688      * Handles the events during a dragging session for a
 689      * HORIZONTAL_SPLIT oriented split pane. This continually
 690      * messages <code>dragDividerTo</code> and then when done messages
 691      * <code>finishDraggingTo</code>. When an instance is created it should be
 692      * messaged with <code>isValid</code> to insure that dragging can happen
 693      * (dragging won't be allowed if the two views can not be resized).
 694      * <p>
 695      * <strong>Warning:</strong>
 696      * Serialized objects of this class will not be compatible with
 697      * future Swing releases. The current serialization support is
 698      * appropriate for short term storage or RMI between applications running
 699      * the same version of Swing.  As of 1.4, support for long term storage
 700      * of all JavaBeans&trade;
 701      * has been added to the <code>java.beans</code> package.
 702      * Please see {@link java.beans.XMLEncoder}.
 703      */
 704     @SuppressWarnings("serial") // Same-version serialization only
 705     protected class DragController
 706     {
 707         /**
 708          * Initial location of the divider.
 709          */
 710         int initialX;
 711 
 712         /**
 713          * Maximum and minimum positions to drag to.
 714          */
 715         int maxX, minX;
 716 
 717         /**
 718          * Initial location the mouse down happened at.
 719          */
 720         int offset;
 721 


 842         protected void completeDrag(int x, int y) {
 843             finishDraggingTo(getNeededLocation(x, y));
 844         }
 845 
 846 
 847         /**
 848          * Messages finishDraggingTo with the new location for the mouse
 849          * event.
 850          *
 851          * @param e a mouse event
 852          */
 853         protected void completeDrag(MouseEvent e) {
 854             finishDraggingTo(positionForMouseEvent(e));
 855         }
 856     } // End of BasicSplitPaneDivider.DragController
 857 
 858 
 859     /**
 860      * Handles the events during a dragging session for a
 861      * VERTICAL_SPLIT oriented split pane. This continually
 862      * messages <code>dragDividerTo</code> and then when done messages
 863      * <code>finishDraggingTo</code>. When an instance is created it should be
 864      * messaged with <code>isValid</code> to insure that dragging can happen
 865      * (dragging won't be allowed if the two views can not be resized).
 866      */
 867     protected class VerticalDragController extends DragController
 868     {
 869         /* DragControllers ivars are now in terms of y, not x. */
 870         /**
 871          * Constructs a new instance of {@code VerticalDragController}.
 872          *
 873          * @param e a mouse event
 874          */
 875         protected VerticalDragController(MouseEvent e) {
 876             super(e);
 877             JSplitPane splitPane = splitPaneUI.getSplitPane();
 878             Component  leftC = splitPane.getLeftComponent();
 879             Component  rightC = splitPane.getRightComponent();
 880 
 881             initialX = getLocation().y;
 882             if (e.getSource() == BasicSplitPaneDivider.this) {
 883                 offset = e.getY();
 884             }


 931             return newY;
 932         }
 933 
 934 
 935         /**
 936          * Returns the new position to put the divider at based on
 937          * the passed in MouseEvent.
 938          */
 939         protected int positionForMouseEvent(MouseEvent e) {
 940             int newY = (e.getSource() == BasicSplitPaneDivider.this) ?
 941                         (e.getY() + getLocation().y) : e.getY();
 942 
 943 
 944             newY = Math.min(maxX, Math.max(minX, newY - offset));
 945             return newY;
 946         }
 947     } // End of BasicSplitPaneDividier.VerticalDragController
 948 
 949 
 950     /**
 951      * Used to layout a <code>BasicSplitPaneDivider</code>.
 952      * Layout for the divider
 953      * involves appropriately moving the left/right buttons around.
 954      *
 955      */
 956     protected class DividerLayout implements LayoutManager
 957     {
 958         public void layoutContainer(Container c) {
 959             if (leftButton != null && rightButton != null &&
 960                 c == BasicSplitPaneDivider.this) {
 961                 if (splitPane.isOneTouchExpandable()) {
 962                     Insets insets = getInsets();
 963 
 964                     if (orientation == JSplitPane.VERTICAL_SPLIT) {
 965                         int extraX = (insets != null) ? insets.left : 0;
 966                         int blockSize = getHeight();
 967 
 968                         if (insets != null) {
 969                             blockSize -= (insets.top + insets.bottom);
 970                             blockSize = Math.max(blockSize, 0);
 971                         }




  37 import javax.swing.border.Border;
  38 import java.beans.*;
  39 import sun.swing.DefaultLookup;
  40 
  41 
  42 
  43 /**
  44  * Divider used by BasicSplitPaneUI. Subclassers may wish to override
  45  * paint to do something more interesting.
  46  * The border effect is drawn in BasicSplitPaneUI, so if you don't like
  47  * that border, reset it there.
  48  * To conditionally drag from certain areas subclass mousePressed and
  49  * call super when you wish the dragging to begin.
  50  * <p>
  51  * <strong>Warning:</strong>
  52  * Serialized objects of this class will not be compatible with
  53  * future Swing releases. The current serialization support is
  54  * appropriate for short term storage or RMI between applications running
  55  * the same version of Swing.  As of 1.4, support for long term storage
  56  * of all JavaBeans&trade;
  57  * has been added to the {@code java.beans} package.
  58  * Please see {@link java.beans.XMLEncoder}.
  59  *
  60  * @author Scott Violet
  61  */
  62 @SuppressWarnings("serial") // Same-version serialization only
  63 public class BasicSplitPaneDivider extends Container
  64     implements PropertyChangeListener
  65 {
  66     /**
  67      * Width or height of the divider based on orientation
  68      * {@code BasicSplitPaneUI} adds two to this.
  69      */
  70     protected static final int ONE_TOUCH_SIZE = 6;
  71 
  72     /**
  73      * The offset of the divider.
  74      */
  75     protected static final int ONE_TOUCH_OFFSET = 2;
  76 
  77     /**


 344     /**
 345      * Paints the divider.
 346      */
 347     public void paint(Graphics g) {
 348       super.paint(g);
 349 
 350       // Paint the border.
 351       Border   border = getBorder();
 352 
 353       if (border != null) {
 354           Dimension     size = getSize();
 355 
 356           border.paintBorder(this, g, 0, 0, size.width, size.height);
 357       }
 358     }
 359 
 360 
 361     /**
 362      * Messaged when the oneTouchExpandable value of the JSplitPane the
 363      * receiver is contained in changes. Will create the
 364      * {@code leftButton} and {@code rightButton} if they
 365      * are null. invalidates the receiver as well.
 366      */
 367     protected void oneTouchExpandableChanged() {
 368         if (!DefaultLookup.getBoolean(splitPane, splitPaneUI,
 369                            "SplitPane.supportsOneTouchButtons", true)) {
 370             // Look and feel doesn't want to support one touch buttons, bail.
 371             return;
 372         }
 373         if (splitPane.isOneTouchExpandable() &&
 374             leftButton == null &&
 375             rightButton == null) {
 376             /* Create the left button and add an action listener to
 377                expand/collapse it. */
 378             leftButton = createLeftOneTouchButton();
 379             if (leftButton != null)
 380                 leftButton.addActionListener(new OneTouchActionHandler(true));
 381 
 382 
 383             /* Create the right button and add an action listener to
 384                expand/collapse it. */


 670             }
 671         }
 672 
 673         /**
 674          * Invoked when the mouse exits a component.
 675          *
 676          * @param e MouseEvent describing the details of the exit event.
 677          * @since 1.5
 678          */
 679         public void mouseExited(MouseEvent e) {
 680             if (e.getSource() == BasicSplitPaneDivider.this) {
 681                 setMouseOver(false);
 682             }
 683         }
 684     }
 685 
 686 
 687     /**
 688      * Handles the events during a dragging session for a
 689      * HORIZONTAL_SPLIT oriented split pane. This continually
 690      * messages {@code dragDividerTo} and then when done messages
 691      * {@code finishDraggingTo}. When an instance is created it should be
 692      * messaged with {@code isValid} to insure that dragging can happen
 693      * (dragging won't be allowed if the two views can not be resized).
 694      * <p>
 695      * <strong>Warning:</strong>
 696      * Serialized objects of this class will not be compatible with
 697      * future Swing releases. The current serialization support is
 698      * appropriate for short term storage or RMI between applications running
 699      * the same version of Swing.  As of 1.4, support for long term storage
 700      * of all JavaBeans&trade;
 701      * has been added to the {@code java.beans} package.
 702      * Please see {@link java.beans.XMLEncoder}.
 703      */
 704     @SuppressWarnings("serial") // Same-version serialization only
 705     protected class DragController
 706     {
 707         /**
 708          * Initial location of the divider.
 709          */
 710         int initialX;
 711 
 712         /**
 713          * Maximum and minimum positions to drag to.
 714          */
 715         int maxX, minX;
 716 
 717         /**
 718          * Initial location the mouse down happened at.
 719          */
 720         int offset;
 721 


 842         protected void completeDrag(int x, int y) {
 843             finishDraggingTo(getNeededLocation(x, y));
 844         }
 845 
 846 
 847         /**
 848          * Messages finishDraggingTo with the new location for the mouse
 849          * event.
 850          *
 851          * @param e a mouse event
 852          */
 853         protected void completeDrag(MouseEvent e) {
 854             finishDraggingTo(positionForMouseEvent(e));
 855         }
 856     } // End of BasicSplitPaneDivider.DragController
 857 
 858 
 859     /**
 860      * Handles the events during a dragging session for a
 861      * VERTICAL_SPLIT oriented split pane. This continually
 862      * messages {@code dragDividerTo} and then when done messages
 863      * {@code finishDraggingTo}. When an instance is created it should be
 864      * messaged with {@code isValid} to insure that dragging can happen
 865      * (dragging won't be allowed if the two views can not be resized).
 866      */
 867     protected class VerticalDragController extends DragController
 868     {
 869         /* DragControllers ivars are now in terms of y, not x. */
 870         /**
 871          * Constructs a new instance of {@code VerticalDragController}.
 872          *
 873          * @param e a mouse event
 874          */
 875         protected VerticalDragController(MouseEvent e) {
 876             super(e);
 877             JSplitPane splitPane = splitPaneUI.getSplitPane();
 878             Component  leftC = splitPane.getLeftComponent();
 879             Component  rightC = splitPane.getRightComponent();
 880 
 881             initialX = getLocation().y;
 882             if (e.getSource() == BasicSplitPaneDivider.this) {
 883                 offset = e.getY();
 884             }


 931             return newY;
 932         }
 933 
 934 
 935         /**
 936          * Returns the new position to put the divider at based on
 937          * the passed in MouseEvent.
 938          */
 939         protected int positionForMouseEvent(MouseEvent e) {
 940             int newY = (e.getSource() == BasicSplitPaneDivider.this) ?
 941                         (e.getY() + getLocation().y) : e.getY();
 942 
 943 
 944             newY = Math.min(maxX, Math.max(minX, newY - offset));
 945             return newY;
 946         }
 947     } // End of BasicSplitPaneDividier.VerticalDragController
 948 
 949 
 950     /**
 951      * Used to layout a {@code BasicSplitPaneDivider}.
 952      * Layout for the divider
 953      * involves appropriately moving the left/right buttons around.
 954      *
 955      */
 956     protected class DividerLayout implements LayoutManager
 957     {
 958         public void layoutContainer(Container c) {
 959             if (leftButton != null && rightButton != null &&
 960                 c == BasicSplitPaneDivider.this) {
 961                 if (splitPane.isOneTouchExpandable()) {
 962                     Insets insets = getInsets();
 963 
 964                     if (orientation == JSplitPane.VERTICAL_SPLIT) {
 965                         int extraX = (insets != null) ? insets.left : 0;
 966                         int blockSize = getHeight();
 967 
 968                         if (insets != null) {
 969                             blockSize -= (insets.top + insets.bottom);
 970                             blockSize = Math.max(blockSize, 0);
 971                         }


< prev index next >