001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing;
021:
022: import java.awt.AWTKeyStroke;
023: import java.awt.event.KeyEvent;
024: import java.io.Serializable;
025:
026: import org.apache.harmony.x.swing.Utilities;
027:
028: public class KeyStroke extends AWTKeyStroke implements Serializable {
029:
030: static {
031: AWTKeyStroke.registerSubclass(KeyStroke.class);
032: }
033:
034: private KeyStroke() {
035: super ();
036: }
037:
038: private KeyStroke(final char keyChar, final int keyCode,
039: final int modifiers, final boolean onKeyRelease) {
040: super (keyChar, keyCode, modifiers, onKeyRelease);
041: }
042:
043: public static KeyStroke getKeyStroke(final String str) {
044: if (Utilities.isEmptyString(str)) {
045: return null;
046: }
047: synchronized (AWTKeyStroke.class) {
048: try {
049: return (KeyStroke) AWTKeyStroke.getAWTKeyStroke(str);
050: } catch (IllegalArgumentException e) {
051: return null;
052: }
053: }
054: }
055:
056: public static KeyStroke getKeyStroke(final Character keyChar,
057: final int modifiers) {
058: synchronized (AWTKeyStroke.class) {
059: return (KeyStroke) AWTKeyStroke.getAWTKeyStroke(keyChar,
060: modifiers);
061: }
062: }
063:
064: public static KeyStroke getKeyStrokeForEvent(final KeyEvent event) {
065: synchronized (AWTKeyStroke.class) {
066: return (KeyStroke) AWTKeyStroke
067: .getAWTKeyStrokeForEvent(event);
068: }
069: }
070:
071: public static KeyStroke getKeyStroke(final int keyCode,
072: final int modifiers, final boolean onKeyRelease) {
073: synchronized (AWTKeyStroke.class) {
074: return (KeyStroke) AWTKeyStroke.getAWTKeyStroke(keyCode,
075: modifiers, onKeyRelease);
076: }
077: }
078:
079: public static KeyStroke getKeyStroke(final int keyCode,
080: final int modifiers) {
081: synchronized (AWTKeyStroke.class) {
082: return (KeyStroke) AWTKeyStroke.getAWTKeyStroke(keyCode,
083: modifiers);
084: }
085: }
086:
087: /**
088: * @deprecated <i>use getKeyStroke(char)</i>
089: */
090: public static KeyStroke getKeyStroke(final char keyChar,
091: final boolean onKeyRelease) {
092: return new KeyStroke(keyChar, 0, 0, onKeyRelease);
093: }
094:
095: public static KeyStroke getKeyStroke(final char keyChar) {
096: synchronized (AWTKeyStroke.class) {
097: return (KeyStroke) AWTKeyStroke.getAWTKeyStroke(keyChar);
098: }
099: }
100: }
|