List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction()
From source file:FileTree3.java
public FileTree3() { super("Directories Tree [Tool Tips]"); setSize(400, 300);//from w ww . ja va 2 s . co m DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer")); DefaultMutableTreeNode node; File[] roots = File.listRoots(); for (int k = 0; k < roots.length; k++) { node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k]))); top.add(node); node.add(new DefaultMutableTreeNode(new Boolean(true))); } m_model = new DefaultTreeModel(top); // NEW m_tree = new JTree(m_model) { public String getToolTipText(MouseEvent ev) { if (ev == null) return null; TreePath path = m_tree.getPathForLocation(ev.getX(), ev.getY()); if (path != null) { FileNode fnode = getFileNode(getTreeNode(path)); if (fnode == null) return null; File f = fnode.getFile(); return (f == null ? null : f.getPath()); } return null; } }; ToolTipManager.sharedInstance().registerComponent(m_tree); m_tree.putClientProperty("JTree.lineStyle", "Angled"); TreeCellRenderer renderer = new IconCellRenderer(); m_tree.setCellRenderer(renderer); m_tree.addTreeExpansionListener(new DirExpansionListener()); m_tree.addTreeSelectionListener(new DirSelectionListener()); m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); m_tree.setShowsRootHandles(true); m_tree.setEditable(false); JScrollPane s = new JScrollPane(); s.getViewport().add(m_tree); getContentPane().add(s, BorderLayout.CENTER); m_display = new JTextField(); m_display.setEditable(false); getContentPane().add(m_display, BorderLayout.NORTH); m_popup = new JPopupMenu(); m_action = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (m_clickedPath == null) return; if (m_tree.isExpanded(m_clickedPath)) m_tree.collapsePath(m_clickedPath); else m_tree.expandPath(m_clickedPath); } }; m_popup.add(m_action); m_popup.addSeparator(); Action a1 = new AbstractAction("Delete") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree3.this, "Delete option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a1); Action a2 = new AbstractAction("Rename") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree3.this, "Rename option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a2); m_tree.add(m_popup); m_tree.addMouseListener(new PopupTrigger()); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:de.codesourcery.eve.skills.ui.utils.PopupMenuBuilder.java
public PopupMenuBuilder addItem(String label, final Runnable r) { this.entries.add(new MyMenuItem(label, new AbstractAction() { @Override//from www . j a va 2 s. co m public boolean isEnabled() { return true; } @Override public void actionPerformed(ActionEvent e) { r.run(); } })); return this; }
From source file:net.java.sip.communicator.plugin.propertieseditor.SearchField.java
/** * Creates an instance <tt>SearchField</tt>. * /* ww w. j a v a 2s . c o m*/ * @param text the text we would like to enter by default * @param sorter the sorter which will be used for filtering. */ public SearchField(String text, JTable table) { super(text); this.table = table; ComponentUI ui = getUI(); if (ui instanceof SearchFieldUI) { SearchFieldUI searchFieldUI = (SearchFieldUI) ui; searchFieldUI.setCallButtonEnabled(false); searchFieldUI.setDeleteButtonEnabled(true); } setBorder(null); setDragEnabled(true); setOpaque(false); setPreferredSize(new Dimension(100, 25)); InputMap imap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); ActionMap amap = getActionMap(); @SuppressWarnings("serial") AbstractAction escapeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { setText(""); } }; amap.put("escape", escapeAction); getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { } public void insertUpdate(DocumentEvent e) { filter(getText()); } public void removeUpdate(DocumentEvent e) { filter(getText()); } }); loadSkin(); }
From source file:hermes.browser.dialog.EditNamingConfigDialog.java
/** * @param parent// w w w .j a va2s.com * @param name * @param modal */ public EditNamingConfigDialog(Frame parent, String selectedConfig, List namingConfigs) { super(parent, "JNDI InitialContext", true); this.namingConfigs = namingConfigs; this.selectedConfig = selectedConfig; setDefaultAction(new AbstractAction() { /** * */ private static final long serialVersionUID = -8231223040278773071L; public void actionPerformed(ActionEvent e) { onOK(); } }); }
From source file:fi.smaa.jsmaa.gui.views.ResultsView.java
@SuppressWarnings("serial") private Component buildExportButton() { JButton exportButton = new JideButton("Export figure dataset as GNUPlot script", ImageFactory.IMAGELOADER.getIcon(scriptIcon)); exportButton.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent arg0) { PlotConverter c = PlotConverterFactory .getConverter((SMAADataSet<?>) ((CategoryPlot) chart.getPlot()).getDataset()); GNUPlotDialog d = new GNUPlotDialog(null, c); GUIHelper.centerWindow(d, parent); d.setVisible(true);// w ww . j ava 2 s. c o m } }); return exportButton; }
From source file:com.keevosh.springframework.boot.netbeans.SpringBootConfigurationCompletionDocumentation.java
@Override public Action getGotoSourceAction() { String sourceType = item.getConfigurationItem().getSourceType(); if (null == sourceType) { return null; }// w ww . j a v a 2s . co m final FileObject fo = item.getClassPath().findResource(sourceType.replaceAll("\\.", "/").concat(".class")); if (null == fo) { return null; } return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { DataObject dataObject; dataObject = DataObject.find(fo); OpenCookie oc = dataObject.getLookup().lookup(org.openide.cookies.OpenCookie.class); if (oc != null) { oc.open(); } } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } }; }
From source file:com.isecpartners.gizmo.FourthIdea.java
public FourthIdea(final BlobScroller scroller, final HTTPMessage msg, final boolean request) { try {/*from www .j a v a2s .com*/ this.buffer_file = File.createTempFile("tmp", "end"); } catch (IOException ex) { Logger.getLogger(FourthIdea.class.getName()).log(Level.SEVERE, null, ex); } initComponents(); init(scroller, msg.contents(), new AbstractAction() { public void actionPerformed(ActionEvent e) { if (request) { scroller.setCommand(jTextPane1.getText(), request, (HttpRequest) msg); } FourthIdea.this.dispose(); } }); }
From source file:org.rdv.ui.ConsoleDialog.java
public ConsoleDialog(JDialog owner) { super(owner); setName("consoleDialog"); setDefaultCloseOperation(AboutDialog.DISPOSE_ON_CLOSE); JPanel container = new JPanel(); container.setLayout(new BorderLayout()); container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); setContentPane(container);/* w w w . ja va 2 s . c o m*/ InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = container.getActionMap(); Action disposeAction = new AbstractAction() { /** serialized version identifier */ private static final long serialVersionUID = 4380189911762232261L; public void actionPerformed(ActionEvent ae) { dispose(); } }; Action copyAction = new AbstractAction() { /** serialized version identifier */ private static final long serialVersionUID = 2596081241883913660L; public void actionPerformed(ActionEvent e) { textArea.selectAll(); textArea.copy(); } }; // Action scrollLockAction = new AbstractAction() { // /** serialized version identifier */ // private static final long serialVersionUID = -8089076016097529064L; // // public void actionPerformed(ActionEvent e) { // //toggle scroll lock // scrollLock_=!scrollLock_; // } // }; disposeAction.putValue(Action.NAME, "OK"); inputMap.put(KeyStroke.getKeyStroke("ENTER"), "dispose"); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "dispose"); actionMap.put("dispose", disposeAction); copyAction.putValue(Action.NAME, "Copy"); actionMap.put("copy", copyAction); // actionMap.put("scroll lock", scrollLockAction); // scrollLockAction.putValue(Action.NAME, "Scroll Lock"); textArea = new JTextArea(); textArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); textArea.setBackground(Color.WHITE); textArea.setForeground(Color.BLACK); textArea.setEditable(false); textArea.setLineWrap(false); Iterator<String> msgIt = messageBuffer.getMessages().iterator(); //add all the messages in the buffer to this point while (msgIt.hasNext()) { addMessage(msgIt.next()); } JScrollPane scrollPane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(640, 480)); container.add(scrollPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JButton okButton = new JButton(disposeAction); buttonPanel.add(okButton, BorderLayout.EAST); JPanel leftBtnsPanel = new JPanel(); leftBtnsPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); buttonPanel.add(leftBtnsPanel, BorderLayout.WEST); JButton copyButton = new JButton(copyAction); leftBtnsPanel.add(copyButton); // JButton scrollLockButton = new JButton(scrollLockAction); // leftBtnsPanel.add(scrollLockButton); container.add(buttonPanel, BorderLayout.SOUTH); // inject resources from the properties for this component ResourceMap resourceMap = RDV.getInstance().getContext().getResourceMap(getClass()); resourceMap.injectComponents(this); pack(); okButton.requestFocusInWindow(); setLocationByPlatform(true); setVisible(true); messageBuffer.addObserver(this); }
From source file:edu.ucla.stat.SOCR.chart.SuperPowerChart.java
protected void createActionComponents(JToolBar toolBar) { JButton button = null;//w ww. j a v a 2 s . c o m toolBar.setFloatable(false); /**************** Demo Tab****************/ if (useStaticExample) { exampleStaticAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { // Create First Example reset(); resetTable(); resetMappingList(); resetExample(); if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) == ALL) setMixPanel(); updateStatus(url); validate(); } }; button = toolBar.add(exampleStaticAction); button.setText(EXAMPLE); button.setToolTipText(chartDescription); } /**************** DO-CHART Tab ****************/ computeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { doChart(); } }; button = toolBar.add(computeAction); button.setText(DOCHART); button.setToolTipText("Press this Button to Generate the Chart"); /**************** CLEAR Tab****************/ clearAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { /* somehow reset has to be called more than once to set to the correct header. I'll leave it like this before I figure out why. annie che 20051123 -_- */ reset(); // Need to work out what this means // reset(); resetTable(); resetMappingList(); resetChart(); ChartExampleData exampleNull = new ChartExampleData(0, 0); /* A Null Example (with no data) is used here to reset the table so that when "CLEAR" button is pressed, the cells of dataTable is NOT null. annieche 20060110. */ updateExample(exampleNull); if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) == ALL) setMixPanel(); updateStatus("The Chart has been reset!"); //updateExample(exampleNull); } }; button = toolBar.add(clearAction); button.setText(CLEAR); button.setToolTipText("Clears All Windows"); /**************** wiki Tab ****************/ Action linkAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { //popInfo("SOCRChart: About", new java.net.URL("http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_Activities_PowerTransformFamily_Graphs"), "SOCR: Power Transform Graphing Activity"); parentApplet.getAppletContext().showDocument(new java.net.URL( "http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials_Activities_PowerTransformFamily_Graphs"), "SOCR: Power Transform Graphing Activity"); } catch (MalformedURLException Exc) { JOptionPane.showMessageDialog(null, Exc, "MalformedURL Error", JOptionPane.ERROR_MESSAGE); Exc.printStackTrace(); } } }; button = toolBar.add(linkAction); //button.setMinimumSize(new Dimension(110, 20)); button.setText(" WIKI_Activity "); button.setToolTipText("Press this Button to go to SOCR_POWER_Activity wiki page"); /**************** TEST Tab ****************/ testAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { doTest(); } }; if (TEST_API) { button = toolBar.add(testAction); button.setText(TEST); button.setToolTipText("Press this Button to test the API"); } }
From source file:components.IntegerEditor.java
public IntegerEditor(int min, int max) { super(new JFormattedTextField()); ftf = (JFormattedTextField) getComponent(); minimum = new Integer(min); maximum = new Integer(max); //Set up the editor for the integer cells. integerFormat = NumberFormat.getIntegerInstance(); NumberFormatter intFormatter = new NumberFormatter(integerFormat); intFormatter.setFormat(integerFormat); intFormatter.setMinimum(minimum);// www . java 2 s . com intFormatter.setMaximum(maximum); ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter)); ftf.setValue(minimum); ftf.setHorizontalAlignment(JTextField.TRAILING); ftf.setFocusLostBehavior(JFormattedTextField.PERSIST); //React when the user presses Enter while the editor is //active. (Tab is handled as specified by //JFormattedTextField's focusLostBehavior property.) ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check"); ftf.getActionMap().put("check", new AbstractAction() { public void actionPerformed(ActionEvent e) { if (!ftf.isEditValid()) { //The text is invalid. if (userSaysRevert()) { //reverted ftf.postActionEvent(); //inform the editor } } else try { //The text is valid, ftf.commitEdit(); //so use it. ftf.postActionEvent(); //stop editing } catch (java.text.ParseException exc) { } } }); }