jdk/src/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java
changeset 1290 da8902cd496c
parent 438 2ae294e4518c
child 1299 027d966d5658
equal deleted inserted replaced
1289:43d45f4159b6 1290:da8902cd496c
    81     private static Border rolloverBorder;
    81     private static Border rolloverBorder;
    82     private static Border nonRolloverBorder;
    82     private static Border nonRolloverBorder;
    83     private static Border nonRolloverToggleBorder;
    83     private static Border nonRolloverToggleBorder;
    84     private boolean rolloverBorders = false;
    84     private boolean rolloverBorders = false;
    85 
    85 
    86     private HashMap borderTable = new HashMap();
    86     private HashMap<AbstractButton, Border> borderTable = new HashMap<AbstractButton, Border>();
    87     private Hashtable rolloverTable = new Hashtable();
    87     private Hashtable<AbstractButton, Boolean> rolloverTable = new Hashtable<AbstractButton, Boolean>();
    88 
    88 
    89 
    89 
    90     /**
    90     /**
    91      * As of Java 2 platform v1.3 this previously undocumented field is no
    91      * As of Java 2 platform v1.3 this previously undocumented field is no
    92      * longer used.
    92      * longer used.
   169         uninstallComponents();
   169         uninstallComponents();
   170         uninstallListeners();
   170         uninstallListeners();
   171         uninstallKeyboardActions();
   171         uninstallKeyboardActions();
   172 
   172 
   173         // Clear instance vars
   173         // Clear instance vars
   174         if (isFloating() == true)
   174         if (isFloating())
   175             setFloating(false, null);
   175             setFloating(false, null);
   176 
   176 
   177         floatingToolBar = null;
   177         floatingToolBar = null;
   178         dragWindow = null;
   178         dragWindow = null;
   179         dockingSource = null;
   179         dockingSource = null;
   271         if ( toolBarFocusListener != null )
   271         if ( toolBarFocusListener != null )
   272         {
   272         {
   273             // Put focus listener on all components in toolbar
   273             // Put focus listener on all components in toolbar
   274             Component[] components = toolBar.getComponents();
   274             Component[] components = toolBar.getComponents();
   275 
   275 
   276             for ( int i = 0; i < components.length; ++i )
   276             for (Component component : components) {
   277             {
   277                 component.addFocusListener(toolBarFocusListener);
   278                 components[ i ].addFocusListener( toolBarFocusListener );
       
   279             }
   278             }
   280         }
   279         }
   281     }
   280     }
   282 
   281 
   283     protected void uninstallListeners( )
   282     protected void uninstallListeners( )
   305         if ( toolBarFocusListener != null )
   304         if ( toolBarFocusListener != null )
   306         {
   305         {
   307             // Remove focus listener from all components in toolbar
   306             // Remove focus listener from all components in toolbar
   308             Component[] components = toolBar.getComponents();
   307             Component[] components = toolBar.getComponents();
   309 
   308 
   310             for ( int i = 0; i < components.length; ++i )
   309             for (Component component : components) {
   311             {
   310                 component.removeFocusListener(toolBarFocusListener);
   312                 components[ i ].removeFocusListener( toolBarFocusListener );
       
   313             }
   311             }
   314 
   312 
   315             toolBarFocusListener = null;
   313             toolBarFocusListener = null;
   316         }
   314         }
   317         handler = null;
   315         handler = null;
   614      */
   612      */
   615     protected void installRolloverBorders ( JComponent c )  {
   613     protected void installRolloverBorders ( JComponent c )  {
   616         // Put rollover borders on buttons
   614         // Put rollover borders on buttons
   617         Component[] components = c.getComponents();
   615         Component[] components = c.getComponents();
   618 
   616 
   619         for ( int i = 0; i < components.length; ++i ) {
   617         for (Component component : components) {
   620             if ( components[ i ] instanceof JComponent ) {
   618             if (component instanceof JComponent) {
   621                 ( (JComponent)components[ i ] ).updateUI();
   619                 ((JComponent) component).updateUI();
   622                 setBorderToRollover( components[ i ] );
   620                 setBorderToRollover(component);
   623             }
   621             }
   624         }
   622         }
   625     }
   623     }
   626 
   624 
   627     /**
   625     /**
   638      */
   636      */
   639     protected void installNonRolloverBorders ( JComponent c )  {
   637     protected void installNonRolloverBorders ( JComponent c )  {
   640         // Put non-rollover borders on buttons. These borders reduce the margin.
   638         // Put non-rollover borders on buttons. These borders reduce the margin.
   641         Component[] components = c.getComponents();
   639         Component[] components = c.getComponents();
   642 
   640 
   643         for ( int i = 0; i < components.length; ++i ) {
   641         for (Component component : components) {
   644             if ( components[ i ] instanceof JComponent ) {
   642             if (component instanceof JComponent) {
   645                 ( (JComponent)components[ i ] ).updateUI();
   643                 ((JComponent) component).updateUI();
   646                 setBorderToNonRollover( components[ i ] );
   644                 setBorderToNonRollover(component);
   647             }
   645             }
   648         }
   646         }
   649     }
   647     }
   650 
   648 
   651     /**
   649     /**
   662      */
   660      */
   663     protected void installNormalBorders ( JComponent c )  {
   661     protected void installNormalBorders ( JComponent c )  {
   664         // Put back the normal borders on buttons
   662         // Put back the normal borders on buttons
   665         Component[] components = c.getComponents();
   663         Component[] components = c.getComponents();
   666 
   664 
   667         for ( int i = 0; i < components.length; ++i ) {
   665         for (Component component : components) {
   668             setBorderToNormal( components[ i ] );
   666             setBorderToNormal(component);
   669         }
   667         }
   670     }
   668     }
   671 
   669 
   672     /**
   670     /**
   673      * Sets the border of the component to have a rollover border which
   671      * Sets the border of the component to have a rollover border which
   679      */
   677      */
   680     protected void setBorderToRollover(Component c) {
   678     protected void setBorderToRollover(Component c) {
   681         if (c instanceof AbstractButton) {
   679         if (c instanceof AbstractButton) {
   682             AbstractButton b = (AbstractButton)c;
   680             AbstractButton b = (AbstractButton)c;
   683 
   681 
   684             Border border = (Border)borderTable.get(b);
   682             Border border = borderTable.get(b);
   685             if (border == null || border instanceof UIResource) {
   683             if (border == null || border instanceof UIResource) {
   686                 borderTable.put(b, b.getBorder());
   684                 borderTable.put(b, b.getBorder());
   687             }
   685             }
   688 
   686 
   689             // Only set the border if its the default border
   687             // Only set the border if its the default border
   719      */
   717      */
   720     protected void setBorderToNonRollover(Component c) {
   718     protected void setBorderToNonRollover(Component c) {
   721         if (c instanceof AbstractButton) {
   719         if (c instanceof AbstractButton) {
   722             AbstractButton b = (AbstractButton)c;
   720             AbstractButton b = (AbstractButton)c;
   723 
   721 
   724             Border border = (Border)borderTable.get(b);
   722             Border border = borderTable.get(b);
   725             if (border == null || border instanceof UIResource) {
   723             if (border == null || border instanceof UIResource) {
   726                 borderTable.put(b, b.getBorder());
   724                 borderTable.put(b, b.getBorder());
   727             }
   725             }
   728 
   726 
   729             // Only set the border if its the default border
   727             // Only set the border if its the default border
   763      */
   761      */
   764     protected void setBorderToNormal(Component c) {
   762     protected void setBorderToNormal(Component c) {
   765         if (c instanceof AbstractButton) {
   763         if (c instanceof AbstractButton) {
   766             AbstractButton b = (AbstractButton)c;
   764             AbstractButton b = (AbstractButton)c;
   767 
   765 
   768             Border border = (Border)borderTable.remove(b);
   766             Border border = borderTable.remove(b);
   769             b.setBorder(border);
   767             b.setBorder(border);
   770 
   768 
   771             Boolean value = (Boolean)rolloverTable.remove(b);
   769             Boolean value = rolloverTable.remove(b);
   772             if (value != null) {
   770             if (value != null) {
   773                 b.setRolloverEnabled(value.booleanValue());
   771                 b.setRolloverEnabled(value.booleanValue());
   774             }
   772             }
   775         }
   773         }
   776     }
   774     }
   783     public boolean isFloating() {
   781     public boolean isFloating() {
   784         return floating;
   782         return floating;
   785     }
   783     }
   786 
   784 
   787     public void setFloating(boolean b, Point p) {
   785     public void setFloating(boolean b, Point p) {
   788         if (toolBar.isFloatable() == true) {
   786         if (toolBar.isFloatable()) {
   789             boolean visible = false;
   787             boolean visible = false;
   790             Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
   788             Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
   791             if (ancestor != null) {
   789             if (ancestor != null) {
   792                 visible = ancestor.isVisible();
   790                 visible = ancestor.isVisible();
   793             }
   791             }
   951         return null;
   949         return null;
   952     }
   950     }
   953 
   951 
   954     protected void dragTo(Point position, Point origin)
   952     protected void dragTo(Point position, Point origin)
   955     {
   953     {
   956         if (toolBar.isFloatable() == true)
   954         if (toolBar.isFloatable())
   957         {
   955         {
   958           try
   956           try
   959           {
   957           {
   960             if (dragWindow == null)
   958             if (dragWindow == null)
   961                 dragWindow = createDragWindow(toolBar);
   959                 dragWindow = createDragWindow(toolBar);
  1001         }
   999         }
  1002     }
  1000     }
  1003 
  1001 
  1004     protected void floatAt(Point position, Point origin)
  1002     protected void floatAt(Point position, Point origin)
  1005     {
  1003     {
  1006         if(toolBar.isFloatable() == true)
  1004         if(toolBar.isFloatable())
  1007         {
  1005         {
  1008           try
  1006           try
  1009           {
  1007           {
  1010             Point offset = dragWindow.getOffset();
  1008             Point offset = dragWindow.getOffset();
  1011             if (offset == null) {
  1009             if (offset == null) {
  1172 
  1170 
  1173         public void mouseReleased(MouseEvent evt) {
  1171         public void mouseReleased(MouseEvent evt) {
  1174             if (!tb.isEnabled()) {
  1172             if (!tb.isEnabled()) {
  1175                 return;
  1173                 return;
  1176             }
  1174             }
  1177             if (isDragging == true) {
  1175             if (isDragging) {
  1178                 Point position = evt.getPoint();
  1176                 Point position = evt.getPoint();
  1179                 if (origin == null)
  1177                 if (origin == null)
  1180                     origin = evt.getComponent().getLocationOnScreen();
  1178                     origin = evt.getComponent().getLocationOnScreen();
  1181                 floatAt(position, origin);
  1179                 floatAt(position, origin);
  1182             }
  1180             }
  1240         }
  1238         }
  1241     }
  1239     }
  1242 
  1240 
  1243     protected class FrameListener extends WindowAdapter {
  1241     protected class FrameListener extends WindowAdapter {
  1244         public void windowClosing(WindowEvent w) {
  1242         public void windowClosing(WindowEvent w) {
  1245             if (toolBar.isFloatable() == true) {
  1243             if (toolBar.isFloatable()) {
  1246                 if (dragWindow != null)
  1244                 if (dragWindow != null)
  1247                     dragWindow.setVisible(false);
  1245                     dragWindow.setVisible(false);
  1248                 floating = false;
  1246                 floating = false;
  1249                 if (floatingToolBar == null)
  1247                 if (floatingToolBar == null)
  1250                     floatingToolBar = createFloatingWindow(toolBar);
  1248                     floatingToolBar = createFloatingWindow(toolBar);