Java Code Examples for javax.swing.text.DefaultEditorKit

The following examples show how to use javax.swing.text.DefaultEditorKit. These examples are extracted from open source projects. 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 Project: netbeans   Source File: EditorSanityTest.java    License: 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 2
Source Project: netbeans   Source File: JavaViewHierarchyRandomTest.java    License: 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 3
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 4
Source Project: netbeans   Source File: JavaViewHierarchyRandomTest.java    License: 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 5
Source Project: netbeans   Source File: JavaViewHierarchyRandomTest.java    License: 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 6
Source Project: netbeans   Source File: NbEditorToolBar.java    License: 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 7
Source Project: netbeans-mmd-plugin   Source File: SwingUtils.java    License: 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 8
Source Project: desktopclient-java   Source File: Utils.java    License: 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 9
Source Project: uima-uimaj   Source File: LogFileViewer.java    License: 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 10
Source Project: java-swing-tips   Source File: MainPanel.java    License: 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 11
Source Project: netbeans   Source File: ServicesTab.java    License: 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 12
Source Project: pcgen   Source File: PCGenMenuBar.java    License: 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 13
Source Project: netbeans   Source File: CommitPopupBuilder.java    License: 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 14
Source Project: netbeans   Source File: CatalogPanel.java    License: 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 15
Source Project: netbeans   Source File: EditorPaneTesting.java    License: 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 16
Source Project: darklaf   Source File: DarkPasswordFieldUIBridge.java    License: 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 17
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
 
Example 18
Source Project: dragonwell8_jdk   Source File: Test6462562.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
 
Example 19
Source Project: TencentKona-8   Source File: bug6474153.java    License: 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 20
Source Project: TencentKona-8   Source File: Test6462562.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
 
Example 21
Source Project: openjdk-jdk9   Source File: Test6462562.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
 
Example 22
Source Project: jdk8u60   Source File: Test6462562.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
 
Example 23
Source Project: jdk8u-jdk   Source File: bug6474153.java    License: 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 24
Source Project: workcraft   Source File: LookAndFeelHelper.java    License: MIT License 5 votes vote down vote up
public static void setDefaultLookAndFeel() {
    String laf = UIManager.getCrossPlatformLookAndFeelClassName();
    InputMap textFieldInputMap = (InputMap) UIManager.get("TextField.focusInputMap");
    InputMap textAreaInputMap = (InputMap) UIManager.get("TextArea.focusInputMap");
    setLookAndFeel(laf);
    if (DesktopApi.getOs().isMac()) {
        textFieldInputMap.put(KeyStroke.getKeyStroke("UP"), DefaultEditorKit.upAction);
        textAreaInputMap.put(KeyStroke.getKeyStroke("UP"), DefaultEditorKit.upAction);
        textFieldInputMap.put(KeyStroke.getKeyStroke("DOWN"), DefaultEditorKit.downAction);
        textAreaInputMap.put(KeyStroke.getKeyStroke("DOWN"), DefaultEditorKit.downAction);
        UIManager.put("TextField.focusInputMap", textFieldInputMap);
        UIManager.put("TextArea.focusInputMap", textAreaInputMap);
    }
}
 
Example 25
Source Project: openjdk-8-source   Source File: bug6474153.java    License: 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 26
Source Project: openjdk-jdk8u   Source File: Test6462562.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
 
Example 27
Source Project: netbeans   Source File: ComponentInspector.java    License: Apache License 2.0 5 votes vote down vote up
final javax.swing.ActionMap setupActionMap(javax.swing.ActionMap map) {
    map.put(DefaultEditorKit.copyAction, copyActionPerformer);
    map.put(DefaultEditorKit.cutAction, cutActionPerformer);
    //map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(explorerManager));
    map.put("delete", deleteActionPerformer); // NOI18N

    return map;
}
 
Example 28
Source Project: netbeans   Source File: PhadhailViews.java    License: Apache License 2.0 5 votes vote down vote up
public ExpPanel() {
    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));
    lookup = ExplorerUtils.createLookup(manager, map);
    InputMap keys = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    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 Project: binnavi   Source File: ConsoleCodeDocument.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructor. Sets up the styles and add the strings to be highlighted into the corresponding
 * vectors.
 */
public ConsoleCodeDocument() {
  super(false);

  putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n");

  StyleConstants.setForeground(pythonPromptAttr, Color.LIGHT_GRAY);
  StyleConstants.setBold(pythonPromptAttr, true);
  StyleConstants.setFontSize(pythonPromptAttr, 13);
}
 
Example 30
Source Project: netbeans   Source File: CallbackSystemActionTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testGlobalChanges() throws Exception {
    class MyAction extends AbstractAction {
        public int cntEnabled;
        public int cntPerformed;
        
        public boolean isEnabled() {
            cntEnabled++;
            return true;
        }
        
        public void actionPerformed(ActionEvent ev) {
            cntPerformed++;
        }
    }
    MyAction myAction = new MyAction();
    
    ActionMap tc = new ActionMap();
    tc.put(DefaultEditorKit.copyAction, myAction);
    CopyAction a = (CopyAction)CopyAction.get(CopyAction.class);
    
    ActionsInfraHid.setActionMap(tc);
    try {
        assertTrue("MyAction is enabled", a.isEnabled());
        assertEquals("isEnabled called once", 1, myAction.cntEnabled);
        a.setActionPerformer(null);
        assertEquals("An enabled is currentlly called again", 2, myAction.cntEnabled);
    } finally {
        ActionsInfraHid.setActionMap(null);
    }
}