Java Swing ActionMap registerUndoRedoActions(JComponent jtc, Action undoAction, Action redoAction)

Here you can find the source of registerUndoRedoActions(JComponent jtc, Action undoAction, Action redoAction)

Description

register Undo Redo Actions

License

Open Source License

Declaration

public static void registerUndoRedoActions(JComponent jtc, Action undoAction, Action redoAction) 

Method Source Code

//package com.java2s;
/*//from   w ww  .j a  va  2  s. c  om
   Copyright (c) 2009-2011 Olivier Chafik, All Rights Reserved
       
   This file is part of JNAerator (http://jnaerator.googlecode.com/).
       
   JNAerator is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
       
   JNAerator is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
       
   You should have received a copy of the GNU General Public License
   along with JNAerator.  If not, see <http://www.gnu.org/licenses/>.
*/

import javax.swing.Action;
import javax.swing.ActionMap;

import javax.swing.InputMap;
import javax.swing.JComponent;

import javax.swing.KeyStroke;

public class Main {
    public static void registerUndoRedoActions(JComponent jtc, Action undoAction, Action redoAction) {
        InputMap inputMap = jtc.getInputMap();
        inputMap.put(KeyStroke.getKeyStroke("pressed UNDO"), "undo");
        inputMap.put(KeyStroke.getKeyStroke("ctrl pressed Z"), "undo");
        inputMap.put(KeyStroke.getKeyStroke("meta pressed Z"), "undo");

        inputMap.put(KeyStroke.getKeyStroke("pressed REDO"), "redo");
        inputMap.put(KeyStroke.getKeyStroke("ctrl pressed Y"), "redo");
        inputMap.put(KeyStroke.getKeyStroke("meta pressed Y"), "redo");

        ActionMap actionMap = jtc.getActionMap();
        actionMap.put("undo", undoAction);
        actionMap.put("redo", redoAction);
    }
}

Related

  1. printActionInputMap(JComponent comp)
  2. printActionMap(ActionMap actionMap, String who)
  3. putAction(Action action)
  4. putAction(JComponent component, Action action)
  5. registerAction(JComponent component, int condition, Action action, String command)
  6. removeAction(InputMap im, ActionMap am, String name)
  7. sysoutActionMap(JComponent com)