dasher.applet
Class JDasherScreen

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by dasher.applet.JDasherScreen
All Implemented Interfaces:
CDasherScreen, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class JDasherScreen
extends javax.swing.JPanel
implements CDasherScreen

This implementation of JDasherScreen is an extension of the Swing basic object JPanel, and works by drawing a frame of Dasher onto the panel whenever its paintComponent method is called.

For a general description of the Screen's contract and specifications of what its methods ought to do, see CDasherScreen. Only details of the implementation will be noted here.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  java.util.HashMap<java.lang.Long,DasherFont> DrawFonts
          Map from font sizes to the Font objects used to draw them.
private  CCustomColours m_Colours
          Custom colour scheme against which colour indices are resolved
private  JDasher m_Dasher
          Dasher instance which draws onto this Screen
protected  int m_iHeight
          Height of this screen in pixels
protected  int m_iWidth
          Width of this screen in pixels
private  java.awt.Graphics paint
          Graphics context in which to draw
private  java.util.HashMap<TextSize,CDasherView.Point> TextSizes
          Map of known sizes of differing characters at different font sizes.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
JDasherScreen(JDasher Dasher, int width, int height)
          Creates a new Screen tied to a given Dasher and with given dimensions
 
Method Summary
 void Blank()
          Clears the screen using the clearRect method
 void Display()
          Method ignored; as we're drawing to Swing's provided surface, the actual displaying of the image will be taken care of for us.
 void DrawCircle(int iCX, int iCY, int iR, int iColour, boolean bFill)
          Draw a circle
 void DrawRectangle(int x1, int y1, int x2, int y2, int Color, int iOutlineColour, EColorSchemes ColorScheme, boolean bDrawOutline, boolean bFill, int iThickness)
          Dasher specifies its co-ordinates like
 void DrawString(java.lang.String string, int x1, int y1, long Size)
          Here be more trouble! Dasher is specifying its strings by the co-ordinates of the top-left corner of a rectangle in which the text will be drawn.
 int GetHeight()
          Gets the height, and hence maximum Y screen co-ordinate.
 int GetWidth()
          Gets the width, and hence maximum X screen co-ordinate.
protected  void paintComponent(java.awt.Graphics g)
          Sets our Graphics context and calls NewFrame; Dasher will do the rest.
 void Polygon(CDasherView.Point[] Points, int Number, int Color)
          Draw a filled polygon - given vertices and color id.
 void Polygon(CDasherView.Point[] Points, int Number, int Color, int iWidth)
          Draw a filled polygon - given vertices, width and color id.
 void Polyline(CDasherView.Point[] Points, int Number, int iWidth)
          Draws a sequence of lines in a fixed colour, usually black.
 void Polyline(CDasherView.Point[] Points, int Number, int iWidth, int Colour)
          Draws a sequence of lines.
 void SendMarker(int iMarker)
          Informs the screen of certain drawing phases.
private  void setColour(int iColour)
          Sets the current Graphics context's colour by querying m_Colours for its RGB values.
 void SetColourScheme(CCustomColours ColourScheme)
          Sets the colour scheme to use
 CDasherView.Point TextSize(java.lang.String string, int Size)
          Graphics.getFontMetrics().getStringBounds is used to determine a probable text size.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

paint

private java.awt.Graphics paint
Graphics context in which to draw


m_Dasher

private JDasher m_Dasher
Dasher instance which draws onto this Screen


m_Colours

private CCustomColours m_Colours
Custom colour scheme against which colour indices are resolved


TextSizes

private java.util.HashMap<TextSize,CDasherView.Point> TextSizes
Map of known sizes of differing characters at different font sizes.


DrawFonts

private java.util.HashMap<java.lang.Long,DasherFont> DrawFonts
Map from font sizes to the Font objects used to draw them.


m_iWidth

protected int m_iWidth
Width of this screen in pixels


m_iHeight

protected int m_iHeight
Height of this screen in pixels

Constructor Detail

JDasherScreen

public JDasherScreen(JDasher Dasher,
                     int width,
                     int height)
Creates a new Screen tied to a given Dasher and with given dimensions

Parameters:
Dasher - Dasher which is displaying using this screen.
width - Width of this screen
height - Height of this screen
Method Detail

GetWidth

public int GetWidth()
Description copied from interface: CDasherScreen
Gets the width, and hence maximum X screen co-ordinate.

Specified by:
GetWidth in interface CDasherScreen
Returns:
width

GetHeight

public int GetHeight()
Description copied from interface: CDasherScreen
Gets the height, and hence maximum Y screen co-ordinate.

Specified by:
GetHeight in interface CDasherScreen
Returns:
height

Blank

public void Blank()
Clears the screen using the clearRect method

Specified by:
Blank in interface CDasherScreen

Display

public void Display()
Method ignored; as we're drawing to Swing's provided surface, the actual displaying of the image will be taken care of for us.

Specified by:
Display in interface CDasherScreen

DrawCircle

public void DrawCircle(int iCX,
                       int iCY,
                       int iR,
                       int iColour,
                       boolean bFill)
Description copied from interface: CDasherScreen
Draw a circle

Specified by:
DrawCircle in interface CDasherScreen
Parameters:
iCX - X co-ordinate of the centre
iCY - Y co-ordinate of the centre
iR - Radius in pixels
iColour - Colour number
bFill - Fill or outline?

DrawRectangle

