List of usage examples for javax.swing.event PopupMenuListener PopupMenuListener
PopupMenuListener
From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java
private void initBooksTable() { booksTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); booksTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override/*from w ww. jav a 2 s.c om*/ public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); booksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPopupMenu booksPopupMenu = new JPopupMenu(); JMenuItem deleteBook = new JMenuItem("Delete"); booksPopupMenu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int rowAtPoint = booksTable.rowAtPoint( SwingUtilities.convertPoint(booksPopupMenu, new Point(0, 0), booksTable)); if (rowAtPoint > -1) { booksTable.setRowSelectionInterval(rowAtPoint, rowAtPoint); } } }); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // TODO Auto-generated method stub } @Override public void popupMenuCanceled(PopupMenuEvent e) { // TODO Auto-generated method stub } }); deleteBook.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (booksTable.getSelectedRow() == -1) { JOptionPane.showMessageDialog(MainWindow.this, "You haven't selected any book."); return; } Book book = booksTableModel.getBooks().get(booksTable.getSelectedRow()); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { log.debug("Deleting book: " + book.getName() + " from database."); bookManager.deleteBook(book); return null; } @Override protected void done() { try { get(); } catch (Exception e) { log.error("There was an exception thrown while deleting a book.", e); return; } updateModel(); } }.execute(); } }); booksPopupMenu.add(deleteBook); booksTable.setComponentPopupMenu(booksPopupMenu); }
From source file:fxts.stations.trader.ui.dialogs.ABusinessDataComboBox.java
/** * Initiation the combo box.//from w w w . j a v a 2s . co m * * @param aDefaultActor instance of default actor */ public void init(IDefaultActor aDefaultActor) { mDefaultActor = aDefaultActor; setModel(getComboBoxModel()); try { mRenderer = new CustomizedListCellRenderer(getRenderer()); setRenderer(mRenderer); subscribeBusinessData(); Accessible acc = getAccessibleContext().getAccessibleChild(0); if (acc != null && acc instanceof JPopupMenu) { ((JPopupMenu) acc).addPopupMenuListener(new PopupMenuListener() { public void popupMenuCanceled(PopupMenuEvent aEvent) { } public void popupMenuWillBecomeInvisible(PopupMenuEvent aEvent) { Object itemObj = getSelectedItem(); if (itemObj instanceof Item) { Item item = (Item) getSelectedItem(); if (item != null) { setStatusEnabled(item.isEnabled()); } } } public void popupMenuWillBecomeVisible(PopupMenuEvent aEvent) { } }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.rapidminer.gui.new_plotter.gui.GlobalConfigurationPanel.java
private void createComponents() { // create panel for global configuration {// w w w . j a va 2s. com // add title label JLabel titleLabel = new ResourceLabel("plotter.configuration_dialog.chart_title"); String title = getPlotConfiguration().getTitleText(); if (title == null) { title = ""; } titleTextField = new JTextField(title); titleLabel.setLabelFor(titleTextField); titleTextField.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { return; } @Override public void keyReleased(KeyEvent e) { String newTitle = titleTextField.getText(); String titleText = getCurrentPlotInstance().getMasterPlotConfiguration().getTitleText(); if (titleText != null) { if (!titleText.equals(newTitle) || titleText == null && newTitle.length() > 0) { if (newTitle.length() > 0) { getPlotConfiguration().setTitleText(newTitle); } else { getPlotConfiguration().setTitleText(null); } } } else { if (newTitle.length() > 0) { getPlotConfiguration().setTitleText(newTitle); } else { getPlotConfiguration().setTitleText(null); } } if (newTitle.equals("Iris") && SwingTools.isControlOrMetaDown(e) && e.getKeyCode() == KeyEvent.VK_D) { startAnimation(); } } @Override public void keyPressed(KeyEvent e) { return; } }); titleTextField.setPreferredSize(new Dimension(115, 23)); titleConfigButton = new JToggleButton(new PopupAction(true, "plotter.configuration_dialog.open_popup", chartTitleConfigurationContainer, PopupPosition.HORIZONTAL)); addThreeComponentRow(this, titleLabel, titleTextField, titleConfigButton); } // add orientation check box { JLabel plotOrientationLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.plot_orientation"); PlotOrientation[] orientations = { PlotOrientation.HORIZONTAL, PlotOrientation.VERTICAL }; plotOrientationComboBox = new JComboBox(orientations); plotOrientationLabel.setLabelFor(plotOrientationComboBox); plotOrientationComboBox.setRenderer(new EnumComboBoxCellRenderer("plotter")); plotOrientationComboBox.setSelectedIndex(0); plotOrientationComboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { return; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { getPlotConfiguration() .setOrientation((PlotOrientation) plotOrientationComboBox.getSelectedItem()); } @Override public void popupMenuCanceled(PopupMenuEvent e) { return; } }); addTwoComponentRow(this, plotOrientationLabel, plotOrientationComboBox); } // add legend popup button { JLabel legendStyleConfigureLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.legend_style"); JToggleButton legendStyleConfigButton = new JToggleButton( new PopupAction(true, "plotter.configuration_dialog.open_popup", legendConfigContainer, PopupAction.PopupPosition.HORIZONTAL)); legendStyleConfigureLabel.setLabelFor(legendStyleConfigButton); addTwoComponentRow(this, legendStyleConfigureLabel, legendStyleConfigButton); } // add legend popup button { JLabel axisStyleConfigureLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.axis_style"); JToggleButton axisStyleConfigureButton = new JToggleButton( new PopupAction(true, "plotter.configuration_dialog.open_popup", axisConfigurationContainer, PopupAction.PopupPosition.HORIZONTAL)); axisStyleConfigureLabel.setLabelFor(axisStyleConfigureButton); addTwoComponentRow(this, axisStyleConfigureLabel, axisStyleConfigureButton); } // add color scheme dialog button { JLabel colorConfigureLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.color_scheme"); colorsSchemesComboBoxModel = new DefaultComboBoxModel(); colorSchemesComboBox = new JComboBox(colorsSchemesComboBoxModel); colorConfigureLabel.setLabelFor(colorSchemesComboBox); colorSchemesComboBox.setRenderer(new ColorSchemeComboBoxRenderer()); colorSchemesComboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { return; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { ColorScheme colorScheme = (ColorScheme) colorSchemesComboBox.getSelectedItem(); if (colorScheme != null) { getPlotConfiguration().setActiveColorScheme(colorScheme.getName()); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { return; } }); JButton colorConfigButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.open_color_scheme_dialog") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { createColorSchemeDialog(); } }); addThreeComponentRow(this, colorConfigureLabel, colorSchemesComboBox, colorConfigButton); } // add plot background color { plotBackGroundColorLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.select_plot_background_color"); plotBackgroundColorChooserButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.select_plot_color") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { createPlotBackgroundColorDialog(); } }); plotBackGroundColorLabel.setLabelFor(plotBackgroundColorChooserButton); addTwoComponentRow(this, plotBackGroundColorLabel, plotBackgroundColorChooserButton); } // add chart background color { frameBackGroundColorLabel = new ResourceLabel( "plotter.configuration_dialog.global_config_panel.select_frame_background_color"); frameBackgroundColorChooserButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.select_frame_color") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { createFrameBackgroundColorDialog(); } }); frameBackGroundColorLabel.setLabelFor(frameBackgroundColorChooserButton); addTwoComponentRow(this, frameBackGroundColorLabel, frameBackgroundColorChooserButton); // GridBagConstraints itemConstraint = new GridBagConstraints(); // itemConstraint.gridwidth = GridBagConstraints.REMAINDER; // itemConstraint.weightx = 1.0; // this.add(frameBackgroundColorChooserButton, itemConstraint); } // add spacer panel { JPanel spacerPanel = new JPanel(); GridBagConstraints itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.gridwidth = GridBagConstraints.REMAINDER; this.add(spacerPanel, itemConstraint); } }
From source file:com.atlassian.theplugin.idea.jira.IssueCreateDialog.java
public IssueCreateDialog(@NotNull IssueListToolWindowPanel issueListToolWindowPanel, @NotNull Project project, JIRAServerModel model, final JiraServerData jiraServerData, @NotNull final JiraWorkspaceConfiguration jiraProjectCfg, @Nullable JiraIssueAdapter parent) { super(false); this.issueListToolWindowPanel = issueListToolWindowPanel; this.project = project; this.model = model; this.jiraConfiguration = jiraProjectCfg; parentIssue = parent;//w w w . j a v a 2s .c om $$$setupUI$$$(); originalEstimate.getDocument() .addDocumentListener(new JiraTimeWdhmTextFieldListener(originalEstimate, true)); assigneeField = new FieldUser(model, jiraServerData, "", null); mainPanel.add(assigneeField, new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(50, -1), new Dimension(150, -1), null, 0, false)); componentsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); init(); pack(); this.jiraServerData = jiraServerData; setTitle(parentIssue == null ? "Create JIRA Issue" : "Create sub-task for issue " + parentIssue.getKey()); projectComboBox.setRenderer(new ColoredListCellRenderer() { @Override protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value != null) { append(((JIRAProject) value).getName(), SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES); } } }); typeComboBox.setRenderer(new JiraConstantCellRenderer()); typeComboBox.setEnabled(false); priorityComboBox.setRenderer(new JiraConstantCellRenderer()); projectComboBox.addPopupMenuListener(new PopupMenuListener() { private Object item = null; public void popupMenuWillBecomeVisible(PopupMenuEvent popupMenuEvent) { item = projectComboBox.getSelectedItem(); } public void popupMenuWillBecomeInvisible(PopupMenuEvent popupMenuEvent) { if (item != null && item != projectComboBox.getSelectedItem()) { updateProjectRelatedItems(); } } public void popupMenuCanceled(PopupMenuEvent popupMenuEvent) { item = null; } }); createAction.setEnabled(false); createAndOpenAction.setEnabled(false); }
From source file:es.emergya.ui.gis.ControlPanel.java
public ControlPanel(final CustomMapView view) { super(new FlowLayout(FlowLayout.LEADING, 12, 0)); this.view = view; // Posicion: panel con un label de icono y un textfield JPanel posPanel = new JPanel(); posPanel.setOpaque(true);//from w w w. j a va 2 s. c o m posPanel.setVisible(true); JLabel mouseLocIcon = new JLabel(LogicConstants.getIcon("map_icon_coordenadas")); posPanel.add(mouseLocIcon); final JTextField posField = new JTextField(15); posField.setEditable(false); posField.setBorder(null); posField.setForeground(UIManager.getColor("Label.foreground")); posField.setFont(UIManager.getFont("Label.font")); posPanel.add(posField); view.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { LatLon ll = ((ICustomMapView) e.getSource()).getLatLon(e.getX(), e.getY()); String position = ""; String format = LogicConstants.get("FORMATO_COORDENADAS_MAPA", "UTM"); if (format.equals(LogicConstants.COORD_UTM)) { UTM u = new UTM(LogicConstants.getInt("ZONA_UTM")); EastNorth en = u.latlon2eastNorth(ll); position = String.format("x: %.1f y: %.1f", en.getX(), en.getY()); } else { position = String.format("Lat: %.4f Lon: %.4f", ll.lat(), ll.lon()); } posField.setText(position); validate(); } @Override public void mouseDragged(MouseEvent e) { } }); posPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); add(posPanel); // Panel de centrado: label, desplegable y parte cambiante JPanel centerPanel = new JPanel(); centerPanel.add(new JLabel(i18n.getString("map.centerIn"))); centerOptions = new JComboBox(new String[] { i18n.getString("map.street"), i18n.getString("map.resource"), i18n.getString("map.incidence"), i18n.getString("map.location") }); centerPanel.add(centerOptions); centerData = new JPanel(new CardLayout()); centerPanel.add(centerData); JPanel centerStreet = new JPanel(); street = new JTextField(30); street.setName(i18n.getString("map.street")); autocompleteKeyListener = new AutocompleteKeyListener(street); street.addKeyListener(autocompleteKeyListener); street.addActionListener(this); centerStreet.add(street); centerData.add(centerStreet, i18n.getString("map.street")); JPanel centerResource = new JPanel(); resources = new JComboBox(avaliableResources); resources.setName(i18n.getString("map.resource")); resources.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); resources.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboResourcesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboResourcesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { // view.repaint(); } }); centerResource.add(resources); centerData.add(centerResource, i18n.getString("map.resource")); centerResource = new JPanel(); incidences = new JComboBox(avaliableIncidences); incidences.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); incidences.setName(i18n.getString("map.incidence")); incidences.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboIncidencesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboIncidencesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); centerResource.add(incidences); centerData.add(centerResource, i18n.getString("map.incidence")); JPanel centerLocation = new JPanel(); cx = new JTextField(10); cx.setName("x"); cx.addActionListener(this); centerLocation.add(cx); cy = new JTextField(10); cy.setName("y"); cy.addActionListener(this); centerLocation.add(cy); centerData.add(centerLocation, i18n.getString("map.location")); centerOptions.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { ((CardLayout) centerData.getLayout()).show(centerData, (String) e.getItem()); } }); JButton centerButton = new JButton(i18n.getString("map.center")); centerButton.addActionListener(this); centerPanel.add(centerButton); add(centerPanel); }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Build menu.//ww w . ja va2s . c om */ public void makeMenu() { JMenuItem menuItem; JMenu menu; JMenu submenu; menuBar = new JMenuBar(); setJMenuBar(menuBar); menu = new JMenu(Menu.MENU_FILE); menu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.EXPORT_MENU); menu.add(submenu); //submenu.setMnemonic( KeyEvent.VK_E ); SchemeExporter.makeSchemeExportMenu(submenu, getActionListener()); // Export window graphics submenu.add(GraphicsExporter.getExportMenu()); menu.addSeparator(); menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu = new JMenu(Menu.MENU_EDIT); menu.setMnemonic(KeyEvent.VK_E); menu.add(undoAction); menu.add(redoAction); menu.add(cloneAction); menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true); painterEnabled.addActionListener(getActionListener()); menu.add(painterEnabled); menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas = Editor.getInstance().getCurrentCanvas(); if (canvas == null || !canvas.getPackage().hasPainters()) { painterEnabled.setVisible(false); } else { painterEnabled.setVisible(true); painterEnabled.setSelected(canvas.isEnableClassPainter()); } } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_VIEW); menu.setMnemonic(KeyEvent.VK_V); gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid()); gridCheckBox.setMnemonic('G'); gridCheckBox.addActionListener(getActionListener()); menu.add(gridCheckBox); ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls()); ctrlCheckBox.setMnemonic('C'); ctrlCheckBox.addActionListener(getActionListener()); menu.add(ctrlCheckBox); showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true); showPortCheckBox.addActionListener(getActionListener()); menu.add(showPortCheckBox); showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false); showObjectNamesCheckBox.addActionListener(getActionListener()); menu.add(showObjectNamesCheckBox); //sync View with current canvas menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas; if ((canvas = getCurrentCanvas()) == null) return; gridCheckBox.setSelected(canvas.isGridVisible()); ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible()); showPortCheckBox.setSelected(canvas.isDrawPorts()); showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames()); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_PACKAGE); menu.setMnemonic(KeyEvent.VK_P); menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I); menuItem.addActionListener(getActionListener()); menu.add(menuItem); if (Desktop.isDesktopSupported()) { menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B); menuItem.addActionListener(getActionListener()); menu.add(menuItem); } menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLOSE_ALL); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu.add(new JSeparator()); final JMenu submenuRecent = new JMenu(Menu.RECENT); submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { final JMenuItem empty = new JMenuItem("Empty"); @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeRecentSubMenu(submenuRecent); if (submenuRecent.getMenuComponentCount() == 0) { submenuRecent.add(empty); empty.setEnabled(false); } else { if (!((submenuRecent.getMenuComponentCount() == 1) && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) { submenuRecent.remove(empty); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menu.add(submenuRecent); final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME); menuScheme.setMnemonic(KeyEvent.VK_S); makeSchemeMenu(menuScheme); menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeSchemeMenu(menuScheme); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); /* * menuItem = new JMenuItem("Planner"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); * menuItem = new JMenuItem("Plan, compile, run"); * menuItem.setActionCommand("Run"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); */ // menuScheme.setMnemonic(KeyEvent.VK_A); menuBar.add(menuScheme); menu = new JMenu(Menu.MENU_OPTIONS); menu.setMnemonic(KeyEvent.VK_O); menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.FONTS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SETTINGS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.MENU_LAF); submenu.setMnemonic(KeyEvent.VK_L); Look.getInstance().createMenuItems(submenu); menu.add(submenu); menuBar.add(menu); makeToolsMenu(menuBar); menu = new JMenu(Menu.MENU_HELP); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:net.java.sip.communicator.impl.osdependent.jdic.SystrayServiceJdicImpl.java
/** * Initializes the systray icon and related listeners. *///from w w w . ja v a 2 s . c o m private void initSystray() { UIService uiService = OsDependentActivator.getUIService(); if (uiService == null) { /* * Delay the call to the #initSystray() method until the UIService * implementation becomes available. */ try { OsDependentActivator.bundleContext.addServiceListener(new DelayedInitSystrayServiceListener(), '(' + Constants.OBJECTCLASS + '=' + UIService.class.getName() + ')'); } catch (InvalidSyntaxException ise) { /* * Oh, it should not really happen. Besides, it is not clear at * the time of this writing what is supposed to happen in the * case of such an exception here. */ } return; } Pair<Object, Object> createdMenu = TrayMenuFactory.createTrayMenu(this, systray.useSwingPopupMenu(), systray.supportsDynamicMenu()); menu = createdMenu.getLeft(); boolean isMac = OSUtils.IS_MAC; logoIcon = Resources.getImage("service.systray.TRAY_ICON_WINDOWS"); logoIconOffline = Resources.getImage("service.systray.TRAY_ICON_WINDOWS_OFFLINE"); logoIconAway = Resources.getImage("service.systray.TRAY_ICON_WINDOWS_AWAY"); logoIconExtendedAway = Resources.getImage("service.systray.TRAY_ICON_WINDOWS_EXTENDED_AWAY"); logoIconFFC = Resources.getImage("service.systray.TRAY_ICON_WINDOWS_FFC"); logoIconDND = Resources.getImage("service.systray.TRAY_ICON_WINDOWS_DND"); // If we're running under Mac OS X, we use special black and white // icons without background. if (isMac) { logoIcon = Resources.getImage("service.systray.TRAY_ICON_MACOSX"); logoIconWhite = Resources.getImage("service.systray.TRAY_ICON_MACOSX_WHITE"); } /* * Default to set offline , if any protocols become online will set it * to online. */ currentIcon = isMac ? logoIcon : logoIconOffline; trayIcon = systray.createTrayIcon(currentIcon, Resources.getApplicationString("service.gui.APPLICATION_NAME"), menu); trayIcon.setIconAutoSize(true); if (isMac) { // init dock Icons dockIconOnline = Resources.getImageURL("service.systray.DOCK_ICON_ONLINE"); dockIconOffline = Resources.getImageURL("service.systray.DOCK_ICON_OFFLINE"); dockIconAway = Resources.getImageURL("service.systray.DOCK_ICON_AWAY"); dockIconExtendedAway = Resources.getImageURL("service.systray.DOCK_ICON_EXTENDED_AWAY"); dockIconFFC = Resources.getImageURL("service.systray.DOCK_ICON_FFC"); dockIconDND = Resources.getImageURL("service.systray.DOCK_ICON_DND"); } //Show/hide the contact list when user clicks on the systray. final Object defaultActionItem; if (systray.useSwingPopupMenu()) { defaultActionItem = ((JMenuItem) createdMenu.getRight()); } else { defaultActionItem = ((MenuItem) createdMenu.getRight()); } /* * Change the Mac OS X icon with the white one when the pop-up menu * appears. */ if (isMac) { TrayMenuFactory.addPopupMenuListener(menu, new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent e) { ImageIcon newIcon = logoIconWhite; trayIcon.setIcon(newIcon); currentIcon = newIcon; } public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { ImageIcon newIcon = logoIcon; getTrayIcon().setIcon(newIcon); currentIcon = newIcon; } public void popupMenuCanceled(PopupMenuEvent e) { popupMenuWillBecomeInvisible(e); } }); } PopupMessageHandler pmh = null; if (!isMac) { pmh = new PopupMessageHandlerTrayIconImpl(trayIcon); addPopupHandler(pmh); OsDependentActivator.bundleContext.registerService(PopupMessageHandler.class.getName(), pmh, null); } initHandlers(); /* * Either we have an incorrect configuration value or the default pop-up * handler is not available yet. We will use the available pop-up * handler and will automatically switch to the configured one when it * becomes available. We will be aware of it since we listen for new * registered services in the BundleContext. */ if ((getActivePopupMessageHandler() == null) && (pmh != null)) setActivePopupMessageHandler(pmh); SwingUtilities.invokeLater(new Runnable() { public void run() { systray.addTrayIcon(trayIcon); trayIcon.setDefaultAction(defaultActionItem); } }); initialized = true; uiService.setMainWindowCanHide(true); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopSearchField.java
public DesktopSearchField() { composition = new JPanel(); composition.setLayout(new BorderLayout()); composition.setFocusable(false);/* ww w . j ava2 s. c o m*/ comboBox = new SearchComboBox() { @Override public void setPopupVisible(boolean v) { if (!items.isEmpty()) { super.setPopupVisible(v); } else if (!v) { super.setPopupVisible(false); } } @Override public void actionPerformed(ActionEvent e) { if (SearchAutoCompleteSupport.SEARCH_ENTER_COMMAND.equals(e.getActionCommand())) { enterHandling = true; } super.actionPerformed(e); } }; comboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (settingValue || disableActionListener) return; if ("comboBoxEdited".equals(e.getActionCommand())) { Object selectedItem = comboBox.getSelectedItem(); if (popupItemSelectionHandling) { if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); updateOptionsDsItem(); } else if (selectedItem instanceof String) { handleSearch((String) selectedItem); } popupItemSelectionHandling = false; } else if (enterHandling) { if (selectedItem instanceof String) { boolean found = false; String newFilter = (String) selectedItem; if (prevValue != null) { if (Objects.equals(getDisplayString((Entity) prevValue), newFilter)) { found = true; } } if (!found) { handleSearch(newFilter); } else { updateComponent(prevValue); clearSearchVariants(); } } else { // Disable variants after select clearSearchVariants(); } enterHandling = false; } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { updateEditState(); } }); } }); Component editorComponent = comboBox.getEditor().getEditorComponent(); editorComponent.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { updateEditState(); } }); } }); comboBox.setEditable(true); comboBox.setPrototypeDisplayValue("AAAAAAAAAAAA"); autoComplete = SearchAutoCompleteSupport.install(comboBox, items); autoComplete.setFilterEnabled(false); for (int i = 0; i < comboBox.getComponentCount(); i++) { java.awt.Component component = comboBox.getComponent(i); component.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { clearSearchVariants(); // Reset invalid value checkSelectedValue(); } }); } // set value only on PopupMenu closing to avoid firing listeners on keyboard navigation comboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { comboBox.updatePopupWidth(); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { if (!autoComplete.isEditableState()) { // Only if realy item changed if (!enterHandling) { Object selectedItem = comboBox.getSelectedItem(); if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); updateOptionsDsItem(); } else if (selectedItem instanceof String) { handleSearch((String) selectedItem); } } else { popupItemSelectionHandling = true; } updateMissingValueState(); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { clearSearchVariants(); } }); setFilterMode(DEFAULT_FILTER_MODE); textField = new JTextField(); textField.setEditable(false); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); valueFormatter = new DefaultValueFormatter(sessionSource.getLocale()); composition.add(comboBox, BorderLayout.CENTER); impl = comboBox; DesktopComponentsHelper.adjustSize(comboBox); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopSuggestionField.java
public DesktopSuggestionField() { composition = new JPanel(); composition.setLayout(new BorderLayout()); composition.setFocusable(false);/* w ww. j a v a2s. co m*/ comboBox = new SearchComboBox() { @Override public void setPopupVisible(boolean v) { if (!items.isEmpty()) { super.setPopupVisible(v); } else if (!v) { super.setPopupVisible(false); } } @Override public void actionPerformed(ActionEvent e) { if (SearchAutoCompleteSupport.SEARCH_ENTER_COMMAND.equals(e.getActionCommand())) { enterHandling = true; } super.actionPerformed(e); } }; comboBox.addActionListener(e -> { if (settingValue || disableActionListener) { return; } if ("comboBoxEdited".equals(e.getActionCommand())) { Object selectedItem = comboBox.getSelectedItem(); if (popupItemSelectionHandling) { if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); } } else if (enterHandling) { if (selectedItem instanceof String) { boolean found = false; String newFilter = (String) selectedItem; if (prevValue != null) { if (Objects.equals(getDisplayString(prevValue), newFilter)) { found = true; } } final boolean searchStringEqualsToCurrentValue = found; // we need to do it later // unable to change current text from ActionListener SwingUtilities.invokeLater(() -> { updateComponent(prevValue); if (!searchStringEqualsToCurrentValue) { handleOnEnterAction(((String) selectedItem)); } }); } else if (currentSearchComponentText != null) { // Disable variants after select final String enterActionString = currentSearchComponentText; SwingUtilities.invokeLater(() -> { updateComponent(prevValue); handleOnEnterAction(enterActionString); }); currentSearchComponentText = null; } } clearSearchVariants(); popupItemSelectionHandling = false; enterHandling = false; } SwingUtilities.invokeLater(this::updateEditState); }); Component editorComponent = comboBox.getEditor().getEditorComponent(); editorComponent.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { SwingUtilities.invokeLater(() -> { updateEditState(); if (e.getKeyChar() != '\n') { handleSearchInput(); } }); } @Override public void keyPressed(KeyEvent e) { SwingUtilities.invokeLater(() -> { if (e.getKeyCode() == KeyEvent.VK_DOWN && arrowDownActionHandler != null && !comboBox.isPopupVisible()) { arrowDownActionHandler.onArrowDownKeyPressed(getComboBoxEditorField().getText()); } }); } }); comboBox.setEditable(true); comboBox.setPrototypeDisplayValue("AAAAAAAAAAAA"); autoComplete = SearchAutoCompleteSupport.install(comboBox, items); autoComplete.setFilterEnabled(false); for (int i = 0; i < comboBox.getComponentCount(); i++) { Component component = comboBox.getComponent(i); component.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { clearSearchVariants(); // Reset invalid value checkSelectedValue(); } }); } final JTextField searchEditorComponent = getComboBoxEditorField(); searchEditorComponent.addActionListener(e -> currentSearchComponentText = searchEditorComponent.getText()); // set value only on PopupMenu closing to avoid firing listeners on keyboard navigation comboBox.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { comboBox.updatePopupWidth(); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { if (!autoComplete.isEditableState()) { popupItemSelectionHandling = comboBox.getSelectedIndex() >= 0; // Only if really item changed if (!enterHandling) { Object selectedItem = comboBox.getSelectedItem(); if (selectedItem instanceof ValueWrapper) { Object selectedValue = ((ValueWrapper) selectedItem).getValue(); setValue(selectedValue); clearSearchVariants(); } } updateMissingValueState(); } } @Override public void popupMenuCanceled(PopupMenuEvent e) { clearSearchVariants(); } }); textField = new JTextField(); textField.setEditable(false); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); valueFormatter = new DefaultValueFormatter(sessionSource.getLocale()); composition.add(comboBox, BorderLayout.CENTER); impl = comboBox; DesktopComponentsHelper.adjustSize(comboBox); Configuration configuration = AppBeans.get(Configuration.NAME); asyncSearchDelayMs = configuration.getConfig(ClientConfig.class).getSuggestionFieldAsyncSearchDelayMs(); }
From source file:es.emergya.ui.gis.HistoryMapViewer.java
@Override protected JPopupMenu getContextMenu() { JPopupMenu menu = new JPopupMenu(); // Centrar aqui JMenuItem cent = new JMenuItem(i18n.getString("map.menu.centerHere"), KeyEvent.VK_C); cent.setIcon(LogicConstants.getIcon("menucontextual_icon_centrar")); cent.addActionListener(new ActionListener() { @Override/*w w w.j av a 2s . c o m*/ public void actionPerformed(ActionEvent e) { mapView.zoomToFactor(mapView.getEastNorth(eventOriginal.getX(), eventOriginal.getY()), mapView.zoomFactor); } }); menu.add(cent); menu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { eventOriginal = HistoryMapViewer.this.mapView.lastMEvent; } @Override public void popupMenuCanceled(PopupMenuEvent arg0) { } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } }); return menu; }