author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 25195 | jdk/src/share/classes/sun/awt/LightweightFrame.java@9de77f5b0df2 |
child 26353 | b5e3b7fbf56d |
permissions | -rw-r--r-- |
15983 | 1 |
/* |
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.awt; |
|
27 |
||
28 |
import java.awt.Container; |
|
29 |
import java.awt.Frame; |
|
30 |
import java.awt.Graphics; |
|
31 |
import java.awt.Image; |
|
32 |
import java.awt.MenuBar; |
|
33 |
import java.awt.MenuComponent; |
|
25195
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
34 |
import java.awt.Rectangle; |
15983 | 35 |
import java.awt.Toolkit; |
36 |
import java.awt.peer.FramePeer; |
|
37 |
||
38 |
/** |
|
39 |
* The class provides basic functionality for a lightweight frame |
|
40 |
* implementation. A subclass is expected to provide painting to an |
|
41 |
* offscreen image and access to it. Thus it can be used for lightweight |
|
42 |
* embedding. |
|
43 |
* |
|
44 |
* @author Artem Ananiev |
|
45 |
* @author Anton Tarasov |
|
46 |
*/ |
|
47 |
@SuppressWarnings("serial") |
|
48 |
public abstract class LightweightFrame extends Frame { |
|
49 |
||
50 |
/** |
|
51 |
* Constructs a new, initially invisible {@code LightweightFrame} |
|
52 |
* instance. |
|
53 |
*/ |
|
54 |
public LightweightFrame() { |
|
55 |
setUndecorated(true); |
|
56 |
setResizable(true); |
|
57 |
setEnabled(true); |
|
58 |
} |
|
59 |
||
60 |
/** |
|
61 |
* Blocks introspection of a parent window by this child. |
|
62 |
* |
|
63 |
* @return null |
|
64 |
*/ |
|
65 |
@Override public final Container getParent() { return null; } |
|
66 |
||
67 |
@Override public Graphics getGraphics() { return null; } |
|
68 |
||
69 |
@Override public final boolean isResizable() { return true; } |
|
70 |
||
71 |
// Block modification of any frame attributes, since they aren't |
|
72 |
// applicable for a lightweight frame. |
|
73 |
||
74 |
@Override public final void setTitle(String title) {} |
|
75 |
@Override public final void setIconImage(Image image) {} |
|
76 |
@Override public final void setIconImages(java.util.List<? extends Image> icons) {} |
|
77 |
@Override public final void setMenuBar(MenuBar mb) {} |
|
78 |
@Override public final void setResizable(boolean resizable) {} |
|
79 |
@Override public final void remove(MenuComponent m) {} |
|
80 |
@Override public final void toFront() {} |
|
81 |
@Override public final void toBack() {} |
|
82 |
||
83 |
@Override public void addNotify() { |
|
84 |
synchronized (getTreeLock()) { |
|
85 |
if (getPeer() == null) { |
|
86 |
SunToolkit stk = (SunToolkit)Toolkit.getDefaultToolkit(); |
|
87 |
try { |
|
88 |
setPeer(stk.createLightweightFrame(this)); |
|
89 |
} catch (Exception e) { |
|
90 |
throw new RuntimeException(e); |
|
91 |
} |
|
92 |
} |
|
93 |
super.addNotify(); |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
private void setPeer(final FramePeer p) { |
|
98 |
AWTAccessor.getComponentAccessor().setPeer(this, p); |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* Requests the peer to emulate activation or deactivation of the |
|
103 |
* frame. Peers should override this method if they are to implement |
|
104 |
* this functionality. |
|
105 |
* |
|
106 |
* @param activate if <code>true</code>, activates the frame; |
|
107 |
* otherwise, deactivates the frame |
|
108 |
*/ |
|
109 |
public void emulateActivation(boolean activate) { |
|
110 |
((FramePeer)getPeer()).emulateActivation(activate); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Delegates the focus grab action to the client (embedding) application. |
|
115 |
* The method is called by the AWT grab machinery. |
|
116 |
* |
|
117 |
* @see SunToolkit#grab(java.awt.Window) |
|
118 |
*/ |
|
119 |
public abstract void grabFocus(); |
|
120 |
||
121 |
/** |
|
122 |
* Delegates the focus ungrab action to the client (embedding) application. |
|
123 |
* The method is called by the AWT grab machinery. |
|
124 |
* |
|
125 |
* @see SunToolkit#ungrab(java.awt.Window) |
|
126 |
*/ |
|
127 |
public abstract void ungrabFocus(); |
|
25195
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
128 |
|
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
129 |
/** |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
130 |
* Returns the scale factor of this frame. The default value is 1. |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
131 |
* |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
132 |
* @return the scale factor |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
133 |
* @see #notifyDisplayChanged(int) |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
134 |
*/ |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
135 |
public abstract int getScaleFactor(); |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
136 |
|
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
137 |
/** |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
138 |
* Called when display of the hosted frame is changed. |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
139 |
* |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
140 |
* @param scaleFactor the scale factor |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
141 |
*/ |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
142 |
public abstract void notifyDisplayChanged(int scaleFactor); |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
143 |
|
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
144 |
/** |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
145 |
* Host window absolute bounds. |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
146 |
*/ |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
147 |
private int hostX, hostY, hostW, hostH; |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
148 |
|
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
149 |
/** |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
150 |
* Returns the absolute bounds of the host (embedding) window. |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
151 |
* |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
152 |
* @return the host window bounds |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
153 |
*/ |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
154 |
public Rectangle getHostBounds() { |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
155 |
if (hostX == 0 && hostY == 0 && hostW == 0 && hostH == 0) { |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
156 |
// The client app is probably unaware of the setHostBounds. |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
157 |
// A safe fall-back: |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
158 |
return getBounds(); |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
159 |
} |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
160 |
return new Rectangle(hostX, hostY, hostW, hostH); |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
161 |
} |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
162 |
|
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
163 |
/** |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
164 |
* Sets the absolute bounds of the host (embedding) window. |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
165 |
*/ |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
166 |
public void setHostBounds(int x, int y, int w, int h) { |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
167 |
hostX = x; |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
168 |
hostY = y; |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
169 |
hostW = w; |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
170 |
hostH = h; |
9de77f5b0df2
8029455: [JLightweightFrame] support scaled painting
serb
parents:
15983
diff
changeset
|
171 |
} |
15983 | 172 |
} |