Example usage for javax.swing JMenuItem setToolTipText

List of usage examples for javax.swing JMenuItem setToolTipText

Introduction

In this page you can find the example usage for javax.swing JMenuItem setToolTipText.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.")
public void setToolTipText(String text) 

Source Link

Document

Registers the text to display in a tool tip.

Usage

From source file:org.gtdfree.GTDFree.java

/**
 * This method initializes jMenu   //ww  w. j a  v a 2 s .  com
 *    
 * @return javax.swing.JMenu   
 */
private JMenu getFileMenu() {
    if (fileMenu == null) {
        fileMenu = new JMenu();
        fileMenu.setText(Messages.getString("GTDFree.File")); //$NON-NLS-1$

        fileMenu.add(getSaveMenuItem());

        autoSaveMenuItem = new JCheckBoxMenuItem();
        autoSaveMenuItem.setText(Messages.getString("GTDFree.File.ASave")); //$NON-NLS-1$

        if (getEngine().getGTDModel().getDataRepository() instanceof GTDDataXML) {
            autoSaveMenuItem.setSelected(
                    getEngine().getGlobalProperties().getBoolean(GlobalProperties.AUTO_SAVE, true));
        } else {
            autoSaveMenuItem.setSelected(true);
            autoSaveMenuItem.setEnabled(false);
        }
        autoSaveMenuItem.setToolTipText(Messages.getString("GTDFree.File.ASave.desc")); //$NON-NLS-1$
        autoSaveMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                getEngine().setAutoSave(autoSaveMenuItem.isSelected());
                getEngine().getGlobalProperties().putProperty(GlobalProperties.AUTO_SAVE,
                        autoSaveMenuItem.isSelected());
            }
        });
        fileMenu.add(autoSaveMenuItem);

        /*fileMenu.add(new JSeparator());
                
        printCurrentMenuItem= new JMenuItem();
        printCurrentMenuItem.setText("Print current view...");
        printCurrentMenuItem.setEnabled(false);
        printCurrentMenuItem.addActionListener(new ActionListener() {
                
           @Override
           public void actionPerformed(ActionEvent e) {
              WorkflowPane p= getEngine().getActiveWorkflowPane();
              if (p!=null) {
          try {
             p.printTable();
          } catch (PrinterException e1) {
             e1.printStackTrace();
             JOptionPane.showMessageDialog(getJFrame(), "Printing failed, error: "+e1.toString(), "Printing failed", JOptionPane.ERROR_MESSAGE);
          }
              }
           }
        });
                
        getEngine().addPropertyChangeListener("activePane", new PropertyChangeListener() {
                
           @Override
           public void propertyChange(PropertyChangeEvent evt) {
              printCurrentMenuItem.setEnabled(getEngine().getActiveWorkflowPane()!=null);
           }
        });
                
        fileMenu.add(printCurrentMenuItem);*/

        fileMenu.add(new JSeparator());

        JMenuItem jmi = new JMenuItem(Messages.getString("GTDFree.File.Print")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_print));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                getPrintDialog().setVisible(true);
            }
        });
        fileMenu.add(jmi);

        fileMenu.add(new JSeparator());

        jmi = new JMenuItem(Messages.getString("GTDFree.File.Import")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_import));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                importFile();
            }
        });
        fileMenu.add(jmi);

        jmi = new JMenuItem(Messages.getString("GTDFree.File.Export")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_export));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                getExportDialog().setVisible(true);
            }
        });
        fileMenu.add(jmi);

        jmi = new JMenuItem(Messages.getString("GTDFree.File.All")); //$NON-NLS-1$
        jmi.setToolTipText(Messages.getString("GTDFree.File.All.desc")); //$NON-NLS-1$
        jmi.setIcon(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_export));
        jmi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                exportFile();
            }
        });
        fileMenu.add(jmi);

        fileMenu.add(new JSeparator());
        fileMenu.add(getExitMenuItem());
    }
    return fileMenu;
}

From source file:org.nuclos.client.ui.collect.CollectController.java

/**
 * alternative entry point: lookup a <code>Collectable</code> (in a foreign entity).
 *//*from  w w w . j  a  va 2 s  .co m*/
