javax.swing.text.DefaultEditorKit Java Examples

The following examples show how to use javax.swing.text.DefaultEditorKit. 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: Utils.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
static WebPopupMenu createCopyMenu(boolean modifiable) {
    WebPopupMenu menu = new WebPopupMenu();
    if (modifiable) {
        Action cut = new DefaultEditorKit.CutAction();
        cut.putValue(Action.NAME, Tr.tr("Cut"));
        cut.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control X"));
        menu.add(cut);
    }

    Action copy = new DefaultEditorKit.CopyAction();
    copy.putValue(Action.NAME, Tr.tr("Copy"));
    copy.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control C"));
    menu.add(copy);

    if (modifiable) {
        Action paste = new DefaultEditorKit.PasteAction();
        paste.putValue(Action.NAME, Tr.tr("Paste"));
        paste.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control V"));
        menu.add(paste);
    }

    return menu;
}
 
Example #2
Source File: PCGenMenuBar.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private JMenu createEditMenu()
{
	JMenu menu = new JMenu();
	menu.setText(LanguageBundle.getString("in_mnuEdit"));
	menu.setMnemonic(KeyEvent.VK_E);
	menu.add(new JMenuItem(actionMap.get(PCGenActionMap.ADD_KIT_COMMAND)));
	menu.addSeparator();
	menu.add(tempMenu);
	menu.addSeparator();

	JMenuItem cutMenuItem = new JMenuItem(new DefaultEditorKit.CutAction());
	cutMenuItem.setText("Cut");
	cutMenuItem.setMnemonic(KeyEvent.VK_T);
	menu.add(cutMenuItem);

	JMenuItem copyMenuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
	copyMenuItem.setText("Copy");
	copyMenuItem.setMnemonic(KeyEvent.VK_C);
	menu.add(copyMenuItem);

	JMenuItem pasteMenuItem = new JMenuItem(new DefaultEditorKit.PasteAction());
	pasteMenuItem.setText("Paste");
	pasteMenuItem.setMnemonic(KeyEvent.VK_P);
	menu.add(pasteMenuItem);
	return menu;
}
 
Example #3
Source File: CommitPopupBuilder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #4
Source File: CatalogPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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();
    
}
 
Example #5
Source File: EditorPaneTesting.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #6
Source File: EditorSanityTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #7
Source File: ServicesTab.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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"));
}
 
Example #8
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static JMenuBar createMenuBar() {
  Component edit = makeEditButtonBar(Arrays.asList(
      makeButton("Cut", new DefaultEditorKit.CutAction()),
      makeButton("Copy", new DefaultEditorKit.CopyAction()),
      makeButton("Paste", new DefaultEditorKit.PasteAction())));

  JMenu menu = new JMenu("File");
  menu.add("111111111");
  menu.addSeparator();
  menu.add(makeEditMenuItem(edit));
  menu.addSeparator();
  menu.add("22222");
  menu.add("3333");
  menu.add("4444444");

  JMenuBar mb = new JMenuBar();
  mb.add(menu);
  return mb;
}
 
Example #9
Source File: JavaViewHierarchyRandomTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #10
Source File: LogFileViewer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Inits the.
 *
 * @param file the file
 * @param d the d
 */
public void init(File file, Dimension d) {
	createMenus();
	this.logFile = file;
	this.textArea = new JTextArea();
	// Copy
	Action copyAction = this.textArea.getActionMap().get(DefaultEditorKit.copyAction);
	copyAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,
			InputEvent.CTRL_MASK));
	copyAction.setEnabled(true);
	this.scrollPane = new JScrollPane(this.textArea);
	this.setContentPane(this.scrollPane);
	this.scrollPane.setPreferredSize(d);
	boolean doneLoadingFile = loadFile();
	if (!doneLoadingFile) {
		this.dispose();
		return;
	}
	this.pack();
	this.setVisible(true);
}
 
Example #11
Source File: ProductSceneViewTopComponent.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private void updateActionMap(Selection newSelection) {
    ActionMap actionMap = getActionMap();
    actionMap.put(SelectionActions.SELECT_ALL, new SelectAllAction());
    actionMap.put(DefaultEditorKit.pasteAction, new PasteAction());
    if (!newSelection.isEmpty()) {
        actionMap.put(DefaultEditorKit.cutAction, new CutAction());
        actionMap.put(DefaultEditorKit.copyAction, new CopyAction());
        actionMap.put("delete", new DeleteAction());
        actionMap.put(SelectionActions.DESELECT_ALL, new DeselectAllAction());
    } else {
        actionMap.remove(DefaultEditorKit.cutAction);
        actionMap.remove(DefaultEditorKit.copyAction);
        actionMap.remove("delete");
        actionMap.remove(SelectionActions.DESELECT_ALL);
    }
    getDynamicContent().remove(actionMap);
    getDynamicContent().add(actionMap);
}
 
Example #12
Source File: JavaViewHierarchyRandomTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
    }
 
