< prev index next >

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

Print this page




 404         map.put(new Actions(Actions.NAVIGATE_UP));
 405         map.put(new Actions(Actions.NAVIGATE_DOWN));
 406     }
 407 
 408     /**
 409      * Unregisters keyboard actions.
 410      */
 411     protected void uninstallKeyboardActions( )
 412     {
 413         SwingUtilities.replaceUIActionMap(toolBar, null);
 414         SwingUtilities.replaceUIInputMap(toolBar, JComponent.
 415                                          WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
 416                                          null);
 417     }
 418 
 419     /**
 420      * Navigates the focused component.
 421      *
 422      * @param direction a direction
 423      */

 424     protected void navigateFocusedComp(int direction)
 425     {
 426         int nComp = toolBar.getComponentCount();
 427         int j;
 428 
 429         switch ( direction )
 430         {
 431             case EAST:
 432             case SOUTH:
 433 
 434                 if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
 435 
 436                 j = focusedCompIndex + 1;
 437 
 438                 while ( j != focusedCompIndex )
 439                 {
 440                     if ( j >= nComp ) j = 0;
 441                     Component comp = toolBar.getComponentAtIndex( j++ );
 442 
 443                     if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )


 869     public void setFloatingLocation(int x, int y) {
 870         floatingX = x;
 871         floatingY = y;
 872     }
 873 
 874     /**
 875      * Returns {@code true} if the {@code JToolBar} is floating
 876      *
 877      * @return {@code true} if the {@code JToolBar} is floating
 878      */
 879     public boolean isFloating() {
 880         return floating;
 881     }
 882 
 883     /**
 884      * Sets the floating property.
 885      *
 886      * @param b {@code true} if the {@code JToolBar} is floating
 887      * @param p the position
 888      */

 889     public void setFloating(boolean b, Point p) {
 890         if (toolBar.isFloatable()) {
 891             boolean visible = false;
 892             Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
 893             if (ancestor != null) {
 894                 visible = ancestor.isVisible();
 895             }
 896             if (dragWindow != null)
 897                 dragWindow.setVisible(false);
 898             this.floating = b;
 899             if (floatingToolBar == null) {
 900                 floatingToolBar = createFloatingWindow(toolBar);
 901             }
 902             if (b == true)
 903             {
 904                 if (dockingSource == null)
 905                 {
 906                     dockingSource = toolBar.getParent();
 907                     dockingSource.remove(toolBar);
 908                 }


1063                 return BorderLayout.EAST;
1064             }
1065             // West  (Base distance on height for now!)
1066             if (p.x < dockingSensitivity && !isBlocked(c, BorderLayout.WEST)) {
1067                 return BorderLayout.WEST;
1068             }
1069             if (p.y >= c.getHeight() - dockingSensitivity && !isBlocked(c, BorderLayout.SOUTH)) {
1070                 return BorderLayout.SOUTH;
1071             }
1072         }
1073         return null;
1074     }
1075 
1076     /**
1077      * The method is used to drag {@code DragWindow} during the {@code JToolBar}
1078      * is being dragged.
1079      *
1080      * @param position the relative to the {@code JTollBar} position
1081      * @param origin the screen position of {@code JToolBar} before dragging
1082      */

1083     protected void dragTo(Point position, Point origin)
1084     {
1085         if (toolBar.isFloatable())
1086         {
1087           try
1088           {
1089             if (dragWindow == null)
1090                 dragWindow = createDragWindow(toolBar);
1091             Point offset = dragWindow.getOffset();
1092             if (offset == null) {
1093                 Dimension size = toolBar.getPreferredSize();
1094                 offset = new Point(size.width/2, size.height/2);
1095                 dragWindow.setOffset(offset);
1096             }
1097             Point global = new Point(origin.x+ position.x,
1098                                      origin.y+position.y);
1099             Point dragPoint = new Point(global.x- offset.x,
1100                                         global.y- offset.y);
1101             if (dockingSource == null)
1102                 dockingSource = toolBar.getParent();




 404         map.put(new Actions(Actions.NAVIGATE_UP));
 405         map.put(new Actions(Actions.NAVIGATE_DOWN));
 406     }
 407 
 408     /**
 409      * Unregisters keyboard actions.
 410      */
 411     protected void uninstallKeyboardActions( )
 412     {
 413         SwingUtilities.replaceUIActionMap(toolBar, null);
 414         SwingUtilities.replaceUIInputMap(toolBar, JComponent.
 415                                          WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
 416                                          null);
 417     }
 418 
 419     /**
 420      * Navigates the focused component.
 421      *
 422      * @param direction a direction
 423      */
 424     @SuppressWarnings("deprecation")
 425     protected void navigateFocusedComp(int direction)
 426     {
 427         int nComp = toolBar.getComponentCount();
 428         int j;
 429 
 430         switch ( direction )
 431         {
 432             case EAST:
 433             case SOUTH:
 434 
 435                 if ( focusedCompIndex < 0 || focusedCompIndex >= nComp ) break;
 436 
 437                 j = focusedCompIndex + 1;
 438 
 439                 while ( j != focusedCompIndex )
 440                 {
 441                     if ( j >= nComp ) j = 0;
 442                     Component comp = toolBar.getComponentAtIndex( j++ );
 443 
 444                     if ( comp != null && comp.isFocusTraversable() && comp.isEnabled() )


 870     public void setFloatingLocation(int x, int y) {
 871         floatingX = x;
 872         floatingY = y;
 873     }
 874 
 875     /**
 876      * Returns {@code true} if the {@code JToolBar} is floating
 877      *
 878      * @return {@code true} if the {@code JToolBar} is floating
 879      */
 880     public boolean isFloating() {
 881         return floating;
 882     }
 883 
 884     /**
 885      * Sets the floating property.
 886      *
 887      * @param b {@code true} if the {@code JToolBar} is floating
 888      * @param p the position
 889      */
 890     @SuppressWarnings("deprecation")
 891     public void setFloating(boolean b, Point p) {
 892         if (toolBar.isFloatable()) {
 893             boolean visible = false;
 894             Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
 895             if (ancestor != null) {
 896                 visible = ancestor.isVisible();
 897             }
 898             if (dragWindow != null)
 899                 dragWindow.setVisible(false);
 900             this.floating = b;
 901             if (floatingToolBar == null) {
 902                 floatingToolBar = createFloatingWindow(toolBar);
 903             }
 904             if (b == true)
 905             {
 906                 if (dockingSource == null)
 907                 {
 908                     dockingSource = toolBar.getParent();
 909                     dockingSource.remove(toolBar);
 910                 }


1065                 return BorderLayout.EAST;
1066             }
1067             // West  (Base distance on height for now!)
1068             if (p.x < dockingSensitivity && !isBlocked(c, BorderLayout.WEST)) {
1069                 return BorderLayout.WEST;
1070             }
1071             if (p.y >= c.getHeight() - dockingSensitivity && !isBlocked(c, BorderLayout.SOUTH)) {
1072                 return BorderLayout.SOUTH;
1073             }
1074         }
1075         return null;
1076     }
1077 
1078     /**
1079      * The method is used to drag {@code DragWindow} during the {@code JToolBar}
1080      * is being dragged.
1081      *
1082      * @param position the relative to the {@code JTollBar} position
1083      * @param origin the screen position of {@code JToolBar} before dragging
1084      */
1085     @SuppressWarnings("deprecation")
1086     protected void dragTo(Point position, Point origin)
1087     {
1088         if (toolBar.isFloatable())
1089         {
1090           try
1091           {
1092             if (dragWindow == null)
1093                 dragWindow = createDragWindow(toolBar);
1094             Point offset = dragWindow.getOffset();
1095             if (offset == null) {
1096                 Dimension size = toolBar.getPreferredSize();
1097                 offset = new Point(size.width/2, size.height/2);
1098                 dragWindow.setOffset(offset);
1099             }
1100             Point global = new Point(origin.x+ position.x,
1101                                      origin.y+position.y);
1102             Point dragPoint = new Point(global.x- offset.x,
1103                                         global.y- offset.y);
1104             if (dockingSource == null)
1105                 dockingSource = toolBar.getParent();


< prev index next >