# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\hg\toolbars\openide.loaders\src\org\openide\awt # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: Toolbar.java --- Toolbar.java Base (BASE) +++ Toolbar.java Locally Modified (Based On LOCAL) @@ -41,36 +41,32 @@ package org.openide.awt; -import java.awt.*; -import java.awt.datatransfer.*; -import java.awt.dnd.*; -import java.awt.event.*; +import java.awt.Component; +import java.awt.Insets; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.EventListener; import java.util.EventObject; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; +import javax.swing.AbstractButton; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JSeparator; +import javax.swing.JToolBar; +import javax.swing.UIManager; import javax.swing.plaf.metal.MetalLookAndFeel; -import javax.swing.plaf.synth.Region; -import javax.swing.plaf.synth.SynthConstants; -import javax.swing.plaf.synth.SynthContext; -import javax.swing.plaf.synth.SynthLookAndFeel; -import javax.swing.plaf.synth.SynthStyle; -import javax.swing.plaf.synth.SynthStyleFactory; import org.openide.cookies.InstanceCookie; -import org.openide.loaders.*; -import org.openide.nodes.Node; -import org.openide.util.*; +import org.openide.loaders.DataFolder; +import org.openide.loaders.DataObject; +import org.openide.loaders.FolderInstance; +import org.openide.util.ImageUtilities; +import org.openide.util.Task; import org.openide.util.actions.Presenter; -import org.openide.util.datatransfer.ExTransferable; /** * Toolbar provides a component which is useful for displaying commonly used @@ -87,27 +83,8 @@ static final Logger LOG = Logger.getLogger(Toolbar.class.getName()); - /** 5 pixels is tolerance of toolbar height so toolbar can be high (BASIC_HEIGHT + HEIGHT_TOLERANCE) - but it will be set to BASIC_HEIGHT high. */ - static int HEIGHT_TOLERANCE = 5; - /** TOP of toolbar empty border. */ - static int TOP = 2; - /** LEFT of toolbar empty border. */ - static int LEFT = 3; - /** BOTTOM of toolbar empty border. */ - static int BOTTOM = 2; - /** RIGHT of toolbar empty border. */ - static int RIGHT = 3; - /** Residual size of the toolbar when dragged far right */ - static int RESIDUAL_WIDTH = 16; - - - /** is toolbar floatable */ - private boolean floatable; /** Toolbar DnDListener */ private DnDListener listener; - /** Toolbar mouse listener */ - private ToolbarMouseListener mouseListener; /** display name of the toolbar */ private String displayName; @@ -130,24 +107,6 @@ isJdk16 = javaVersion.startsWith( "1.6" ); } - private static final int customFontHeightCorrection; - - static { - int customFontSize = UIManager.getInt( "customFontSize" ); - if( customFontSize < 1 ) - customFontSize = 1; - - int defaultFontSize = UIManager.getInt( "nbDefaultFontSize" ); - if( defaultFontSize <= 0 ) - defaultFontSize = 11; - - customFontHeightCorrection = Math.max( customFontSize - defaultFontSize, 0 ); - } - - private static Class synthIconClass = null; - - private static boolean testExecuted = false; - /** Create a new Toolbar with empty name. */ public Toolbar () { this (""); // NOI18N @@ -174,443 +133,17 @@ this (name, name, f); } - Toolbar(DataFolder folder, boolean f) { + Toolbar(DataFolder folder) { super(); backingFolder = folder; - initAll(folder.getName(), f); - initDnD(); + initAll(folder.getName(), false); + putClientProperty("folder", folder); //NOI18N } - /** - * Test if SynthIcon is available and can be used for painting native Toolbar - * D&D handle. If not use our own handle. Reflection is used here as it is Sun - * proprietary API. - */ - private static boolean useSynthIcon () { - if (!testExecuted) { - testExecuted = true; - try { - synthIconClass = Class.forName("sun.swing.plaf.synth.SynthIcon"); - } catch (ClassNotFoundException exc) { - LOG.log(Level.INFO, null, exc); - } - } - return (synthIconClass != null); - } - - private void initDnD() { - DropTarget dt = new DropTarget(this, getDnd()); - } - DataFolder getFolder() { return backingFolder; } - - @Override - public void paint( Graphics g ) { - super.paint( g ); - if( -1 != dropTargetButtonIndex ) { - paintDropGesture( g ); - } - } - - private void updateDropGesture( DropTargetDragEvent e ) { - Point p = e.getLocation(); - Component c = getComponentAt(p); - int index = Toolbar.this.getComponentIndex(c); - if( index == 0 ) { - //dragging over toolbar's grip - resetDropGesture(); - } else { - //find out whether we want to drop before or after this component - boolean b = p.x <= c.getLocation().x + c.getWidth() / 2; - if( index != dropTargetButtonIndex || b != insertBefore ) { - dropTargetButtonIndex = index; - insertBefore = b; - repaint(); - } - } - } - - private void resetDropGesture() { - dropTargetButtonIndex = -1; - repaint(); - } - - private void paintDropGesture( Graphics g ) { - Component c = getComponentAtIndex( dropTargetButtonIndex ); - if( null == c ) - return; - - Point location = c.getLocation(); - int cursorLocation = location.x; - if( !insertBefore ) { - cursorLocation += c.getWidth(); - if( dropTargetButtonIndex == getComponentCount()-1 ) - cursorLocation -= 3; - } - drawDropLine( g, cursorLocation ); - } - - private void drawDropLine( Graphics g, int x ) { - Color oldColor = g.getColor(); - g.setColor( Color.black ); - int height = getHeight(); - g.drawLine( x, 3, x, height-4 ); - g.drawLine( x-1, 3, x-1, height-4 ); - - g.drawLine( x+1, 2, x+1+2, 2 ); - g.drawLine( x+1, height-3, x+1+2, height-3 ); - - g.drawLine( x-2, 2, x-2-2, 2 ); - g.drawLine( x-2, height-3, x-2-2, height-3 ); - g.setColor( oldColor ); - } - - /** - * Remove a toolbar button represented by the given Transferable. - */ - private void removeButton( Transferable t ) { - try { - Object o = null; - if( t.isDataFlavorSupported( buttonDataFlavor ) ) { - o = t.getTransferData( buttonDataFlavor ); //XXX - } - if( null != o && o instanceof DataObject ) { - ((DataObject) o).delete(); - repaint(); - if( backingFolder.getChildren().length == 0 ) { - javax.swing.SwingUtilities.invokeLater(new java.lang.Runnable() { - - public void run() { - try { - backingFolder.delete(); - } - catch (java.io.IOException e) { - LOG.log(Level.WARNING, - null, - e); - } - } - }); - } - } - } catch( UnsupportedFlavorException ex ) { - Exceptions.printStackTrace(ex); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - } - - /** - * Perform the drop operation. - * - * @return True if the drop has been successful. - */ - private boolean handleDrop( Transferable t ) { - try { - Object o; - if( t.isDataFlavorSupported( actionDataFlavor ) ) { - o = t.getTransferData( actionDataFlavor ); - if( o instanceof Node ) { - DataObject dobj = ((Node)o).getLookup().lookup( DataObject.class ); - return addButton( dobj, dropTargetButtonIndex-1, insertBefore ); - } - } else { - o = t.getTransferData( buttonDataFlavor ); - if( o instanceof DataObject ) { - return moveButton( (DataObject)o, dropTargetButtonIndex-1, insertBefore ); - } - } - } catch (UnsupportedFlavorException e) { - Exceptions.printStackTrace(e); - } catch (IOException ioe) { - Exceptions.printStackTrace(ioe); - } - return false; - } - - /** - * Component index of the button under the drag cursor, or -1 when the cursor - * is above the toolbar drag handle - */ - int dropTargetButtonIndex = -1; - /** - * Component index of the button being dragged, only used when dragging a button - * within the same toolbar. - */ - int dragSourceButtonIndex = -1; - /** - * True if the button being dragged should be dropped BEFORE the button - * under the drag cursor. - */ - boolean insertBefore = true; - /** - * True indicates the toolbar instance whose button is being dragged. - */ - boolean isDragSourceToolbar = false; - - private static DataFlavor buttonDataFlavor = new DataFlavor( DataObject.class, "Toolbar Item" ); - private static DataFlavor actionDataFlavor = new DataFlavor( Node.class, "Action Node" ); - - private DnDSupport dnd; - private class DnDSupport implements DragSourceListener, DragGestureListener, DropTargetListener, DragSourceMotionListener { - private DragSource dragSource = new DragSource(); - - private Cursor dragMoveCursor = DragSource.DefaultMoveDrop; - private Cursor dragNoDropCursor = DragSource.DefaultMoveNoDrop; - private Cursor dragRemoveCursor = Utilities.createCustomCursor( Toolbar.this, ImageUtilities.loadImage( "org/openide/loaders/delete.gif"), "NO_ACTION_MOVE" ); - private Map recognizers = new HashMap(); - - public DnDSupport() { - dragSource.addDragSourceMotionListener(this); - } - - public void register(Component c) { - DragGestureRecognizer dgr = recognizers.get( c ); - if( null == dgr ) { - dgr = dragSource.createDefaultDragGestureRecognizer(c, DnDConstants.ACTION_MOVE, this); - recognizers.put( c, dgr ); - } - } - - public void unregister(Component c) { - DragGestureRecognizer dgr = recognizers.get( c ); - if( null != dgr ) { - dgr.removeDragGestureListener( this ); - recognizers.remove( c ); - } - } - - public void dragEnter(DragSourceDragEvent e) { - //handled in dragMouseMoved - } - - public void dragOver(DragSourceDragEvent e) { - //handled in dragMouseMoved - } - - public void dragExit(DragSourceEvent e) { - //handled in dragMouseMoved - resetDropGesture(); - } - - public void dragDropEnd(DragSourceDropEvent e) { - isDragSourceToolbar = false; - Component sourceComponent = e.getDragSourceContext().getComponent(); - if( sourceComponent instanceof JButton ) { - ((JButton)sourceComponent).getModel().setRollover( false ); - } - sourceComponent.repaint(); - resetDropGesture(); - if ( e.getDropSuccess() == false && !isInToolbarPanel( e.getLocation() ) ) { - removeButton( e.getDragSourceContext().getTransferable() ); - } - } - - public void dragGestureRecognized(DragGestureEvent e) { - if( !ToolbarPool.getDefault().isInEditMode() - || "QuickSearch".equals(getName()) ) //HACK (137286)- there's not better way... - return; - try { - Component c = e.getComponent(); - //do not allow to drag toolbar separators - if( c instanceof JToolBar.Separator || "grip".equals( c.getName() ) ) - return; - Transferable t = null; - if (c instanceof JComponent) { - final DataObject dob = (DataObject) ((JComponent) c).getClientProperty("file"); - if (dob != null) { - t = new ExTransferable.Single( buttonDataFlavor ) { - public Object getData() { - return dob; - } - }; - } - } - if( c instanceof JButton ) { - ((JButton)c).getModel().setArmed( false ); - ((JButton)c).getModel().setPressed( false ); - ((JButton)c).getModel().setRollover( true ); - } - if (t != null) { - dragSourceButtonIndex = Toolbar.this.getComponentIndex( c ); - isDragSourceToolbar = true; - dragSource.startDrag(e, dragMoveCursor, t, this); - } - - } catch ( InvalidDnDOperationException idoe ) { - Exceptions.printStackTrace(idoe); - } - } - - public void dropActionChanged (DragSourceDragEvent e) { - //ignore - } - - public void drop(DropTargetDropEvent dtde) { - boolean res = false; - try { - if( validateDropPosition() ) { - res = handleDrop( dtde.getTransferable() ); - } - } finally { - dtde.dropComplete(res); - } - resetDropGesture(); - } - - public void dragExit(DropTargetEvent dte) { - resetDropGesture(); - } - - public void dropActionChanged(DropTargetDragEvent dtde) { - //ignore - } - - public void dragEnter(DropTargetDragEvent e) { - if( e.isDataFlavorSupported( buttonDataFlavor ) - || e.isDataFlavorSupported( actionDataFlavor ) ) { - e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); - } else { - e.rejectDrag(); - } - } - - public void dragOver(DropTargetDragEvent e) { - if( e.isDataFlavorSupported( buttonDataFlavor ) - || e.isDataFlavorSupported( actionDataFlavor ) ) { - updateDropGesture( e ); - if( !validateDropPosition() ) { - e.rejectDrag(); - } else { - e.acceptDrag( DnDConstants.ACTION_COPY_OR_MOVE ); - } - } else { - e.rejectDrag(); - } - } - - public void dragMouseMoved(DragSourceDragEvent e) { - DragSourceContext context = e.getDragSourceContext(); - int action = e.getDropAction(); - if ((action & DnDConstants.ACTION_MOVE) != 0) { - context.setCursor( dragMoveCursor ); - } else { - if( isInToolbarPanel( e.getLocation() ) ) - context.setCursor( dragNoDropCursor ); - else - context.setCursor( dragRemoveCursor ); - } - } - } - - private boolean isInToolbarPanel( Point p ) { - Component c = ToolbarPool.getDefault(); - SwingUtilities.convertPointFromScreen( p, c ); - return c.contains( p ); - } - - /** - * Add a new toolbar button represented by the given DataObject. - */ - private boolean addButton( DataObject dobj, int dropIndex, boolean dropBefore ) throws IOException { - if( null == dobj ) - return false; - //check if the dropped button (action) already exists in this toolbar - String objName = dobj.getName(); - DataObject[] children = backingFolder.getChildren(); - for( int i=0; i children = - new ArrayList( Arrays.asList( backingFolder.getChildren() ) ); - if( null == objUnderCursor ) { - children.remove( objToMove ); - children.add( objToMove ); - } else { - int targetIndex = children.indexOf( objUnderCursor ); - int currentIndex = children.indexOf( objToMove ); - if( currentIndex < targetIndex ) - targetIndex--; - children.remove( objToMove ); - children.add( targetIndex, objToMove ); - } - - backingFolder.setOrder( children.toArray( new DataObject[children.size()]) ); - } - - private DataObject getDataObjectUnderDropCursor( int dropIndex, boolean dropBefore ) { - DataObject[] buttons = backingFolder.getChildren(); - DataObject objUnderCursor = null; - if( buttons.length > 0 ) { - if( !dropBefore ) - dropIndex++; - if( dropIndex < buttons.length && dropIndex >= 0 ) { - objUnderCursor = buttons[dropIndex]; - } - } - return objUnderCursor; - } - - private boolean validateDropPosition() { - //the drag cursor cannot be positioned above toolbar's drag handle - return dropTargetButtonIndex >= 0 - //when toolbar has buttons '1 2 3 4 5' and we're dragging button 3, - //do not allow drop between buttons 2 and 3 and also between buttons 3 and 3 - && !(isDragSourceToolbar && (dragSourceButtonIndex == dropTargetButtonIndex //drop index 3 - || (dropTargetButtonIndex == dragSourceButtonIndex-1 && !insertBefore) //drop index 2 - || (dropTargetButtonIndex == dragSourceButtonIndex+1 && insertBefore))) //drop index 4 - //dragging a button to an empty toolbar - || (dropTargetButtonIndex < 0 && getComponentCount() == 1); - } - /** Start tracking content of the underlaying folder if not doing so yet */ final Folder waitFinished() { // check for too early call (from constructor and UI.setUp...) @@ -671,10 +204,7 @@ } super.addImpl (c, constraints, idx); - if( !("grip".equals(c.getName()) || (c instanceof JToolBar.Separator)) ) { - getDnd().register(c); } - } /** * Create a new Toolbar. @@ -691,47 +221,17 @@ * toolbar layout manager. * @return basic toolbar height * @since 4.15 + * @deprecated Returns preferred icon size. */ public static int getBasicHeight () { - if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { - return 44; - } else { - return 34; + return ToolbarPool.getDefault().getPreferredIconSize(); } - } private void initAll(String name, boolean f) { - floatable = f; - mouseListener = null; - setName (name); - setFloatable (false); - String lAndF = UIManager.getLookAndFeel().getName(); + setFloatable (f); - if (lAndF.equals("Windows")) { - //Get rid of extra height, also allow for minimalist main - //window - setBorder(Boolean.getBoolean("netbeans.small.main.window") ? - BorderFactory.createEmptyBorder(1,1,1,1) : - BorderFactory.createEmptyBorder()); //NOI18N - } else if (!"Aqua".equals(UIManager.getLookAndFeel().getID()) && !"GTK".equals(UIManager.getLookAndFeel().getID())){ - Border b = UIManager.getBorder ("ToolBar.border"); //NOI18N - - if ((b==null) || (b instanceof javax.swing.plaf.metal.MetalBorders.ToolBarBorder)) - b=BorderFactory.createEtchedBorder (EtchedBorder.LOWERED); - setBorder (new CompoundBorder ( - b, - new EmptyBorder (TOP, LEFT, BOTTOM, RIGHT)) - ); - - } - - if (!"Aqua".equals(UIManager.getLookAndFeel().getID())) { - putClientProperty("JToolBar.isRollover", Boolean.TRUE); // NOI18N - } - addGrip(); - getAccessibleContext().setAccessibleName(displayName == null ? getName() : displayName); getAccessibleContext().setAccessibleDescription(getName()); } @@ -745,100 +245,18 @@ } } - @Override - public Dimension getPreferredSize() { - String lfid = UIManager.getLookAndFeel().getID(); - int minheight; - - if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { - if ("Aqua".equals(lfid)) { - minheight = 29 + 8; - } else if ("Metal".equals(lfid)) { - minheight = 36 + 8; - } else if ("Windows".equals(lfid)) { - minheight = isXPTheme() ? (23 + 8) : (27 + 8); - } else if ("GTK".equals(lfid)) { - minheight = 32 + 8; - } else { - minheight = 28 + 8; - } - } else { - if ("Aqua".equals(lfid)) { - minheight = 29; - } else if ("Metal".equals(lfid)) { - minheight = 36; - } else if ("Windows".equals(lfid)) { - minheight = isXPTheme() ? 23 : 27; - } else if ("GTK".equals(lfid)) { - minheight = 32; - } else { - minheight = 28; - } - } - Dimension result = super.getPreferredSize(); - result.height = Math.max (result.height, minheight); - return result; - } - - /** Removes all ACTION components. */ - @Override - public void removeAll () { - for( int i=0; i getParent().getWidth() - RESIDUAL_WIDTH ? - 0 : e.getX() - startPoint.x; - - fireDropToolbar (dx, - e.getY() - startPoint.y, - DnDEvent.DND_ONE); - dragging = false; - } - } - - /** Invoked when a mouse button is pressed on a component and then dragged. */ - @Override - public void mouseDragged (MouseEvent e) { - int m = e.getModifiers(); - int type = DnDEvent.DND_ONE; - int dx; - - if (e.isControlDown()) - type = DnDEvent.DND_LINE; - else if (((m & InputEvent.BUTTON2_MASK) != 0) || - ((m & InputEvent.BUTTON3_MASK) != 0)) - type = DnDEvent.DND_END; - if (startPoint == null) { - startPoint = new Point (e.getX(), e.getY()); - } - - if ( getX() + e.getX() + startPoint.x > getParent().getWidth() - RESIDUAL_WIDTH ) { - if ( getX() >= getParent().getWidth() - RESIDUAL_WIDTH ) { - dx = 0; - } - else { - dx = getParent().getWidth() - RESIDUAL_WIDTH - getX(); - } - } - else { - dx = e.getX() - startPoint.x; - } - - fireDragToolbar ( dx, - e.getY() - startPoint.y, - type); - dragging = true; - } - - } // end of inner class ToolbarMouseListener - /** * This class can be used to produce a Toolbar instance from * the given DataFolder. @@ -1012,7 +337,7 @@ */ @Override protected InstanceCookie acceptCookie (InstanceCookie cookie) - throws java.io.IOException, ClassNotFoundException { + throws IOException, ClassNotFoundException { boolean is; if (cookie instanceof InstanceCookie.Of) { @@ -1047,53 +372,44 @@ * @return the updated ToolbarPool representee */ protected Object createInstance(final InstanceCookie[] cookies) - throws java.io.IOException, ClassNotFoundException { + throws IOException, ClassNotFoundException { // refresh the toolbar's content Toolbar.this.removeAll(); for (int i = 0; i < cookies.length; i++) { try { - java.lang.Object obj = cookies[i].instanceCreate(); - java.lang.Object file = cookiesToObjects.get(obj); + Object obj = cookies[i].instanceCreate(); + Object file = cookiesToObjects.get(obj); - if (obj instanceof org.openide.util.actions.Presenter.Toolbar) { - obj = ((org.openide.util.actions.Presenter.Toolbar) obj).getToolbarPresenter(); + if (obj instanceof Presenter.Toolbar) { + obj = ((Presenter.Toolbar) obj).getToolbarPresenter(); } - if (obj instanceof java.awt.Component) { + if (obj instanceof Component) { // remove border and grip if requested. "Fixed" toolbar // item has to live alone in toolbar now - if ((obj instanceof javax.swing.JComponent) && - "Fixed".equals(((javax.swing.JComponent) obj).getClientProperty("Toolbar"))) { - floatable = false; + if ((obj instanceof JComponent) && + "Fixed".equals(((JComponent) obj).getClientProperty("Toolbar"))) { org.openide.awt.Toolbar.this.removeAll(); setBorder(null); } if (obj instanceof javax.swing.JComponent) { - if (org.openide.awt.ToolbarPool.getDefault().getPreferredIconSize() == - 24) { - ((javax.swing.JComponent) obj).putClientProperty("PreferredIconSize", - new java.lang.Integer(24)); + if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { + ((JComponent) obj).putClientProperty("PreferredIconSize", new Integer(24)); } - ((javax.swing.JComponent) obj).putClientProperty("file", - file); + ((JComponent) obj).putClientProperty("file", file); } - org.openide.awt.Toolbar.this.add((java.awt.Component) obj); + Toolbar.this.add((Component) obj); continue; } - if (obj instanceof javax.swing.Action) { - javax.swing.Action a = (javax.swing.Action) obj; - javax.swing.JButton b = new org.openide.awt.Toolbar.DefaultIconButton(); + if (obj instanceof Action) { + Action a = (Action) obj; + JButton b = new DefaultIconButton(); - if (org.openide.awt.ToolbarPool.getDefault().getPreferredIconSize() == - 24) { - b.putClientProperty("PreferredIconSize", - new java.lang.Integer(24)); + if (ToolbarPool.getDefault().getPreferredIconSize() == 24) { + b.putClientProperty("PreferredIconSize", new Integer(24)); } - if (null == a.getValue(javax.swing.Action.SMALL_ICON) && - (null == a.getValue(javax.swing.Action.NAME) || - a.getValue(javax.swing.Action.NAME).toString().length() == - 0)) { - a.putValue(javax.swing.Action.SMALL_ICON, - new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") )); + if (null == a.getValue(Action.SMALL_ICON) + && (null == a.getValue(Action.NAME) || a.getValue(Action.NAME).toString().length() == 0)) { + a.putValue(Action.SMALL_ICON, new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") )); } org.openide.awt.Actions.connect(b, a); b.putClientProperty("file", file); @@ -1126,273 +442,7 @@ } // end of inner class Folder - /** Bumps for floatable toolbar */ - private final class ToolbarBump extends JPanel { - /** Top gap. */ - static final int TOPGAP = 2; - /** Bottom gap. */ - static final int BOTGAP = 2; - /** Width of bump element. */ - static final int WIDTH = 6; - - /** Minimum size. */ - Dimension dim; - /** Maximum size. */ - Dimension max; - - static final long serialVersionUID =-8819972936203315277L; - - /** Create new ToolbarBump. */ - public ToolbarBump () { - super(); - int width = WIDTH; - dim = new Dimension (width, width); - max = new Dimension (width, Integer.MAX_VALUE); - Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); - } - - /** Paint bumps to specific Graphics. */ @Override - public void paint (Graphics g) { - Dimension size = this.getSize (); - int height = size.height - BOTGAP; - g.setColor (this.getBackground ()); - - for (int x = 0; x+1 < size.width; x+=4) { - for (int y = TOPGAP; y+1 < height; y+=4) { - g.setColor (this.getBackground ().brighter ()); - g.drawLine (x, y, x, y); - if (x+5 < size.width && y+5 < height) { - g.drawLine (x+2, y+2, x+2, y+2); - } - g.setColor (this.getBackground ().darker ().darker ()); - g.drawLine (x+1, y+1, x+1, y+1); - if (x+5 < size.width && y+5 < height) { - g.drawLine (x+3, y+3, x+3, y+3); - } - } - } - } - - /** @return minimum size */ - @Override - public Dimension getMinimumSize () { - return dim; - } - - /** @return preferred size */ - @Override - public Dimension getPreferredSize () { - return this.getMinimumSize (); - } - - @Override - public Dimension getMaximumSize () { - return max; - } - } // end of inner class ToolbarBump - - /** Bumps for floatable toolbar GTK L&F */ - private final class ToolbarGtk extends JPanel { - /** Top gap. */ - int TOPGAP; - /** Bottom gap. */ - int BOTGAP; - /** Width of bump element. */ - static final int WIDTH = 6; - - /** Minimum size. */ - Dimension dim; - /** Maximum size. */ - Dimension max; - - static final long serialVersionUID = -8819972936203315277L; - - /** Create new ToolbarBump. */ - public ToolbarGtk () { - super(); - int width = WIDTH; - if (useSynthIcon()) { - TOPGAP = 0; - BOTGAP = 0; - } else { - TOPGAP = 2; - BOTGAP = 2; - } - dim = new Dimension (width, width); - max = new Dimension (width, Integer.MAX_VALUE); - Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); - } - - /** Paint bumps to specific Graphics. */ - @Override - public void paint (Graphics g) { - if (useSynthIcon()) { - int height = Toolbar.this.getHeight() - BOTGAP; - Icon icon = UIManager.getIcon("ToolBar.handleIcon"); - Region region = Region.TOOL_BAR; - SynthStyleFactory sf = SynthLookAndFeel.getStyleFactory(); - SynthStyle style = sf.getStyle(Toolbar.this, region); - SynthContext context = new SynthContext(Toolbar.this, region, style, SynthConstants.DEFAULT); - - // for vertical toolbar, you'll need to ask for getIconHeight() instead - Method m = null; - try { - m = synthIconClass.getMethod("getIconWidth",Icon.class, SynthContext.class); - } catch (NoSuchMethodException exc) { - LOG.log(Level.WARNING, null, exc); - } - int width = 0; - //width = SynthIcon.getIconWidth(icon, context); - try { - width = (Integer) m.invoke(null, new Object [] {icon, context}); - } catch (IllegalAccessException exc) { - LOG.log(Level.WARNING, null, exc); - } catch (InvocationTargetException exc) { - LOG.log(Level.WARNING, null, exc); - } - try { - m = synthIconClass.getMethod("paintIcon",Icon.class,SynthContext.class, - Graphics.class,Integer.TYPE,Integer.TYPE,Integer.TYPE,Integer.TYPE); - } catch (NoSuchMethodException exc) { - LOG.log(Level.WARNING, null, exc); - } - //SynthIcon.paintIcon(icon, context, g, 0, 0, width, height); - try { - m.invoke(null, new Object [] {icon,context,g,new Integer(0),new Integer(-1), - new Integer(width),new Integer(height)}); - } catch (IllegalAccessException exc) { - LOG.log(Level.WARNING, null, exc); - } catch (InvocationTargetException exc) { - LOG.log(Level.WARNING, null, exc); - } - } else { - Dimension size = this.getSize(); - int height = size.height - BOTGAP; - g.setColor (this.getBackground ()); - - for (int x = 0; x+1 < size.width; x+=4) { - for (int y = TOPGAP; y+1 < height; y+=4) { - g.setColor (this.getBackground ().brighter ()); - g.drawLine (x, y, x, y); - if (x+5 < size.width && y+5 < height) { - g.drawLine (x+2, y+2, x+2, y+2); - } - g.setColor (this.getBackground ().darker ().darker ()); - g.drawLine (x+1, y+1, x+1, y+1); - if (x+5 < size.width && y+5 < height) { - g.drawLine (x+3, y+3, x+3, y+3); - } - } - } - } - } - - /** @return minimum size */ - @Override - public Dimension getMinimumSize () { - return dim; - } - - /** @return preferred size */ - @Override - public Dimension getPreferredSize () { - return new Dimension(WIDTH,Toolbar.this.getHeight() - BOTGAP - TOPGAP); - } - - @Override - public Dimension getMaximumSize () { - return max; - } - } // end of inner class ToolbarGtk - - /** Recognizes if XP theme is set. - * @return true if XP theme is set, false otherwise - */ - private static Boolean isXP = null; - private static boolean isXPTheme () { - if (isXP == null) { - Boolean xp = (Boolean)Toolkit.getDefaultToolkit(). - getDesktopProperty("win.xpstyle.themeActive"); //NOI18N - isXP = Boolean.TRUE.equals(xp)? Boolean.TRUE : Boolean.FALSE; - } - return isXP.booleanValue(); - } - - private final class ToolbarAqua extends JPanel { - /** Width of grip */ - static final int WIDTH = 8; - /** Minimum size. */ - Dimension dim; - /** Maximum size. */ - Dimension max; - static final long serialVersionUID =-8819972972003315277L; - - public ToolbarAqua() { - dim = new Dimension (WIDTH, WIDTH); - max = new Dimension (WIDTH, Integer.MAX_VALUE); - Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); - } - - @Override - public void paintComponent (Graphics g) { - super.paintComponent(g); - java.awt.Graphics2D g2d = (Graphics2D) g; - g2d.addRenderingHints(getHints()); - - int sz = 5; - - int y = ((getHeight() / 2) - (sz / 2)) - 2; - int x = ((getWidth() / 2) - (sz / 2)) - 2; - - GradientPaint gradient = new GradientPaint(x+1, y+1, Color.BLACK, - x+sz-1, y+sz-1, Color.WHITE); - - Paint paint = g2d.getPaint(); - - g2d.setPaint(gradient); - g2d.drawArc(x,y,sz,sz,0,359); - - g.setColor(new Color(240,240,240)); - g.drawLine(x+(sz/2), y + (sz/2),x+(sz/2), y + (sz/2)); - - g2d.setPaint(paint); - } - - /** @return minimum size */ - @Override - public Dimension getMinimumSize () { - return dim; - } - - /** @return preferred size */ - @Override - public Dimension getPreferredSize () { - return this.getMinimumSize (); - } - - @Override - public Dimension getMaximumSize () { - return max; - } - } - - private static java.util.Map hintsMap = null; - @SuppressWarnings("unchecked") - static final Map getHints() { - //XXX We REALLY need to put this in a graphics utils lib - if (hintsMap == null) { - //Thanks to Phil Race for making this possible - hintsMap = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N - if (hintsMap == null) { - hintsMap = new HashMap(); - hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - } - } - return hintsMap; - } - - @Override public void setUI(javax.swing.plaf.ToolBarUI ui) { super.setUI(ui); if( null != backingFolder && null != processor ) { @@ -1401,184 +451,11 @@ } } - private final class ToolbarXP extends JPanel { - /** Width of grip */ - static final int WIDTH = 7; - /** Minimum size. */ - Dimension dim; - /** Maximum size. */ - Dimension max; - static final long serialVersionUID =-8819972936203315277L; - public ToolbarXP() { - dim = new Dimension (WIDTH, WIDTH); - max = new Dimension (WIDTH, Integer.MAX_VALUE); - Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); - } - - @Override - public void paintComponent (Graphics g) { - super.paintComponent(g); - int x = 3; - for (int i=4; i < getHeight()-4; i+=4) { - //first draw the rectangular highlight below each dot - g.setColor(UIManager.getColor("controlLtHighlight")); //NOI18N - g.fillRect(x + 1, i + 1, 2, 2); - //Get the shadow color. We'll paint the darkest dot first, - //and work our way to the lightest - Color col = UIManager.getColor("controlShadow"); //NOI18N - g.setColor(col); - //draw the darkest dot - g.drawLine(x+1, i+1, x+1, i+1); - - //Get the color components and calculate the amount each component - //should increase per dot - int red = col.getRed(); - int green = col.getGreen(); - int blue = col.getBlue(); - - //Get the default component background - we start with the dark - //color, and for each dot, add a percentage of the difference - //between this and the background color - Color back = getBackground(); - int rb = back.getRed(); - int gb = back.getGreen(); - int bb = back.getBlue(); - - //Get the amount to increment each component for each dot - int incr = (rb - red) / 5; - int incg = (gb - green) / 5; - int incb = (bb - blue) / 5; - - //Increment the colors - red += incr; - green += incg; - blue += incb; - //Create a slightly lighter color and draw the dot - col = new Color(red, green, blue); - g.setColor(col); - g.drawLine(x+1, i, x+1, i); - - //And do it for the next dot, and so on, for all four dots - red += incr; - green += incg; - blue += incb; - col = new Color(red, green, blue); - g.setColor(col); - g.drawLine(x, i+1, x, i+1); - - red += incr; - green += incg; - blue += incb; - col = new Color(red, green, blue); - g.setColor(col); - g.drawLine(x, i, x, i); - } - } - - /** @return minimum size */ - @Override - public Dimension getMinimumSize() { - return dim; - } - - /** @return preferred size */ - @Override - public Dimension getPreferredSize () { - return this.getMinimumSize (); - } - - @Override - public Dimension getMaximumSize () { - return max; - } - } - - /* - public static void main(String[] args) { - JFrame jf = new JFrame(); - jf.getContentPane().add (new ToolbarXP()); - jf.setSize(new java.awt.Dimension(200,200)); - jf.setLocation(20,20); - jf.show(); - } + /** DnDListener is Drag and Drop listener for Toolbar motion events. + * @deprecated There is no public support for toolbar drag and drop. */ - - - /** Grip for floatable toolbar, used for Windows Classic L&F */ - private final class ToolbarGrip extends JPanel { - /** Horizontal gaps. */ - static final int HGAP = 1; - /** Vertical gaps. */ - static final int VGAP = 2; - /** Step between two grip elements. */ - static final int STEP = 1; - /** Width of grip element. */ - static final int WIDTH = 2; - - /** Number of grip elements. */ - int columns; - /** Minimum size. */ - Dimension dim; - /** Maximum size. */ - Dimension max; - - static final long serialVersionUID =-8819972936203315276L; - - /** Create new ToolbarGrip for default number of grip elements. */ - public ToolbarGrip () { - this(1); - } - - /** Create new ToolbarGrip for specific number of grip elements. - * @param col number of grip elements - */ - public ToolbarGrip (int col) { - super (); - columns = col; - int width = (col - 1) * STEP + col * WIDTH + 2 * HGAP; - dim = new Dimension (width, width); - max = new Dimension (width, Integer.MAX_VALUE); - this.setBorder (new EmptyBorder (VGAP, HGAP, VGAP, HGAP)); - Toolbar.setToolTipText (this, Toolbar.this.getDisplayName()); - } - - /** Paint grip to specific Graphics. */ - @Override - public void paint (Graphics g) { - Dimension size = this.getSize(); - int top = VGAP; - int bottom = size.height - 1 - VGAP; - int height = bottom - top; - g.setColor ( this.getBackground() ); - - for (int i = 0, x = HGAP; i < columns; i++, x += WIDTH + STEP) { - g.draw3DRect (x, top, WIDTH, height, true); // grip element is 3D rectangle now - } - - } - - /** @return minimum size */ - @Override - public Dimension getMinimumSize () { - return dim; - } - - /** @return preferred size */ - @Override - public Dimension getPreferredSize () { - return this.getMinimumSize(); - } - - @Override - public Dimension getMaximumSize () { - return max; - } - - } // end of inner class ToolbarGrip - - /** DnDListener is Drag and Drop listener for Toolbar motion events. */ - public interface DnDListener extends java.util.EventListener { + public interface DnDListener extends EventListener { /** Invoced when toolbar is dragged. */ public void dragToolbar (DnDEvent e); @@ -1587,7 +464,9 @@ } // end of interface DnDListener - /** DnDEvent is Toolbar's drag and drop event. */ + /** DnDEvent is Toolbar's drag and drop event. + * @deprecated + */ public static class DnDEvent extends EventObject { /** Type of DnDEvent. Dragging with only one Toolbar. */ public static final int DND_ONE = 1; @@ -1647,7 +526,7 @@ Icon retValue = super.getIcon(); if( null == retValue && (null == getText() || getText().length() == 0 ) ) { if (unknownIcon == null) { - unknownIcon = new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") ); + unknownIcon = new ImageIcon( ImageUtilities.loadImage( "org/openide/loaders/unknown.gif") ); //NOI18N } retValue = unknownIcon; } @@ -1655,10 +534,4 @@ } } - private DnDSupport getDnd() { - if (dnd == null) { - dnd = new DnDSupport(); - } - return dnd; - } } // end of class Toolbar Index: ToolbarPool.java --- ToolbarPool.java Base (BASE) +++ ToolbarPool.java Locally Modified (Based On LOCAL) @@ -42,19 +42,37 @@ package org.openide.awt; -import java.awt.*; -import java.awt.event.*; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; import java.io.IOException; -import java.util.*; import java.util.ArrayList; -import javax.accessibility.*; -import javax.swing.*; +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; +import java.util.WeakHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.swing.ButtonGroup; +import javax.swing.JComponent; import javax.swing.JComponent.AccessibleJComponent; -import javax.swing.border.Border; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButtonMenuItem; import org.openide.cookies.InstanceCookie; -import org.openide.filesystems.*; -import org.openide.loaders.*; -import org.openide.util.*; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.Repository; +import org.openide.loaders.DataFolder; +import org.openide.loaders.FolderInstance; +import org.openide.util.Task; +import org.openide.util.TaskListener; /** * This class keeps track of the current toolbars and their names. @@ -107,9 +125,10 @@ try { fo = FileUtil.createFolder(root, "Toolbars"); // NOI18N } catch (IOException ex) { - Exceptions.printStackTrace(ex); + Logger.getLogger(ToolbarPool.class.getName()).log(Level.CONFIG, "Cannot create Toolbars folder.", ex); } - if (fo == null) throw new IllegalStateException("No Toolbars/"); // NOI18N + if (fo == null) + throw new IllegalStateException("No Toolbars/"); // NOI18N DataFolder folder = DataFolder.findFolder(fo); defaultPool = new ToolbarPool(folder); // we mustn't do this in constructor to prevent from @@ -142,25 +161,7 @@ getAccessibleContext().setAccessibleName(instance.instanceName()); getAccessibleContext().setAccessibleDescription(instance.instanceName()); - - if ("Windows".equals(UIManager.getLookAndFeel().getID())) { - if( isXPTheme() ) { - //Set up custom borders for XP - setBorder(BorderFactory.createCompoundBorder( - upperBorder, - BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(0, 0, 1, 0, - fetchColor("controlShadow", Color.DARK_GRAY)), - BorderFactory.createMatteBorder(0, 0, 1, 0, mid)) - )); //NOI18N - } else { - setBorder( BorderFactory.createEtchedBorder() ); } - } else if ("GTK".equals(UIManager.getLookAndFeel().getID())) { - //No border - setBorder (BorderFactory.createEmptyBorder(0, 0, 0, 0)); - } - } /** * Gets preferred size of icons used by toolbar buttons. Default icon size @@ -185,61 +186,6 @@ this.preferredIconSize = preferredIconSize; } - public Border getBorder() { - //Issue 36867, hide border if there are no toolbars. Not the most - //performant way to do it; if it has a measurable impact, can be - //improved - if (center != null && center instanceof Container && - ((Container)center).getComponentCount() > 0) { - - boolean show = false; - for (int i=0; i < ((Container)center).getComponentCount(); i++) { - Component c = ((Container)center).getComponent(i); - if (c.isVisible()) { - show = true; - break; - } - } - if (show) { - return super.getBorder(); - } - } - return lowerBorder; - } - - private static Color fetchColor (String key, Color fallback) { - //Fix ExceptionInInitializerError from MainWindow on GTK L&F - use - //fallback colors - Color result = (Color) UIManager.get(key); - if (result == null) { - result = fallback; - } - return result; - } - - private static Color mid; - static { - Color lo = fetchColor("controlShadow", Color.DARK_GRAY); //NOI18N - Color hi = fetchColor("control", Color.GRAY); //NOI18N - - int r = (lo.getRed() + hi.getRed()) / 2; - int g = (lo.getGreen() + hi.getGreen()) / 2; - int b = (lo.getBlue() + hi.getBlue()) / 2; - mid = new Color(r, g, b); - } - - private static final Border lowerBorder = BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(0, 0, 1, 0, - fetchColor("controlShadow", Color.DARK_GRAY)), - BorderFactory.createMatteBorder(0, 0, 1, 0, mid)); //NOI18N - - private static final Border upperBorder = BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(1, 0, 0, 0, - fetchColor("controlShadow", Color.DARK_GRAY)), - BorderFactory.createMatteBorder(1, 0, 0, 0, - fetchColor("controlLtHighlight", Color.WHITE))); //NOI18N - - /** Allows to wait till the content of the pool is initialized. */ public final void waitFinished () { instance.instanceFinished (); @@ -262,15 +208,15 @@ /** Updates the default configuration. */ private synchronized void updateDefault () { - Toolbar[] toolbars = getToolbars (); + Toolbar[] bars = getToolbars (); name = ""; // NOI18N - if (toolbars.length == 1) { - revalidate(toolbars[0]); + if (bars.length == 1) { + revalidate(bars[0]); } else { JPanel tp = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); - for (int i = 0; i < toolbars.length; i++) { - tp.add(toolbars[i]); + for (int i = 0; i < bars.length; i++) { + tp.add(bars[i]); } revalidate(tp); } @@ -285,7 +231,9 @@ revalidate (comp); } - /** Sets DnDListener to all Toolbars. */ + /** Sets DnDListener to all Toolbars. + * @deprecated + */ public void setToolbarsListener (Toolbar.DnDListener l) { for (Toolbar t: toolbars.values()) { t.setDnDListener (l); @@ -302,11 +250,6 @@ } add (center = c, BorderLayout.CENTER); center.addMouseListener (listener); - -// java.awt.Window w = javax.swing.SwingUtilities.windowForComponent (this); -// if (w != null) { -// w.validate(); -// } } } @@ -366,7 +309,7 @@ activate (config); } - firePropertyChange("configuration", old, name); + firePropertyChange("configuration", old, name); //NOI18N } /** @@ -402,9 +345,11 @@ /** Read accessible context * @return - accessible context */ + @Override public AccessibleContext getAccessibleContext () { if(toolbarAccessibleContext == null) { toolbarAccessibleContext = new AccessibleJComponent() { + @Override public AccessibleRole getAccessibleRole() { return AccessibleRole.TOOL_BAR; } @@ -413,28 +358,7 @@ return toolbarAccessibleContext; } - /** Recognizes if XP theme is set. - * (copy & paste from org.openide.awt.Toolbar to avoid API changes) - * @return true if XP theme is set, false otherwise - */ - private static Boolean isXP = null; - private static boolean isXPTheme () { - if (isXP == null) { - Boolean xp = (Boolean)Toolkit.getDefaultToolkit(). - getDesktopProperty("win.xpstyle.themeActive"); //NOI18N - isXP = Boolean.TRUE.equals(xp)? Boolean.TRUE : Boolean.FALSE; - } - return isXP.booleanValue(); - } - /** - * @return True if the Toolbar Customizer is visible and toolbar buttons can be dragged. - */ - boolean isInEditMode() { - return null != getClientProperty( "editMode" ); - } - - /** * This class is used for delayed setting of configuration after instance * creation is finished. It may happen during IDE start that * ToolbarPool.setConfiguration is called before instance is created. @@ -473,6 +397,7 @@ * Full name of the data folder's primary file separated by dots. * @return the name */ + @Override public String instanceName () { return instanceClass().getName(); } @@ -481,6 +406,7 @@ * Returns the root class of all objects. * @return Object.class */ + @Override public Class instanceClass () { return ToolbarPool.class; } @@ -490,8 +416,10 @@ * @param cookie the instance cookie to test * @return true if the cookie can provide Configuration */ + @Override protected InstanceCookie acceptCookie (InstanceCookie cookie) throws java.io.IOException, ClassNotFoundException { + Class cls = cookie.instanceClass(); if (ToolbarPool.Configuration.class.isAssignableFrom (cls)) { return cookie; @@ -508,10 +436,11 @@ * @param df a DataFolder to create the cookie for * @return a Toolbar.Folder for the specified folder */ + @Override protected InstanceCookie acceptFolder (DataFolder df) { InstanceCookie ic = foldersCache.get (df); if (ic == null) { - ic = (FolderInstance)new Toolbar (df, true).waitFinished (); + ic = (FolderInstance) new Toolbar(df).waitFinished (); foldersCache.put (df, ic); } return ic; @@ -533,10 +462,10 @@ for (int i = 0; i < length; i++) { try { - java.lang.Object obj = cookies[i].instanceCreate(); + Object obj = cookies[i].instanceCreate(); - if (obj instanceof org.openide.awt.Toolbar) { - org.openide.awt.Toolbar toolbar = (org.openide.awt.Toolbar) obj; + if (obj instanceof Toolbar) { + Toolbar toolbar = (Toolbar) obj; // should be done by ToolbarPanel in add method toolbar.removeMouseListener(listener); @@ -545,8 +474,8 @@ toolbarNames.add(toolbar.getName()); continue; } - if (obj instanceof org.openide.awt.ToolbarPool.Configuration) { - org.openide.awt.ToolbarPool.Configuration config = (org.openide.awt.ToolbarPool.Configuration) obj; + if (obj instanceof ToolbarPool.Configuration) { + ToolbarPool.Configuration config = (ToolbarPool.Configuration) obj; java.lang.String name = config.getName(); if (name == null) { @@ -555,25 +484,22 @@ conf.put(name, config); continue; } - if (obj instanceof java.awt.Component) { - java.awt.Component comp = (java.awt.Component) obj; - java.lang.String name = comp.getName(); + if (obj instanceof Component) { + Component comp = (Component) obj; + String name = comp.getName(); if (name == null) { name = cookies[i].instanceName(); } - conf.put(name, - new org.openide.awt.ToolbarPool.ComponentConfiguration(comp)); + conf.put(name, new ToolbarPool.ComponentConfiguration(comp)); continue; } + } catch (IOException ex) { + Logger.getLogger(ToolbarPool.class.getName()).log(Level.INFO, "Error while creating toolbars.", ex); + } catch (ClassNotFoundException ex) { + Logger.getLogger(ToolbarPool.class.getName()).log(Level.INFO, "Error while creating toolbars.", ex); } - catch (java.io.IOException ex) { - Exceptions.printStackTrace(ex); } - catch (java.lang.ClassNotFoundException ex) { - Exceptions.printStackTrace(ex); - } - } update (toolbars, conf, toolbarNames); return ToolbarPool.this; @@ -581,6 +507,7 @@ /** Recreate the instance in AWT thread. */ + @Override protected Task postCreationTask (Runnable run) { return new AWTTask (run); } @@ -635,9 +562,11 @@ * component */ private static final class ComponentConfiguration extends JPopupMenu implements Configuration, ActionListener { + private Component comp; - ComponentConfiguration() {} + ComponentConfiguration() { + } static final long serialVersionUID =-409474484612485719L; /** @param comp component that represents this configuration */ @@ -652,6 +581,7 @@ /** @return name of the component */ + @Override public String getName () { return comp.getName (); } @@ -662,11 +592,9 @@ removeAll (); // generate list of available toolbar panels - Iterator it = Arrays.asList (ToolbarPool.getDefault ().getConfigurations ()).iterator (); ButtonGroup bg = new ButtonGroup (); String current = ToolbarPool.getDefault ().getConfiguration (); - while (it.hasNext()) { - final String name = (String)it.next (); + for( String name : ToolbarPool.getDefault().getConfigurations() ) { JRadioButtonMenuItem mi = new JRadioButtonMenuItem (name, (name.compareTo (current) == 0)); mi.addActionListener (this); bg.add (mi); @@ -681,8 +609,6 @@ public void actionPerformed (ActionEvent evt) { ToolbarPool.getDefault().setConfiguration (evt.getActionCommand ()); } - } - } // end of ToolbarPool