List of usage examples for javax.swing JPopupMenu JPopupMenu
public JPopupMenu()
JPopupMenu
without an "invoker". From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
@Override protected JButton buildToolBarAddCriterionButton() { JButton button = new JButton(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADDCRITERION)); button.setToolTipText("Add criterion"); final JPopupMenu addMenu = new JPopupMenu(); addUtilityAddItemsToMenu(addMenu);/*from w w w .j a v a2 s.co m*/ button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { addMenu.show((Component) evt.getSource(), evt.getX(), evt.getY()); } }); return button; }
From source file:components.PopupMenuDemo.java
public void createPopupMenu() { JMenuItem menuItem;/*from w ww.j ava 2s .c om*/ //Create the popup menu. JPopupMenu popup = new JPopupMenu(); menuItem = new JMenuItem("A popup menu item"); menuItem.addActionListener(this); popup.add(menuItem); menuItem = new JMenuItem("Another popup menu item"); menuItem.addActionListener(this); popup.add(menuItem); //Add listener to the text area so the popup menu can come up. MouseListener popupListener = new PopupListener(popup); output.addMouseListener(popupListener); }
From source file:medsavant.enrichment.app.RegionListAggregatePanel.java
private JPopupMenu createPopup() { JPopupMenu menu = new JPopupMenu(); TableModel model = tablePanel.getTable().getModel(); final int[] selRows = tablePanel.getTable().getSelectedRows(); if (selRows.length == 1) { JMenuItem browseItem = new JMenuItem(String.format("<html>Look at %s in genome browser</html>", "<i>" + model.getValueAt(selRows[0], 0) + "</i>")); browseItem.addActionListener(new ActionListener() { @Override//from www . j a v a2 s .c o m public void actionPerformed(ActionEvent ae) { TableModel model = tablePanel.getTable().getModel(); int r = selRows[0]; LocationController.getInstance().setLocation((String) model.getValueAt(r, 1), new Range((Integer) model.getValueAt(r, 2), (Integer) model.getValueAt(r, 3))); ViewController.getInstance().getMenu().switchToSubSection(BrowserPage.getInstance()); } }); menu.add(browseItem); } JMenuItem posItem = new JMenuItem(String.format("<html>Filter by %s</html>", selRows.length == 1 ? "Region <i>" + model.getValueAt(selRows[0], 0) + "</i>" : "Selected Regions")); posItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { ThreadController.getInstance().cancelWorkers(pageName); List<GenomicRegion> regions = new ArrayList<GenomicRegion>(); TableModel model = tablePanel.getTable().getModel(); for (int r : selRows) { String geneName = (String) model.getValueAt(r, 0); String chrom = (String) model.getValueAt(r, 1); Integer start = (Integer) model.getValueAt(r, 2); Integer end = (Integer) model.getValueAt(r, 3); regions.add(new GenomicRegion(geneName, chrom, start, end)); } QueryUtils.addQueryOnRegions(regions, Arrays.asList(new RegionSet[] { (RegionSet) regionSetCombo.getSelectedItem() })); } }); menu.add(posItem); return menu; }
From source file:com.mirth.connect.client.ui.components.MirthTable.java
private JPopupMenu getColumnMenu() { JPopupMenu columnMenu = new JPopupMenu(); DefaultTableModel model = (DefaultTableModel) getModel(); 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// w ww .j av a 2 s . c o m public void actionPerformed(ActionEvent evt) { 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); saveColumnOrder(); } } }); columnMenu.add(menuItem); } columnMenu.addSeparator(); JMenuItem menuItem = new JMenuItem("Restore Default"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { restoreDefaultColumnPreferences(); } }); columnMenu.add(menuItem); return columnMenu; }
From source file:edu.ku.brc.af.ui.db.JAutoCompTextField.java
protected void keyReleasedInternal(KeyEvent ev) { //System.out.println(ev); if (dbAdapter != null) { if (ev.getKeyCode() == JAutoCompComboBox.SEARCH_KEY) { /*lookup(getText()); /*from w w w.j a va 2 s. co m*/ if (!foundMatch) { setText(""); }*/ ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { JMenuItem mi = (JMenuItem) ae.getSource(); int inx = 0; for (PickListItemIFace pli : dbAdapter.getList()) { String title = pli.getTitle(); if (mi.getText().equals(title)) { setSelectedIndex(inx); break; } inx++; } popupMenu = null; } }; String txt = getText(); int cnt = 0; for (PickListItemIFace pli : dbAdapter.getList()) { String title = pli.getTitle(); if (title.length() >= txt.length() && title.startsWith(txt)) { cnt++; } } if (cnt > 0) { popupMenu = new JPopupMenu(); for (PickListItemIFace pli : dbAdapter.getList()) { String title = pli.getTitle(); if (title.length() >= txt.length() && title.startsWith(txt)) { JMenuItem mi = new JMenuItem(title); setControlSize(mi); popupMenu.add(mi); mi.addActionListener(al); } } Point location = getLocation(); Dimension size = getSize(); popupMenu.show(this, location.x, location.y + size.height); } } else if (ev.getKeyCode() == KeyEvent.VK_ENTER) { addNewItemFromTextField(); } else if (ev.getKeyCode() == KeyEvent.VK_END)// || ev.getKeyCode() == KeyEvent.VK_SHIFT) { setSelectionStart(prevCaretPos); setSelectionEnd(getText().length()); } /*else { char key = ev.getKeyChar(); if (ev.getKeyCode() == KeyEvent.VK_BACK_SPACE) { String s = getText(); if (foundMatch) { //System.out.println("len ["+s.length()+"]"); //System.out.println(s+"["+s.substring(0, s.length()-1)+"]"); setText(s.length() == 0 ? "" : s.substring(0, s.length()-1)); } else { hasChanged = true; } return; } else if ((!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) && ev.getKeyCode() != KeyEvent.VK_DELETE) { if (ev.getKeyCode() == KeyEvent.VK_ENTER) { addNewItemFromTextField(); } //System.out.println("Key Code "+ev.getKeyCode()+" Pos: "+getCaretPosition()+" Del: "+KeyEvent.VK_DELETE); if (ev.getKeyCode() == KeyEvent.VK_END)// || ev.getKeyCode() == KeyEvent.VK_SHIFT) { setSelectionStart(prevCaretPos); setSelectionEnd(getText().length()); } return; } else if(ev.getKeyCode() == KeyEvent.VK_DELETE) { foundMatch = false; hasChanged = true; return; } //System.out.println("["+ev.getKeyCode()+"]["+KeyEvent.VK_DELETE+"]"); caretPos = getCaretPosition(); String text = ""; try { text = getText(0, caretPos); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(JAutoCompTextField.class, ex); ex.printStackTrace(); } lookup(text); }*/ } }
From source file:uk.co.markfrimston.tasktree.Main.java
public Main(TaskTree taskTree) { super();//from w w w. j a v a 2 s. c o m this.taskTree = taskTree; this.setTitle("Task Tree"); this.setSize(new Dimension(300, 500)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel quickInPanel = new JPanel(new BorderLayout()); this.quickIn = new JTextArea(); this.quickIn.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_ENTER) { String newText = quickIn.getText().trim(); if (newText != null && newText.length() > 0) { addTask(Main.this.taskTree.getRoot(), 0, newText, true); try { Main.this.taskTree.changesMade(); } catch (Exception e) { error(e.getMessage()); } } quickIn.setText(""); } } }); this.quickIn.setPreferredSize(new Dimension(300, 75)); this.quickIn.setBorder(BorderFactory.createTitledBorder("Quick Input")); quickInPanel.add(this.quickIn, BorderLayout.CENTER); this.syncButton = new JButton("Sync"); this.syncButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new SyncThread(Main.this).start(); } }); quickInPanel.add(this.syncButton, BorderLayout.EAST); this.getContentPane().add(quickInPanel, BorderLayout.NORTH); this.tree = new JTree(taskTree.getTreeModel()); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object newVal = htmlFilter(String.valueOf(node.getUserObject())); if (node.getChildCount() > 0 && !tree.isExpanded(new TreePath(node.getPath()))) { DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) node.getFirstLeaf(); newVal = htmlFilter(String.valueOf(node.getUserObject())) + " <span style='color:silver;font-style:italic'>" + "(" + String.valueOf(firstLeaf.getUserObject()) + ")</span>"; } newVal = "<html>" + newVal + "</html>"; return super.getTreeCellRendererComponent(tree, newVal, selected, expanded, leaf, row, hasFocus); } }; ImageIcon bulletIcon = new ImageIcon(Main.class.getResource("bullet.gif")); renderer.setLeafIcon(bulletIcon); renderer.setOpenIcon(bulletIcon); renderer.setClosedIcon(bulletIcon); renderer.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0)); this.tree.setCellRenderer(renderer); this.tree.setRootVisible(false); this.tree.setShowsRootHandles(true); this.tree.addMouseListener(new MouseAdapter() { protected void doSelectRow(MouseEvent arg0) { int row = tree.getRowForLocation(arg0.getX(), arg0.getY()); if (row != -1) { tree.setSelectionRow(row); if (arg0.isPopupTrigger()) { popup.show(tree, arg0.getX(), arg0.getY()); } } } public void mousePressed(MouseEvent arg0) { doSelectRow(arg0); } public void mouseReleased(MouseEvent arg0) { doSelectRow(arg0); } }); JScrollPane treeScroll = new JScrollPane(tree); treeScroll.setBorder(BorderFactory.createTitledBorder("Task List")); this.getContentPane().add(treeScroll, BorderLayout.CENTER); this.popup = new JPopupMenu(); JMenuItem addBefore = new JMenuItem("Add Before"); addBefore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected); promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addBefore); JMenuItem addAfter = new JMenuItem("Add After"); addAfter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected) + 1; promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addAfter); JMenuItem addNested = new JMenuItem("Add Nested"); addNested.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); int pos = selected.getChildCount(); promptAndInsert(selected, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { ex.getMessage(); } } }); this.popup.add(addNested); this.popup.add(new JSeparator()); JMenuItem moveTop = new JMenuItem("Move to Top"); moveTop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, 0); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveTop); JMenuItem moveUp = new JMenuItem("Move Up"); moveUp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.max(parent.getIndex(selected) - 1, 0); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveUp); JMenuItem moveDown = new JMenuItem("Move Down"); moveDown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.min(parent.getIndex(selected) + 1, parent.getChildCount() - 1); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveDown); JMenuItem moveBottom = new JMenuItem("Move to Bottom"); moveBottom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, parent.getChildCount() - 1); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveBottom); this.popup.add(new JSeparator()); JMenuItem rename = new JMenuItem("Edit"); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); String newText = prompt((String) selected.getUserObject()); if (newText != null && newText.length() > 0) { selected.setUserObject(newText); Main.this.taskTree.getTreeModel().reload(selected); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } } }); this.popup.add(rename); JMenuItem delete = new JMenuItem("Delete"); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptAndRemove(getSelectedNode()); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(delete); this.setVisible(true); loadConfig(); load(); syncButton.setVisible(this.taskTree.hasSyncCapability()); }
From source file:net.sf.maltcms.chromaui.charts.events.ChartPanelMouseListener.java
/** * * @param arg0//ww w . ja v a 2s. c om */ @Override public void chartMouseClicked(final ChartMouseEvent arg0) { final ChartPanelMouseListener cpml = this; if (arg0.getEntity() != null) { if (arg0.getEntity() instanceof XYItemEntity) { XYItemEntity xyie = (XYItemEntity) arg0.getEntity(); if (arg0.getTrigger().getButton() == MouseEvent.BUTTON1) { // if (arg0.getTrigger().isAltDown() && arg0.getTrigger().isShiftDown()) { // System.out.println("Item removed"); fireEvent(new XYItemEntityRemovedEvent((XYItemEntity) arg0.getEntity(), cpml)); } else if (arg0.getTrigger().isAltDown()) { // System.out.println("Item added"); fireEvent(new XYItemEntityAddedEvent((XYItemEntity) arg0.getEntity(), cpml)); } else { setTarget(arg0); // System.out.println("Item clicked"); fireEvent(new XYItemEntityClickedEvent((XYItemEntity) arg0.getEntity(), cpml)); } } } else if (arg0.getEntity() instanceof LegendItemEntity) { JPopupMenu jpm = new JPopupMenu(); final LegendItemEntity lie = (LegendItemEntity) arg0.getEntity(); Dataset ds = lie.getDataset(); Comparable skey = lie.getSeriesKey(); Plot plot = arg0.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot xyplot = arg0.getChart().getXYPlot(); if (xyplot.getSeriesCount() > 1) { XYDataset xyds = (XYDataset) ds; XYItemRenderer xyir = xyplot.getRendererForDataset(xyds); xyir.setSeriesVisible(xyds.indexOf(skey), !xyir.isSeriesVisible(xyds.indexOf(skey))); xyir.setSeriesVisibleInLegend(xyds.indexOf(skey), Boolean.TRUE); } } else if (plot instanceof CategoryPlot) { CategoryPlot cplot = arg0.getChart().getCategoryPlot(); if (cplot.getDatasetCount() > 1) { CategoryDataset cds = (CategoryDataset) ds; CategoryItemRenderer xyir = cplot.getRendererForDataset(cds); int seriesIndex = cds.getColumnIndex(skey); if (seriesIndex == -1) { seriesIndex = cds.getRowIndex(skey); } xyir.setSeriesVisible(seriesIndex, !xyir.isSeriesVisible(seriesIndex)); xyir.setSeriesVisibleInLegend(seriesIndex, Boolean.TRUE); } } // AbstractAction hse = new AbstractAction("Hide") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; // AbstractAction hse = new AbstractAction("Show") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; // AbstractAction hse = new AbstractAction("Remove") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; } } }
From source file:javazoom.jlgui.player.amp.equalizer.ui.EqualizerUI.java
public void loadUI() { log.info("Load EqualizerUI (EDT=" + SwingUtilities.isEventDispatchThread() + ")"); removeAll();//w ww .j a v a 2 s . c o m // Background ImageBorder border = new ImageBorder(); border.setImage(ui.getEqualizerImage()); setBorder(border); // On/Off add(ui.getAcEqOnOff(), ui.getAcEqOnOff().getConstraints()); ui.getAcEqOnOff().removeActionListener(this); ui.getAcEqOnOff().addActionListener(this); // Auto add(ui.getAcEqAuto(), ui.getAcEqAuto().getConstraints()); ui.getAcEqAuto().removeActionListener(this); ui.getAcEqAuto().addActionListener(this); // Sliders add(ui.getAcEqPresets(), ui.getAcEqPresets().getConstraints()); for (int i = 0; i < ui.getAcEqSliders().length; i++) { add(ui.getAcEqSliders()[i], ui.getAcEqSliders()[i].getConstraints()); ui.getAcEqSliders()[i].setValue(maxGain - gainValue[i]); ui.getAcEqSliders()[i].removeChangeListener(this); ui.getAcEqSliders()[i].addChangeListener(this); } if (ui.getSpline() != null) { ui.getSpline().setValues(gainValue); add(ui.getSpline(), ui.getSpline().getConstraints()); } // Popup menu on TitleBar mainpopup = new JPopupMenu(); String[] presets = { "Normal", "Classical", "Club", "Dance", "Full Bass", "Full Bass & Treble", "Full Treble", "Laptop", "Live", "Party", "Pop", "Reggae", "Rock", "Techno" }; JMenuItem mi; for (int p = 0; p < presets.length; p++) { mi = new JMenuItem(presets[p]); mi.removeActionListener(this); mi.addActionListener(this); mainpopup.add(mi); } ui.getAcEqPresets().removeActionListener(this); ui.getAcEqPresets().addActionListener(this); validate(); }
From source file:com.opendoorlogistics.studio.scripts.list.ScriptsPanel.java
/** * Create the panel./* w w w . ja v a 2s .c o m*/ */ public ScriptsPanel(ODLApi api, File directory, ScriptUIManager launchScriptEditor) { this.scriptUIManager = launchScriptEditor; this.api = api; // find a sensible directory if (directory == null) { directory = new File(ScriptConstants.DIRECTORY); if (!directory.exists()) { directory = new File(""); } } this.directory = directory; setLayout(new BorderLayout(0, 0)); // Add directory browser and label at the top in their own panel. // Label is wrapped in a panel because alignment is being ignored and this at least makes it properly centred. // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4275005 boolean lockedDir = scriptUIManager.getAppPermissions().isScriptDirectoryLocked(); if (!lockedDir) { JLabel lblLabel = new JLabel("Scripts directory"); JPanel labelPanel = new JPanel(new BorderLayout()); labelPanel.add(lblLabel, BorderLayout.CENTER); labelPanel.setMaximumSize(lblLabel.getMinimumSize()); dirChooser = new FileBrowserPanel(directory.getAbsolutePath(), new FilenameChangeListener() { @Override public void filenameChanged(String newFilename) { ScriptsPanel.this.directory = new File(newFilename); onDirectoryChanged(ScriptsPanel.this.directory); } }, true, "Select"); JPanel topPanel = LayoutUtils.createVerticalBoxLayout(labelPanel, dirChooser); add(topPanel, BorderLayout.NORTH); } else { dirChooser = null; } // add toolbar at the bottom JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); add(toolBar, BorderLayout.SOUTH); // create all actions and add as buttons and menu items popup = new JPopupMenu(); actions = createActions(launchScriptEditor.getAppPermissions()); for (Action action : actions) { toolBar.add(action); popup.add(action); } // add list in the centre scriptsTree = new ScriptsTree(scriptUIManager, popup); scriptsTree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { ScriptsPanel.this.updateAppearance(); } }); add(scriptsTree.getScrollPane(), BorderLayout.CENTER); // // create selection changed listener on the list // listControl.addListSelectionListener(new ListSelectionListener() { // // @Override // public void valueChanged(ListSelectionEvent e) { // updateAppearance(); // } // }); // finally file the list onDirectoryChanged(directory); }
From source file:it.unibas.spicygui.vista.ProjectTreeTopComponent.java
private void creaPopUp() { this.popUpMenu = new JPopupMenu(); this.popUpMenu.add(this.actionSelectMappingTask); this.popUpMenu.add(this.actionOpenGeneric); this.popUpMenu.add(this.actionRemoveScenario); this.popUpMenu.add(this.actionSettingEngineConfiguration); this.popUpMenu.add(this.actionAddMappingInCompositionScene); this.popUpMenu.add(this.actionCreateCompositionScene); this.jTree.addMouseListener(new PopUpListener()); }