API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.swing. ComponentInputMap View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

/*
 * @(#)ComponentInputMap.java	1.11 06/04/07
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package javax.swing;

/**
 * A <code>ComponentInputMap</code> is an <code>InputMap</code>
 * associated with a particular <code>JComponent</code>.
 * The component is automatically notified whenever
 * the <code>ComponentInputMap</code> changes.
 * <code>ComponentInputMap</code>s are used for
 * <code>WHEN_IN_FOCUSED_WINDOW</code> bindings.
 *
 * @version 1.11 04/07/06
 * @author Scott Violet
 * @since 1.3
 */
public class ComponentInputMap extends InputMap {
    /** Component binding is created for. */
    private JComponent          component;

    /**
     * Creates a <code>ComponentInputMap</code> associated with the 
     * specified component.  
     *
     * @param component  a non-null <code>JComponent</code>
     * @throws IllegalArgumentException  if <code>component</code> is null
     */
    public ComponentInputMap(JComponent component) {
	this.component = component;
	if (component == null) {
	    throw new IllegalArgumentException("ComponentInputMaps must be associated with a non-null JComponent");
	}
    }

    /**
     * Sets the parent, which must be a <code>ComponentInputMap</code>
     * associated with the same component as this
     * <code>ComponentInputMap</code>.
     *
     * @param map  a <code>ComponentInputMap</code>
     *           
     * @throws IllegalArgumentException  if <code>map</code>
     *         is not a <code>ComponentInputMap</code>
     *         or is not associated with the same component
     */
    public void setParent(InputMap map) {
	if (getParent() == map) {
	    return;
	}
	if (map != null && (!(map instanceof ComponentInputMap) ||
		 ((ComponentInputMap)map).getComponent() != getComponent())) {
	    throw new IllegalArgumentException("ComponentInputMaps must have a parent ComponentInputMap associated with the same component");
	}
	super.setParent(map);
	getComponent().componentInputMapChanged(this);
    }

    /**
     * Returns the component the <code>InputMap</code> was created for.
     */
    public JComponent getComponent() {
	return component;
    }

    /**
     * Adds a binding for <code>keyStroke</code> to <code>actionMapKey</code>.
     * If <code>actionMapKey</code> is null, this removes the current binding
     * for <code>keyStroke</code>.
     */
    public void put(KeyStroke keyStroke, Object actionMapKey) {
	super.put(keyStroke, actionMapKey);
	if (getComponent() != null) {
	    getComponent().componentInputMapChanged(this);
	}
    }

    /**
     * Removes the binding for <code>key</code> from this object.
     */
    public void remove(KeyStroke key) {
	super.remove(key);
	if (getComponent() != null) {
	    getComponent().componentInputMapChanged(this);
	}
    }

    /**
     * Removes all the mappings from this object.
     */
    public void clear() {
	int oldSize = size();
	super.clear();
	if (oldSize > 0 && getComponent() != null) {
	    getComponent().componentInputMapChanged(this);
	}
    }
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar