Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jplot
Class Graph  view Graph download Graph.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byjplot.Graph
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable
Direct Known Subclasses:
Graph_2D, Graph_Piper

public abstract class Graph
extends javax.swing.JPanel
implements java.awt.print.Printable

The Graph class builds a panel which displays a graph according to the data stored in the DataArray. Extends JPanel since the graph is returned in a panel (it can be used in other applications or embedded in a frame. Implements Printable, so we can print the graph, and ComponentListener, needed to listen to a resize event. This class should be subclassed in order to build a specific graph type (i.e. a 2D graph, piper diagram or 3D, later)

Version:
24/08/99

Nested Class Summary
 class Graph.DragListener
           
 class Graph.GraphMouseListener
           
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  double arc
           
protected  double[] axisLength
           
protected  java.awt.image.BufferedImage bi
           
protected  double borderWidth
           
protected  double bottomMargin
           
private  java.awt.Color boxColor
           
protected  int boxHeight
           
protected  int boxWidth
           
protected  double cos
           
(package private)  java.util.Vector data
           
protected  double[] diff
           
protected  GraphPars gp
           
protected  int height
           
private  boolean initializing
           
protected  double[] inv
           
private  JPlot jplot
           
protected  double keyLen
           
protected  double ldy
           
protected  double leftMargin
           
protected  boolean legendActive
           
protected  double legendHeight
           
protected  double legendWidth
           
protected  java.awt.geom.Line2D.Double line
           
private static double LNTEN
           
protected  int Na
           
protected  double normalSep
           
protected  int[] numberOfTics
           
protected  java.awt.Dimension panelSize
           
protected  java.awt.Dimension panelSizeForPrinter
           
protected  double piperSep
           
protected  java.awt.geom.Rectangle2D.Double rect
           
protected  double rightMargin
           
protected  double[] sep
           
protected  double sin
           
protected  boolean somethingActive
           
protected  double tan
           
protected  java.lang.String[][] ticLabel
           
protected  double[] ticLength
           
protected  double topMargin
           
protected  double triangleBottom
           
protected  double triangleHeight
           
protected  double triangleSide
           
protected  int width
           
protected  int X
           
protected  int x1
           
protected  float xSep
           
protected  int xStart
           
protected  int Y
           
protected  int y1
           
protected  float ySep
           
protected  int yStart
           
 
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.Container
 
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
Graph(JPlot jp, GraphPars gp)
          Main constructor.
 
Method Summary
protected  double calculateTicSep(double min, double max)
          Calculation of the separation length between tics.
protected  java.awt.Graphics2D createGraphics()
          This function builds the graph in a double-buffered image zone.
protected  void drawLegend(java.awt.Graphics2D g2, DataArray da, int i)
           
(package private) static void drawPointType(int index, java.awt.Graphics2D g2, double _x, double _y, float ps)
          Draws a point-type corresponding to a symbolic constant, yielding values from 0 to gp.NO_SYMBOL (==13).
(package private) abstract  void fillGraphArea(java.awt.Graphics2D g2)
          Fills the graph area with a background color.
private  void finishZoom(int x1, int y1, int x2, int y2)
          Set the size of the plot.
static java.lang.String formatNumber(double num, int n)
          formats a double precision number such that it is correctly rounded for output.
 java.awt.image.BufferedImage getBufferedImage(java.awt.Dimension size)
          Creates the graph and returns the graph in a buffer.
protected  void getLegendBox(java.util.Vector data)
           
 java.awt.Dimension getMinimumSize()
          Get the minimum size of this component.
static int getNumDigits(double num)
          Return the number of digits required to display the given number.
 java.awt.Dimension getPreferredSize()
          Get the preferred size of this component.
static double log10(double x)
          Returns the log10 of a double value.
(package private) abstract  void makeTicLabels()
          Determine the axis labels, if needed.
 void paintComponent(java.awt.Graphics g)
          Overloaded paintComponent, is called at each repaint.
protected  void plotLabels(java.awt.Graphics2D g2)
           
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
          This method prints the specified page to the specified graphics context in the specified format.
 void resetLabelPositions(double w0, double h0, double w1, double h1)
           
private  void setDefaultLabelPositions(double m)
           
(package private) abstract  boolean setMinMax(int axis, java.util.Vector data)
          Find the minimum and maximum values for X- and Y axes.
protected  void show(java.util.Vector data)
          Draws the graph on the graphics canvas of this panel.
(package private) abstract  double toX(double x)
          Returns the X-value scaled to the pixel-availability.
(package private) abstract  double toY(double x)
          Returns the Y-value scaled to the pixel-availability.
(package private) abstract  void updateGraph()
          This function builds the graph in a double-buffered image zone.
protected  void updateMargins()
          This method updates the margins as a function of the label widths and the axes texts.
private  void zoomRect(int x, int y)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, 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, processMouseEvent, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

java.util.Vector data

X

protected final int X
See Also:
Constant Field Values

Y

protected final int Y
See Also:
Constant Field Values

Na

protected final int Na
See Also:
Constant Field Values

axisLength

protected double[] axisLength

leftMargin

protected double leftMargin

rightMargin

protected double rightMargin

bottomMargin

protected double bottomMargin

topMargin

protected double topMargin

ticLabel

protected java.lang.String[][] ticLabel

ticLength

protected double[] ticLength

diff

protected double[] diff

inv

protected double[] inv

numberOfTics

protected int[] numberOfTics

sep

protected double[] sep

legendActive

protected boolean legendActive

somethingActive

protected boolean somethingActive

xSep

protected final float xSep
See Also:
Constant Field Values

ySep

protected final float ySep
See Also:
Constant Field Values

gp

protected GraphPars gp

ldy

protected double ldy

keyLen

protected double keyLen

legendWidth

protected double legendWidth

legendHeight

protected double legendHeight

panelSize

protected java.awt.Dimension panelSize

panelSizeForPrinter

protected java.awt.Dimension panelSizeForPrinter

width

protected int width

height

protected int height

boxColor

private final java.awt.Color boxColor

LNTEN

private static final double LNTEN

line

protected java.awt.geom.Line2D.Double line

rect

protected java.awt.geom.Rectangle2D.Double rect

x1

protected int x1

y1

protected int y1

boxWidth

protected int boxWidth

boxHeight

protected int boxHeight

xStart

protected int xStart

yStart

protected int yStart

bi

protected java.awt.image.BufferedImage bi

initializing

private boolean initializing

piperSep

protected double piperSep

normalSep

protected double normalSep

triangleBottom

protected double triangleBottom

triangleSide

protected double triangleSide

triangleHeight

protected double triangleHeight

borderWidth

protected double borderWidth

arc

protected double arc

tan

protected double tan

sin

protected double sin

cos

protected double cos

jplot

private JPlot jplot
Constructor Detail

Graph

public Graph(JPlot jp,
             GraphPars gp)
Main constructor.

Method Detail

getMinimumSize

public java.awt.Dimension getMinimumSize()
Get the minimum size of this component. This is the panel size defined by width and height.


getPreferredSize

public java.awt.Dimension getPreferredSize()
Get the preferred size of this component. This is the panel size defined by width and height


finishZoom

private void finishZoom(int x1,
                        int y1,
                        int x2,
                        int y2)
Set the size of the plot.


zoomRect

private void zoomRect(int x,
                      int y)

log10

public static double log10(double x)
Returns the log10 of a double value.


calculateTicSep

protected double calculateTicSep(double min,
                                 double max)
Calculation of the separation length between tics. Some smart rounding algorithms are needed to get the scaling properly in case of data going to 10.3 or so... Usefull stuff stolen from the Gnuplot sources, thank you guys!!


getNumDigits

public static int getNumDigits(double num)
Return the number of digits required to display the given number. If more than 15 digits are required, 15 is returned).


