ch.aplu.util
Class GWindow

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--ch.aplu.util.GWindow
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ComponentListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public class GWindow
extends javax.swing.JFrame
implements java.awt.event.ComponentListener

Class to define a simple screen window with an event handler to exit the application when clicking the close button in the title bar.
Subclass of JFrame. 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

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, width and height of the embedded component and show the window Default width: 500 pixels Default height: 500 pixels
GWindow(java.lang.String title)
          Construct a GWindow with given title and show the window
GWindow(java.lang.String title, Position position, Size size)
          Construct a GWindow with given title, size of the embedded component, position and show the window.
GWindow(java.lang.String title, Size size)
          Construct a GWindow with given title and size of the embedded component and show the 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 componentHidden(java.awt.event.ComponentEvent e)
          For internal use
 void componentMoved(java.awt.event.ComponentEvent e)
          For internal use
 void componentResized(java.awt.event.ComponentEvent e)
          For internal use
 void componentShown(java.awt.event.ComponentEvent e)
          For internal use
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(int x, int y, boolean lowerLeft)
          Draw the last loaded image into offscreen buffer (x, y) coordindates of 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.
 java.awt.image.BufferedImage getBufferedImage()
          Return a reference to the offscreen buffer created by GWindow's constructor
 int getCurrentHeight()
          Return the current height of the window in user coordinates
 int getCurrentWidth()
          Return the current width of the window in user coordinates
static java.lang.String[] getDesktopProperties()
          Return the property names of available system properties.
 int getImageHeight()
          Return the height (vertical size) of the last loaded GIF or JPEG image (in device coordinates).
 int getImageHeight(java.awt.Image image)
          Return the height (vertical size) of the given GIF or JPEG image (in device coordinates).
 int getImageHeight(java.lang.String imagePath)
          Return the height (vertical size) of the GIF or JPEG image from the given path (in device coordinates).
 int getImageHeight(java.net.URL imageUrl)
          Return the height (vertical size) of the GIF or JPEG image from the given URL (in device coordinates).
 int getImageWidth()
          Return the width (horizontal size) of the last loaded GIF or JPEG image (in device coordinates).
 int getImageWidth(java.awt.Image image)
          Return the width (horizontal size) of the given GIF or JPEG image (in device coordinates).
 int getImageWidth(java.lang.String imagePath)
          Return the width (horizontal size) of the GIF or JPEG image from the given path (in device coordinates).
 int getImageWidth(java.net.URL imageUrl)
          Return the width (horizontal size) of the GIF or JPEG image from the given URL (in device coordinates).
 java.awt.Graphics2D getOffG2D()
          Return the Graphics2D context of the offscreen buffer created by GWindow's constructor
 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
 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 loadImage(java.awt.Image image)
          Load the given GIF or JPEG image and set the current image's width and height.
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
 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)
           
 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 (in device coordinates)
 void setWinPosition(Position position)
          Set the position of the window (in device coordinates)
 void setWinSize(int width, int height)
          Set the size of the embedded component (in device coordinates) (User coordinates 0..width-1, 0..height-1, origin at uppler left corner)
 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 May be used in constructor to avoid the keyword new
 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) Increment is always positive
 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) Increment is always positive
 int toUserX(double windowX)
          Convert window coordinate to user coordinate (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) Increment is always positive
 double toWindowWidth(int userWidth)
          Convert user coordinates increment to window coordinates increment (horizontal) Increment is always positive
 double toWindowX(int userX)
          Convert user coordinates to window coordinates (horizontal)
 double toWindowY(int userY)
          Convert user coordinates to window coordinates (vertical)
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, 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, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, 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, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, isOpaque, 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, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, 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, width and height of the embedded component and show the window Default width: 500 pixels Default height: 500 pixels


GWindow

public GWindow(java.lang.String title)
Construct a GWindow with given title and show the window


GWindow

public GWindow(java.lang.String title,
               Size size)
Construct a GWindow with given title and size of the embedded component and show the window

Parameters:
size - a ref to a Size object (width, height)
See Also:
(User coordinates 0..width-1, 0..height-1, origin at uppler left corner)

GWindow

public GWindow(java.lang.String title,
               Position position,
               Size size)
Construct a GWindow with given title, size of the embedded component, position and show the window. Creates an offscreen buffer (instance of BufferedImage) to be used for animations.

Parameters:
position - a ref to a Position object
size - a ref to a Size object (width, height)
See Also:
Position, (User coordinates 0..width-1, 0..height-1, origin at upper left corner)
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 (in device coordinates)

Parameters:
position - a ref to a Position object (upper left corner)
See Also:
Position

setWinPosition

public void setWinPosition(int ulx,
                           int uly)
Set the position of the window (in device coordinates)

Parameters:
ulx - x-coordinate of upper left corner
uly - y-coordinate of upper left corner

setWinSize

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

Parameters:
size - a ref to a Size object (width, height)
See Also:
(User coordinates 0..width-1, 0..height-1, origin at uppler left corner)

setWinSize

public void setWinSize(int width,
                       int height)
Set the size of the embedded component (in device coordinates) (User coordinates 0..width-1, 0..height-1, origin at uppler left corner)


setWinCenter

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

Parameters:
size - a ref to a Size object (width, height)
See Also:
(User coordinates 0..width-1, 0..height-1, origin at uppler left corner)

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)

getCurrentWidth

public int getCurrentWidth()
Return the current width of the window in user coordinates


getCurrentHeight

public int getCurrentHeight()
Return the current height of the window in user coordinates


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

toUserX

public int toUserX(double windowX)
Convert window coordinate to user coordinate (horizontal)


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


componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
For internal use

Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
For internal use

Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
For internal use

Specified by:
componentResized in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
For internal use

Specified by:
componentShown in interface java.awt.event.ComponentListener

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)


loadImage

public boolean loadImage(java.awt.Image image)
Load the given GIF or JPEG image and set the current image's width and height. Return true if successful and when loading is complete. If not successful, width and height is set to 0.


drawImage

public void drawImage(int x,
                      int y,
                      boolean lowerLeft)
Draw the last loaded image into offscreen buffer (x, y) coordindates of of upper left corner. If lowerLeft = true, coordinates of lower left corner.


getImageWidth

public int getImageWidth(java.lang.String imagePath)
Return the width (horizontal size) of the GIF or JPEG image from the given path (in device coordinates). Return 0, if image is invalid.


getImageWidth

public int getImageWidth(java.net.URL imageUrl)
Return the width (horizontal size) of the GIF or JPEG image from the given URL (in device coordinates). Return 0, if image is invalid.


getImageWidth

public int getImageWidth(java.awt.Image image)
Return the width (horizontal size) of the given GIF or JPEG image (in device coordinates). Return 0, if image is invalid.


getImageHeight

public int getImageHeight(java.lang.String imagePath)
Return the height (vertical size) of the GIF or JPEG image from the given path (in device coordinates). Return 0, if image is invalid.


getImageHeight

public int getImageHeight(java.net.URL imageUrl)
Return the height (vertical size) of the GIF or JPEG image from the given URL (in device coordinates). Return 0, if image is invalid.


getImageHeight

public int getImageHeight(java.awt.Image image)
Return the height (vertical size) of the given GIF or JPEG image (in device coordinates). Return 0, if image is invalid.


getImageWidth

public int getImageWidth()
Return the width (horizontal size) of the last loaded GIF or JPEG image (in device coordinates). Return 0, if image is invalid.


getImageHeight

public int getImageHeight()
Return the height (vertical size) of the last loaded GIF or JPEG image (in device coordinates). Return 0, if image is invalid.


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