001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry A. Durnev
019: * @version $Revision$
020: *
021: */package java.awt;
022:
023: import org.apache.harmony.awt.wtk.NativeWindow;
024:
025: /**
026: * Heavyweight component specific behaviour
027: */
028:
029: class HWBehavior implements ComponentBehavior {
030:
031: private final Component component;
032: private NativeWindow nativeWindow;
033:
034: HWBehavior(Component comp) {
035: component = comp;
036: Toolkit.checkHeadless();
037: // implicitly disable IM for all heavyweight components
038: // TextComponents must set this flag back to true
039: component.dispatchToIM = false;
040: }
041:
042: public boolean isOpaque() {
043: // heavyweights are always opaque
044: return true;
045: }
046:
047: public boolean isLightweight() {
048: return false;
049: }
050:
051: public void setVisible(boolean b) {
052: if (nativeWindow != null) {
053: nativeWindow.setVisible(b);
054: }
055: }
056:
057: public NativeWindow getNativeWindow() {
058: return nativeWindow;
059: }
060:
061: public void addNotify() {
062: nativeWindow = createNativeWindow();
063: nativeWindow.setVisible(component.isVisible());
064: updateFocus();
065: }
066:
067: protected NativeWindow createNativeWindow() {
068: return component.toolkit.createNativeWindow(component);
069: }
070:
071: private void updateFocus() {
072: if (component.isShowing()) {
073: Window wnd = component.getWindowAncestor();
074: if ((wnd == null) || (!wnd.isFocused() && !wnd.isActive())) {
075: return;
076: }
077:
078: KeyboardFocusManager.getCurrentKeyboardFocusManager()
079: .requestFocusInWindow(wnd, true);
080: }
081: }
082:
083: public Graphics getGraphics(int translationX, int translationY,
084: int width, int height) {
085:
086: return component.toolkit.getGraphicsFactory()
087: .getGraphics2D(nativeWindow, translationX,
088: translationY, width, height);
089: }
090:
091: public void setBounds(int x, int y, int w, int h, int bMask) {
092: if (nativeWindow != null) {
093: Point loc = new Point(x, y);
094: if (!(component instanceof Window)) {
095: Component parent = component.getHWAncestor();
096: loc = MouseDispatcher.convertPoint(component, 0, 0,
097: parent);
098: }
099:
100: nativeWindow.setBounds(loc.x, loc.y, w, h, bMask);
101:
102: }
103: }
104:
105: public boolean isDisplayable() {
106: return (nativeWindow != null);
107: }
108:
109: public void setEnabled(boolean value) {
110: if (nativeWindow != null) {
111: nativeWindow.setEnabled(value);
112: }
113: }
114:
115: public void removeNotify() {
116: if (nativeWindow == null) {
117: return;
118: }
119: component.toolkit.removeNativeWindow(nativeWindow);
120: NativeWindow temp = nativeWindow;
121: nativeWindow = null;
122:
123: if (!(component instanceof Window)) {
124: // dispose only if HW ancestor is not disposed already
125: Component hwAncestor = component.getHWAncestor();
126: if ((hwAncestor == null) || !hwAncestor.isDisplayable()) {
127: return;
128: }
129: }
130: temp.dispose();
131:
132: }
133:
134: public void onMove(int x, int y) {
135: setBounds(component.x, component.y, component.w, component.h,
136: NativeWindow.BOUNDS_NOSIZE);
137:
138: }
139:
140: public void setZOrder(int newIndex, int oldIndex) {
141: NativeWindow win = null;
142: Container par = component.getParent();
143: if (par != null) {
144: int size = par.getComponentCount();
145: for (int i = Math.min(newIndex - 1, size - 1); i >= 0; i--) {
146: Component comp = par.getComponent(i);
147: if (!comp.isLightweight() && comp.isDisplayable()) {
148: win = comp.getNativeWindow();
149: break;
150: }
151: }
152: }
153: if (nativeWindow != null) {
154: nativeWindow.placeAfter(win);
155: }
156: }
157:
158: public boolean setFocus(boolean focus, Component opposite) {
159: if (nativeWindow != null) {
160: return nativeWindow.setFocus(focus);
161: }
162: return false;
163: }
164: }
|