List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:ch.descabato.browser.BackupBrowser.java
public static void main2(final String[] args) throws InterruptedException, InvocationTargetException, SecurityException, IOException { if (args.length > 1) throw new IllegalArgumentException( "SYNTAX: java... " + BackupBrowser.class.getName() + " [initialPath]"); SwingUtilities.invokeAndWait(new Runnable() { @Override//from w w w. j a v a 2s. c o m public void run() { tryLoadSubstanceLookAndFeel(); final JFrame f = new JFrame("OtrosVfsBrowser demo"); f.addWindowListener(finishedListener); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); DataConfiguration dc = null; final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); File favoritesFile = new File("favorites.properties"); propertiesConfiguration.setFile(favoritesFile); if (favoritesFile.exists()) { try { propertiesConfiguration.load(); } catch (ConfigurationException e) { e.printStackTrace(); } } dc = new DataConfiguration(propertiesConfiguration); propertiesConfiguration.setAutoSave(true); final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null); comp.setSelectionMode(SelectionMode.FILES_ONLY); comp.setMultiSelectionEnabled(true); comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) { @Override public void actionPerformed(ActionEvent e) { FileObject[] selectedFiles = comp.getSelectedFiles(); System.out.println("Selected files count=" + selectedFiles.length); for (FileObject selectedFile : selectedFiles) { try { FileSize fileSize = new FileSize(selectedFile.getContent().getSize()); System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString()); Desktop.getDesktop() .open(new File(new URI(selectedFile.getURL().toExternalForm()))); // byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l); // JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes))); // JDialog d = new JDialog(f); // d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI()); // d.getContentPane().add(sp); // d.setSize(600, 400); // d.setVisible(true); } catch (Exception e1) { LOGGER.error("Failed to read file", e1); JOptionPane.showMessageDialog(f, (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent e) { f.dispose(); try { propertiesConfiguration.save(); } catch (ConfigurationException e1) { e1.printStackTrace(); } System.exit(0); } }); contentPane.add(comp); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); while (!finished) Thread.sleep(100); }
From source file:org.apache.jmeter.gui.action.SearchTreeDialog.java
@Override protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); // Hide Window on ESC Action escapeAction = new AbstractAction("ESCAPE") { private static final long serialVersionUID = -6543764044868772971L; @Override/*from ww w.ja v a2 s . c o m*/ public void actionPerformed(ActionEvent actionEvent) { setVisible(false); } }; // Do search on Enter Action enterAction = new AbstractAction("ENTER") { private static final long serialVersionUID = -3661361497864527363L; @Override public void actionPerformed(ActionEvent actionEvent) { doSearch(actionEvent); } }; ActionMap actionMap = rootPane.getActionMap(); actionMap.put(escapeAction.getValue(Action.NAME), escapeAction); actionMap.put(enterAction.getValue(Action.NAME), enterAction); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME)); inputMap.put(KeyStrokes.ENTER, enterAction.getValue(Action.NAME)); return rootPane; }
From source file:biomine.bmvis2.pipeline.NodeLabelOperation.java
public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { JPanel ret = new JPanel(); ret.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1;//from w w w . ja va 2 s . c o m c.weighty = 0; c.gridy = 0; final Set<String> avail = graph.getAvailableNodeLabels(); for (final String str : avail) { final JCheckBox box = new JCheckBox(); box.setSelected(enabledLabels.contains(str)); box.setAction(new AbstractAction(str) { public void actionPerformed(ActionEvent arg0) { if (box.isSelected() != enabledLabels.contains(str)) { if (box.isSelected()) enabledLabels.add(str); else enabledLabels.remove(str); v.settingsChanged(false); } } }); ret.add(box, c); c.gridy++; } return ret; }
From source file:gui.ReEditingPopupGraphMousePlugin.java
@SuppressWarnings({ "unchecked", "serial" }) protected void handlePopup(MouseEvent e) { final VisualizationViewer<V, E> vv = (VisualizationViewer<V, E>) e.getSource(); final Layout<V, E> layout = vv.getGraphLayout(); final Graph<V, E> graph = layout.getGraph(); final Point2D p = e.getPoint(); final Point2D ivp = p; GraphElementAccessor<V, E> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final V vertex = pickSupport.getVertex(layout, ivp.getX(), ivp.getY()); final E edge = pickSupport.getEdge(layout, ivp.getX(), ivp.getY()); final PickedState<V> pickedVertexState = vv.getPickedVertexState(); final PickedState<E> pickedEdgeState = vv.getPickedEdgeState(); if (vertex != null) { Set<V> picked = pickedVertexState.getPicked(); if (picked.size() > 0) { if (graph instanceof UndirectedGraph == false) { JMenu directedMenu = new JMenu("Create Directed Edge"); popup.add(directedMenu); for (final V other : picked) { directedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") { public void actionPerformed(ActionEvent e) { graph.addEdge(edgeFactory.create(), other, vertex, EdgeType.DIRECTED); vv.repaint(); }//from ww w . j av a 2 s . c o m }); } } if (graph instanceof DirectedGraph == false) { JMenu undirectedMenu = new JMenu("Create Undirected Edge"); popup.add(undirectedMenu); for (final V other : picked) { undirectedMenu.add(new AbstractAction("[" + other + "," + vertex + "]") { public void actionPerformed(ActionEvent e) { graph.addEdge(edgeFactory.create(), other, vertex); vv.repaint(); } }); } } } popup.add(new AbstractAction("Delete TETRA Vertex") { public void actionPerformed(ActionEvent e) { pickedVertexState.pick(vertex, false); graph.removeVertex(vertex); vv.repaint(); } }); } else if (edge != null) { popup.add(new AbstractAction("Delete Edge") { public void actionPerformed(ActionEvent e) { pickedEdgeState.pick(edge, false); graph.removeEdge(edge); vv.repaint(); } }); } else { popup.add(new AbstractAction("Create TETRA Vertex") { public void actionPerformed(ActionEvent e) { V newVertex = vertexFactory.create(); graph.addVertex(newVertex); layout.setLocation(newVertex, vv.getRenderContext().getMultiLayerTransformer().inverseTransform(p)); vv.repaint(); } }); } if (popup.getComponentCount() > 0) { popup.show(vv, e.getX(), e.getY()); } } }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
/** * Creates a wrapper around an existing action of the component to be used * in menus./*from w w w. j a va2s . c o m*/ * * @param c * base component * @param actionKey * key in the component's ActionMap * @param caption * caption of the action wrapper * @param acceleratorKey * accelerator key of the action wrapper * @return action that translates its * {@link Action#actionPerformed(ActionEvent)} to the underlaying * existing action. */ public static Action createActionWrapper(final JComponent c, final String actionKey, String caption, final String acceleratorKey) { final Action baseAction = c.getActionMap().get(actionKey); Action result = new AbstractAction(caption) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(acceleratorKey)); } @Override public void actionPerformed(ActionEvent e) { ActionEvent newEvent = new ActionEvent(c, e.getID(), actionKey, e.getWhen(), e.getModifiers()); baseAction.actionPerformed(newEvent); } @Override public void setEnabled(boolean newValue) { super.setEnabled(newValue); baseAction.setEnabled(newValue); } }; return result; }
From source file:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java
@SuppressWarnings("unchecked") public OverviewDialog(Window window, String title, @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData, Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider, FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) { super(window, title, ModalityType.MODELESS); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setAlwaysOnTop(true);//from w ww .j a v a2 s .c o m this.fieldViewSelectionModel = fvsm; @SuppressWarnings({ "rawtypes" }) JComboBox activeTiCombo = new JComboBox(comboBoxModel); TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer( curationData.getTraitColorProvider(), tiNameProvider); activeTiCombo.setRenderer(tiCellRenderer); JLabel infoLabel = new JLabel(" "); infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED)); final JFrame[] helpDialog = new JFrame[1]; Action helpAction = new AbstractAction("?") { @Override public void actionPerformed(ActionEvent e) { if (helpDialog[0] != null) { GuiUtil.restoreFrame(helpDialog[0]); } else { JFrame f = new JFrame("Overview Help"); helpDialog[0] = f; f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setAlwaysOnTop(true); f.setLocationRelativeTo(overview); String html = Overview.getOverviewHelpHtml(); JLabel label = new JLabel(html); label.setBorder(new EmptyBorder(0, 10, 0, 10)); f.setContentPane(label); f.pack(); f.setVisible(true); } } }; // Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this); if (window != null) { if (window instanceof JFrame) { System.out.println("Found window: " + ((JFrame) window).getTitle()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); if (helpDialog[0] != null) { helpDialog[0].dispose(); } } }); } KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview"); Box top = Box.createHorizontalBox(); top.add(activeTiCombo); top.add(new JButton(helpAction)); overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel); overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true)); Container cp = getContentPane(); cp.add(top, BorderLayout.NORTH); // cp.add(traitLabel, BorderLayout.NORTH); cp.add(infoLabel, BorderLayout.SOUTH); cp.add(overview, BorderLayout.CENTER); pack(); // setResizable(false); // setLocationRelativeTo(showOverviewButton); // DEFAULT POSITION is "out of the way" setVisible(true); this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener); addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent e) { toFront(); } @Override public void windowClosed(WindowEvent e) { fieldViewSelectionModel.removeListSelectionListener(listSelectionListener); removeWindowListener(this); } }); }
From source file:com.diversityarrays.kdxplore.vistool.VisToolbarFactory.java
static public VisToolToolBar create(final String title, final JComponent comp, final Closure<File> snapshotter, final VisToolDataProvider visToolDataProvider, boolean floatable, final String[] imageSuffixes) { Window window = GuiUtil.getOwnerWindow(comp); boolean anyButtons = false; final JCheckBox keepOnTop; if (window == null) { keepOnTop = null;/*w ww . j av a 2 s .c om*/ } else { anyButtons = true; keepOnTop = new JCheckBox(Msg.OPTION_KEEP_ON_TOP(), true); keepOnTop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.setAlwaysOnTop(keepOnTop.isSelected()); } }); window.setAlwaysOnTop(keepOnTop.isSelected()); // buttons.add(keepOnTop); final PropertyChangeListener alwaysOnTopListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { keepOnTop.setSelected(window.isAlwaysOnTop()); } }; window.addPropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { window.removeWindowListener(this); window.removePropertyChangeListener(PROPERTY_ALWAYS_ON_TOP, alwaysOnTopListener); } }); } final JButton cameraButton; if (snapshotter == null) { cameraButton = null; } else { Action cameraAction = new AbstractAction(Msg.ACTION_SNAPSHOT()) { @Override public void actionPerformed(ActionEvent e) { if (chooser == null) { chooser = new JFileChooser(); chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (!f.isFile()) { return true; } String loname = f.getName().toLowerCase(); for (String sfx : imageSuffixes) { if (loname.endsWith(sfx)) { return true; } } return false; } @Override public String getDescription() { return Msg.DESC_IMAGE_FILE(); } }); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); } if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(comp)) { File file = chooser.getSelectedFile(); snapshotter.execute(file); } } }; ImageIcon icon = loadIcon("camera-24.png"); //$NON-NLS-1$ if (icon != null) { cameraAction.putValue(Action.SMALL_ICON, icon); cameraAction.putValue(Action.NAME, null); } anyButtons = true; cameraButton = new JButton(cameraAction); } final JButton refreshButton; if (visToolDataProvider == null) { refreshButton = null; } else { anyButtons = true; refreshButton = new JButton(Msg.ACTION_REFRESH()); ImageIcon icon = loadIcon("refresh-24.png"); //$NON-NLS-1$ if (icon != null) { refreshButton.setIcon(icon); // don't remove the name } refreshButton.setForeground(Color.RED); refreshButton.setEnabled(false); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (visToolDataProvider.refreshData()) { refreshButton.setEnabled(false); } } }); visToolDataProvider.addVisToolDataChangedListener(new VisToolDataChangedListener() { @Override public void visToolDataChanged(Object source) { refreshButton.setEnabled(true); } }); } VisToolToolBar toolBar = null; if (anyButtons) { toolBar = new VisToolToolBar(keepOnTop, cameraButton, refreshButton); toolBar.setFloatable(floatable); } return toolBar; }
From source file:com.employee.scheduler.nurserostering.swingui.NurseRosteringPanel.java
private JPanel createHeaderPanel() { JPanel headerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); headerPanel.add(new JLabel("Planning window start:")); planningWindowStartField = new JTextField(10); planningWindowStartField.setEditable(false); headerPanel.add(planningWindowStartField); advancePlanningWindowStartAction = new AbstractAction("Advance 1 day into the future") { public void actionPerformed(ActionEvent e) { advancePlanningWindowStart(); }/*from w ww .j av a 2 s.c o m*/ }; advancePlanningWindowStartAction.setEnabled(false); headerPanel.add(new JButton(advancePlanningWindowStartAction)); return headerPanel; }
From source file:org.optaplanner.examples.nurserostering.swingui.NurseRosteringPanel.java
private JPanel createHeaderPanel() { JPanel headerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); headerPanel.add(new JLabel("Planning window start:")); planningWindowStartField = new JTextField(10); planningWindowStartField.setEditable(false); headerPanel.add(planningWindowStartField); advancePlanningWindowStartAction = new AbstractAction("Advance 1 day into the future") { @Override/*from ww w . j a v a2s. com*/ public void actionPerformed(ActionEvent e) { advancePlanningWindowStart(); } }; advancePlanningWindowStartAction.setEnabled(false); headerPanel.add(new JButton(advancePlanningWindowStartAction)); return headerPanel; }
From source file:turtlekit.viewer.StatesPerSecondCharter.java
@Override public void setupFrame(JFrame frame) { final ChartPanel chartPanel = ChartsUtil.createChartPanel(dataset, "States Per Second", null, null); chartPanel.setPreferredSize(new java.awt.Dimension(550, 250)); // frame.setContentPane(chartPanel); frame.add(chartPanel);/* www.j a v a2s.co m*/ frame.add(new JButton(new AbstractAction("clear") { @Override public void actionPerformed(ActionEvent e) { serie.clear(); } }), BorderLayout.SOUTH); frame.setLocation(50, 0); }