List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:net.sourceforge.jasa.view.OrderBookView.java
@Override public void afterPropertiesSet() throws Exception { this.setModel(this); this.setPreferredSize(new Dimension(400, 200)); JPopupMenu popup = new JPopupMenu(); popup.add(new AbstractAction("Inspect order") { @Override//from w w w . ja v a 2 s . c o m public void actionPerformed(ActionEvent e) { int row = getSelectedRow(); int column = getSelectedColumn(); Order order = null; if (column > 1) { order = asks.get(row); } else { order = bids.get(row); } if (order != null) { Inspector.inspect(order); } } }); setComponentPopupMenu(popup); }
From source file:com.intel.stl.ui.common.view.JumpChartPanel.java
protected JMenu addJumpMenu(JPopupMenu popup) { return JumpPopupUtil.appendPopupMenu(popup, true, new IActionCreator() { @Override/*from w w w .ja v a 2 s. com*/ public Action createAction(final JumpDestination destination) { return new AbstractAction(destination.getName()) { private static final long serialVersionUID = -2231031530367349855L; @Override public void actionPerformed(ActionEvent e) { if (jumpToEntity != null) { fireJumpEvent(jumpToEntity.getKey(), destination); } } }; } }); }
From source file:biomine.bmvis2.pipeline.BestPathHiderOperation.java
public JComponent getSettingsComponent(final SettingsChangeCallback settingsChangeCallback, final VisualGraph graph) { long nodeCount = graph.getAllNodes().size(); if (oldCount != 0) { long newTarget = (target * nodeCount) / oldCount; this.target = Math.max(newTarget, target); } else/*w w w.j ava 2 s .c om*/ this.target = nodeCount; this.oldCount = nodeCount; JPanel ret = new JPanel(); // if int overflows, we're fucked final JSlider sl = new JSlider(0, (int) nodeCount, (int) Math.min(target, nodeCount)); sl.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (target == sl.getValue()) return; target = sl.getValue(); settingsChangeCallback.settingsChanged(false); } }); ret.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; //c.gridwidth=2; ret.add(sl, c); c.gridy++; int choices = graph.getNodesOfInterest().size() + 1; Object[] items = new Object[choices]; items[0] = "All PoIs"; for (int i = 1; i < choices; i++) { items[i] = i + " nearest"; } final JComboBox pathTypeBox = new JComboBox(items); pathTypeBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int i = pathTypeBox.getSelectedIndex(); grader.setPathK(i); settingsChangeCallback.settingsChanged(false); } }); ret.add(new JLabel("hide by best path quality to:"), c); c.gridy++; ret.add(pathTypeBox, c); c.gridy++; System.out.println("new confpane nodeCount = " + nodeCount); final JCheckBox useMatchingColoring = new JCheckBox(); ret.add(useMatchingColoring, c); useMatchingColoring.setAction(new AbstractAction("Use matching coloring") { public void actionPerformed(ActionEvent arg0) { matchColoring = useMatchingColoring.isSelected(); settingsChangeCallback.settingsChanged(false); } }); useMatchingColoring.setAlignmentX(JComponent.CENTER_ALIGNMENT); c.gridy++; final JCheckBox labelsBox = new JCheckBox(); ret.add(labelsBox, c); labelsBox.setAction(new AbstractAction("Show goodness in node labels") { public void actionPerformed(ActionEvent arg0) { showLabel = labelsBox.isSelected(); settingsChangeCallback.settingsChanged(false); } }); return ret; }
From source file:org.nekorp.workflow.desktop.view.AppMainWindow.java
/** * call this somewhere in your GUI construction *//*from w w w .java 2s . c o m*/ private void setupKeyShortcut() { KeyStroke key1 = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK); actionMap.put(key1, new AbstractAction("guardar") { @Override public void actionPerformed(ActionEvent e) { if (editorMonitor.hasChange()) { try { aplication.guardaServicio(); } catch (IllegalArgumentException ex) { //no lo guardo. } } } }); // key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK); // actionMap.put(key1, new AbstractAction("deshacer") { // @Override // public void actionPerformed(ActionEvent e) { // if (editorMonitor.hasChange()) { // editorMonitor.undo(); // } // } // }); // key1 = KeyStroke.getKeyStroke(KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK); // actionMap.put(key1, new AbstractAction("rehacer") { // @Override // public void actionPerformed(ActionEvent e) { // editorMonitor.redo(); // } // }); // add more actions.. KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e); if (actionMap.containsKey(keyStroke)) { final Action a = actionMap.get(keyStroke); final ActionEvent ae = new ActionEvent(e.getSource(), e.getID(), null); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { a.actionPerformed(ae); } }); return true; } return false; } }); }
From source file:maltcms.ui.nb.pipelineRunner.actions.RunMaltcmsPipelinesAction.java
private Action[] buildActions(Lookup lookup) { final IChromAUIProject project = LookupUtils.ensureSingle(lookup, IChromAUIProject.class); Collection<Action> topLevelActions = new ArrayList<>(); File projectPipelinesPath = new File(FileUtil.toFile(project.getLocation()), "pipelines"); File[] maltcmsVersions = projectPipelinesPath.listFiles(new FileFilter() { @Override//w w w . j a v a 2s . com public boolean accept(File f) { return f.isDirectory(); } }); if (maltcmsVersions == null) { return new Action[0]; } Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Found maltcms versions: {0}", Arrays.deepToString(maltcmsVersions)); for (File maltcmsVersion : maltcmsVersions) { Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Checking pipelines below {0}", maltcmsVersion); List<File> c = new ArrayList<>(FileUtils.listFiles(maltcmsVersion, new String[] { "mpl" }, true)); Collections.sort(c, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Found {0} pipeline definitions!", c.size()); Collection<Action> actions = new ArrayList<>(); for (File pipelineFile : c) { FileObject fo = FileUtil.toFileObject(pipelineFile); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding pipeline {0}", pipelineFile.getName()); DataObject dobj; try { dobj = DataObject.find(fo); if (dobj instanceof MaltcmsPipelineFormatDataObject) { final MaltcmsPipelineFormatDataObject mpfdo = (MaltcmsPipelineFormatDataObject) dobj; AbstractAction pipelineRunAction = new AbstractAction(fo.getName()) { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Creating PipelineRunOpenSupport"); PipelineRunOpenSupport pos = new PipelineRunOpenSupport( mpfdo.getPrimaryEntry()); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Calling pos.open()!"); pos.open(); Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Done!"); } }); } }; Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding dataobject action"); actions.add(pipelineRunAction); // subMenu.add(new JMenuItem(pipelineRunAction)); } } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } Logger.getLogger(RunMaltcmsPipelinesAction.class.getName()).log(Level.FINE, "Adding {0} Pipeline specific actions!", actions.size()); topLevelActions.add(Lookup.getDefault().lookup(INodeFactory.class) .createMenuItem(maltcmsVersion.getName(), actions.toArray(new Action[actions.size()]))); } return topLevelActions.toArray(new Action[topLevelActions.size()]); }
From source file:gate.corpora.twitter.Population.java
@Override protected List<Action> buildActions(final NameBearerHandle handle) { List<Action> actions = new ArrayList<Action>(); if (!(handle.getTarget() instanceof Corpus)) return actions; actions.add(new AbstractAction("Populate from Twitter JSON files") { private static final long serialVersionUID = -8511779592856786327L; @Override/*from w w w . j av a 2s . c o m*/ public void actionPerformed(ActionEvent e) { final PopulationDialogWrapper dialog = new PopulationDialogWrapper(); // If no files were selected then just stop try { final List<URL> fileUrls = dialog.getFileUrls(); if ((fileUrls == null) || fileUrls.isEmpty()) { return; } // Run the population in a separate thread so we don't lock up the GUI Thread thread = new Thread(Thread.currentThread().getThreadGroup(), "Twitter JSON Corpus Populator") { public void run() { try { for (URL fileUrl : fileUrls) { populateCorpus((Corpus) handle.getTarget(), fileUrl, dialog.getEncoding(), dialog.getContentKeys(), dialog.getFeatureKeys(), dialog.getTweetsPerDoc()); } } catch (ResourceInstantiationException e) { e.printStackTrace(); } } }; thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } catch (MalformedURLException e0) { e0.printStackTrace(); } } }); return actions; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
@SuppressWarnings("serial") private Action getEditableAction() { if (editableAction == null) { String actionCommand = bundle.getString(EDITABLE_NODE_KEY); String actionKey = bundle.getString(EDITABLE_NODE_KEY + ".action"); editableAction = new AbstractAction(actionCommand) { @Override// w ww . j ava2 s .c o m public void actionPerformed(ActionEvent e) { if (editCheckboxEnable) { editable = !editable; updateView(); } } }; editableAction.setEnabled(editCheckboxEnable); editableAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); } return this.editableAction; }
From source file:jgraph.JShow.java
/** * a driver for this demo// w ww . ja v a2 s .c o m */ @SuppressWarnings("serial") public static void showtest(DirectedOrderedSparseMultigraph<Object, Object> graph) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JShow demo = new JShow(graph); JMenu menu = new JMenu("Snapshot"); menu.add(new AbstractAction("To JPEG") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:EHRAppointment.ChartPanelDraw.java
private JButton createZoom() { // To enable and desable zoom final JButton auto = new JButton(new AbstractAction("Auto Zoom") { @Override//from ww w. jav a 2 s . co m public void actionPerformed(ActionEvent e) { chartPanel.restoreAutoBounds(); } }); return auto; }
From source file:biomine.bmvis2.pipeline.sources.QueryGraphSource.java
public static QueryGraphSource createFromDialog(Collection<VisualNode> start, String database) { final CrawlSuggestionList sel = new CrawlSuggestionList(); final JDialog dial = new JDialog(); if (database != null) sel.setDatabase(database);/*from ww w . java 2s . co m*/ for (VisualNode vn : start) { if (vn.getBMNode() != null) sel.addNode(vn); } dial.setModalityType(ModalityType.APPLICATION_MODAL); final CrawlQuery q = new CrawlQuery(); // Helper class to pass back data from anonymous inner classes to this method class Z { boolean okPressed = false; } final Z z = new Z(); JButton okButton = new JButton(new AbstractAction("OK") { public void actionPerformed(ActionEvent arg0) { dial.setVisible(false); q.addAll(sel.getQueryTerms()); z.okPressed = true; } }); JPanel pane = new JPanel(); pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1; c.weighty = 1; c.fill = c.BOTH; c.gridwidth = 2; c.gridx = 0; c.gridy = 0; pane.add(sel, c); c.weighty = 0; c.gridy++; c.fill = c.HORIZONTAL; c.gridwidth = 1; pane.add(okButton, c); dial.setContentPane(pane); dial.setSize(600, 500); dial.setVisible(true);//this will hopefully block if (z.okPressed) { if (q.size() == 0) { JOptionPane.showMessageDialog(dial, "At least 1 edge must be selected: no queries added"); return null; } return new QueryGraphSource(q, sel.getDatabase()); } return null; }