public void DrawRectangle(int x1,
                          int y1,
                          int x2,
                          int y2,
                          int Color,
                          int iOutlineColour,
                          EColorSchemes ColorScheme,
                          boolean bDrawOutline,
                          boolean bFill,
                          int iThickness)
Dasher specifies its co-ordinates like
 y2---------x2
 |           |
 |           |
 x1,y1-------/

Whereas Java wants

                        width
 x,y---------------\
 |                               |
 |                               | height
 |                               |
 \-----------------/
 

Therefore, I use (x1, y2) as the point to feed to Java, and calculate height and width.

Specified by:
DrawRectangle in interface CDasherScreen
Parameters:
x1 - top left of rectangle (x coordinate)
y1 - top left corner of rectangle (y coordinate)
x2 - bottom right of rectangle (x coordinate)
y2 - bottom right of rectangle (y coordinate)
Color - the colour to be used (numeric)
ColorScheme - Which colourscheme is to be used
bDrawOutline - Whether to draw an outline or not
bFill - Whether to fill or not
iThickness - Line thickness for outline

DrawString

public void DrawString(java.lang.String string,
                       int x1,
                       int y1,
                       long Size)
Here be more trouble! Dasher is specifying its strings by the co-ordinates of the top-left corner of a rectangle in which the text will be drawn. So,
   x,y------------\
   | Some String  |
   \--------------/
  

Java's DrawString method however specifies the baseline of the first character, which is the bottom in the case of non-descenders such as a and b, but is not for descenders such as g.

Therefore we must figure out the height and adjust x appropriately before drawing the string.

It's important to note also that some work in this direction is done by DasherView calling the Screen's TextSize method. This supplies a height and width of a given string in pixels, using a HashMap to do so efficiently.

Specified by:
DrawString in interface CDasherScreen
Parameters:
string - String to draw
x1 - Top-left hand corner x co-ordinate
y1 - Top-left hand corner y co-ordinate
Size - Font size in points

Polygon

public void Polygon(CDasherView.Point[] Points,
                    int Number,
                    int Color)
Description copied from interface: CDasherScreen
Draw a filled polygon - given vertices and color id. This is not (currently) used in standard Dasher. However, it could be very useful in the future. Please implement unless it will be very difficult, in which case make this function call Polyline. Draw a filled polygon

Specified by:
Polygon in interface CDasherScreen
Parameters:
Points - array of points defining the edge of the polygon
Number - number of points in the array
Color - colour of the polygon (numeric)

Polygon

public void Polygon(CDasherView.Point[] Points,
                    int Number,
                    int Color,
                    int iWidth)
Description copied from interface: CDasherScreen
Draw a filled polygon - given vertices, width and color id. This is not (currently) used in standard Dasher. However, it could be very useful in the future. Please implement unless it will be very difficult, in which case make this function call Polyline. Draw a filled polygon

Specified by:
Polygon in interface CDasherScreen
Parameters:
Points - array of points defining the edge of the polygon
Number - number of points in the array
Color - colour of the polygon (numeric)
iWidth - Width of the polygon border to draw

Polyline

public void Polyline(CDasherView.Point[] Points,
                     int Number,
                     int iWidth)
Description copied from interface: CDasherScreen
Draws a sequence of lines in a fixed colour, usually black.

Specified by:
Polyline in interface CDasherScreen
Parameters:
Points - Array of Points describing the vertices of the line.
Number - Number of points
iWidth - Line width

Polyline

public void Polyline(CDasherView.Point[] Points,
                     int Number,
                     int iWidth,
                     int Colour)
Description copied from interface: CDasherScreen
Draws a sequence of lines.

Specified by:
Polyline in interface CDasherScreen
Parameters:
Points - Array of Points describing the vertices of the line.
Number - Number of points
iWidth - Line width
Colour - Colour number

SetColourScheme

public void SetColourScheme(CCustomColours ColourScheme)
Description copied from interface: CDasherScreen
Sets the colour scheme to use

Specified by:
SetColourScheme in interface CDasherScreen
Parameters:
ColourScheme - New colour scheme

TextSize

public CDasherView.Point TextSize(java.lang.String string,
                                  int Size)
Graphics.getFontMetrics().getStringBounds is used to determine a probable text size.

Results, referenced by a struct containing information about both the character and font size concerned, are stored in a HashMap for quick access in the future.

At present, StringBounds' returned answer is augmented by one pixel in the x direction in the interests of readability.

Specified by:
TextSize in interface CDasherScreen
Parameters:
string - String whose size we want to determine
Size - Font size to use
Returns:
Point defining its size.

setColour

private void setColour(int iColour)
Sets the current Graphics context's colour by querying m_Colours for its RGB values.

A colour of -1 is read as being the same as colour 3.

Parameters:
iColour - Colour to set

SendMarker

public void SendMarker(int iMarker)
Description copied from interface: CDasherScreen
Informs the screen of certain drawing phases.

A '0' will be sent when beginning to draw persistent features (ie. those which should remain the same from frame to frame), and a '1' will be sent prior to drawing ephemeral details which should vanish if not redrawn next frame.

Specified by:
SendMarker in interface CDasherScreen
Parameters:
iMarker - Marker number

paintComponent

protected void paintComponent(java.awt.Graphics g)
Sets our Graphics context and calls NewFrame; Dasher will do the rest.

Overrides:
paintComponent in class javax.swing.JComponent