formatNumber

public static java.lang.String formatNumber(double num,
                                            int n)
formats a double precision number such that it is correctly rounded for output. Kind of pre-processor for all number for output.


makeTicLabels

abstract void makeTicLabels()
Determine the axis labels, if needed. These are numbers which are translated in Strings. The length is evalulated and used to set the left and bottom margins.


updateMargins

protected void updateMargins()
This method updates the margins as a function of the label widths and the axes texts. Also sets the default positions of the text labels.


setDefaultLabelPositions

private void setDefaultLabelPositions(double m)

setMinMax

abstract boolean setMinMax(int axis,
                           java.util.Vector data)
Find the minimum and maximum values for X- and Y axes.


plotLabels

protected void plotLabels(java.awt.Graphics2D g2)

getLegendBox

protected void getLegendBox(java.util.Vector data)

drawLegend

protected void drawLegend(java.awt.Graphics2D g2,
                          DataArray da,
                          int i)

toX

abstract double toX(double x)
Returns the X-value scaled to the pixel-availability. This function takes the X-value and returns the corresponding coordinates for the panel.


toY

abstract double toY(double x)
Returns the Y-value scaled to the pixel-availability. This function takes the Y-value and returns the corresponding coordinates for the panel.


fillGraphArea

abstract void fillGraphArea(java.awt.Graphics2D g2)
Fills the graph area with a background color.


show

protected void show(java.util.Vector data)
Draws the graph on the graphics canvas of this panel. Performs a test on the minimum and maximum values. If they are different by more than 10 % with respect to their previous values, release all fixed positions of legend, labels etc and restore the default positions. Otherwise, they may fall far beyond the screen, leading to a coredump.


resetLabelPositions

public void resetLabelPositions(double w0,
                                double h0,
                                double w1,
                                double h1)

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage(java.awt.Dimension size)
Creates the graph and returns the graph in a buffer. The graph is drawn using the specified dimension. This class stores the current widht/height of the graph and changes the margins (computation-intensive) only if the size is actually different from the current settings.


paintComponent

public void paintComponent(java.awt.Graphics g)
Overloaded paintComponent, is called at each repaint. If the panel size changed then the user probably resized the window with the mouse and we have to reset the margins of the graph.


createGraphics

protected java.awt.Graphics2D createGraphics()
This function builds the graph in a double-buffered image zone.


updateGraph

abstract void updateGraph()
This function builds the graph in a double-buffered image zone.


drawPointType

static void drawPointType(int index,
                          java.awt.Graphics2D g2,
                          double _x,
                          double _y,
                          float ps)
Draws a point-type corresponding to a symbolic constant, yielding values from 0 to gp.NO_SYMBOL (==13).


print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
          throws java.awt.print.PrinterException
Description copied from interface: java.awt.print.Printable
This method prints the specified page to the specified graphics context in the specified format. The pages are numbered starting from zero.

Specified by:
print in interface java.awt.print.Printable