Java Swing ActionMap printActionInputMap(JComponent comp)

Here you can find the source of printActionInputMap(JComponent comp)

Description

Print Action and Input Map for component

License

Open Source License

Parameter

Parameter Description
comp Component with ActionMap

Declaration

public static void printActionInputMap(JComponent comp) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Product: Adempiere ERP & CRM Smart Business Solution                       *
 * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.                *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 * For the text or an alternative of this public license, you may reach us    *
 * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
 * or via info@compiere.org or http://www.compiere.org/license.html           *
 *****************************************************************************/

import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.KeyStroke;

public class Main {
    /**//from  w w  w  .  j a  va2s . c  o m
     * Print Action and Input Map for component
     * @param comp  Component with ActionMap
     */
    public static void printActionInputMap(JComponent comp) {
        //   Action Map
        ActionMap am = comp.getActionMap();
        Object[] amKeys = am.allKeys(); //  including Parents
        if (amKeys != null) {
            System.out.println("-------------------------");
            System.out.println("ActionMap for Component " + comp.toString());
            for (int i = 0; i < amKeys.length; i++) {
                Action a = am.get(amKeys[i]);

                StringBuffer sb = new StringBuffer("- ");
                sb.append(a.getValue(Action.NAME));
                if (a.getValue(Action.ACTION_COMMAND_KEY) != null)
                    sb.append(", Cmd=").append(a.getValue(Action.ACTION_COMMAND_KEY));
                if (a.getValue(Action.SHORT_DESCRIPTION) != null)
                    sb.append(" - ").append(a.getValue(Action.SHORT_DESCRIPTION));
                System.out.println(sb.toString() + " - " + a);
            }
        }
        /**   Same as below
        KeyStroke[] kStrokes = comp.getRegisteredKeyStrokes();
        if (kStrokes != null)
        {
        System.out.println("-------------------------");
           System.out.println("Registered Key Strokes - " + comp.toString());
           for (int i = 0; i < kStrokes.length; i++)
           {
        System.out.println("- " + kStrokes[i].toString());
           }
        }
        /** Focused            */
        InputMap im = comp.getInputMap(JComponent.WHEN_FOCUSED);
        KeyStroke[] kStrokes = im.allKeys();
        if (kStrokes != null) {
            System.out.println("-------------------------");
            System.out.println("InputMap for Component When Focused - " + comp.toString());
            for (int i = 0; i < kStrokes.length; i++) {
                System.out.println("- " + kStrokes[i].toString() + " - " + im.get(kStrokes[i]).toString());
            }
        }
        /** Focused in Window   */
        im = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        kStrokes = im.allKeys();
        if (kStrokes != null) {
            System.out.println("-------------------------");
            System.out.println("InputMap for Component When Focused in Window - " + comp.toString());
            for (int i = 0; i < kStrokes.length; i++) {
                System.out.println("- " + kStrokes[i].toString() + " - " + im.get(kStrokes[i]).toString());
            }
        }
        /** Focused when Ancester   */
        im = comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        kStrokes = im.allKeys();
        if (kStrokes != null) {
            System.out.println("-------------------------");
            System.out.println("InputMap for Component When Ancestor - " + comp.toString());
            for (int i = 0; i < kStrokes.length; i++) {
                System.out.println("- " + kStrokes[i].toString() + " - " + im.get(kStrokes[i]).toString());
            }
        }
        System.out.println("-------------------------");
    }
}

Related

  1. checkActions(JComponent aComponent)
  2. cloneActionMap(ActionMap original)
  3. dumpActionMap(JComponent comp)
  4. fillInputMap(ActionMap am)
  5. installActions(JComponent comp, Action actions[], int condition)
  6. printActionMap(ActionMap actionMap, String who)
  7. putAction(Action action)
  8. putAction(JComponent component, Action action)
  9. registerAction(JComponent component, int condition, Action action, String command)