T
- E
- public abstract class GenericNativeWindow<T extends com4j.Com4jObject,E extends ComEventListener> extends ComEventObject<T> implements NativeWindow
GenericNativeWindow
is a top-level native window with a title
and a border. This class implements the NativeWindow
interface.
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
Since a native window somehow combines the features, which are provided though the distinct Java objects
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.
This class fully implements the NativeWindow
interface, which
does'nt make use of the generic parameters T
and E
.
Using the NativeWindow
interface wherever possible, is highly
recommended.
NativeWindow
Modifier and Type | Class and Description |
---|---|
protected class |
GenericNativeWindow.EventInvocationCache
This
HashMap derived class provides a fast mapping mechanism
between the name of an event method invoked on the native event interface
and the corresponding method to be invoked on a registered
NativeWindowListener together with its event id. |
protected class |
GenericNativeWindow.EventInvocationItem
Represents an item stored in the event invocation cache
EventInvocationCache . |
protected class |
GenericNativeWindow.NativeWindowEventDispatcher
The class
NativeWindowEventDispatcher implements a custom
layer to handle native window events as defined in
NativeWindowListener . |
Modifier and Type | Field and Description |
---|---|
protected NativeSystemColor |
DEFAULT_BACKGROUND_COLOR
The default background color of a native window represented as a
NativeSystemColor enum constant. |
events
ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, NORMAL
Modifier | Constructor and Description |
---|---|
protected |
GenericNativeWindow(T base,
Class<E> eventInterface)
Constructs a new
GenericNativeWindow object by using the COM
object's proxy class specified. |
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
GenericNativeWindow 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
GenericNativeWindow 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 |
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
GenericNativeWindow 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.
|
addComEventListener, comEventListeners, getComEventListeners, isComEventListener, removeComEventListener
clone, equals, hashCode, isDisposed, isInstanceOf, referenceEquals, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
isDisposed
protected final NativeSystemColor DEFAULT_BACKGROUND_COLOR
NativeSystemColor
enum constant.protected GenericNativeWindow(T base, Class<E> eventInterface)
GenericNativeWindow
object by using the COM
object's proxy class specified.base
- the native COM object's proxy classeventInterface
- the native COM interface, that implements the window event
methods for this native windowpublic String getName()
getName
in interface NativeWindow
public String getTitle()
getTitle
in interface NativeWindow
setTitle(java.lang.String)
public void setTitle(String title)
setTitle
in interface NativeWindow
title
- the title to be displayed in the window's border. A
null
value is treated as an empty string, "".getTitle()
public int getX()
window.getBounds().x
, or
window.getLocation().x
because it doesn't cause any heap
allocations.getX
in interface NativeWindow
public int getY()
window.getBounds().y
, or
window.getLocation().y
because it doesn't cause any heap
allocations.getY
in interface NativeWindow
public int getWidth()
window.getBounds().width
, or
window.getSize().width
because it doesn't cause any heap
allocations.getWidth
in interface NativeWindow
public int getHeight()
window.getBounds().height
, or
window.getSize().height
because it doesn't cause any heap
allocations.getHeight
in interface NativeWindow
public Container getParent()
null
.getParent
in interface NativeWindow
public boolean isShowing()
isShowing
in interface NativeWindow
true
if this native window is showing,
false
otherwisesetVisible(boolean)
public boolean isVisible()
isVisible
in interface NativeWindow
true
if this native window is visible,
false
otherwisesetVisible(boolean)
public void setVisible(boolean visible)
visible
.setVisible
in interface NativeWindow
visible
- if true
, shows this native window; otherwise,
hides this native windowisVisible()
public Rectangle getBounds()
Rectangle
object. The bounds specify this native window's
width, height, and location relative to its parent.getBounds
in interface NativeWindow
setBounds(int, int, int, int)
,
getLocation(java.awt.Point)
,
getSize()
public 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.getBounds
in interface NativeWindow
rv
- the return value, modified to the native window's boundspublic void setBounds(int x, int y, int width, int height)
x
and y
, and the new
size is specified by width
and height
.setBounds
in interface NativeWindow
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)
public 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
setBounds
in interface NativeWindow
r
- the new bounding rectangle for this componentgetBounds()
,
setLocation(int, int)
,
setLocation(Point)
,
setSize(int, int)
,
setSize(Dimension)
public void setBounds(Point p, Dimension d)
p.x
and p.y
, and the new
size is specified by d.width
and d.height
.setBounds
in interface NativeWindow
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)
public 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.getLocation
in interface NativeWindow
rv
- the return value, modified to the native window's locationpublic Point getLocation()
getLocation
in interface NativeWindow
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()
public Point getLocationOnScreen()
getLocationOnScreen
in interface NativeWindow
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)
public void setLocation(int x, int y)
x
and y
parameters in the coordinate space of this native window's parent.setLocation
in interface NativeWindow
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)
public void setLocation(Point p)
p
. Point p
is given in the parent's coordinate space.setLocation
in interface NativeWindow
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)
public 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.getSize
in interface NativeWindow
Dimension
object that indicates the size of this
native windowsetSize(int, int)
public 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.getSize
in interface NativeWindow
rv
- the return value, modified to the native window's sizepublic void setSize(int width, int height)
width
and
height height
.setSize
in interface NativeWindow
width
- the new width of this native window in pixelsheight
- the new height of this native window in pixelsgetSize()
,
setBounds(int, int, int, int)
public void setSize(Dimension d)
d.width
and
height d.height
.setSize
in interface NativeWindow
d
- the dimension specifying the new size of this native windowsetSize(int, int)
,
setBounds(int, int, int, int)
public boolean isEnabled()
setEnabled
method.isEnabled
in interface NativeWindow
true
if the native window is enabled;
false
otherwisesetEnabled(boolean)
public void setEnabled(boolean enabled)
enabled
. An enabled native window can respond to
user input and generate events. Native windows are enabled initially by
default.setEnabled
in interface NativeWindow
enabled
- if true
, this native window is enabled; otherwise
this native window is disabledisEnabled()
public Color getBackground()
getBackground
in interface NativeWindow
setBackground(java.awt.Color)
public void setBackground(Color c)
setBackground
in interface NativeWindow
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()
public void setBackground(NativeSystemColor c)
setBackground
in interface NativeWindow
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()
public int getExtendedState()
NORMAL
ICONIFIED
MAXIMIZED_HORIZ
MAXIMIZED_VERT
MAXIMIZED_BOTH
MAXIMIZED_HORIZ
and MAXIMIZED_VERT
.
getExtendedState
in interface NativeWindow
setExtendedState(int)
public 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.
setExtendedState
in interface NativeWindow
state
- a bitwise mask of frame state constantsgetExtendedState()
,
Toolkit.isFrameStateSupported(int)
public int getState()
For compatibility with old programs this method still returns
NativeWindow.NORMAL
and NativeWindow.ICONIFIED
but it only reports the iconic state of the native window, other aspects
of native window state are not reported by this method.
getState
in interface NativeWindow
NativeWindow.NORMAL
or
NativeWindow.ICONIFIED
.setState(int)
,
getExtendedState()
public void setState(int state)
For compatibility with old programs this method still accepts
NativeWindow.NORMAL
and NativeWindow.ICONIFIED
but it only changes the iconic state of the native window, other aspects
of native window state are not affected by this method.
setState
in interface NativeWindow
state
- either NativeWindow.NORMAL
or
NativeWindow.ICONIFIED
.getState()
,
setExtendedState(int)
public boolean isAlwaysOnTop()
isAlwaysOnTop
in interface NativeWindow
true
, if this native window is in always-on-top
state, false
otherwisesetAlwaysOnTop(boolean)
public 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.
setAlwaysOnTop
in interface NativeWindow
alwaysOnTop
- new value of always-on-top state of the native windowisAlwaysOnTop()
,
toFront()
,
toBack()
public 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.
toBack
in interface NativeWindow
toFront()
public 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.
toFront
in interface NativeWindow
toBack()
public void requestFocus()
requestFocus
in interface NativeWindow
public boolean isActive()
isActive
in interface NativeWindow
true
, if this native window is currently active,
false
otherwiseisFocused()
public boolean isFocused()
The focused native window is also the active native window.
isFocused
in interface NativeWindow
true
, if this native window is currently the focused
window, false
otherwiseisActive()
public boolean isUndecorated()
isUndecorated
in interface NativeWindow
true
if native window is undecorated;
false
otherwise.setUndecorated(boolean)
public void setUndecorated(boolean undecorated)
setUndecorated
in interface NativeWindow
undecorated
- true
if no frame decorations are to be enabled;
false
if frame decorations are to be enabled.isUndecorated()
public boolean isResizable()
isResizable
in interface NativeWindow
true
if the user can resize this native window;
false
otherwise.setResizable(boolean)
public void setResizable(boolean resizable)
setResizable
in interface NativeWindow
resizable
- true
if this native window is resizable;
false
otherwise.isResizable()
public Insets getInsets()
A NativeWindow
object, for example, has a top inset that
corresponds to the height of the window's title bar.
getInsets
in interface NativeWindow
Insets
public void addNativeWindowListener(NativeWindowListener listener)
listener
is
null
, no exception is thrown and no action is performed.addNativeWindowListener
in interface NativeWindow
listener
- the native window listener to be addedremoveNativeWindowListener(NativeWindowListener)
,
getNativeWindowListeners()
,
NativeWindowListener
,
NativeWindowAdapter
public void removeNativeWindowListener(NativeWindowListener listener)
null
or was not
previously added to this GenericNativeWindow
instance.removeNativeWindowListener
in interface NativeWindow
listener
- the native window listener to be removedaddNativeWindowListener(NativeWindowListener)
,
getNativeWindowListeners()
,
NativeWindowListener
,
NativeWindowAdapter
public NativeWindowListener[] getNativeWindowListeners()
GenericNativeWindow
instance.getNativeWindowListeners
in interface NativeWindow
NativeWindowListener
s or
an empty array if no native window listeners are currently
registeredaddNativeWindowListener(NativeWindowListener)
,
removeNativeWindowListener(NativeWindowListener)
public boolean isNativeWindowListener(NativeWindowListener listener)
listener
is registered on this
GenericNativeWindow
instance.isNativeWindowListener
in interface NativeWindow
listener
- the native window listener to testtrue
if the specified native window listener
listener
is registered with this
GenericNativeWindow
instance; false
otherwise.addNativeWindowListener(NativeWindowListener)
,
removeNativeWindowListener(NativeWindowListener)
,
getNativeWindowListeners()
public void dispose()
GenericNativeWindow
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
dispose
in interface NativeWindow
dispose
in class ComEventObject<T extends com4j.Com4jObject>
ComObject.isDisposed()
Copyright © 2009 - 2016 DataGis. All Rights Reserved.