public void runLookupCollectable(final ICollectableListOfValues clctlovSource) throws CommonBusinessException {

    // show the internal frame in the front of the modal layer:
    final MainFrameTab ifrm = this.getTab();

    ifrm.setVisible(true);

    if (!clctlovSource.isSearchComponent()) {
        String label = getSpringLocaleDelegate().getMessage("CollectController.41", "Auswahl bernehmen");
        String description = getSpringLocaleDelegate().getMessage("CollectController.42",
                "Findet die bernahme in einem Unterformular statt werden mittels Mehrfachauswahl zustzliche Datenstze im Unterformular erzeugt.");
        if (clctlovSource instanceof CollectableListOfValues) {
            final CollectableListOfValues clov = (CollectableListOfValues) clctlovSource;
            if (clov.getValueListProvider() instanceof DatasourceBasedCollectableFieldsProvider) {
                ss.setValueListProviderDatasource(
                        ((DatasourceBasedCollectableFieldsProvider) clov.getValueListProvider())
                                .getDatasourceVO());
                ss.setValueListProviderDatasourceParameter(
                        ((DatasourceBasedCollectableFieldsProvider) clov.getValueListProvider())
                                .getValueListParameter());
            } else if (clov
                    .getValueListProvider() instanceof CollectableFieldsProviderCache.CachingCollectableFieldsProvider) {
                CollectableFieldsProvider delegate = ((CollectableFieldsProviderCache.CachingCollectableFieldsProvider) clov
                        .getValueListProvider()).getDelegate();
                if (delegate instanceof DatasourceBasedCollectableFieldsProvider) {
                    ss.setValueListProviderDatasource(
                            ((DatasourceBasedCollectableFieldsProvider) delegate).getDatasourceVO());
                    ss.setValueListProviderDatasourceParameter(
                            ((DatasourceBasedCollectableFieldsProvider) delegate).getValueListParameter());
                }
            }
        } else if (clctlovSource instanceof EntityListOfValues) {
            label = getSpringLocaleDelegate().getMessage("CollectController.lookup.generation",
                    "Objekte ausw\u00e4hlen");
            description = getSpringLocaleDelegate().getMessage(
                    "CollectController.lookup.generation.description",
                    "Parameterobjekte fr die Objektgenerierung ausw\u00e4hlen.");
        }
        final JMenuItem miPopupApplySelection = new JMenuItem(label);
        miPopupApplySelection.setToolTipText(description);

        getResultPanel().popupmenuRow.removeAll();//.addSeparator();
        getResultPanel().popupmenuRow.add(miPopupApplySelection);
        miPopupApplySelection.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                acceptLookedUpCollectable(clctlovSource);
                getTab().dispose();
            }
        });
    }

    // remove mouse listener for double click in table:
    getResultPanel().removeDoubleClickMouseListener(this.getMouseListenerForTableDoubleClick());

    // add alternative mouse listener for foreign key lookup:
    foreignKeyMouseListenerForTableDoubleClick = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent ev) {
            if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) {
                int iRow = getResultTable().rowAtPoint(ev.getPoint());
                if (iRow >= 0 && iRow < getResultTable().getRowCount()) {
                    getResultTable().getSelectionModel().setSelectionInterval(iRow, iRow);
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            acceptLookedUpCollectable(clctlovSource);
                            getTab().dispose();
                        }
                    });
                }
            }
        }
    };

    getResultPanel().addDoubleClickMouseListener(foreignKeyMouseListenerForTableDoubleClick);
    // @see NUCLOS-432
    //getResultTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    getResultTable().getActionMap().put(KeyBindingProvider.EDIT_2.getKey(), new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            acceptLookedUpCollectable(clctlovSource);
            getTab().dispose();
        }
    });

    if (this.isSearchPanelAvailable()) {
        if (ss.getValueListProviderDatasource() != null) {
            this.runViewAll();
        } else {
            this.runSearch();
        }
    } else {
        this.runViewAll();
    }

    final Boolean modalLookup = (Boolean) clctlovSource
            .getProperty(ICollectableListOfValues.PROPERTY_MODAL_LOOKUP);
    if (Boolean.TRUE.equals(modalLookup)) {
        JDialog d = new JDialog(Main.getInstance().getMainFrame(), ifrm.getTitle(), true);
        FrameUtils.externalizeIntoWindow(ifrm, d);
        d.pack();
        d.setVisible(true);
    }
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * @return/*w  ww .  j  a v  a2s.c om*/
 * @precondition hasComparisonOperator()
 */
