|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.url; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; import javax.swing.ImageIcon; import javax.swing.JMenu; import javax.swing.JMenuItem; import org.openide.awt.*; import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.WeakListeners; import org.openide.util.actions.Presenter; import org.openide.util.actions.SystemAction; import org.netbeans.modules.url.URLDataObject; import org.openide.ErrorManager; import org.openide.filesystems.Repository; /** The action that create popup menu with urls to IDE resources. * Only purpose of this dummy action is to present Places/Resources folder in toolbar/menu. * * @author Gabriel Tichy */ public class ResourcesAction extends SystemAction implements Presenter.Toolbar, Presenter.Menu { static final long serialVersionUID = 2183102479251760124L; /** Toolbar button for toolbar presenter. Icon will be action's icon. */ ToolbarButton toolbarButton; /** Popup menu (for toolbar) with resources bookmarks. */ private JPopupMenuPlus popupMenu; /** Action icon. */ private static javax.swing.ImageIcon icon; /** Gets help context for this action. Implements superclass abstract method. * @return the help context for this action */ public HelpCtx getHelpCtx () { return new HelpCtx (ResourcesAction.class); } /** Gets name of action. Implements superclass abstract method. * @return the name of the action */ public String getName () { return NbBundle.getMessage (ResourcesAction.class, "ACT_IDEResources"); // NOI18N } /** Specifies icon resource name. Overrides superclass method. * @return name of resource for icon */ protected String iconResource () { return "org/netbeans/modules/url/webLink.gif"; // NOI18N } /** Gets presenter for menu. Overrides superclass method. */ public JMenuItem getMenuPresenter () { JMenuItem menu = new LazyMenu ( findSessionFolder ("Resources"), // NOI18N NbBundle.getBundle (ResourcesAction.class).getString ("Resources") // NOI18N ); return menu; } /** Returns a Component that presents the Action, that implements this * interface, in a ToolBar. * @return the Component representation for the Action */ public java.awt.Component getToolbarPresenter () { if (toolbarButton != null) return toolbarButton; synchronized (ResourcesAction.class) { if (toolbarButton != null) return toolbarButton; toolbarButton = new ToolbarButton ( new ImageIcon (getClass ().getResource ("/org/netbeans/modules/url/resourcesButton.gif"))); // NOI18N toolbarButton.setToolTipText (Actions.cutAmpersand (getName ())); toolbarButton.addActionListener (new ActionListener() { public void actionPerformed (ActionEvent evt) { showPopupMenu (); } }); return toolbarButton; } } private void showPopupMenu () { java.awt.Point p = toolbarButton.getLocation (); p.y += toolbarButton.getHeight (); if (popupMenu == null) popupMenu = new LazyPopup (findSessionFolder ("Resources")); // NOI18N popupMenu.show (toolbarButton.getParent (), p.x, p.y); } public void actionPerformed (java.awt.event.ActionEvent actionEvent) { } /** Menu item which will create its items lazilly when the popup will becomming visible. * Performance savings.*/ private static class LazyMenu extends JInlineMenu implements PopupMenuListener { /** Bookmarks node on which menu to create. */ private DataFolder folder; /** Sub menu. */ private final JMenu menu; /** Indicates whether menu items were uptodate. */ private boolean uptodate = false; /** Listener on changes in folder (children/order). */ private PropertyChangeListener propertyListener; /** Constructor. */ public LazyMenu (DataFolder folder, String name) { this.folder = folder; this.menu = new JMenuPlus (); Actions.setMenuText (menu, name, true); if (icon == null) icon = new ImageIcon (ResourcesAction.class.getResource (((ResourcesAction)SystemAction.get (ResourcesAction.class)).iconResource ())); menu.setIcon (icon); menu.getPopupMenu ().addPopupMenuListener (this); setMenuItems (new JMenuItem[] {menu}); this.folder.addPropertyChangeListener (WeakListeners.propertyChange (propertyListener = new PropertyChangeListener () { public void propertyChange (PropertyChangeEvent evt) { if (DataFolder.PROP_CHILDREN.equals (evt.getPropertyName ()) || DataFolder.PROP_ORDER.equals(evt.getPropertyName())) { uptodate = false; } } }, this.folder)); } /** Dummy implementation of |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.