ch.aplu.util
Class GWindow

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by ch.aplu.util.GWindow
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class GWindow
extends javax.swing.JFrame

Simple screen window with an event handler to exit the application when clicking the close button in the title bar.
The exit handler will call the dispose method for the graphic context in order to release system resources automatically. Defaut background is white, default drawing color is black.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JFrame
EXIT_ON_CLOSE
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GWindow()
          Construct a GWindow with default title and size.
GWindow(Position position, Size size, boolean noTitlebar)
          Same as GWindow(), but titlebar may be omited.
GWindow(java.lang.String title)
          Same as GWindow() with given title.
GWindow(java.lang.String title, Position position, Size size)
          Same as GWindow() with given title, position and size of client window.
GWindow(java.lang.String title, Size size)
          Same as GWindow() with given title and size of client window.
 
Method Summary
 void addExitListener(ExitListener exitListener)
          Register an ExitListener to get a notification when the close button is clicked.
 void adjust()
          Actualize the conversion between window und user coordinates according to the current component size.
 void clear()
          Clear the screen graphics (without calling repaint).
 void clearBuf()
          Clear the graphics offline buffer (without calling repaint).
 void clearStore(java.awt.Color color)
          Clear store buffer by uniformly painting it with given color.
static void delay(int time)
          Delay execution for the given amount of time ( in ms ).
 void disableClose(boolean b)
          Disable/Enable the title bar's closing button.
 void drawImage(java.awt.image.BufferedImage bi, int x, int y, boolean lowerLeft)
          Draw the given BufferedImage into offscreen buffer at (x, y) coordinates of upper left corner.
 java.lang.String getAbout()
          Return copywrite information.
 java.awt.geom.AffineTransform getAffineScale()
          Perform scaling of the offscreen buffer to fit the image to the current window dimension.
 java.awt.Color getBgColor()
          Return the current background color.
 int getBottomInset()
          Return the bottom inset of the window (border width) in pixels.
 java.awt.image.BufferedImage getBufferedImage()
          Return a reference to the offscreen buffer created by GWindow's constructor.
 int getCurrentHeight()
          Return the height of the client area in user coordinates.
 int getCurrentWidth()
          Return the width of the client area in user coordinates.
static java.lang.String[] getDesktopProperties()
          Return the property names of available system properties.
 int getLeftInset()
          Return the left inset of the window (border width) in pixels.
 java.awt.Graphics2D getOffG2D()
          Return the Graphics2D context of the offscreen buffer created by GWindow's constructor.
 java.awt.Color getPixelColor(double x, double y)
          Return the color of the screen pixel at given location.
 int getPopupHeight()
          Return the height of the window in user coordinates when it was created.
 int getPopupWidth()
          Return the width of the window in user coordinates when it was created.
 int getRightInset()
          Return the right inset of the window (border width) in pixels.
 double getScaleX()
          Return the current magnification factor of horizontal window size.
 double getScaleY()
          Return the current magnification factor of vertical window size.
static int getScreenHeight()
          Get the height of the screen (in pixels).
static int getScreenWidth()
          Get the width of the screen (in pixels).
 java.lang.String getVersion()
          Return version information.
 boolean isDisposed()
          Return true, if the window was disposed or released.
static Position position(int ulx, int uly)
          Return a Position ref with specified upperleft x and y coordinates.
 void recallGraphics()
          Copy the store buffer to the offscreen buffer.
 java.awt.Color setBgColor(java.awt.Color color)
          Set the background color of the window and offscreen buffer and show the window.
 void setOffG2D(java.awt.Graphics2D g2D)
          Set the Graphics2D context of the offscreen buffer.
 void setTitle(java.lang.String title)
          Set the title in the window's title bar.
 void setWinCenter()
          Set window to screen center.
 void setWinCenter(Size size)
          Set window to screen center with given size of the embedded component.
 void setWindow(double xmin, double xmax, double ymin, double ymax)
          Set window coordinate system left_x, right_x, bottom_y, top_y
 void setWinPosition(int ulx, int uly)
          Set the position of the window (x-y-coordinates of upper left corner in device coordinates).
 void setWinPosition(Position position)
          Set the position of the window (position of uppler left corner in device coordinates).
 void setWinSize(int width, int height)
          Set the size of the embedded component (in device coordinates) to given width and heigth.
 void setWinSize(Size size)
          Set the size of the embedded component (in device coordinates).
 void showComponent(javax.swing.JComponent component)
          Add the component to the frame's contentPane and show the window with default background color.
 void showComponent(javax.swing.JComponent component, boolean visible)
          Same as showComponent(JComponent component) but set visibilty to the given value.
 void showComponent(javax.swing.JComponent component, java.awt.Color bgColor)
          Add a component to the frame's contentPane and show the window with the given background color.
 void showComponent(javax.swing.JComponent component, java.awt.Color bgColor, boolean visible)
          Same as showComponent(JComponent component, Color bgColor) but set visibilty to the given value.
