0N/A/*
2362N/A * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/A/**
0N/A * A <code>ComponentInputMap</code> is an <code>InputMap</code>
0N/A * associated with a particular <code>JComponent</code>.
0N/A * The component is automatically notified whenever
0N/A * the <code>ComponentInputMap</code> changes.
0N/A * <code>ComponentInputMap</code>s are used for
0N/A * <code>WHEN_IN_FOCUSED_WINDOW</code> bindings.
0N/A *
0N/A * @author Scott Violet
0N/A * @since 1.3
0N/A */
0N/Apublic class ComponentInputMap extends InputMap {
0N/A /** Component binding is created for. */
0N/A private JComponent component;
0N/A
0N/A /**
0N/A * Creates a <code>ComponentInputMap</code> associated with the
0N/A * specified component.
0N/A *
0N/A * @param component a non-null <code>JComponent</code>
0N/A * @throws IllegalArgumentException if <code>component</code> is null
0N/A */
0N/A public ComponentInputMap(JComponent component) {
0N/A this.component = component;
0N/A if (component == null) {
0N/A throw new IllegalArgumentException("ComponentInputMaps must be associated with a non-null JComponent");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the parent, which must be a <code>ComponentInputMap</code>
0N/A * associated with the same component as this
0N/A * <code>ComponentInputMap</code>.
0N/A *
0N/A * @param map a <code>ComponentInputMap</code>
0N/A *
0N/A * @throws IllegalArgumentException if <code>map</code>
0N/A * is not a <code>ComponentInputMap</code>
0N/A * or is not associated with the same component
0N/A */
0N/A public void setParent(InputMap map) {
0N/A if (getParent() == map) {
0N/A return;
0N/A }
0N/A if (map != null && (!(map instanceof ComponentInputMap) ||
0N/A ((ComponentInputMap)map).getComponent() != getComponent())) {
0N/A throw new IllegalArgumentException("ComponentInputMaps must have a parent ComponentInputMap associated with the same component");
0N/A }
0N/A super.setParent(map);
0N/A getComponent().componentInputMapChanged(this);
0N/A }
0N/A
0N/A /**
0N/A * Returns the component the <code>InputMap</code> was created for.
0N/A */
0N/A public JComponent getComponent() {
0N/A return component;
0N/A }
0N/A
0N/A /**
0N/A * Adds a binding for <code>keyStroke</code> to <code>actionMapKey</code>.
0N/A * If <code>actionMapKey</code> is null, this removes the current binding
0N/A * for <code>keyStroke</code>.
0N/A */
0N/A public void put(KeyStroke keyStroke, Object actionMapKey) {
0N/A super.put(keyStroke, actionMapKey);
0N/A if (getComponent() != null) {
0N/A getComponent().componentInputMapChanged(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes the binding for <code>key</code> from this object.
0N/A */
0N/A public void remove(KeyStroke key) {
0N/A super.remove(key);
0N/A if (getComponent() != null) {
0N/A getComponent().componentInputMapChanged(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes all the mappings from this object.
0N/A */
0N/A public void clear() {
0N/A int oldSize = size();
0N/A super.clear();
0N/A if (oldSize > 0 && getComponent() != null) {
0N/A getComponent().componentInputMapChanged(this);
0N/A }
0N/A }
0N/A}