1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58:
59: import ;
60: import ;
61: import ;
62:
63: import ;
64: import ;
65: import ;
66:
67: public class XWindowPeer
68: extends SwingWindowPeer
69: {
70:
71: private static int standardSelect = Event.BUTTON_PRESS_MASK
72: | Event.BUTTON_RELEASE_MASK
73: | Event.POINTER_MOTION_MASK
74:
75: | Event.EXPOSURE_MASK
76: | Event.PROPERTY_CHANGE_MASK
77:
78:
79: | Event.KEY_PRESS_MASK
80: | Event.KEY_RELEASE_MASK
81:
82: ;
83:
84:
87: protected Window xwindow;
88:
89:
92: private Insets insets;
93:
94: XWindowPeer(java.awt.Window window)
95: {
96: super(window);
97: XGraphicsDevice dev = XToolkit.getDefaultDevice();
98:
99:
100: Window.Attributes atts = new Window.Attributes();
101:
102: int x = Math.max(window.getX(), 0);
103: int y = Math.max(window.getY(), 0);
104: int w = Math.max(window.getWidth(), 1);
105: int h = Math.max(window.getHeight(), 1);
106: xwindow = new Window(dev.getDisplay().default_root, x, y, w, h, 0, atts);
107: xwindow.select_input(standardSelect);
108:
109: dev.getEventPump().registerWindow(xwindow, window);
110: xwindow.set_wm_delete_window();
111:
112: boolean undecorated;
113: if (awtComponent instanceof Frame)
114: {
115: Frame f = (Frame) awtComponent;
116: undecorated = f.isUndecorated();
117: }
118: else if (awtComponent instanceof Dialog)
119: {
120: Dialog d = (Dialog) awtComponent;
121: undecorated = d.isUndecorated();
122: }
123: else
124: {
125: undecorated = true;
126: }
127: if (undecorated)
128: {
129:
130:
131:
132:
133:
134:
135: Atom at = Atom.intern(dev.getDisplay(), "_MOTIF_WM_HINTS");
136: if (at != null)
137: {
138: xwindow.change_property(Window.REPLACE, at, at, 32,
139: new int[]{1 << 1, 0, 0, 0, 0}, 0, 5);
140: }
141: }
142: insets = new Insets(0, 0, 0, 0);
143: }
144:
145: public void toBack()
146: {
147:
148:
149: }
150:
151: public void toFront()
152: {
153:
154:
155: }
156:
157: public void updateAlwaysOnTop()
158: {
159:
160:
161: }
162:
163: public boolean requestWindowFocus()
164: {
165:
166: return false;
167: }
168:
169: public Point getLocationOnScreen()
170: {
171: return new Point(xwindow.x, xwindow.y);
172: }
173:
174:
179: public Graphics getGraphics()
180: {
181: XGraphics2D xg2d = new XGraphics2D(xwindow);
182: xg2d.setColor(awtComponent.getForeground());
183: xg2d.setBackground(awtComponent.getBackground());
184: xg2d.setFont(awtComponent.getFont());
185: return xg2d;
186: }
187:
188: public Image createImage(int w, int h)
189: {
190:
191: return createVolatileImage(w, h);
192: }
193:
194: @Override
195: public VolatileImage createVolatileImage(int width, int height)
196: {
197: GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
198: GraphicsDevice gd = ge.getDefaultScreenDevice();
199: GraphicsConfiguration gc = gd.getDefaultConfiguration();
200: return gc.createCompatibleVolatileImage(width, height);
201: }
202:
203:
208: public void show()
209: {
210:
211:
212:
213:
214: XGraphicsDevice dev = XToolkit.getDefaultDevice();
215: xwindow.map();
216: EventQueue eq = XToolkit.getDefaultToolkit().getSystemEventQueue();
217: java.awt.Window w = (java.awt.Window) super.awtComponent;
218: eq.postEvent(new WindowEvent(w, WindowEvent.WINDOW_OPENED));
219: eq.postEvent(new PaintEvent(w, PaintEvent.PAINT,
220: new Rectangle(0, 0, w.getWidth(),
221: w.getHeight())));
222:
223: Graphics g = getGraphics();
224: g.clearRect(0, 0, awtComponent.getWidth(), awtComponent.getHeight());
225: g.dispose();
226:
227:
228:
229:
230:
231: Atom atom = (Atom) Atom.intern(dev.getDisplay(), "_NET_FRAME_EXTENTS");
232: Window.Property p = xwindow.get_property(false, atom, Atom.CARDINAL, 0,
233: Window.MAX_WM_LENGTH);
234: if (p.format() != 0)
235: {
236: insets = new Insets(p.value(0), p.value(1), p.value(2), p.value(3));
237: Window.Changes ch = new Window.Changes();
238: ch.width(awtComponent.getWidth() - insets.left - insets.top);
239: ch.height(awtComponent.getHeight() - insets.top - insets.bottom);
240: xwindow.configure(ch);
241: }
242:
243: }
244:
245:
251: public void hide()
252: {
253: xwindow.unmap();
254: }
255:
256:
267: public void reshape(int x, int y, int width, int height)
268: {
269: Insets i = insets;
270: xwindow.move_resize(x - i.left, y - i.right, width - i.left - i.right,
271: height - i.top - i.bottom);
272: }
273:
274: public Insets insets()
275: {
276: return (Insets) insets.clone();
277: }
278:
279:
284: public FontMetrics getFontMetrics(Font font)
285: {
286: ClasspathFontPeer fontPeer = (ClasspathFontPeer) font.getPeer();
287: return fontPeer.getFontMetrics(font);
288: }
289:
290:
293: protected void finalize()
294: {
295: XGraphicsDevice dev = XToolkit.getDefaultDevice();
296: dev.getEventPump().unregisterWindow(xwindow);
297: }
298:
299: public Window getXwindow()
300: {
301: return xwindow;
302: }
303: }