static Size size(int width, int height)
          Return a Size ref with specified width and height.
 void storeGraphics()
          Copy the offscreen buffer to a store buffer.
 int topLeftInset()
          Return the top inset of the window (title bar + border) in pixels.
 java.awt.Shape toUser(java.awt.Shape shape)
          Convert the given shape from window coordinates to user coordinates.
 int toUserHeight(double windowHeight)
          Convert window coordinates increment to user coordinates increment (vertical).
 java.awt.geom.AffineTransform toUserTransform()
          Create an affine transform to convert a shape from window coordinates to user coordinates and return it.
 int toUserWidth(double windowWidth)
          Convert window coordinates increment to user coordinates increment (horizontal).
 int toUserY(double windowY)
          Convert window coordinate to user coordinate (vertical).
 double toWindowHeight(int userHeight)
          Convert user coordinates increment to window coordinates increment (vertical).
 double toWindowWidth(int userWidth)
          Convert user coordinates increment to window coordinates increment (horizontal).
 double toWindowX(int userX)
          Convert user coordinates to window coordinates (horizontal).
 double toWindowY(int userY)
          Convert user coordinates to window coordinates (vertical).
 void transformGraphics(java.awt.geom.AffineTransform at)
          Transform offscreen buffer with given affine transformation.
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

GWindow

public GWindow()
Construct a GWindow with default title and size. of the embedded component and show the window at default screen positition. Creates an offscreen buffer (instance of BufferedImage) to be used for animations. Default size of client window: 500 x 500 pixels. Default position upper left corner: 50,50.


GWindow

public GWindow(java.lang.String title)
Same as GWindow() with given title.


GWindow

public GWindow(java.lang.String title,
               Size size)
Same as GWindow() with given title and size of client window.


GWindow

public GWindow(java.lang.String title,
               Position position,
               Size size)
Same as GWindow() with given title, position and size of client window. If size is a Fullscreen object reference, the window size will be adapted to the current screen dimensions and the size of the client area is accordingly adapted and may be asked with getWidth(), getHeight().


GWindow

public GWindow(Position position,
               Size size,
               boolean noTitlebar)
Same as GWindow(), but titlebar may be omited. If size is a Fullscreen object reference, the window size will be adapted to the current screen dimensions and the size of the client area is accordingly adapted and may be asked with getWidth(), getHeight().

Method Detail

addExitListener

public void addExitListener(ExitListener exitListener)
Register an ExitListener to get a notification when the close button is clicked. (In this case, this is the only action performed when clicking the close button.)


position

public static Position position(int ulx,
                                int uly)
Return a Position ref with specified upperleft x and y coordinates. May be used in constructor to avoid the keyword new


size

public static Size size(int width,
                        int height)
Return a Size ref with specified width and height. May be used in constructor to avoid the keyword new


getScreenWidth

public static int getScreenWidth()
Get the width of the screen (in pixels).


getScreenHeight

public static int getScreenHeight()
Get the height of the screen (in pixels).


setBgColor

public java.awt.Color setBgColor(java.awt.Color color)
Set the background color of the window and offscreen buffer and show the window. All drawings are erased. Return the previous color.


getBgColor

public java.awt.Color getBgColor()
Return the current background color.


setWinPosition

public void setWinPosition(Position position)
Set the position of the window (position of uppler left corner in device coordinates).


setWinPosition

public void setWinPosition(int ulx,
                           int uly)
Set the position of the window (x-y-coordinates of upper left corner in device coordinates).


setWinSize

public void setWinSize(Size size)
Set the size of the embedded component (in device coordinates).


setWinSize

public void setWinSize(int width,
                       int height)
Set the size of the embedded component (in device coordinates) to given width and heigth.


setWinCenter

public void setWinCenter(Size size)
Set window to screen center with given size of the embedded component.


setWinCenter

public void setWinCenter()
Set window to screen center.


showComponent

public void showComponent(javax.swing.JComponent component)
Add the component to the frame's contentPane and show the window with default background color.


showComponent

public void showComponent(javax.swing.JComponent component,
                          boolean visible)
Same as showComponent(JComponent component) but set visibilty to the given value. (Visibility may be changed by setVisible())


showComponent

public void showComponent(javax.swing.JComponent component,
                          java.awt.Color bgColor)
Add a component to the frame's contentPane and show the window with the given background color.


showComponent

public void showComponent(javax.swing.JComponent component,
                          java.awt.Color bgColor,
                          boolean visible)
