1 /* GLightweightPeer.java --
2    Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
3 
4 This file is part of GNU Classpath.
5 
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10 
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20 
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25 
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37 
38 
39 package gnu.java.awt.peer;
40 
41 import java.awt.AWTEvent;
42 import java.awt.AWTException;
43 import java.awt.BufferCapabilities;
44 import java.awt.Color;
45 import java.awt.Component;
46 import java.awt.Cursor;
47 import java.awt.Dimension;
48 import java.awt.Font;
49 import java.awt.FontMetrics;
50 import java.awt.Graphics;
51 import java.awt.GraphicsConfiguration;
52 import java.awt.Image;
53 import java.awt.Insets;
54 import java.awt.Point;
55 import java.awt.Rectangle;
56 import java.awt.Toolkit;
57 import java.awt.event.PaintEvent;
58 import java.awt.image.ColorModel;
59 import java.awt.image.ImageObserver;
60 import java.awt.image.ImageProducer;
61 import java.awt.image.VolatileImage;
62 import java.awt.peer.ContainerPeer;
63 import java.awt.peer.LightweightPeer;
64 
65 /**
66  * A stub class that implements the ComponentPeer and ContainerPeer
67  * interfaces using callbacks into the Component and Container
68  * classes.  GLightweightPeer allows the Component and Container
69  * classes to treat lightweight and heavyweight peers in the same way.
70  *
71  * Lightweight components are painted directly onto their parent
72  * containers through an Image object provided by the toolkit.
73  */
74 public class GLightweightPeer
75   implements LightweightPeer, ContainerPeer
76 {
GLightweightPeer()77   public GLightweightPeer()
78   {
79     // Nothing to do here.
80   }
81 
82   // -------- java.awt.peer.ContainerPeer implementation:
83 
insets()84   public Insets insets()
85   {
86     // Nothing to do here for lightweights.
87     return null;
88   }
89 
getInsets()90   public Insets getInsets()
91   {
92     // Nothing to do here for lightweights.
93     return null;
94   }
95 
beginValidate()96   public void beginValidate()
97   {
98     // Nothing to do here for lightweights.
99   }
100 
endValidate()101   public void endValidate()
102   {
103     // Nothing to do here for lightweights.
104   }
105 
beginLayout()106   public void beginLayout()
107   {
108     // Nothing to do here for lightweights.
109   }
110 
endLayout()111   public void endLayout()
112   {
113     // Nothing to do here for lightweights.
114   }
115 
isPaintPending()116   public boolean isPaintPending()
117   {
118     // Nothing to do here for lightweights.
119     return false;
120   }
121 
122   // -------- java.awt.peer.ComponentPeer implementation:
123 
checkImage(Image img, int width, int height, ImageObserver o)124   public int checkImage(Image img, int width, int height, ImageObserver o)
125   {
126     // Nothing to do here for lightweights.
127     return -1;
128   }
129 
createImage(ImageProducer prod)130   public Image createImage(ImageProducer prod)
131   {
132     // Nothing to do here for lightweights.
133     return null;
134   }
135 
136   /* This method is not called. */
createImage(int width, int height)137   public Image createImage(int width, int height)
138   {
139     // Nothing to do here for lightweights.
140     return null;
141   }
142 
disable()143   public void disable()
144   {
145     // Nothing to do here for lightweights.
146   }
147 
dispose()148   public void dispose()
149   {
150     // Nothing to do here for lightweights.
151   }
152 
enable()153   public void enable()
154   {
155     // Nothing to do here for lightweights.
156   }
157 
getGraphicsConfiguration()158   public GraphicsConfiguration getGraphicsConfiguration()
159   {
160     // Nothing to do here for lightweights.
161     return null;
162   }
163 
getFontMetrics(Font f)164   public FontMetrics getFontMetrics(Font f)
165   {
166     // We shouldn't end up here, but if we do we can still try do something
167     // reasonable.
168     Toolkit tk = Toolkit.getDefaultToolkit();
169     return tk.getFontMetrics(f);
170   }
171 
172   /* Returning null here tells the Component object that called us to
173    * use its parent's Graphics. */
getGraphics()174   public Graphics getGraphics()
175   {
176     // Nothing to do here for lightweights.
177     return null;
178   }
179 
getLocationOnScreen()180   public Point getLocationOnScreen()
181   {
182     // Nothing to do here for lightweights.
183     return null;
184   }
185 
getMinimumSize()186   public Dimension getMinimumSize()
187   {
188     return minimumSize();
189   }
190 
getPreferredSize()191   public Dimension getPreferredSize()
192   {
193     return preferredSize();
194   }
195 
196   /* Returning null here tells the Component object that called us to
197    * use its parent's Toolkit. */
getToolkit()198   public Toolkit getToolkit()
199   {
200     // Nothing to do here for lightweights.
201     return null;
202   }
203 
handleEvent(AWTEvent e)204   public void handleEvent(AWTEvent e)
205   {
206     // This can only happen when an application posts a PaintEvent for
207     // a lightweight component directly. We still support painting for
208     // this case.
209     if (e instanceof PaintEvent)
210       {
211         PaintEvent pe = (PaintEvent) e;
212         Component target = (Component) e.getSource();
213         if (target != null && target.isShowing())
214           {
215             Graphics g = target.getGraphics();
216             if (g != null)
217               {
218                 try
219                   {
220                     Rectangle clip = pe.getUpdateRect();
221                     g.setClip(clip);
222                     target.paint(g);
223                   }
224                 finally
225                   {
226                     g.dispose();
227                   }
228               }
229           }
230       }
231   }
232 
hide()233   public void hide()
234   {
235     // Nothing to do here for lightweights.
236   }
237 
isFocusable()238   public boolean isFocusable()
239   {
240     // Nothing to do here for lightweights.
241     return false;
242   }
243 
isFocusTraversable()244   public boolean isFocusTraversable()
245   {
246     // Nothing to do here for lightweights.
247     return false;
248   }
249 
minimumSize()250   public Dimension minimumSize()
251   {
252     return new Dimension(0, 0);
253   }
254 
preferredSize()255   public Dimension preferredSize()
256   {
257     return new Dimension(0, 0);
258   }
259 
paint(Graphics graphics)260   public void paint(Graphics graphics)
261   {
262     // Nothing to do here for lightweights.
263   }
264 
prepareImage(Image img, int width, int height, ImageObserver o)265   public boolean prepareImage(Image img, int width, int height,
266                               ImageObserver o)
267   {
268     // Nothing to do here for lightweights.
269     return false;
270   }
271 
print(Graphics graphics)272   public void print(Graphics graphics)
273   {
274     // Nothing to do here for lightweights.
275   }
276 
repaint(long tm, int x, int y, int width, int height)277   public void repaint(long tm, int x, int y, int width, int height)
278   {
279     // Nothing to do here for lightweights.
280   }
281 
requestFocus()282   public void requestFocus()
283   {
284     // Nothing to do here for lightweights.
285   }
286 
requestFocus(Component source, boolean bool1, boolean bool2, long x)287   public boolean requestFocus(Component source, boolean bool1, boolean bool2,
288                               long x)
289   {
290     // Nothing to do here for lightweights.
291     return false;
292   }
293 
reshape(int x, int y, int width, int height)294   public void reshape(int x, int y, int width, int height)
295   {
296     // Nothing to do here for lightweights.
297   }
298 
setBackground(Color color)299   public void setBackground(Color color)
300   {
301     // Nothing to do here for lightweights.
302   }
303 
setBounds(int x, int y, int width, int height)304   public void setBounds(int x, int y, int width, int height)
305   {
306     // Nothing to do here for lightweights.
307   }
308 
309   /**
310    * Sets the cursor on the heavy-weight parent peer.
311    * Called by the MouseListener on mouse enter.
312    */
setCursor(Cursor cursor)313   public void setCursor(Cursor cursor)
314   {
315     // Nothing to do here for lightweights.
316   }
317 
setEnabled(boolean enabled)318   public void setEnabled(boolean enabled)
319   {
320     // Nothing to do here for lightweights.
321   }
322 
setEventMask(long eventMask)323   public void setEventMask(long eventMask)
324   {
325     // Nothing to do here for lightweights.
326   }
327 
setFont(Font font)328   public void setFont(Font font)
329   {
330     // Nothing to do here for lightweights.
331   }
332 
setForeground(Color color)333   public void setForeground(Color color)
334   {
335     // Nothing to do here for lightweights.
336   }
337 
setVisible(boolean visible)338   public void setVisible(boolean visible)
339   {
340     // Nothing to do here for lightweights.
341   }
342 
show()343   public void show()
344   {
345     // Nothing to do here for lightweights.
346   }
347 
getColorModel()348   public ColorModel getColorModel()
349   {
350     // Nothing to do here for lightweights.
351     return null;
352   }
353 
isObscured()354   public boolean isObscured()
355   {
356     // Nothing to do here for lightweights.
357     return false;
358   }
359 
canDetermineObscurity()360   public boolean canDetermineObscurity()
361   {
362     // Nothing to do here for lightweights.
363     return false;
364   }
365 
coalescePaintEvent(PaintEvent e)366   public void coalescePaintEvent(PaintEvent e)
367   {
368     // Nothing to do here for lightweights.
369   }
370 
updateCursorImmediately()371   public void updateCursorImmediately()
372   {
373     // Nothing to do here for lightweights.
374   }
375 
createVolatileImage(int width, int height)376   public VolatileImage createVolatileImage(int width, int height)
377   {
378     // Nothing to do here for lightweights.
379     return null;
380   }
381 
handlesWheelScrolling()382   public boolean handlesWheelScrolling()
383   {
384     // Nothing to do here for lightweights.
385     return false;
386   }
387 
createBuffers(int x, BufferCapabilities capabilities)388   public void createBuffers(int x, BufferCapabilities capabilities)
389     throws AWTException
390   {
391     // Nothing to do here for lightweights.
392   }
393 
getBackBuffer()394   public Image getBackBuffer()
395   {
396     // Nothing to do here for lightweights.
397     return null;
398   }
399 
flip(BufferCapabilities.FlipContents contents)400   public void flip(BufferCapabilities.FlipContents contents)
401   {
402     // Nothing to do here for lightweights.
403   }
404 
destroyBuffers()405   public void destroyBuffers()
406   {
407     // Nothing to do here for lightweights.
408   }
409 
isRestackSupported()410   public boolean isRestackSupported()
411   {
412     // Nothing to do here for lightweights.
413     return false;
414   }
415 
cancelPendingPaint(int x, int y, int width, int height)416   public void cancelPendingPaint(int x, int y, int width, int height)
417   {
418     // Nothing to do here for lightweights.
419   }
420 
restack()421   public void restack()
422   {
423     // Nothing to do here for lightweights.
424   }
425 
getBounds()426   public Rectangle getBounds()
427   {
428     // Nothing to do here for lightweights.
429     return null;
430   }
431 
reparent(ContainerPeer parent)432   public void reparent(ContainerPeer parent)
433   {
434     // Nothing to do here for lightweights.
435   }
436 
setBounds(int x, int y, int z, int width, int height)437   public void setBounds(int x, int y, int z, int width, int height)
438   {
439     // Nothing to do here for lightweights.
440   }
441 
isReparentSupported()442   public boolean isReparentSupported()
443   {
444     // Nothing to do here for lightweights.
445     return true;
446   }
447 
layout()448   public void layout()
449   {
450     // Nothing to do here for lightweights.
451   }
452 
requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time, sun.awt.CausedFocusEvent.Cause cause)453   public boolean requestFocus(Component lightweightChild, boolean temporary,
454                               boolean focusedWindowChangeAllowed,
455                               long time, sun.awt.CausedFocusEvent.Cause cause)
456   {
457     // Always grant focus request.
458     return true;
459   }
460 
461 }
462