|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
dasher.applet.JDasherScreen
public class JDasherScreen
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.
| 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 |
|---|
private java.awt.Graphics paint
private JDasher m_Dasher
private CCustomColours m_Colours
private java.util.HashMap<TextSize,CDasherView.Point> TextSizes
private java.util.HashMap<java.lang.Long,DasherFont> DrawFonts
protected int m_iWidth
protected int m_iHeight
| Constructor Detail |
|---|
public JDasherScreen(JDasher Dasher,
int width,
int height)
Dasher - Dasher which is displaying using this screen.width - Width of this screenheight - Height of this screen| Method Detail |
|---|
public int GetWidth()
CDasherScreen
GetWidth in interface CDasherScreenpublic int GetHeight()
CDasherScreen
GetHeight in interface CDasherScreenpublic void Blank()
Blank in interface CDasherScreenpublic void Display()
Display in interface CDasherScreen
public void DrawCircle(int iCX,
int iCY,
int iR,
int iColour,
boolean bFill)
CDasherScreen
DrawCircle in interface CDasherScreeniCX - X co-ordinate of the centreiCY - Y co-ordinate of the centreiR - Radius in pixelsiColour - Colour numberbFill - Fill or outline?
public void DrawRectangle(int x1,
int y1,
int x2,
int y2,
int Color,
int iOutlineColour,
EColorSchemes ColorScheme,
boolean bDrawOutline,
boolean bFill,
int iThickness)
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.
DrawRectangle in interface CDasherScreenx1 - 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 usedbDrawOutline - Whether to draw an outline or notbFill - Whether to fill or notiThickness - Line thickness for outline
public void DrawString(java.lang.String string,
int x1,
int y1,
long Size)
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.
DrawString in interface CDasherScreenstring - String to drawx1 - Top-left hand corner x co-ordinatey1 - Top-left hand corner y co-ordinateSize - Font size in points
public void Polygon(CDasherView.Point[] Points,
int Number,
int Color)
CDasherScreen
Polygon in interface CDasherScreenPoints - array of points defining the edge of the polygonNumber - number of points in the arrayColor - colour of the polygon (numeric)
public void Polygon(CDasherView.Point[] Points,
int Number,
int Color,
int iWidth)
CDasherScreen
Polygon in interface CDasherScreenPoints - array of points defining the edge of the polygonNumber - number of points in the arrayColor - colour of the polygon (numeric)iWidth - Width of the polygon border to draw
public void Polyline(CDasherView.Point[] Points,
int Number,
int iWidth)
CDasherScreen
Polyline in interface CDasherScreenPoints - Array of Points describing the vertices of the line.Number - Number of pointsiWidth - Line width
public void Polyline(CDasherView.Point[] Points,
int Number,
int iWidth,
int Colour)
CDasherScreen
Polyline in interface CDasherScreenPoints - Array of Points describing the vertices of the line.Number - Number of pointsiWidth - Line widthColour - Colour numberpublic void SetColourScheme(CCustomColours ColourScheme)
CDasherScreen
SetColourScheme in interface CDasherScreenColourScheme - New colour scheme
public CDasherView.Point TextSize(java.lang.String string,
int 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.
TextSize in interface CDasherScreenstring - String whose size we want to determineSize - Font size to use
private void setColour(int iColour)
A colour of -1 is read as being the same as colour 3.
iColour - Colour to setpublic void SendMarker(int iMarker)
CDasherScreenA '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.
SendMarker in interface CDasherScreeniMarker - Marker numberprotected void paintComponent(java.awt.Graphics g)
paintComponent in class javax.swing.JComponent
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||