JLogView_.widgets
Class LGCanvas

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 JLogView_.widgets.LGCanvas
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class LGCanvas
extends javax.swing.JPanel
implements java.awt.event.MouseListener, java.awt.print.Printable, java.awt.event.ActionListener

LGCanvas is a widget represeting the main canvas area. Put simply, this is the drawing area where all the axis, labels, plots, annotations and legend will be drawn. There are different responses that need to occur with mouse interactions: zoom, position on the axes, coordinates of the point the mouse pointer is on etc...

This canvas object can also be saved as an image or printed.

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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
LGCanvas()
          This is the constructor of the LGCanvas.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          This method comes from the ActionListener interface.
 java.lang.String getColumnNameOf(float x, float y)
          This methods returns the column name of a given data point if the data point is nowhere to be found in the current graph data the result might be null.
 LGGraph getGraph()
          This methods returns the current graph.
 javax.swing.JLabel getGraphTitle()
          This methods returns the current graph title as a label object.
 LGLegend getLegend()
          This methods returns the legend of the current graph, the main use of this function is for updating the legend font, entries and position.
 float[] getRealCoords(int x, int y)
          This methods converts between coordinates systems.
 float[] getSpotNear(int x, int y)
          This methods attempts to return the coordinates of the nearest graph data point to the given pixels coordinates on the canvas.
 void mouseClicked(java.awt.event.MouseEvent e)
          This method comes from the MouseListener interface.
 void mouseEntered(java.awt.event.MouseEvent e)
          This method comes from the MouseListener interface.
 void mouseExited(java.awt.event.MouseEvent e)
          This method comes from the MouseListener interface.
 void mousePressed(java.awt.event.MouseEvent e)
          This method comes from the MouseListener interface.
 void mouseReleased(java.awt.event.MouseEvent e)
          This method comes from the MouseListener interface.
 void paint(java.awt.Graphics h)
          This method is overriding the default paint method.
 int print(java.awt.Graphics g, java.awt.print.PageFormat format, int pageIndex)
          This methods prints out the current canvas on the given printer graphics context.
 void removeGraphAnnotations()
          This methods clears out all annotations from the current graph
 void saveAsImage(java.lang.String format, java.io.File writeto)
          This methods saves the current canvas display as an image, this does not include the red lines pointing to the axis.
 void setAnnotateActive(boolean note)
          This methods tells the canvas whether or not to be in annotating mode.
 void setGraph(LGGraph graph)
          This methods sets the current graph to be displayed, it also adjust the axes accordingly.
 void setGraphTitle(javax.swing.JLabel newtitle)
          This methods updates the current graph title using a label object.
 void setLegend(LGLegend newleg)
          This methods sets the legend for the current graph to be displayed, it triggers a column renaming if the legend entries and the graph column names do not match anymore.
 void setMousePos(int x, int y)
          This methods tells the LGCanvas the current position of the mouse within the canvas.
 void setUseColours(boolean usethem)
          This methods tells the canvas whether of not to use colours for drawing the graph
 void setUseLineStyles(boolean usethem)
          This methods tells the canvas whether of not to use different line styles when drawing the graph
 void setUseRedLines(boolean usethem)
          This methods tells the canvas whether or not to draw red line coming from the mouse pointer to each axis.
 void setUseSymbols(boolean usethem)
          This methods tells the canvas whether of not to use different symbols when drawing the graph coordinates entries from the table
 void setZoomActive(boolean zoom)
          This methods tells the canvas whether or not to be in zooming mode.
 void switchAxisLabels(boolean lab)
          This methods tells the canvas to switch the axis labels on or off.
 void switchLegend(boolean leg)
          This methods tells the canvas to switch the legend on or off.
 void update(java.awt.Graphics h)
          This method is overriding the default update method to ensure slick repainting.
 boolean XisResolutionAxis()
          This methods tells whether or not the current X axis is treated as a resolution axis
 
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, getBaseline, getBaselineResizeBehavior, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, 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
 
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
 

Constructor Detail

LGCanvas

public LGCanvas()
This is the constructor of the LGCanvas.

Method Detail

setGraph

public void setGraph(LGGraph graph)
This methods sets the current graph to be displayed, it also adjust the axes accordingly.

Parameters:
graph - an LGGraph object that represents the graph to be drawn on the canvas
See Also:
LGGraph

getGraph

public LGGraph getGraph()
This methods returns the current graph.

Returns:
an LGGraph object that represents the graph drawn on the canvas
See Also:
LGGraph

getLegend

public LGLegend getLegend()
This methods returns the legend of the current graph, the main use of this function is for updating the legend font, entries and position.

Returns:
an LGLegend object that represents the legend of the graph drawn on the canvas
See Also:
LGLegend

setLegend

public void setLegend(LGLegend newleg)
This methods sets the legend for the current graph to be displayed, it triggers a column renaming if the legend entries and the graph column names do not match anymore.

Parameters:
newleg - an LGLegend object that represents the legend of the graph to be drawn on the canvas
See Also:
LGLegend

removeGraphAnnotations

public void removeGraphAnnotations()
This methods clears out all annotations from the current graph


setMousePos

public void setMousePos(int x,
                        int y)
This methods tells the LGCanvas the current position of the mouse within the canvas.

Parameters:
x - the x coordinates of the mouse on the canvas
y - the y coordinates of the mouse on the canvas