public JPopupMenu newComparisonOperatorPopupMenu() {
    if (!hasComparisonOperator()) {
        throw new IllegalStateException();
    }
    final JPopupMenu result = new JPopupMenu(
            getSpringLocaleDelegate().getMessage("AbstractCollectableComponent.16", "Vergleichsoperator"));

    // 1. comparison operators:
    final ButtonGroup btngrpComparisonOperators = new ButtonGroup();

    final ItemListener itemlistener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                final String sOperatorName = ((AbstractButton) ev.getItem()).getActionCommand();
                setComparisonOperator(ComparisonOperator.getInstance(sOperatorName));
                runLocked(new Runnable() {
                    @Override
                    public void run() {
                        updateSearchConditionInModel();
                    }
                });
            }
        }
    };

    ComparisonOperator[] supportedComparisonOperators = getSupportedComparisonOperators();
    if (supportedComparisonOperators == null)
        return null;

    for (ComparisonOperator compop : supportedComparisonOperators) {
        JMenuItem mi = new JRadioButtonMenuItem(
                getSpringLocaleDelegate().getMessage(compop.getResourceIdForLabel(), null));
        mi.setActionCommand(compop.name());
        mi.setToolTipText(getSpringLocaleDelegate().getMessage(compop.getResourceIdForDescription(), null));
        result.add(mi);
        btngrpComparisonOperators.add(mi);
        mi.addItemListener(itemlistener);
    }

    result.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            for (int i = 0, n = result.getComponentCount(); i < n; i++) {
                Component c = result.getComponent(i);
                if (c instanceof JMenuItem && StringUtils.emptyIfNull(((JMenuItem) c).getActionCommand())
                        .equals(getComparisonOperator().name()))
                    ((JMenuItem) c).setSelected(true);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent ev) {
        }
    });

    // 2. right operand (value or other field):
    if (canDisplayComparisonWithOtherField()) {
        addRightOperandToPopupMenu(result, this);
    }

    return result;
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.ImporterAgent.java

