List of usage examples for javax.swing.event PopupMenuListener PopupMenuListener
PopupMenuListener
From source file:org.languagetool.gui.LanguageToolSupport.java
private void showPopup(MouseEvent event) { if (documentSpans.isEmpty() && languageTool.getDisabledRules().isEmpty()) { //No errors and no disabled Rules return;//ww w .j av a 2 s . c om } int offset = this.textComponent.viewToModel(event.getPoint()); Span span = getSpan(offset); JPopupMenu popup = new JPopupMenu("Grammar Menu"); if (span != null) { JLabel msgItem = new JLabel("<html>" + span.msg.replace("<suggestion>", "<b>").replace("</suggestion>", "</b>") + "</html>"); msgItem.setToolTipText(span.desc.replace("<suggestion>", "").replace("</suggestion>", "")); msgItem.setBorder(new JMenuItem().getBorder()); popup.add(msgItem); popup.add(new JSeparator()); for (String r : span.replacement) { ReplaceMenuItem item = new ReplaceMenuItem(r, span); popup.add(item); item.addActionListener(actionListener); } popup.add(new JSeparator()); JMenuItem moreItem = new JMenuItem(messages.getString("guiMore")); moreItem.addActionListener(e -> showDialog(textComponent, span.msg, span.desc, span.rule, span.url)); popup.add(moreItem); JMenuItem ignoreItem = new JMenuItem(messages.getString("guiTurnOffRule")); ignoreItem.addActionListener(e -> disableRule(span.rule.getId())); popup.add(ignoreItem); popup.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); } List<Rule> disabledRules = getDisabledRules(); if (!disabledRules.isEmpty()) { JMenu activateRuleMenu = new JMenu(messages.getString("guiActivateRule")); addDisabledRulesToMenu(disabledRules, activateRuleMenu); popup.add(activateRuleMenu); } if (span != null) { textComponent.setCaretPosition(span.start); textComponent.moveCaretPosition(span.end); } popup.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } @Override public void popupMenuCanceled(PopupMenuEvent e) { if (span != null) { textComponent.setCaretPosition(span.start); } } }); popup.show(textComponent, event.getPoint().x, event.getPoint().y); }
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
protected void setupResultContextMenuStates() { this.getResultPanel().popupmenuRow.addPopupMenuListener(new PopupMenuListener() { @Override//from w w w . ja v a 2 s .c o m public void popupMenuWillBecomeVisible(PopupMenuEvent e) { UIUtils.runCommand(getTab(), new Runnable() { @Override public void run() { try { final List<StateVO> lstSubsequenteStates = getSubsequentStates( getSelectedCollectables()); JMenu mi = getResultPanel().miStates; mi.setVisible(lstSubsequenteStates.size() != 0); // try to find single soruce state... StateVO statevoSource = getSingleSourceStateIfAny(getSelectedCollectables()); for (final StateVO statevoTarget : lstSubsequenteStates) { final JMenuItem miStateChange = new JMenuItem( new StateChangeAction(statevoSource, statevoTarget)); miStateChange.setIcon(null); mi.add(miStateChange); } } catch (Exception e1) { getResultPanel().miStates.setVisible(false); LOG.warn("popupMenuWillBecomeVisible failed: " + e1 + ", setting it invisible"); } } }); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { clearStatesMenu(); } @Override public void popupMenuCanceled(PopupMenuEvent e) { clearStatesMenu(); } private void clearStatesMenu() { getResultPanel().miStates.removeAll(); } }); }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
/** * @return//w ww .jav a2s. co m * @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.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
/** * @param result//from w ww . ja v a 2s .co m * @param clctcomp */ private static void addRightOperandToPopupMenu(JPopupMenu result, final AbstractCollectableComponent clctcomp) { result.addSeparator(); final ButtonGroup btngrpCompareWith = new ButtonGroup(); final SpringLocaleDelegate localeDelegate = SpringLocaleDelegate.getInstance(); final JRadioButtonMenuItem miValue = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.17", "Wertvergleich")); miValue.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.10", "Dieses Feld mit einem festen Wert vergleichen")); result.add(miValue); btngrpCompareWith.add(miValue); miValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { clctcomp.resetWithComparison(); clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } }); final JRadioButtonMenuItem miOtherField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.12", "Feldvergleich...")); miOtherField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.9", "Dieses Feld mit dem Inhalt eines anderen Felds vergleichen")); result.add(miOtherField); btngrpCompareWith.add(miOtherField); miOtherField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { assert clctcomp.clcte != null; // select entity field with the same data type: final List<CollectableEntityField> lstclctefFiltered = CollectionUtils.select( CollectableUtils.getCollectableEntityFields(clctcomp.clcte), new Predicate<CollectableEntityField>() { @Override public boolean evaluate(CollectableEntityField clctef) { return clctef.getJavaClass() == clctcomp.clctef.getJavaClass(); } }); // and sort by label: final List<CollectableEntityField> lstclctefSorted = CollectionUtils.sorted(lstclctefFiltered, new CollectableEntityField.LabelComparator()); final JComboBox cmbbx = new JComboBox(lstclctefSorted.toArray()); cmbbx.setSelectedItem(clctcomp.getComparisonOtherField()); final int iBtn = JOptionPane .showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.6", "Anderes Feld: "), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.15", "Vergleich mit anderem Feld"), JOptionPane.OK_CANCEL_OPTION); if (iBtn == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((CollectableEntityField) cmbbx.getSelectedItem()); if (clctcomp.getComparisonOtherField() != null) { // clear the view: clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { // If the user selects "other field" and forgot to set the operator, we assume "EQUAL": clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); final List<ComparisonParameter> compatibleParameters = ComparisonParameter .getCompatibleParameters(clctcomp.getEntityField()); final JRadioButtonMenuItem miParameterField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.18", null)); miParameterField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.19", null)); btngrpCompareWith.add(miParameterField); if (compatibleParameters.size() > 0) { result.add(miParameterField); miParameterField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { ResourceIdMapper<ComparisonParameter> mapper = new ResourceIdMapper<ComparisonParameter>( compatibleParameters); JComboBox cmbbx = new JComboBox(CollectionUtils.sorted(compatibleParameters, mapper).toArray()); cmbbx.setRenderer(new DefaultListRenderer(mapper)); cmbbx.setSelectedItem(clctcomp.getComparisonParameter()); final int opt = JOptionPane.showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.20", null), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.19", null), JOptionPane.OK_CANCEL_OPTION); if (opt == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((ComparisonParameter) cmbbx.getSelectedItem()); if (clctcomp.getComparisonParameter() != null) { clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); } result.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent ev) { if (clctcomp.getComparisonParameter() != null) { miParameterField.setSelected(true); } else if (clctcomp.getComparisonOtherField() == null || clctcomp.getComparisonOperator().getOperandCount() < 2) { miValue.setSelected(true); } else { miOtherField.setSelected(true); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) { } @Override public void popupMenuCanceled(PopupMenuEvent ev) { } }); }
From source file:org.omegat.gui.scripting.ScriptingWindow.java
private void setupRunButtons(JPanel panel) { m_btnRunScript = new JButton(); Mnemonics.setLocalizedText(m_btnRunScript, OStrings.getString("SCW_RUN_SCRIPT")); m_btnRunScript.setAlignmentX(Component.LEFT_ALIGNMENT); m_btnRunScript.setHorizontalAlignment(SwingConstants.LEFT); m_btnRunScript.addActionListener(new ActionListener() { @Override//from w ww . jav a 2s.c o m public void actionPerformed(ActionEvent a) { runScript(); } }); panel.add(m_btnRunScript); m_btnCancelScript = new JButton(); Mnemonics.setLocalizedText(m_btnCancelScript, OStrings.getString("SCW_CANCEL_SCRIPT")); m_btnCancelScript.setToolTipText(OStrings.getString("SCW_CANCEL_BUTTON_TOOLTIP")); m_btnCancelScript.setAlignmentX(Component.LEFT_ALIGNMENT); m_btnCancelScript.setHorizontalAlignment(SwingConstants.LEFT); m_btnCancelScript.addActionListener(e -> cancelCurrentScript()); panel.add(m_btnCancelScript); for (int i = 0; i < NUMBERS_OF_QUICK_SCRIPTS; i++) { final int index = i; final int scriptKey = scriptKey(index); m_quickScriptButtons[i] = new JButton(String.valueOf(scriptKey)); // Run a script from the quick button bar m_quickScriptButtons[i].addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent a) { if (Preferences.existsPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey)) { runQuickScript(index); } else { logResult(StringUtil.format(OStrings.getString("SCW_NO_SCRIPT_BOUND"), scriptKey)); } } }); JPopupMenu quickScriptPopup = new JPopupMenu(); // Add a script to the quick script button bar final JMenuItem addQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_ADD_SCRIPT")); addQuickScriptMenuItem.addActionListener(new QuickScriptUpdater(index)); quickScriptPopup.add(addQuickScriptMenuItem); // Remove a script from the button bar final JMenuItem removeQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_REMOVE_SCRIPT")); removeQuickScriptMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String scriptName = Preferences .getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, "(unknown)"); logResult(StringUtil.format(OStrings.getString("SCW_REMOVED_QUICK_SCRIPT"), scriptName, scriptKey)); Preferences.setPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, ""); m_quickScriptButtons[index].setToolTipText(OStrings.getString("SCW_NO_SCRIPT_SET")); m_quickScriptButtons[index].setText(" " + scriptKey + " "); unsetQuickScriptMenu(index); } }); quickScriptPopup.add(removeQuickScriptMenuItem); quickScriptPopup.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { // Disable add a script command if script selection empty addQuickScriptMenuItem.setEnabled(!m_scriptList.isSelectionEmpty()); // Disable remove a script command if the quick run button is not bounded String scriptName = Preferences .getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, null); removeQuickScriptMenuItem.setEnabled(!StringUtil.isEmpty(scriptName)); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // do nothing } @Override public void popupMenuCanceled(PopupMenuEvent e) { // do nothing } }); m_quickScriptButtons[i].setComponentPopupMenu(quickScriptPopup); panel.add(m_quickScriptButtons[i]); } }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;//from w w w.jav a 2s . com } if (columnGroupCount != 0) { panelBox.add(Box.createHorizontalStrut(7)); } final int tableIndex = columnGroupCount; final DataTableModel tableModel = new DataTableModel(); final JTable table = new JTable(tableModel); table.setDragEnabled(true); table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount)); if (showThresholdCheckBoxGroup.isSelected()) { tableModel.setThresholdVisible(true); } if (showMinMaxCheckBoxGroup.isSelected()) { tableModel.setMaxMinVisible(true); table.getColumn("Min").setCellRenderer(doubleCellRenderer); table.getColumn("Max").setCellRenderer(doubleCellRenderer); } table.getColumn("Value").setCellRenderer(dataCellRenderer); tables.add(table); tableModels.add(tableModel); JScrollPane tableScrollPane = new JScrollPane(table); panelBox.add(tableScrollPane); // popup menu for panel JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TransferHandler.getCopyAction().actionPerformed( new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers())); } }); popupMenu.add(copyMenuItem); popupMenu.addSeparator(); JMenuItem printMenuItem = new JMenuItem("Print..."); printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException pe) { } } }); popupMenu.add(printMenuItem); popupMenu.addSeparator(); final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false); showMaxMinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setMaxMinVisible(showMaxMinMenuItem.isSelected()); } }); showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem); popupMenu.add(showMaxMinMenuItem); final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false); showThresholdMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setThresholdVisible(showThresholdMenuItem.isSelected()); } }); showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem); popupMenu.add(showThresholdMenuItem); popupMenu.addSeparator(); JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row"); blankRowMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tableModel.addBlankRow(); } }); popupMenu.add(blankRowMenuItem); final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows"); removeSelectedRowsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeSelectedRows(tableIndex); } }); popupMenu.add(removeSelectedRowsMenuItem); popupMenu.addSeparator(); JMenu numberOfColumnsMenu = new JMenu("Number of columns"); numberOfColumnsMenu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent me) { JMenu menu = (JMenu) me.getSource(); for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) { JMenuItem menuItem = menu.getItem(j); boolean selected = (j == (columnGroupCount - 1)); menuItem.setSelected(selected); } } public void menuDeselected(MenuEvent me) { } public void menuCanceled(MenuEvent me) { } }); for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) { final int number = i + 1; JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setNumberOfColumns(number); } }); numberOfColumnsMenu.add(item); } popupMenu.add(numberOfColumnsMenu); popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean anyRowsSelected = table.getSelectedRowCount() > 0; copyMenuItem.setEnabled(anyRowsSelected); removeSelectedRowsMenuItem.setEnabled(anyRowsSelected); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it table.setComponentPopupMenu(popupMenu); tableScrollPane.setComponentPopupMenu(popupMenu); panelBox.revalidate(); columnGroupCount++; properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount)); }
From source file:org.rdv.viz.image.ImageViz.java
private void initPopupMenu() { final JPopupMenu popupMenu = new JPopupMenu(); // create a popup to copy an image to the clipboard final JMenuItem copyImageMenuItem = new JMenuItem("Copy"); copyImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { copyImage();//from w w w .j a v a 2 s.co m } }); popupMenu.add(copyImageMenuItem); popupMenu.addSeparator(); // create a popup to save an image final JMenuItem saveImageMenuItem = new JMenuItem("Save as..."); saveImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { saveImage(); } }); popupMenu.add(saveImageMenuItem); popupMenu.addSeparator(); // create a popup to copy an image to the clipboard final JMenuItem printImageMenuItem = new JMenuItem("Print..."); printImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { printImage(); } }); popupMenu.add(printImageMenuItem); popupMenu.addSeparator(); final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in"); zoomInMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { imagePanel.zoomIn(); } }); popupMenu.add(zoomInMenuItem); final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out"); zoomOutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { imagePanel.zoomOut(); } }); popupMenu.add(zoomOutMenuItem); final JSeparator zoomMenuSeparator = new JPopupMenu.Separator(); popupMenu.add(zoomMenuSeparator); autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", true); autoScaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setAutoScale(autoScaleMenuItem.isSelected()); } }); popupMenu.add(autoScaleMenuItem); final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale"); resetScaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { imagePanel.setScale(1); } }); popupMenu.add(resetScaleMenuItem); showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image", imagePanel.isNavigationImageEnabled()); showNavigationImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setShowNavigationImage(showNavigationImageMenuItem.isSelected()); } }); popupMenu.add(showNavigationImageMenuItem); final JMenu maximumFilmstripImagesMenu = new JMenu("Maximum number of images"); maximumFilmstripImagesButtonGroup = new ButtonGroup(); for (final int maximumFilmstripImagesValue : MAXIMUM_FILMSTRIP_IMAGES_VALUES) { boolean selected = filmstripPanel.getMaximumImages() == maximumFilmstripImagesValue; JMenuItem maximumFilmStripImagesMenuItem = new JRadioButtonMenuItem( Integer.toString(maximumFilmstripImagesValue), selected); maximumFilmStripImagesMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { filmstripPanel.setMaximumImages(maximumFilmstripImagesValue); } }); maximumFilmstripImagesButtonGroup.add(maximumFilmStripImagesMenuItem); maximumFilmstripImagesMenu.add(maximumFilmStripImagesMenuItem); } popupMenu.add(maximumFilmstripImagesMenu); popupMenu.addSeparator(); final JCheckBoxMenuItem showAsFilmstripMenuItem = new JCheckBoxMenuItem("Show as filmstrip", filmstripMode); showAsFilmstripMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { boolean filmstripMode = showAsFilmstripMenuItem.isSelected(); setFilmstripMode(filmstripMode); } }); popupMenu.add(showAsFilmstripMenuItem); final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image", useThumbnailImage); useThumbnailImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setUseThumbnailImage(useThumbnailImageMenuItem.isSelected()); } }); popupMenu.add(useThumbnailImageMenuItem); hideRoboticControlsMenuItem = new JCheckBoxMenuItem("Disable robotic controls", false); hideRoboticControlsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setRoboticControls(); } }); popupMenu.add(hideRoboticControlsMenuItem); // enable the save image popup if an image is being displayed popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean hasImage = displayedImageData != null; saveImageMenuItem.setEnabled(hasImage); copyImageMenuItem.setEnabled(hasImage); printImageMenuItem.setEnabled(hasImage); boolean enableZoom = hasImage && !filmstripMode; zoomInMenuItem.setEnabled(enableZoom); zoomInMenuItem.setVisible(!filmstripMode); zoomOutMenuItem.setEnabled(enableZoom); zoomOutMenuItem.setVisible(!filmstripMode); zoomMenuSeparator.setVisible(!filmstripMode); autoScaleMenuItem.setVisible(!filmstripMode); resetScaleMenuItem.setVisible(!filmstripMode); showNavigationImageMenuItem.setVisible(!filmstripMode); maximumFilmstripImagesMenu.setVisible(filmstripMode); showAsFilmstripMenuItem.setSelected(filmstripMode); useThumbnailImageMenuItem.setSelected(useThumbnailImage); useThumbnailImageMenuItem.setVisible(imageHasThumbnail()); hideRoboticControlsMenuItem.setVisible(flexTPSStream != null); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it panel.setComponentPopupMenu(popupMenu); imagePanel.setComponentPopupMenu(popupMenu); filmstripPanel.setComponentPopupMenu(popupMenu); panel.addMouseListener(new MouseInputAdapter() { }); }
From source file:org.yccheok.jstock.gui.AjaxAutoCompleteJComboBox.java
private PopupMenuListener getPopupMenuListener() { return new PopupMenuListener() { @Override/* ww w .j a va 2 s . c o m*/ public void popupMenuWillBecomeVisible(PopupMenuEvent e) { // We will have a much wider drop down list. Utils.adjustPopupWidth(AjaxAutoCompleteJComboBox.this); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // Reset popup width. AjaxAutoCompleteJComboBox.this.setPopupWidth(-1); } @Override public void popupMenuCanceled(PopupMenuEvent e) { // Reset popup width. AjaxAutoCompleteJComboBox.this.setPopupWidth(-1); } }; }
From source file:org.yccheok.jstock.gui.AutoCompleteJComboBox.java
private PopupMenuListener getPopupMenuListener() { return new PopupMenuListener() { @Override/*from w ww .j a v a 2 s. com*/ public void popupMenuWillBecomeVisible(PopupMenuEvent e) { // We will have a much wider drop down list. Utils.adjustPopupWidth(AutoCompleteJComboBox.this); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // Reset popup width. AutoCompleteJComboBox.this.setPopupWidth(-1); } @Override public void popupMenuCanceled(PopupMenuEvent e) { // Reset popup width. AutoCompleteJComboBox.this.setPopupWidth(-1); } }; }
From source file:processing.app.Editor.java
protected void configurePopupMenu(final SketchTextArea textarea) { JPopupMenu menu = textarea.getPopupMenu(); menu.addSeparator();//from ww w.j ava 2 s. c o m JMenuItem item = createToolMenuItem("cc.arduino.packages.formatter.AStyle"); item.setName("menuToolsAutoFormat"); menu.add(item); item = newJMenuItem(_("Comment/Uncomment"), '/'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCommentUncomment(); } }); menu.add(item); item = newJMenuItem(_("Increase Indent"), ']'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(true); } }); menu.add(item); item = newJMenuItem(_("Decrease Indent"), '['); item.setName("menuDecreaseIndent"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(false); } }); menu.add(item); item = new JMenuItem(_("Copy for Forum")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleDiscourseCopy(); } }); menu.add(item); item = new JMenuItem(_("Copy as HTML")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleHTMLCopy(); } }); menu.add(item); final JMenuItem referenceItem = new JMenuItem(_("Find in Reference")); referenceItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleFindReference(); } }); menu.add(referenceItem); final JMenuItem openURLItem = new JMenuItem(_("Open URL")); openURLItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Base.openURL(e.getActionCommand()); } }); menu.add(openURLItem); menu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { String referenceFile = base.getPdeKeywords().getReference(getCurrentKeyword()); referenceItem.setEnabled(referenceFile != null); int offset = textarea.getCaretPosition(); org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset); if (token != null && token.isHyperlink()) { openURLItem.setEnabled(true); openURLItem.setActionCommand(token.getLexeme()); } else { openURLItem.setEnabled(false); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); }