@Override public void keyPressed(KeyEvent event) { if (event.getKeyCode()==27){ button.getAction().actionPerformed(null); } }
/** * Sets the specified button's icon to the proper scale. * * @param button the button to update */ private void setButtonIcon(JButton button) { // Note: the action's icon must not be changed and remain in its original, non-scaled size ImageIcon icon = IconManager.getScaledIcon((ImageIcon)button.getAction().getValue(Action.SMALL_ICON), scaleFactor); if(!USE_MAC_OS_X_CLIENT_PROPERTIES) // Add padding around the icon so the button feels less crowded icon = IconManager.getPaddedIcon(icon, new Insets(3, 4, 3, 4)); button.setIcon(icon); }
private void registerListeners() { KeyStroke refreshKey = KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK, true); getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(refreshKey, "refresh"); // NOI18N getActionMap().put("refresh", refreshBtn.getAction()); // NOI18N }
@Override public void windowClosing(WindowEvent e) { ActionEvent myEvent = new ActionEvent(e.getSource(), 1, QUIT_ACTION); ui.getQuit().getAction().actionPerformed(myEvent); } });
@Override public void windowClosing(WindowEvent e) { ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); configUI.getQuit().getAction().actionPerformed(myEvent); // if (canQuitCategory(configUI)) { // e.getWindow().dispose(); // } } });
@Override public void windowClosing(WindowEvent e) { ActionEvent myEvent = new ActionEvent(e.getSource(), 1, QUIT_ACTION); ui.getQuit().getAction().actionPerformed(myEvent); } });
@Override public void windowClosing(WindowEvent e) { ActionEvent myEvent = new ActionEvent(e.getSource(), 1, QUIT_ACTION); ui.getQuit().getAction().actionPerformed(myEvent); } });
void $afterCompleteSetup() { JRootPane rootPane = ui.getRootPane(); JButton close = ui.close; rootPane.setDefaultButton(close); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "close"); rootPane.getActionMap().put("close", close.getAction()); } }
void $afterCompleteSetup() { JRootPane rootPane = ui.getRootPane(); JButton close = ui.close; rootPane.setDefaultButton(close); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "close"); rootPane.getActionMap().put("close", close.getAction()); } }
void $afterCompleteSetup() { JRootPane rootPane = ui.getRootPane(); JButton close = ui.close; rootPane.setDefaultButton(close); InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "close"); rootPane.getActionMap().put("close", close.getAction()); } }
private JButton createToolbarItem(Container pParent, Element pElement) { JButton button = createButton(pParent, pElement); // (somehow) a hack: we remove the text, so we get the "real" toolbar look, // but only when we where build from an action if (button.getAction()!=null) { button.setText(null); } // check if this toolbar item is enabled/disabled Attribute enabledAttribute = pElement.getAttribute(SwingXMLBuilder.ENABLED_ATTRIBUTE); if (enabledAttribute != null) { boolean enabled = "false".equals(enabledAttribute.getValue()); button.setEnabled(enabled); } return button; }
@Override public void setTabEnabled(boolean enabled) { this.setEnabled(enabled); for (Component c : getComponents()) { if (enabled) { if (c instanceof JButton) { JButton but = (JButton) c; Action a = but.getAction(); if (a != null) { but.setEnabled(a.isEnabled()); } else { c.setEnabled(enabled); } } else { c.setEnabled(enabled); } } else { c.setEnabled(enabled); } } }
/** * Clears the result panel. */ public void clearResult() { refreshButton.setEnabled(false); renderedResultPanel.removeAll(); // Update the 'save result' buttons appropriately for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) { JButton saveButton = (JButton) saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI) (saveButton .getAction()); // Update the action action.setResultReference(null); action.setInvocationContext(context); saveButton.setEnabled(false); } renderersComboBox.setModel(new DefaultComboBoxModel()); renderersComboBox.setEnabled(false); revalidate(); repaint(); }
/** * Clears the result panel. */ public void clearResult() { renderedResultPanel.removeAll(); // Update the 'save result' buttons appropriately for (int i=0; i< saveButtonsPanel.getComponents().length; i++){ JButton saveButton = (JButton)saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI)(saveButton.getAction()); // Update the action action.setResultReference(null); action.setInvocationContext(null); saveButton.setEnabled(false); } renderersComboBox.setModel(new DefaultComboBoxModel()); renderersComboBox.setEnabled(false); revalidate(); repaint(); }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component result = super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); Action action = ((JButton) value).getAction(); setIcon((Icon) action.getValue(Action.LARGE_ICON_KEY)); setText((String) action.getValue(Action.NAME)); setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); setEnabled(action.isEnabled()); setBorder(border); return result; } }
/** * Clears the result panel. */ public void clearResult() { refreshButton.setEnabled(false); wrapTextCheckBox.setVisible(false); renderedResultPanel.removeAll(); // Update the 'save result' buttons appropriately for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) { JButton saveButton = (JButton) saveButtonsPanel.getComponent(i); SaveIndividualResultSPI action = (SaveIndividualResultSPI) (saveButton .getAction()); // Update the action action.setResultReference(null); action.setInvocationContext(null); saveButton.setEnabled(false); } renderersComboBox.setModel(new DefaultComboBoxModel()); renderersComboBox.setEnabled(false); revalidate(); repaint(); }
private boolean processFKey(final KeyEvent e){ if(e.getID() != KeyEvent.KEY_PRESSED) return false; final Window windowAncestor = SwingUtilities.getWindowAncestor(e.getComponent()); if (windowAncestor != ownWindowAncestor) { resetModifiers(); return false; } int keyCode = e.getKeyCode(); if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12 ) { final JButton btn = createButtons(nextModifiers)[keyCode - KeyEvent.VK_F1]; if(btn.getAction() instanceof SetAcceleratorOnNextClickAction && e.getComponent() instanceof JTextComponent) return false; if(timer.isRunning()){ timer.stop(); onModifierChangeImpl(); } btn.doClick(); return true; } return false; }
/** * Initializes this dialog. */ private void initDialog() { setResizable( false ); final JComponent pane = createContentPane(); final JButton runAnalysisButton = ToolUtils.createRunAnalysisButton( this ); this.runAction = ( RestorableAction )runAnalysisButton.getAction(); final JButton closeButton = ToolUtils.createCloseButton(); final JComponent buttons = SwingComponentUtils.createButtonPane( runAnalysisButton, closeButton ); SwingComponentUtils.setupWindowContentPane( this, pane, buttons, runAnalysisButton ); } }
@Test public void createsToolbarButtonWithAction() { String content = "<FreeplaneUIEntries>" + "<Entry name='home' builder='toolbar'>" + "<Entry name='action'/>" + "</Entry>" + "</FreeplaneUIEntries>"; final AFreeplaneAction someAction = Mockito.mock(AFreeplaneAction.class); when(freeplaneActions.getAction("action")).thenReturn(someAction); Entry builtMenuStructure = buildJMenu(content); assertThat(((JButton)new EntryAccessor().getComponent(builtMenuStructure.getChild(0).getChild(0))).getAction(), CoreMatchers.<Action>equalTo(someAction)); }
@Test public void createsToolbarButtonWithAction() { Entry actionEntry = new Entry(); final AFreeplaneAction action = Mockito.mock(AFreeplaneAction.class); new EntryAccessor().setAction(actionEntry, action); Entry toolbarEntry = new Entry(); final FreeplaneToolBar toolbar = new FreeplaneToolBar("toolbar", SwingConstants.HORIZONTAL); new EntryAccessor().setComponent(toolbarEntry, toolbar); toolbarEntry.addChild(actionEntry); final JToolbarComponentBuilder toolbarActionGroupBuilder = new JToolbarComponentBuilder(); toolbarActionGroupBuilder.visit(actionEntry); JButton button = (JButton)new EntryAccessor().getComponent(actionEntry); assertThat(button.getAction(), CoreMatchers.<Action>equalTo(action)); assertThat(button.getParent(), CoreMatchers.equalTo((Container)toolbar)); }