1 /* 2 * Copyright (c) 2000, 2016, 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.AWTException; 29 import java.awt.BufferCapabilities; 30 import java.awt.Color; 31 import java.awt.Component; 32 import java.awt.Cursor; 33 import java.awt.Dimension; 34 import java.awt.Font; 35 import java.awt.FontMetrics; 36 import java.awt.Graphics; 37 import java.awt.GraphicsConfiguration; 38 import java.awt.Image; 39 import java.awt.Insets; 40 import java.awt.event.FocusEvent.Cause; 41 import java.awt.Point; 42 import java.awt.Event; 43 import java.awt.event.PaintEvent; 44 import java.awt.image.ColorModel; 45 import java.awt.image.ImageObserver; 46 import java.awt.image.ImageProducer; 47 import java.awt.image.VolatileImage; 48 import java.awt.peer.CanvasPeer; 49 import java.awt.peer.LightweightPeer; 50 import java.awt.peer.PanelPeer; 51 import java.awt.peer.ComponentPeer; 52 import java.awt.peer.ContainerPeer; 53 import java.awt.Rectangle; 54 import sun.java2d.pipe.Region; 55 56 57 /** 58 * Implements the LightweightPeer interface for use in lightweight components 59 * that have no native window associated with them. This gets created by 60 * default in Component so that Component and Container can be directly 61 * extended to create useful components written entirely in java. These 62 * components must be hosted somewhere higher up in the component tree by a 63 * native container (such as a Frame). 64 * 65 * This implementation provides no useful semantics and serves only as a 66 * marker. One could provide alternative implementations in java that do 67 * something useful for some of the other peer interfaces to minimize the 68 * native code. 69 * 70 * This was renamed from java.awt.LightweightPeer (a horrible and confusing 71 * name) and moved from java.awt.Toolkit into sun.awt as a public class in 72 * its own file. 73 * 74 * @author Timothy Prinzing 75 * @author Michael Martak 76 */ 77 78 public class NullComponentPeer implements LightweightPeer, 79 CanvasPeer, PanelPeer { 80 81 public boolean isObscured() { 82 return false; 83 } 84 85 public boolean canDetermineObscurity() { 86 return false; 87 } 88 89 public boolean isFocusable() { 90 return false; 91 } 92 93 public void setVisible(boolean b) { 94 } 95 96 public void show() { 97 } 98 99 public void hide() { 100 } 101 102 public void setEnabled(boolean b) { 103 } 104 105 public void enable() { 106 } 107 108 public void disable() { 109 } 110 111 public void paint(Graphics g) { 112 } 113 114 public void repaint(long tm, int x, int y, int width, int height) { 115 } 116 117 public void print(Graphics g) { 118 } 119 120 public void setBounds(int x, int y, int width, int height, int op) { 121 } 122 123 public void reshape(int x, int y, int width, int height) { 124 } 125 126 public void coalescePaintEvent(PaintEvent e) { 127 } 128 129 @SuppressWarnings("deprecation") 130 public boolean handleEvent(Event e) { 131 return false; 132 } 133 134 public void handleEvent(java.awt.AWTEvent arg0) { 135 } 136 137 public Dimension getPreferredSize() { 138 return new Dimension(1,1); 139 } 140 141 public Dimension getMinimumSize() { 142 return new Dimension(1,1); 143 } 144 145 public ColorModel getColorModel() { 146 return null; 147 } 148 149 public Graphics getGraphics() { 150 return null; 151 } 152 153 public GraphicsConfiguration getGraphicsConfiguration() { 154 return null; 155 } 156 157 public FontMetrics getFontMetrics(Font font) { 158 return null; 159 } 160 161 public void dispose() { 162 // no native code 163 } 164 165 public void setForeground(Color c) { 166 } 167 168 public void setBackground(Color c) { 169 } 170 171 public void setFont(Font f) { 172 } 173 174 public void updateCursorImmediately() { 175 } 176 177 public void setCursor(Cursor cursor) { 178 } 179 180 public boolean requestFocus 181 (Component lightweightChild, boolean temporary, 182 boolean focusedWindowChangeAllowed, long time, Cause cause) { 183 return false; 184 } 185 186 public Image createImage(ImageProducer producer) { 187 return null; 188 } 189 190 public Image createImage(int width, int height) { 191 return null; 192 } 193 194 public boolean prepareImage(Image img, int w, int h, ImageObserver o) { 195 return false; 196 } 197 198 public int checkImage(Image img, int w, int h, ImageObserver o) { 199 return 0; 200 } 201 202 public Dimension preferredSize() { 203 return getPreferredSize(); 204 } 205 206 public Dimension minimumSize() { 207 return getMinimumSize(); 208 } 209 210 public Point getLocationOnScreen() { 211 return new Point(0,0); 212 } 213 214 public Insets getInsets() { 215 return insets(); 216 } 217 218 public void beginValidate() { 219 } 220 221 public void endValidate() { 222 } 223 224 public Insets insets() { 225 return new Insets(0, 0, 0, 0); 226 } 227 228 public boolean isPaintPending() { 229 return false; 230 } 231 232 public boolean handlesWheelScrolling() { 233 return false; 234 } 235 236 public VolatileImage createVolatileImage(int width, int height) { 237 return null; 238 } 239 240 public void beginLayout() { 241 } 242 243 public void endLayout() { 244 } 245 246 public void createBuffers(int numBuffers, BufferCapabilities caps) 247 throws AWTException { 248 throw new AWTException( 249 "Page-flipping is not allowed on a lightweight component"); 250 } 251 public Image getBackBuffer() { 252 throw new IllegalStateException( 253 "Page-flipping is not allowed on a lightweight component"); 254 } 255 public void flip(int x1, int y1, int x2, int y2, 256 BufferCapabilities.FlipContents flipAction) 257 { 258 throw new IllegalStateException( 259 "Page-flipping is not allowed on a lightweight component"); 260 } 261 public void destroyBuffers() { 262 } 263 264 /** 265 * @see java.awt.peer.ComponentPeer#isReparentSupported 266 */ 267 public boolean isReparentSupported() { 268 return false; 269 } 270 271 /** 272 * @see java.awt.peer.ComponentPeer#reparent 273 */ 274 public void reparent(ContainerPeer newNativeParent) { 275 throw new UnsupportedOperationException(); 276 } 277 278 public void layout() { 279 } 280 281 public Rectangle getBounds() { 282 return new Rectangle(0, 0, 0, 0); 283 } 284 285 286 /** 287 * Applies the shape to the native component window. 288 * @since 1.7 289 */ 290 public void applyShape(Region shape) { 291 } 292 293 /** 294 * Lowers this component at the bottom of the above HW peer. If the above parameter 295 * is null then the method places this component at the top of the Z-order. 296 */ 297 public void setZOrder(ComponentPeer above) { 298 } 299 300 public boolean updateGraphicsData(GraphicsConfiguration gc) { 301 return false; 302 } 303 304 public GraphicsConfiguration getAppropriateGraphicsConfiguration( 305 GraphicsConfiguration gc) 306 { 307 return gc; 308 } 309 }