maclib
Class DrawingFrame

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 maclib.DrawingFrame
All Implemented Interfaces:
java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class DrawingFrame
extends java.awt.Frame
implements java.awt.event.WindowListener

A DrawingFrame is a top-level window containing a DrawingApplet, used for a drawing panel. The DrawingApplet provides automatic repaint, using an off-screen image, and also listeners for keyboard and mouse events. Most of these features are implemented in an attached DrawingStuff object.

Usually, a DrawingFrame is instanciated during the initialization of a GrafPort that provides QuickDraw-like drawing and event routines onto the attached drawing panel.

A DrawingFrame may be also directly instanciated and a GrafPort object is then allocated and it may be obtained by a call to the getPort method.

Version:
04 may 2012
Author:
Philippe Chassignet, Ecole Polytechnique
See Also:
DrawingApplet, DrawingStuff, GrafPort, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
static int DEFAULT_FRAME_HEIGHT
          The default initial height for a new DrawingFrame.
static int DEFAULT_FRAME_WIDTH
          The default initial width for a new DrawingFrame.
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DrawingFrame()
          Constructs and initializes a DrawingFrame having : the title "Drawing", the default initial size for the frame, the default size for the off-screen image
DrawingFrame(java.lang.String title)
          Constructs and initializes a DrawingFrame having : the specified title, the default initial size for the frame, the default size for the off-screen image
DrawingFrame(java.lang.String title, int width, int height)
          Constructs and initializes a DrawingFrame having : the specified title, the specified initial size for the frame, the default final size for the off-screen image
DrawingFrame(java.lang.String title, int width, int height, int fullWidth, int fullHeight)
          Constructs and initializes a DrawingFrame having : the specified title, the specified initial size for the frame, the specified final size for the off-screen image
 
Method Summary
 void dispose()
          Disposes of this DrawingFrame and attached objects.
 void finalize()
          Called by the garbage collector when there are no more reference to this DrawingFrame.
 java.lang.String getName()
          Returns the title given to this DrawingFrame.
 GrafPort getPort()
          Returns the GrafPort object that provides QuickDraw-like drawing and event routines onto the attached drawing panel.
 java.awt.Rectangle getPortBounds()
          Gets the drawing bounds of this DrawingFrame.
 DrawingStuff getStuff()
          Returns the attached DrawingStuff object that provides automatic repaint and interfaces for keyboard and mouse events.
 void setPortBounds(java.awt.Rectangle b)
          Sets the drawing bounds of this DrawingFrame as specified by the given Rectangle object.
 void setPortSize(int width, int height)
          Sets the drawing size of this DrawingFrame as specified.
 void showStatus(java.lang.String s)
          Prints a string of text (for user information) on System.out.
 void windowActivated(java.awt.event.WindowEvent e)
          Invoked by the event handler when this DrawingFrame is activated and will receive keyboard events.
 void windowClosed(java.awt.event.WindowEvent e)
          Invoked by the event handler when this DrawingFrame has been closed by a call to dispose.
 void windowClosing(java.awt.event.WindowEvent e)
          Invoked by the event handler when this DrawingFrame is in the process of being closed by the user.
 void windowDeactivated(java.awt.event.WindowEvent e)
          Invoked by the event handler when this DrawingFrame is de-activated and will no longer receive keyboard event.
 void windowDeiconified(java.awt.event.WindowEvent e)
          Invoked by the event handler when this DrawingFrame is de-iconified.
 void windowIconified(java.awt.event.WindowEvent e)
          Invoked by the event handler when this DrawingFrame is iconified.
 void windowOpened(java.awt.event.WindowEvent e)
          Invoked by the event handler when this DrawingFrame has been opened, that is, the first time it is made visible.
 
Methods inherited from class java.awt.Frame
addNotify, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, 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, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, 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, 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
 

Field Detail

DEFAULT_FRAME_WIDTH

public static final int DEFAULT_FRAME_WIDTH
The default initial width for a new DrawingFrame.

See Also:
DrawingFrame(java.lang.String), Constant Field Values

DEFAULT_FRAME_HEIGHT

public static final int DEFAULT_FRAME_HEIGHT
The default initial height for a new DrawingFrame.

See Also:
DrawingFrame(java.lang.String), Constant Field Values
Constructor Detail

DrawingFrame

public DrawingFrame(java.lang.String title,
                    int width,
                    int height,
                    int fullWidth,
                    int fullHeight)
Constructs and initializes a DrawingFrame having :

