< prev index next >

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

Print this page




 674      * also install the appropriate border depending on the state of the flag.
 675      *
 676      * @param rollover if true, rollover borders are installed.
 677      *        Otherwise non-rollover borders are installed
 678      * @see #isRolloverBorders
 679      * @since 1.4
 680      */
 681     public void setRolloverBorders( boolean rollover ) {
 682         rolloverBorders = rollover;
 683 
 684         if ( rolloverBorders )  {
 685             installRolloverBorders( toolBar );
 686         } else  {
 687             installNonRolloverBorders( toolBar );
 688         }
 689     }
 690 
 691     /**
 692      * Installs rollover borders on all the child components of the JComponent.
 693      * <p>
 694      * This is a convenience method to call <code>setBorderToRollover</code>
 695      * for each child component.
 696      *
 697      * @param c container which holds the child components (usually a JToolBar)
 698      * @see #setBorderToRollover
 699      * @since 1.4
 700      */
 701     protected void installRolloverBorders ( JComponent c )  {
 702         // Put rollover borders on buttons
 703         Component[] components = c.getComponents();
 704 
 705         for (Component component : components) {
 706             if (component instanceof JComponent) {
 707                 ((JComponent) component).updateUI();
 708                 setBorderToRollover(component);
 709             }
 710         }
 711     }
 712 
 713     /**
 714      * Installs non-rollover borders on all the child components of the JComponent.
 715      * A non-rollover border is the border that is installed on the child component
 716      * while it is in the toolbar.
 717      * <p>
 718      * This is a convenience method to call <code>setBorderToNonRollover</code>
 719      * for each child component.
 720      *
 721      * @param c container which holds the child components (usually a JToolBar)
 722      * @see #setBorderToNonRollover
 723      * @since 1.4
 724      */
 725     protected void installNonRolloverBorders ( JComponent c )  {
 726         // Put non-rollover borders on buttons. These borders reduce the margin.
 727         Component[] components = c.getComponents();
 728 
 729         for (Component component : components) {
 730             if (component instanceof JComponent) {
 731                 ((JComponent) component).updateUI();
 732                 setBorderToNonRollover(component);
 733             }
 734         }
 735     }
 736 
 737     /**
 738      * Installs normal borders on all the child components of the JComponent.
 739      * A normal border is the original border that was installed on the child
 740      * component before it was added to the toolbar.
 741      * <p>
 742      * This is a convenience method to call <code>setBorderNormal</code>
 743      * for each child component.
 744      *
 745      * @param c container which holds the child components (usually a JToolBar)
 746      * @see #setBorderToNonRollover
 747      * @since 1.4
 748      */
 749     protected void installNormalBorders ( JComponent c )  {
 750         // Put back the normal borders on buttons
 751         Component[] components = c.getComponents();
 752 
 753         for (Component component : components) {
 754             setBorderToNormal(component);
 755         }
 756     }
 757 
 758     /**
 759      * Sets the border of the component to have a rollover border which
 760      * was created by the {@link #createRolloverBorder} method.
 761      *
 762      * @param c component which will have a rollover border installed


1218      * @return an instance of {@code MouseInputListener}
1219      */
1220     protected MouseInputListener createDockingListener( ) {
1221         getHandler().tb = toolBar;
1222         return getHandler();
1223     }
1224 
1225     /**
1226      * Constructs a new instance of {@code WindowListener}.
1227      *
1228      * @return a new instance of {@code WindowListener}
1229      */
1230     protected WindowListener createFrameListener() {
1231         return new FrameListener();
1232     }
1233 
1234     /**
1235      * Paints the contents of the window used for dragging.
1236      *
1237      * @param g Graphics to paint to.
1238      * @throws NullPointerException is <code>g</code> is null
1239      * @since 1.5
1240      */
1241     protected void paintDragWindow(Graphics g) {
1242         g.setColor(dragWindow.getBackground());
1243         int w = dragWindow.getWidth();
1244         int h = dragWindow.getHeight();
1245         g.fillRect(0, 0, w, h);
1246         g.setColor(dragWindow.getBorderColor());
1247         g.drawRect(0, 0, w - 1, h - 1);
1248     }
1249 
1250 
1251     private static class Actions extends UIAction {
1252         private static final String NAVIGATE_RIGHT = "navigateRight";
1253         private static final String NAVIGATE_LEFT = "navigateLeft";
1254         private static final String NAVIGATE_UP = "navigateUp";
1255         private static final String NAVIGATE_DOWN = "navigateDown";
1256 
1257         public Actions(String name) {
1258             super(name);


1561         getHandler().mouseMoved(e);
1562         }
1563     }
1564 
1565     /**
1566      * The window which appears during dragging the {@code JToolBar}.
1567      */
1568     @SuppressWarnings("serial") // Same-version serialization only
1569     protected class DragWindow extends Window
1570     {
1571         Color borderColor = Color.gray;
1572         int orientation = toolBar.getOrientation();
1573         Point offset; // offset of the mouse cursor inside the DragWindow
1574 
1575         DragWindow(Window w) {
1576             super(w);
1577         }
1578 
1579     /**
1580      * Returns the orientation of the toolbar window when the toolbar is
1581      * floating. The orientation is either one of <code>JToolBar.HORIZONTAL</code>
1582      * or <code>JToolBar.VERTICAL</code>.
1583      *
1584      * @return the orientation of the toolbar window
1585      * @since 1.6
1586      */
1587     public int getOrientation() {
1588         return orientation;
1589     }
1590 
1591         /**
1592          * Sets the orientation.
1593          *
1594          * @param o the new orientation
1595          */
1596         public void setOrientation(int o) {
1597             if(isShowing()) {
1598                 if (o == this.orientation)
1599                     return;
1600                 this.orientation = o;
1601                 Dimension size = getSize();
1602                 setSize(new Dimension(size.height, size.width));




 674      * also install the appropriate border depending on the state of the flag.
 675      *
 676      * @param rollover if true, rollover borders are installed.
 677      *        Otherwise non-rollover borders are installed
 678      * @see #isRolloverBorders
 679      * @since 1.4
 680      */
 681     public void setRolloverBorders( boolean rollover ) {
 682         rolloverBorders = rollover;
 683 
 684         if ( rolloverBorders )  {
 685             installRolloverBorders( toolBar );
 686         } else  {
 687             installNonRolloverBorders( toolBar );
 688         }
 689     }
 690 
 691     /**
 692      * Installs rollover borders on all the child components of the JComponent.
 693      * <p>
 694      * This is a convenience method to call {@code setBorderToRollover}
 695      * for each child component.
 696      *
 697      * @param c container which holds the child components (usually a JToolBar)
 698      * @see #setBorderToRollover
 699      * @since 1.4
 700      */
 701     protected void installRolloverBorders ( JComponent c )  {
 702         // Put rollover borders on buttons
 703         Component[] components = c.getComponents();
 704 
 705         for (Component component : components) {
 706             if (component instanceof JComponent) {
 707                 ((JComponent) component).updateUI();
 708                 setBorderToRollover(component);
 709             }
 710         }
 711     }
 712 
 713     /**
 714      * Installs non-rollover borders on all the child components of the JComponent.
 715      * A non-rollover border is the border that is installed on the child component
 716      * while it is in the toolbar.
 717      * <p>
 718      * This is a convenience method to call {@code setBorderToNonRollover}
 719      * for each child component.
 720      *
 721      * @param c container which holds the child components (usually a JToolBar)
 722      * @see #setBorderToNonRollover
 723      * @since 1.4
 724      */
 725     protected void installNonRolloverBorders ( JComponent c )  {
 726         // Put non-rollover borders on buttons. These borders reduce the margin.
 727         Component[] components = c.getComponents();
 728 
 729         for (Component component : components) {
 730             if (component instanceof JComponent) {
 731                 ((JComponent) component).updateUI();
 732                 setBorderToNonRollover(component);
 733             }
 734         }
 735     }
 736 
 737     /**
 738      * Installs normal borders on all the child components of the JComponent.
 739      * A normal border is the original border that was installed on the child
 740      * component before it was added to the toolbar.
 741      * <p>
 742      * This is a convenience method to call {@code setBorderNormal}
 743      * for each child component.
 744      *
 745      * @param c container which holds the child components (usually a JToolBar)
 746      * @see #setBorderToNonRollover
 747      * @since 1.4
 748      */
 749     protected void installNormalBorders ( JComponent c )  {
 750         // Put back the normal borders on buttons
 751         Component[] components = c.getComponents();
 752 
 753         for (Component component : components) {
 754             setBorderToNormal(component);
 755         }
 756     }
 757 
 758     /**
 759      * Sets the border of the component to have a rollover border which
 760      * was created by the {@link #createRolloverBorder} method.
 761      *
 762      * @param c component which will have a rollover border installed


1218      * @return an instance of {@code MouseInputListener}
1219      */
1220     protected MouseInputListener createDockingListener( ) {
1221         getHandler().tb = toolBar;
1222         return getHandler();
1223     }
1224 
1225     /**
1226      * Constructs a new instance of {@code WindowListener}.
1227      *
1228      * @return a new instance of {@code WindowListener}
1229      */
1230     protected WindowListener createFrameListener() {
1231         return new FrameListener();
1232     }
1233 
1234     /**
1235      * Paints the contents of the window used for dragging.
1236      *
1237      * @param g Graphics to paint to.
1238      * @throws NullPointerException is {@code g} is null
1239      * @since 1.5
1240      */
1241     protected void paintDragWindow(Graphics g) {
1242         g.setColor(dragWindow.getBackground());
1243         int w = dragWindow.getWidth();
1244         int h = dragWindow.getHeight();
1245         g.fillRect(0, 0, w, h);
1246         g.setColor(dragWindow.getBorderColor());
1247         g.drawRect(0, 0, w - 1, h - 1);
1248     }
1249 
1250 
1251     private static class Actions extends UIAction {
1252         private static final String NAVIGATE_RIGHT = "navigateRight";
1253         private static final String NAVIGATE_LEFT = "navigateLeft";
1254         private static final String NAVIGATE_UP = "navigateUp";
1255         private static final String NAVIGATE_DOWN = "navigateDown";
1256 
1257         public Actions(String name) {
1258             super(name);


1561         getHandler().mouseMoved(e);
1562         }
1563     }
1564 
1565     /**
1566      * The window which appears during dragging the {@code JToolBar}.
1567      */
1568     @SuppressWarnings("serial") // Same-version serialization only
1569     protected class DragWindow extends Window
1570     {
1571         Color borderColor = Color.gray;
1572         int orientation = toolBar.getOrientation();
1573         Point offset; // offset of the mouse cursor inside the DragWindow
1574 
1575         DragWindow(Window w) {
1576             super(w);
1577         }
1578 
1579     /**
1580      * Returns the orientation of the toolbar window when the toolbar is
1581      * floating. The orientation is either one of {@code JToolBar.HORIZONTAL}
1582      * or {@code JToolBar.VERTICAL}.
1583      *
1584      * @return the orientation of the toolbar window
1585      * @since 1.6
1586      */
1587     public int getOrientation() {
1588         return orientation;
1589     }
1590 
1591         /**
1592          * Sets the orientation.
1593          *
1594          * @param o the new orientation
1595          */
1596         public void setOrientation(int o) {
1597             if(isShowing()) {
1598                 if (o == this.orientation)
1599                     return;
1600                 this.orientation = o;
1601                 Dimension size = getSize();
1602                 setSize(new Dimension(size.height, size.width));


< prev index next >