setUseRedLines

public void setUseRedLines(boolean usethem)
This methods tells the canvas whether or not to draw red line coming from the mouse pointer to each axis.

Parameters:
usethem - a boolean

setUseColours

public void setUseColours(boolean usethem)
This methods tells the canvas whether of not to use colours for drawing the graph

Parameters:
usethem - a boolean, true -> colours, false->black / white

setUseLineStyles

public void setUseLineStyles(boolean usethem)
This methods tells the canvas whether of not to use different line styles when drawing the graph

Parameters:
usethem - a boolean, true -> use patterns, false->continuous line

setUseSymbols

public void setUseSymbols(boolean usethem)
This methods tells the canvas whether of not to use different symbols when drawing the graph coordinates entries from the table

Parameters:
usethem - a boolean, true -> different symbols, false->only big dots

switchLegend

public void switchLegend(boolean leg)
This methods tells the canvas to switch the legend on or off.

Parameters:
leg - a boolean, true -> display legend, false->hide legend

switchAxisLabels

public void switchAxisLabels(boolean lab)
This methods tells the canvas to switch the axis labels on or off.

Parameters:
lab - a boolean, true -> display axis labels, false->hide axis labels

getGraphTitle

public javax.swing.JLabel getGraphTitle()
This methods returns the current graph title as a label object. It will have information concerning the colour, the font face, font style and font size to used to display the title.

Returns:
a JLabel object containing the graph title and its display settings.
See Also:
JLabel

setGraphTitle

public void setGraphTitle(javax.swing.JLabel newtitle)
This methods updates the current graph title using a label object. It passes information concerning the colour, the font face, font style and font size to used to display the title back to the current graph.

Parameters:
newtitle - a JLabel object containing the graph title and its display settings.
See Also:
JLabel

paint

public void paint(java.awt.Graphics h)
This method is overriding the default paint method. Obviously in our case There are loads of data structures that are getting drawn, and they are not widgets: graph, legend, annotation, axes, plots

Overrides:
paint in class javax.swing.JComponent
Parameters:
h - the graphic context of this canvas
See Also:
Graphics

getRealCoords

public float[] getRealCoords(int x,
                             int y)
This methods converts between coordinates systems. Give it the canvas pixel coordinates to get the graph local coordinates.

Parameters:
x - the x coordinate on the canvas
y - the y coordinate on the canvas
Returns:
an array of 2 float containing the converted coordinates.

getSpotNear

public float[] getSpotNear(int x,
                           int y)
This methods attempts to return the coordinates of the nearest graph data point to the given pixels coordinates on the canvas. It is an attempt in the sense that if no point is near enough the result will be null.

Parameters:
x - the x coordinate on the canvas
y - the y coordinate on the canvas
Returns:
an array of 2 float containing the local graph coordinates of the nearest point or null

XisResolutionAxis

public boolean XisResolutionAxis()
This methods tells whether or not the current X axis is treated as a resolution axis

Returns:
true is X is treated as a resolution axis false otherwise.

getColumnNameOf

public java.lang.String getColumnNameOf(float x,
                                        float y)
This methods returns the column name of a given data point if the data point is nowhere to be found in the current graph data the result might be null.

Parameters:
x - the x graph local coordinate of the data point
y - the y graph local coordinate of the data point
Returns:
a String object containing the name of the column or null
See Also:
String

update

public void update(java.awt.Graphics h)
This method is overriding the default update method to ensure slick repainting.

Overrides:
update in class javax.swing.JComponent
Parameters:
h - the graphic context of this canvas
See Also:
Graphics

setZoomActive

public void setZoomActive(boolean zoom)
This methods tells the canvas whether or not to be in zooming mode. When being in zooming mode, a mouse drag on the canvas sets the zone we want to zoom on.

Parameters:
zoom - a boolean, true-> we are zooming, false-> we are only displaying.

setAnnotateActive

public void setAnnotateActive(boolean note)
This methods tells the canvas whether or not to be in annotating mode. When being in annotating mode, a mouse click will create a pop up window in which annotations details are to be entered

Parameters:
note - a boolean, true-> we are annotating, false-> we are only displaying.

saveAsImage

public void saveAsImage(java.lang.String format,
                        java.io.File writeto)
This methods saves the current canvas display as an image, this does not include the red lines pointing to the axis.

Parameters:
format - a String describing the format (acceptable values: jpg, bmp, png, gif)
writeto - a String containing the path of the file in which to write the image.

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat format,
                 int pageIndex)
This methods prints out the current canvas on the given printer graphics context.

Specified by:
print in interface java.awt.print.Printable
Parameters:
g - a Graphics object representing the graphic context of the chosen printer
format - the page format being used for printing
pageIndex - the index of the page we print on.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
This method comes from the MouseListener interface. It handles response to mouse clicks on the canvas

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
This method comes from the MouseListener interface. It handles response to mouse entering sub-widgets area. In our case nothing.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
This method comes from the MouseListener interface. It handles response to mouse exiting sub-widgets area. In our case nothing.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
This method comes from the MouseListener interface. It handles response to mouse button being pressed on the canvas.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
This method comes from the MouseListener interface. It handles response to mouse button being released on the canvas.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
This method comes from the ActionListener interface. It handles response to button widgets being clicked.

Specified by:
actionPerformed in interface java.awt.event.ActionListener