Parameters:
title - the title given to this DrawingFrame
width - the initial width of the frame
height - the initial height of the frame
fullWidth - the final width of the off-screen image
fullHeight - the final height of the off-screen image

DrawingFrame

public DrawingFrame(java.lang.String title,
                    int width,
                    int height)
Constructs and initializes a DrawingFrame having :

Parameters:
title - the title given to this DrawingFrame
width - the initial width of the frame
height - the initial height of the frame
See Also:
DrawingStuff.DEFAULT_SCREEN_WIDTH, DrawingStuff.DEFAULT_SCREEN_HEIGHT

DrawingFrame

public DrawingFrame(java.lang.String title)
Constructs and initializes a DrawingFrame having :

Parameters:
title - the title given to this DrawingFrame
See Also:
DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HEIGHT, DrawingStuff.DEFAULT_SCREEN_WIDTH, DrawingStuff.DEFAULT_SCREEN_HEIGHT

DrawingFrame

public DrawingFrame()
Constructs and initializes a DrawingFrame having :

See Also:
DEFAULT_FRAME_WIDTH, DEFAULT_FRAME_HEIGHT, DrawingStuff.DEFAULT_SCREEN_WIDTH, DrawingStuff.DEFAULT_SCREEN_HEIGHT
Method Detail

getStuff

public DrawingStuff getStuff()
Returns the attached DrawingStuff object that provides automatic repaint and interfaces for keyboard and mouse events.

Returns:
the DrawingStuff object

getPort

public GrafPort getPort()
Returns the GrafPort object that provides QuickDraw-like drawing and event routines onto the attached drawing panel.

Returns:
the GrafPort object

getName

public java.lang.String getName()
Returns the title given to this DrawingFrame. Overrides getName of class Component, so that the title is returned in place of the internal name.

Overrides:
getName in class java.awt.Component
Returns:
the name of this DrawingFrame

dispose

public void dispose()
Disposes of this DrawingFrame and attached objects.

Overrides:
dispose in class java.awt.Window

finalize

public void finalize()
              throws java.lang.Throwable
Called by the garbage collector when there are no more reference to this DrawingFrame.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

setPortSize

public void setPortSize(int width,
                        int height)
Sets the drawing size of this DrawingFrame as specified.

Parameters:
width - the width of the panel in pixels
height - the height of the panel in pixels
See Also:
setPortBounds(java.awt.Rectangle)

setPortBounds

public void setPortBounds(java.awt.Rectangle b)
Sets the drawing bounds of this DrawingFrame as specified by the given Rectangle object.

Parameters:
a - Rectangle object that specifies the screen coordinates of the drawing area
See Also:
getPortBounds()

getPortBounds

public java.awt.Rectangle getPortBounds()
Gets the drawing bounds of this DrawingFrame.

Returns:
a new Rectangle object filled with the screen coordinates of the drawing area
See Also:
setPortBounds(java.awt.Rectangle)

windowOpened

public void windowOpened(java.awt.event.WindowEvent e)
Invoked by the event handler when this DrawingFrame has been opened, that is, the first time it is made visible.

Specified by:
windowOpened in interface java.awt.event.WindowListener

windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Invoked by the event handler when this DrawingFrame is in the process of being closed by the user. This DrawingFrame is disposed. The application terminates when the last DrawingFrame is disposed.

Specified by:
windowClosing in interface java.awt.event.WindowListener

windowClosed

public void windowClosed(java.awt.event.WindowEvent e)
Invoked by the event handler when this DrawingFrame has been closed by a call to dispose.

Specified by:
windowClosed in interface java.awt.event.WindowListener

windowIconified

public void windowIconified(java.awt.event.WindowEvent e)
Invoked by the event handler when this DrawingFrame is iconified.

Specified by:
windowIconified in interface java.awt.event.WindowListener

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent e)
Invoked by the event handler when this DrawingFrame is de-iconified.

Specified by:
windowDeiconified in interface java.awt.event.WindowListener

windowActivated

public void windowActivated(java.awt.event.WindowEvent e)
Invoked by the event handler when this DrawingFrame is activated and will receive keyboard events.

Specified by:
windowActivated in interface java.awt.event.WindowListener

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent e)
Invoked by the event handler when this DrawingFrame is de-activated and will no longer receive keyboard event.

Specified by:
windowDeactivated in interface java.awt.event.WindowListener

showStatus

public void showStatus(java.lang.String s)
Prints a string of text (for user information) on System.out.

Parameters:
s - the string to be printed