Example #13
Source File: JavaViewHierarchyRandomTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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');
    }
 
Example #14
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: SwingUtils.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #16
Source File: AnnotationHolderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public Lookup getLookup(MimePath mimePath) {
    return Lookups.singleton(new DefaultEditorKit() {
        @Override
        public Document createDefaultDocument() {
            return new GuardedDocument(this.getClass());
        }
    });
}
 
Example #17
Source File: Tab.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates */
private Tab() {
    this.manager = new ExplorerManager();
    
    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));
    map.put("delete", ExplorerUtils.actionDelete (manager, true)); // or false

    // following line tells the top component which lookup should be associated with it
    associateLookup (ExplorerUtils.createLookup (manager, map));
}
 
Example #18
Source File: bug6474153.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkArray(JTextComponent.KeyBinding[] keyActionArray) {
    if (keyActionArray.length != 1) {
        throw new RuntimeException("Wrong array lenght!");
    }
    if (!DefaultEditorKit.upAction.equals(keyActionArray[0].actionName)) {
        throw new RuntimeException("Wrong action name!");
    }
    if (!KeyStroke.getKeyStroke("UP").equals(keyActionArray[0].key)) {
        throw new RuntimeException("Wrong keystroke!");
    }
}
 
Example #19
Source File: JsCommentGeneratorEmbeddedTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void insertNewline(String source, String reformatted, IndentPrefs preferences) throws Exception {
    int sourcePos = source.indexOf('^');
    assertNotNull(sourcePos);
    source = source.substring(0, sourcePos) + source.substring(sourcePos + 1);
    Formatter formatter = getFormatter(null);

    int reformattedPos = reformatted.indexOf('^');
    assertNotNull(reformattedPos);
    reformatted = reformatted.substring(0, reformattedPos) + reformatted.substring(reformattedPos + 1);

    JEditorPane ta = getPane(source);
    Caret caret = ta.getCaret();
    caret.setDot(sourcePos);
    BaseDocument doc = (BaseDocument) ta.getDocument();
    if (formatter != null) {
        configureIndenters(doc, formatter, true);
    }

    setupDocumentIndentation(doc, preferences);

    runKitAction(ta, DefaultEditorKit.insertBreakAction, "\n");

    // wait for generating comment
    Future<?> future = JsDocumentationCompleter.RP.submit(new Runnable() {
        @Override
        public void run() {
        }
    });
    future.get();

    String formatted = doc.getText(0, doc.getLength());
    assertEquals(reformatted, formatted);

    if (reformattedPos != -1) {
        assertEquals(reformattedPos, caret.getDot());
    }
}
 
Example #20
Source File: LafManagerImplUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void installCutCopyPasteShortcuts(InputMap inputMap, boolean useSimpleActionKeys) {
  String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction;
  String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction;
  String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction;
  // Ctrl+Ins, Shift+Ins, Shift+Del
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), copyActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK), pasteActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK), cutActionKey);
  // Ctrl+C, Ctrl+V, Ctrl+X
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), copyActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), pasteActionKey);
  inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK), DefaultEditorKit.cutAction);
}
 
Example #21
Source File: MultiplePasteAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isEnabled(AnActionEvent e) {
  Object component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  if (!(component instanceof JComponent)) return false;
  Editor editor = e.getData(CommonDataKeys.EDITOR);
  if (editor != null) return !editor.isViewer();
  Action pasteAction = ((JComponent)component).getActionMap().get(DefaultEditorKit.pasteAction);
  return pasteAction != null;
}
 
Example #22
Source File: DemoUtils.java    From java-ocr-api with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void enableMenu(JTextComponent text) {
    final Action actionCopySelected = text.getActionMap().get(DefaultEditorKit.copyAction);
    final Action actionSelectAll = text.getActionMap().get(DefaultEditorKit.selectAllAction);
    final Action actionUnselect = text.getActionMap().get("unselect");
    Action actionCopyAll = new AbstractAction("Copy All to System Clipboard") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if(actionSelectAll != null) {
                actionSelectAll.actionPerformed(e);
            }
            if(actionCopySelected != null) {
                actionCopySelected.actionPerformed(e);
            }
            if(actionUnselect != null) {
                actionUnselect.actionPerformed(e);
            }
        }
    };

    JPopupMenu popupMenu = new JPopupMenu();
    if(actionCopySelected != null) {
        actionCopySelected.putValue(Action.NAME, "Copy Selected");
        popupMenu.add(actionCopySelected);
    }
    if(actionSelectAll != null && actionCopySelected != null) {
        popupMenu.add(actionCopyAll);
    }
    text.setComponentPopupMenu(popupMenu);
}
 
Example #23
Source File: Install.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public EM() {
    manager = new ExplorerManager();
    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, true)); // or false
    
    lookup = ExplorerUtils.createLookup(manager, map);
    
    initComponent();
}
 
