javax.swing.AbstractAction Java Examples
The following examples show how to use
javax.swing.AbstractAction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScenarioEditor.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addTool(final Tool t, JMenu menu, JToolBar toolbar, ButtonGroup menuGroup, ButtonGroup toolbarGroup) { final JToggleButton toggle = new JToggleButton(); final JCheckBoxMenuItem check = new JCheckBoxMenuItem(); Action action = new AbstractAction(t.getName()) { @Override public void actionPerformed(ActionEvent e) { if (currentTool != null) { currentTool.deactivate(); } currentTool = t; toggle.setSelected(true); check.setSelected(true); currentTool.activate(); } }; toggle.setAction(action); check.setAction(action); menu.add(check); toolbar.add(toggle); menuGroup.add(check); toolbarGroup.add(toggle); }
Example #2
Source File: GUIUtils.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
/** * Registers a keyboard handler to a given component * * @param component Component to register the handler to * @param condition see {@link JComponent} and {@link JComponent#WHEN_IN_FOCUSED_WINDOW} * @param stroke Keystroke to activate the handler * @param listener ActionListener to handle the key press * @param actionCommand Action command string */ public static void registerKeyHandler(JComponent component, int condition, KeyStroke stroke, final ActionListener listener, final String actionCommand) { component.getInputMap(condition).put(stroke, actionCommand); component.getActionMap().put(actionCommand, new AbstractAction() { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { ActionEvent newEvent = new ActionEvent(event.getSource(), ActionEvent.ACTION_PERFORMED, actionCommand); listener.actionPerformed(newEvent); } }); }
Example #3
Source File: SqlTemplatesAndActions.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public Action getCheckSpatialIndexAction( ColumnLevel column, DatabaseViewer spatialiteViewer ) { if (sqlTemplates.hasRecoverSpatialIndex()) { return new AbstractAction("Check spatial index"){ @Override public void actionPerformed( ActionEvent e ) { String tableName = column.parent.tableName; String columnName = column.columnName; String query = sqlTemplates.checkSpatialIndex(tableName, columnName); spatialiteViewer.addTextToQueryEditor(query); } }; } else { return null; } }
Example #4
Source File: ButtonFactory.java From openAGV with Apache License 2.0 | 6 votes |
private static JButton createFontStyleBoldButton(DrawingEditor editor) { JButton button = new JButton(); button.setIcon(ImageDirectory.getImageIcon("/toolbar/attributeFontBold.png")); button.setText(null); button.setToolTipText(BUNDLE.getString("buttonFactory.button_fontStyleBold.tooltipText")); button.setFocusable(false); AbstractAction action = new AttributeToggler<>(editor, AttributeKeys.FONT_BOLD, Boolean.TRUE, Boolean.FALSE, new StyledEditorKit.BoldAction()); action.putValue(ActionUtil.UNDO_PRESENTATION_NAME_KEY, BUNDLE.getString("buttonFactory.action_fontStyleBold.undo.presentationName")); button.addActionListener(action); return button; }
Example #5
Source File: SpinnerUtil.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Workaround for a swing bug : when the user enters an illegal value, the * text is forced to the last value. * * @param spinner the spinner to update */ public static void fixIntegerList (final JSpinner spinner) { JSpinner.DefaultEditor editor; editor = (JSpinner.DefaultEditor) spinner.getEditor(); final JFormattedTextField ftf = editor.getTextField(); ftf.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enterAction"); ftf.getActionMap().put("enterAction", new AbstractAction() { @Override public void actionPerformed (ActionEvent e) { try { spinner.setValue(Integer.parseInt(ftf.getText())); } catch (NumberFormatException ex) { // Reset to last value ftf.setText(ftf.getValue().toString()); } } }); }
Example #6
Source File: TestDataComponent.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private Action onRenameAction() { return new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { assignThePreviouslySelected(); Boolean flag = testDesign.getProject().getTestData() .renameTestDataColumn(std.getName(), getValue("oldvalue").toString(), getValue("newvalue").toString()); putValue("rename", flag); if (flag) { selectThePreviouslySelected(); } } }; }
Example #7
Source File: NewDocumentAction.java From pumpernickel with MIT License | 6 votes |
/** * @param text * this is an optional action name. If this is null a default * name like "New Document" is used, but you can customize this * to resemble "New Spreadsheet" or "New Image". */ public NewDocumentAction(DocumentControls controls, String text) { Objects.requireNonNull(controls); this.controls = controls; DocumentCommand.NEW.install(this); controls.registerAction(this); if (text != null) putValue(AbstractAction.NAME, text); controls.getOpenDocuments().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { refresh(); } }, false); refresh(); }
Example #8
Source File: SqlTemplatesAndActions.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public Action getDisableSpatialIndexAction( ColumnLevel column, DatabaseViewer spatialiteViewer ) { if (sqlTemplates.hasRecoverSpatialIndex()) { return new AbstractAction("Disable spatial index"){ @Override public void actionPerformed( ActionEvent e ) { String tableName = column.parent.tableName; String columnName = column.columnName; String query = sqlTemplates.disableSpatialIndex(tableName, columnName); spatialiteViewer.addTextToQueryEditor(query); } }; } else { return null; } }
Example #9
Source File: MarkerBarListener.java From microba with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void installKeyboardActions(JComponent c) { c.getInputMap().put(DELETE_KEYSTROKE, VK_DELETE_KEY); c.getActionMap().put(VK_DELETE_KEY, new AbstractAction() { public void actionPerformed(ActionEvent e) { BoundedTableModel dataModel = bar.getDataModel(); ListSelectionModel selectionModel = bar.getSelectionModel(); MarkerMutationModel mutationModel = bar.getMutationModel(); if (selectionModel != null && dataModel != null && mutationModel != null && !selectionModel.isSelectionEmpty()) { int selected = selectionModel.getLeadSelectionIndex(); if (dataModel.isCellEditable(selected, bar .getPositionColumn())) { mutationModel.removeMarkerAtIndex(selected); } } } }); }
Example #10
Source File: DependencyNode.java From netbeans with Apache License 2.0 | 6 votes |
public @Override Action createContextAwareInstance(final Lookup context) { return new AbstractAction(BTN_Open_Project()) { public @Override void actionPerformed(ActionEvent e) { Set<Project> projects = new HashSet<Project>(); for (Artifact art : context.lookupAll(Artifact.class)) { File f = art.getFile(); if (f != null) { Project p = FileOwnerQuery.getOwner(org.openide.util.Utilities.toURI(f)); if (p != null) { projects.add(p); } } } OpenProjects.getDefault().open(projects.toArray(new NbMavenProjectImpl[projects.size()]), false, true); } }; }
Example #11
Source File: PumpCommand.java From pumpernickel with MIT License | 6 votes |
protected PumpCommand(String text, Character accelerator, String commandName, Class<T> actionClass) { if (text != null) { properties.put(AbstractAction.NAME, text); } if (accelerator != null) { int modifiers = Toolkit.getDefaultToolkit() .getMenuShortcutKeyMask(); KeyStroke keyStroke = KeyStroke.getKeyStroke( accelerator.charValue(), modifiers); properties.put(AbstractAction.ACCELERATOR_KEY, keyStroke); } if (commandName != null) { properties.put(AbstractAction.ACTION_COMMAND_KEY, commandName); } this.actionClass = actionClass; }
Example #12
Source File: OSPCombo.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Shows the popup immediately below the specified field. If item is selected, * sets the field text and fires property change. * * @param field the field that displays the selected string */ public void showPopup(final JTextField display) { //display = field; Action selectAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { int prev = selected; selected = Integer.parseInt(e.getActionCommand()); display.setText(items[selected]); OSPCombo.this.firePropertyChange("index", prev, -1); //$NON-NLS-1$ } }; removeAll(); for(int i = 0; i<items.length; i++) { String next = items[i].toString(); JMenuItem item = new JMenuItem(next); item.setFont(display.getFont()); item.addActionListener(selectAction); item.setActionCommand(String.valueOf(i)); add(item); } int popupHeight = 8+getComponentCount()*display.getHeight(); setPopupSize(display.getWidth(), popupHeight); show(display, 0, display.getHeight()); }
Example #13
Source File: ProfilerTableActions.java From netbeans with Apache License 2.0 | 6 votes |
private Action selectNextRowAction() { return new AbstractAction() { public void actionPerformed(ActionEvent e) { ProfilerColumnModel cModel = table._getColumnModel(); if (table.getRowCount() == 0 || cModel.getVisibleColumnCount() == 0) return; int row = table.getSelectedRow(); if (row == -1) { table.selectColumn(cModel.getFirstVisibleColumn(), false); table.selectRow(0, true); } else { if (++row == table.getRowCount()) { row = 0; int column = table.getSelectedColumn(); if (column == -1) column = cModel.getFirstVisibleColumn(); column = cModel.getNextVisibleColumn(column); table.selectColumn(column, false); } table.selectRow(row, true); } } }; }
Example #14
Source File: AbstractViewTabDisplayerUI.java From netbeans with Apache License 2.0 | 6 votes |
/** Registers shortcut for enable/ disable auto-hide functionality */ @Override public void registerShortcuts(JComponent comp) { comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK), PIN_ACTION); comp.getActionMap().put(PIN_ACTION, pinAction); //TODO make shortcut configurable comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT). put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD0, InputEvent.CTRL_DOWN_MASK), TRANSPARENCY_ACTION); comp.getActionMap().put(TRANSPARENCY_ACTION, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { shouldPerformAction(TabbedContainer.COMMAND_TOGGLE_TRANSPARENCY, getSelectionModel().getSelectedIndex(), null); } }); }
Example #15
Source File: ButtonColumn.java From triplea with GNU General Public License v3.0 | 6 votes |
/** * Converts a given column to buttons. The existing column data text will become the text of the * new buttons. * * @param table The table to be updated. * @param column Zero-based column number of the table. * @param buttonListener The listener that will be fired when one of the new buttons are clicked. */ public static void attachButtonColumn( final JTable table, final int column, final BiConsumer<Integer, DefaultTableModel> buttonListener) { Preconditions.checkState(table.getModel().getColumnCount() > column); new ButtonColumn( table, column, new AbstractAction() { private static final long serialVersionUID = 786926815237533866L; @Override public void actionPerformed(final ActionEvent e) { final int rowNumber = Integer.parseInt(e.getActionCommand()); final DefaultTableModel defaultTableModel = (DefaultTableModel) table.getModel(); buttonListener.accept(rowNumber, defaultTableModel); } }); }
Example #16
Source File: FindInQueryBar.java From netbeans with Apache License 2.0 | 6 votes |
FindInQueryBar(FindInQuerySupport support) { this.support = support; initComponents(); lastSearchModel = new DefaultComboBoxModel(); findCombo.setModel(lastSearchModel); findCombo.setSelectedItem(""); // NOI18N initialized = true; addComboEditorListener(); InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); String closeKey = "close"; // NOI18N inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), closeKey); getActionMap().put(closeKey, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { FindInQueryBar.this.support.cancel(); } }); }
Example #17
Source File: frmReleaseNote.java From Course_Generator with GNU General Public License v3.0 | 6 votes |
/** * Manage low level key strokes ESCAPE : Close the window * * @return */ protected JRootPane createRootPane() { JRootPane rootPane = new JRootPane(); KeyStroke strokeEscape = KeyStroke.getKeyStroke("ESCAPE"); @SuppressWarnings("serial") Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { setVisible(false); } }; InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(strokeEscape, "ESCAPE"); rootPane.getActionMap().put("ESCAPE", actionListener); return rootPane; }
Example #18
Source File: AddModulePanel.java From netbeans with Apache License 2.0 | 6 votes |
private static void exchangeCommands(String[][] commandsToExchange, final JComponent target, final JComponent source) { InputMap targetBindings = target.getInputMap(); KeyStroke[] targetBindingKeys = targetBindings.allKeys(); ActionMap targetActions = target.getActionMap(); InputMap sourceBindings = source.getInputMap(); ActionMap sourceActions = source.getActionMap(); for (int i = 0; i < commandsToExchange.length; i++) { String commandFrom = commandsToExchange[i][0]; String commandTo = commandsToExchange[i][1]; final Action orig = targetActions.get(commandTo); if (orig == null) { continue; } sourceActions.put(commandTo, new AbstractAction() { public void actionPerformed(ActionEvent e) { orig.actionPerformed(new ActionEvent(target, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers())); } }); for (int j = 0; j < targetBindingKeys.length; j++) { if (targetBindings.get(targetBindingKeys[j]).equals(commandFrom)) { sourceBindings.put(targetBindingKeys[j], commandTo); } } } }
Example #19
Source File: IDEF0ViewPlugin.java From ramus with GNU General Public License v3.0 | 6 votes |
private ActionDescriptor createExportToIDL() { ActionDescriptor descriptor = new ActionDescriptor(); descriptor.setMenu("IDEF0"); AbstractAction action = new AbstractAction() { { putValue(ACTION_COMMAND_KEY, "ExportToIDL"); } @Override public void actionPerformed(java.awt.event.ActionEvent e) { exportToIdl(); } }; descriptor.setAction(action); return descriptor; }
Example #20
Source File: DeleteProfilingPointAction.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Action createContextAwareInstance(Lookup actionContext) { if (!ProfilingPointsManager.getDefault().isProfilingSessionInProgress()) { Collection<? extends CodeProfilingPoint.Annotation> anns = actionContext.lookupAll(CodeProfilingPoint.Annotation.class); if (anns.size() == 1) { final CodeProfilingPoint pp = anns.iterator().next().profilingPoint(); return new AbstractAction(getName()) { @Override public void actionPerformed(ActionEvent ae) { ProfilingPointsManager.getDefault().removeProfilingPoint(pp); } }; } } return this; }
Example #21
Source File: ClosableTab.java From incubator-iotdb with Apache License 2.0 | 6 votes |
ClosableTab(String name, TabCloseCallBack closeCallBack) { setName(name); setLayout(null); closeTabButton = new JButton("Close"); closeTabButton.setLocation(720, 5); closeTabButton.setSize(new Dimension(70, 30)); closeTabButton.setFont(closeTabButton.getFont().deriveFont(10.0f)); add(closeTabButton); closeTabButton.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { closeCallBack.call(name); } }); }
Example #22
Source File: XTextField.java From scelight with Apache License 2.0 | 6 votes |
@Override public void registerFocusHotkey( final JComponent rootComponent, final KeyStroke keyStroke ) { final Object actionKey = new Object(); final String toolTipText = getToolTipText(); if ( toolTipText != null ) { if ( toolTipText.endsWith( "</html>" ) ) setToolTipText( toolTipText.substring( 0, toolTipText.length() - 7 ) + LGuiUtils.keyStrokeToString( keyStroke ) + "</html>" ); else setToolTipText( toolTipText + LGuiUtils.keyStrokeToString( keyStroke ) ); } rootComponent.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ).put( keyStroke, actionKey ); rootComponent.getActionMap().put( actionKey, new AbstractAction() { @Override public void actionPerformed( final ActionEvent event ) { requestFocusInWindow(); } } ); }
Example #23
Source File: A4Preferences.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public Action getAction(final T value) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { set(value); } }; }
Example #24
Source File: ClassesInfoPanel.java From hprof-tools with MIT License | 5 votes |
public ClassesInfoPanel(@Nonnull MemoryDump data, @Nonnull TabbedInfoWindow mainWindow) { super(new BorderLayout()); this.mainWindow = mainWindow; dataTable = new ClassesInfoTable(); JScrollPane scroller = new JScrollPane(dataTable); dataTable.setRowSelectionAllowed(true); add(scroller, BorderLayout.CENTER); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem listWithOutgoingRefs = new JMenuItem("List with outgoing references"); listWithOutgoingRefs.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { presenter.onListInstances(selectedItem); } }); popupMenu.add(listWithOutgoingRefs); JMenuItem calculateRetainedHeap = new JMenuItem("Calculate retained heap size"); popupMenu.add(calculateRetainedHeap); MouseListener popupListener = new PopupListener(popupMenu); dataTable.addMouseListener(popupListener); ClassProvider clsProvider = new ClassProvider(data); InstanceProvider instanceProvider = new InstanceProvider(data); presenter = new ClassesInfoPresenterImpl(this, clsProvider, instanceProvider); }
Example #25
Source File: MainViewsPanel.java From magarena with GNU General Public License v3.0 | 5 votes |
private AbstractAction getMinusButtonAction() { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { activeView.doMinusButtonAction(); } }; }
Example #26
Source File: LinearGradientPrintingTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void createUI() { f = new JFrame("LinearGradient Printing Test"); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final LinearGradientPrintingTest gpt = new LinearGradientPrintingTest(); Container c = f.getContentPane(); c.add(BorderLayout.CENTER, gpt); final JButton print = new JButton("Print"); print.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(gpt); final boolean doPrint = job.printDialog(); if (doPrint) { try { job.print(); } catch (PrinterException ex) { throw new RuntimeException(ex); } } } }); c.add(print, BorderLayout.SOUTH); f.pack(); f.setVisible(true); }
Example #27
Source File: ColorButton.java From magarena with GNU General Public License v3.0 | 5 votes |
private AbstractAction getSelectColorAction() { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final Color newColor = JColorChooser.showDialog(null, MText.get(_S1), getBackground()); if (newColor != null) { setBackground(newColor); } } }; }
Example #28
Source File: CGraphHotkeys.java From binnavi with Apache License 2.0 | 5 votes |
/** * Register the default hotkeys of a graph view. * * @param parent Parent window used for dialogs. * @param panel The panel where the view is shown. * @param debuggerProvider Provides the debugger used by some hotkeys. * @param searchField The search field that is shown in the graph panel. * @param addressField The address field that is shown in the graph panel. */ public static void registerHotKeys(final JFrame parent, final CGraphPanel panel, final IFrontEndDebuggerProvider debuggerProvider, final CGraphSearchField searchField, final CGotoAddressField addressField) { Preconditions.checkNotNull(parent, "IE01606: Parent argument can not be null"); Preconditions.checkNotNull(panel, "IE01607: Panel argument can not be null"); Preconditions.checkNotNull(searchField, "IE01608: Search field argument can not be null"); Preconditions.checkNotNull(addressField, "IE01609: Address field argument can not be null"); final InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap actionMap = panel.getActionMap(); inputMap.put(HotKeys.GRAPH_GOTO_ADDRESS_FIELD_KEY.getKeyStroke(), "GOTO_ADDRESS_FIELD"); actionMap.put("GOTO_ADDRESS_FIELD", new AbstractAction() { /** * Used for serialization. */ private static final long serialVersionUID = -8994014581850287793L; @Override public void actionPerformed(final ActionEvent event) { addressField.requestFocusInWindow(); } }); inputMap.put(HotKeys.GRAPH_SHOW_HOTKEYS_ACCELERATOR_KEY.getKeyStroke(), "SHOW_HOTKEYS"); actionMap.put("SHOW_HOTKEYS", new CShowHotkeysAction(parent)); registerSearchKeys(panel.getModel().getGraph().getView(), searchField, inputMap, actionMap); registerDebuggerKeys(panel.getModel().getParent(), panel.getModel().getGraph(), debuggerProvider, inputMap, actionMap); }
Example #29
Source File: MainPane.java From DroidUIBuilder with Apache License 2.0 | 5 votes |
/** * 将指定组件进入到主界面上的导航工具条. * * @param toolbarGroup * @param toolbarMain * @param nativeShowText * @param willToWorkbench * @param isHot true则将在按钮右上角画一个"hot"样式的小图标 * @return */ private JToggleButton addNativeComTo(ButtonGroup toolbarGroup , JToolBar toolbarMain, String nativeShowText , final JComponent willToWorkbench, final boolean isHot) { AbstractAction actionNavigate = new AbstractAction(nativeShowText){ public void actionPerformed(ActionEvent e){ // 点击按钮则把它对象的组件设置到工作台 setContentToCenter(willToWorkbench); } }; // 导航按钮实例化 JToggleButton btnNavigate = new JToggleButton(actionNavigate){ public void paintComponent(Graphics g) { super.paintComponent(g); // 画"hot"小图标 if(isHot) { ImageIcon hotIcon = org.droiddraw.resource.IconFactory .getInstance().getNavigateTool_hot_Icon(); g.drawImage(hotIcon.getImage() , this.getWidth() - hotIcon.getIconWidth(), 2 , hotIcon.getIconWidth(), hotIcon.getIconHeight(), null); } } }; // 加入到工具条 toolbarGroup.add(btnNavigate); toolbarMain.add(btnNavigate); return btnNavigate; }
Example #30
Source File: DiagramScene.java From hottub with GNU General Public License v2.0 | 5 votes |
public Action createGotoAction(final Figure f) { final DiagramScene diagramScene = this; Action a = new AbstractAction() { public void actionPerformed(ActionEvent e) { diagramScene.gotoFigure(f); } }; a.setEnabled(true); a.putValue(Action.SMALL_ICON, new ColorIcon(f.getColor())); String name = f.getLines()[0]; name += " ("; if (f.getCluster() != null) { name += "B" + f.getCluster().toString(); } if (!this.getFigureWidget(f).isVisible()) { if (f.getCluster() != null) { name += ", "; } name += "hidden"; } name += ")"; a.putValue(Action.NAME, name); return a; }