1 /* ComponentPeer.java -- Toplevel component peer
2 Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
39 package java
.awt
.peer
;
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
;
49 import java
.awt
.FontMetrics
;
50 import java
.awt
.Graphics
;
51 import java
.awt
.GraphicsConfiguration
;
52 import java
.awt
.Image
;
53 import java
.awt
.Point
;
54 import java
.awt
.Rectangle
;
55 import java
.awt
.Toolkit
;
56 import java
.awt
.event
.PaintEvent
;
57 import java
.awt
.image
.ColorModel
;
58 import java
.awt
.image
.ImageObserver
;
59 import java
.awt
.image
.ImageProducer
;
60 import java
.awt
.image
.VolatileImage
;
63 * Defines the methods that a component peer is required to implement.
65 public interface ComponentPeer
68 * Returns the construction status of the specified image. This is called
69 * by {@link Component#checkImage(Image, int, int, ImageObserver)}.
71 * @param img the image
72 * @param width the width of the image
73 * @param height the height of the image
74 * @param ob the image observer to be notified of updates of the status
76 * @return a bitwise ORed set of ImageObserver flags
78 int checkImage(Image img
, int width
, int height
,
82 * Creates an image by starting the specified image producer. This is called
83 * by {@link Component#createImage(ImageProducer)}.
85 * @param prod the image producer to be used to create the image
87 * @return the created image
89 Image
createImage(ImageProducer prod
);
92 * Creates an empty image with the specified <code>width</code> and
93 * <code>height</code>.
95 * @param width the width of the image to be created
96 * @param height the height of the image to be created
98 * @return the created image
100 Image
createImage(int width
, int height
);
103 * Disables the component. This is called by {@link Component#disable()}.
108 * Disposes the component peer. This should release all resources held by the
109 * peer. This is called when the component is no longer in use.
114 * Enables the component. This is called by {@link Component#enable()}.
119 * Returns the color model of the component. This is currently not used.
121 * @return the color model of the component
123 ColorModel
getColorModel();
126 * Returns the font metrics for the specified font. This is called by
127 * {@link Component#getFontMetrics(Font)}.
129 * @param f the font for which to query the font metrics
131 * @return the font metrics for the specified font
133 FontMetrics
getFontMetrics(Font f
);
136 * Returns a {@link Graphics} object suitable for drawing on this component.
137 * This is called by {@link Component#getGraphics()}.
139 * @return a graphics object suitable for drawing on this component
141 Graphics
getGraphics();
144 * Returns the location of this component in screen coordinates. This is
145 * called by {@link Component#getLocationOnScreen()}.
147 * @return the location of this component in screen coordinates
149 Point
getLocationOnScreen();
152 * Returns the minimum size for the component. This is called by
153 * {@link Component#getMinimumSize()}.
155 * @return the minimum size for the component
157 Dimension
getMinimumSize();
160 * Returns the preferred size for the component. This is called by
161 * {@link Component#getPreferredSize()}.
163 * @return the preferred size for the component
165 Dimension
getPreferredSize();
168 * Returns the toolkit that created this peer.
170 * @return the toolkit that created this peer
172 Toolkit
getToolkit();
175 * Handles the given event. This is called from
176 * {@link Component#dispatchEvent(AWTEvent)} to give the peer a chance to
177 * react to events for the component.
181 void handleEvent(AWTEvent e
);
184 * Makes the component invisible. This is called from
185 * {@link Component#hide()}.
190 * Returns <code>true</code> if the component can receive keyboard input
191 * focus. This is called from {@link Component#isFocusTraversable()}.
193 * @specnote Part of the earlier 1.1 API, replaced by isFocusable().
195 boolean isFocusTraversable();
198 * Returns <code>true</code> if the component can receive keyboard input
199 * focus. This is called from {@link Component#isFocusable()}.
201 boolean isFocusable();
204 * Returns the minimum size for the component. This is called by
205 * {@link Component#minimumSize()}.
207 * @return the minimum size for the component
209 Dimension
minimumSize();
212 * Returns the preferred size for the component. This is called by
213 * {@link Component#getPreferredSize()}.
215 * @return the preferred size for the component
217 Dimension
preferredSize();
219 void paint(Graphics graphics
);
222 * Prepares an image for rendering on this component. This is called by
223 * {@link Component#prepareImage(Image, int, int, ImageObserver)}.
225 * @param img the image to prepare
226 * @param width the desired width of the rendered image
227 * @param height the desired height of the rendered image
228 * @param ob the image observer to be notified of updates in the preparation
231 * @return <code>true</code> if the image has been fully prepared,
232 * <code>false</code> otherwise (in which case the image observer
235 boolean prepareImage(Image img
, int width
, int height
,
238 void print(Graphics graphics
);
241 * Repaints the specified rectangle of this component. This is called from
242 * {@link Component#repaint(long, int, int, int, int)}.
244 * @param tm number of milliseconds to wait with repainting
245 * @param x the X coordinate of the upper left corner of the damaged rectangle
246 * @param y the Y coordinate of the upper left corner of the damaged rectangle
247 * @param width the width of the damaged rectangle
248 * @param height the height of the damaged rectangle
250 void repaint(long tm
, int x
, int y
, int width
, int height
);
253 * Requests that this component receives the focus. This is called from
254 * {@link Component#requestFocus()}.
256 * @specnote Part of the earlier 1.1 API, apparently replaced by argument
257 * form of the same method.
262 * Requests that this component receives the focus. This is called from
263 * {@link Component#requestFocus()}.
270 boolean requestFocus(Component source
, boolean bool1
, boolean bool2
, long x
);
273 * Notifies the peer that the bounds of this component have changed. This
274 * is called by {@link Component#reshape(int, int, int, int)}.
276 * @param x the X coordinate of the upper left corner of the component
277 * @param y the Y coordinate of the upper left corner of the component
278 * @param width the width of the component
279 * @param height the height of the component
281 void reshape(int x
, int y
, int width
, int height
);
284 * Sets the background color of the component. This is called by
285 * {@link Component#setBackground(Color)}.
287 * @param color the background color to set
289 void setBackground(Color color
);
292 * Notifies the peer that the bounds of this component have changed. This
293 * is called by {@link Component#setBounds(int, int, int, int)}.
295 * @param x the X coordinate of the upper left corner of the component
296 * @param y the Y coordinate of the upper left corner of the component
297 * @param width the width of the component
298 * @param height the height of the component
300 void setBounds(int x
, int y
, int width
, int height
);
303 * Sets the cursor of the component. This is called by
304 * {@link Component#setCursor(Cursor)}.
306 * @specnote Part of the earlier 1.1 API, apparently no longer needed.
308 void setCursor(Cursor cursor
);
311 * Sets the enabled/disabled state of this component. This is called by
312 * {@link Component#setEnabled(boolean)}.
314 * @param enabled <code>true</code> to enable the component,
315 * <code>false</code> to disable it
317 void setEnabled(boolean enabled
);
320 * Sets the font of the component. This is called by
321 * {@link Component#setFont(Font)}.
323 * @param font the font to set
325 void setFont(Font font
);
328 * Sets the foreground color of the component. This is called by
329 * {@link Component#setForeground(Color)}.
331 * @param color the foreground color to set
333 void setForeground(Color color
);
336 * Sets the visibility state of the component. This is called by
337 * {@link Component#setVisible(boolean)}.
339 * @param visible <code>true</code> to make the component visible,
340 * <code>false</code> to make it invisible
342 void setVisible(boolean visible
);
345 * Makes the component visible. This is called by {@link Component#show()}.
350 * Get the graphics configuration of the component. The color model
351 * of the component can be derived from the configuration.
353 * @return the graphics configuration of the component
355 GraphicsConfiguration
getGraphicsConfiguration();
358 * Part of an older API, no longer needed.
360 void setEventMask(long mask
);
363 * Returns <code>true</code> if this component has been obscured,
364 * <code>false</code> otherwise. This will only work if
365 * {@link #canDetermineObscurity()} also returns <code>true</code>.
367 * @return <code>true</code> if this component has been obscured,
368 * <code>false</code> otherwise.
370 boolean isObscured();
373 * Returns <code>true</code> if this component peer can determine if the
374 * component has been obscured, <code>false</code> otherwise.
376 * @return <code>true</code> if this component peer can determine if the
377 * component has been obscured, <code>false</code> otherwise
379 boolean canDetermineObscurity();
382 * Coalesces the specified paint event.
384 * @param e the paint event
386 void coalescePaintEvent(PaintEvent e
);
389 * Updates the cursor.
391 void updateCursorImmediately();
394 * Returns true, if this component can handle wheel scrolling,
395 * <code>false</code> otherwise.
397 * @return true, if this component can handle wheel scrolling,
398 * <code>false</code> otherwise
400 boolean handlesWheelScrolling();
403 * A convenience method that creates a volatile image. The volatile
404 * image is created on the screen device on which this component is
405 * displayed, in the device's current graphics configuration.
407 * @param width width of the image
408 * @param height height of the image
414 VolatileImage
createVolatileImage(int width
, int height
);
417 * Create a number of image buffers that implement a buffering
418 * strategy according to the given capabilities.
420 * @param numBuffers the number of buffers
421 * @param caps the buffering capabilities
423 * @throws AWTException if the specified buffering strategy is not
428 void createBuffers(int numBuffers
, BufferCapabilities caps
)
432 * Return the back buffer of this component.
434 * @return the back buffer of this component.
438 Image
getBackBuffer();
441 * Perform a page flip, leaving the contents of the back buffer in
442 * the specified state.
444 * @param contents the state in which to leave the back buffer
448 void flip(BufferCapabilities
.FlipContents contents
);
451 * Destroy the resources created by createBuffers.
455 void destroyBuffers();
458 * Get the bounds of this component peer.
460 * @return component peer bounds
463 Rectangle
getBounds();
466 * Reparent this component under another container.
471 void reparent(ContainerPeer parent
);
474 * Set the bounds of this component peer.
476 * @param x the new x co-ordinate
477 * @param y the new y co-ordinate
478 * @param width the new width
479 * @param height the new height
480 * @param z the new stacking level
483 void setBounds (int x
, int y
, int width
, int height
, int z
);
486 * Check if this component supports being reparented.
488 * @return true if this component can be reparented,
492 boolean isReparentSupported();
495 * Layout this component peer.