public interface NativeWindow extends Disposable
NativeWindow
is a top-level native window with a title and a
border.
The size of the native window includes any area designated for the border.
The dimensions of the border area may be obtained using the
getInsets
method, however, since these dimensions are
platform-dependent, a valid insets value cannot be obtained until the native
window is displayed by calling setVisible
. Since the border area
is included in the overall size of the frame, the border effectively obscures
a portion of the frame, constraining the area available for rendering and/or
displaying subcomponents to the rectangle which has an upper-left corner
location of (insets.left, insets.top)
, and has a size of
width - (insets.left + insets.right)
by
height - (insets.top + insets.bottom)
.
A native window may have its native decorations (i.e. Frame
and
Titlebar
) turned off with setUndecorated
. In
contrast to Java AWT frames, this can not only be done while the frame is not
displayed, but regardless or whether the window is displayer or not.
In a virtual device multi-screen environment in which the desktop area could span multiple physical screen devices, the bounds of all configurations are relative to the virtual-coordinate system. The origin of the virtual-coordinate system is at the upper left-hand corner of the primary physical screen. Depending on the location of the primary screen in the virtual device, negative coordinates are possible, as shown in the following figure.
In such an environment, when calling setLocation
, you must pass
a virtual coordinate to this method. Similarly, calling
getLocationOnScreen
on a NativeWindow
returns
virtual device coordinates.
Native windows are capable of generating the following types of
NativeWindowEvent
s:
WINDOW_OPENED
WINDOW_CLOSING
: WINDOW_CLOSED
WINDOW_ICONIFIED
WINDOW_DEICONIFIED
WINDOW_ACTIVATED
WINDOW_DEACTIVATED
WINDOW_GAINED_FOCUS
WINDOW_LOST_FOCUS
WINDOW_STATE_CHANGED
java.awt.Component
,
java.awt.Container
,
java.awt.Window
,
java.awt.Frame
,
java.awt.Component
. The numeric values of these constants are
these defined in java.awt.ComponentEvent
.
WINDOW_MOVED = ComponentEvent.COMPONENT_MOVED
WINDOW_RESIZED = ComponentEvent.COMPONENT_RESIZED
WINDOW_SHOWN = ComponentEvent.COMPONENT_SHOWN
WINDOW_HIDDEN = ComponentEvent.COMPONENT_HIDDEN
A native COM window consists of two distinct parts, which are provided
through two distinct interfaces in COM and two classes in Java. One class is
this abstract GenericNativeWindow
class, which implements the
NativeWindow
interface, and the other class is the actual
descendant of this class. The latter provides the methods that deal with the
capabilities and functions implemented in the native window, the first
deals with the window itself. Since the functional class derives from this
class, it actually provides all the methods available for the native window.
GenericNativeWindow
Modifier and Type | Field and Description |
---|---|
static int |
ICONIFIED
This state bit indicates that the native window is iconified.
|
static int |
MAXIMIZED_BOTH
This state bit mask indicates that the native window is fully maximized
(that is both horizontally and vertically).
|
static int |
MAXIMIZED_HORIZ
This state bit indicates that the native window is maximized in the
horizontal direction.
|
static int |
MAXIMIZED_VERT
This state bit indicates that the native window is maximized in the
vertical direction.
|
static int |
NORMAL
The native window is in the "normal" state.
|
Modifier and Type | Method and Description |
---|---|
void |
addNativeWindowListener(NativeWindowListener listener)
Adds the specified native window listener to receive window events from
the underlying native window.
|
void |
dispose()
Releases the reference to the underlying native window represented by
this
NativeWindow object. |
Color |
getBackground()
Gets the background color of this native window.
|
Rectangle |
getBounds()
Gets the bounds of this native window in the form of a
Rectangle object. |
Rectangle |
getBounds(Rectangle rv)
Stores the bounds of this native window into "return value"
rv and return rv . |
int |
getExtendedState()
Gets the state of this native window.
|
int |
getHeight()
Returns the current height of this native window.
|
Insets |
getInsets()
Determines the insets of this native window, which indicate the size of
the window's border.
|
Point |
getLocation()
Gets the location of this native window in the form of a point specifying
the native window's top-left corner.
|
Point |
getLocation(Point rv)
Stores the x,y origin of this native window into "return value"
rv and return rv . |
Point |
getLocationOnScreen()
Gets the location of this native window in the form of a point specifying
the native window's top-left corner in the screen's coordinate space.
|
String |
getName()
Returns the native name of the window.
|
NativeWindowListener[] |
getNativeWindowListeners()
Returns an array of all the native window listeners registered on this
NativeWindow instance. |
Container |
getParent()
Gets the parent of this component.
|
Dimension |
getSize()
Returns the size of this native window in the form of a
Dimension object. |
Dimension |
getSize(Dimension rv)
Stores the width/height of this native window into "return value"
rv and return rv . |
int |
getState()
Gets the state of this native window (obsolete).
|
String |
getTitle()
Gets the title of this native window.
|
int |
getWidth()
Returns the current width of this native window.
|
int |
getX()
Returns the current x coordinate of the native window's origin.
|
int |
getY()
Returns the current y coordinate of the native window's origin.
|
boolean |
isActive()
Returns whether this native window is active.
|
boolean |
isAlwaysOnTop()
Returns whether this native window is an always-on-top window.
|
boolean |
isDisposed()
Indicates whether the underlying native window is already disposed.
|
boolean |
isEnabled()
Determines whether this native window is enabled.
|
boolean |
isFocused()
Returns whether this native window is focused.
|
boolean |
isNativeWindowListener(NativeWindowListener listener)
Indicates whether the specified native window listener
listener is registered on this NativeWindow
instance. |
boolean |
isResizable()
Indicates whether this native window is resizable by the user.
|
boolean |
isShowing()
Determines whether this component is native window on screen.
|
boolean |
isUndecorated()
Indicates whether this native window is undecorated.
|
boolean |
isVisible()
Indicates whether this native window is visible.
|
void |
removeNativeWindowListener(NativeWindowListener listener)
Removes the specified native window listener, so that it no longer
receives window events from the underlying native window.
|
void |
requestFocus()
Requests that this native window become the focused window.
|
void |
setAlwaysOnTop(boolean alwaysOnTop)
Changes the always-on-top window state of this native window.
|
void |
setBackground(Color c)
Sets the background color of this native window.
|
void |
setBackground(NativeSystemColor c)
Sets the background color of this native window.
|
void |
setBounds(int x,
int y,
int width,
int height)
Moves and resizes this native window.
|
void |
setBounds(Point p,
Dimension d)
Moves and resizes this native window.
|
void |
setBounds(Rectangle r)
Moves and resizes this native window to conform to the new bounding
rectangle
r . |
void |
setEnabled(boolean enabled)
Enables or disables this native window, depending on the value of the
parameter
enabled . |
void |
setExtendedState(int state)
Sets the state of this frame.
|
void |
setLocation(int x,
int y)
Moves this native window to a new location.
|
void |
setLocation(Point p)
Moves this native window to a new location.
|
void |
setResizable(boolean resizable)
Sets whether this native window is resizable by the user.
|
void |
setSize(Dimension d)
Resizes this native window so that it has width
d.width and
height d.height . |
void |
setSize(int width,
int height)
Resizes this native window so that it has width
width and
height height . |
void |
setState(int state)
Sets the state of this native window (obsolete).
|
void |
setTitle(String title)
Sets the title for this native window to the specified string.
|
void |
setUndecorated(boolean undecorated)
Disables or enables decorations for this native window.
|
void |
setVisible(boolean visible)
Shows or hides this native window depending on the value of parameter
visible . |
void |
toBack()
If this native window is visible, sends this native window to the back
and may cause it to lose focus or activation if it is the focused or
active window.
|
void |
toFront()
If this native window is visible, brings this native window to the front
and may make it the focused window.
|
static final int NORMAL
static final int ICONIFIED
static final int MAXIMIZED_HORIZ
static final int MAXIMIZED_VERT
static final int MAXIMIZED_BOTH
MAXIMIZED_VERT | MAXIMIZED_HORIZ
.
Note that the correct test for the native window being fully maximized is
(state & GenericNativeWindow.MAXIMIZED_BOTH) == GenericNativeWindow.MAXIMIZED_BOTH
To test if the native window is maximized in some direction use
(state & GenericNativeWindow.MAXIMIZED_BOTH) != 0
String getName()
String getTitle()
setTitle(java.lang.String)
void setTitle(String title)
title
- the title to be displayed in the window's border. A
null
value is treated as an empty string, "".getTitle()
int getX()
window.getBounds().x
, or
window.getLocation().x
because it doesn't cause any heap
allocations.int getY()
window.getBounds().y
, or
window.getLocation().y
because it doesn't cause any heap
allocations.int getWidth()
window.getBounds().width
, or
window.getSize().width
because it doesn't cause any heap
allocations.int getHeight()
window.getBounds().height
, or
window.getSize().height
because it doesn't cause any heap
allocations.Container getParent()
null
.boolean isShowing()
true
if this native window is showing,
false
otherwisesetVisible(boolean)
boolean isVisible()
true
if this native window is visible,
false
otherwisesetVisible(boolean)
void setVisible(boolean visible)
visible
.visible
- if true
, shows this native window; otherwise,
hides this native windowisVisible()
Rectangle getBounds()
Rectangle
object. The bounds specify this native window's
width, height, and location relative to its parent.setBounds(int, int, int, int)
,
getLocation(java.awt.Point)
,
getSize()
Rectangle getBounds(Rectangle rv)
rv
and return rv
. If rv
is
null
a new Rectangle
is allocated. This version
of getBounds
is useful if the caller wants to avoid
allocating a new Rectangle
object on the heap.rv
- the return value, modified to the native window's boundsvoid setBounds(int x, int y, int width, int height)
x
and y
, and the new
size is specified by width
and height
.x
- the new x-coordinate of this native windowy
- the new y-coordinate of this native windowwidth
- the new width
of this native windowheight
- the new height
of this native windowgetBounds()
,
setLocation(int, int)
,
setLocation(Point)
,
setSize(int, int)
,
setSize(Dimension)
void setBounds(Rectangle r)
r
. This native window's new position is specified
by r.x
and r.y
, and its new size is specified
by r.width
and r.height
r
- the new bounding rectangle for this componentgetBounds()
,
setLocation(int, int)
,
setLocation(Point)
,
setSize(int, int)
,
setSize(Dimension)
void setBounds(Point p, Dimension d)
p.x
and p.y
, and the new
size is specified by d.width
and d.height
.p
- the point defining the top-left corner of the new locationd
- the dimension specifying the new size of this componentgetBounds()
,
setLocation(int, int)
,
setLocation(Point)
,
setSize(int, int)
,
setSize(Dimension)
Point getLocation(Point rv)
rv
and return rv
. If rv
is
null
a new Point
is allocated. This version of
getLocation
is useful if the caller wants to avoid
allocating a new Point
object on the heap.rv
- the return value, modified to the native window's locationPoint getLocation()
Point
representing the top-left
corner of the native window's bounds in the coordinate space of
the native window's parentsetLocation(int, int)
,
getLocationOnScreen()
Point getLocationOnScreen()
Point
representing the top-left
corner of the native window's bounds in the coordinate space of
the screensetLocation(int, int)
,
getLocation(java.awt.Point)
void setLocation(int x, int y)
x
and y
parameters in the coordinate space of this native window's parent.x
- the x-coordinate of the new location's top-left corner
in the parent's coordinate spacey
- the y-coordinate of the new location's top-left corner
in the parent's coordinate spacegetLocation(java.awt.Point)
,
setBounds(int, int, int, int)
void setLocation(Point p)
p
. Point p
is given in the parent's coordinate space.p
- the point defining the top-left corner of the new location,
given in the coordinate space of this native window's parentgetLocation(java.awt.Point)
,
setBounds(int, int, int, int)
Dimension getSize()
Dimension
object. The height
field of the
Dimension
object contains this native window's height, and
the width
field of the Dimension
object
contains this native window's width.Dimension
object that indicates the size of this
native windowsetSize(int, int)
Dimension getSize(Dimension rv)
rv
and return rv
. If rv
is
null
a new Dimension
object is allocated. This
version of getSize
is useful if the caller wants to avoid
allocating a new Dimension
object on the heap.rv
- the return value, modified to the native window's sizevoid setSize(int width, int height)
width
and
height height
.width
- the new width of this native window in pixelsheight
- the new height of this native window in pixelsgetSize()
,
setBounds(int, int, int, int)
void setSize(Dimension d)
d.width
and
height d.height
.d
- the dimension specifying the new size of this native windowsetSize(int, int)
,
setBounds(int, int, int, int)
boolean isEnabled()
setEnabled
method.true
if the native window is enabled;
false
otherwisesetEnabled(boolean)
void setEnabled(boolean enabled)
enabled
. An enabled native window can respond to
user input and generate events. Native windows are enabled initially by
default.enabled
- if true
, this native window is enabled; otherwise
this native window is disabledisEnabled()
Color getBackground()
setBackground(java.awt.Color)
void setBackground(Color c)
c
- the color to become this native window's color; if this
parameter is null
, then this native window will
get the operation system's default window background colorgetBackground()
void setBackground(NativeSystemColor c)
c
- the color to become this native window's color; if this
parameter is null
, then this native window will
get the operation system's default window background colorgetBackground()
int getExtendedState()
NORMAL
ICONIFIED
MAXIMIZED_HORIZ
MAXIMIZED_VERT
MAXIMIZED_BOTH
MAXIMIZED_HORIZ
and MAXIMIZED_VERT
.
setExtendedState(int)
void setExtendedState(int state)
NORMAL
ICONIFIED
MAXIMIZED_HORIZ
MAXIMIZED_VERT
MAXIMIZED_BOTH
MAXIMIZED_HORIZ
and MAXIMIZED_VERT
.
Note that if the state is not supported on a given platform, nothing will
happen. The application may determine if a specific state is available
via the java.awt.Toolkit#isFrameStateSupported(int state)
method.
state
- a bitwise mask of frame state constantsgetExtendedState()
,
Toolkit.isFrameStateSupported(int)
int getState()
For compatibility with old programs this method still returns
GenericNativeWindow.NORMAL
and
GenericNativeWindow.ICONIFIED
but it only reports the iconic
state of the native window, other aspects of native window state are not
reported by this method.
GenericNativeWindow.NORMAL
or
GenericNativeWindow.ICONIFIED
.setState(int)
,
getExtendedState()
void setState(int state)
For compatibility with old programs this method still accepts
GenericNativeWindow.NORMAL
and
GenericNativeWindow.ICONIFIED
but it only changes the iconic
state of the native window, other aspects of native window state are not
affected by this method.
state
- either GenericNativeWindow.NORMAL
or
GenericNativeWindow.ICONIFIED
.getState()
,
setExtendedState(int)
boolean isAlwaysOnTop()
true
, if this native window is in always-on-top
state, false
otherwisesetAlwaysOnTop(boolean)
void setAlwaysOnTop(boolean alwaysOnTop)
If some other window already is always-on-top then the relative order between these windows is unspecified (depends on platform). No window can be brought to be over always-on-top window except maybe another always-on-top window.
This method makes this native window always-on-top if
alwaysOnTop
is true
. If the window is visible,
this includes bringing window toFront
, then "sticking" it to
the top-most position. If the window is not visible it does nothing other
than setting the always-on-top property. If later the window is shown, it
will be always-on-top. If the window is already always-on-top, this call
does nothing.
If alwaysOnTop
is false
this method changes the
state from always-on-top to normal. The window remains top-most but its
z-order can be changed in the normal way as for any other window. Does
nothing if this window is not always-on-top. Has no effect on relative
z-order of windows if there are no other always-on-top windows.
alwaysOnTop
- new value of always-on-top state of the native windowisAlwaysOnTop()
,
toFront()
,
toBack()
void toBack()
Places this native window at the bottom of the stacking order and shows it behind any other windows in this VM. No action will take place if this window is not visible.
toFront()
void toFront()
Places this native window at the top of the stacking order and shows it in front of any other windows in this VM. No action will take place if this window is not visible.
toBack()
void requestFocus()
boolean isActive()
true
, if this native window is currently active,
false
otherwiseisFocused()
boolean isFocused()
The focused native window is also the active native window.
true
, if this native window is currently the focused
window, false
otherwiseisActive()
boolean isUndecorated()
true
if native window is undecorated;
false
otherwise.setUndecorated(boolean)
void setUndecorated(boolean undecorated)
undecorated
- true
if no frame decorations are to be enabled;
false
if frame decorations are to be enabled.isUndecorated()
boolean isResizable()
true
if the user can resize this native window;
false
otherwise.setResizable(boolean)
void setResizable(boolean resizable)
resizable
- true
if this native window is resizable;
false
otherwise.isResizable()
Insets getInsets()
A NativeWindow
object, for example, has a top inset that
corresponds to the height of the window's title bar.
Insets
void addNativeWindowListener(NativeWindowListener listener)
listener
is
null
, no exception is thrown and no action is performed.listener
- the native window listener to be addedremoveNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
getNativeWindowListeners()
,
NativeWindowListener
,
NativeWindowAdapter
void removeNativeWindowListener(NativeWindowListener listener)
null
or was not
previously added to this NativeWindow
instance.listener
- the native window listener to be removedaddNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
getNativeWindowListeners()
,
NativeWindowListener
,
NativeWindowAdapter
NativeWindowListener[] getNativeWindowListeners()
NativeWindow
instance.NativeWindowListener
s or
an empty array if no native window listeners are currently
registeredaddNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
removeNativeWindowListener(com.datagis.com4j.NativeWindowListener)
boolean isNativeWindowListener(NativeWindowListener listener)
listener
is registered on this NativeWindow
instance.listener
- the native window listener to testtrue
if the specified native window listener
listener
is registered with this
NativeWindow
instance; false
otherwise.addNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
removeNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
getNativeWindowListeners()
void dispose()
NativeWindow
object. Although, dispose
can
be called on a COM object multiple times, regardless whether the object
is already disposed, method isDisposed
may be used to
determine, whether an object is disposed or not.
Since Java objects tend to live longer in memory until they are garbage collected, and applications have generally no control over when this happens, calling the dispose method at any time enables applications to dispose the underlying native windows deterministically.
After having disposed a native window, one has no longer access to the
window's methods nor will any events be delivered to any event listener
that still may be registered. Accessing methods of a disposed native
window will throw an IllegalStateException
.
dispose
in interface Disposable
isDisposed()
boolean isDisposed()
0
as its hash code value. So, this method could
easily be replaced by:
return (this.hashCode() != 0);
true
if the underlying COM object is disposed;
false
otherwiseCopyright © 2009 - 2016 DataGis. All Rights Reserved.