Source for gnu.java.awt.peer.GLightweightPeer

   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.MouseAdapter;
  58: import java.awt.event.MouseEvent;
  59: import java.awt.event.PaintEvent;
  60: import java.awt.image.ColorModel;
  61: import java.awt.image.ImageObserver;
  62: import java.awt.image.ImageProducer;
  63: import java.awt.image.VolatileImage;
  64: import java.awt.peer.ComponentPeer;
  65: import java.awt.peer.ContainerPeer;
  66: import java.awt.peer.LightweightPeer;
  67: 
  68: /*
  69:  * Another possible implementation strategy for lightweight peers is
  70:  * to make GLightweightPeer a placeholder class that implements
  71:  * LightweightPeer.  Then the Component and Container classes could
  72:  * identify a peer as lightweight and handle it specially.  The
  73:  * current approach is probably more clear but less efficient.
  74:  */
  75: 
  76: /**
  77:  * A stub class that implements the ComponentPeer and ContainerPeer
  78:  * interfaces using callbacks into the Component and Container
  79:  * classes.  GLightweightPeer allows the Component and Container
  80:  * classes to treat lightweight and heavyweight peers in the same way.
  81:  *
  82:  * Lightweight components are painted directly onto their parent
  83:  * containers through an Image object provided by the toolkit.
  84:  */
  85: public class GLightweightPeer 
  86:   implements LightweightPeer, ContainerPeer
  87: {
  88:   private Component comp;
  89: 
  90:   private Insets containerInsets;
  91: 
  92:   public GLightweightPeer(Component comp)
  93:   {
  94:     this.comp = comp;
  95:   }
  96: 
  97:   // -------- java.awt.peer.ContainerPeer implementation:
  98:   
  99:   public Insets insets()
 100:   {
 101:     return getInsets ();
 102:   }
 103:   
 104:   public Insets getInsets()
 105:   {
 106:     if (containerInsets == null)
 107:       containerInsets = new Insets (0,0,0,0);
 108:     return containerInsets;
 109:   }
 110:   
 111:   public void beginValidate()
 112:   {
 113:   }
 114:   
 115:   public void endValidate()
 116:   {
 117:   }
 118:   
 119:   public void beginLayout()
 120:   {
 121:   }
 122:   
 123:   public void endLayout()
 124:   {
 125:   }
 126:   
 127:   public boolean isPaintPending()
 128:   {
 129:     return false;
 130:   }
 131: 
 132:   // -------- java.awt.peer.ComponentPeer implementation:
 133: 
 134:   public int checkImage(Image img, int width, int height, ImageObserver o)
 135:   {
 136:     return comp.getToolkit().checkImage(img, width, height, o);
 137:   }
 138: 
 139:   public Image createImage(ImageProducer prod)
 140:   {
 141:     return comp.getToolkit().createImage(prod);
 142:   }
 143: 
 144:   /* This method is not called. */
 145:   public Image createImage(int width, int height)
 146:   {
 147:     return null;
 148:   }
 149: 
 150:   public void disable() {}
 151: 
 152:   public void dispose() {}
 153: 
 154:   public void enable() {}
 155: 
 156:   public GraphicsConfiguration getGraphicsConfiguration()
 157:   {
 158:     return null;
 159:   }
 160: 
 161:   public FontMetrics getFontMetrics(Font f)
 162:   {
 163:     return comp.getToolkit().getFontMetrics(f);
 164:   }
 165: 
 166:   /* Returning null here tells the Component object that called us to
 167:    * use its parent's Graphics. */
 168:   public Graphics getGraphics()
 169:   {
 170:     return null;
 171:   }
 172: 
 173:   public Point getLocationOnScreen()
 174:   {
 175:     Point parentLocation = comp.getParent().getLocationOnScreen();
 176:     return new Point (parentLocation.x + comp.getX(),
 177:                       parentLocation.y + comp.getY());
 178:   }
 179: 
 180:   public Dimension getMinimumSize()
 181:   {
 182:     return new Dimension(comp.getWidth(), comp.getHeight());
 183:   }
 184: 
 185:   /* A lightweight component's preferred size is equivalent to its
 186:    * Component width and height values. */
 187:   public Dimension getPreferredSize()
 188:   {
 189:     return new Dimension(comp.getWidth(), comp.getHeight());
 190:   }
 191: 
 192:   /* Returning null here tells the Component object that called us to
 193:    * use its parent's Toolkit. */
 194:   public Toolkit getToolkit()
 195:   {
 196:     return null;
 197:   }
 198: 
 199:   public void handleEvent(AWTEvent e) {}
 200: 
 201:   public void hide() {}
 202: 
 203:   public boolean isFocusable() 
 204:   {
 205:     return false;
 206:   }
 207: 
 208:   public boolean isFocusTraversable()
 209:   {
 210:     return false;
 211:   }
 212: 
 213:   public Dimension minimumSize()
 214:   {
 215:     return getMinimumSize();
 216:   }
 217: 
 218:   public Dimension preferredSize()
 219:   {
 220:     return getPreferredSize();
 221:   }
 222: 
 223:   public void paint(Graphics graphics) {}
 224: 
 225:   public boolean prepareImage(Image img, int width, int height,
 226:                   ImageObserver o)
 227:   {
 228:     return comp.getToolkit().prepareImage(img, width, height, o);
 229:   }
 230: 
 231:   public void print(Graphics graphics) {}
 232: 
 233:   public void repaint(long tm, int x, int y, int width, int height)
 234:   {
 235:     Component p = comp.getParent();
 236:     if (p != null)
 237:       p.repaint(tm, x + comp.getX(), y + comp.getY(), width, height);
 238:   }
 239: 
 240:   public void requestFocus() {}
 241: 
 242:   public boolean requestFocus(Component source, boolean bool1, boolean bool2, long x)
 243:   {
 244:     return false;
 245:   }
 246: 
 247:   public void reshape(int x, int y, int width, int height) {}
 248: 
 249:   public void setBackground(Color color) {}
 250: 
 251:   public void setBounds(int x, int y, int width, int height) {}
 252: 
 253:   /**
 254:    * Sets the cursor on the heavy-weight parent peer.
 255:    * Called by the MouseListener on mouse enter.
 256:    */
 257:   public void setCursor(Cursor cursor)
 258:   {
 259:     Component p = comp.getParent();
 260:     while (p != null && p.isLightweight())
 261:       p = p.getParent();
 262: 
 263:     if (p != null)
 264:       {
 265:     // Don't actually change the cursor of the component
 266:     // otherwise other childs inherit this cursor.
 267:     ComponentPeer peer = p.getPeer();
 268:     if (peer != null)
 269:       peer.setCursor(cursor);
 270:       }
 271:   }
 272: 
 273:   public void setEnabled(boolean enabled) {}
 274: 
 275:   public void setEventMask(long eventMask) {}
 276: 
 277:   public void setFont(Font font) {}
 278: 
 279:   public void setForeground(Color color) {}
 280: 
 281:   public void setVisible(boolean visible) {}
 282: 
 283:   public void show() {}
 284: 
 285:   public ColorModel getColorModel ()
 286:   {
 287:     return comp.getColorModel ();
 288:   }
 289: 
 290:   public boolean isObscured()
 291:   {
 292:     return false;
 293:   }
 294: 
 295:   public boolean canDetermineObscurity()
 296:   {
 297:     return false;
 298:   }
 299: 
 300:   public void coalescePaintEvent(PaintEvent e) { }
 301: 
 302:   public void updateCursorImmediately() { }
 303: 
 304:   public VolatileImage createVolatileImage(int width, int height) 
 305:   { 
 306:     return null; 
 307:   }
 308: 
 309:   public boolean handlesWheelScrolling()
 310:   {
 311:     return false;
 312:   }
 313: 
 314:   public void createBuffers(int x, BufferCapabilities capabilities) 
 315:     throws AWTException { }
 316: 
 317:   public Image getBackBuffer()
 318:   {
 319:     return null;
 320:   }
 321: 
 322:   public void flip(BufferCapabilities.FlipContents contents) { }
 323: 
 324:   public void destroyBuffers() { }
 325: 
 326:   public boolean isRestackSupported()
 327:   {
 328:     return false;
 329:   }
 330: 
 331:   public void cancelPendingPaint(int x, int y, int width, int height)
 332:   {
 333:     
 334:   }
 335: 
 336:   public void restack()
 337:   {
 338:     
 339:   }
 340: 
 341:   public Rectangle getBounds()
 342:   {
 343:     return null;
 344:   }
 345: 
 346:   public void reparent(ContainerPeer parent)
 347:   {
 348:     
 349:   }
 350: 
 351:   public void setBounds(int x, int y, int z, int width, int height)
 352:   {
 353:     
 354:   }
 355: 
 356:   public boolean isReparentSupported()
 357:   {
 358:     return false;
 359:   }
 360: 
 361:   public void layout()
 362:   {
 363:     
 364:   }
 365: }