javax.swing.text.DefaultEditorKit源码实例Demo

类javax.swing.text.DefaultEditorKit源码实例Demo

下面列出了javax.swing.text.DefaultEditorKit 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: EditorSanityTest.java
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());
}
 
源代码2 项目: netbeans   文件: JavaViewHierarchyRandomTest.java
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);
}
 
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);
}
 
源代码4 项目: netbeans   文件: JavaViewHierarchyRandomTest.java
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);
    }
 
源代码5 项目: netbeans   文件: JavaViewHierarchyRandomTest.java
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');
    }
 
源代码6 项目: netbeans   文件: NbEditorToolBar.java
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);
}
 
源代码7 项目: netbeans-mmd-plugin   文件: SwingUtils.java
@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;
}
 
源代码8 项目: desktopclient-java   文件: Utils.java
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;
}
 
源代码9 项目: uima-uimaj   文件: LogFileViewer.java
/**
 * 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);
}
 
源代码10 项目: java-swing-tips   文件: MainPanel.java
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;
}
 
源代码11 项目: netbeans   文件: ServicesTab.java
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"));
}
 
源代码12 项目: pcgen   文件: PCGenMenuBar.java
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;
}
 
源代码13 项目: netbeans   文件: CommitPopupBuilder.java
/**
 * 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));
}
 
源代码14 项目: netbeans   文件: CatalogPanel.java
/** 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();
    
}
 
源代码15 项目: netbeans   文件: EditorPaneTesting.java
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);
        }
    }
}
 
源代码16 项目: darklaf   文件: DarkPasswordFieldUIBridge.java
@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);
        }
    }
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: Test6462562.java
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);
}
 
源代码18 项目: dragonwell8_jdk   文件: Test6462562.java
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);
}
 
源代码19 项目: TencentKona-8   文件: bug6474153.java
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!");
    }
}
 
源代码20 项目: TencentKona-8   文件: Test6462562.java
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);
}
 
源代码21 项目: openjdk-jdk9   文件: Test6462562.java
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);
}
 
源代码22 项目: jdk8u60   文件: Test6462562.java
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);
}
 
源代码23 项目: jdk8u-jdk   文件: bug6474153.java
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!");
    }
}
 
源代码24 项目: workcraft   文件: LookAndFeelHelper.java
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);
    }
}
 
源代码25 项目: openjdk-8-source   文件: bug6474153.java
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!");
    }
}
 
源代码26 项目: openjdk-jdk8u   文件: Test6462562.java
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);
}
 
源代码27 项目: netbeans   文件: ComponentInspector.java
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;
}
 
源代码28 项目: netbeans   文件: PhadhailViews.java
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");
}
 
源代码29 项目: binnavi   文件: ConsoleCodeDocument.java
/**
 * 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);
}
 
源代码30 项目: netbeans   文件: CallbackSystemActionTest.java
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);
    }
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 同包方法