org.PingOO.DLAI.lib.graph
Class Contour

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--org.PingOO.DLAI.lib.graph.Graph2D
                    |
                    +--org.PingOO.DLAI.lib.graph.G2Dint
                          |
                          +--org.PingOO.DLAI.lib.graph.Contour

public class Contour
extends G2Dint

This class extends the interactive graphics class G2Dint to incorporate contouring.

Version:
Revision: 1.11 Date: 1996/08/12 23:37:08
Author:
Leigh Brookshaw (http://www.sci.usq.edu.au/staff/leighb/graph/) (leighb@usq.edu.au)
See Also:
Serialized Form

Inner Class Summary
protected  class Contour.ContourKeyListener
           
 
Inner classes inherited from class org.PingOO.DLAI.lib.graph.G2Dint
G2Dint.G2DintActionListener, G2Dint.G2DintKeyListener, G2Dint.G2DintMouseListener, G2Dint.G2DintMouseMotionListener, G2Dint.Gin, G2Dint.Range
 
Inner classes inherited from class org.PingOO.DLAI.lib.graph.Graph2D
Graph2D.Graph2DKeyListener, Graph2D.LoadMessage
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AWTTreeLock
 
Field Summary
protected  boolean autoLabels
          If true the labels will be calculated for each contour level.
protected  boolean autoLevels
          If set the class calculates the contour levels based on the data minimum and maximum.
protected  java.awt.Color contourColor
          Color to draw non labelled contour line.
protected  java.util.Vector[] curves
          Vector array containing the Contour curves.
protected  java.awt.event.KeyListener defaultContourKeyListener
           
protected  boolean drawlabels
          If false labels are not drawn.
protected  double[] grid
          The data grid, a 2D array stored in linear form.
protected  boolean gridLimits
          If true the limits of the plot are the limits of the data grid not the limits of the contours!
protected  java.awt.Color labelcolor
          Color to use in drawing Labels
protected  java.awt.Font labelfont
          Font to use in drawing Labels
protected  java.awt.Color labelledColor
          Color to draw labelled contour line
protected  int labelLevels
          Which levels will get labels.
protected  int labelPrecision
          Precision to use in drawing Labels.
protected  TextLine[] labels
          The label for each contour level.
protected  int labelSignificant
          Number of Significant figures to use in drawing Labels.
protected  int labelStyle
          Style to use in drawing Labels.
protected  double[] levels
          The array of contour levels.
protected  boolean logLevels
          If true the contour levels are calculated in logarithmic intervals.
protected static int MINCELLS
          The minimum length of a curve before it gets a label.
protected static int NLEVELS
          Default number of contour levels
 boolean noContours
          Boolean value if true Contours will not be calculated.
protected  int nx
          Dimension of the contour grid in the X direction.
protected  int ny
          Dimension of the contour grid in the Y direction.
protected  double xmax
          The X maximum limit of the data grid.
protected  double xmin
          The X minimum limit of the data grid.
protected  double ymax
          The Y maximum limit of the data grid.
protected  double ymin
          The Y minimum limit of the data grid.
protected  double zmax
          The maximum value of the grid values.
protected  double zmin
          The minimum value of the grid values.
 
Fields inherited from class org.PingOO.DLAI.lib.graph.G2Dint
cpgin, defaultActionListener, defaultMouseListener, defaultMouseMotionListener, dpgin, drag, range, userlimits, x0, x1, x1old, xaxis, y0, y1, y1old, yaxis
 
Fields inherited from class org.PingOO.DLAI.lib.graph.Graph2D
axis, borderBottom, borderLeft, borderRight, borderTop, clearAll, DataBackground, datarect, dataset, DefaultBackground, defaultKeyListener, drawgrid, drawzero, frame, framecolor, gridcolor, lastText, load_thread, loadingData, markers, paintAll, square, zerocolor
 
Fields inherited from class java.awt.Canvas
base, graphicsConfig, nameCounter, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
Contour()
          Instantiates the class.
 
Method Summary
 void attachContours()
          Attaches contours so that they will be plotted.
private  void attachCurves()
          Attaches all the curves to the graph and to the axes
private  void attachCurves(java.util.Vector v)
          Attaches all the curves from a given level to the graph and to the axes.
private  void calcLabels()
          Calculates the labels.
private  void calcLevels()
          Calculates the contour levels.
protected  void calculateCurves()
          Calculates the contours and attach them to the graph and axes.
 void deleteContours()
          Delete all the Contours.
 void detachContours()
          Detaches contours so that they will not be plotted.
private  void detachCurves()
          Detaches All the curves from the graph and the axes.
private  void detachCurves(java.util.Vector v)
          Detaches all the curves from a given level from the graph and the axes.
 int[] getDim()
          Returns the dimensions of the grid.
 double[] getGrid()
          Returns the grid
 int getLabelPrecision()
          Gets the label precision.
 int getLabelSignificance()
          Gets the number of significant figures for labels.
 int getLabelStyle()
          Gets the label style, either TextLine.SCIENTIFIC or TextLine.ALGEBRAIC.
 double[] getLevels()
          Returns the contour levels.
 double[] getRange()
          Returns the range of the grid.
 boolean loadGrid(java.net.URL file)
          Loads the grid to contour from a URL.
 void paintFirst(java.awt.Graphics g, java.awt.Rectangle r)
          Befores anything is painted, calculates the contours.
 void paintLast(java.awt.Graphics g, java.awt.Rectangle rect)
          Last thing to be done is to draw the contour labels if required.
 void setAutoLevels(boolean b)
          If true, contour levels are calculated automatically.
 void setContourColor(java.awt.Color c)
          Sets the contour's color.
private  void setContourColors()
          Sets the colors for the contour lines.
private  void setContourColors(java.util.Vector v, java.awt.Color c)
          Sets the colors for the contour lines.
 void setDrawLabels(boolean b)
          If true contour levels are not labeled.
 void setGrid(double[] grid, int nx, int ny)
          Sets the grid to be contoured.
 void setLabelColor(java.awt.Color c)
          Sets the Color to be used with all the labels.
 void setLabelFont(java.awt.Font f)
          Sets the font to be used with all the labels.
 void setLabelledContourColor(java.awt.Color c)
          Sets the labelled contour's color.
 void setLabelLevels(int i)
          Sets the contour levels that are to have labels.
 void setLabelPrecision(int p)
          Sets the label precision.
 void setLabels(TextLine[] labels, int nl)
          Manually sets the Contour labels.
 void setLabelSignificance(int s)
          Sets the label significant figures.
 void setLabelStyle(int s)
          Sets the label style, either TextLine.SCIENTIFIC or TextLine.ALGEBRAIC.
 void setLevels(double[] levels, int nl)
          Manually sets the contour levels.
 void setLimitsToGrid(boolean b)
          If true the limits of the plot will be the grid limits.
 void setLogLevels(boolean b)
          If true contour levels are calculated on a log scale.
 void setNLevels(int l)
          Sets the number of contour levels.
 void setRange(double xmin, double xmax, double ymin, double ymax)
          Sets the range of the grid.
private  void zrange()
          Calculates the range of the grid
 
Methods inherited from class org.PingOO.DLAI.lib.graph.G2Dint
attachAxis, createXAxis, createYAxis, getClosestPoint, update
 
Methods inherited from class org.PingOO.DLAI.lib.graph.Graph2D
attachDataSet, createAxis, detachAxes, detachAxis, detachDataSet, detachDataSets, drawAxis, drawFrame, finishedloading, ForceSquare, getDataRectangle, getMarkers, getXmax, getXmin, getYmax, getYmin, loadDataSet, loadFile, loadmessage, paint, paintBeforeData, setDataBackground, setGraphBackground, setMarkers, startedloading
 
Methods inherited from class java.awt.Canvas
, addNotify, constructComponentName, postsOldMouseEvents
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, doLayout, enable, enable, enableEvents, enableInputMethods, eventEnabled, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initIDs, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, lightweightPrint, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, readObject, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

MINCELLS

protected static final int MINCELLS
The minimum length of a curve before it gets a label.

NLEVELS

protected static final int NLEVELS
Default number of contour levels

nx

protected int nx
Dimension of the contour grid in the X direction.

ny

protected int ny
Dimension of the contour grid in the Y direction.

curves

protected java.util.Vector[] curves
Vector array containing the Contour curves.
Each index in the array contains curves at a given contour level.

autoLevels

protected boolean autoLevels
If set the class calculates the contour levels based on the data minimum and maximum. Default value true.

logLevels

protected boolean logLevels
If true the contour levels are calculated in logarithmic intervals.

gridLimits

protected boolean gridLimits
If true the limits of the plot are the limits of the data grid not the limits of the contours!

levels

protected double[] levels
The array of contour levels.

labels

protected TextLine[] labels
The label for each contour level.

labelfont

protected java.awt.Font labelfont
Font to use in drawing Labels

labelcolor

protected java.awt.Color labelcolor
Color to use in drawing Labels

labelStyle

protected int labelStyle
Style to use in drawing Labels.
TextLine.SCIENTIFIC or TextLine.ALGEBRAIC.

labelPrecision

protected int labelPrecision
Precision to use in drawing Labels.

labelSignificant

protected int labelSignificant
Number of Significant figures to use in drawing Labels.

labelLevels

protected int labelLevels
Which levels will get labels. If it is equal to 1 every level gets a label, equal to 2 every second level etc.
If it is equal to 0 no labels are displayed.

drawlabels

protected boolean drawlabels
If false labels are not drawn.

autoLabels

protected boolean autoLabels
If true the labels will be calculated for each contour level.
These might not look all that hot.

contourColor

protected java.awt.Color contourColor
Color to draw non labelled contour line.

labelledColor

protected java.awt.Color labelledColor
Color to draw labelled contour line

grid

protected double[] grid
The data grid, a 2D array stored in linear form.
It is assumed that [0,0] is the bottom left corner and the data is ordered by row.

xmin

protected double xmin
The X minimum limit of the data grid.

xmax

protected double xmax
The X maximum limit of the data grid.

ymin

protected double ymin
The Y minimum limit of the data grid.

ymax

protected double ymax
The Y maximum limit of the data grid.

zmin

protected double zmin
The minimum value of the grid values.

zmax

protected double zmax
The maximum value of the grid values.

noContours

public boolean noContours
Boolean value if true Contours will not be calculated.

defaultContourKeyListener

protected java.awt.event.KeyListener defaultContourKeyListener
Constructor Detail

Contour

public Contour()
Instantiates the class.
Method Detail

loadGrid

public boolean loadGrid(java.net.URL file)
Loads the grid to contour from a URL.
There are 2 formats for the data optionally the limits of the grid can be parsed. 1st Number: nx 2nd Number: ny nx*ny numbers following

Optionally :

           1st Number:   nx
           2nd Number:   ny
           3rd Number:   xmin
           4th Number:   xmax
           5th Number:   ymin
           6th Number:   ymax
           nx*ny numbers following
 

If xmin, xmax, ymin, ymax are not specified they are assumed to be [1.0,nx,1.0,ny].

Parameters:
file - URL of the file to load.
Returns:
true of the load was successful.

setRange

public void setRange(double xmin,
                     double xmax,
                     double ymin,
                     double ymax)
Sets the range of the grid.
Parameters:
xmin - Minimum X value.
xmax - Maximum X value.
ymin - Minimum Y value.
ymax - Maximum Y value.

getRange

public double[] getRange()
Returns the range of the grid.
Returns:
An array contining xmin, xmax, ymin, ymax.

getDim

public int[] getDim()
Returns the dimensions of the grid.
Returns:
An array containing the number of columns, number of rows.

getGrid

public double[] getGrid()
Returns the grid
Returns:
An array of size nx by ny contining the data grid.

setLevels

public void setLevels(double[] levels,
                      int nl)
Manually sets the contour levels.
Parameters:
levels - An array containing the contour levels.
nl - The number of contour levels in the arrray.

setLabels

public void setLabels(TextLine[] labels,
                      int nl)
Manually sets the Contour labels.
Parameters:
labels - An array containing the labels.
nl - Number of labels in the Array.

setLabelFont

public void setLabelFont(java.awt.Font f)
Sets the font to be used with all the labels.
Parameters:
f - Font.

setLabelColor

public void setLabelColor(java.awt.Color c)
Sets the Color to be used with all the labels.
Parameters:
c - Color.

setGrid

public void setGrid(double[] grid,
                    int nx,
                    int ny)
Sets the grid to be contoured.
Parameters:
grid - Array of values.
nx - Number of columns.
ny - Number of rows.

deleteContours

public void deleteContours()
Delete all the Contours.

detachContours

public void detachContours()
Detaches contours so that they will not be plotted.

attachContours

public void attachContours()
Attaches contours so that they will be plotted.

setContourColor

public void setContourColor(java.awt.Color c)
Sets the contour's color.
Parameters:
c - Color.

setLabelledContourColor

public void setLabelledContourColor(java.awt.Color c)
Sets the labelled contour's color.
Parameters:
c - Color.

getLevels

public double[] getLevels()
Returns the contour levels.
Returns:
An array containing the contour levels.

setLimitsToGrid

public void setLimitsToGrid(boolean b)
If true the limits of the plot will be the grid limits. If false the limits of the plot will be the contours.
Parameters:
b - boolean

setLabelLevels

public void setLabelLevels(int i)
Sets the contour levels that are to have labels.
    if 0 no labels are drawn ;
    if 1 every level gets a label ;
    If 2 every 2nd level gets a label ;
    etc.
 

setLogLevels

public void setLogLevels(boolean b)
If true contour levels are calculated on a log scale.
Parameters:
b - boolean

setNLevels

public void setNLevels(int l)
Sets the number of contour levels.

setAutoLevels

public void setAutoLevels(boolean b)
If true, contour levels are calculated automatically.
Parameters:
b - boolean

setDrawLabels

public void setDrawLabels(boolean b)
If true contour levels are not labeled.
Parameters:
b - boolean

setLabelStyle

public void setLabelStyle(int s)
Sets the label style, either TextLine.SCIENTIFIC or TextLine.ALGEBRAIC.
Parameters:
s - Style

getLabelStyle

public int getLabelStyle()
Gets the label style, either TextLine.SCIENTIFIC or TextLine.ALGEBRAIC.
Returns:
style

setLabelPrecision

public void setLabelPrecision(int p)
Sets the label precision.
Parameters:
s - Precision

getLabelPrecision

public int getLabelPrecision()
Gets the label precision.
Returns:
precision

setLabelSignificance

public void setLabelSignificance(int s)
Sets the label significant figures.
Parameters:
s - Number of significant figures.

getLabelSignificance

public int getLabelSignificance()
Gets the number of significant figures for labels.
Returns:
number of significant figures.

calcLevels

private void calcLevels()
Calculates the contour levels.

calcLabels

private void calcLabels()
Calculates the labels.

zrange

private void zrange()
Calculates the range of the grid

paintFirst

public void paintFirst(java.awt.Graphics g,
                       java.awt.Rectangle r)
Befores anything is painted, calculates the contours.
Overrides:
paintFirst in class Graph2D

setContourColors

private void setContourColors()
Sets the colors for the contour lines.

setContourColors

private void setContourColors(java.util.Vector v,
                              java.awt.Color c)
Sets the colors for the contour lines.

attachCurves

private void attachCurves()
Attaches all the curves to the graph and to the axes

attachCurves

private void attachCurves(java.util.Vector v)
Attaches all the curves from a given level to the graph and to the axes.

detachCurves

private void detachCurves()
Detaches All the curves from the graph and the axes.

detachCurves

private void detachCurves(java.util.Vector v)
Detaches all the curves from a given level from the graph and the axes.

paintLast

public void paintLast(java.awt.Graphics g,
                      java.awt.Rectangle rect)
Last thing to be done is to draw the contour labels if required.
Overrides:
paintLast in class Graph2D

calculateCurves

protected void calculateCurves()
Calculates the contours and attach them to the graph and axes.