/** Registers the agent with the tool bar.*/
private void register() {
    String description = "Open the Importer.";
    TaskBar tb = registry.getTaskBar();/*from  ww w.  j a va2  s  .  co m*/
    IconManager icons = IconManager.getInstance();
    JButton b = new JButton(icons.getIcon(IconManager.IMPORT));
    b.setToolTipText(description);
    ActionListener l = new ActionListener() {

        /** Posts an event to start the agent.*/
        public void actionPerformed(ActionEvent e) {
            EventBus bus = registry.getEventBus();
            ExperimenterData exp = (ExperimenterData) registry.lookup(LookupNames.CURRENT_USER_DETAILS);
            if (exp == null)
                return;
            GroupData gp = null;
            try {
                gp = exp.getDefaultGroup();
            } catch (Exception ex) {
                //No default group
            }
            long id = -1;
            if (gp != null)
                id = gp.getId();
            if (groupId == -1)
                groupId = id;
            LoadImporter event = new LoadImporter(null, browserType);
            event.setGroup(groupId);
            event.setObjects(objects);
            bus.post(event);
        }
    };
    b.addActionListener(l);
    tb.addToToolBar(TaskBar.AGENTS, b);
    JMenuItem item = new JMenuItem(icons.getIcon(IconManager.IMPORT));
    item.setText("Import...");
    item.setToolTipText(description);
    item.addActionListener(l);
    tb.addToMenu(TaskBar.FILE_MENU, item);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java

/**
 * Creates the selection menu.//  w  w  w. j  a va  2 s  .com
 * 
 * @return See above.
 */
private JPopupMenu createDocSelectionMenu() {
    if (docSelectionMenu != null)
        return docSelectionMenu;
    docSelectionMenu = new JPopupMenu();
    JMenuItem item = new JMenuItem("Local document...");
    item.setToolTipText("Import a local document to the server " + "and attach it.");
    item.addActionListener(controller);
    item.setActionCommand("" + EditorControl.ADD_LOCAL_DOCS);
    docSelectionMenu.add(item);
    item = new JMenuItem("Uploaded document...");
    item.setToolTipText("Attach a document already uploaded " + "to the server.");
    item.addActionListener(controller);
    item.setActionCommand("" + EditorControl.ADD_UPLOADED_DOCS);
    docSelectionMenu.add(item);
    return docSelectionMenu;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Creates or recycles the menu.//from  ww  w .jav a 2  s  . c  o m
 * 
 * @param invoker The component invoking the menu.
 * @param loc The location of the mouse clicked.
 */
private void showViewMenu(JComponent invoker, Point loc) {
    if (viewMenu == null) {
        viewMenu = new JPopupMenu();
        IconManager icons = IconManager.getInstance();
        JMenuItem button = new JMenuItem(icons.getIcon(IconManager.VIEW));
        button.setText(ViewAction.NAME);
        button.setToolTipText(ViewAction.DESCRIPTION);
        button.setActionCommand("" + EditorControl.VIEW_IMAGE);
        button.addActionListener(controller);
        viewMenu.add(button);
        button = new JMenuItem(icons.getIcon(IconManager.VIEWER_IJ));
        button.setText(ViewAction.NAME_IJ);
        button.setToolTipText(ViewAction.DESCRIPTION_IJ);
        button.setActionCommand("" + EditorControl.VIEW_IMAGE_IN_IJ);
        button.addActionListener(controller);
        viewMenu.add(button);
    }
    viewMenu.show(invoker, loc.x, loc.y);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java

/** 
 * Builds the menu displaying the available scripts.
 * /*from  ww  w.  j av a 2 s .c o  m*/
 * @return See above.
 */
private JPopupMenu getScriptsMenu() {
    JPopupMenu menu = new JPopupMenu();

    Collection<ScriptObject> scripts = model.getScripts();
    //Scripts are sorted.
    if (scripts == null || scripts.size() == 0)
        return menu;
    IconManager icons = IconManager.getInstance();
    JMenuItem refresh = new JMenuItem(icons.getIcon(IconManager.REFRESH));
    refresh.setText("Reload Scripts");
    refresh.setToolTipText("Reloads the existing scripts.");
    refresh.addActionListener(controller);
    refresh.setActionCommand("" + EditorControl.RELOAD_SCRIPT);
    menu.add(refresh);
    menu.add(new JSeparator());

    Iterator<ScriptObject> i = scripts.iterator();
    ScriptObject so;
    Map<String, ScriptSubMenu> menus = new HashMap<String, ScriptSubMenu>();
    String path;
    ScriptSubMenu subMenu;
    List<ScriptSubMenu> others = new ArrayList<ScriptSubMenu>();
    List<String> formattedName = new ArrayList<String>();
    while (i.hasNext()) {
        so = i.next();
        setScriptIcon(so);
        path = so.getPath();
        subMenu = menus.get(path);
        if (subMenu == null) {
            subMenu = new ScriptSubMenu(path, formattedName);
            //formattedName.add(subMenu.getUnformattedText());
            menus.put(path, subMenu);
            if (so.isOfficialScript())
                menu.add(subMenu);
            else
                others.add(subMenu);
        }
        //if (!ScriptMenuItem.isScriptWithUI(so.getScriptLabel()))
        subMenu.addScript(so).addActionListener(controller);
    }
    if (others.size() > 0) {
        menu.add(new JSeparator());
        JMenu uploadedMenu = new JMenu("User Scripts");
        menu.add(uploadedMenu);
        Iterator<ScriptSubMenu> j = others.iterator();
        while (j.hasNext())
            uploadedMenu.add(j.next());
    }
    return menu;
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Brings up the <code>Available Scripts</code> on top of the specified
 * component at the specified location./*from  w w w.  j  a  v a2  s .  c o  m*/
 * 
 * @param c The component that requested the pop-pup menu.
 * @param p The point at which to display the menu, relative to the
 *          <code>component</code>'s coordinates.
 */
void showAvailableScriptsMenu(Component c, Point p) {
    if (p == null)
        return;
    if (c == null) {
        c = scriptButton;
    }
    IconManager icons = IconManager.getInstance();
    Collection<ScriptObject> scripts = model.getAvailableScripts();
    if (CollectionUtils.isEmpty(scripts))
        return;
    if (scriptsMenu == null) {
        scriptsMenu = new JPopupMenu();
        JMenuItem refresh = new JMenuItem(icons.getIcon(IconManager.REFRESH));
        refresh.setText("Reload Scripts");
        refresh.setToolTipText("Reloads the existing scripts.");
        refresh.addMouseListener(new MouseAdapter() {

            /**
             * Launches the dialog when the user releases the mouse.
             * MouseAdapter#mouseReleased(MouseEvent)
             */
            public void mouseReleased(MouseEvent e) {
                model.setAvailableScripts(null);
                scriptsMenu = null;
                controller.reloadAvailableScripts(e.getPoint());
            }
        });
        scriptsMenu.add(refresh);
        scriptsMenu.add(new JSeparator());

        ScriptObject so;
        Map<String, JMenu> menus = new HashMap<String, JMenu>();
        String path;

        Icon icon = icons.getIcon(IconManager.ANALYSIS);
        Icon largeIcon = icons.getIcon(IconManager.ANALYSIS_48);
        ActionListener listener = new ActionListener() {

            /** 
             * Listens to the selection of a script.
             * @see ActionListener#actionPerformed(ActionEvent)
             */
            public void actionPerformed(ActionEvent e) {
                ScriptMenuItem item = (ScriptMenuItem) e.getSource();
                controller.handleScriptSelection(item.getScript());
            }
        };
        String name = "";
        //loop twice to check if we need to add the first element
        String refString = null;
        int count = 0;
        Iterator<ScriptObject> i = scripts.iterator();
        String sep;
        String[] values;
        String value;
        while (i.hasNext()) {
            so = i.next();
            value = "";
            path = so.getPath();
            if (path != null) {
                sep = FilenameUtils.getPrefix(path);
                if (path.startsWith(sep))
                    path = path.substring(1, path.length());
                values = UIUtilities.splitString(path);
                if (values != null && values.length > 0)
                    value = values[0];
            }

            if (refString == null) {
                refString = value;
                count++;
            } else if (refString.equals(value))
                count++;
        }
        int index = 0;
        if (scripts.size() == count)
            index++;
        i = scripts.iterator();
        List<JMenuItem> topMenus = new ArrayList<JMenuItem>();
        JMenu ref = null;
        while (i.hasNext()) {
            so = i.next();
            path = so.getPath();
            if (path != null) {
                sep = FilenameUtils.getPrefix(path);
                if (path.startsWith(sep))
                    path = path.substring(1, path.length());
                values = UIUtilities.splitString(path);
                if (values != null) {
                    for (int j = index; j < values.length; j++) {
                        value = values[j];
                        JMenu v;
                        String text = name + value;
                        if (menus.containsKey(text)) {
                            v = menus.get(text);
                        } else {
                            value = value.replace(ScriptObject.PARAMETER_SEPARATOR,
                                    ScriptObject.PARAMETER_UI_SEPARATOR);
                            v = new JMenu(value);
                        }
                        if (ref == null)
                            topMenus.add(v);
                        else
                            ref.add(v);
                        ref = v;
                        name += values[j];
                        menus.put(name, v);
                    }
                }
            }
            ScriptMenuItem item = new ScriptMenuItem(so);
            item.addActionListener(listener);
            if (ref != null)
                ref.add(item);
            else
                topMenus.add(item);
            name = "";
            ref = null;
            if (so.getIcon() == null) {
                so.setIcon(icon);
                so.setIconLarge(largeIcon);
            }
        }
        Iterator<JMenuItem> j = topMenus.iterator();
        while (j.hasNext()) {
            scriptsMenu.add(j.next());
        }
    }
    scriptsMenu.show(c, p.x, p.y);
}

From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java

/**
 * Makes and returns a copy of the specified item.
 *
 * @param original The item to handle./*from   w  ww. ja  va2s. c  o  m*/
 * @return See above.
 */
private JMenuItem copyItem(JMenuItem original) {
    JMenuItem item = new JMenuItem(original.getAction());
    item.setIcon(original.getIcon());
    item.setText(original.getText());
    item.setToolTipText(original.getToolTipText());
    ActionListener[] al = original.getActionListeners();
    for (int j = 0; j < al.length; j++)
        item.addActionListener(al[j]);
    return item;
}

From source file:org.orbisgis.mapeditor.map.mapsManager.TreeLeafMapContextFile.java

@Override
public void feedPopupMenu(JPopupMenu menu) {
    super.feedPopupMenu(menu);
    if (!isLoaded()) {
        JMenuItem folderRemove = new JMenuItem(I18N.tr("Delete"), MapEditorIcons.getIcon("remove"));
        folderRemove.setToolTipText(I18N.tr("Remove permanently the map"));
        folderRemove.setActionCommand("delete");
        folderRemove.addActionListener(EventHandler.create(ActionListener.class, this, "onDeleteFile"));
        MenuCommonFunctions.updateOrInsertMenuItem(menu, folderRemove);
    }/*from www  .j a  va 2  s.c om*/
}