List of usage examples for javax.swing JPopupMenu JPopupMenu
public JPopupMenu()
JPopupMenu
without an "invoker". From source file:edu.harvard.mcz.imagecapture.SpecimenPartAttributeDialog.java
private void init() { thisDialog = this; setBounds(100, 100, 820, 335);/*from w ww.j a v a 2s.c o m*/ getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); JPanel panel = new JPanel(); panel.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); { JLabel lblAttributeType = new JLabel("Attribute Type"); panel.add(lblAttributeType, "2, 2, right, default"); } { comboBoxType = new JComboBox(); comboBoxType.setModel(new DefaultComboBoxModel( new String[] { "caste", "scientific name", "sex", "life stage", "part association" })); comboBoxType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String item = comboBoxType.getSelectedItem().toString(); if (item != null) { comboBoxValue.setEditable(false); if (item.equals("scientific name")) { comboBoxValue.setEditable(true); } if (item.equals("sex")) { comboBoxValue.setModel(new DefaultComboBoxModel(Sex.getSexValues())); } if (item.equals("life stage")) { comboBoxValue.setModel(new DefaultComboBoxModel(LifeStage.getLifeStageValues())); } if (item.equals("caste")) { comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues())); } if (item.equals("part association")) { comboBoxValue .setModel(new DefaultComboBoxModel(PartAssociation.getPartAssociationValues())); } } } }); panel.add(comboBoxType, "4, 2, fill, default"); } { JLabel lblValue = new JLabel("Value"); panel.add(lblValue, "2, 4, right, default"); } { comboBoxValue = new JComboBox(); comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues())); panel.add(comboBoxValue, "4, 4, fill, default"); } { JLabel lblUnits = new JLabel("Units"); panel.add(lblUnits, "2, 6, right, default"); } { textFieldUnits = new JTextField(); panel.add(textFieldUnits, "4, 6, fill, default"); textFieldUnits.setColumns(10); } { JLabel lblRemarks = new JLabel("Remarks"); panel.add(lblRemarks, "2, 8, right, default"); } contentPanel.setLayout(new BorderLayout(0, 0)); contentPanel.add(panel, BorderLayout.WEST); { textFieldRemarks = new JTextField(); panel.add(textFieldRemarks, "4, 8, fill, default"); textFieldRemarks.setColumns(10); } { JButton btnAdd = new JButton("Add"); btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SpecimenPartAttribute newAttribs = new SpecimenPartAttribute(); newAttribs.setAttributeType(comboBoxType.getSelectedItem().toString()); newAttribs.setAttributeValue(comboBoxValue.getSelectedItem().toString()); newAttribs.setAttributeUnits(textFieldUnits.getText()); newAttribs.setAttributeRemark(textFieldRemarks.getText()); newAttribs.setSpecimenPartId(parentPart); newAttribs.setAttributeDeterminer(Singleton.getSingletonInstance().getUserFullName()); parentPart.getAttributeCollection().add(newAttribs); SpecimenPartAttributeLifeCycle sls = new SpecimenPartAttributeLifeCycle(); try { sls.attachDirty(newAttribs); } catch (SaveFailedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ((AbstractTableModel) table.getModel()).fireTableDataChanged(); } }); panel.add(btnAdd, "4, 10"); } try { JLabel lblNewLabel = new JLabel(parentPart.getSpecimenId().getBarcode() + ":" + parentPart.getPartName() + " " + parentPart.getPreserveMethod() + " (" + parentPart.getLotCount() + ") Right click on table to edit attributes."); contentPanel.add(lblNewLabel, BorderLayout.NORTH); } catch (Exception e) { JLabel lblNewLabel = new JLabel("No Specimen"); contentPanel.add(lblNewLabel, BorderLayout.NORTH); } JComboBox comboBox = new JComboBox(); comboBox.addItem("caste"); JComboBox comboBox1 = new JComboBox(); for (int i = 0; i < Caste.getCasteValues().length; i++) { comboBox1.addItem(Caste.getCasteValues()[i]); } JScrollPane scrollPane = new JScrollPane(); table = new JTable(new SpecimenPartsAttrTableModel( (Collection<SpecimenPartAttribute>) parentPart.getAttributeCollection())); //table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox)); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnRow = ((JTable) e.getComponent()).getSelectedRow(); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnRow = ((JTable) e.getComponent()).getSelectedRow(); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); popupMenu = new JPopupMenu(); JMenuItem mntmCloneRow = new JMenuItem("Edit Row"); mntmCloneRow.setMnemonic(KeyEvent.VK_E); mntmCloneRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // Launch a dialog to edit the selected row. SpecimenPartAttribEditDialog popup = new SpecimenPartAttribEditDialog( ((SpecimenPartsAttrTableModel) table.getModel()).getRowObject(clickedOnRow)); popup.setVisible(true); } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisDialog, "Failed to edit a part attribute row. " + ex.getMessage()); } } }); popupMenu.add(mntmCloneRow); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.setMnemonic(KeyEvent.VK_D); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (clickedOnRow >= 0) { ((SpecimenPartsAttrTableModel) table.getModel()).deleteRow(clickedOnRow); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisDialog, "Failed to delete a part attribute row. " + ex.getMessage()); } } }); popupMenu.add(mntmDeleteRow); // TODO: Enable controlled value editing of selected row. // table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox1)); scrollPane.setViewportView(table); contentPanel.add(scrollPane, BorderLayout.EAST); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton.grabFocus(); thisDialog.setVisible(false); } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { thisDialog.setVisible(false); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java
public void initComponentsManual() { attachmentPopupMenu = new JPopupMenu(); JMenuItem viewAttach = new JMenuItem("View Attachment"); viewAttach.setIcon(new ImageIcon(Frame.class.getResource("images/attach.png"))); viewAttach.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { viewAttachment();/*from w w w.j ava 2s .c o m*/ } }); attachmentPopupMenu.add(viewAttach); JMenuItem exportAttach = new JMenuItem("Export Attachment"); exportAttach.setIcon(new ImageIcon(Frame.class.getResource("images/report_disk.png"))); exportAttach.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportAttachment(); } }); attachmentPopupMenu.add(exportAttach); pageSizeField.setDocument(new MirthFieldConstraints(3, false, false, true)); pageNumberField.setDocument(new MirthFieldConstraints(7, false, false, true)); advancedSearchPopup = new MessageBrowserAdvancedFilter(parent, this, "Advanced Search Filter", true, true); advancedSearchPopup.setVisible(false); LineBorder lineBorder = new LineBorder(new Color(0, 0, 0)); TitledBorder titledBorder = new TitledBorder("Current Search"); titledBorder.setBorder(lineBorder); lastSearchCriteriaPane.setBorder(titledBorder); lastSearchCriteriaPane.setBackground(Color.white); lastSearchCriteria.setBackground(Color.white); mirthDatePicker1.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { allDayCheckBox.setEnabled(mirthDatePicker1.getDate() != null || mirthDatePicker2.getDate() != null); mirthTimePicker1.setEnabled(mirthDatePicker1.getDate() != null && !allDayCheckBox.isSelected()); } }); mirthDatePicker2.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { allDayCheckBox.setEnabled(mirthDatePicker1.getDate() != null || mirthDatePicker2.getDate() != null); mirthTimePicker2.setEnabled(mirthDatePicker2.getDate() != null && !allDayCheckBox.isSelected()); } }); pageNumberField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_ENTER && pageGoButton.isEnabled()) { jumpToPageNumber(); } } }); if (!Arrays.asList("postgres", "oracle", "mysql").contains(PlatformUI.SERVER_DATABASE)) { regexTextSearchCheckBox.setEnabled(false); } this.addAncestorListener(new AncestorListener() { @Override public void ancestorAdded(AncestorEvent event) { } @Override public void ancestorMoved(AncestorEvent event) { } @Override public void ancestorRemoved(AncestorEvent event) { // Stop waiting for message browser requests when the message browser // is no longer being displayed parent.mirthClient.getServerConnection().abort(getAbortOperations()); // Clear the message cache when leaving the message browser. parent.messageBrowser.clearCache(); // Clear the table selection to prevent the selection listener from triggering multiple times while the model is being cleared deselectRows(); // Clear the records in the table tableModel.clear(); // Remove all columns for (TableColumn tableColumn : messageTreeTable.getColumns(true)) { messageTreeTable.removeColumn(tableColumn); } } }); }
From source file:net.sf.jabref.gui.MainTableSelectionListener.java
@Override public void mouseClicked(MouseEvent e) { // First find the column on which the user has clicked. final int col = table.columnAtPoint(e.getPoint()); final int row = table.rowAtPoint(e.getPoint()); // A double click on an entry should open the entry's editor. if (e.getClickCount() == 2) { BibtexEntry toShow = tableRows.get(row); editSignalled(toShow);/*from ww w. jav a 2s. co m*/ } // Check if the user has clicked on an icon cell to open url or pdf. final String[] iconType = table.getIconTypeForColumn(col); // Workaround for Windows. Right-click is not popup trigger on mousePressed, but // on mouseReleased. Therefore we need to avoid taking action at this point, because // action will be taken when the button is released: if (OS.WINDOWS && (iconType != null) && (e.getButton() != MouseEvent.BUTTON1)) { return; } if (iconType != null) { // left click on icon field SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]); if ((e.getClickCount() == 1) && (field != null)) { // special field found if (field.isSingleValueField()) { // directly execute toggle action instead of showing a menu with one action field.getValues().get(0).getAction(panel.frame()).action(); } else { JPopupMenu menu = new JPopupMenu(); for (SpecialFieldValue val : field.getValues()) { menu.add(val.getMenuAction(panel.frame())); } menu.show(table, e.getX(), e.getY()); } return; } Object value = table.getValueAt(row, col); if (value == null) { return; // No icon here, so we do nothing. } final BibtexEntry entry = tableRows.get(row); // Get the icon type. Corresponds to the field name. int hasField = -1; for (int i = iconType.length - 1; i >= 0; i--) { if (entry.getField(iconType[i]) != null) { hasField = i; } } if (hasField == -1) { return; } final String fieldName = iconType[hasField]; //If this is a file link field with specified file types, //we should also pass the types. String[] fileTypes = {}; if ((hasField == 0) && iconType[hasField].equals(Globals.FILE_FIELD) && (iconType.length > 1)) { fileTypes = iconType; } final List<String> listOfFileTypes = Collections.unmodifiableList(Arrays.asList(fileTypes)); // Open it now. We do this in a thread, so the program won't freeze during the wait. JabRefExecutorService.INSTANCE.execute(new Runnable() { @Override public void run() { panel.output(Localization.lang("External viewer called") + '.'); Object link = entry.getField(fieldName); if (link == null) { LOGGER.info("Error: no link to " + fieldName + '.'); return; // There is an icon, but the field is not set. } // See if this is a simple file link field, or if it is a file-list // field that can specify a list of links: if (fieldName.equals(Globals.FILE_FIELD)) { // We use a FileListTableModel to parse the field content: FileListTableModel fileList = new FileListTableModel(); fileList.setContent((String) link); FileListEntry flEntry = null; // If there are one or more links of the correct type, // open the first one: if (!listOfFileTypes.isEmpty()) { for (int i = 0; i < fileList.getRowCount(); i++) { flEntry = fileList.getEntry(i); boolean correctType = false; for (String listOfFileType : listOfFileTypes) { if (flEntry.getType().toString().equals(listOfFileType)) { correctType = true; } } if (correctType) { break; } flEntry = null; } } //If there are no file types specified, consider all files. else if (fileList.getRowCount() > 0) { flEntry = fileList.getEntry(0); } if (flEntry != null) { // if (fileList.getRowCount() > 0) { // FileListEntry flEntry = fileList.getEntry(0); ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "", flEntry.getLink(), flEntry.getType().getIcon(), panel.metaData(), flEntry.getType()); boolean success = item.openLink(); if (!success) { panel.output(Localization.lang("Unable to open link.")); } } } else { try { JabRefDesktop.openExternalViewer(panel.metaData(), (String) link, fieldName); } catch (IOException ex) { panel.output(Localization.lang("Unable to open link.")); } /*ExternalFileType type = Globals.prefs.getExternalFileTypeByMimeType("text/html"); ExternalFileMenuItem item = new ExternalFileMenuItem (panel.frame(), entry, "", (String)link, type.getIcon(), panel.metaData(), type); boolean success = item.openLink(); if (!success) { panel.output(Localization.lang("Unable to open link.")); } */ //Util.openExternalViewer(panel.metaData(), (String)link, fieldName); } //catch (IOException ex) { // panel.output(Globals.lang("Error") + ": " + ex.getMessage()); //} } }); } }
From source file:gdt.jgui.entity.bookmark.JBookmarksFacetOpenItem.java
/** * Get the popup menu for the child node of the facet node * in the digest view.//from ww w . j a v a2 s. c o m * @return the popup menu. */ @Override public JPopupMenu getPopupMenu(final String digestLocator$) { JPopupMenu popup = new JPopupMenu(); JMenuItem openItem = new JMenuItem("Open"); popup.add(openItem); openItem.setHorizontalTextPosition(JMenuItem.RIGHT); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // System.out.println("JBookmarkFacetOpenItem:open:digest locator="+digestLocator$); Properties locator = Locator.toProperties(digestLocator$); String encodedSelection$ = locator.getProperty(JEntityDigestDisplay.SELECTION); byte[] ba = Base64.decodeBase64(encodedSelection$); String selection$ = new String(ba, "UTF-8"); // System.out.println("JBookmarkFacetOpenItem:open:selection="+selection$); locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String type$ = locator.getProperty(Locator.LOCATOR_TYPE); if (JFolderPanel.LOCATOR_TYPE_FILE.equals(type$)) { String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File file = new File(filePath$); Desktop.getDesktop().open(file); return; } if (JEntityDigestDisplay.LOCATOR_FACET_COMPONENT.equals(type$)) { String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); JBookmarksEditor be = new JBookmarksEditor(); String beLocator$ = be.getLocator(); beLocator$ = Locator.append(beLocator$, Entigrator.ENTIHOME, entihome$); beLocator$ = Locator.append(beLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, beLocator$); return; } String bookmarkKey$ = locator.getProperty(JBookmarksEditor.BOOKMARK_KEY); Entigrator entigrator = console.getEntigrator(entihome$); String componentKey$ = locator.getProperty(JEntityDigestDisplay.COMPONENT_KEY); Sack entity = entigrator.getEntityAtKey(componentKey$); Core bookmark = entity.getElementItem("jbookmark", bookmarkKey$); // System.out.println("JBookmarkFacetOpenItem:open:selection="+selection$); JConsoleHandler.execute(console, bookmark.value); } catch (Exception ee) { Logger.getLogger(JBookmarksFacetOpenItem.class.getName()).info(ee.toString()); } } }); return popup; }
From source file:blue.automation.AutomationManager.java
public JPopupMenu getAutomationMenu(SoundLayer soundLayer) { this.selectedSoundLayer = soundLayer; // if (menu == null || dirty) { JPopupMenu menu = new JPopupMenu(); // Build Instrument Menu JMenu instrRoot = new JMenu("Instrument"); Arrangement arrangement = data.getArrangement(); ParameterIdList paramIdList = soundLayer.getAutomationParameters(); for (int i = 0; i < arrangement.size(); i++) { InstrumentAssignment ia = arrangement.getInstrumentAssignment(i); if (ia.enabled && ia.instr instanceof Automatable) { ParameterList params = ((Automatable) ia.instr).getParameterList(); if (params.size() <= 0) { continue; }/*from w w w . ja va 2 s .c o m*/ JMenu instrMenu = new JMenu(); instrMenu.setText(ia.arrangementId + ") " + ia.instr.getName()); for (int j = 0; j < params.size(); j++) { Parameter param = params.getParameter(j); JMenuItem paramItem = new JMenuItem(); paramItem.setText(param.getName()); paramItem.addActionListener(parameterActionListener); if (param.isAutomationEnabled()) { if (paramIdList.contains(param.getUniqueId())) { paramItem.setForeground(Color.GREEN); } else { paramItem.setForeground(Color.ORANGE); } } paramItem.putClientProperty("instr", ia.instr); paramItem.putClientProperty("param", param); instrMenu.add(paramItem); } instrRoot.add(instrMenu); } } menu.add(instrRoot); // Build Mixer Menu Mixer mixer = data.getMixer(); if (mixer.isEnabled()) { JMenu mixerRoot = new JMenu("Mixer"); // add channels ChannelList channels = mixer.getChannels(); if (channels.size() > 0) { JMenu channelsMenu = new JMenu("Channels"); for (int i = 0; i < channels.size(); i++) { channelsMenu.add(buildChannelMenu(channels.getChannel(i), soundLayer)); } mixerRoot.add(channelsMenu); } // add subchannels ChannelList subChannels = mixer.getSubChannels(); if (subChannels.size() > 0) { JMenu subChannelsMenu = new JMenu("Sub-Channels"); for (int i = 0; i < subChannels.size(); i++) { subChannelsMenu.add(buildChannelMenu(subChannels.getChannel(i), soundLayer)); } mixerRoot.add(subChannelsMenu); } // add master channel Channel master = mixer.getMaster(); mixerRoot.add(buildChannelMenu(master, soundLayer)); menu.add(mixerRoot); } menu.addSeparator(); JMenuItem clearAll = new JMenuItem("Clear All"); clearAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object retVal = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation( "Please Confirm Clearing All Parameter Data for this SoundLayer")); if (retVal == NotifyDescriptor.YES_OPTION) { ParameterIdList idList = selectedSoundLayer.getAutomationParameters(); Iterator iter = new ArrayList(idList.getParameters()).iterator(); while (iter.hasNext()) { String paramId = (String) iter.next(); Parameter param = getParameter(paramId); param.setAutomationEnabled(false); idList.removeParameterId(paramId); } } } }); menu.add(clearAll); clearAll.setEnabled(soundLayer.getAutomationParameters().size() > 0); // } // System.err.println(parameterMap); return menu; }
From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java
public VGraphUI() { VHintButton zoomIn = new VHintButton(VIcons.ZOOM_IN); menu.add(zoomIn);//from w w w. j av a2 s . c o m zoomIn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VGraphCell cell = selectedCell; Object o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; chart.zoomInBoth(0, 0); graph.repaint(); } } }); VHintButton zoomOut = new VHintButton(VIcons.ZOOM_OUT); menu.add(zoomOut); zoomOut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VGraphCell cell = selectedCell; Object o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; chart.zoomOutBoth(0, 0); graph.repaint(); } } }); VHintButton settings = new VHintButton(VIcons.APPLICATION_FORM_EDIT); menu.add(settings); settings.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VGraphCell cell = selectedCell; Object o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; ChartEditor editor = ChartEditorManager.getChartEditor(chart.getChart()); int result = JOptionPane.showConfirmDialog(graph.getParent(), editor, "Chart_Properties", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { editor.updateChart(chart.getChart()); graph.repaint(); } } } }); VHintButton legend = new VHintButton(VIcons.BRICKS); menu.add(legend); legend.addActionListener(new ActionListener() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { VGraphCell cell = selectedCell; Object o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; VLegend legend = new VLegend(chart.getChart()); JPopupMenu menu = new JPopupMenu(); menu.add(legend); menu.show(graph, 0, 0); } } }); }
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
private JPopupMenu getColumnMenu() { SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel(); JPopupMenu columnMenu = new JPopupMenu(); for (int i = 0; i < model.getColumnCount(); i++) { final String columnName = model.getColumnName(i); // Get the column object by name. Using an index may not return the column object if the column is hidden TableColumnExt column = getColumnExt(columnName); // Create the menu item final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName); // Show or hide the checkbox menuItem.setSelected(column.isVisible()); menuItem.addActionListener(new ActionListener() { @Override//from w w w.j a v a2 s .co m public void actionPerformed(ActionEvent arg0) { TableColumnExt column = getColumnExt(menuItem.getText()); // Determine whether to show or hide the selected column boolean enable = !column.isVisible(); // Do not hide a column if it is the last remaining visible column if (enable || getColumnCount() > 1) { column.setVisible(enable); Set<String> customHiddenColumns = customHiddenColumnMap.get(channelId); if (customHiddenColumns != null) { if (enable) { customHiddenColumns.remove(columnName); } else { customHiddenColumns.add(columnName); } } } saveColumnOrder(); } }); columnMenu.add(menuItem); } columnMenu.addSeparator(); JMenuItem menuItem = new JMenuItem("Collapse All"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { collapseAll(); } }); columnMenu.add(menuItem); menuItem = new JMenuItem("Expand All"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { expandAll(); } }); columnMenu.add(menuItem); columnMenu.addSeparator(); menuItem = new JMenuItem("Restore Default"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (metaDataColumns != null) { defaultVisibleColumns.addAll(metaDataColumns); } restoreDefaultColumnPreferences(); } }); columnMenu.add(menuItem); return columnMenu; }
From source file:com.net2plan.gui.utils.topologyPane.TopologyPanel.java
/** * Default constructor.//from w ww. j av a 2 s. c o m * * @param callback Topology callback listening plugin events * @param defaultDesignDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/networkTopologies}) * @param defaultDemandDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/trafficMatrices}) * @param canvasType Canvas type (i.e. JUNG) * @param plugins List of plugins to be included (it may be null) */ public TopologyPanel(final IVisualizationCallback callback, File defaultDesignDirectory, File defaultDemandDirectory, Class<? extends ITopologyCanvas> canvasType, List<ITopologyCanvasPlugin> plugins) { File currentDir = SystemUtils.getCurrentDir(); this.callback = callback; this.defaultDesignDirectory = defaultDesignDirectory == null ? new File( currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator() + "data" + SystemUtils.getDirectorySeparator() + "networkTopologies") : defaultDesignDirectory; this.defaultDemandDirectory = defaultDemandDirectory == null ? new File( currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator() + "data" + SystemUtils.getDirectorySeparator() + "trafficMatrices") : defaultDemandDirectory; this.multilayerControlPanel = new MultiLayerControlPanel(callback); try { canvas = canvasType.getDeclaredConstructor(IVisualizationCallback.class, TopologyPanel.class) .newInstance(callback, this); } catch (Exception e) { throw new RuntimeException(e); } if (plugins != null) for (ITopologyCanvasPlugin plugin : plugins) addPlugin(plugin); setLayout(new BorderLayout()); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true); toolbar.setFloatable(false); toolbar.setOpaque(false); toolbar.setBorderPainted(false); JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(toolbar, BorderLayout.NORTH); add(topPanel, BorderLayout.NORTH); JComponent canvasComponent = canvas.getCanvasComponent(); canvasPanel = new JPanel(new BorderLayout()); canvasComponent.setBorder(LineBorder.createBlackLineBorder()); JToolBar multiLayerToolbar = new JToolBar(JToolBar.VERTICAL); multiLayerToolbar.setRollover(true); multiLayerToolbar.setFloatable(false); multiLayerToolbar.setOpaque(false); canvasPanel.add(canvasComponent, BorderLayout.CENTER); canvasPanel.add(multiLayerToolbar, BorderLayout.WEST); add(canvasPanel, BorderLayout.CENTER); btn_load = new JButton(); btn_load.setToolTipText("Load a network design"); btn_loadDemand = new JButton(); btn_loadDemand.setToolTipText("Load a traffic demand set"); btn_save = new JButton(); btn_save.setToolTipText("Save current state to a file"); btn_zoomIn = new JButton(); btn_zoomIn.setToolTipText("Zoom in"); btn_zoomOut = new JButton(); btn_zoomOut.setToolTipText("Zoom out"); btn_zoomAll = new JButton(); btn_zoomAll.setToolTipText("Zoom all"); btn_takeSnapshot = new JButton(); btn_takeSnapshot.setToolTipText("Take a snapshot of the canvas"); btn_showNodeNames = new JToggleButton(); btn_showNodeNames.setToolTipText("Show/hide node names"); btn_showLinkIds = new JToggleButton(); btn_showLinkIds.setToolTipText( "Show/hide link utilization, measured as the ratio between the total traffic in the link (including that in protection segments) and total link capacity (including that reserved by protection segments)"); btn_showNonConnectedNodes = new JToggleButton(); btn_showNonConnectedNodes.setToolTipText("Show/hide non-connected nodes"); btn_increaseNodeSize = new JButton(); btn_increaseNodeSize.setToolTipText("Increase node size"); btn_decreaseNodeSize = new JButton(); btn_decreaseNodeSize.setToolTipText("Decrease node size"); btn_increaseFontSize = new JButton(); btn_increaseFontSize.setToolTipText("Increase font size"); btn_decreaseFontSize = new JButton(); btn_decreaseFontSize.setToolTipText("Decrease font size"); /* Multilayer buttons */ btn_increaseInterLayerDistance = new JButton(); btn_increaseInterLayerDistance .setToolTipText("Increase the distance between layers (when more than one layer is visible)"); btn_decreaseInterLayerDistance = new JButton(); btn_decreaseInterLayerDistance .setToolTipText("Decrease the distance between layers (when more than one layer is visible)"); btn_showLowerLayerInfo = new JToggleButton(); btn_showLowerLayerInfo .setToolTipText("Shows the links in lower layers that carry traffic of the picked element"); btn_showLowerLayerInfo.setSelected(getVisualizationState().isShowInCanvasLowerLayerPropagation()); btn_showUpperLayerInfo = new JToggleButton(); btn_showUpperLayerInfo.setToolTipText( "Shows the links in upper layers that carry traffic that appears in the picked element"); btn_showUpperLayerInfo.setSelected(getVisualizationState().isShowInCanvasUpperLayerPropagation()); btn_showThisLayerInfo = new JToggleButton(); btn_showThisLayerInfo.setToolTipText( "Shows the links in the same layer as the picked element, that carry traffic that appears in the picked element"); btn_showThisLayerInfo.setSelected(getVisualizationState().isShowInCanvasThisLayerPropagation()); btn_npChangeUndo = new JButton(); btn_npChangeUndo.setToolTipText( "Navigate back to the previous state of the network (last time the network design was changed)"); btn_npChangeRedo = new JButton(); btn_npChangeRedo.setToolTipText( "Navigate forward to the next state of the network (when network design was changed"); btn_osmMap = new JToggleButton(); btn_osmMap.setToolTipText( "Toggle between on/off the OSM support. An internet connection is required in order for this to work."); btn_tableControlWindow = new JButton(); btn_tableControlWindow.setToolTipText("Show the network topology control window."); // MultiLayer control window JPopupMenu multiLayerPopUp = new JPopupMenu(); multiLayerPopUp.add(multilayerControlPanel); JPopUpButton btn_multilayer = new JPopUpButton("", multiLayerPopUp); btn_reset = new JButton("Reset"); btn_reset.setToolTipText("Reset the user interface"); btn_reset.setMnemonic(KeyEvent.VK_R); btn_load.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDesign.png"))); btn_loadDemand.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDemand.png"))); btn_save.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/saveDesign.png"))); btn_showNodeNames .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNodeName.png"))); btn_showLinkIds .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLinkUtilization.png"))); btn_showNonConnectedNodes.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png"))); //btn_whatIfActivated.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png"))); btn_zoomIn.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomIn.png"))); btn_zoomOut.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomOut.png"))); btn_zoomAll.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomAll.png"))); btn_takeSnapshot.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/takeSnapshot.png"))); btn_increaseNodeSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseNode.png"))); btn_decreaseNodeSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseNode.png"))); btn_increaseFontSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseFont.png"))); btn_decreaseFontSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseFont.png"))); btn_increaseInterLayerDistance.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseLayerDistance.png"))); btn_decreaseInterLayerDistance.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseLayerDistance.png"))); btn_multilayer .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerControl.png"))); btn_showThisLayerInfo .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerPropagation.png"))); btn_showUpperLayerInfo.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerUpperPropagation.png"))); btn_showLowerLayerInfo.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerLowerPropagation.png"))); btn_tableControlWindow .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showControl.png"))); btn_osmMap.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showOSM.png"))); btn_npChangeUndo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/undoButton.png"))); btn_npChangeRedo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/redoButton.png"))); btn_load.addActionListener(this); btn_loadDemand.addActionListener(this); btn_save.addActionListener(this); btn_showNodeNames.addActionListener(this); btn_showLinkIds.addActionListener(this); btn_showNonConnectedNodes.addActionListener(this); btn_zoomIn.addActionListener(this); btn_zoomOut.addActionListener(this); btn_zoomAll.addActionListener(this); btn_takeSnapshot.addActionListener(this); btn_reset.addActionListener(this); btn_increaseInterLayerDistance.addActionListener(this); btn_decreaseInterLayerDistance.addActionListener(this); btn_showLowerLayerInfo.addActionListener(this); btn_showUpperLayerInfo.addActionListener(this); btn_showThisLayerInfo.addActionListener(this); btn_increaseNodeSize.addActionListener(this); btn_decreaseNodeSize.addActionListener(this); btn_increaseFontSize.addActionListener(this); btn_decreaseFontSize.addActionListener(this); btn_npChangeUndo.addActionListener(this); btn_npChangeRedo.addActionListener(this); btn_osmMap.addActionListener(this); btn_tableControlWindow.addActionListener(this); toolbar.add(btn_load); toolbar.add(btn_loadDemand); toolbar.add(btn_save); toolbar.add(new JToolBar.Separator()); toolbar.add(btn_zoomIn); toolbar.add(btn_zoomOut); toolbar.add(btn_zoomAll); toolbar.add(btn_takeSnapshot); toolbar.add(new JToolBar.Separator()); toolbar.add(btn_showNodeNames); toolbar.add(btn_showLinkIds); toolbar.add(btn_showNonConnectedNodes); toolbar.add(new JToolBar.Separator()); toolbar.add(btn_increaseNodeSize); toolbar.add(btn_decreaseNodeSize); toolbar.add(btn_increaseFontSize); toolbar.add(btn_decreaseFontSize); toolbar.add(new JToolBar.Separator()); toolbar.add(Box.createHorizontalGlue()); toolbar.add(btn_osmMap); toolbar.add(btn_tableControlWindow); toolbar.add(btn_reset); multiLayerToolbar.add(new JToolBar.Separator()); multiLayerToolbar.add(btn_multilayer); multiLayerToolbar.add(btn_increaseInterLayerDistance); multiLayerToolbar.add(btn_decreaseInterLayerDistance); multiLayerToolbar.add(btn_showLowerLayerInfo); multiLayerToolbar.add(btn_showUpperLayerInfo); multiLayerToolbar.add(btn_showThisLayerInfo); multiLayerToolbar.add(Box.createVerticalGlue()); multiLayerToolbar.add(btn_npChangeUndo); multiLayerToolbar.add(btn_npChangeRedo); this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (e.getComponent().getSize().getHeight() != 0 && e.getComponent().getSize().getWidth() != 0) { canvas.zoomAll(); } } }); List<Component> children = SwingUtils.getAllComponents(this); for (Component component : children) if (component instanceof AbstractButton) component.setFocusable(false); if (ErrorHandling.isDebugEnabled()) { canvas.getCanvasComponent().addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { Point point = e.getPoint(); position.setText("view = " + point + ", NetPlan coord = " + canvas.getCanvasPointFromNetPlanPoint(point)); } }); position = new JLabel(); add(position, BorderLayout.SOUTH); } else { position = null; } new FileDrop(canvasComponent, new LineBorder(Color.BLACK), new FileDrop.Listener() { @Override public void filesDropped(File[] files) { for (File file : files) { try { if (!file.getName().toLowerCase(Locale.getDefault()).endsWith(".n2p")) return; loadDesignFromFile(file); break; } catch (Throwable e) { break; } } } }); btn_showNodeNames.setSelected(getVisualizationState().isCanvasShowNodeNames()); btn_showLinkIds.setSelected(getVisualizationState().isCanvasShowLinkLabels()); btn_showNonConnectedNodes.setSelected(getVisualizationState().isCanvasShowNonConnectedNodes()); final ITopologyCanvasPlugin popupPlugin = new PopupMenuPlugin(callback, this.canvas); addPlugin(new PanGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK)); if (callback.getVisualizationState().isNetPlanEditable() && getCanvas() instanceof JUNGCanvas) addPlugin(new AddLinkGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK, MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK)); addPlugin(popupPlugin); if (callback.getVisualizationState().isNetPlanEditable()) addPlugin(new MoveNodePlugin(callback, canvas, MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK)); setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "Network topology")); // setAllowLoadTrafficDemand(callback.allowLoadTrafficDemands()); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
private JPopupMenu createPopupMenu(boolean over_peak) { JPopupMenu menu = new JPopupMenu(); if (over_peak) { updatePeakActions();/*from ww w . j ava 2 s .c o m*/ ButtonGroup group = new ButtonGroup(); if (shown_mslevel.equals("ms")) { for (GlycanAction a : theApplication.getPluginManager().getMsPeakActions()) { JRadioButtonMenuItem last = new JRadioButtonMenuItem( new GlycanAction(a, "annotatepeaks", -1, "", this)); menu.add(last); last.setSelected(a == ms_action); group.add(last); } } else { for (GlycanAction a : theApplication.getPluginManager().getMsMsPeakActions()) { JRadioButtonMenuItem last = new JRadioButtonMenuItem( new GlycanAction(a, "annotatepeaks", -1, "", this)); menu.add(last); last.setSelected(a == msms_action); group.add(last); } } menu.addSeparator(); } menu.add(theActionManager.get("zoomnone")); menu.add(theActionManager.get("zoomin")); menu.add(theActionManager.get("zoomout")); return menu; }
From source file:ca.sqlpower.swingui.object.VariablesPanel.java
@SuppressWarnings("unchecked") private void showVarsPicker() { final MultiValueMap namespaces = this.variableHelper.getNamespaces(); List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size()); sortedNames.addAll(namespaces.keySet()); Collections.sort(sortedNames, new Comparator<String>() { public int compare(String o1, String o2) { if (o1 == null) { return -1; }//ww w . j av a2 s .c o m if (o2 == null) { return 1; } return o1.compareTo(o2); }; }); final JPopupMenu menu = new JPopupMenu(); for (final String name : sortedNames) { final JMenu subMenu = new JMenu(name); menu.add(subMenu); subMenu.addMenuListener(new MenuListener() { private Timer timer; public void menuSelected(MenuEvent e) { subMenu.removeAll(); subMenu.add(new PleaseWaitAction()); ActionListener menuPopulator = new ActionListener() { public void actionPerformed(ActionEvent e) { if (subMenu.isPopupMenuVisible()) { subMenu.removeAll(); for (Object namespaceO : namespaces.getCollection(name)) { String namespace = (String) namespaceO; logger.debug("Resolving variables for namespace ".concat(namespace)); int nbItems = 0; for (String key : variableHelper.keySet(namespace)) { subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key), (String) key)); nbItems++; } if (nbItems == 0) { subMenu.add(new DummyAction()); logger.debug("No variables found."); } } subMenu.revalidate(); subMenu.getPopupMenu().pack(); } } }; timer = new Timer(700, menuPopulator); timer.setRepeats(false); timer.start(); } public void menuDeselected(MenuEvent e) { timer.stop(); } public void menuCanceled(MenuEvent e) { timer.stop(); } }); } menu.show(varNameText, 0, varNameText.getHeight()); }