Same as showComponent(JComponent component, Color bgColor) but set visibilty to the given value. (Visibility may be changed by setVisible())


getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Return a reference to the offscreen buffer created by GWindow's constructor.


getOffG2D

public java.awt.Graphics2D getOffG2D()
Return the Graphics2D context of the offscreen buffer created by GWindow's constructor.


setOffG2D

public void setOffG2D(java.awt.Graphics2D g2D)
Set the Graphics2D context of the offscreen buffer.


getCurrentWidth

public int getCurrentWidth()
Return the width of the client area in user coordinates.


getCurrentHeight

public int getCurrentHeight()
Return the height of the client area in user coordinates.


getLeftInset

public int getLeftInset()
Return the left inset of the window (border width) in pixels.


getRightInset

public int getRightInset()
Return the right inset of the window (border width) in pixels.


topLeftInset

public int topLeftInset()
Return the top inset of the window (title bar + border) in pixels.


getBottomInset

public int getBottomInset()
Return the bottom inset of the window (border width) in pixels.


getScaleX

public double getScaleX()
Return the current magnification factor of horizontal window size.


getScaleY

public double getScaleY()
Return the current magnification factor of vertical window size.


getPopupWidth

public int getPopupWidth()
Return the width of the window in user coordinates when it was created.


getPopupHeight

public int getPopupHeight()
Return the height of the window in user coordinates when it was created.


getAffineScale

public java.awt.geom.AffineTransform getAffineScale()
Perform scaling of the offscreen buffer to fit the image to the current window dimension. Return a reference to the new affine tranformation.


setTitle

public void setTitle(java.lang.String title)
Set the title in the window's title bar.

Overrides:
setTitle in class java.awt.Frame

toUserY

public int toUserY(double windowY)
Convert window coordinate to user coordinate (vertical).


toUserWidth

public int toUserWidth(double windowWidth)
Convert window coordinates increment to user coordinates increment (horizontal). Increment is always positive.


toUserHeight

public int toUserHeight(double windowHeight)
Convert window coordinates increment to user coordinates increment (vertical). Increment is always positive.


toWindowX

public double toWindowX(int userX)
Convert user coordinates to window coordinates (horizontal).


toWindowY

public double toWindowY(int userY)
Convert user coordinates to window coordinates (vertical).


toWindowWidth

public double toWindowWidth(int userWidth)
Convert user coordinates increment to window coordinates increment (horizontal). Increment is always positive.


toWindowHeight

public double toWindowHeight(int userHeight)
Convert user coordinates increment to window coordinates increment (vertical). Increment is always positive.


setWindow

public void setWindow(double xmin,
                      double xmax,
                      double ymin,
                      double ymax)
Set window coordinate system left_x, right_x, bottom_y, top_y


toUser

public java.awt.Shape toUser(java.awt.Shape shape)
Convert the given shape from window coordinates to user coordinates. Return a reference to a new tranformed shape.


toUserTransform

public java.awt.geom.AffineTransform toUserTransform()
Create an affine transform to convert a shape from window coordinates to user coordinates and return it.


getVersion

public java.lang.String getVersion()
Return version information.


getAbout

public java.lang.String getAbout()
Return copywrite information.


adjust

public void adjust()
Actualize the conversion between window und user coordinates according to the current component size.


delay

public static void delay(int time)
Delay execution for the given amount of time ( in ms ).


clearBuf

public void clearBuf()
Clear the graphics offline buffer (without calling repaint).


clear

public void clear()
Clear the screen graphics (without calling repaint).


getDesktopProperties

public static java.lang.String[] getDesktopProperties()
Return the property names of available system properties. Return null, if no properties are available on the current platform.


disableClose

public void disableClose(boolean b)
Disable/Enable the title bar's closing button.


storeGraphics

public void storeGraphics()
Copy the offscreen buffer to a store buffer.


recallGraphics

public void recallGraphics()
Copy the store buffer to the offscreen buffer.


clearStore

public void clearStore(java.awt.Color color)
Clear store buffer by uniformly painting it with given color.


transformGraphics

public void transformGraphics(java.awt.geom.AffineTransform at)
Transform offscreen buffer with given affine transformation.


getPixelColor

public java.awt.Color getPixelColor(double x,
                                    double y)
Return the color of the screen pixel at given location.


isDisposed

public boolean isDisposed()
Return true, if the window was disposed or released.


drawImage

public void drawImage(java.awt.image.BufferedImage bi,
                      int x,
                      int y,
                      boolean lowerLeft)
Draw the given BufferedImage into offscreen buffer at (x, y) coordinates of upper left corner. If lowerLeft = true, coordinates of lower left corner.