mev-4.0.01/source/org/tigr/graph/GraphCanvas.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: GraphCanvas.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.5 $
2 26 Feb 07 jari 8  * $Date: 2006/02/23 20:59:40 $
2 26 Feb 07 jari 9  * $Author: caliente $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.graph;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.awt.Color;
2 26 Feb 07 jari 15 import java.awt.Font;
2 26 Feb 07 jari 16 import java.awt.Graphics;
2 26 Feb 07 jari 17 import java.awt.Graphics2D;
2 26 Feb 07 jari 18 import java.util.Vector;
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20 public class GraphCanvas extends Drawable {
2 26 Feb 07 jari 21     
2 26 Feb 07 jari 22     public final static int SYSTEM_QUADRANT1_ONLY = 1000;
2 26 Feb 07 jari 23     public final static int SYSTEM_QUADRANT12_ONLY = 1001;
2 26 Feb 07 jari 24     public final static int SYSTEM_ALL_QUADRANTS = 1002;
2 26 Feb 07 jari 25     public final static int SYSTEM_BOUNDS = 1100;
2 26 Feb 07 jari 26     public final static int HISTOGRAM_BAR_OUTLINE = 2000;
2 26 Feb 07 jari 27     public final static int HISTOGRAM_BAR_SOLID = 2001;
2 26 Feb 07 jari 28     public final static int GRAPH_POINTS_SEPERATE = 3000;
2 26 Feb 07 jari 29     public final static int GRAPH_POINTS_CONNECT = 3001;
2 26 Feb 07 jari 30     
2 26 Feb 07 jari 31     protected double graphStartX, graphStopX, graphStartY, graphStopY;
2 26 Feb 07 jari 32     protected int preXSpacing, postXSpacing, preYSpacing, postYSpacing;
2 26 Feb 07 jari 33     protected double xAxisValue, yAxisValue;
2 26 Feb 07 jari 34     
2 26 Feb 07 jari 35     public boolean fixedHeight, fixedWidth;
2 26 Feb 07 jari 36     public int graphHeight, graphWidth;
2 26 Feb 07 jari 37     
2 26 Feb 07 jari 38     public boolean referenceLinesOn = true;
2 26 Feb 07 jari 39     public String title, xLabel, yLabel;
2 26 Feb 07 jari 40     protected Font tickFont, labelFont, titleFont;
2 26 Feb 07 jari 41     protected int tickFontHeight, tickFontWidth, labelFontHeight, labelFontWidth, titleFontHeight, titleFontWidth;
2 26 Feb 07 jari 42     
2 26 Feb 07 jari 43     protected Vector graphElements;
2 26 Feb 07 jari 44     
2 26 Feb 07 jari 45     public GraphCanvas() {
2 26 Feb 07 jari 46   initialize();
2 26 Feb 07 jari 47     }
2 26 Feb 07 jari 48     
2 26 Feb 07 jari 49     public GraphCanvas(int graphHeight, int graphWidth) {
2 26 Feb 07 jari 50   this.fixedHeight = true;
2 26 Feb 07 jari 51   this.fixedWidth = true;
2 26 Feb 07 jari 52   this.graphHeight = graphHeight;
2 26 Feb 07 jari 53   this.graphWidth = graphWidth;
2 26 Feb 07 jari 54   
2 26 Feb 07 jari 55   initialize();
2 26 Feb 07 jari 56     }
2 26 Feb 07 jari 57     
2 26 Feb 07 jari 58     public void initialize() {
2 26 Feb 07 jari 59   graphElements = new Vector();
2 26 Feb 07 jari 60   setDoubleBuffered(true);
2 26 Feb 07 jari 61   setBackground(Color.white);
2 26 Feb 07 jari 62   
2 26 Feb 07 jari 63   setTickFont("monospaced", Font.PLAIN, 10);
2 26 Feb 07 jari 64   setLabelFont("monospaced", Font.PLAIN, 12);
2 26 Feb 07 jari 65   setTitleFont("monospaced", Font.PLAIN, 16);
2 26 Feb 07 jari 66     }
2 26 Feb 07 jari 67     
2 26 Feb 07 jari 68     public void controlPaint(Graphics g1D) {
2 26 Feb 07 jari 69   Graphics2D g = (Graphics2D) g1D;
2 26 Feb 07 jari 70   drawGraph(g);
2 26 Feb 07 jari 71     }
2 26 Feb 07 jari 72     
2 26 Feb 07 jari 73     public void setTickFont(String fontName, int fontStyle, int fontSize) {
2 26 Feb 07 jari 74   tickFont = new Font(fontName, fontStyle, fontSize);
2 26 Feb 07 jari 75   tickFontWidth = (int) (.6 * fontSize);
2 26 Feb 07 jari 76   tickFontHeight = fontSize;
2 26 Feb 07 jari 77     }
2 26 Feb 07 jari 78     
2 26 Feb 07 jari 79     public void setLabelFont(String fontName, int fontStyle, int fontSize) {
2 26 Feb 07 jari 80   labelFont = new Font(fontName, fontStyle, fontSize);
2 26 Feb 07 jari 81   labelFontWidth = (int) (.6 * fontSize);
2 26 Feb 07 jari 82   labelFontHeight = fontSize;
2 26 Feb 07 jari 83     }
2 26 Feb 07 jari 84     
2 26 Feb 07 jari 85     public void setTitleFont(String fontName, int fontStyle, int fontSize) {
2 26 Feb 07 jari 86   titleFont = new Font(fontName, fontStyle, fontSize);
2 26 Feb 07 jari 87   titleFontWidth = (int) (.6 * fontSize);
2 26 Feb 07 jari 88   titleFontHeight = fontSize;
2 26 Feb 07 jari 89     }
2 26 Feb 07 jari 90     
2 26 Feb 07 jari 91     public void drawGraph(Graphics2D g) {
2 26 Feb 07 jari 92   
2 26 Feb 07 jari 93   drawSystem(g, SYSTEM_BOUNDS);
2 26 Feb 07 jari 94   
2 26 Feb 07 jari 95   for (int i = 0; i < graphElements.size(); i++) {
2 26 Feb 07 jari 96       drawGraphElement(g, (GraphElement) graphElements.elementAt(i));
2 26 Feb 07 jari 97   }
2 26 Feb 07 jari 98   
2 26 Feb 07 jari 99   if (referenceLinesOn) { //Grid tracing is active
2 26 Feb 07 jari 100       //  drawReferenceLines(g);
2 26 Feb 07 jari 101   }
2 26 Feb 07 jari 102   
2 26 Feb 07 jari 103   drawXLabel(g, xLabel, Color.black);
2 26 Feb 07 jari 104   drawYLabel(g, yLabel, Color.black);
2 26 Feb 07 jari 105   drawTitle(g, title, Color.black);
2 26 Feb 07 jari 106     }
2 26 Feb 07 jari 107     
2 26 Feb 07 jari 108     public void drawGraphElement(Graphics2D g, GraphElement e) {
2 26 Feb 07 jari 109   if (e instanceof GraphPoint) drawPoint(g, (GraphPoint) e);
2 26 Feb 07 jari 110   else if (e instanceof GraphBar) drawBar(g, (GraphBar) e);
2 26 Feb 07 jari 111   else if (e instanceof GraphTick) drawTick(g, (GraphTick) e);
2 26 Feb 07 jari 112   else if (e instanceof GraphLine) drawLine(g, (GraphLine) e);
2 26 Feb 07 jari 113   else if (e instanceof GraphPointGroup) drawPointGroup(g, (GraphPointGroup) e);
2 26 Feb 07 jari 114     }
2 26 Feb 07 jari 115     
2 26 Feb 07 jari 116   /*
2 26 Feb 07 jari 117   public void drawReferenceLines(Graphics2D g) {
2 26 Feb 07 jari 118     drawReferenceLines(g, getXOldEvent(), getYOldEvent());
2 26 Feb 07 jari 119   }
2 26 Feb 07 jari 120    */
2 26 Feb 07 jari 121     
2 26 Feb 07 jari 122     public void drawReferenceLines(Graphics2D g, int x, int y) {
2 26 Feb 07 jari 123   if ((x <= convertX(graphStopX)) && (x >= convertX(graphStartX))) {
2 26 Feb 07 jari 124       g.setColor(Color.magenta);
2 26 Feb 07 jari 125       g.drawLine(x, convertY(graphStartY), x, convertY(graphStopY));
2 26 Feb 07 jari 126   }
2 26 Feb 07 jari 127   
2 26 Feb 07 jari 128   if ((y >= convertY(graphStopY)) && (y <= convertY(graphStartY))) {
2 26 Feb 07 jari 129       g.setColor(Color.magenta);
2 26 Feb 07 jari 130       g.drawLine(convertX(graphStartX), y, convertX(graphStopX), y);
2 26 Feb 07 jari 131   }
2 26 Feb 07 jari 132     }
2 26 Feb 07 jari 133     
2 26 Feb 07 jari 134     public void addGraphElement(GraphElement e) {
2 26 Feb 07 jari 135   graphElements.addElement(e);
2 26 Feb 07 jari 136     }
2 26 Feb 07 jari 137     
2 26 Feb 07 jari 138     public void removeAllGraphElements() {
2 26 Feb 07 jari 139   graphElements = new Vector();
2 26 Feb 07 jari 140     }
2 26 Feb 07 jari 141     
2 26 Feb 07 jari 142     public void clearAll(Graphics2D g) {
2 26 Feb 07 jari 143   fillRect(g, 0, 0, getSize().width, getSize().height, getBackground());
2 26 Feb 07 jari 144     }
2 26 Feb 07 jari 145     
2 26 Feb 07 jari 146     public void setGraphStartX(double graphStartX) {this.graphStartX = graphStartX;}
2 26 Feb 07 jari 147     public double getGraphStartX() {return this.graphStartX;}
2 26 Feb 07 jari 148     public void setGraphStartY(double graphStartY) {this.graphStartY = graphStartY;}
2 26 Feb 07 jari 149     public double getGraphStartY() {return this.graphStartY;}
2 26 Feb 07 jari 150     public void setGraphStopX(double graphStopX) {this.graphStopX = graphStopX;}
2 26 Feb 07 jari 151     public double getGraphStopX() {return this.graphStopX;}
2 26 Feb 07 jari 152     public void setGraphStopY(double graphStopY) {this.graphStopY = graphStopY;}
2 26 Feb 07 jari 153     public double getGraphStopY() {return this.graphStopY;}
2 26 Feb 07 jari 154     public void setGraphBounds(double graphStartX, double graphStopX, double graphStartY, double graphStopY) {
2 26 Feb 07 jari 155   this.graphStartX = graphStartX;
2 26 Feb 07 jari 156   this.graphStopX = graphStopX;
2 26 Feb 07 jari 157   this.graphStartY = graphStartY;
2 26 Feb 07 jari 158   this.graphStopY = graphStopY;
2 26 Feb 07 jari 159     }
2 26 Feb 07 jari 160     
2 26 Feb 07 jari 161     public void setPreXSpacing(int preXSpacing) {this.preXSpacing = preXSpacing;}
2 26 Feb 07 jari 162     public int getPreXSpacing() {return this.preXSpacing;}
2 26 Feb 07 jari 163     public void setPostXSpacing(int postXSpacing) {this.postXSpacing = postXSpacing;}
2 26 Feb 07 jari 164     public int getPostXSpacing() {return this.postXSpacing;}
2 26 Feb 07 jari 165     public void setPreYSpacing(int preYSpacing) {this.preYSpacing = preYSpacing;}
2 26 Feb 07 jari 166     public int getPreYSpacing() {return this.preYSpacing;}
2 26 Feb 07 jari 167     public void setPostYSpacing(int postYSpacing) {this.postYSpacing = postYSpacing;}
2 26 Feb 07 jari 168     public int getPostYSpacing() {return this.postYSpacing;}
2 26 Feb 07 jari 169     public void setGraphSpacing(int preXSpacing, int postXSpacing, int preYSpacing, int postYSpacing) {
2 26 Feb 07 jari 170   this.preXSpacing = preXSpacing;
2 26 Feb 07 jari 171   this.postXSpacing = postXSpacing;
2 26 Feb 07 jari 172   this.preYSpacing = preYSpacing;
2 26 Feb 07 jari 173   this.postYSpacing = postYSpacing;
2 26 Feb 07 jari 174     }
2 26 Feb 07 jari 175     
2 26 Feb 07 jari 176     public void setXAxisValue(double x) {this.xAxisValue = x;}
2 26 Feb 07 jari 177     public double getXAxisValue() {return this.xAxisValue;}
2 26 Feb 07 jari 178     public void setYAxisValue(double y) {this.yAxisValue = y;}
2 26 Feb 07 jari 179     public double getYAxisValue() {return this.yAxisValue;}
2 26 Feb 07 jari 180     
2 26 Feb 07 jari 181     public void drawSystem(Graphics2D g, int systemStyle) {
2 26 Feb 07 jari 182   switch (systemStyle) {
2 26 Feb 07 jari 183       case SYSTEM_BOUNDS:
2 26 Feb 07 jari 184     drawLine(g, new GraphPoint(graphStartX, xAxisValue), new GraphPoint(graphStopX, xAxisValue), Color.black);
2 26 Feb 07 jari 185     drawLine(g, new GraphPoint(yAxisValue, graphStartY), new GraphPoint(yAxisValue, graphStopY), Color.black);
2 26 Feb 07 jari 186     break;
2 26 Feb 07 jari 187       case SYSTEM_QUADRANT1_ONLY:
2 26 Feb 07 jari 188     break;
2 26 Feb 07 jari 189       case SYSTEM_QUADRANT12_ONLY:
2 26 Feb 07 jari 190     break;
2 26 Feb 07 jari 191       case SYSTEM_ALL_QUADRANTS:
2 26 Feb 07 jari 192     break;
2 26 Feb 07 jari 193   }
2 26 Feb 07 jari 194     }
2 26 Feb 07 jari 195     
2 26 Feb 07 jari 196     public int getWidth() {
2 26 Feb 07 jari 197   if (fixedWidth) {
2 26 Feb 07 jari 198       return graphWidth;
2 26 Feb 07 jari 199   } else {
2 26 Feb 07 jari 200       return getSize().width;
2 26 Feb 07 jari 201   }
2 26 Feb 07 jari 202     }
2 26 Feb 07 jari 203     
2 26 Feb 07 jari 204     public int getHeight() {
2 26 Feb 07 jari 205   if (fixedHeight) {
2 26 Feb 07 jari 206       return graphHeight;
2 26 Feb 07 jari 207   } else {
2 26 Feb 07 jari 208       return getSize().height;
2 26 Feb 07 jari 209   }
2 26 Feb 07 jari 210     }
2 26 Feb 07 jari 211     
2 26 Feb 07 jari 212     protected double getXScale() {
2 26 Feb 07 jari 213   return ((getWidth() - preXSpacing - postXSpacing) / (graphStopX - graphStartX));
2 26 Feb 07 jari 214     }
2 26 Feb 07 jari 215     
2 26 Feb 07 jari 216     protected double getYScale() {
2 26 Feb 07 jari 217   return ((getHeight() - preYSpacing - postYSpacing) / (graphStopY - graphStartY));
2 26 Feb 07 jari 218     }
2 26 Feb 07 jari 219     
2 26 Feb 07 jari 220     protected int convertX(double x) {
2 26 Feb 07 jari 221   return (int) ((x - graphStartX) * getXScale() + preXSpacing);
2 26 Feb 07 jari 222     }
2 26 Feb 07 jari 223     
2 26 Feb 07 jari 224     protected int convertY(double y) {
2 26 Feb 07 jari 225   return (int) ((graphStopY - y) * getYScale() + preYSpacing);
2 26 Feb 07 jari 226     }
2 26 Feb 07 jari 227     
2 26 Feb 07 jari 228     public void drawTick(Graphics2D g, GraphTick e) {
2 26 Feb 07 jari 229   if (e.getOrientation() == GC.HORIZONTAL) {
2 26 Feb 07 jari 230       if (e.getLabel() != "") {
2 26 Feb 07 jari 231     drawVerticalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor(), e.getLabel(), e.getLabelColor());
2 26 Feb 07 jari 232       } else {
2 26 Feb 07 jari 233     drawVerticalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor());
2 26 Feb 07 jari 234       }
2 26 Feb 07 jari 235       
2 26 Feb 07 jari 236   } else if (e.getOrientation() == GC.VERTICAL) {
2 26 Feb 07 jari 237       if (e.getLabel() != "") {
2 26 Feb 07 jari 238     drawHorizontalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor(), e.getLabel(), e.getLabelColor());
2 26 Feb 07 jari 239       } else {
2 26 Feb 07 jari 240     drawHorizontalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor());
2 26 Feb 07 jari 241       }
2 26 Feb 07 jari 242   }
2 26 Feb 07 jari 243     }
2 26 Feb 07 jari 244     
2 26 Feb 07 jari 245     public void drawVerticalTick(Graphics2D g, double x, int length, int alignment, Color color) {
2 26 Feb 07 jari 246   if (x < graphStartX || x > graphStopX) return;
2 26 Feb 07 jari 247   
2 26 Feb 07 jari 248   switch (alignment) {
2 26 Feb 07 jari 249       case GC.C:
2 26 Feb 07 jari 250     drawLine(g, convertX(x), convertY(xAxisValue) - (int) (length / 2), convertX(x), convertY(xAxisValue) + (int) (length / 2), color);
2 26 Feb 07 jari 251     break;
2 26 Feb 07 jari 252       case GC.N:
2 26 Feb 07 jari 253     drawLine(g, convertX(x), convertY(xAxisValue), convertX(x), convertY(xAxisValue) - length, color);
2 26 Feb 07 jari 254     break;
2 26 Feb 07 jari 255       case GC.S:
2 26 Feb 07 jari 256     drawLine(g, convertX(x), convertY(xAxisValue), convertX(x), convertY(xAxisValue) + length, color);
2 26 Feb 07 jari 257     break;
2 26 Feb 07 jari 258   }
2 26 Feb 07 jari 259     }
2 26 Feb 07 jari 260     
2 26 Feb 07 jari 261     public void drawVerticalTick(Graphics2D g, double x, int length, int alignment, Color color, String label, Color tickColor) {
2 26 Feb 07 jari 262   drawVerticalTick(g, x, length, alignment, color);
2 26 Feb 07 jari 263   
2 26 Feb 07 jari 264   if (true) { //Rotate labels
2 26 Feb 07 jari 265       g.rotate(- Math.PI / 2);
2 26 Feb 07 jari 266       drawString(g, label, - getHeight() + postYSpacing - (label.length() * tickFontWidth) - length,
2 26 Feb 07 jari 267       convertX(x) + (tickFontHeight / 2), tickColor, tickFont);
2 26 Feb 07 jari 268       g.rotate(Math.PI / 2);
2 26 Feb 07 jari 269   } else {
2 26 Feb 07 jari 270       drawString(g, label, convertX(x) - (label.length() * tickFontWidth / 2),
2 26 Feb 07 jari 271       getHeight() - postYSpacing + length + 10, tickColor, tickFont);
2 26 Feb 07 jari 272   }
2 26 Feb 07 jari 273     }
2 26 Feb 07 jari 274     
2 26 Feb 07 jari 275     public void drawHorizontalTick(Graphics2D g, double y, int length, int alignment, Color color) {
2 26 Feb 07 jari 276   if (y < graphStartY || y > graphStopY) return;
2 26 Feb 07 jari 277   
2 26 Feb 07 jari 278   switch (alignment) {
2 26 Feb 07 jari 279       case GC.C:
2 26 Feb 07 jari 280     drawLine(g, convertX(yAxisValue) - (int) (length / 2), convertY(y), convertX(yAxisValue) + (int) (length / 2), convertY(y), color);
2 26 Feb 07 jari 281     break;
2 26 Feb 07 jari 282       case GC.E:
2 26 Feb 07 jari 283     drawLine(g, convertX(yAxisValue), convertY(y), convertX(yAxisValue) + length, convertY(y), color);
2 26 Feb 07 jari 284     break;
2 26 Feb 07 jari 285       case GC.W:
2 26 Feb 07 jari 286     drawLine(g, convertX(yAxisValue), convertY(y), convertX(yAxisValue) - length, convertY(y), color);
2 26 Feb 07 jari 287     break;
2 26 Feb 07 jari 288   }
2 26 Feb 07 jari 289     }
2 26 Feb 07 jari 290     
2 26 Feb 07 jari 291     // Modifications are necessary...
2 26 Feb 07 jari 292     public void drawHorizontalTick(Graphics2D g, double y, int length, int alignment, Color color, String label, Color tickColor) {
2 26 Feb 07 jari 293   drawHorizontalTick(g, y, length, alignment, color);
2 26 Feb 07 jari 294   
2 26 Feb 07 jari 295   drawString(g, label, preXSpacing - length - (label.length() * tickFontWidth),
2 26 Feb 07 jari 296   convertY(y) + (tickFontHeight / 2), tickColor, tickFont);
2 26 Feb 07 jari 297     }
2 26 Feb 07 jari 298     
2 26 Feb 07 jari 299     public void drawTitle(Graphics2D g, String title, Color titleColor) {
2 26 Feb 07 jari 300   if (title == null) return;
2 26 Feb 07 jari 301   drawString(g, title, getWidth() / 2 - (title.length() * titleFontWidth / 2), titleFontHeight * 2, titleColor, titleFont);
2 26 Feb 07 jari 302     }
2 26 Feb 07 jari 303     
2 26 Feb 07 jari 304     public void drawXLabel(Graphics2D g, String label, Color labelColor) {
2 26 Feb 07 jari 305   if (label == null) return;
2 26 Feb 07 jari 306   drawString(g, label, getWidth() / 2 - (label.length() * labelFontWidth / 2), convertY(graphStartY) + postYSpacing - labelFontHeight, labelColor, labelFont);
2 26 Feb 07 jari 307     }
2 26 Feb 07 jari 308     
2 26 Feb 07 jari 309     public void drawYLabel(Graphics2D g, String label, Color labelColor) {
2 26 Feb 07 jari 310   if (label == null) return;
2 26 Feb 07 jari 311   g.rotate(- Math.PI / 2);
2 26 Feb 07 jari 312   drawString(g, label, - postYSpacing + preXSpacing - (getHeight() / 2) - (label.length() * labelFontWidth / 2), labelFontHeight, labelColor, labelFont);
2 26 Feb 07 jari 313   g.rotate(Math.PI / 2);
2 26 Feb 07 jari 314     }
2 26 Feb 07 jari 315     
2 26 Feb 07 jari 316     public void drawPoint(Graphics2D g, GraphPoint graphPoint) {
2 26 Feb 07 jari 317   drawPointAt(g, graphPoint.getX(), graphPoint.getY(), graphPoint.getColor(), graphPoint.getPointSize());
2 26 Feb 07 jari 318     }
2 26 Feb 07 jari 319     
2 26 Feb 07 jari 320     public void drawPointAt(Graphics2D g, double x, double y, Color pointColor, int pointSize) {
2 26 Feb 07 jari 321   if ((x < graphStartX || x > graphStopX) || (y < graphStartY || y > graphStopY)) return;
2 26 Feb 07 jari 322   
2 26 Feb 07 jari 323   fillRect(g, convertX(x) - (pointSize / 2), convertY(y) - (pointSize / 2), pointSize, pointSize, pointColor);
2 26 Feb 07 jari 324     }
2 26 Feb 07 jari 325     
2 26 Feb 07 jari 326     public void drawPoints(Graphics2D g, Vector graphPoints, int graphPointStyle) {
2 26 Feb 07 jari 327   GraphPoint graphPoint, graphPoint2 = null;
2 26 Feb 07 jari 328   
2 26 Feb 07 jari 329   switch (graphPointStyle) {
2 26 Feb 07 jari 330       case GRAPH_POINTS_SEPERATE:
2 26 Feb 07 jari 331     for (int i = 0; i < graphPoints.size(); i++) {
2 26 Feb 07 jari 332         graphPoint = (GraphPoint) graphPoints.elementAt(i);
2 26 Feb 07 jari 333         drawPoint(g, graphPoint);
2 26 Feb 07 jari 334     }
2 26 Feb 07 jari 335     break;
2 26 Feb 07 jari 336       case GRAPH_POINTS_CONNECT:
2 26 Feb 07 jari 337     for (int i = 0; i < graphPoints.size(); i++) {
2 26 Feb 07 jari 338         graphPoint = (GraphPoint) graphPoints.elementAt(i);
2 26 Feb 07 jari 339         if (i == 0) graphPoint2 = graphPoint;
2 26 Feb 07 jari 340         drawLine(g, graphPoint2, graphPoint, Color.black);
2 26 Feb 07 jari 341         drawPoint(g, graphPoint2);
2 26 Feb 07 jari 342         drawPoint(g, graphPoint);
2 26 Feb 07 jari 343         graphPoint2 = graphPoint;
2 26 Feb 07 jari 344     }
2 26 Feb 07 jari 345     break;
2 26 Feb 07 jari 346   }
2 26 Feb 07 jari 347     }
2 26 Feb 07 jari 348     
2 26 Feb 07 jari 349     public void drawPointGroup(Graphics2D g, GraphPointGroup gpg) {
2 26 Feb 07 jari 350   
2 26 Feb 07 jari 351   double[] x = gpg.getX();
2 26 Feb 07 jari 352   double[] y = gpg.getY();
2 26 Feb 07 jari 353   Color pointColor = gpg.getColor();
2 26 Feb 07 jari 354   int pointSize = gpg.getPointSize();
2 26 Feb 07 jari 355   
2 26 Feb 07 jari 356   for (int i = 0; i < Math.min(x.length, y.length); i++) {
2 26 Feb 07 jari 357       drawPointAt(g, x[i], y[i], pointColor, pointSize);
2 26 Feb 07 jari 358   }
2 26 Feb 07 jari 359     }
2 26 Feb 07 jari 360     
2 26 Feb 07 jari 361     public void drawLine(Graphics2D g, GraphLine e) {
2 26 Feb 07 jari 362   drawLine(g, convertX(e.getX1()), convertY(e.getY1()), convertX(e.getX2()), convertY(e.getY2()), e.getColor());
2 26 Feb 07 jari 363     }
2 26 Feb 07 jari 364     
2 26 Feb 07 jari 365     public void drawLine(Graphics2D g, GraphPoint graphPoint1, GraphPoint graphPoint2, Color lineColor) {
2 26 Feb 07 jari 366   drawLine(g, convertX(graphPoint1.getX()), convertY(graphPoint1.getY()),
2 26 Feb 07 jari 367   convertX(graphPoint2.getX()), convertY(graphPoint2.getY()), lineColor);
2 26 Feb 07 jari 368     }
2 26 Feb 07 jari 369     
2 26 Feb 07 jari 370     public void drawBar(Graphics2D g, GraphBar e) {
2 26 Feb 07 jari 371   if (e.getStyle() == GraphBar.VERTICAL) {
2 26 Feb 07 jari 372       drawVerticalHistogramBar(g, e.getLower(), e.getUpper(), e.getValue(), e.getColor(), e.getStyle());
2 26 Feb 07 jari 373   } else if (e.getStyle() == GraphBar.HORIZONTAL) {
2 26 Feb 07 jari 374       //Nothing yet
2 26 Feb 07 jari 375   }
2 26 Feb 07 jari 376     }
2 26 Feb 07 jari 377     
2 26 Feb 07 jari 378     public void drawVerticalHistogramBar(Graphics2D g, double low, double high, double value, Color barColor, int style) {
2 26 Feb 07 jari 379   if ((low < graphStartX || low > graphStopX) || (high < graphStartX || high > graphStopX)) return;
2 26 Feb 07 jari 380   if (value < graphStartY || value > graphStopY) return;
2 26 Feb 07 jari 381   
2 26 Feb 07 jari 382   if (style == GraphBar.OUTLINE) {
2 26 Feb 07 jari 383       drawRect(g, convertX(low), convertY(value), (int) ((high - low) * getXScale()), (int) (value * getYScale()) - 1, barColor);
2 26 Feb 07 jari 384   } else if (style == GraphBar.SOLID) {
2 26 Feb 07 jari 385       fillRect(g, convertX(low), convertY(value), (int) ((high - low) * getXScale()) + 1, (int) (value * getYScale()) + 1, barColor);
2 26 Feb 07 jari 386   }
2 26 Feb 07 jari 387     }
2 26 Feb 07 jari 388     
2 26 Feb 07 jari 389 } //End GraphCanvas