Example #24
Source File: Customizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new Customizer */
public Customizer( Node paletteRoot, PaletteController controller, Settings settings ) {
    this.root = paletteRoot;
    this.controller = controller;
    this.settings = settings;
    explorerManager = new ExplorerManager();

    ActionMap map = getActionMap();
    map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(explorerManager));
    map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(explorerManager));
    map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(explorerManager));
    map.put("delete", ExplorerUtils.actionDelete(explorerManager, true)); // NOI18N

    lookup = ExplorerUtils.createLookup(explorerManager, map);

    explorerManager.setRootContext(paletteRoot);

    initComponents();
    
    createCustomButtons();

    CheckTreeView treeView = new CheckTreeView( settings );
    treeView.getAccessibleContext().setAccessibleName(
        Utils.getBundleString("ACSN_PaletteContentsTree")); // NOI18N
    treeView.getAccessibleContext().setAccessibleDescription(
        Utils.getBundleString("ACSD_PaletteContentsTree")); // NOI18N
    treePanel.add(treeView, java.awt.BorderLayout.CENTER);
    captionLabel.setLabelFor(treeView);

    explorerManager.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent ev) {
            if (ExplorerManager.PROP_SELECTED_NODES.equals(ev.getPropertyName())) {
                updateInfoLabel(explorerManager.getSelectedNodes());
                updateButtons();
            }
        }
    });
    updateButtons();
}
 
Example #25
Source File: ClipboardBase.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
static public Action getPasteDefaultKit() {
    Action action = findAction(DefaultEditorKit.pasteAction);
    if (action == null)
        return null;

    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
    action.putValue(Action.SHORT_DESCRIPTION, "Paste");

    action.putValue(AbstractAction.SMALL_ICON, ResourceManager.getIcon("sun/Paste16.gif"));

    return action;
}
 
Example #26
Source File: DarkPasswordFieldUIBridge.java    From darklaf with MIT License 5 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();
    ActionMap map = getComponent().getActionMap();
    if (map.get(DefaultEditorKit.selectWordAction) != null) {
        Action a = map.get(DefaultEditorKit.selectLineAction);
        if (a != null) {
            map.remove(DefaultEditorKit.selectWordAction);
            map.put(DefaultEditorKit.selectWordAction, a);
        }
    }
}
 
Example #27
Source File: ComponentSource.java    From LoboBrowser with MIT License 5 votes vote down vote up
public JMenu getEditMenu() {
  final JMenu menu = new JMenu("Edit");
  menu.setMnemonic('E');

  menu.add(menuItem("Cut", 'X', KeyStroke.getKeyStroke(KeyEvent.VK_X, CMD_CTRL_KEY_MASK), new DefaultEditorKit.CutAction()));
  menu.add(menuItem("Copy", 'C', KeyStroke.getKeyStroke(KeyEvent.VK_C, CMD_CTRL_KEY_MASK), new DefaultEditorKit.CopyAction()));
  menu.add(menuItem("Paste", 'V', KeyStroke.getKeyStroke(KeyEvent.VK_V, CMD_CTRL_KEY_MASK), new DefaultEditorKit.PasteAction()));

  return menu;
}
 
Example #28
Source File: QueryBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void installActions(ActionMap map, InputMap keys) {
   /*
    map.put(DefaultEditorKit.copyAction, copyActionPerformer);
    map.put(DefaultEditorKit.cutAction, cutActionPerformer);
    // Paste still done the old way...
    //map.put(DefaultEditorKit.pasteAction, pasteActionPerformer);
    */
    map.put("delete", deleteActionPerformer); // or false
    map.put(DefaultEditorKit.copyAction, copyActionPerformer);
    map.put(DefaultEditorKit.cutAction, cutActionPerformer); 

    /*
    // Popup menu from the keyboard
    map.put ("org.openide.actions.PopupAction",
            new AbstractAction() {
        public void actionPerformed(ActionEvent evt) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    showKeyboardPopup();
                }
            });
        }
    });

    keys.put(KeyStroke.getKeyStroke("control C"), DefaultEditorKit.copyAction);
    keys.put(KeyStroke.getKeyStroke("control X"), DefaultEditorKit.cutAction);
    keys.put(KeyStroke.getKeyStroke("control V"), DefaultEditorKit.pasteAction);
     */
    keys.put(KeyStroke.getKeyStroke("DELETE"), "delete");
}
 
Example #29
Source File: ClipboardBase.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
static public Action getSelectAllDefaultEditorKit() {
    Action action = findAction(DefaultEditorKit.selectAllAction);
    if (action == null)
        return null;
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
    action.putValue(Action.SHORT_DESCRIPTION, "Select All");

    return action;
}
 
Example #30
Source File: MainFrame.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void remapCommandOnMac() {
    // Remap to command v and C on a Mac
    if (Bither.getGenericApplication() != null && Bither.getGenericApplication().isMac()) {
        InputMap im = (InputMap) UIManager.get("TextField.focusInputMap");
        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);
    }

}