0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017:
0018: package java.awt;
0019:
0020: import java.awt.dnd.DropTarget;
0021: import java.awt.event.ComponentEvent;
0022: import java.awt.event.ComponentListener;
0023: import java.awt.event.FocusEvent;
0024: import java.awt.event.FocusListener;
0025: import java.awt.event.HierarchyBoundsListener;
0026: import java.awt.event.HierarchyEvent;
0027: import java.awt.event.HierarchyListener;
0028: import java.awt.event.InputMethodEvent;
0029: import java.awt.event.InputMethodListener;
0030: import java.awt.event.InvocationEvent;
0031: import java.awt.event.KeyEvent;
0032: import java.awt.event.KeyListener;
0033: import java.awt.event.MouseEvent;
0034: import java.awt.event.MouseListener;
0035: import java.awt.event.MouseMotionListener;
0036: import java.awt.event.MouseWheelEvent;
0037: import java.awt.event.MouseWheelListener;
0038: import java.awt.event.PaintEvent;
0039: import java.awt.event.WindowEvent;
0040: import java.awt.im.InputContext;
0041: import java.awt.im.InputMethodRequests;
0042: import java.awt.image.BufferStrategy;
0043: import java.awt.image.BufferedImage;
0044: import java.awt.image.ColorModel;
0045: import java.awt.image.ImageObserver;
0046: import java.awt.image.ImageProducer;
0047: import java.awt.image.VolatileImage;
0048: import java.awt.image.WritableRaster;
0049: import java.awt.peer.ComponentPeer;
0050: import java.beans.PropertyChangeListener;
0051: import java.beans.PropertyChangeSupport;
0052: import java.io.IOException;
0053: import java.io.ObjectInputStream;
0054: import java.io.PrintStream;
0055: import java.io.PrintWriter;
0056: import java.io.Serializable;
0057: import java.lang.reflect.Array;
0058: import java.lang.reflect.Method;
0059: import java.security.AccessController;
0060: import java.security.PrivilegedAction;
0061: import java.util.ArrayList;
0062: import java.util.Collection;
0063: import java.util.EventListener;
0064: import java.util.HashMap;
0065: import java.util.HashSet;
0066: import java.util.Hashtable;
0067: import java.util.Iterator;
0068: import java.util.LinkedList;
0069: import java.util.Locale;
0070: import java.util.Map;
0071: import java.util.Set;
0072:
0073: import javax.accessibility.Accessible;
0074: import javax.accessibility.AccessibleComponent;
0075: import javax.accessibility.AccessibleContext;
0076: import javax.accessibility.AccessibleRole;
0077: import javax.accessibility.AccessibleState;
0078: import javax.accessibility.AccessibleStateSet;
0079:
0080: import org.apache.harmony.awt.ClipRegion;
0081: import org.apache.harmony.awt.FieldsAccessor;
0082: import org.apache.harmony.awt.gl.MultiRectArea;
0083: import org.apache.harmony.awt.internal.nls.Messages;
0084: import org.apache.harmony.awt.state.State;
0085: import org.apache.harmony.awt.text.TextFieldKit;
0086: import org.apache.harmony.awt.text.TextKit;
0087: import org.apache.harmony.awt.wtk.NativeWindow;
0088:
0089: public abstract class Component implements ImageObserver,
0090: MenuContainer, Serializable {
0091: private static final long serialVersionUID = -7644114512714619750L;
0092:
0093: public static final float TOP_ALIGNMENT = 0.0f;
0094:
0095: public static final float CENTER_ALIGNMENT = 0.5f;
0096:
0097: public static final float BOTTOM_ALIGNMENT = 1.0f;
0098:
0099: public static final float LEFT_ALIGNMENT = 0.0f;
0100:
0101: public static final float RIGHT_ALIGNMENT = 1.0f;
0102:
0103: private static final Hashtable<Class<?>, Boolean> childClassesFlags = new Hashtable<Class<?>, Boolean>();
0104:
0105: private static final ComponentPeer peer = new ComponentPeer() {
0106: };
0107:
0108: private static final boolean incrementalImageUpdate;
0109:
0110: final transient Toolkit toolkit = Toolkit.getDefaultToolkit();
0111:
0112: protected abstract class AccessibleAWTComponent extends
0113: AccessibleContext implements Serializable,
0114: AccessibleComponent {
0115: private static final long serialVersionUID = 642321655757800191L;
0116:
0117: protected class AccessibleAWTComponentHandler implements
0118: ComponentListener {
0119: protected AccessibleAWTComponentHandler() {
0120: }
0121:
0122: public void componentHidden(ComponentEvent e) {
0123: if (behaviour.isLightweight()) {
0124: return;
0125: }
0126: firePropertyChange(
0127: AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0128: AccessibleState.VISIBLE, null);
0129: }
0130:
0131: public void componentMoved(ComponentEvent e) {
0132: }
0133:
0134: public void componentResized(ComponentEvent e) {
0135: }
0136:
0137: public void componentShown(ComponentEvent e) {
0138: if (behaviour.isLightweight()) {
0139: return;
0140: }
0141: firePropertyChange(
0142: AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0143: null, AccessibleState.VISIBLE);
0144: }
0145: }
0146:
0147: protected class AccessibleAWTFocusHandler implements
0148: FocusListener {
0149: public void focusGained(FocusEvent e) {
0150: if (behaviour.isLightweight()) {
0151: return;
0152: }
0153: firePropertyChange(
0154: AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0155: null, AccessibleState.FOCUSED);
0156: }
0157:
0158: public void focusLost(FocusEvent e) {
0159: if (behaviour.isLightweight()) {
0160: return;
0161: }
0162: firePropertyChange(
0163: AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
0164: AccessibleState.FOCUSED, null);
0165: }
0166: }
0167:
0168: protected ComponentListener accessibleAWTComponentHandler;
0169:
0170: protected FocusListener accessibleAWTFocusHandler;
0171:
0172: /**
0173: * Number of registered property change listeners
0174: */
0175: int listenersCount;
0176:
0177: public void addFocusListener(FocusListener l) {
0178: Component.this .addFocusListener(l);
0179: }
0180:
0181: @Override
0182: public void addPropertyChangeListener(
0183: PropertyChangeListener listener) {
0184: toolkit.lockAWT();
0185: try {
0186: super .addPropertyChangeListener(listener);
0187: listenersCount++;
0188: if (accessibleAWTComponentHandler == null) {
0189: accessibleAWTComponentHandler = new AccessibleAWTComponentHandler();
0190: Component.this
0191: .addComponentListener(accessibleAWTComponentHandler);
0192: }
0193: if (accessibleAWTFocusHandler == null) {
0194: accessibleAWTFocusHandler = new AccessibleAWTFocusHandler();
0195: Component.this
0196: .addFocusListener(accessibleAWTFocusHandler);
0197: }
0198: } finally {
0199: toolkit.unlockAWT();
0200: }
0201: }
0202:
0203: public boolean contains(Point p) {
0204: toolkit.lockAWT();
0205: try {
0206: return Component.this .contains(p);
0207: } finally {
0208: toolkit.unlockAWT();
0209: }
0210: }
0211:
0212: public Accessible getAccessibleAt(Point arg0) {
0213: toolkit.lockAWT();
0214: try {
0215: return null;
0216: } finally {
0217: toolkit.unlockAWT();
0218: }
0219: }
0220:
0221: public Color getBackground() {
0222: toolkit.lockAWT();
0223: try {
0224: return Component.this .getBackground();
0225: } finally {
0226: toolkit.unlockAWT();
0227: }
0228: }
0229:
0230: public Rectangle getBounds() {
0231: toolkit.lockAWT();
0232: try {
0233: return Component.this .getBounds();
0234: } finally {
0235: toolkit.unlockAWT();
0236: }
0237: }
0238:
0239: public Cursor getCursor() {
0240: toolkit.lockAWT();
0241: try {
0242: return Component.this .getCursor();
0243: } finally {
0244: toolkit.unlockAWT();
0245: }
0246: }
0247:
0248: public Font getFont() {
0249: toolkit.lockAWT();
0250: try {
0251: return Component.this .getFont();
0252: } finally {
0253: toolkit.unlockAWT();
0254: }
0255: }
0256:
0257: public FontMetrics getFontMetrics(Font f) {
0258: toolkit.lockAWT();
0259: try {
0260: return Component.this .getFontMetrics(f);
0261: } finally {
0262: toolkit.unlockAWT();
0263: }
0264: }
0265:
0266: public Color getForeground() {
0267: toolkit.lockAWT();
0268: try {
0269: return Component.this .getForeground();
0270: } finally {
0271: toolkit.unlockAWT();
0272: }
0273: }
0274:
0275: public Point getLocation() {
0276: toolkit.lockAWT();
0277: try {
0278: return Component.this .getLocation();
0279: } finally {
0280: toolkit.unlockAWT();
0281: }
0282: }
0283:
0284: public Point getLocationOnScreen() {
0285: toolkit.lockAWT();
0286: try {
0287: return Component.this .getLocationOnScreen();
0288: } finally {
0289: toolkit.unlockAWT();
0290: }
0291: }
0292:
0293: public Dimension getSize() {
0294: toolkit.lockAWT();
0295: try {
0296: return Component.this .getSize();
0297: } finally {
0298: toolkit.unlockAWT();
0299: }
0300: }
0301:
0302: public boolean isEnabled() {
0303: toolkit.lockAWT();
0304: try {
0305: return Component.this .isEnabled();
0306: } finally {
0307: toolkit.unlockAWT();
0308: }
0309: }
0310:
0311: public boolean isFocusTraversable() {
0312: toolkit.lockAWT();
0313: try {
0314: return Component.this .isFocusTraversable();
0315: } finally {
0316: toolkit.unlockAWT();
0317: }
0318: }
0319:
0320: public boolean isShowing() {
0321: toolkit.lockAWT();
0322: try {
0323: return Component.this .isShowing();
0324: } finally {
0325: toolkit.unlockAWT();
0326: }
0327: }
0328:
0329: public boolean isVisible() {
0330: toolkit.lockAWT();
0331: try {
0332: return Component.this .isVisible();
0333: } finally {
0334: toolkit.unlockAWT();
0335: }
0336: }
0337:
0338: public void removeFocusListener(FocusListener l) {
0339: Component.this .removeFocusListener(l);
0340: }
0341:
0342: @Override
0343: public void removePropertyChangeListener(
0344: PropertyChangeListener listener) {
0345: toolkit.lockAWT();
0346: try {
0347: super .removePropertyChangeListener(listener);
0348: listenersCount--;
0349: if (listenersCount > 0) {
0350: return;
0351: }
0352: // if there are no more listeners, remove handlers:
0353: Component.this
0354: .removeFocusListener(accessibleAWTFocusHandler);
0355: Component.this
0356: .removeComponentListener(accessibleAWTComponentHandler);
0357: accessibleAWTComponentHandler = null;
0358: accessibleAWTFocusHandler = null;
0359: } finally {
0360: toolkit.unlockAWT();
0361: }
0362: }
0363:
0364: public void requestFocus() {
0365: toolkit.lockAWT();
0366: try {
0367: Component.this .requestFocus();
0368: } finally {
0369: toolkit.unlockAWT();
0370: }
0371: }
0372:
0373: public void setBackground(Color color) {
0374: toolkit.lockAWT();
0375: try {
0376: Component.this .setBackground(color);
0377: } finally {
0378: toolkit.unlockAWT();
0379: }
0380: }
0381:
0382: public void setBounds(Rectangle r) {
0383: toolkit.lockAWT();
0384: try {
0385: Component.this .setBounds(r);
0386: } finally {
0387: toolkit.unlockAWT();
0388: }
0389: }
0390:
0391: public void setCursor(Cursor cursor) {
0392: toolkit.lockAWT();
0393: try {
0394: Component.this .setCursor(cursor);
0395: } finally {
0396: toolkit.unlockAWT();
0397: }
0398: }
0399:
0400: public void setEnabled(boolean enabled) {
0401: toolkit.lockAWT();
0402: try {
0403: Component.this .setEnabled(enabled);
0404: } finally {
0405: toolkit.unlockAWT();
0406: }
0407: }
0408:
0409: public void setFont(Font f) {
0410: toolkit.lockAWT();
0411: try {
0412: Component.this .setFont(f);
0413: } finally {
0414: toolkit.unlockAWT();
0415: }
0416: }
0417:
0418: public void setForeground(Color color) {
0419: toolkit.lockAWT();
0420: try {
0421: Component.this .setForeground(color);
0422: } finally {
0423: toolkit.unlockAWT();
0424: }
0425: }
0426:
0427: public void setLocation(Point p) {
0428: toolkit.lockAWT();
0429: try {
0430: Component.this .setLocation(p);
0431: } finally {
0432: toolkit.unlockAWT();
0433: }
0434: }
0435:
0436: public void setSize(Dimension size) {
0437: toolkit.lockAWT();
0438: try {
0439: Component.this .setSize(size);
0440: } finally {
0441: toolkit.unlockAWT();
0442: }
0443: }
0444:
0445: public void setVisible(boolean visible) {
0446: toolkit.lockAWT();
0447: try {
0448: Component.this .setVisible(visible);
0449: } finally {
0450: toolkit.unlockAWT();
0451: }
0452: }
0453:
0454: @Override
0455: public Accessible getAccessibleParent() {
0456: toolkit.lockAWT();
0457: try {
0458: Accessible aParent = super .getAccessibleParent();
0459: if (aParent != null) {
0460: return aParent;
0461: }
0462: Container parent = getParent();
0463: return (parent instanceof Accessible ? (Accessible) parent
0464: : null);
0465: } finally {
0466: toolkit.unlockAWT();
0467: }
0468: }
0469:
0470: @Override
0471: public Accessible getAccessibleChild(int i) {
0472: toolkit.lockAWT();
0473: try {
0474: return null;
0475: } finally {
0476: toolkit.unlockAWT();
0477: }
0478: }
0479:
0480: @Override
0481: public int getAccessibleChildrenCount() {
0482: toolkit.lockAWT();
0483: try {
0484: return 0;
0485: } finally {
0486: toolkit.unlockAWT();
0487: }
0488: }
0489:
0490: @Override
0491: public AccessibleComponent getAccessibleComponent() {
0492: return this ;
0493: }
0494:
0495: @Override
0496: public String getAccessibleDescription() {
0497: return super .getAccessibleDescription(); // why override?
0498: }
0499:
0500: @Override
0501: public int getAccessibleIndexInParent() {
0502: toolkit.lockAWT();
0503: try {
0504: if (getAccessibleParent() == null) {
0505: return -1;
0506: }
0507: int count = 0;
0508: Container parent = getParent();
0509: for (int i = 0; i < parent.getComponentCount(); i++) {
0510: Component aComp = parent.getComponent(i);
0511: if (aComp instanceof Accessible) {
0512: if (aComp == Component.this ) {
0513: return count;
0514: }
0515: ++count;
0516: }
0517: }
0518: return -1;
0519: } finally {
0520: toolkit.unlockAWT();
0521: }
0522: }
0523:
0524: @Override
0525: public AccessibleRole getAccessibleRole() {
0526: toolkit.lockAWT();
0527: try {
0528: return AccessibleRole.AWT_COMPONENT;
0529: } finally {
0530: toolkit.unlockAWT();
0531: }
0532: }
0533:
0534: @Override
0535: public AccessibleStateSet getAccessibleStateSet() {
0536: toolkit.lockAWT();
0537: try {
0538: AccessibleStateSet set = new AccessibleStateSet();
0539: if (isEnabled()) {
0540: set.add(AccessibleState.ENABLED);
0541: }
0542: if (isFocusable()) {
0543: set.add(AccessibleState.FOCUSABLE);
0544: }
0545: if (hasFocus()) {
0546: set.add(AccessibleState.FOCUSED);
0547: }
0548: if (isOpaque()) {
0549: set.add(AccessibleState.OPAQUE);
0550: }
0551: if (isShowing()) {
0552: set.add(AccessibleState.SHOWING);
0553: }
0554: if (isVisible()) {
0555: set.add(AccessibleState.VISIBLE);
0556: }
0557: return set;
0558: } finally {
0559: toolkit.unlockAWT();
0560: }
0561: }
0562:
0563: @Override
0564: public Locale getLocale() throws IllegalComponentStateException {
0565: toolkit.lockAWT();
0566: try {
0567: return Component.this .getLocale();
0568: } finally {
0569: toolkit.unlockAWT();
0570: }
0571: }
0572: }
0573:
0574: protected class BltBufferStrategy extends BufferStrategy {
0575: protected VolatileImage[] backBuffers;
0576:
0577: protected BufferCapabilities caps;
0578:
0579: protected int width;
0580:
0581: protected int height;
0582:
0583: protected boolean validatedContents;
0584:
0585: protected BltBufferStrategy(int numBuffers,
0586: BufferCapabilities caps)
0587: throws org.apache.harmony.luni.util.NotImplementedException {
0588: if (true) {
0589: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0590: }
0591: }
0592:
0593: @Override
0594: public boolean contentsLost() {
0595: if (true) {
0596: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0597: }
0598: return false;
0599: }
0600:
0601: @Override
0602: public boolean contentsRestored() {
0603: if (true) {
0604: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0605: }
0606: return false;
0607: }
0608:
0609: protected void createBackBuffers(int numBuffers) {
0610: if (true) {
0611: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0612: }
0613: }
0614:
0615: @Override
0616: public BufferCapabilities getCapabilities() {
0617: return (BufferCapabilities) caps.clone();
0618: }
0619:
0620: @Override
0621: public Graphics getDrawGraphics() {
0622: if (true) {
0623: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0624: }
0625: return null;
0626: }
0627:
0628: protected void revalidate() {
0629: if (true) {
0630: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0631: }
0632: }
0633:
0634: @Override
0635: public void show() {
0636: if (true) {
0637: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0638: }
0639: }
0640: }
0641:
0642: protected class FlipBufferStrategy extends BufferStrategy {
0643: protected BufferCapabilities caps;
0644:
0645: protected Image drawBuffer;
0646:
0647: protected VolatileImage drawVBuffer;
0648:
0649: protected int numBuffers;
0650:
0651: protected boolean validatedContents;
0652:
0653: protected FlipBufferStrategy(int numBuffers,
0654: BufferCapabilities caps) throws AWTException {
0655: if (!(Component.this instanceof Window)
0656: && !(Component.this instanceof Canvas)) {
0657: // awt.14B=Only Canvas or Window is allowed
0658: throw new ClassCastException(Messages
0659: .getString("awt.14B")); //$NON-NLS-1$
0660: }
0661: // TODO: throw new AWTException("Capabilities are not supported");
0662: this .numBuffers = numBuffers;
0663: this .caps = (BufferCapabilities) caps.clone();
0664: }
0665:
0666: @Override
0667: public boolean contentsLost() {
0668: if (true) {
0669: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0670: }
0671: return false;
0672: }
0673:
0674: @Override
0675: public boolean contentsRestored() {
0676: if (true) {
0677: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0678: }
0679: return false;
0680: }
0681:
0682: protected void createBuffers(int numBuffers,
0683: BufferCapabilities caps) throws AWTException {
0684: if (numBuffers < 2) {
0685: // awt.14C=Number of buffers must be greater than one
0686: throw new IllegalArgumentException(Messages
0687: .getString("awt.14C")); //$NON-NLS-1$
0688: }
0689: if (!caps.isPageFlipping()) {
0690: // awt.14D=Buffer capabilities should support flipping
0691: throw new IllegalArgumentException(Messages
0692: .getString("awt.14D")); //$NON-NLS-1$
0693: }
0694: if (!Component.this .behaviour.isDisplayable()) {
0695: // awt.14E=Component should be displayable
0696: throw new IllegalStateException(Messages
0697: .getString("awt.14E")); //$NON-NLS-1$
0698: }
0699: // TODO: throw new AWTException("Capabilities are not supported");
0700: if (true) {
0701: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0702: }
0703: }
0704:
0705: protected void destroyBuffers() {
0706: if (true) {
0707: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0708: }
0709: }
0710:
0711: protected void flip(BufferCapabilities.FlipContents flipAction) {
0712: if (true) {
0713: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0714: }
0715: }
0716:
0717: protected Image getBackBuffer() {
0718: if (true) {
0719: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0720: }
0721: return null;
0722: }
0723:
0724: @Override
0725: public BufferCapabilities getCapabilities() {
0726: return (BufferCapabilities) caps.clone();
0727: }
0728:
0729: @Override
0730: public Graphics getDrawGraphics() {
0731: if (true) {
0732: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0733: }
0734: return null;
0735: }
0736:
0737: protected void revalidate() {
0738: if (true) {
0739: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0740: }
0741: }
0742:
0743: @Override
0744: public void show() {
0745: if (true) {
0746: throw new RuntimeException("Method is not implemented"); //$NON-NLS-1$
0747: }
0748: }
0749: }
0750:
0751: /**
0752: * The internal component's state utilized by the visual theme
0753: */
0754: class ComponentState implements State {
0755: private Dimension defaultMinimumSize = new Dimension();
0756:
0757: public boolean isEnabled() {
0758: return enabled;
0759: }
0760:
0761: public boolean isVisible() {
0762: return visible;
0763: }
0764:
0765: public boolean isFocused() {
0766: return isFocusOwner();
0767: }
0768:
0769: public Font getFont() {
0770: return Component.this .getFont();
0771: }
0772:
0773: public boolean isFontSet() {
0774: return font != null;
0775: }
0776:
0777: public Color getBackground() {
0778: Color c = Component.this .getBackground();
0779: return (c != null) ? c : getDefaultBackground();
0780: }
0781:
0782: public boolean isBackgroundSet() {
0783: return backColor != null;
0784: }
0785:
0786: public Color getTextColor() {
0787: Color c = getForeground();
0788: return (c != null) ? c : getDefaultForeground();
0789: }
0790:
0791: public boolean isTextColorSet() {
0792: return foreColor != null;
0793: }
0794:
0795: @SuppressWarnings("deprecation")
0796: public FontMetrics getFontMetrics() {
0797: return toolkit.getFontMetrics(Component.this .getFont());
0798: }
0799:
0800: public Rectangle getBounds() {
0801: return new Rectangle(x, y, w, h);
0802: }
0803:
0804: public Dimension getSize() {
0805: return new Dimension(w, h);
0806: }
0807:
0808: public long getWindowId() {
0809: NativeWindow win = getNativeWindow();
0810: return (win != null) ? win.getId() : 0;
0811: }
0812:
0813: public Dimension getDefaultMinimumSize() {
0814: if (defaultMinimumSize == null) {
0815: calculate();
0816: }
0817: return defaultMinimumSize;
0818: }
0819:
0820: public void setDefaultMinimumSize(Dimension size) {
0821: defaultMinimumSize = size;
0822: }
0823:
0824: public void reset() {
0825: defaultMinimumSize = null;
0826: }
0827:
0828: public void calculate() {
0829: // to be overridden
0830: }
0831: }
0832:
0833: private transient AccessibleContext accessibleContext;
0834:
0835: final transient ComponentBehavior behaviour;
0836:
0837: Container parent;
0838:
0839: private String name;
0840:
0841: private boolean autoName = true;
0842:
0843: private Font font;
0844:
0845: private Color backColor;
0846:
0847: private Color foreColor;
0848:
0849: boolean deprecatedEventHandler = true;
0850:
0851: private long enabledEvents;
0852:
0853: private long enabledAWTEvents;
0854:
0855: private final AWTListenerList<ComponentListener> componentListeners = new AWTListenerList<ComponentListener>(
0856: this );
0857:
0858: private final AWTListenerList<FocusListener> focusListeners = new AWTListenerList<FocusListener>(
0859: this );
0860:
0861: private final AWTListenerList<HierarchyListener> hierarchyListeners = new AWTListenerList<HierarchyListener>(
0862: this );
0863:
0864: private final AWTListenerList<HierarchyBoundsListener> hierarchyBoundsListeners = new AWTListenerList<HierarchyBoundsListener>(
0865: this );
0866:
0867: private final AWTListenerList<KeyListener> keyListeners = new AWTListenerList<KeyListener>(
0868: this );
0869:
0870: private final AWTListenerList<MouseListener> mouseListeners = new AWTListenerList<MouseListener>(
0871: this );
0872:
0873: private final AWTListenerList<MouseMotionListener> mouseMotionListeners = new AWTListenerList<MouseMotionListener>(
0874: this );
0875:
0876: private final AWTListenerList<MouseWheelListener> mouseWheelListeners = new AWTListenerList<MouseWheelListener>(
0877: this );
0878:
0879: private final AWTListenerList<InputMethodListener> inputMethodListeners = new AWTListenerList<InputMethodListener>(
0880: this );
0881:
0882: int x;
0883:
0884: int y;
0885:
0886: int w;
0887:
0888: int h;
0889:
0890: private Dimension maximumSize;
0891:
0892: private Dimension minimumSize;
0893:
0894: private Dimension preferredSize;
0895:
0896: private int boundsMaskParam;
0897:
0898: private boolean ignoreRepaint;
0899:
0900: private boolean enabled = true;
0901:
0902: private boolean inputMethodsEnabled = true;
0903:
0904: transient boolean dispatchToIM = true;
0905:
0906: private boolean focusable = true; // By default, all Components return
0907:
0908: // true from isFocusable() method
0909: boolean visible = true;
0910:
0911: private boolean calledSetFocusable;
0912:
0913: private boolean overridenIsFocusable = true;
0914:
0915: private boolean focusTraversalKeysEnabled = true;
0916:
0917: /**
0918: * Possible keys are: FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS,
0919: * UP_CYCLE_TRAVERSAL_KEYS
0920: */
0921: private final Map<Integer, Set<? extends AWTKeyStroke>> traversalKeys = new HashMap<Integer, Set<? extends AWTKeyStroke>>();
0922:
0923: int[] traversalIDs;
0924:
0925: private Locale locale;
0926:
0927: private ComponentOrientation orientation;
0928:
0929: private PropertyChangeSupport propertyChangeSupport;
0930:
0931: private ArrayList<PopupMenu> popups;
0932:
0933: private boolean coalescer;
0934:
0935: private Hashtable<Integer, LinkedList<AWTEvent>> eventsTable;
0936:
0937: /** Cashed reference used during EventQueue.postEvent() */
0938: private LinkedList<AWTEvent> eventsList;
0939:
0940: private int hierarchyChangingCounter;
0941:
0942: private boolean wasShowing;
0943:
0944: private boolean wasDisplayable;
0945:
0946: Cursor cursor;
0947:
0948: DropTarget dropTarget;
0949:
0950: private boolean mouseExitedExpected;
0951:
0952: transient MultiRectArea repaintRegion;
0953:
0954: transient RedrawManager redrawManager;
0955:
0956: private boolean valid;
0957:
0958: private HashMap<Image, ImageParameters> updatedImages;
0959:
0960: /**
0961: * The lock object for private component's data which don't affect the
0962: * component hierarchy
0963: */
0964: private class ComponentLock {
0965: }
0966:
0967: private final transient Object componentLock = new ComponentLock();
0968: static {
0969: PrivilegedAction<String[]> action = new PrivilegedAction<String[]>() {
0970: public String[] run() {
0971: String properties[] = new String[2];
0972: properties[0] = System.getProperty(
0973: "awt.image.redrawrate", "100"); //$NON-NLS-1$ //$NON-NLS-2$
0974: properties[1] = System.getProperty(
0975: "awt.image.incrementaldraw", "true"); //$NON-NLS-1$ //$NON-NLS-2$
0976: return properties;
0977: }
0978: };
0979: String properties[] = AccessController.doPrivileged(action);
0980: // FIXME: rate is never used, can this code and the get property above
0981: // be removed?
0982: // int rate;
0983: //
0984: // try {
0985: // rate = Integer.decode(properties[0]).intValue();
0986: // } catch (NumberFormatException e) {
0987: // rate = 100;
0988: // }
0989: incrementalImageUpdate = properties[1].equals("true"); //$NON-NLS-1$
0990: }
0991:
0992: protected Component() {
0993: toolkit.lockAWT();
0994: try {
0995: orientation = ComponentOrientation.UNKNOWN;
0996: redrawManager = null;
0997: traversalIDs = this instanceof Container ? KeyboardFocusManager.contTraversalIDs
0998: : KeyboardFocusManager.compTraversalIDs;
0999: for (int element : traversalIDs) {
1000: traversalKeys.put(new Integer(element), null);
1001: }
1002: behaviour = createBehavior();
1003: deriveCoalescerFlag();
1004: } finally {
1005: toolkit.unlockAWT();
1006: }
1007: }
1008:
1009: /**
1010: * Determine that the class inherited from Component declares the method
1011: * coalesceEvents(), and put the results to the childClassesFlags map
1012: *
1013: */
1014: private void deriveCoalescerFlag() {
1015: Class<?> this Class = getClass();
1016: boolean flag = true;
1017: synchronized (childClassesFlags) {
1018: Boolean flagWrapper = childClassesFlags.get(this Class);
1019: if (flagWrapper == null) {
1020: Method coalesceMethod = null;
1021: for (Class<?> c = this Class; c != Component.class; c = c
1022: .getSuperclass()) {
1023: try {
1024: coalesceMethod = c
1025: .getDeclaredMethod(
1026: "coalesceEvents", new Class[] { //$NON-NLS-1$
1027: Class
1028: .forName("java.awt.AWTEvent"), //$NON-NLS-1$
1029: Class
1030: .forName("java.awt.AWTEvent") }); //$NON-NLS-1$
1031: } catch (Exception e) {
1032: }
1033: if (coalesceMethod != null) {
1034: break;
1035: }
1036: }
1037: flag = (coalesceMethod != null);
1038: childClassesFlags.put(this Class, Boolean.valueOf(flag));
1039: } else {
1040: flag = flagWrapper.booleanValue();
1041: }
1042: }
1043: coalescer = flag;
1044: if (flag) {
1045: eventsTable = new Hashtable<Integer, LinkedList<AWTEvent>>();
1046: } else {
1047: eventsTable = null;
1048: }
1049: }
1050:
1051: public void setName(String name) {
1052: String oldName;
1053: toolkit.lockAWT();
1054: try {
1055: autoName = false;
1056: oldName = this .name;
1057: this .name = name;
1058: } finally {
1059: toolkit.unlockAWT();
1060: }
1061: firePropertyChange("name", oldName, name); //$NON-NLS-1$
1062: }
1063:
1064: public String getName() {
1065: toolkit.lockAWT();
1066: try {
1067: if ((name == null) && autoName) {
1068: name = autoName();
1069: }
1070: return name;
1071: } finally {
1072: toolkit.unlockAWT();
1073: }
1074: }
1075:
1076: String autoName() {
1077: String name = getClass().getName();
1078: if (name.indexOf("$") != -1) { //$NON-NLS-1$
1079: return null;
1080: }
1081: int number = toolkit.autoNumber.nextComponent++;
1082: name = name.substring(name.lastIndexOf(".") + 1) + Integer.toString(number); //$NON-NLS-1$
1083: return name;
1084: }
1085:
1086: @Override
1087: public String toString() {
1088: /*
1089: * The format is based on 1.5 release behavior which can be revealed by
1090: * the following code:
1091: *
1092: * Component c = new Component(){}; c.setVisible(false);
1093: * System.out.println(c);
1094: */
1095: toolkit.lockAWT();
1096: try {
1097: return getClass().getName() + "[" + paramString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
1098: } finally {
1099: toolkit.unlockAWT();
1100: }
1101: }
1102:
1103: public void add(PopupMenu popup) {
1104: toolkit.lockAWT();
1105: try {
1106: if (popup.getParent() == this ) {
1107: return;
1108: }
1109: if (popups == null) {
1110: popups = new ArrayList<PopupMenu>();
1111: }
1112: popup.setParent(this );
1113: popups.add(popup);
1114: } finally {
1115: toolkit.unlockAWT();
1116: }
1117: }
1118:
1119: public boolean contains(Point p) {
1120: toolkit.lockAWT();
1121: try {
1122: return contains(p.x, p.y);
1123: } finally {
1124: toolkit.unlockAWT();
1125: }
1126: }
1127:
1128: public boolean contains(int x, int y) {
1129: toolkit.lockAWT();
1130: try {
1131: return inside(x, y);
1132: } finally {
1133: toolkit.unlockAWT();
1134: }
1135: }
1136:
1137: @Deprecated
1138: public Dimension size() {
1139: toolkit.lockAWT();
1140: try {
1141: return new Dimension(w, h);
1142: } finally {
1143: toolkit.unlockAWT();
1144: }
1145: }
1146:
1147: public Container getParent() {
1148: toolkit.lockAWT();
1149: try {
1150: return parent;
1151: } finally {
1152: toolkit.unlockAWT();
1153: }
1154: }
1155:
1156: /**
1157: * @return the nearest heavyweight ancestor in hierarchy or
1158: * <code>null</code> if not found
1159: */
1160: Component getHWAncestor() {
1161: return (parent != null ? parent.getHWSurface() : null);
1162: }
1163:
1164: /**
1165: * @return heavyweight component that is equal to or is a nearest
1166: * heavyweight container of the current component, or
1167: * <code>null</code> if not found
1168: */
1169: Component getHWSurface() {
1170: Component parent;
1171: for (parent = this ; (parent != null)
1172: && (parent.isLightweight()); parent = parent
1173: .getParent()) {
1174: ;
1175: }
1176: return parent;
1177: }
1178:
1179: Window getWindowAncestor() {
1180: Component par;
1181: for (par = this ; par != null && !(par instanceof Window); par = par
1182: .getParent()) {
1183: ;
1184: }
1185: return (Window) par;
1186: }
1187:
1188: /** To be called by container */
1189: void setParent(Container parent) {
1190: this .parent = parent;
1191: setRedrawManager();
1192: }
1193:
1194: void setRedrawManager() {
1195: redrawManager = getRedrawManager();
1196: }
1197:
1198: public void remove(MenuComponent menu) {
1199: toolkit.lockAWT();
1200: try {
1201: if (menu.getParent() == this ) {
1202: menu.setParent(null);
1203: popups.remove(menu);
1204: }
1205: } finally {
1206: toolkit.unlockAWT();
1207: }
1208: }
1209:
1210: public void list(PrintStream out, int indent) {
1211: toolkit.lockAWT();
1212: try {
1213: out.println(getIndentStr(indent) + this );
1214: } finally {
1215: toolkit.unlockAWT();
1216: }
1217: }
1218:
1219: public void list(PrintWriter out) {
1220: toolkit.lockAWT();
1221: try {
1222: list(out, 1);
1223: } finally {
1224: toolkit.unlockAWT();
1225: }
1226: }
1227:
1228: public void list(PrintWriter out, int indent) {
1229: toolkit.lockAWT();
1230: try {
1231: out.println(getIndentStr(indent) + this );
1232: } finally {
1233: toolkit.unlockAWT();
1234: }
1235: }
1236:
1237: String getIndentStr(int indent) {
1238: char[] ind = new char[indent];
1239: for (int i = 0; i < indent; ind[i++] = ' ') {
1240: ;
1241: }
1242: return new String(ind);
1243: }
1244:
1245: public void list(PrintStream out) {
1246: toolkit.lockAWT();
1247: try {
1248: // default indent = 1
1249: list(out, 1);
1250: } finally {
1251: toolkit.unlockAWT();
1252: }
1253: }
1254:
1255: public void list() {
1256: toolkit.lockAWT();
1257: try {
1258: list(System.out);
1259: } finally {
1260: toolkit.unlockAWT();
1261: }
1262: }
1263:
1264: public void print(Graphics g) {
1265: toolkit.lockAWT();
1266: try {
1267: paint(g);
1268: } finally {
1269: toolkit.unlockAWT();
1270: }
1271: }
1272:
1273: public void printAll(Graphics g) {
1274: toolkit.lockAWT();
1275: try {
1276: paintAll(g);
1277: } finally {
1278: toolkit.unlockAWT();
1279: }
1280: }
1281:
1282: public void setSize(int width, int height) {
1283: toolkit.lockAWT();
1284: try {
1285: resize(width, height);
1286: } finally {
1287: toolkit.unlockAWT();
1288: }
1289: }
1290:
1291: public void setSize(Dimension d) {
1292: toolkit.lockAWT();
1293: try {
1294: resize(d);
1295: } finally {
1296: toolkit.unlockAWT();
1297: }
1298: }
1299:
1300: @Deprecated
1301: public void resize(int width, int height) {
1302: toolkit.lockAWT();
1303: try {
1304: boundsMaskParam = NativeWindow.BOUNDS_NOMOVE;
1305: setBounds(x, y, width, height);
1306: } finally {
1307: toolkit.unlockAWT();
1308: }
1309: }
1310:
1311: @Deprecated
1312: public void resize(Dimension size) {
1313: toolkit.lockAWT();
1314: try {
1315: setSize(size.width, size.height);
1316: } finally {
1317: toolkit.unlockAWT();
1318: }
1319: }
1320:
1321: public boolean isOpaque() {
1322: toolkit.lockAWT();
1323: try {
1324: return behaviour.isOpaque();
1325: } finally {
1326: toolkit.unlockAWT();
1327: }
1328: }
1329:
1330: @Deprecated
1331: public void disable() {
1332: toolkit.lockAWT();
1333: try {
1334: setEnabledImpl(false);
1335: } finally {
1336: toolkit.unlockAWT();
1337: }
1338: fireAccessibleStateChange(AccessibleState.ENABLED, false);
1339: }
1340:
1341: @Deprecated
1342: public void enable() {
1343: toolkit.lockAWT();
1344: try {
1345: setEnabledImpl(true);
1346: } finally {
1347: toolkit.unlockAWT();
1348: }
1349: fireAccessibleStateChange(AccessibleState.ENABLED, true);
1350: }
1351:
1352: @Deprecated
1353: public void enable(boolean b) {
1354: toolkit.lockAWT();
1355: try {
1356: if (b) {
1357: enable();
1358: } else {
1359: disable();
1360: }
1361: } finally {
1362: toolkit.unlockAWT();
1363: }
1364: }
1365:
1366: public Point getLocation(Point rv) {
1367: toolkit.lockAWT();
1368: try {
1369: if (rv == null) {
1370: rv = new Point();
1371: }
1372: rv.setLocation(getX(), getY());
1373: return rv;
1374: } finally {
1375: toolkit.unlockAWT();
1376: }
1377: }
1378:
1379: public Point getLocation() {
1380: toolkit.lockAWT();
1381: try {
1382: return location();
1383: } finally {
1384: toolkit.unlockAWT();
1385: }
1386: }
1387:
1388: public Dimension getSize() {
1389: toolkit.lockAWT();
1390: try {
1391: return size();
1392: } finally {
1393: toolkit.unlockAWT();
1394: }
1395: }
1396:
1397: public Dimension getSize(Dimension rv) {
1398: toolkit.lockAWT();
1399: try {
1400: if (rv == null) {
1401: rv = new Dimension();
1402: }
1403: rv.setSize(getWidth(), getHeight());
1404: return rv;
1405: } finally {
1406: toolkit.unlockAWT();
1407: }
1408: }
1409:
1410: public boolean isValid() {
1411: toolkit.lockAWT();
1412: try {
1413: return valid && behaviour.isDisplayable();
1414: } finally {
1415: toolkit.unlockAWT();
1416: }
1417: }
1418:
1419: @Deprecated
1420: public Point location() {
1421: toolkit.lockAWT();
1422: try {
1423: return new Point(x, y);
1424: } finally {
1425: toolkit.unlockAWT();
1426: }
1427: }
1428:
1429: public void addNotify() {
1430: toolkit.lockAWT();
1431: try {
1432: prepare4HierarchyChange();
1433: behaviour.addNotify();
1434: finishHierarchyChange(this , parent, 0);
1435: if (dropTarget != null) {
1436: dropTarget.addNotify(peer);
1437: }
1438: } finally {
1439: toolkit.unlockAWT();
1440: }
1441: }
1442:
1443: void mapToDisplay(boolean b) {
1444: if (b && !isDisplayable()) {
1445: if ((this instanceof Window)
1446: || ((parent != null) && parent.isDisplayable())) {
1447: addNotify();
1448: }
1449: } else if (!b && isDisplayable()) {
1450: removeNotify();
1451: }
1452: }
1453:
1454: /**
1455: * @return accessible context specific for particular component
1456: */
1457: AccessibleContext createAccessibleContext() {
1458: return null;
1459: }
1460:
1461: public AccessibleContext getAccessibleContext() {
1462: toolkit.lockAWT();
1463: try {
1464: if (accessibleContext == null) {
1465: accessibleContext = createAccessibleContext();
1466: }
1467: return accessibleContext;
1468: } finally {
1469: toolkit.unlockAWT();
1470: }
1471: }
1472:
1473: public Toolkit getToolkit() {
1474: return toolkit;
1475: }
1476:
1477: public final Object getTreeLock() {
1478: return toolkit.awtTreeLock;
1479: }
1480:
1481: @Deprecated
1482: public boolean action(Event evt, Object what) {
1483: // to be overridden: do nothing,
1484: // just return false to propagate event up to the parent container
1485: return false;
1486: }
1487:
1488: private PropertyChangeSupport getPropertyChangeSupport() {
1489: synchronized (componentLock) {
1490: if (propertyChangeSupport == null) {
1491: propertyChangeSupport = new PropertyChangeSupport(this );
1492: }
1493: return propertyChangeSupport;
1494: }
1495: }
1496:
1497: public void addPropertyChangeListener(
1498: PropertyChangeListener listener) {
1499: getPropertyChangeSupport().addPropertyChangeListener(listener);
1500: }
1501:
1502: public void addPropertyChangeListener(String propertyName,
1503: PropertyChangeListener listener) {
1504: getPropertyChangeSupport().addPropertyChangeListener(
1505: propertyName, listener);
1506: }
1507:
1508: public void applyComponentOrientation(
1509: ComponentOrientation orientation) {
1510: toolkit.lockAWT();
1511: try {
1512: setComponentOrientation(orientation);
1513: } finally {
1514: toolkit.unlockAWT();
1515: }
1516: }
1517:
1518: public boolean areFocusTraversalKeysSet(int id) {
1519: toolkit.lockAWT();
1520: try {
1521: Integer Id = new Integer(id);
1522: if (traversalKeys.containsKey(Id)) {
1523: return traversalKeys.get(Id) != null;
1524: }
1525: // awt.14F=invalid focus traversal key identifier
1526: throw new IllegalArgumentException(Messages
1527: .getString("awt.14F")); //$NON-NLS-1$
1528: } finally {
1529: toolkit.unlockAWT();
1530: }
1531: }
1532:
1533: @Deprecated
1534: public Rectangle bounds() {
1535: toolkit.lockAWT();
1536: try {
1537: return new Rectangle(x, y, w, h);
1538: } finally {
1539: toolkit.unlockAWT();
1540: }
1541: }
1542:
1543: public int checkImage(Image image, int width, int height,
1544: ImageObserver observer) {
1545: toolkit.lockAWT();
1546: try {
1547: return toolkit.checkImage(image, width, height, observer);
1548: } finally {
1549: toolkit.unlockAWT();
1550: }
1551: }
1552:
1553: public int checkImage(Image image, ImageObserver observer) {
1554: toolkit.lockAWT();
1555: try {
1556: return toolkit.checkImage(image, -1, -1, observer);
1557: } finally {
1558: toolkit.unlockAWT();
1559: }
1560: }
1561:
1562: protected AWTEvent coalesceEvents(AWTEvent existingEvent,
1563: AWTEvent newEvent) {
1564: toolkit.lockAWT();
1565: try {
1566: // Nothing to do:
1567: // 1. Mouse events coalesced at WTK level
1568: // 2. Paint events handled by RedrawManager
1569: // This method is for overriding only
1570: return null;
1571: } finally {
1572: toolkit.unlockAWT();
1573: }
1574: }
1575:
1576: boolean isCoalescer() {
1577: return coalescer;
1578: }
1579:
1580: AWTEvent getRelativeEvent(int id) {
1581: Integer idWrapper = new Integer(id);
1582: eventsList = eventsTable.get(idWrapper);
1583: if (eventsList == null) {
1584: eventsList = new LinkedList<AWTEvent>();
1585: eventsTable.put(idWrapper, eventsList);
1586: return null;
1587: }
1588: if (eventsList.isEmpty()) {
1589: return null;
1590: }
1591: return eventsList.getLast();
1592: }
1593:
1594: void addNewEvent(AWTEvent event) {
1595: eventsList.addLast(event);
1596: }
1597:
1598: void removeRelativeEvent() {
1599: eventsList.removeLast();
1600: }
1601:
1602: void removeNextEvent(int id) {
1603: eventsTable.get(new Integer(id)).removeFirst();
1604: }
1605:
1606: public Image createImage(ImageProducer producer) {
1607: toolkit.lockAWT();
1608: try {
1609: return toolkit.createImage(producer);
1610: } finally {
1611: toolkit.unlockAWT();
1612: }
1613: }
1614:
1615: public Image createImage(int width, int height) {
1616: toolkit.lockAWT();
1617: try {
1618: if (!isDisplayable()) {
1619: return null;
1620: }
1621: GraphicsConfiguration gc = getGraphicsConfiguration();
1622: if (gc == null) {
1623: return null;
1624: }
1625: ColorModel cm = gc.getColorModel(Transparency.OPAQUE);
1626: WritableRaster wr = cm.createCompatibleWritableRaster(
1627: width, height);
1628: Image image = new BufferedImage(cm, wr, cm
1629: .isAlphaPremultiplied(), null);
1630: fillImageBackground(image, width, height);
1631: return image;
1632: } finally {
1633: toolkit.unlockAWT();
1634: }
1635: }
1636:
1637: public VolatileImage createVolatileImage(int width, int height,
1638: ImageCapabilities caps) throws AWTException {
1639: toolkit.lockAWT();
1640: try {
1641: if (!isDisplayable()) {
1642: return null;
1643: }
1644: GraphicsConfiguration gc = getGraphicsConfiguration();
1645: if (gc == null) {
1646: return null;
1647: }
1648: VolatileImage image = gc.createCompatibleVolatileImage(
1649: width, height, caps);
1650: fillImageBackground(image, width, height);
1651: return image;
1652: } finally {
1653: toolkit.unlockAWT();
1654: }
1655: }
1656:
1657: public VolatileImage createVolatileImage(int width, int height) {
1658: toolkit.lockAWT();
1659: try {
1660: if (!isDisplayable()) {
1661: return null;
1662: }
1663: GraphicsConfiguration gc = getGraphicsConfiguration();
1664: if (gc == null) {
1665: return null;
1666: }
1667: VolatileImage image = gc.createCompatibleVolatileImage(
1668: width, height);
1669: fillImageBackground(image, width, height);
1670: return image;
1671: } finally {
1672: toolkit.unlockAWT();
1673: }
1674: }
1675:
1676: /**
1677: * Fill the image being created by createImage() or createVolatileImage()
1678: * with the component's background color to prepare it for double-buffered
1679: * painting
1680: */
1681: private void fillImageBackground(Image image, int width, int height) {
1682: Graphics gr = image.getGraphics();
1683: gr.setColor(getBackground());
1684: gr.fillRect(0, 0, width, height);
1685: gr.dispose();
1686: }
1687:
1688: @Deprecated
1689: public void deliverEvent(Event evt) {
1690: postEvent(evt);
1691: }
1692:
1693: public void doLayout() {
1694: toolkit.lockAWT();
1695: try {
1696: layout();
1697: } finally {
1698: toolkit.unlockAWT();
1699: }
1700: // Implemented in Container
1701: }
1702:
1703: private void firePropertyChangeImpl(String propertyName,
1704: Object oldValue, Object newValue) {
1705: PropertyChangeSupport pcs;
1706: synchronized (componentLock) {
1707: if (propertyChangeSupport == null) {
1708: return;
1709: }
1710: pcs = propertyChangeSupport;
1711: }
1712: pcs.firePropertyChange(propertyName, oldValue, newValue);
1713: }
1714:
1715: protected void firePropertyChange(String propertyName,
1716: int oldValue, int newValue) {
1717: firePropertyChangeImpl(propertyName, new Integer(oldValue),
1718: new Integer(newValue));
1719: }
1720:
1721: protected void firePropertyChange(String propertyName,
1722: boolean oldValue, boolean newValue) {
1723: firePropertyChangeImpl(propertyName, Boolean.valueOf(oldValue),
1724: Boolean.valueOf(newValue));
1725: }
1726:
1727: protected void firePropertyChange(final String propertyName,
1728: final Object oldValue, final Object newValue) {
1729: firePropertyChangeImpl(propertyName, oldValue, newValue);
1730: }
1731:
1732: public void firePropertyChange(String propertyName, byte oldValue,
1733: byte newValue) {
1734: firePropertyChangeImpl(propertyName, new Byte(oldValue),
1735: new Byte(newValue));
1736: }
1737:
1738: public void firePropertyChange(String propertyName, char oldValue,
1739: char newValue) {
1740: firePropertyChangeImpl(propertyName, new Character(oldValue),
1741: new Character(newValue));
1742: }
1743:
1744: public void firePropertyChange(String propertyName, short oldValue,
1745: short newValue) {
1746: firePropertyChangeImpl(propertyName, new Short(oldValue),
1747: new Short(newValue));
1748: }
1749:
1750: public void firePropertyChange(String propertyName, long oldValue,
1751: long newValue) {
1752: firePropertyChangeImpl(propertyName, new Long(oldValue),
1753: new Long(newValue));
1754: }
1755:
1756: public void firePropertyChange(String propertyName, float oldValue,
1757: float newValue) {
1758: firePropertyChangeImpl(propertyName, new Float(oldValue),
1759: new Float(newValue));
1760: }
1761:
1762: public void firePropertyChange(String propertyName,
1763: double oldValue, double newValue) {
1764: firePropertyChangeImpl(propertyName, new Double(oldValue),
1765: new Double(newValue));
1766: }
1767:
1768: public float getAlignmentX() {
1769: toolkit.lockAWT();
1770: try {
1771: return CENTER_ALIGNMENT;
1772: } finally {
1773: toolkit.unlockAWT();
1774: }
1775: }
1776:
1777: public float getAlignmentY() {
1778: toolkit.lockAWT();
1779: try {
1780: return CENTER_ALIGNMENT;
1781: } finally {
1782: toolkit.unlockAWT();
1783: }
1784: }
1785:
1786: public Color getBackground() {
1787: toolkit.lockAWT();
1788: try {
1789: if ((backColor == null) && (parent != null)) {
1790: return parent.getBackground();
1791: }
1792: return backColor;
1793: } finally {
1794: toolkit.unlockAWT();
1795: }
1796: }
1797:
1798: public Rectangle getBounds() {
1799: toolkit.lockAWT();
1800: try {
1801: return bounds();
1802: } finally {
1803: toolkit.unlockAWT();
1804: }
1805: }
1806:
1807: public Rectangle getBounds(Rectangle rv) {
1808: toolkit.lockAWT();
1809: try {
1810: if (rv == null) {
1811: rv = new Rectangle();
1812: }
1813: rv.setBounds(x, y, w, h);
1814: return rv;
1815: } finally {
1816: toolkit.unlockAWT();
1817: }
1818: }
1819:
1820: public ColorModel getColorModel() {
1821: toolkit.lockAWT();
1822: try {
1823: return getToolkit().getColorModel();
1824: } finally {
1825: toolkit.unlockAWT();
1826: }
1827: }
1828:
1829: public Component getComponentAt(Point p) {
1830: toolkit.lockAWT();
1831: try {
1832: return getComponentAt(p.x, p.y);
1833: } finally {
1834: toolkit.unlockAWT();
1835: }
1836: }
1837:
1838: public Component getComponentAt(int x, int y) {
1839: toolkit.lockAWT();
1840: try {
1841: return locate(x, y);
1842: } finally {
1843: toolkit.unlockAWT();
1844: }
1845: }
1846:
1847: public ComponentOrientation getComponentOrientation() {
1848: toolkit.lockAWT();
1849: try {
1850: return orientation;
1851: } finally {
1852: toolkit.unlockAWT();
1853: }
1854: }
1855:
1856: public Cursor getCursor() {
1857: toolkit.lockAWT();
1858: try {
1859: if (cursor != null) {
1860: return cursor;
1861: } else if (parent != null) {
1862: return parent.getCursor();
1863: }
1864: return Cursor.getDefaultCursor();
1865: } finally {
1866: toolkit.unlockAWT();
1867: }
1868: }
1869:
1870: public DropTarget getDropTarget() {
1871: toolkit.lockAWT();
1872: try {
1873: return dropTarget;
1874: } finally {
1875: toolkit.unlockAWT();
1876: }
1877: }
1878:
1879: public Container getFocusCycleRootAncestor() {
1880: toolkit.lockAWT();
1881: try {
1882: for (Container c = parent; c != null; c = c.getParent()) {
1883: if (c.isFocusCycleRoot()) {
1884: return c;
1885: }
1886: }
1887: return null;
1888: } finally {
1889: toolkit.unlockAWT();
1890: }
1891: }
1892:
1893: @SuppressWarnings("unchecked")
1894: public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
1895: toolkit.lockAWT();
1896: try {
1897: Integer kId = new Integer(id);
1898: KeyboardFocusManager.checkTraversalKeysID(traversalKeys,
1899: kId);
1900: Set<? extends AWTKeyStroke> keys = traversalKeys.get(kId);
1901: if (keys == null && parent != null) {
1902: keys = parent.getFocusTraversalKeys(id);
1903: }
1904: if (keys == null) {
1905: keys = KeyboardFocusManager
1906: .getCurrentKeyboardFocusManager()
1907: .getDefaultFocusTraversalKeys(id);
1908: }
1909: return (Set<AWTKeyStroke>) keys;
1910: } finally {
1911: toolkit.unlockAWT();
1912: }
1913: }
1914:
1915: public boolean getFocusTraversalKeysEnabled() {
1916: toolkit.lockAWT();
1917: try {
1918: return focusTraversalKeysEnabled;
1919: } finally {
1920: toolkit.unlockAWT();
1921: }
1922: }
1923:
1924: @SuppressWarnings("deprecation")
1925: public FontMetrics getFontMetrics(Font f) {
1926: return toolkit.getFontMetrics(f);
1927: }
1928:
1929: public Color getForeground() {
1930: toolkit.lockAWT();
1931: try {
1932: if (foreColor == null && parent != null) {
1933: return parent.getForeground();
1934: }
1935: return foreColor;
1936: } finally {
1937: toolkit.unlockAWT();
1938: }
1939: }
1940:
1941: public Graphics getGraphics() {
1942: toolkit.lockAWT();
1943: try {
1944: if (!isDisplayable()) {
1945: return null;
1946: }
1947: Graphics g = behaviour.getGraphics(0, 0, w, h);
1948: if (g instanceof Graphics2D) {
1949: ((Graphics2D) g).setBackground(this .getBackground());
1950: }
1951: g.setColor(foreColor);
1952: g.setFont(getFont());
1953: return g;
1954: } finally {
1955: toolkit.unlockAWT();
1956: }
1957: }
1958:
1959: public GraphicsConfiguration getGraphicsConfiguration() {
1960: toolkit.lockAWT();
1961: try {
1962: Window win = getWindowAncestor();
1963: if (win == null) {
1964: return null;
1965: }
1966: return win.getGraphicsConfiguration();
1967: } finally {
1968: toolkit.unlockAWT();
1969: }
1970: }
1971:
1972: public int getHeight() {
1973: toolkit.lockAWT();
1974: try {
1975: return h;
1976: } finally {
1977: toolkit.unlockAWT();
1978: }
1979: }
1980:
1981: public boolean getIgnoreRepaint() {
1982: toolkit.lockAWT();
1983: try {
1984: return ignoreRepaint;
1985: } finally {
1986: toolkit.unlockAWT();
1987: }
1988: }
1989:
1990: public InputContext getInputContext() {
1991: toolkit.lockAWT();
1992: try {
1993: Container parent = getParent();
1994: if (parent != null) {
1995: return parent.getInputContext();
1996: }
1997: return null;
1998: } finally {
1999: toolkit.unlockAWT();
2000: }
2001: }
2002:
2003: public InputMethodRequests getInputMethodRequests() {
2004: return null;
2005: }
2006:
2007: public Locale getLocale() {
2008: toolkit.lockAWT();
2009: try {
2010: if (locale == null) {
2011: if (parent == null) {
2012: if (this instanceof Window) {
2013: return Locale.getDefault();
2014: }
2015: // awt.150=no parent
2016: throw new IllegalComponentStateException(Messages
2017: .getString("awt.150")); //$NON-NLS-1$
2018: }
2019: return getParent().getLocale();
2020: }
2021: return locale;
2022: } finally {
2023: toolkit.unlockAWT();
2024: }
2025: }
2026:
2027: public Point getLocationOnScreen()
2028: throws IllegalComponentStateException {
2029: toolkit.lockAWT();
2030: try {
2031: Point p = new Point();
2032: if (isShowing()) {
2033: Component comp;
2034: for (comp = this ; comp != null
2035: && !(comp instanceof Window); comp = comp
2036: .getParent()) {
2037: p.translate(comp.getX(), comp.getY());
2038: }
2039: if (comp instanceof Window) {
2040: p.translate(comp.getX(), comp.getY());
2041: }
2042: return p;
2043: }
2044: // awt.151=component must be showing on the screen to determine its location
2045: throw new IllegalComponentStateException(Messages
2046: .getString("awt.151")); //$NON-NLS-1$
2047: } finally {
2048: toolkit.unlockAWT();
2049: }
2050: }
2051:
2052: @Deprecated
2053: public ComponentPeer getPeer() {
2054: toolkit.lockAWT();
2055: try {
2056: if (behaviour.isDisplayable()) {
2057: return peer;
2058: }
2059: return null;
2060: } finally {
2061: toolkit.unlockAWT();
2062: }
2063: }
2064:
2065: public PropertyChangeListener[] getPropertyChangeListeners() {
2066: return getPropertyChangeSupport().getPropertyChangeListeners();
2067: }
2068:
2069: public PropertyChangeListener[] getPropertyChangeListeners(
2070: String propertyName) {
2071: return getPropertyChangeSupport().getPropertyChangeListeners(
2072: propertyName);
2073: }
2074:
2075: public int getWidth() {
2076: toolkit.lockAWT();
2077: try {
2078: return w;
2079: } finally {
2080: toolkit.unlockAWT();
2081: }
2082: }
2083:
2084: public int getX() {
2085: toolkit.lockAWT();
2086: try {
2087: return x;
2088: } finally {
2089: toolkit.unlockAWT();
2090: }
2091: }
2092:
2093: public int getY() {
2094: toolkit.lockAWT();
2095: try {
2096: return y;
2097: } finally {
2098: toolkit.unlockAWT();
2099: }
2100: }
2101:
2102: @Deprecated
2103: public boolean gotFocus(Event evt, Object what) {
2104: // to be overridden: do nothing,
2105: // just return false to propagate event up to the parent container
2106: return false;
2107: }
2108:
2109: @Deprecated
2110: public boolean handleEvent(Event evt) {
2111: switch (evt.id) {
2112: case Event.ACTION_EVENT:
2113: return action(evt, evt.arg);
2114: case Event.GOT_FOCUS:
2115: return gotFocus(evt, null);
2116: case Event.LOST_FOCUS:
2117: return lostFocus(evt, null);
2118: case Event.MOUSE_DOWN:
2119: return mouseDown(evt, evt.x, evt.y);
2120: case Event.MOUSE_DRAG:
2121: return mouseDrag(evt, evt.x, evt.y);
2122: case Event.MOUSE_ENTER:
2123: return mouseEnter(evt, evt.x, evt.y);
2124: case Event.MOUSE_EXIT:
2125: return mouseExit(evt, evt.x, evt.y);
2126: case Event.MOUSE_MOVE:
2127: return mouseMove(evt, evt.x, evt.y);
2128: case Event.MOUSE_UP:
2129: return mouseUp(evt, evt.x, evt.y);
2130: case Event.KEY_ACTION:
2131: case Event.KEY_PRESS:
2132: return keyDown(evt, evt.key);
2133: case Event.KEY_ACTION_RELEASE:
2134: case Event.KEY_RELEASE:
2135: return keyUp(evt, evt.key);
2136: }
2137: return false;// event not handled
2138: }
2139:
2140: public boolean hasFocus() {
2141: toolkit.lockAWT();
2142: try {
2143: return isFocusOwner();
2144: } finally {
2145: toolkit.unlockAWT();
2146: }
2147: }
2148:
2149: @Deprecated
2150: public void hide() {
2151: toolkit.lockAWT();
2152: try {
2153: if (!visible) {
2154: return;
2155: }
2156: prepare4HierarchyChange();
2157: visible = false;
2158: moveFocusOnHide();
2159: behaviour.setVisible(false);
2160: postEvent(new ComponentEvent(this ,
2161: ComponentEvent.COMPONENT_HIDDEN));
2162: finishHierarchyChange(this , parent, 0);
2163: notifyInputMethod(null);
2164: invalidateRealParent();
2165: } finally {
2166: toolkit.unlockAWT();
2167: }
2168: }
2169:
2170: @Deprecated
2171: public boolean inside(int x, int y) {
2172: toolkit.lockAWT();
2173: try {
2174: return x >= 0 && x < getWidth() && y >= 0
2175: && y < getHeight();
2176: } finally {
2177: toolkit.unlockAWT();
2178: }
2179: }
2180:
2181: public void invalidate() {
2182: toolkit.lockAWT();
2183: try {
2184: valid = false;
2185: resetDefaultSize();
2186: invalidateRealParent();
2187: } finally {
2188: toolkit.unlockAWT();
2189: }
2190: }
2191:
2192: public boolean isBackgroundSet() {
2193: toolkit.lockAWT();
2194: try {
2195: return backColor != null;
2196: } finally {
2197: toolkit.unlockAWT();
2198: }
2199: }
2200:
2201: public boolean isCursorSet() {
2202: toolkit.lockAWT();
2203: try {
2204: return cursor != null;
2205: } finally {
2206: toolkit.unlockAWT();
2207: }
2208: }
2209:
2210: public boolean isDisplayable() {
2211: toolkit.lockAWT();
2212: try {
2213: return behaviour.isDisplayable();
2214: } finally {
2215: toolkit.unlockAWT();
2216: }
2217: }
2218:
2219: public boolean isDoubleBuffered() {
2220: toolkit.lockAWT();
2221: try {
2222: // false by default
2223: return false;
2224: } finally {
2225: toolkit.unlockAWT();
2226: }
2227: }
2228:
2229: public boolean isEnabled() {
2230: toolkit.lockAWT();
2231: try {
2232: return enabled;
2233: } finally {
2234: toolkit.unlockAWT();
2235: }
2236: }
2237:
2238: /**
2239: * "Recursive" isEnabled().
2240: *
2241: * @return true if not only component itself is enabled but its heavyweight
2242: * parent is also "indirectly" enabled
2243: */
2244: boolean isIndirectlyEnabled() {
2245: Component comp = this ;
2246: while (comp != null) {
2247: if (!comp.isLightweight() && !comp.isEnabled()) {
2248: return false;
2249: }
2250: comp = comp.getRealParent();
2251: }
2252: return true;
2253: }
2254:
2255: boolean isKeyEnabled() {
2256: if (!isEnabled()) {
2257: return false;
2258: }
2259: return isIndirectlyEnabled();
2260: }
2261:
2262: /**
2263: * Gets only parent of a child component, but not owner of a window.
2264: *
2265: * @return parent of child component, null if component is a top-level
2266: * (Window instance)
2267: */
2268: Container getRealParent() {
2269: return (!(this instanceof Window) ? getParent() : null);
2270: }
2271:
2272: public boolean isFocusCycleRoot(Container container) {
2273: toolkit.lockAWT();
2274: try {
2275: return getFocusCycleRootAncestor() == container;
2276: } finally {
2277: toolkit.unlockAWT();
2278: }
2279: }
2280:
2281: public boolean isFocusOwner() {
2282: toolkit.lockAWT();
2283: try {
2284: return KeyboardFocusManager
2285: .getCurrentKeyboardFocusManager().getFocusOwner() == this ;
2286: } finally {
2287: toolkit.unlockAWT();
2288: }
2289: }
2290:
2291: @Deprecated
2292: public boolean isFocusTraversable() {
2293: toolkit.lockAWT();
2294: try {
2295: overridenIsFocusable = false;
2296: return focusable; // a Component must either be both focusable and
2297: // focus traversable, or neither
2298: } finally {
2299: toolkit.unlockAWT();
2300: }
2301: }
2302:
2303: public boolean isFocusable() {
2304: toolkit.lockAWT();
2305: try {
2306: return isFocusTraversable();
2307: } finally {
2308: toolkit.unlockAWT();
2309: }
2310: }
2311:
2312: public boolean isFontSet() {
2313: toolkit.lockAWT();
2314: try {
2315: return font != null;
2316: } finally {
2317: toolkit.unlockAWT();
2318: }
2319: }
2320:
2321: public boolean isForegroundSet() {
2322: toolkit.lockAWT();
2323: try {
2324: return foreColor != null;
2325: } finally {
2326: toolkit.unlockAWT();
2327: }
2328: }
2329:
2330: public boolean isLightweight() {
2331: toolkit.lockAWT();
2332: try {
2333: return behaviour.isLightweight();
2334: } finally {
2335: toolkit.unlockAWT();
2336: }
2337: }
2338:
2339: public boolean isShowing() {
2340: toolkit.lockAWT();
2341: try {
2342: return (isVisible() && isDisplayable() && (parent != null) && parent
2343: .isShowing());
2344: } finally {
2345: toolkit.unlockAWT();
2346: }
2347: }
2348:
2349: public boolean isVisible() {
2350: toolkit.lockAWT();
2351: try {
2352: return visible;
2353: } finally {
2354: toolkit.unlockAWT();
2355: }
2356: }
2357:
2358: @Deprecated
2359: public boolean keyDown(Event evt, int key) {
2360: // to be overridden: do nothing,
2361: // just return false to propagate event up to the parent container
2362: return false;
2363: }
2364:
2365: @Deprecated
2366: public boolean keyUp(Event evt, int key) {
2367: // to be overridden: do nothing,
2368: // just return false to propagate event up to the parent container
2369: return false;
2370: }
2371:
2372: @Deprecated
2373: public void layout() {
2374: toolkit.lockAWT();
2375: try {
2376: // Implemented in Container
2377: } finally {
2378: toolkit.unlockAWT();
2379: }
2380: }
2381:
2382: @Deprecated
2383: public Component locate(int x, int y) {
2384: toolkit.lockAWT();
2385: try {
2386: if (contains(x, y)) {
2387: return this ;
2388: }
2389: return null;
2390: } finally {
2391: toolkit.unlockAWT();
2392: }
2393: }
2394:
2395: @Deprecated
2396: public boolean lostFocus(Event evt, Object what) {
2397: // to be overridden: do nothing,
2398: // just return false to propagate event up to the parent container
2399: return false;
2400: }
2401:
2402: @Deprecated
2403: public boolean mouseDown(Event evt, int x, int y) {
2404: // to be overridden: do nothing,
2405: // just return false to propagate event up to the parent container
2406: return false;
2407: }
2408:
2409: @Deprecated
2410: public boolean mouseDrag(Event evt, int x, int y) {
2411: // to be overridden: do nothing,
2412: // just return false to propagate event up to the parent container
2413: return false;
2414: }
2415:
2416: @Deprecated
2417: public boolean mouseEnter(Event evt, int x, int y) {
2418: // to be overridden: do nothing,
2419: // just return false to propagate event up to the parent container
2420: return false;
2421: }
2422:
2423: @Deprecated
2424: public boolean mouseExit(Event evt, int x, int y) {
2425: // to be overridden: do nothing,
2426: // just return false to propagate event up to the parent container
2427: return false;
2428: }
2429:
2430: @Deprecated
2431: public boolean mouseMove(Event evt, int x, int y) {
2432: // to be overridden: do nothing,
2433: // just return false to propagate event up to the parent container
2434: return false;
2435: }
2436:
2437: @Deprecated
2438: public boolean mouseUp(Event evt, int x, int y) {
2439: // to be overridden: do nothing,
2440: // just return false to propagate event up to the parent container
2441: return false;
2442: }
2443:
2444: @Deprecated
2445: public void move(int x, int y) {
2446: toolkit.lockAWT();
2447: try {
2448: boundsMaskParam = NativeWindow.BOUNDS_NOSIZE;
2449: setBounds(x, y, w, h);
2450: } finally {
2451: toolkit.unlockAWT();
2452: }
2453: }
2454:
2455: @Deprecated
2456: public void nextFocus() {
2457: toolkit.lockAWT();
2458: try {
2459: transferFocus(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
2460: } finally {
2461: toolkit.unlockAWT();
2462: }
2463: }
2464:
2465: protected String paramString() {
2466: /*
2467: * The format is based on 1.5 release behavior which can be revealed by
2468: * the following code:
2469: *
2470: * Component c = new Component(){}; c.setVisible(false);
2471: * System.out.println(c);
2472: */
2473: toolkit.lockAWT();
2474: try {
2475: return getName()
2476: + "," + getX() + "," + getY() + "," + getWidth() + "x" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
2477: + getHeight() + (!isVisible() ? ",hidden" : ""); //$NON-NLS-1$ //$NON-NLS-2$
2478: } finally {
2479: toolkit.unlockAWT();
2480: }
2481: }
2482:
2483: @Deprecated
2484: @SuppressWarnings("deprecation")
2485: public boolean postEvent(Event evt) {
2486: boolean handled = handleEvent(evt);
2487: if (handled) {
2488: return true;
2489: }
2490: // propagate non-handled events up to parent
2491: Component par = parent;
2492: // try to call postEvent only on components which
2493: // override any of deprecated method handlers
2494: // while (par != null && !par.deprecatedEventHandler) {
2495: // par = par.parent;
2496: // }
2497: // translate event coordinates before posting it to parent
2498: if (par != null) {
2499: evt.translate(x, y);
2500: par.postEvent(evt);
2501: }
2502: return false;
2503: }
2504:
2505: public boolean prepareImage(Image image, ImageObserver observer) {
2506: toolkit.lockAWT();
2507: try {
2508: return toolkit.prepareImage(image, -1, -1, observer);
2509: } finally {
2510: toolkit.unlockAWT();
2511: }
2512: }
2513:
2514: public boolean prepareImage(Image image, int width, int height,
2515: ImageObserver observer) {
2516: toolkit.lockAWT();
2517: try {
2518: return toolkit.prepareImage(image, width, height, observer);
2519: } finally {
2520: toolkit.unlockAWT();
2521: }
2522: }
2523:
2524: public void removeNotify() {
2525: toolkit.lockAWT();
2526: try {
2527: if (dropTarget != null) {
2528: dropTarget.removeNotify(peer);
2529: }
2530: prepare4HierarchyChange();
2531: moveFocus();
2532: behaviour.removeNotify();
2533: finishHierarchyChange(this , parent, 0);
2534: removeNotifyInputContext();
2535: } finally {
2536: toolkit.unlockAWT();
2537: }
2538: }
2539:
2540: /**
2541: * Calls InputContext.removeNotify
2542: */
2543: private void removeNotifyInputContext() {
2544: if (!inputMethodsEnabled) {
2545: return;
2546: }
2547: InputContext ic = getInputContext();
2548: if (ic != null) {
2549: ic.removeNotify(this );
2550: }
2551: }
2552:
2553: /**
2554: * This method is called when some property of a component changes, making
2555: * it unfocusable, e. g. hide(), removeNotify(), setEnabled(false),
2556: * setFocusable(false) is called, and therefore automatic forward focus
2557: * traversal is necessary
2558: */
2559: void moveFocus() {
2560: // don't use transferFocus(), but query focus traversal policy directly
2561: // and if it returns null, transfer focus up cycle
2562: // and find next focusable component there
2563: KeyboardFocusManager kfm = KeyboardFocusManager
2564: .getCurrentKeyboardFocusManager();
2565: Container root = kfm.getCurrentFocusCycleRoot();
2566: Component nextComp = this ;
2567: boolean success = !isFocusOwner();
2568: while (!success) {
2569: if (root != nextComp.getFocusCycleRootAncestor()) {
2570: // component was probably removed from container
2571: // so focus will be lost in some time
2572: return;
2573: }
2574: nextComp = root.getFocusTraversalPolicy()
2575: .getComponentAfter(root, nextComp);
2576: if (nextComp == this ) {
2577: nextComp = null; // avoid looping
2578: }
2579: if (nextComp != null) {
2580: success = nextComp.requestFocusInWindow();
2581: } else {
2582: nextComp = root;
2583: root = root.getFocusCycleRootAncestor();
2584: // if no acceptable component is found at all - clear global
2585: // focus owner
2586: if (root == null) {
2587: if (nextComp instanceof Window) {
2588: Window wnd = (Window) nextComp;
2589: wnd.setFocusOwner(null);
2590: wnd.setRequestedFocus(null);
2591: }
2592: kfm.clearGlobalFocusOwner();
2593: return;
2594: }
2595: }
2596: }
2597: }
2598:
2599: /**
2600: * For Container there's a difference between moving focus when being made
2601: * invisible or made unfocusable in some other way, because when container
2602: * is made invisible, component still remains visible, i. e. its hide() or
2603: * setVisible() is not called.
2604: */
2605: void moveFocusOnHide() {
2606: moveFocus();
2607: }
2608:
2609: public void removePropertyChangeListener(
2610: PropertyChangeListener listener) {
2611: getPropertyChangeSupport().removePropertyChangeListener(
2612: listener);
2613: }
2614:
2615: public void removePropertyChangeListener(String propertyName,
2616: PropertyChangeListener listener) {
2617: getPropertyChangeSupport().removePropertyChangeListener(
2618: propertyName, listener);
2619: }
2620:
2621: public void repaint(long tm, int x, int y, int width, int height) {
2622: toolkit.lockAWT();
2623: try {
2624: if (width <= 0 || height <= 0 || (redrawManager == null)
2625: || !isShowing()) {
2626: return;
2627: }
2628: if (behaviour instanceof LWBehavior) {
2629: if (parent == null || !parent.visible
2630: || !parent.behaviour.isDisplayable()) {
2631: return;
2632: }
2633: if (repaintRegion == null) {
2634: repaintRegion = new MultiRectArea(new Rectangle(x,
2635: y, width, height));
2636: }
2637: repaintRegion.intersect(new Rectangle(0, 0, this .w,
2638: this .h));
2639: repaintRegion.translate(this .x, this .y);
2640: parent.repaintRegion = repaintRegion;
2641: repaintRegion = null;
2642: parent.repaint(tm, x + this .x, y + this .y, width,
2643: height);
2644: } else {
2645: if (repaintRegion != null) {
2646: redrawManager.addUpdateRegion(this , repaintRegion);
2647: repaintRegion = null;
2648: } else {
2649: redrawManager.addUpdateRegion(this , new Rectangle(
2650: x, y, width, height));
2651: }
2652: toolkit.getSystemEventQueueCore().notifyEventMonitor(
2653: toolkit);
2654: }
2655: } finally {
2656: toolkit.unlockAWT();
2657: }
2658: }
2659:
2660: void postEvent(AWTEvent e) {
2661: getToolkit().getSystemEventQueueImpl().postEvent(e);
2662: }
2663:
2664: public void repaint(int x, int y, int width, int height) {
2665: toolkit.lockAWT();
2666: try {
2667: repaint(0, x, y, width, height);
2668: } finally {
2669: toolkit.unlockAWT();
2670: }
2671: }
2672:
2673: public void repaint() {
2674: toolkit.lockAWT();
2675: try {
2676: if (w > 0 && h > 0) {
2677: repaint(0, 0, 0, w, h);
2678: }
2679: } finally {
2680: toolkit.unlockAWT();
2681: }
2682: }
2683:
2684: public void repaint(long tm) {
2685: toolkit.lockAWT();
2686: try {
2687: repaint(tm, 0, 0, w, h);
2688: } finally {
2689: toolkit.unlockAWT();
2690: }
2691: }
2692:
2693: protected boolean requestFocus(boolean temporary) {
2694: toolkit.lockAWT();
2695: try {
2696: return requestFocusImpl(temporary, true, false);
2697: } finally {
2698: toolkit.unlockAWT();
2699: }
2700: }
2701:
2702: public void requestFocus() {
2703: toolkit.lockAWT();
2704: try {
2705: requestFocus(false);
2706: } finally {
2707: toolkit.unlockAWT();
2708: }
2709: }
2710:
2711: protected boolean requestFocusInWindow(boolean temporary) {
2712: toolkit.lockAWT();
2713: try {
2714: Window wnd = getWindowAncestor();
2715: if ((wnd == null) || !wnd.isFocused()) {
2716: return false;
2717: }
2718: return requestFocusImpl(temporary, false, false);
2719: } finally {
2720: toolkit.unlockAWT();
2721: }
2722: }
2723:
2724: boolean requestFocusImpl(boolean temporary, boolean crossWindow,
2725: boolean rejectionRecovery) {
2726: if (!rejectionRecovery && isFocusOwner()) {
2727: return true;
2728: }
2729: Window wnd = getWindowAncestor();
2730: Container par = getRealParent();
2731: if ((par != null) && par.isRemoved) {
2732: return false;
2733: }
2734: if (!isShowing() || !isFocusable() || !wnd.isFocusableWindow()) {
2735: return false;
2736: }
2737: return KeyboardFocusManager.getCurrentKeyboardFocusManager()
2738: .requestFocus(this , temporary, crossWindow, true);
2739: }
2740:
2741: public boolean requestFocusInWindow() {
2742: toolkit.lockAWT();
2743: try {
2744: return requestFocusInWindow(false);
2745: } finally {
2746: toolkit.unlockAWT();
2747: }
2748: }
2749:
2750: @Deprecated
2751: public void reshape(int x, int y, int w, int h) {
2752: toolkit.lockAWT();
2753: try {
2754: setBounds(x, y, w, h, boundsMaskParam, true);
2755: boundsMaskParam = 0;
2756: } finally {
2757: toolkit.unlockAWT();
2758: }
2759: }
2760:
2761: public void setBounds(int x, int y, int w, int h) {
2762: toolkit.lockAWT();
2763: try {
2764: reshape(x, y, w, h);
2765: } finally {
2766: toolkit.unlockAWT();
2767: }
2768: }
2769:
2770: /**
2771: * Update the component bounds and post the appropriate events
2772: */
2773: void setBounds(int x, int y, int w, int h, int bMask,
2774: boolean updateBehavior) {
2775: int oldX = this .x;
2776: int oldY = this .y;
2777: int oldW = this .w;
2778: int oldH = this .h;
2779: setBoundsFields(x, y, w, h, bMask);
2780: // Moved
2781: if ((oldX != this .x) || (oldY != this .y)) {
2782: invalidateRealParent();
2783: postEvent(new ComponentEvent(this ,
2784: ComponentEvent.COMPONENT_MOVED));
2785: spreadHierarchyBoundsEvents(this ,
2786: HierarchyEvent.ANCESTOR_MOVED);
2787: }
2788: // Resized
2789: if ((oldW != this .w) || (oldH != this .h)) {
2790: invalidate();
2791: postEvent(new ComponentEvent(this ,
2792: ComponentEvent.COMPONENT_RESIZED));
2793: spreadHierarchyBoundsEvents(this ,
2794: HierarchyEvent.ANCESTOR_RESIZED);
2795: }
2796: if (updateBehavior) {
2797: behaviour.setBounds(this .x, this .y, this .w, this .h, bMask);
2798: }
2799: notifyInputMethod(new Rectangle(x, y, w, h));
2800: }
2801:
2802: /**
2803: * Calls InputContextImpl.notifyClientWindowChanged.
2804: */
2805: void notifyInputMethod(Rectangle bounds) {
2806: // only Window actually notifies IM of bounds change
2807: }
2808:
2809: private void setBoundsFields(int x, int y, int w, int h, int bMask) {
2810: if ((bMask & NativeWindow.BOUNDS_NOSIZE) == 0) {
2811: this .w = w;
2812: this .h = h;
2813: }
2814: if ((bMask & NativeWindow.BOUNDS_NOMOVE) == 0) {
2815: this .x = x;
2816: this .y = y;
2817: }
2818: }
2819:
2820: Insets getNativeInsets() {
2821: return new Insets(0, 0, 0, 0);
2822: }
2823:
2824: Insets getInsets() {
2825: return new Insets(0, 0, 0, 0);
2826: }
2827:
2828: boolean isMouseExitedExpected() {
2829: return mouseExitedExpected;
2830: }
2831:
2832: void setMouseExitedExpected(boolean expected) {
2833: mouseExitedExpected = expected;
2834: }
2835:
2836: public void setBounds(Rectangle r) {
2837: toolkit.lockAWT();
2838: try {
2839: setBounds(r.x, r.y, r.width, r.height);
2840: } finally {
2841: toolkit.unlockAWT();
2842: }
2843: }
2844:
2845: public void setComponentOrientation(ComponentOrientation o) {
2846: ComponentOrientation oldOrientation;
2847: toolkit.lockAWT();
2848: try {
2849: oldOrientation = orientation;
2850: orientation = o;
2851: } finally {
2852: toolkit.unlockAWT();
2853: }
2854: firePropertyChange(
2855: "componentOrientation", oldOrientation, orientation); //$NON-NLS-1$
2856: invalidate();
2857: }
2858:
2859: public void setCursor(Cursor cursor) {
2860: toolkit.lockAWT();
2861: try {
2862: this .cursor = cursor;
2863: setCursor();
2864: } finally {
2865: toolkit.unlockAWT();
2866: }
2867: }
2868:
2869: /**
2870: * Set current cursor shape to Component's Cursor
2871: */
2872: void setCursor() {
2873: if (isDisplayable() && isShowing()) {
2874: Rectangle absRect = new Rectangle(getLocationOnScreen(),
2875: getSize());
2876: Point absPointerPos = toolkit.dispatcher.mouseDispatcher
2877: .getPointerPos();
2878: if (absRect.contains(absPointerPos)) {
2879: // set Cursor only on top-level Windows(on X11)
2880: Window topLevelWnd = getWindowAncestor();
2881: if (topLevelWnd != null) {
2882: Point pointerPos = MouseDispatcher.convertPoint(
2883: null, absPointerPos, topLevelWnd);
2884: Component compUnderCursor = topLevelWnd
2885: .findComponentAt(pointerPos);
2886: // if (compUnderCursor == this ||
2887: // compUnderCursor.getCursorAncestor() == this) {
2888: NativeWindow wnd = topLevelWnd.getNativeWindow();
2889: if (compUnderCursor != null && wnd != null) {
2890: compUnderCursor.getRealCursor()
2891: .getNativeCursor().setCursor(
2892: wnd.getId());
2893: }
2894: // }
2895: }
2896: }
2897: }
2898: }
2899:
2900: /**
2901: * Gets the ancestor Cursor if Component is disabled (directly or via an
2902: * ancestor) even if Cursor is explicitly set
2903: *
2904: * @return actual Cursor to be displayed
2905: */
2906: Cursor getRealCursor() {
2907: Component cursorAncestor = getCursorAncestor();
2908: return cursorAncestor != null ? cursorAncestor.getCursor()
2909: : Cursor.getDefaultCursor();
2910: }
2911:
2912: /**
2913: * Gets the ancestor(or component itself) whose cursor is set when pointer
2914: * is inside component
2915: *
2916: * @return actual Cursor to be displayed
2917: */
2918: Component getCursorAncestor() {
2919: Component comp;
2920: for (comp = this ; comp != null; comp = comp.getParent()) {
2921: if (comp instanceof Window || comp.isCursorSet()
2922: && comp.isKeyEnabled()) {
2923: return comp;
2924: }
2925: }
2926: return null;
2927: }
2928:
2929: public void setDropTarget(DropTarget dt) {
2930: toolkit.lockAWT();
2931: try {
2932: if (dropTarget == dt) {
2933: return;
2934: }
2935: DropTarget oldDropTarget = dropTarget;
2936: dropTarget = dt;
2937: if (oldDropTarget != null) {
2938: if (behaviour.isDisplayable()) {
2939: oldDropTarget.removeNotify(peer);
2940: }
2941: oldDropTarget.setComponent(null);
2942: }
2943: if (dt != null) {
2944: dt.setComponent(this );
2945: if (behaviour.isDisplayable()) {
2946: dt.addNotify(peer);
2947: }
2948: }
2949: } finally {
2950: toolkit.unlockAWT();
2951: }
2952: }
2953:
2954: public void setEnabled(boolean value) {
2955: toolkit.lockAWT();
2956: try {
2957: enable(value);
2958: } finally {
2959: toolkit.unlockAWT();
2960: }
2961: }
2962:
2963: void setEnabledImpl(boolean value) {
2964: if (enabled != value) {
2965: enabled = value;
2966: setCursor();
2967: if (!enabled) {
2968: moveFocusOnHide();
2969: }
2970: behaviour.setEnabled(value);
2971: }
2972: }
2973:
2974: private void fireAccessibleStateChange(AccessibleState state,
2975: boolean value) {
2976: if (behaviour.isLightweight()) {
2977: return;
2978: }
2979: AccessibleContext ac = getAccessibleContext();
2980: if (ac != null) {
2981: AccessibleState oldValue = null;
2982: AccessibleState newValue = null;
2983: if (value) {
2984: newValue = state;
2985: } else {
2986: oldValue = state;
2987: }
2988: ac.firePropertyChange(
2989: AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
2990: oldValue, newValue);
2991: }
2992: }
2993:
2994: public void setFocusTraversalKeys(int id,
2995: Set<? extends AWTKeyStroke> keystrokes) {
2996: Set<? extends AWTKeyStroke> oldTraversalKeys;
2997: String propName = "FocusTraversalKeys"; //$NON-NLS-1$
2998: toolkit.lockAWT();
2999: try {
3000: Integer kId = new Integer(id);
3001: KeyboardFocusManager.checkTraversalKeysID(traversalKeys,
3002: kId);
3003: Map<Integer, Set<? extends AWTKeyStroke>> keys = new HashMap<Integer, Set<? extends AWTKeyStroke>>();
3004: for (int kid : traversalIDs) {
3005: Integer key = new Integer(kid);
3006: keys.put(key, getFocusTraversalKeys(kid));
3007: }
3008: KeyboardFocusManager.checkKeyStrokes(traversalIDs, keys,
3009: kId, keystrokes);
3010: oldTraversalKeys = traversalKeys.get(new Integer(id));
3011: // put a copy of keystrokes object into map:
3012: Set<? extends AWTKeyStroke> newKeys = keystrokes;
3013: if (keystrokes != null) {
3014: newKeys = new HashSet<AWTKeyStroke>(keystrokes);
3015: }
3016: traversalKeys.put(kId, newKeys);
3017: String direction = ""; //$NON-NLS-1$
3018: switch (id) {
3019: case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS:
3020: direction = "forward"; //$NON-NLS-1$
3021: break;
3022: case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS:
3023: direction = "backward"; //$NON-NLS-1$
3024: break;
3025: case KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS:
3026: direction = "upCycle"; //$NON-NLS-1$
3027: break;
3028: case KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS:
3029: direction = "downCycle"; //$NON-NLS-1$
3030: break;
3031: }
3032: propName = direction + propName;
3033: } finally {
3034: toolkit.unlockAWT();
3035: }
3036: firePropertyChange(propName, oldTraversalKeys, keystrokes);
3037: }
3038:
3039: public void setFocusTraversalKeysEnabled(boolean value) {
3040: boolean oldFocusTraversalKeysEnabled;
3041: toolkit.lockAWT();
3042: try {
3043: oldFocusTraversalKeysEnabled = focusTraversalKeysEnabled;
3044: focusTraversalKeysEnabled = value;
3045: } finally {
3046: toolkit.unlockAWT();
3047: }
3048: firePropertyChange(
3049: "focusTraversalKeysEnabled", oldFocusTraversalKeysEnabled, //$NON-NLS-1$
3050: focusTraversalKeysEnabled);
3051: }
3052:
3053: public void setFocusable(boolean focusable) {
3054: boolean oldFocusable;
3055: toolkit.lockAWT();
3056: try {
3057: calledSetFocusable = true;
3058: oldFocusable = this .focusable;
3059: this .focusable = focusable;
3060: if (!focusable) {
3061: moveFocus();
3062: }
3063: } finally {
3064: toolkit.unlockAWT();
3065: }
3066: firePropertyChange("focusable", oldFocusable, focusable); //$NON-NLS-1$
3067: }
3068:
3069: public Font getFont() {
3070: toolkit.lockAWT();
3071: try {
3072: return (font == null) && (parent != null) ? parent
3073: .getFont() : font;
3074: } finally {
3075: toolkit.unlockAWT();
3076: }
3077: }
3078:
3079: public void setFont(Font f) {
3080: Font oldFont;
3081: toolkit.lockAWT();
3082: try {
3083: oldFont = font;
3084: setFontImpl(f);
3085: } finally {
3086: toolkit.unlockAWT();
3087: }
3088: firePropertyChange("font", oldFont, font); //$NON-NLS-1$
3089: }
3090:
3091: void setFontImpl(Font f) {
3092: if (!(f == font || (f != null && f.equals(font)))) {// to avoid dead loop in repaint()
3093: font = f;
3094: invalidate();
3095: if (isShowing()) {
3096: repaint();
3097: }
3098: }
3099: }
3100:
3101: /**
3102: * Invalidate the component if it inherits the font from the parent. This
3103: * method is overridden in Container.
3104: *
3105: * @return true if the component was invalidated, false otherwise
3106: */
3107: boolean propagateFont() {
3108: if (font == null) {
3109: invalidate();
3110: return true;
3111: }
3112: return false;
3113: }
3114:
3115: public void setForeground(Color c) {
3116: Color oldFgColor;
3117:
3118: toolkit.lockAWT();
3119: try {
3120: oldFgColor = foreColor;
3121: foreColor = c;
3122: } finally {
3123: toolkit.unlockAWT();
3124: }
3125:
3126: // Update only if new color differs from the old one.
3127: // It is needed to avoid dead loops in repaint().
3128: if (!(oldFgColor == c || (c != null && c.equals(oldFgColor)))) {
3129: firePropertyChange("foreground", oldFgColor, c); //$NON-NLS-1$
3130: repaint();
3131: }
3132: }
3133:
3134: public void setBackground(Color c) {
3135: Color oldBgColor;
3136:
3137: toolkit.lockAWT();
3138: try {
3139: oldBgColor = backColor;
3140: backColor = c;
3141: } finally {
3142: toolkit.unlockAWT();
3143: }
3144:
3145: // update only if new color differs from the old one
3146: // to avoid dead loop in repaint()
3147: if (!(c == oldBgColor || (c != null && c.equals(oldBgColor)))) {
3148: firePropertyChange("background", oldBgColor, c); //$NON-NLS-1$
3149: repaint();
3150: }
3151: }
3152:
3153: public void setIgnoreRepaint(boolean value) {
3154: toolkit.lockAWT();
3155: try {
3156: ignoreRepaint = value;
3157: } finally {
3158: toolkit.unlockAWT();
3159: }
3160: }
3161:
3162: public void setLocale(Locale locale) {
3163: Locale oldLocale;
3164: toolkit.lockAWT();
3165: try {
3166: oldLocale = this .locale;
3167: this .locale = locale;
3168: } finally {
3169: toolkit.unlockAWT();
3170: }
3171: firePropertyChange("locale", oldLocale, locale); //$NON-NLS-1$
3172: }
3173:
3174: public void setLocation(Point p) {
3175: toolkit.lockAWT();
3176: try {
3177: setLocation(p.x, p.y);
3178: } finally {
3179: toolkit.unlockAWT();
3180: }
3181: }
3182:
3183: public void setLocation(int x, int y) {
3184: toolkit.lockAWT();
3185: try {
3186: move(x, y);
3187: } finally {
3188: toolkit.unlockAWT();
3189: }
3190: }
3191:
3192: public void setVisible(boolean b) {
3193: // show() & hide() are not deprecated for Window,
3194: // so have to call them from setVisible()
3195: show(b);
3196: }
3197:
3198: @Deprecated
3199: public void show() {
3200: toolkit.lockAWT();
3201: try {
3202: if (visible) {
3203: return;
3204: }
3205: prepare4HierarchyChange();
3206: mapToDisplay(true);
3207: validate();
3208: visible = true;
3209: behaviour.setVisible(true);
3210: postEvent(new ComponentEvent(this ,
3211: ComponentEvent.COMPONENT_SHOWN));
3212: finishHierarchyChange(this , parent, 0);
3213: notifyInputMethod(new Rectangle(x, y, w, h));
3214: invalidateRealParent();
3215: } finally {
3216: toolkit.unlockAWT();
3217: }
3218: }
3219:
3220: @Deprecated
3221: public void show(boolean b) {
3222: if (b) {
3223: show();
3224: } else {
3225: hide();
3226: }
3227: }
3228:
3229: void transferFocus(int dir) {
3230: Container root = null;
3231: if (this instanceof Container) {
3232: Container cont = (Container) this ;
3233: if (cont.isFocusCycleRoot()) {
3234: root = cont.getFocusTraversalRoot();
3235: }
3236: }
3237: if (root == null) {
3238: root = getFocusCycleRootAncestor();
3239: }
3240: // transfer focus up cycle if root is unreachable
3241: Component comp = this ;
3242: while ((root != null)
3243: && !(root.isFocusCycleRoot() && root.isShowing()
3244: && root.isEnabled() && root.isFocusable())) {
3245: comp = root;
3246: root = root.getFocusCycleRootAncestor();
3247: }
3248: if (root == null) {
3249: return;
3250: }
3251: FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
3252: Component nextComp = null;
3253: switch (dir) {
3254: case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS:
3255: nextComp = policy.getComponentAfter(root, comp);
3256: break;
3257: case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS:
3258: nextComp = policy.getComponentBefore(root, comp);
3259: break;
3260: }
3261: if (nextComp != null) {
3262: nextComp.requestFocus(false);
3263: }
3264: }
3265:
3266: public void transferFocus() {
3267: toolkit.lockAWT();
3268: try {
3269: nextFocus();
3270: } finally {
3271: toolkit.unlockAWT();
3272: }
3273: }
3274:
3275: public void transferFocusBackward() {
3276: toolkit.lockAWT();
3277: try {
3278: transferFocus(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
3279: } finally {
3280: toolkit.unlockAWT();
3281: }
3282: }
3283:
3284: public void transferFocusUpCycle() {
3285: toolkit.lockAWT();
3286: try {
3287: KeyboardFocusManager kfm = KeyboardFocusManager
3288: .getCurrentKeyboardFocusManager();
3289: Container root = kfm.getCurrentFocusCycleRoot();
3290:
3291: if (root == null) {
3292: return;
3293: }
3294:
3295: boolean success = false;
3296: Component nextComp = null;
3297: Container newRoot = root;
3298: do {
3299: nextComp = newRoot instanceof Window ? newRoot
3300: .getFocusTraversalPolicy().getDefaultComponent(
3301: newRoot) : newRoot;
3302: newRoot = newRoot.getFocusCycleRootAncestor();
3303: if (nextComp == null) {
3304: break;
3305: }
3306: success = nextComp.requestFocusInWindow();
3307: if (newRoot == null) {
3308: break;
3309: }
3310: kfm.setGlobalCurrentFocusCycleRoot(newRoot);
3311: } while (!success);
3312: if (!success && root != newRoot) {
3313: kfm.setGlobalCurrentFocusCycleRoot(root);
3314: }
3315: } finally {
3316: toolkit.unlockAWT();
3317: }
3318: }
3319:
3320: public void validate() {
3321: toolkit.lockAWT();
3322: try {
3323: if (!behaviour.isDisplayable()) {
3324: return;
3325: }
3326: validateImpl();
3327: } finally {
3328: toolkit.unlockAWT();
3329: }
3330: }
3331:
3332: void validateImpl() {
3333: valid = true;
3334: }
3335:
3336: NativeWindow getNativeWindow() {
3337: return behaviour.getNativeWindow();
3338: }
3339:
3340: public boolean isMaximumSizeSet() {
3341: toolkit.lockAWT();
3342: try {
3343: return maximumSize != null;
3344: } finally {
3345: toolkit.unlockAWT();
3346: }
3347: }
3348:
3349: public boolean isMinimumSizeSet() {
3350: toolkit.lockAWT();
3351: try {
3352: return minimumSize != null;
3353: } finally {
3354: toolkit.unlockAWT();
3355: }
3356: }
3357:
3358: public boolean isPreferredSizeSet() {
3359: toolkit.lockAWT();
3360: try {
3361: return preferredSize != null;
3362: } finally {
3363: toolkit.unlockAWT();
3364: }
3365: }
3366:
3367: public Dimension getMaximumSize() {
3368: toolkit.lockAWT();
3369: try {
3370: return isMaximumSizeSet() ? new Dimension(maximumSize)
3371: : new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
3372: } finally {
3373: toolkit.unlockAWT();
3374: }
3375: }
3376:
3377: public Dimension getMinimumSize() {
3378: toolkit.lockAWT();
3379: try {
3380: return minimumSize();
3381: } finally {
3382: toolkit.unlockAWT();
3383: }
3384: }
3385:
3386: @Deprecated
3387: public Dimension minimumSize() {
3388: toolkit.lockAWT();
3389: try {
3390: if (isMinimumSizeSet()) {
3391: return (Dimension) minimumSize.clone();
3392: }
3393: Dimension defSize = getDefaultMinimumSize();
3394: if (defSize != null) {
3395: return (Dimension) defSize.clone();
3396: }
3397: return isDisplayable() ? new Dimension(1, 1)
3398: : new Dimension(w, h);
3399: } finally {
3400: toolkit.unlockAWT();
3401: }
3402: }
3403:
3404: public Dimension getPreferredSize() {
3405: toolkit.lockAWT();
3406: try {
3407: return preferredSize();
3408: } finally {
3409: toolkit.unlockAWT();
3410: }
3411: }
3412:
3413: @Deprecated
3414: public Dimension preferredSize() {
3415: toolkit.lockAWT();
3416: try {
3417: if (isPreferredSizeSet()) {
3418: return new Dimension(preferredSize);
3419: }
3420: Dimension defSize = getDefaultPreferredSize();
3421: if (defSize != null) {
3422: return new Dimension(defSize);
3423: }
3424: return new Dimension(getMinimumSize());
3425: } finally {
3426: toolkit.unlockAWT();
3427: }
3428: }
3429:
3430: public void setMaximumSize(Dimension maximumSize) {
3431: Dimension oldMaximumSize;
3432: toolkit.lockAWT();
3433: try {
3434: oldMaximumSize = this .maximumSize;
3435: if (oldMaximumSize != null) {
3436: oldMaximumSize = oldMaximumSize.getSize();
3437: }
3438: if (this .maximumSize == null) {
3439: if (maximumSize != null) {
3440: this .maximumSize = new Dimension(maximumSize);
3441: }
3442: } else {
3443: if (maximumSize != null) {
3444: this .maximumSize.setSize(maximumSize);
3445: } else {
3446: this .maximumSize = null;
3447: }
3448: }
3449: } finally {
3450: toolkit.unlockAWT();
3451: }
3452: firePropertyChange(
3453: "maximumSize", oldMaximumSize, this .maximumSize); //$NON-NLS-1$
3454: toolkit.lockAWT();
3455: try {
3456: invalidateRealParent();
3457: } finally {
3458: toolkit.unlockAWT();
3459: }
3460: }
3461:
3462: public void setMinimumSize(Dimension minimumSize) {
3463: Dimension oldMinimumSize;
3464: toolkit.lockAWT();
3465: try {
3466: oldMinimumSize = this .minimumSize;
3467: if (oldMinimumSize != null) {
3468: oldMinimumSize = oldMinimumSize.getSize();
3469: }
3470: if (this .minimumSize == null) {
3471: if (minimumSize != null) {
3472: this .minimumSize = new Dimension(minimumSize);
3473: }
3474: } else {
3475: if (minimumSize != null) {
3476: this .minimumSize.setSize(minimumSize);
3477: } else {
3478: this .minimumSize = null;
3479: }
3480: }
3481: } finally {
3482: toolkit.unlockAWT();
3483: }
3484: firePropertyChange(
3485: "minimumSize", oldMinimumSize, this .minimumSize); //$NON-NLS-1$
3486: toolkit.lockAWT();
3487: try {
3488: invalidateRealParent();
3489: } finally {
3490: toolkit.unlockAWT();
3491: }
3492: }
3493:
3494: public void setPreferredSize(Dimension preferredSize) {
3495: Dimension oldPreferredSize;
3496: toolkit.lockAWT();
3497: try {
3498: oldPreferredSize = this .preferredSize;
3499: if (oldPreferredSize != null) {
3500: oldPreferredSize = oldPreferredSize.getSize();
3501: }
3502: if (this .preferredSize == null) {
3503: if (preferredSize != null) {
3504: this .preferredSize = new Dimension(preferredSize);
3505: }
3506: } else {
3507: if (preferredSize != null) {
3508: this .preferredSize.setSize(preferredSize);
3509: } else {
3510: this .preferredSize = null;
3511: }
3512: }
3513: } finally {
3514: toolkit.unlockAWT();
3515: }
3516: firePropertyChange(
3517: "preferredSize", oldPreferredSize, this .preferredSize); //$NON-NLS-1$
3518: toolkit.lockAWT();
3519: try {
3520: invalidateRealParent();
3521: } finally {
3522: toolkit.unlockAWT();
3523: }
3524: }
3525:
3526: RedrawManager getRedrawManager() {
3527: if (parent == null) {
3528: return null;
3529: }
3530: return parent.getRedrawManager();
3531: }
3532:
3533: /**
3534: * @return true if component has a focusable peer
3535: */
3536: boolean isPeerFocusable() {
3537: // The recommendations for Windows and Unix are that
3538: // Canvases, Labels, Panels, Scrollbars, ScrollPanes, Windows,
3539: // and lightweight Components have non-focusable peers,
3540: // and all other Components have focusable peers.
3541: if (this instanceof Canvas || this instanceof Label
3542: || this instanceof Panel || this instanceof Scrollbar
3543: || this instanceof ScrollPane || this instanceof Window
3544: || isLightweight()) {
3545: return false;
3546: }
3547: return true;
3548: }
3549:
3550: /**
3551: * @return true if focusability was explicitly set via a call to
3552: * setFocusable() or via overriding isFocusable() or
3553: * isFocusTraversable()
3554: */
3555: boolean isFocusabilityExplicitlySet() {
3556: return calledSetFocusable || overridenIsFocusable;
3557: }
3558:
3559: public void paintAll(Graphics g) {
3560: toolkit.lockAWT();
3561: try {
3562: paint(g);
3563: } finally {
3564: toolkit.unlockAWT();
3565: }
3566: }
3567:
3568: public void update(Graphics g) {
3569: toolkit.lockAWT();
3570: try {
3571: if (!isLightweight() && !isPrepainter()) {
3572: g.setColor(getBackground());
3573: g.fillRect(0, 0, w, h);
3574: g.setColor(getForeground());
3575: }
3576: paint(g);
3577: } finally {
3578: toolkit.unlockAWT();
3579: }
3580: }
3581:
3582: public void paint(Graphics g) {
3583: toolkit.lockAWT();
3584: try {
3585: // Just to nothing
3586: } finally {
3587: toolkit.unlockAWT();
3588: }
3589: }
3590:
3591: void prepaint(Graphics g) {
3592: // Just to nothing. For overriding.
3593: }
3594:
3595: boolean isPrepainter() {
3596: return false;
3597: }
3598:
3599: void prepare4HierarchyChange() {
3600: if (hierarchyChangingCounter++ == 0) {
3601: wasShowing = isShowing();
3602: wasDisplayable = isDisplayable();
3603: prepareChildren4HierarchyChange();
3604: }
3605: }
3606:
3607: void prepareChildren4HierarchyChange() {
3608: // To be inherited by Container
3609: }
3610:
3611: void finishHierarchyChange(Component changed,
3612: Container changedParent, int ancestorFlags) {
3613: if (--hierarchyChangingCounter == 0) {
3614: int changeFlags = ancestorFlags;
3615: if (wasShowing != isShowing()) {
3616: changeFlags |= HierarchyEvent.SHOWING_CHANGED;
3617: }
3618: if (wasDisplayable != isDisplayable()) {
3619: changeFlags |= HierarchyEvent.DISPLAYABILITY_CHANGED;
3620: }
3621: if (changeFlags > 0) {
3622: postEvent(new HierarchyEvent(this ,
3623: HierarchyEvent.HIERARCHY_CHANGED, changed,
3624: changedParent, changeFlags));
3625: }
3626: finishChildrenHierarchyChange(changed, changedParent,
3627: ancestorFlags);
3628: }
3629: }
3630:
3631: void finishChildrenHierarchyChange(Component changed,
3632: Container changedParent, int ancestorFlags) {
3633: // To be inherited by Container
3634: }
3635:
3636: void postHierarchyBoundsEvents(Component changed, int id) {
3637: postEvent(new HierarchyEvent(this , id, changed, null, 0));
3638: }
3639:
3640: void spreadHierarchyBoundsEvents(Component changed, int id) {
3641: // To be inherited by Container
3642: }
3643:
3644: public final void dispatchEvent(AWTEvent e) {
3645: if (e.isConsumed()) {
3646: return;
3647: }
3648: if (e instanceof PaintEvent) {
3649: toolkit.dispatchAWTEvent(e);
3650: processPaintEvent((PaintEvent) e);
3651: return;
3652: }
3653: KeyboardFocusManager kfm = KeyboardFocusManager
3654: .getCurrentKeyboardFocusManager();
3655: if (!e.dispatchedByKFM && kfm.dispatchEvent(e)) {
3656: return;
3657: }
3658: if (e instanceof KeyEvent) {
3659: KeyEvent ke = (KeyEvent) e;
3660: // consumes KeyEvent which represents a focus traversal key
3661: if (getFocusTraversalKeysEnabled()) {
3662: kfm.processKeyEvent(this , ke);
3663: if (ke.isConsumed()) {
3664: return;
3665: }
3666: }
3667: }
3668: if (inputMethodsEnabled && dispatchToIM && e.isPosted
3669: && dispatchEventToIM(e)) {
3670: return;
3671: }
3672: if (e.getID() == WindowEvent.WINDOW_ICONIFIED) {
3673: notifyInputMethod(null);
3674: }
3675: AWTEvent.EventDescriptor descriptor = toolkit.eventTypeLookup
3676: .getEventDescriptor(e);
3677: toolkit.dispatchAWTEvent(e);
3678: if (descriptor != null) {
3679: if (isEventEnabled(descriptor.eventMask)
3680: || (getListeners(descriptor.listenerType).length > 0)) {
3681: processEvent(e);
3682: }
3683: // input events can be consumed by user listeners:
3684: if (!e.isConsumed()
3685: && ((enabledAWTEvents & descriptor.eventMask) != 0)) {
3686: postprocessEvent(e, descriptor.eventMask);
3687: }
3688: }
3689: postDeprecatedEvent(e);
3690: }
3691:
3692: private void postDeprecatedEvent(AWTEvent e) {
3693: if (deprecatedEventHandler) {
3694: Event evt = e.getEvent();
3695: if (evt != null) {
3696: postEvent(evt);
3697: }
3698: }
3699: }
3700:
3701: void postprocessEvent(AWTEvent e, long eventMask) {
3702: toolkit.lockAWT();
3703: try {
3704: // call system listeners under AWT lock
3705: if (eventMask == AWTEvent.FOCUS_EVENT_MASK) {
3706: preprocessFocusEvent((FocusEvent) e);
3707: } else if (eventMask == AWTEvent.KEY_EVENT_MASK) {
3708: preprocessKeyEvent((KeyEvent) e);
3709: } else if (eventMask == AWTEvent.MOUSE_EVENT_MASK) {
3710: preprocessMouseEvent((MouseEvent) e);
3711: } else if (eventMask == AWTEvent.MOUSE_MOTION_EVENT_MASK) {
3712: preprocessMouseMotionEvent((MouseEvent) e);
3713: } else if (eventMask == AWTEvent.COMPONENT_EVENT_MASK) {
3714: preprocessComponentEvent((ComponentEvent) e);
3715: } else if (eventMask == AWTEvent.MOUSE_WHEEL_EVENT_MASK) {
3716: preprocessMouseWheelEvent((MouseWheelEvent) e);
3717: } else if (eventMask == AWTEvent.INPUT_METHOD_EVENT_MASK) {
3718: preprocessInputMethodEvent((InputMethodEvent) e);
3719: }
3720: } finally {
3721: toolkit.unlockAWT();
3722: }
3723: }
3724:
3725: private void preprocessInputMethodEvent(InputMethodEvent e) {
3726: processInputMethodEventImpl(e, inputMethodListeners
3727: .getSystemListeners());
3728: }
3729:
3730: private void preprocessMouseWheelEvent(MouseWheelEvent e) {
3731: processMouseWheelEventImpl(e, mouseWheelListeners
3732: .getSystemListeners());
3733: }
3734:
3735: private void processMouseWheelEventImpl(MouseWheelEvent e,
3736: Collection<MouseWheelListener> c) {
3737: for (MouseWheelListener listener : c) {
3738: switch (e.getID()) {
3739: case MouseEvent.MOUSE_WHEEL:
3740: listener.mouseWheelMoved(e);
3741: break;
3742: }
3743: }
3744: }
3745:
3746: private void preprocessComponentEvent(ComponentEvent e) {
3747: processComponentEventImpl(e, componentListeners
3748: .getSystemListeners());
3749: }
3750:
3751: void preprocessMouseMotionEvent(MouseEvent e) {
3752: processMouseMotionEventImpl(e, mouseMotionListeners
3753: .getSystemListeners());
3754: }
3755:
3756: void preprocessMouseEvent(MouseEvent e) {
3757: processMouseEventImpl(e, mouseListeners.getSystemListeners());
3758: }
3759:
3760: void preprocessKeyEvent(KeyEvent e) {
3761: processKeyEventImpl(e, keyListeners.getSystemListeners());
3762: }
3763:
3764: void preprocessFocusEvent(FocusEvent e) {
3765: processFocusEventImpl(e, focusListeners.getSystemListeners());
3766: }
3767:
3768: protected void processEvent(AWTEvent e) {
3769: long eventMask = toolkit.eventTypeLookup.getEventMask(e);
3770: if (eventMask == AWTEvent.COMPONENT_EVENT_MASK) {
3771: processComponentEvent((ComponentEvent) e);
3772: } else if (eventMask == AWTEvent.FOCUS_EVENT_MASK) {
3773: processFocusEvent((FocusEvent) e);
3774: } else if (eventMask == AWTEvent.KEY_EVENT_MASK) {
3775: processKeyEvent((KeyEvent) e);
3776: } else if (eventMask == AWTEvent.MOUSE_EVENT_MASK) {
3777: processMouseEvent((MouseEvent) e);
3778: } else if (eventMask == AWTEvent.MOUSE_WHEEL_EVENT_MASK) {
3779: processMouseWheelEvent((MouseWheelEvent) e);
3780: } else if (eventMask == AWTEvent.MOUSE_MOTION_EVENT_MASK) {
3781: processMouseMotionEvent((MouseEvent) e);
3782: } else if (eventMask == AWTEvent.HIERARCHY_EVENT_MASK) {
3783: processHierarchyEvent((HierarchyEvent) e);
3784: } else if (eventMask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) {
3785: processHierarchyBoundsEvent((HierarchyEvent) e);
3786: } else if (eventMask == AWTEvent.INPUT_METHOD_EVENT_MASK) {
3787: processInputMethodEvent((InputMethodEvent) e);
3788: }
3789: }
3790:
3791: @SuppressWarnings("unchecked")
3792: public <T extends EventListener> T[] getListeners(
3793: Class<T> listenerType) {
3794: if (ComponentListener.class.isAssignableFrom(listenerType)) {
3795: return (T[]) getComponentListeners();
3796: } else if (FocusListener.class.isAssignableFrom(listenerType)) {
3797: return (T[]) getFocusListeners();
3798: } else if (HierarchyBoundsListener.class
3799: .isAssignableFrom(listenerType)) {
3800: return (T[]) getHierarchyBoundsListeners();
3801: } else if (HierarchyListener.class
3802: .isAssignableFrom(listenerType)) {
3803: return (T[]) getHierarchyListeners();
3804: } else if (InputMethodListener.class
3805: .isAssignableFrom(listenerType)) {
3806: return (T[]) getInputMethodListeners();
3807: } else if (KeyListener.class.isAssignableFrom(listenerType)) {
3808: return (T[]) getKeyListeners();
3809: } else if (MouseWheelListener.class
3810: .isAssignableFrom(listenerType)) {
3811: return (T[]) getMouseWheelListeners();
3812: } else if (MouseMotionListener.class
3813: .isAssignableFrom(listenerType)) {
3814: return (T[]) getMouseMotionListeners();
3815: } else if (MouseListener.class.isAssignableFrom(listenerType)) {
3816: return (T[]) getMouseListeners();
3817: } else if (PropertyChangeListener.class
3818: .isAssignableFrom(listenerType)) {
3819: return (T[]) getPropertyChangeListeners();
3820: }
3821: return (T[]) Array.newInstance(listenerType, 0);
3822: }
3823:
3824: private void processPaintEvent(PaintEvent event) {
3825: if (redrawManager == null || getIgnoreRepaint()) {
3826: return;
3827: }
3828: Rectangle clipRect = event.getUpdateRect();
3829: if ((clipRect.width <= 0) || (clipRect.height <= 0)) {
3830: return;
3831: }
3832: Graphics g = getGraphics();
3833: if (g == null) {
3834: return;
3835: }
3836:
3837: initGraphics(g, event);
3838:
3839: if (event.getID() == PaintEvent.PAINT) {
3840: paint(g);
3841: } else {
3842: update(g);
3843: }
3844: g.dispose();
3845: }
3846:
3847: void initGraphics(Graphics g, PaintEvent e) {
3848: Rectangle clip = e.getUpdateRect();
3849: if (clip instanceof ClipRegion) {
3850: g.setClip(((ClipRegion) clip).getClip());
3851: } else {
3852: g.setClip(clip);
3853: }
3854: if (isPrepainter()) {
3855: prepaint(g);
3856: } else if (!isLightweight() && (e.getID() == PaintEvent.PAINT)) {
3857: g.setColor(getBackground());
3858: g.fillRect(0, 0, w, h);
3859: }
3860: g.setFont(getFont());
3861: g.setColor(getForeground());
3862: }
3863:
3864: protected final void enableEvents(long eventsToEnable) {
3865: toolkit.lockAWT();
3866: try {
3867: enabledEvents |= eventsToEnable;
3868: deprecatedEventHandler = false;
3869: } finally {
3870: toolkit.unlockAWT();
3871: }
3872: }
3873:
3874: private void enableAWTEvents(long eventsToEnable) {
3875: enabledAWTEvents |= eventsToEnable;
3876: }
3877:
3878: protected final void disableEvents(long eventsToDisable) {
3879: toolkit.lockAWT();
3880: try {
3881: enabledEvents &= ~eventsToDisable;
3882: } finally {
3883: toolkit.unlockAWT();
3884: }
3885: }
3886:
3887: /*
3888: * For use in MouseDispatcher only. Really it checks not only mouse events.
3889: */
3890: boolean isMouseEventEnabled(long eventMask) {
3891: return (isEventEnabled(eventMask) || (enabledAWTEvents & eventMask) != 0);
3892: }
3893:
3894: boolean isEventEnabled(long eventMask) {
3895: return ((enabledEvents & eventMask) != 0);
3896: }
3897:
3898: public void enableInputMethods(boolean enable) {
3899: toolkit.lockAWT();
3900: try {
3901: if (!enable) {
3902: removeNotifyInputContext();
3903: }
3904: inputMethodsEnabled = enable;
3905: } finally {
3906: toolkit.unlockAWT();
3907: }
3908: }
3909:
3910: public ComponentListener[] getComponentListeners() {
3911: return componentListeners
3912: .getUserListeners(new ComponentListener[0]);
3913: }
3914:
3915: public void addComponentListener(ComponentListener l) {
3916: componentListeners.addUserListener(l);
3917: }
3918:
3919: public void removeComponentListener(ComponentListener l) {
3920: componentListeners.removeUserListener(l);
3921: }
3922:
3923: protected void processComponentEvent(ComponentEvent e) {
3924: processComponentEventImpl(e, componentListeners
3925: .getUserListeners());
3926: }
3927:
3928: private void processComponentEventImpl(ComponentEvent e,
3929: Collection<ComponentListener> c) {
3930: for (ComponentListener listener : c) {
3931: switch (e.getID()) {
3932: case ComponentEvent.COMPONENT_HIDDEN:
3933: listener.componentHidden(e);
3934: break;
3935: case ComponentEvent.COMPONENT_MOVED:
3936: listener.componentMoved(e);
3937: break;
3938: case ComponentEvent.COMPONENT_RESIZED:
3939: listener.componentResized(e);
3940: break;
3941: case ComponentEvent.COMPONENT_SHOWN:
3942: listener.componentShown(e);
3943: break;
3944: }
3945: }
3946: }
3947:
3948: public FocusListener[] getFocusListeners() {
3949: return focusListeners.getUserListeners(new FocusListener[0]);
3950: }
3951:
3952: public void addFocusListener(FocusListener l) {
3953: focusListeners.addUserListener(l);
3954: }
3955:
3956: void addAWTFocusListener(FocusListener l) {
3957: enableAWTEvents(AWTEvent.FOCUS_EVENT_MASK);
3958: focusListeners.addSystemListener(l);
3959: }
3960:
3961: public void removeFocusListener(FocusListener l) {
3962: focusListeners.removeUserListener(l);
3963: }
3964:
3965: protected void processFocusEvent(FocusEvent e) {
3966: processFocusEventImpl(e, focusListeners.getUserListeners());
3967: }
3968:
3969: private void processFocusEventImpl(FocusEvent e,
3970: Collection<FocusListener> c) {
3971: for (FocusListener listener : c) {
3972: switch (e.getID()) {
3973: case FocusEvent.FOCUS_GAINED:
3974: listener.focusGained(e);
3975: break;
3976: case FocusEvent.FOCUS_LOST:
3977: listener.focusLost(e);
3978: break;
3979: }
3980: }
3981: }
3982:
3983: public HierarchyListener[] getHierarchyListeners() {
3984: return hierarchyListeners
3985: .getUserListeners(new HierarchyListener[0]);
3986: }
3987:
3988: public void addHierarchyListener(HierarchyListener l) {
3989: hierarchyListeners.addUserListener(l);
3990: }
3991:
3992: public void removeHierarchyListener(HierarchyListener l) {
3993: hierarchyListeners.removeUserListener(l);
3994: }
3995:
3996: protected void processHierarchyEvent(HierarchyEvent e) {
3997: for (HierarchyListener listener : hierarchyListeners
3998: .getUserListeners()) {
3999: switch (e.getID()) {
4000: case HierarchyEvent.HIERARCHY_CHANGED:
4001: listener.hierarchyChanged(e);
4002: break;
4003: }
4004: }
4005: }
4006:
4007: public HierarchyBoundsListener[] getHierarchyBoundsListeners() {
4008: return hierarchyBoundsListeners
4009: .getUserListeners(new HierarchyBoundsListener[0]);
4010: }
4011:
4012: public void addHierarchyBoundsListener(HierarchyBoundsListener l) {
4013: hierarchyBoundsListeners.addUserListener(l);
4014: }
4015:
4016: public void removeHierarchyBoundsListener(HierarchyBoundsListener l) {
4017: hierarchyBoundsListeners.removeUserListener(l);
4018: }
4019:
4020: protected void processHierarchyBoundsEvent(HierarchyEvent e) {
4021: for (HierarchyBoundsListener listener : hierarchyBoundsListeners
4022: .getUserListeners()) {
4023: switch (e.getID()) {
4024: case HierarchyEvent.ANCESTOR_MOVED:
4025: listener.ancestorMoved(e);
4026: break;
4027: case HierarchyEvent.ANCESTOR_RESIZED:
4028: listener.ancestorResized(e);
4029: break;
4030: }
4031: }
4032: }
4033:
4034: public KeyListener[] getKeyListeners() {
4035: return keyListeners.getUserListeners(new KeyListener[0]);
4036: }
4037:
4038: public void addKeyListener(KeyListener l) {
4039: keyListeners.addUserListener(l);
4040: }
4041:
4042: void addAWTKeyListener(KeyListener l) {
4043: enableAWTEvents(AWTEvent.KEY_EVENT_MASK);
4044: keyListeners.addSystemListener(l);
4045: }
4046:
4047: public void removeKeyListener(KeyListener l) {
4048: keyListeners.removeUserListener(l);
4049: }
4050:
4051: protected void processKeyEvent(KeyEvent e) {
4052: processKeyEventImpl(e, keyListeners.getUserListeners());
4053: }
4054:
4055: private void processKeyEventImpl(KeyEvent e,
4056: Collection<KeyListener> c) {
4057: for (KeyListener listener : c) {
4058: switch (e.getID()) {
4059: case KeyEvent.KEY_PRESSED:
4060: listener.keyPressed(e);
4061: break;
4062: case KeyEvent.KEY_RELEASED:
4063: listener.keyReleased(e);
4064: break;
4065: case KeyEvent.KEY_TYPED:
4066: listener.keyTyped(e);
4067: break;
4068: }
4069: }
4070: }
4071:
4072: public MouseListener[] getMouseListeners() {
4073: return mouseListeners.getUserListeners(new MouseListener[0]);
4074: }
4075:
4076: public void addMouseListener(MouseListener l) {
4077: mouseListeners.addUserListener(l);
4078: }
4079:
4080: void addAWTMouseListener(MouseListener l) {
4081: enableAWTEvents(AWTEvent.MOUSE_EVENT_MASK);
4082: mouseListeners.addSystemListener(l);
4083: }
4084:
4085: void addAWTMouseMotionListener(MouseMotionListener l) {
4086: enableAWTEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
4087: mouseMotionListeners.addSystemListener(l);
4088: }
4089:
4090: void addAWTComponentListener(ComponentListener l) {
4091: enableAWTEvents(AWTEvent.COMPONENT_EVENT_MASK);
4092: componentListeners.addSystemListener(l);
4093: }
4094:
4095: void addAWTInputMethodListener(InputMethodListener l) {
4096: enableAWTEvents(AWTEvent.INPUT_METHOD_EVENT_MASK);
4097: inputMethodListeners.addSystemListener(l);
4098: }
4099:
4100: void addAWTMouseWheelListener(MouseWheelListener l) {
4101: enableAWTEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
4102: mouseWheelListeners.addSystemListener(l);
4103: }
4104:
4105: public void removeMouseListener(MouseListener l) {
4106: mouseListeners.removeUserListener(l);
4107: }
4108:
4109: protected void processMouseEvent(MouseEvent e) {
4110: processMouseEventImpl(e, mouseListeners.getUserListeners());
4111: }
4112:
4113: private void processMouseEventImpl(MouseEvent e,
4114: Collection<MouseListener> c) {
4115: for (MouseListener listener : c) {
4116: switch (e.getID()) {
4117: case MouseEvent.MOUSE_CLICKED:
4118: listener.mouseClicked(e);
4119: break;
4120: case MouseEvent.MOUSE_ENTERED:
4121: listener.mouseEntered(e);
4122: break;
4123: case MouseEvent.MOUSE_EXITED:
4124: listener.mouseExited(e);
4125: break;
4126: case MouseEvent.MOUSE_PRESSED:
4127: listener.mousePressed(e);
4128: break;
4129: case MouseEvent.MOUSE_RELEASED:
4130: listener.mouseReleased(e);
4131: break;
4132: }
4133: }
4134: }
4135:
4136: private void processMouseMotionEventImpl(MouseEvent e,
4137: Collection<MouseMotionListener> c) {
4138: for (MouseMotionListener listener : c) {
4139: switch (e.getID()) {
4140: case MouseEvent.MOUSE_DRAGGED:
4141: listener.mouseDragged(e);
4142: break;
4143: case MouseEvent.MOUSE_MOVED:
4144: listener.mouseMoved(e);
4145: break;
4146: }
4147: }
4148: }
4149:
4150: public MouseMotionListener[] getMouseMotionListeners() {
4151: return mouseMotionListeners
4152: .getUserListeners(new MouseMotionListener[0]);
4153: }
4154:
4155: public void addMouseMotionListener(MouseMotionListener l) {
4156: mouseMotionListeners.addUserListener(l);
4157: }
4158:
4159: public void removeMouseMotionListener(MouseMotionListener l) {
4160: mouseMotionListeners.removeUserListener(l);
4161: }
4162:
4163: protected void processMouseMotionEvent(MouseEvent e) {
4164: processMouseMotionEventImpl(e, mouseMotionListeners
4165: .getUserListeners());
4166: }
4167:
4168: public MouseWheelListener[] getMouseWheelListeners() {
4169: return mouseWheelListeners
4170: .getUserListeners(new MouseWheelListener[0]);
4171: }
4172:
4173: public void addMouseWheelListener(MouseWheelListener l) {
4174: mouseWheelListeners.addUserListener(l);
4175: }
4176:
4177: public void removeMouseWheelListener(MouseWheelListener l) {
4178: mouseWheelListeners.removeUserListener(l);
4179: }
4180:
4181: protected void processMouseWheelEvent(MouseWheelEvent e) {
4182: processMouseWheelEventImpl(e, mouseWheelListeners
4183: .getUserListeners());
4184: }
4185:
4186: public InputMethodListener[] getInputMethodListeners() {
4187: return inputMethodListeners
4188: .getUserListeners(new InputMethodListener[0]);
4189: }
4190:
4191: public void addInputMethodListener(InputMethodListener l) {
4192: inputMethodListeners.addUserListener(l);
4193: }
4194:
4195: public void removeInputMethodListener(InputMethodListener l) {
4196: inputMethodListeners.removeUserListener(l);
4197: }
4198:
4199: protected void processInputMethodEvent(InputMethodEvent e) {
4200: processInputMethodEventImpl(e, inputMethodListeners
4201: .getUserListeners());
4202: }
4203:
4204: private void processInputMethodEventImpl(InputMethodEvent e,
4205: Collection<InputMethodListener> c) {
4206: for (InputMethodListener listener : c) {
4207: switch (e.getID()) {
4208: case InputMethodEvent.CARET_POSITION_CHANGED:
4209: listener.caretPositionChanged(e);
4210: break;
4211: case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
4212: listener.inputMethodTextChanged(e);
4213: break;
4214: }
4215: }
4216: }
4217:
4218: public Point getMousePosition() throws HeadlessException {
4219: Point absPointerPos = MouseInfo.getPointerInfo().getLocation();
4220: Window winUnderPtr = toolkit.dispatcher.mouseDispatcher
4221: .findWindowAt(absPointerPos);
4222: Point pointerPos = MouseDispatcher.convertPoint(null,
4223: absPointerPos, winUnderPtr);
4224: boolean isUnderPointer = false;
4225: if (winUnderPtr == null) {
4226: return null;
4227: }
4228: isUnderPointer = winUnderPtr.isComponentAt(this , pointerPos);
4229: if (isUnderPointer) {
4230: return MouseDispatcher.convertPoint(null, absPointerPos,
4231: this );
4232: }
4233: return null;
4234: }
4235:
4236: /**
4237: * Set native caret at the given position <br>
4238: * Note: this method takes AWT lock inside because it walks through the
4239: * component hierarchy
4240: */
4241: void setCaretPos(final int x, final int y) {
4242: Runnable r = new Runnable() {
4243: public void run() {
4244: toolkit.lockAWT();
4245: try {
4246: setCaretPosImpl(x, y);
4247: } finally {
4248: toolkit.unlockAWT();
4249: }
4250: }
4251: };
4252: if (Thread.currentThread() instanceof EventDispatchThread) {
4253: r.run();
4254: } else {
4255: toolkit.getSystemEventQueueImpl().postEvent(
4256: new InvocationEvent(this , r));
4257: }
4258: }
4259:
4260: /**
4261: * This method should be called only at event dispatch thread
4262: */
4263: void setCaretPosImpl(int x, int y) {
4264: Component c = this ;
4265: while ((c != null) && c.behaviour.isLightweight()) {
4266: x += c.x;
4267: y += c.y;
4268: c = c.getParent();
4269: }
4270: if (c == null) {
4271: return;
4272: }
4273: if (c instanceof Window) {
4274: Insets insets = c.getNativeInsets();
4275: x -= insets.left;
4276: y -= insets.top;
4277: }
4278: toolkit.getWindowFactory().setCaretPosition(x, y);
4279: }
4280:
4281: // to be overridden in standard components such as Button and List
4282: Dimension getDefaultMinimumSize() {
4283: return null;
4284: }
4285:
4286: // to be overridden in standard components such as Button and List
4287: Dimension getDefaultPreferredSize() {
4288: return null;
4289: }
4290:
4291: // to be overridden in standard components such as Button and List
4292: void resetDefaultSize() {
4293: }
4294:
4295: ComponentBehavior createBehavior() {
4296: return new LWBehavior(this );
4297: }
4298:
4299: Color getDefaultBackground() {
4300: return getWindowAncestor().getDefaultBackground();
4301: }
4302:
4303: Color getDefaultForeground() {
4304: return getWindowAncestor().getDefaultForeground();
4305: }
4306:
4307: /**
4308: * Called when native resource for this component is created (for
4309: * heavyweights only)
4310: */
4311: void nativeWindowCreated(NativeWindow win) {
4312: // to be overridden
4313: }
4314:
4315: /**
4316: * Determine the component's area hidden behind the windows that have higher
4317: * Z-order, including windows of other applications
4318: *
4319: * @param part - the part of the component to determine its hidden area, or
4320: * null for the whole component
4321: * @return the calculated region, or null if it cannot be determined
4322: */
4323: MultiRectArea getObscuredRegion(Rectangle part) {
4324: if (!visible || parent == null || !parent.visible) {
4325: return null;
4326: }
4327: Rectangle r = new Rectangle(0, 0, w, h);
4328: if (part != null) {
4329: r = r.intersection(part);
4330: }
4331: if (r.isEmpty()) {
4332: return null;
4333: }
4334: r.translate(x, y);
4335: MultiRectArea ret = parent.getObscuredRegion(r);
4336: if (ret != null) {
4337: parent.addObscuredRegions(ret, this );
4338: ret.translate(-x, -y);
4339: ret.intersect(new Rectangle(0, 0, w, h));
4340: }
4341: return ret;
4342: }
4343:
4344: private void readObject(ObjectInputStream stream)
4345: throws IOException, ClassNotFoundException {
4346: stream.defaultReadObject();
4347: FieldsAccessor accessor = new FieldsAccessor(Component.class,
4348: this );
4349: accessor.set("toolkit", Toolkit.getDefaultToolkit()); //$NON-NLS-1$
4350: accessor.set("behaviour", createBehavior()); //$NON-NLS-1$
4351: accessor.set("componentLock", new Object()); // $NON-LOCK-1$ //$NON-NLS-1$
4352: }
4353:
4354: final void onDrawImage(Image image, Point destLocation,
4355: Dimension destSize, Rectangle source) {
4356: ImageParameters imageParams;
4357: if (updatedImages == null) {
4358: updatedImages = new HashMap<Image, ImageParameters>();
4359: }
4360: imageParams = updatedImages.get(image);
4361: if (imageParams == null) {
4362: imageParams = new ImageParameters();
4363: updatedImages.put(image, imageParams);
4364: }
4365: imageParams.addDrawing(destLocation, destSize, source);
4366: }
4367:
4368: public boolean imageUpdate(Image img, int infoflags, int x, int y,
4369: int w, int h) {
4370: toolkit.lockAWT();
4371: try {
4372: boolean done = false;
4373: if ((infoflags & (ALLBITS | FRAMEBITS)) != 0) {
4374: done = true;
4375: } else if ((infoflags & SOMEBITS) != 0
4376: && incrementalImageUpdate) {
4377: done = true;
4378: }
4379: if (done) {
4380: repaint();
4381: }
4382: return (infoflags & (ABORT | ALLBITS)) == 0;
4383: } finally {
4384: toolkit.unlockAWT();
4385: }
4386: }
4387:
4388: private void invalidateRealParent() {
4389: Container realParent = getRealParent();
4390: if ((realParent != null) && realParent.isValid()) {
4391: realParent.invalidate();
4392: }
4393: }
4394:
4395: private class ImageParameters {
4396: private final LinkedList<DrawingParameters> drawingParams = new LinkedList<DrawingParameters>();
4397:
4398: Dimension size = new Dimension(Component.this .w,
4399: Component.this .h);
4400:
4401: void addDrawing(Point destLocation, Dimension destSize,
4402: Rectangle source) {
4403: drawingParams.add(new DrawingParameters(destLocation,
4404: destSize, source));
4405: }
4406:
4407: Iterator<DrawingParameters> drawingParametersIterator() {
4408: return drawingParams.iterator();
4409: }
4410:
4411: class DrawingParameters {
4412: Point destLocation;
4413:
4414: Dimension destSize;
4415:
4416: Rectangle source;
4417:
4418: DrawingParameters(Point destLocation, Dimension destSize,
4419: Rectangle source) {
4420: this .destLocation = new Point(destLocation);
4421: if (destSize != null) {
4422: this .destSize = new Dimension(destSize);
4423: } else {
4424: this .destSize = null;
4425: }
4426: if (source != null) {
4427: this .source = new Rectangle(source);
4428: } else {
4429: this .source = null;
4430: }
4431: }
4432: }
4433: }
4434:
4435: /**
4436: * TextComponent support
4437: */
4438: private TextKit textKit = null;
4439:
4440: TextKit getTextKit() {
4441: return textKit;
4442: }
4443:
4444: void setTextKit(TextKit kit) {
4445: textKit = kit;
4446: }
4447:
4448: /**
4449: * TextField support
4450: */
4451: private TextFieldKit textFieldKit = null;
4452:
4453: TextFieldKit getTextFieldKit() {
4454: return textFieldKit;
4455: }
4456:
4457: void setTextFieldKit(TextFieldKit kit) {
4458: textFieldKit = kit;
4459: }
4460:
4461: /**
4462: * Dispatches input & focus events to input method
4463: * context.
4464: * @param e event to pass to InputContext.dispatchEvent()
4465: * @return true if event was consumed by IM, false otherwise
4466: */
4467: private boolean dispatchEventToIM(AWTEvent e) {
4468: InputContext ic = getInputContext();
4469: if (ic == null) {
4470: return false;
4471: }
4472: int id = e.getID();
4473: boolean isInputEvent = ((id >= KeyEvent.KEY_FIRST) && (id <= KeyEvent.KEY_LAST))
4474: || ((id >= MouseEvent.MOUSE_FIRST) && (id <= MouseEvent.MOUSE_LAST));
4475: if (((id >= FocusEvent.FOCUS_FIRST) && (id <= FocusEvent.FOCUS_LAST))
4476: || isInputEvent) {
4477: ic.dispatchEvent(e);
4478: }
4479: return e.isConsumed();
4480: }
4481: }
|