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