/** * Creates new form AbstractSearchResultsPanel */ public AbstractSearchResultsPanel(SearchComposition<?> searchComposition, SearchProvider.Presenter searchProviderPresenter) { this.searchComposition = searchComposition; this.searchProviderPresenter = searchProviderPresenter; initComponents(); explorerManager = new ExplorerManager(); ActionMap map = this.getActionMap(); // map delete key to delete action map.put("delete", //NOI18N ExplorerUtils.actionDelete(explorerManager, false)); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(explorerManager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(explorerManager)); lookup = ExplorerUtils.createLookup(explorerManager, ResultView.getInstance().getActionMap()); initActions(); initToolbar(); initSelectionListeners(); }
private ServicesTab() { manager = new ExplorerManager(); manager.setRootContext(new ServicesNode()); ActionMap map = getActionMap(); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete(manager, false)); associateLookup(ExplorerUtils.createLookup(manager, map)); view = new BeanTreeView(); view.setRootVisible(false); setLayout(new BorderLayout()); add(view); setName(ID); setDisplayName(NbBundle.getMessage(ServicesTab.class, "LBL_Services")); }
public static RandomTestContainer.Round addRound(RandomTestContainer container) throws Exception { RandomTestContainer.Round round = container.addRound(); round.setOpCount(100); round.setRatio(DocumentTesting.INSERT_CHAR, 5); round.setRatio(DocumentTesting.INSERT_TEXT, 3); round.setRatio(DocumentTesting.INSERT_PHRASE, 3); round.setRatio(DocumentTesting.REMOVE_CHAR, 3); round.setRatio(DocumentTesting.REMOVE_TEXT, 1); round.setRatio(DocumentTesting.UNDO, 1); round.setRatio(DocumentTesting.REDO, 1); round.setRatio(EditorPaneTesting.TYPE_CHAR, 10); EditorPaneTesting.setActionRatio(round, DefaultEditorKit.insertBreakAction, 1); EditorPaneTesting.setActionRatio(round, DefaultEditorKit.insertTabAction, 1); EditorPaneTesting.setActionRatio(round, DefaultEditorKit.deleteNextCharAction, 1); EditorPaneTesting.setActionRatio(round, DefaultEditorKit.deletePrevCharAction, 1); round.setRatio(EditorPaneTesting.MOVE, 20); round.setRatio(EditorPaneTesting.SELECT, 20); round.setRatio(EditorPaneTesting.SET_CARET_OFFSET, 1); return round; }
public static void testFixedScenarios(RandomTestContainer container) throws Exception { // Fixed scenario - last undo throwed exc. RandomTestContainer.Context gContext = container.context(); JEditorPane pane = EditorPaneTesting.getEditorPane(container); // Insert initial text into doc // DocumentTesting.insert(container.context(), 0, "abc\ndef\n\nghi"); DocumentTesting.insert(gContext, 0, "\n\n\n\n\n"); DocumentTesting.remove(gContext, 0, DocumentTesting.getDocument(gContext).getLength()); // Check for an error caused by delete a line-2-begining and insert at line-1-end and two undos DocumentTesting.insert(gContext, 0, "a\nb\n\n"); EditorPaneTesting.setCaretOffset(gContext, 2); EditorPaneTesting.performAction(gContext, pane, DefaultEditorKit.deleteNextCharAction); EditorPaneTesting.moveOrSelect(gContext, SwingConstants.WEST, false); // Should go to end of first line EditorPaneTesting.typeChar(gContext, 'c'); DocumentTesting.undo(gContext, 1); DocumentTesting.undo(gContext, 1); // This throwed ISE for plain text mime type }
private boolean initActionMapInEDT() { // Init action map: cut,copy,delete,paste actions. javax.swing.ActionMap am = editor.getActionMap(); //#43157 - editor actions need to be accessible from outside using the TopComponent.getLookup(ActionMap.class) call. // used in main menu enabling/disabling logic. javax.swing.ActionMap paneMap = pane.getActionMap(); // o.o.windows.DelegateActionMap.setParent() leads to CloneableEditor.getEditorPane() provideUnfinishedPane = true; try { am.setParent(paneMap); } finally { provideUnfinishedPane = false; } //#41223 set the defaults befor the custom editor + kit get initialized, giving them opportunity to // override defaults.. paneMap.put(DefaultEditorKit.cutAction, getAction(DefaultEditorKit.cutAction)); paneMap.put(DefaultEditorKit.copyAction, getAction(DefaultEditorKit.copyAction)); paneMap.put("delete", getAction(DefaultEditorKit.deleteNextCharAction)); // NOI18N paneMap.put(DefaultEditorKit.pasteAction, getAction(DefaultEditorKit.pasteAction)); return true; }
/** * This method builds the popup menu. */ private void build(ActionMap actionMap) { popupPresenter = new JPopupMenu(); cutAction = actionMap.get(DefaultEditorKit.cutAction); copyAction = actionMap.get(DefaultEditorKit.copyAction); pasteAction = actionMap.get(DefaultEditorKit.pasteAction); selectAllAction = actionMap.get(DefaultEditorKit.selectAllAction); popupPresenter.add(createMenuItem("CTL_MenuItem_Cut", KeyEvent.VK_X, cutAction)); popupPresenter.add(createMenuItem("CTL_MenuItem_Copy", KeyEvent.VK_C, copyAction)); popupPresenter.add(createMenuItem("CTL_MenuItem_Paste", KeyEvent.VK_V, pasteAction)); popupPresenter.addSeparator(); popupPresenter.add(createMenuItem("CTL_MenuItem_SelectAll", KeyEvent.VK_A, selectAllAction)); }
/** Creates new form TemplatesPanel */ public TemplatesPanel (String pathToSelect) { ActionMap map = getActionMap (); map.put (DefaultEditorKit.copyAction, ExplorerUtils.actionCopy (getExplorerManager ())); map.put (DefaultEditorKit.cutAction, ExplorerUtils.actionCut (getExplorerManager ())); map.put (DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste (getExplorerManager ())); map.put ("delete", ExplorerUtils.actionDelete (getExplorerManager (), true)); // NOI18N initComponents (); createTemplateView (); treePanel.add (view, BorderLayout.CENTER); associateLookup (ExplorerUtils.createLookup (getExplorerManager (), map)); initialize (pathToSelect); }
/** Creates new form LicensePanel */ public LicensePanel(URL url) { this.url = url; initComponents(); initAccessibility(); try { jEditorPane1.setPage(url); } catch (IOException exc) { //Problem with locating file System.err.println("Exception: " + exc.getMessage()); //NOI18N exc.printStackTrace(); } ActionMap actionMap = jEditorPane1.getActionMap(); actionMap.put(DefaultEditorKit.upAction, new ScrollAction(-1)); actionMap.put(DefaultEditorKit.downAction, new ScrollAction(1)); }
/** Creates new form CatalogPanel */ public CatalogPanel() { ActionMap map = getActionMap(); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(getExplorerManager())); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(getExplorerManager())); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(getExplorerManager())); map.put("delete", ExplorerUtils.actionDelete(getExplorerManager(), true)); // NOI18N initComponents(); createCatalogView(); treePanel.add(view, BorderLayout.CENTER); associateLookup(ExplorerUtils.createLookup(getExplorerManager(), map)); initialize(); }
public ListViewNavigatorPanel () { manager = new ExplorerManager(); ActionMap map = getActionMap(); copyAction = ExplorerUtils.actionCopy(manager); map.put(DefaultEditorKit.copyAction, copyAction); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete(manager, true)); // or false lookup = ExplorerUtils.createLookup(manager, map); listView = new ListView(); fillListView(listView); add(listView); }
public void testNewlineLineOne() throws Exception { loggingOn(); RandomTestContainer container = createContainer(); JEditorPane pane = container.getInstance(JEditorPane.class); Document doc = pane.getDocument(); doc.putProperty("mimeType", "text/plain"); ViewHierarchyRandomTesting.initRandomText(container); ViewHierarchyRandomTesting.addRound(container).setOpCount(OP_COUNT); ViewHierarchyRandomTesting.testFixedScenarios(container); RandomTestContainer.Context context = container.context(); // Clear document contents DocumentTesting.remove(context, 0, doc.getLength()); DocumentTesting.insert(context, 0, "\n"); EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, false); EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, true); EditorPaneTesting.performAction(context, pane, DefaultEditorKit.deleteNextCharAction); DocumentTesting.undo(context, 1); }
public void testDeleteAterInsertBreak() throws Exception { loggingOn(); RandomTestContainer container = createContainer(); JEditorPane pane = container.getInstance(JEditorPane.class); Document doc = pane.getDocument(); doc.putProperty("mimeType", "text/plain"); ViewHierarchyRandomTesting.initRandomText(container); RandomTestContainer.Context context = container.context(); DocumentTesting.insert(context, 0, " osen \n\n\n esl\t\ta \t\t \n\n\nabcd\td m\t\tabcdef\te\t\tab\tcdef\tef\tkojd \t\t \n\n\n t\t vpjm\ta\ngooywzmj q\tugos\tdefy\t i xs us tg z" ); EditorPaneTesting.setCaretOffset(context, 70); DocumentTesting.remove(context, 50, 10); EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertBreakAction); EditorPaneTesting.performAction(context, pane, DefaultEditorKit.deleteNextCharAction); }
public void testTwoDeletes() throws Exception { loggingOn(); RandomTestContainer container = createContainer(); JEditorPane pane = container.getInstance(JEditorPane.class); Document doc = pane.getDocument(); doc.putProperty("mimeType", "text/plain"); ViewHierarchyRandomTesting.initRandomText(container); RandomTestContainer.Context context = container.context(); DocumentTesting.insert(context, 0, " osen \n\n\nbs\tmn\nziil esl\t\ta \t\t \n\n\nabc \n\n\nd\td m\t\ta\nbcdef\te\t\tab\tcdef\tef\tkojd \t\t \n\n\net\t vpjm\ta\ngooywzmj q\tugos\tdefy\t i xs us ttl\tg z" ); EditorPaneTesting.setCaretOffset(context, 115); EditorPaneTesting.performAction(context, pane, DefaultEditorKit.deletePrevCharAction); EditorPaneTesting.performAction(context, pane, DefaultEditorKit.deleteNextCharAction); }
public void testSelectionAndInsertTab() throws Exception { loggingOn(); RandomTestContainer container = createContainer(); JEditorPane pane = container.getInstance(JEditorPane.class); Document doc = pane.getDocument(); doc.putProperty("mimeType", "text/plain"); ViewHierarchyRandomTesting.initRandomText(container); RandomTestContainer.Context context = container.context(); DocumentTesting.insert(context, 0, " osen \n\n\n esl\t\ta \t\t \n\n\nabcd\td m\t\tabcdef\te\t\tab\tcdef\tef\tkojd p\t\t \n\n\n t\t vpjm\ta\ngooywzmj q\tugos\tdefy\t i xs us tg z" ); EditorPaneTesting.setCaretOffset(context, 64); EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, false); EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, true); DocumentTesting.insert(context, 19, "g"); EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, true); EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, true); EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, true); EditorPaneTesting.performAction(context, pane, DefaultEditorKit.deletePrevCharAction); EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertTabAction); EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, false); EditorPaneTesting.typeChar(context, 'f'); }
public static void typeChar(Context context, char ch) throws Exception { JEditorPane pane = context.getInstance(JEditorPane.class); if (ch == '\n') { // Insert break performAction(context, pane, DefaultEditorKit.insertBreakAction, null, true); } else if (ch == '\t') { // Insert TAB performAction(context, pane, DefaultEditorKit.insertTabAction, null, true); } else { // default key typed action StringBuilder sb = null; if (context.isLogOp()) { sb = context.logOpBuilder(); sb.append("typeChar(context, '").append(CharSequenceUtilities.debugChar(ch)).append("')\n"); debugCaret(sb, pane).append(" => "); } performAction(context, pane, DefaultEditorKit.defaultKeyTypedAction, new ActionEvent(pane, 0, String.valueOf(ch)), false); if (context.isLogOp()) { debugCaret(sb, pane).append("\n"); context.logOp(sb); } } }
static Action[] prepareActions() { DefaultEditorKit dek = new DefaultEditorKit(); Action[] defActions = dek.getActions(); Action[] newActions = new Action[defActions.length]; for (int i = 0; i < defActions.length; i++) { Object actionName = defActions[i].getValue(Action.NAME); if (actionName.equals(beginLineAction)) { newActions[i] = new OutputBeginLineAction(beginLineAction, false); } else if (actionName.equals(selectionBeginLineAction)) { newActions[i] = new OutputBeginLineAction(selectionBeginLineAction, true); } else if (actionName.equals(endLineAction)) { newActions[i] = new OutputEndLineAction(endLineAction, false); } else if (actionName.equals(selectionEndLineAction)) { newActions[i] = new OutputEndLineAction(selectionEndLineAction, true); } else { newActions[i] = defActions[i]; } } return newActions; }
private void installNoOpActionMappings(){ InputMap im = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); // cut KeyStroke[] keys = findEditorKeys(DefaultEditorKit.cutAction, KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); for (int i = 0; i < keys.length; i++) { im.put(keys[i], NOOP_ACTION_KEY); } // copy keys = findEditorKeys(DefaultEditorKit.copyAction, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); for (int i = 0; i < keys.length; i++) { im.put(keys[i], NOOP_ACTION_KEY); } // delete keys = findEditorKeys(DefaultEditorKit.deleteNextCharAction, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); //NOI18N for (int i = 0; i < keys.length; i++) { im.put(keys[i], NOOP_ACTION_KEY); } // paste keys = findEditorKeys(DefaultEditorKit.pasteAction, KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK)); for (int i = 0; i < keys.length; i++) { im.put(keys[i], NOOP_ACTION_KEY); } getActionMap().put(NOOP_ACTION_KEY, NOOP_ACTION); }
public void testPlainEditorKits() { // VIS: JEditorPane when constructed contains javax.swing.JEditorPane$PlainEditorKit // and calling JEP.setContenetType("text/plain") has no effect. IMO this is probably // a defect in JDK, becuase JEP should always honour its EditorKit registry. JEditorPane pane = new JEditorPane(); pane.setEditorKit(new DefaultEditorKit() { public @Override String getContentType() { return "text/whatever"; } }); setContentTypeInAwt(pane, "text/plain"); // Test JDK kit EditorKit kitFromJdk = pane.getEditorKit(); assertNotNull("Can't find JDK kit for text/plain", kitFromJdk); assertEquals("The kit for text/plain should not be from JDK", "org.netbeans.modules.editor.plain.PlainKit", kitFromJdk.getClass().getName()); // Test Netbeans kit EditorKit kitFromNb = CloneableEditorSupport.getEditorKit("text/plain"); assertNotNull("Can't find Nb kit for text/plain", kitFromNb); assertEquals("Wrong Nb kit for text/plain", "org.netbeans.modules.editor.plain.PlainKit", kitFromNb.getClass().getName()); }
/** Creates new form text */ public text() { //initComponents(); jScrollPane1 = new javax.swing.JScrollPane(); jTextPane1 = new javax.swing.JTextPane(); jScrollPane1.setViewportView(jTextPane1); jTextPane1.setFont(new java.awt.Font("Tahoma", 1, 11)); jTextPane1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { jTextPane1KeyReleased(evt); } }); add(jScrollPane1); h.initHexcode(); code=h.S; jTextPane1.getDocument().putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n"); }
/** * Adds particular key accelerators to the editor component. */ protected void addBindings(JTextPane editor) { InputMap inputMap = editor.getInputMap(); //Ctrl-c to copy current selection KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.copyAction); //Ctrl-v to paste clipboard content key = KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.pasteAction); //Ctrl-x to cut current selection key = KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK); inputMap.put(key, DefaultEditorKit.cutAction); }
@Override public void componentActivated() { cutAction.setEnabled(false); copyAction.setEnabled(false); pasteAction.setEnabled(false); // -- Updateing Cut/Copy/Paste acctions for this panel ------------------- ActionMap actionMap = getActionMap(); actionMap.put(DefaultEditorKit.cutAction, cutAction); actionMap.put(DefaultEditorKit.copyAction, copyAction); actionMap.put(DefaultEditorKit.pasteAction, pasteAction); // -- Start observing ---------------------------------------------------- cutAction.startObserving(); copyAction.startObserving(); pasteAction.startObserving(); // -- Adjusting size of the panel ---------------------------------------- if (isFirstRun) { Graphics g = getGraphics(); panel.paint(g); panel.adjustSize(); } }
private static void installMap(InputMap componentMap, boolean strict) { InputMap map = new AutoComplete.InputMap(); if (strict) { map.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), DefaultEditorKit.selectionBackwardAction); // ignore VK_DELETE and CTRL+VK_X and beep instead when strict matching map.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0), errorFeedbackAction); map.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_DOWN_MASK), errorFeedbackAction); } else { // VK_BACKSPACE will move the selection to the left if the selected item is in the list // it will delete the previous character otherwise map.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), "nonstrict-backspace"); // leave VK_DELETE and CTRL+VK_X as is } map.setParent(componentMap.getParent()); componentMap.setParent(map); }
/** * Replaces the editor's default copy action in security restricted * environments with one messaging the ClipboardService. Does nothing * if not restricted. * * @param editor the editor to replace */ public static void replaceCopyAction(final JEditorPane editor) { if (!isRestricted()) return; Action safeCopy = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { ClipboardService cs = (ClipboardService)ServiceManager.lookup ("javax.jnlp.ClipboardService"); StringSelection transferable = new StringSelection(editor.getSelectedText()); cs.setContents(transferable); } catch (Exception e1) { // do nothing } } }; editor.getActionMap().put(DefaultEditorKit.copyAction, safeCopy); }
public void updateActionEnabled(JComponent component, ActionMap map) { if (!(component instanceof JTextComponent)) return; JTextComponent textComponent = (JTextComponent) component; boolean selectedText = textComponent.getSelectionEnd() - textComponent.getSelectionStart() > 0; boolean containsText = textComponent.getDocument().getLength() > 0; boolean editable = textComponent.isEditable(); boolean copyProtected = (textComponent instanceof JPasswordField); boolean dataOnClipboard = textComponent.getToolkit() .getSystemClipboard().getContents(null) != null; map.get(DefaultEditorKit.cutAction).setEnabled( !copyProtected && editable && selectedText); map.get(DefaultEditorKit.copyAction).setEnabled( !copyProtected && selectedText); map.get(DefaultEditorKit.pasteAction).setEnabled( editable && dataOnClipboard); map.get(DefaultEditorKit.deleteNextCharAction).setEnabled( editable && selectedText); map.get(DefaultEditorKit.selectAllAction).setEnabled(containsText); }
/** * Based on: http://stackoverflow.com/a/7253059/2375667 */ private static void addMacKeyboardActionsTo(String key) { InputMap im = (InputMap) UIManager.get(key); // Copy/paste actions im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), DefaultEditorKit.copyAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK), DefaultEditorKit.pasteAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), DefaultEditorKit.cutAction); // Navigation actions im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.META_DOWN_MASK), DefaultEditorKit.beginLineAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.META_DOWN_MASK), DefaultEditorKit.endLineAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK), DefaultEditorKit.previousWordAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK), DefaultEditorKit.nextWordAction); // Navigation selection actions im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK), DefaultEditorKit.selectionBeginLineAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK), DefaultEditorKit.selectionEndLineAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK), DefaultEditorKit.selectionPreviousWordAction); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK), DefaultEditorKit.selectionNextWordAction); // Other actions im.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_DOWN_MASK), DefaultEditorKit.selectAllAction); }
@Override public Object get(KeyStroke keyStroke) { if (keyStroke.getKeyEventType() != KeyEvent.KEY_PRESSED) { Object retValue = super.get(keyStroke); if (retValue != null) { return retValue; } if (keyStroke.getKeyEventType() == KeyEvent.KEY_TYPED && keyStroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED && component instanceof JTextComponent) { return DefaultEditorKit.defaultKeyTypedAction; } } CommandKeymap keymap = CommandKeymap.getDefault(); String commandId = keymap.findCommand(keyStroke, component); LOG.debug("Search command. key:{}, context:{} -> command:{}", keyStroke, component.getComponentType(), commandId); if (commandId != null) { return commandId; } return super.get(keyStroke); }
@Nonnull @ReturnsOriginal public static JPopupMenu addTextActions(@Nonnull final JPopupMenu menu) { final Action cut = new DefaultEditorKit.CutAction(); cut.putValue(Action.NAME, "Cut"); menu.add(cut); final Action copy = new DefaultEditorKit.CopyAction(); copy.putValue(Action.NAME, "Copy"); menu.add(copy); final Action paste = new DefaultEditorKit.PasteAction(); paste.putValue(Action.NAME, "Paste"); menu.add(paste); menu.add(new SelectAllTextAction()); return menu; }
/** * <p>Adds 3 JMenuItems that perform Cut/Copy/Paste for any standard JMenu.</p> * * @param menu - the menu to append the CCP menu items */ public static void addCCPMenuItems(JMenu menu) { JMenuItem menuItem = null; menuItem = new JMenuItem(new DefaultEditorKit.CutAction()); menuItem.setText("Cut"); menuItem.setMnemonic(KeyEvent.VK_T); menu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CopyAction()); menuItem.setText("Copy"); menuItem.setMnemonic(KeyEvent.VK_C); menu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.PasteAction()); menuItem.setText("Paste"); menuItem.setMnemonic(KeyEvent.VK_P); menu.add(menuItem); }
/** * <p>Adds 3 JMenuItems that perform Cut/Copy/Paste for any standard JPopupMenu.</p> * * @param popupMenu - the popupMenu to append the CCP menu items */ public static void addCCPMenuItem(JPopupMenu popupMenu) { JMenuItem menuItem = null; menuItem = new JMenuItem(new DefaultEditorKit.CutAction()); menuItem.setText("Cut"); menuItem.setMnemonic(KeyEvent.VK_T); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK)); popupMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CopyAction()); menuItem.setText("Copy"); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK)); popupMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.PasteAction()); menuItem.setText("Paste"); menuItem.setMnemonic(KeyEvent.VK_P); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK)); popupMenu.add(menuItem); }
/** * action to be performed * * @param ev */ public void actionPerformed(ActionEvent ev) { Action textPaste = null; DefaultEditorKit kit = new DefaultEditorKit(); Action[] defActions = kit.getActions(); for (Action defAction : defActions) { if (defAction.getValue(Action.NAME) == DefaultEditorKit.pasteAction) { textPaste = defAction; break; } } final Action textPasteFinal = textPaste; if (multiViewer.getFrame().isActive() || textPasteFinal == null) { execute("paste;"); } else textPasteFinal.actionPerformed(ev); }
public static void addCopyPasteToPopupMenu(JPopupMenu menu, JComponent comp) { HashMap<Object, Action> actions = SwingUtil.createActionTable((JTextComponent) comp); Action cutAction = actions.get(DefaultEditorKit.cutAction); JMenuItem miCut = new JMenuItem(cutAction); miCut.setText(I18N.getMsg("msg.common.cut")); miCut.setIcon(I18N.getIcon("icon.small.cut")); menu.add(miCut); Action copyAction = actions.get(DefaultEditorKit.copyAction); JMenuItem miCopy = new JMenuItem(copyAction); miCopy.setText(I18N.getMsg("msg.common.copy")); miCopy.setIcon(I18N.getIcon("icon.small.copy")); menu.add(miCopy); Action pasteAction = actions.get(DefaultEditorKit.pasteAction); JMenuItem miPaste = new JMenuItem(pasteAction); miPaste.setText(I18N.getMsg("msg.common.paste")); miPaste.setIcon(I18N.getIcon("icon.small.paste")); menu.add(miPaste); }
public KeywordDocument(Set<String> keywords, Set<String> ports) { doc = this; rootElement = doc.getDefaultRootElement(); putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n"); normal = new SimpleAttributeSet(); StyleConstants.setForeground(normal, Color.black); comment = new SimpleAttributeSet(); StyleConstants.setForeground(comment, new Color(0, 139, 69, 255)); StyleConstants.setItalic(comment, true); keyword = new SimpleAttributeSet(); StyleConstants.setForeground(keyword, Color.blue); StyleConstants.setBold(keyword, true); port = new SimpleAttributeSet(); StyleConstants.setForeground(port, Color.magenta); quote = new SimpleAttributeSet(); StyleConstants.setForeground(quote, Color.red); this.keywords = keywords; this.ports = ports; }
protected JMenuBar createMenuBar() { JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); menubar.add(file); menubar.add(edit); file.add(getRun()); file.add(getOpenAction()); file.add(getSaveAction()); file.add(aboutAction); file.add(new ExitAction()); edit.add(textComp.getActionMap().get(DefaultEditorKit.cutAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.copyAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.pasteAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.selectAllAction)); return menubar; }
protected void makeActionsPretty() { Action a; a = textComp.getActionMap().get(DefaultEditorKit.cutAction); a.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif")); a.putValue(Action.NAME, "Cut"); a = textComp.getActionMap().get(DefaultEditorKit.copyAction); a.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif")); a.putValue(Action.NAME, "Copy"); a = textComp.getActionMap().get(DefaultEditorKit.pasteAction); a.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif")); a.putValue(Action.NAME, "Paste"); a = textComp.getActionMap().get(DefaultEditorKit.selectAllAction); a.putValue(Action.NAME, "Select All"); }
protected JMenuBar createMenuBar() { JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); menubar.add(file); menubar.add(edit); file.add(getOpenAction()); file.add(getSaveAction()); file.add(getRun()); file.add(new ExitAction()); edit.add(textComp.getActionMap().get(DefaultEditorKit.cutAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.copyAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.pasteAction)); edit.add(textComp.getActionMap().get(DefaultEditorKit.selectAllAction)); return menubar; }
private RepositoryTopComponent() { initComponents(); setName(NbBundle.getMessage(RepositoryTopComponent.class, "CTL_RepositoryTopComponent")); setToolTipText(NbBundle.getMessage(RepositoryTopComponent.class, "HINT_RepositoryTopComponent")); // setIcon(Utilities.loadImage(ICON_PATH, true)); ActionMap map = this.getActionMap (); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); associateLookup (ExplorerUtils.createLookup (manager, map)); BeanTreeView view = new BeanTreeView(); view.setRootVisible(false); manager.setRootContext(new AbstractNode(new ServerChildren())); add (view, BorderLayout.CENTER); //if ((Utilities.getOperatingSystem() & Utilities.OS_WINDOWS_MASK) != 0) { // view.getViewport().getView().setFont(new Font ("SansSerif", Font.PLAIN, 12)); //} jToolBar1.add(SystemAction.get(PublishReportUnitAction.class)); jToolBar1.add(SystemAction.get(RunReportUnitButton.class).createContextAwareInstance(Utilities.actionsGlobalContext())); }
public static JMenuBar makeManuBar() { JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("File"); Component edit = makeEditButtonBar(Arrays.asList( makeButton("Cut", new DefaultEditorKit.CutAction()), makeButton("Copy", new DefaultEditorKit.CopyAction()), makeButton("Paste", new DefaultEditorKit.PasteAction()))); menu.add("aaaaaaaaaa"); menu.addSeparator(); menu.add(makeEditMenuItem(edit)); menu.addSeparator(); menu.add("bbbb"); menu.add("cccccc"); menu.add("ddddd"); mb.add(menu); return mb; }
@Override public synchronized void replaceSelection(final String s) { if (!isEditable()) { new DefaultEditorKit.BeepAction().actionPerformed(null); return; } int start = getSelectionStart(); int end = getSelectionEnd(); Document doc = getDocument(); try { if (start != end) { doc.remove(start, end - start); } //May be these attributes placed in Document ???? AttributeSet as = (editorKit instanceof StyledEditorKit) ? ((StyledEditorKit) editorKit) .getInputAttributes() : null; if (s != null) { doc.insertString(start, s, as); } } catch (BadLocationException e) { } }
public void testFireActionPerformed() { SimpleActionListener listener1 = new SimpleActionListener("first"); SimpleActionListener listener2 = new SimpleActionListener("second"); SimpleActionListener listener3 = new SimpleActionListener("third"); jtf.addActionListener(listener1); jtf.addActionListener(listener2); jtf.addActionListener(listener3); fireOrder = ""; jtf.setAction(new DefaultEditorKit.BeepAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(final ActionEvent arg0) { fireOrder += "Action"; super.actionPerformed(arg0); } }); jtf.fireActionPerformed(); assertEquals("Actionthirdsecondfirst", fireOrder); }