mev-4.0.01/source/org/tigr/graph/GraphViewer.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: GraphViewer.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.6 $
2 26 Feb 07 jari 8  * $Date: 2006/03/24 15:49:44 $
2 26 Feb 07 jari 9  * $Author: eleanorahowe $
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.AlphaComposite;
2 26 Feb 07 jari 15 import java.awt.Color;
2 26 Feb 07 jari 16 import java.awt.Composite;
2 26 Feb 07 jari 17 import java.awt.Cursor;
2 26 Feb 07 jari 18 import java.awt.Font;
2 26 Feb 07 jari 19 import java.awt.FontMetrics;
2 26 Feb 07 jari 20 import java.awt.Graphics;
2 26 Feb 07 jari 21 import java.awt.Graphics2D;
2 26 Feb 07 jari 22 import java.awt.GridBagLayout;
2 26 Feb 07 jari 23 import java.awt.RenderingHints;
2 26 Feb 07 jari 24 import java.awt.event.ActionEvent;
2 26 Feb 07 jari 25 import java.awt.event.ActionListener;
2 26 Feb 07 jari 26 import java.awt.event.KeyEvent;
2 26 Feb 07 jari 27 import java.awt.event.KeyListener;
2 26 Feb 07 jari 28 import java.awt.event.MouseEvent;
2 26 Feb 07 jari 29 import java.awt.event.MouseListener;
2 26 Feb 07 jari 30 import java.awt.event.MouseMotionListener;
2 26 Feb 07 jari 31 import java.awt.event.WindowAdapter;
2 26 Feb 07 jari 32 import java.awt.event.WindowEvent;
2 26 Feb 07 jari 33 import java.awt.image.BufferedImage;
2 26 Feb 07 jari 34 import java.text.DecimalFormat;
2 26 Feb 07 jari 35 import java.util.Hashtable;
2 26 Feb 07 jari 36 import java.util.Vector;
2 26 Feb 07 jari 37
2 26 Feb 07 jari 38 import javax.swing.JCheckBoxMenuItem;
2 26 Feb 07 jari 39 import javax.swing.JFrame;
2 26 Feb 07 jari 40 import javax.swing.JMenu;
2 26 Feb 07 jari 41 import javax.swing.JMenuBar;
2 26 Feb 07 jari 42 import javax.swing.JMenuItem;
2 26 Feb 07 jari 43 import javax.swing.JPopupMenu;
2 26 Feb 07 jari 44 import javax.swing.JScrollPane;
2 26 Feb 07 jari 45 import javax.swing.ScrollPaneConstants;
2 26 Feb 07 jari 46
2 26 Feb 07 jari 47 import org.tigr.util.awt.ActionInfoEvent;
2 26 Feb 07 jari 48 import org.tigr.util.awt.ActionInfoListener;
2 26 Feb 07 jari 49 import org.tigr.util.awt.BoundariesDialog;
2 26 Feb 07 jari 50 import org.tigr.util.awt.Drawable;
2 26 Feb 07 jari 51 import org.tigr.util.awt.GBA;
2 26 Feb 07 jari 52 import org.tigr.util.awt.Viewer;
2 26 Feb 07 jari 53
2 26 Feb 07 jari 54 public class GraphViewer extends Viewer {
2 26 Feb 07 jari 55    public static final long serialVersionUID = 1000101030001L;    
2 26 Feb 07 jari 56     
2 26 Feb 07 jari 57     public final static int SYSTEM_QUADRANT1_ONLY = 1000;
2 26 Feb 07 jari 58     public final static int SYSTEM_QUADRANT12_ONLY = 1001;
2 26 Feb 07 jari 59     public final static int SYSTEM_ALL_QUADRANTS = 1002;
2 26 Feb 07 jari 60     public final static int SYSTEM_BOUNDS = 1100;
2 26 Feb 07 jari 61     public final static int HISTOGRAM_BAR_OUTLINE = 2000;
2 26 Feb 07 jari 62     public final static int HISTOGRAM_BAR_SOLID = 2001;
2 26 Feb 07 jari 63     public final static int GRAPH_POINTS_SEPERATE = 3000;
2 26 Feb 07 jari 64     public final static int GRAPH_POINTS_CONNECT = 3001;
2 26 Feb 07 jari 65     
2 26 Feb 07 jari 66     protected int startx, stopx, starty, stopy;
2 26 Feb 07 jari 67     protected double graphstartx, graphstopx, graphstarty, graphstopy;
2 26 Feb 07 jari 68     protected int preXSpacing, postXSpacing, preYSpacing, postYSpacing;
2 26 Feb 07 jari 69     protected double xAxisValue = 0, yAxisValue = 0;
2 26 Feb 07 jari 70     protected int pointSize;
2 26 Feb 07 jari 71     protected Font tickFont, labelFont, titleFont;
2 26 Feb 07 jari 72     protected int tickFontHeight, tickFontWidth, labelFontHeight, labelFontWidth, titleFontHeight, titleFontWidth;
2 26 Feb 07 jari 73     
2 26 Feb 07 jari 74     protected String title, xLabel, yLabel, subTitle;
2 26 Feb 07 jari 75     
2 26 Feb 07 jari 76     protected JScrollPane scrollPane;
2 26 Feb 07 jari 77     protected JMenuBar menuBar;
2 26 Feb 07 jari 78     protected Drawable canvas;
2 26 Feb 07 jari 79     protected EventListener eventListener;
2 26 Feb 07 jari 80     protected GBA gba;
2 26 Feb 07 jari 81     
2 26 Feb 07 jari 82     protected boolean referenceLinesOn = true;
2 26 Feb 07 jari 83     
2 26 Feb 07 jari 84     private boolean redrawCachedImage = true;
2 26 Feb 07 jari 85     private BufferedImage cachedImage;
2 26 Feb 07 jari 86     
2 26 Feb 07 jari 87     protected Vector graphElements;
2 26 Feb 07 jari 88     protected JPopupMenu popup;
2 26 Feb 07 jari 89     protected boolean showCoordinates = false;
2 26 Feb 07 jari 90     protected DecimalFormat coordinateFormat;
2 26 Feb 07 jari 91     protected FontMetrics metrics;
2 26 Feb 07 jari 92     
2 26 Feb 07 jari 93     public static String[] getPersistenceDelegateArgs() {
2 26 Feb 07 jari 94       return new String[] {"frame", "startx", "stopx", "starty", "stopy",
2 26 Feb 07 jari 95             "graphstartx", "graphstopx", "graphstarty", "graphstopy",
2 26 Feb 07 jari 96           "preXSpacing", "postXSpacing", "preYSpacing", "postYSpacing",
2 26 Feb 07 jari 97           "title", "xLabel", "yLabel"};
2 26 Feb 07 jari 98     }
2 26 Feb 07 jari 99     
2 26 Feb 07 jari 100     /*
2 26 Feb 07 jari 101      * XMLEncoder/Decoder constructor
2 26 Feb 07 jari 102      */
2 26 Feb 07 jari 103     public GraphViewer(JFrame frame, Integer startx, Integer stopx, Integer starty, Integer stopy,
2 26 Feb 07 jari 104           Double graphstartx, Double graphstopx, Double graphstarty, Double graphstopy,
2 26 Feb 07 jari 105           Integer preXSpacing, Integer postXSpacing, Integer preYSpacing, Integer postYSpacing,
2 26 Feb 07 jari 106           String title, String xLabel, String yLabel) {
2 26 Feb 07 jari 107       this(frame, startx.intValue(), stopx.intValue(), starty.intValue(), stopy.intValue(), 
2 26 Feb 07 jari 108           graphstartx.doubleValue(), graphstopx.doubleValue(), graphstarty.doubleValue(), graphstopy.doubleValue(),
2 26 Feb 07 jari 109           preXSpacing.intValue(), postXSpacing.intValue(), preYSpacing.intValue(), postYSpacing.intValue(), 
2 26 Feb 07 jari 110         title, xLabel, yLabel);
2 26 Feb 07 jari 111     }    
2 26 Feb 07 jari 112     public GraphViewer(JFrame frame, int startx, int stopx, int starty, int stopy,
2 26 Feb 07 jari 113     double graphstartx, double graphstopx, double graphstarty, double graphstopy,
2 26 Feb 07 jari 114     int preXSpacing, int postXSpacing, int preYSpacing, int postYSpacing,
2 26 Feb 07 jari 115     String title, String xLabel, String yLabel) {
2 26 Feb 07 jari 116         super(frame);
2 26 Feb 07 jari 117         
2 26 Feb 07 jari 118         this.startx = startx;
2 26 Feb 07 jari 119         this.stopx = stopx;
2 26 Feb 07 jari 120         this.starty = starty;
2 26 Feb 07 jari 121         this.stopy = stopy;
2 26 Feb 07 jari 122         this.graphstartx = graphstartx;
2 26 Feb 07 jari 123         this.graphstopx = graphstopx;
2 26 Feb 07 jari 124         this.graphstarty = graphstarty;
2 26 Feb 07 jari 125         this.graphstopy = graphstopy;
2 26 Feb 07 jari 126         this.preXSpacing = preXSpacing;
2 26 Feb 07 jari 127         this.postXSpacing = postXSpacing;
2 26 Feb 07 jari 128         this.preYSpacing = preYSpacing;
2 26 Feb 07 jari 129         this.postYSpacing = postYSpacing;
2 26 Feb 07 jari 130         
2 26 Feb 07 jari 131         this.title = title;
2 26 Feb 07 jari 132         this.xLabel = xLabel;
2 26 Feb 07 jari 133         this.yLabel = yLabel;
2 26 Feb 07 jari 134         
2 26 Feb 07 jari 135         initializeViewer();
2 26 Feb 07 jari 136         initializeCanvas();
2 26 Feb 07 jari 137         if(frame != null)
2 26 Feb 07 jari 138             initializeFrame();
2 26 Feb 07 jari 139         initializePopupMenu();
2 26 Feb 07 jari 140     }
2 26 Feb 07 jari 141     
2 26 Feb 07 jari 142     
2 26 Feb 07 jari 143     public void setSubTitle(String subTitle){this.subTitle = subTitle;}
2 26 Feb 07 jari 144     public String getSubTitle(){return this.subTitle;}
2 26 Feb 07 jari 145     public void setTitle(String title){this.title = title;}
2 26 Feb 07 jari 146     public String getTitle(){return this.title;}
2 26 Feb 07 jari 147     
2 26 Feb 07 jari 148     private void initializeViewer() {
2 26 Feb 07 jari 149         setLayout(new GridBagLayout());
2 26 Feb 07 jari 150         eventListener = new EventListener();
2 26 Feb 07 jari 151         gba = new GBA();
2 26 Feb 07 jari 152         
2 26 Feb 07 jari 153         graphElements = new Vector();
2 26 Feb 07 jari 154         
2 26 Feb 07 jari 155         setBackground(Color.white);
2 26 Feb 07 jari 156         //setTickFont("monospaced", Font.PLAIN, 10);
2 26 Feb 07 jari 157         //setLabelFont("monospaced", Font.PLAIN, 12);
2 26 Feb 07 jari 158         //setTitleFont("monospaced", Font.PLAIN, 16);
2 26 Feb 07 jari 159         //   setTickFont("Arial", Font.PLAIN, 10);
2 26 Feb 07 jari 160         //setLabelFont("Arial", Font.PLAIN, 12);
2 26 Feb 07 jari 161         //setTitleFont("Arial", Font.PLAIN, 16);
2 26 Feb 07 jari 162         
2 26 Feb 07 jari 163         setTickFont("SansSerif", Font.BOLD, 10);
2 26 Feb 07 jari 164         setLabelFont("SansSerif", Font.BOLD, 12);
2 26 Feb 07 jari 165         setTitleFont("SansSerif", Font.BOLD, 16);
2 26 Feb 07 jari 166         
2 26 Feb 07 jari 167         setSize(stopx - startx + preXSpacing + postXSpacing, stopy - starty + preYSpacing + postYSpacing);
2 26 Feb 07 jari 168         coordinateFormat = new DecimalFormat();
2 26 Feb 07 jari 169         coordinateFormat.setMaximumFractionDigits(3);
2 26 Feb 07 jari 170     }
2 26 Feb 07 jari 171     
2 26 Feb 07 jari 172     private void initializeCanvas() {
2 26 Feb 07 jari 173         canvas = new Drawable(startx, stopx, starty, stopy) {
2 26 Feb 07 jari 174             public void controlPaint(Graphics g) {
2 26 Feb 07 jari 175                 display(g);
2 26 Feb 07 jari 176             }};
2 26 Feb 07 jari 177             
2 26 Feb 07 jari 178             canvas.setBackground(Color.white);
2 26 Feb 07 jari 179             canvas.addMouseListener(eventListener);
2 26 Feb 07 jari 180             canvas.addMouseMotionListener(eventListener);
2 26 Feb 07 jari 181             
2 26 Feb 07 jari 182             scrollPane = new JScrollPane(canvas, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
2 26 Feb 07 jari 183             scrollPane.getViewport().setBackground(Color.white);
2 26 Feb 07 jari 184             
2 26 Feb 07 jari 185             gba.add(this, scrollPane, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C);
2 26 Feb 07 jari 186     }
2 26 Feb 07 jari 187     
2 26 Feb 07 jari 188     private void initializeFrame() {
2 26 Feb 07 jari 189         frame.getContentPane().setLayout(new GridBagLayout());
2 26 Feb 07 jari 190         frame.setResizable(true);
2 26 Feb 07 jari 191         frame.setBackground(Color.white);
2 26 Feb 07 jari 192         frame.addWindowListener(new WindowAdapter() {
2 26 Feb 07 jari 193             public void windowClosing(WindowEvent e) {close();}
2 26 Feb 07 jari 194         });
2 26 Feb 07 jari 195         initializeMenuBar(frame);
2 26 Feb 07 jari 196         
2 26 Feb 07 jari 197         gba.add(frame.getContentPane(), this, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C);
2 26 Feb 07 jari 198         frame.pack();
2 26 Feb 07 jari 199     }
2 26 Feb 07 jari 200     
2 26 Feb 07 jari 201     private void initializeMenuBar(JFrame frame) {
2 26 Feb 07 jari 202         menuBar = new JMenuBar();
2 26 Feb 07 jari 203         frame.setJMenuBar(menuBar);
2 26 Feb 07 jari 204         
2 26 Feb 07 jari 205         JMenu fileMenu = new JMenu("File");
2 26 Feb 07 jari 206         
2 26 Feb 07 jari 207         JMenuItem closeItem = new JMenuItem("Close");
2 26 Feb 07 jari 208         closeItem.addActionListener(eventListener);
2 26 Feb 07 jari 209         fileMenu.add(closeItem);
2 26 Feb 07 jari 210         
2 26 Feb 07 jari 211         JMenu controlMenu = new JMenu("Control");
2 26 Feb 07 jari 212         
2 26 Feb 07 jari 213         JMenuItem graphBoundariesItem = new JMenuItem("Set Boundaries");
2 26 Feb 07 jari 214         graphBoundariesItem.addActionListener(eventListener);
2 26 Feb 07 jari 215         controlMenu.add(graphBoundariesItem);
2 26 Feb 07 jari 216         graphBoundariesItem.setEnabled(false);
2 26 Feb 07 jari 217         
2 26 Feb 07 jari 218         JCheckBoxMenuItem referenceLinesItem = new JCheckBoxMenuItem("Reference Lines");
2 26 Feb 07 jari 219         referenceLinesItem.addActionListener(eventListener);
2 26 Feb 07 jari 220         controlMenu.add(referenceLinesItem);
2 26 Feb 07 jari 221         referenceLinesItem.setSelected(true);
2 26 Feb 07 jari 222         
2 26 Feb 07 jari 223         menuBar.add(fileMenu);
2 26 Feb 07 jari 224         menuBar.add(controlMenu);
2 26 Feb 07 jari 225     }
2 26 Feb 07 jari 226     
2 26 Feb 07 jari 227     protected void initializePopupMenu(){
2 26 Feb 07 jari 228         popup = new JPopupMenu();
2 26 Feb 07 jari 229         JMenuItem item = new JMenuItem("Set Bounds");
2 26 Feb 07 jari 230         item.setActionCommand("Set Boundaries");
2 26 Feb 07 jari 231         item.addActionListener(eventListener);
2 26 Feb 07 jari 232         popup.add(item);
2 26 Feb 07 jari 233         popup.addSeparator();
2 26 Feb 07 jari 234         item = new JMenuItem("Reference Lines");
2 26 Feb 07 jari 235         item.setActionCommand("Reference Lines");
2 26 Feb 07 jari 236         item.addActionListener(eventListener);
2 26 Feb 07 jari 237         popup.add(item);
2 26 Feb 07 jari 238     }
2 26 Feb 07 jari 239     
2 26 Feb 07 jari 240     public void display(Graphics g1D) {
2 26 Feb 07 jari 241         Graphics2D g = (Graphics2D) g1D;
2 26 Feb 07 jari 242         metrics = g.getFontMetrics();
2 26 Feb 07 jari 243         if (false /*Draw from cached image*/) {
2 26 Feb 07 jari 244             if ((cachedImage == null) || (redrawCachedImage == true)) {
2 26 Feb 07 jari 245                 constructImage();
2 26 Feb 07 jari 246                 redrawCachedImage = false;
2 26 Feb 07 jari 247             }
2 26 Feb 07 jari 248             drawImage(g);
2 26 Feb 07 jari 249         }
2 26 Feb 07 jari 250         
2 26 Feb 07 jari 251         else drawGraph(g);
2 26 Feb 07 jari 252     }
2 26 Feb 07 jari 253     
2 26 Feb 07 jari 254     public void drawGraph(Graphics2D g) {
2 26 Feb 07 jari 255         GraphElement e;
2 26 Feb 07 jari 256         
2 26 Feb 07 jari 257         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
2 26 Feb 07 jari 258         //g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
2 26 Feb 07 jari 259         
2 26 Feb 07 jari 260         drawSystem(g, SYSTEM_BOUNDS);
2 26 Feb 07 jari 261         for (int i = 0; i < graphElements.size(); i++) {
2 26 Feb 07 jari 262             e = (GraphElement) graphElements.elementAt(i);
2 26 Feb 07 jari 263             if (e instanceof GraphPoint) drawPoint(g, (GraphPoint) e);
2 26 Feb 07 jari 264             else if (e instanceof GraphBar) drawBar(g, (GraphBar) e);
2 26 Feb 07 jari 265             else if (e instanceof GraphTick) drawTick(g, (GraphTick) e);
2 26 Feb 07 jari 266             else if (e instanceof GraphLine) drawLine(g, (GraphLine) e);
2 26 Feb 07 jari 267         }
2 26 Feb 07 jari 268         
2 26 Feb 07 jari 269         if (referenceLinesOn) { //Grid tracing is active
2 26 Feb 07 jari 270             int x = getXOldEvent();
2 26 Feb 07 jari 271             int y = getYOldEvent();
2 26 Feb 07 jari 272             int coordinateWidth;
2 26 Feb 07 jari 273             double xVal = 0;
2 26 Feb 07 jari 274             double yVal = 0;
2 26 Feb 07 jari 275             
2 26 Feb 07 jari 276             boolean onGraph =  (x <= convertX(graphstopx)) && (x >= convertX(graphstartx)) &&
2 26 Feb 07 jari 277             (y >= convertY(graphstopy)) && (y <= convertY(graphstarty));
2 26 Feb 07 jari 278             
2 26 Feb 07 jari 279             if (onGraph) {
2 26 Feb 07 jari 280                 
2 26 Feb 07 jari 281                 this.setCursor(Cursor.CROSSHAIR_CURSOR);
2 26 Feb 07 jari 282                 
2 26 Feb 07 jari 283                 xVal = ((x - convertX(this.graphstartx))/this.getXScale()) + this.graphstartx;
2 26 Feb 07 jari 284                 yVal = ((convertY(this.graphstarty) - y)/this.getYScale()) + this.graphstarty;
2 26 Feb 07 jari 285                 
2 26 Feb 07 jari 286                 g.setColor(Color.magenta);
2 26 Feb 07 jari 287                 g.drawLine(x, convertY(graphstarty), x, convertY(graphstopy));
2 26 Feb 07 jari 288                 g.drawLine(convertX(graphstartx), y, convertX(graphstopx), y);
2 26 Feb 07 jari 289                 
2 26 Feb 07 jari 290                 if(this.showCoordinates){
2 26 Feb 07 jari 291                     coordinateWidth = metrics.stringWidth(coordinateFormat.format(xVal)+", "+coordinateFormat.format(yVal));
2 26 Feb 07 jari 292                     Composite comp = g.getComposite();
2 26 Feb 07 jari 293                     g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
2 26 Feb 07 jari 294                     g.setColor(Color.blue);
2 26 Feb 07 jari 295                     g.fillRect(x ,y-15, coordinateWidth + 10, 15);
2 26 Feb 07 jari 296                     g.setComposite(comp);
2 26 Feb 07 jari 297                     g.setColor(Color.black);
2 26 Feb 07 jari 298                     g.drawString(coordinateFormat.format(xVal)+", "+coordinateFormat.format(yVal), x+5, y-3);
2 26 Feb 07 jari 299                 }
2 26 Feb 07 jari 300             }
2 26 Feb 07 jari 301             else{
2 26 Feb 07 jari 302                 this.setCursor(Cursor.DEFAULT_CURSOR);
2 26 Feb 07 jari 303             }
2 26 Feb 07 jari 304         }
2 26 Feb 07 jari 305         
2 26 Feb 07 jari 306         //enforceGraphBounds(g);
2 26 Feb 07 jari 307         
2 26 Feb 07 jari 308         drawXLabel(g, xLabel, Color.black);
2 26 Feb 07 jari 309         drawYLabel(g, yLabel, Color.black);
2 26 Feb 07 jari 310         drawTitle(g, title, Color.black);
2 26 Feb 07 jari 311     }
2 26 Feb 07 jari 312     
2 26 Feb 07 jari 313     public void constructImage() {
2 26 Feb 07 jari 314         Graphics2D g = (Graphics2D) this.getGraphics();
2 26 Feb 07 jari 315         BufferedImage tempImage = (BufferedImage)java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(canvas.getSize().width, canvas.getSize().height);        
2 26 Feb 07 jari 316   //      BufferedImage tempImage = (BufferedImage) createImage(canvas.getSize().width, canvas.getSize().height);
2 26 Feb 07 jari 317         g = tempImage.createGraphics();
2 26 Feb 07 jari 318         drawGraph(g);
2 26 Feb 07 jari 319         cachedImage = tempImage;
2 26 Feb 07 jari 320     }
2 26 Feb 07 jari 321     
2 26 Feb 07 jari 322     public void drawImage(Graphics2D g) {
2 26 Feb 07 jari 323         g.drawImage(cachedImage, 0, 0, this);
2 26 Feb 07 jari 324     }
2 26 Feb 07 jari 325     
2 26 Feb 07 jari 326     public void addGraphElement(GraphElement e) {
2 26 Feb 07 jari 327         graphElements.addElement(e);
2 26 Feb 07 jari 328     }
2 26 Feb 07 jari 329     
2 26 Feb 07 jari 330     public void setGraphStartX(double graphStartX) {this.graphstartx = graphStartX;}
2 26 Feb 07 jari 331     public double getGraphStartX() {return this.graphstartx;}
2 26 Feb 07 jari 332     public void setGraphStopX(double graphStopX) {this.graphstopx = graphStopX;}
2 26 Feb 07 jari 333     public double getGraphStopX() {return this.graphstopx;}
2 26 Feb 07 jari 334     public void setGraphStartY(double graphStartY) {this.graphstarty = graphStartY;}
2 26 Feb 07 jari 335     public double getGraphStartY() {return this.graphstarty;}
2 26 Feb 07 jari 336     public void setGraphStopY(double graphStopY) {this.graphstopy = graphStopY;}
2 26 Feb 07 jari 337     public double getGraphStopY() {return this.graphstopy;}
2 26 Feb 07 jari 338     public double getStartX(){return startx;}
2 26 Feb 07 jari 339     public double getStartY(){return starty;}
2 26 Feb 07 jari 340     public int getStopX(){return stopx;}
2 26 Feb 07 jari 341     public int getStopY(){return stopy;}
2 26 Feb 07 jari 342
2 26 Feb 07 jari 343     public int getPostXSpacing(){return postXSpacing;}
2 26 Feb 07 jari 344     public int getPostYSpacing(){return postYSpacing;}
2 26 Feb 07 jari 345     
2 26 Feb 07 jari 346     public void setXAxisValue(double x) {this.xAxisValue = x;}
2 26 Feb 07 jari 347     public double getXAxisValue() {return this.xAxisValue;}
2 26 Feb 07 jari 348     public void setYAxisValue(double y) {this.yAxisValue = y;}
2 26 Feb 07 jari 349     public double getYAxisValue() {return this.yAxisValue;}
2 26 Feb 07 jari 350     
2 26 Feb 07 jari 351     public void setPreXSpacing(int x){ 
2 26 Feb 07 jari 352         this.preXSpacing = x; 
2 26 Feb 07 jari 353       //  ((GraphCanvas)(this.canvas)).setPreXSpacing(x);
2 26 Feb 07 jari 354     }
2 26 Feb 07 jari 355     public int getPreXSpacing(){ return this.preXSpacing; }
2 26 Feb 07 jari 356     public void setPreYSpacing(int y){ 
2 26 Feb 07 jari 357         this.preYSpacing = y; 
2 26 Feb 07 jari 358        // ((GraphCanvas)(this.canvas)).setPreYSpacing(y);
2 26 Feb 07 jari 359     }
2 26 Feb 07 jari 360     public int getPreYSpacing() { return this.preYSpacing; }
2 26 Feb 07 jari 361     public void setPostYSpacing(int y){ this.postYSpacing = y; }
2 26 Feb 07 jari 362     
2 26 Feb 07 jari 363     public String getXLabel(){ return this.xLabel; }
2 26 Feb 07 jari 364     public void setXLabel(String xlabel) {this.xLabel = xlabel;}
2 26 Feb 07 jari 365     public String getYLabel(){ return this.yLabel; }
2 26 Feb 07 jari 366     public void setYLabel(String ylabel) {this.yLabel = ylabel;}
2 26 Feb 07 jari 367     
2 26 Feb 07 jari 368     public void setTickFont(String fontName, int fontStyle, int fontSize) {
2 26 Feb 07 jari 369         tickFont = new Font(fontName, fontStyle, fontSize);
2 26 Feb 07 jari 370         tickFontWidth = (int) (.6 * fontSize);
2 26 Feb 07 jari 371         tickFontHeight = fontSize;
2 26 Feb 07 jari 372     }
2 26 Feb 07 jari 373     
2 26 Feb 07 jari 374     public void setLabelFont(String fontName, int fontStyle, int fontSize) {
2 26 Feb 07 jari 375         labelFont = new Font(fontName, fontStyle, fontSize);
2 26 Feb 07 jari 376         labelFontWidth = (int) (.6 * fontSize);
2 26 Feb 07 jari 377         labelFontHeight = fontSize;
2 26 Feb 07 jari 378     }
2 26 Feb 07 jari 379     
2 26 Feb 07 jari 380     public void setTitleFont(String fontName, int fontStyle, int fontSize) {
2 26 Feb 07 jari 381         titleFont = new Font(fontName, fontStyle, fontSize);
2 26 Feb 07 jari 382         titleFontWidth = (int) (.6 * fontSize);
2 26 Feb 07 jari 383         titleFontHeight = fontSize;
2 26 Feb 07 jari 384     }
2 26 Feb 07 jari 385     
2 26 Feb 07 jari 386     public void setPointSize(int pointSize) {this.pointSize = pointSize;}
2 26 Feb 07 jari 387     public int getPointSize() {return this.pointSize;}
2 26 Feb 07 jari 388     
2 26 Feb 07 jari 389     public void showAll() {canvas.repaint();}
2 26 Feb 07 jari 390     public void clearAll(Graphics2D g) {canvas.fillRect(g, startx, starty, getSize().width, getSize().height, Color.white);}
2 26 Feb 07 jari 391     
2 26 Feb 07 jari 392     public void drawSystem(Graphics2D g, int systemStyle) {
2 26 Feb 07 jari 393         switch (systemStyle) {
2 26 Feb 07 jari 394             case SYSTEM_QUADRANT1_ONLY:
2 26 Feb 07 jari 395                 g.drawLine(startx + preXSpacing, stopy - postYSpacing, stopx - postXSpacing, stopy - postYSpacing);
2 26 Feb 07 jari 396                 g.drawLine(startx + preXSpacing, stopy - postYSpacing, startx + preXSpacing, starty + preYSpacing);
2 26 Feb 07 jari 397                 break;
2 26 Feb 07 jari 398             case SYSTEM_QUADRANT12_ONLY:
2 26 Feb 07 jari 399                 g.drawLine(startx + preXSpacing, stopy - postYSpacing, stopx - postXSpacing, stopy - postYSpacing);
2 26 Feb 07 jari 400                 g.drawLine(startx + preXSpacing, stopy - postYSpacing, startx + preXSpacing, starty + preYSpacing);
2 26 Feb 07 jari 401                 g.drawLine((stopx - postXSpacing - startx + preXSpacing) / 2, stopy - postYSpacing,
2 26 Feb 07 jari 402                 (stopx - postXSpacing - startx + preXSpacing) / 2, starty + preYSpacing);
2 26 Feb 07 jari 403                 break;
2 26 Feb 07 jari 404             case SYSTEM_BOUNDS:
2 26 Feb 07 jari 405                 drawLine(g, new GraphPoint(graphstartx, xAxisValue), new GraphPoint(graphstopx, xAxisValue), Color.black);
2 26 Feb 07 jari 406                 drawLine(g, new GraphPoint(yAxisValue, graphstarty), new GraphPoint(yAxisValue, graphstopy), Color.black);
2 26 Feb 07 jari 407                 break;
2 26 Feb 07 jari 408             case SYSTEM_ALL_QUADRANTS:
2 26 Feb 07 jari 409                 break;
2 26 Feb 07 jari 410         }
2 26 Feb 07 jari 411     }
2 26 Feb 07 jari 412     
2 26 Feb 07 jari 413     //protected double getXScale() {return ((stopx - preXSpacing - postXSpacing) / (graphstopx - graphstartx));}
2 26 Feb 07 jari 414     //protected double getYScale() {return ((stopy - preYSpacing - postYSpacing) / (graphstopy - graphstarty));}
2 26 Feb 07 jari 415     protected double getXScale() {return((canvas.getSize().width - preXSpacing - postXSpacing) / (graphstopx - graphstartx));}
2 26 Feb 07 jari 416     protected double getYScale() {return((canvas.getSize().height - preYSpacing - postYSpacing) / (graphstopy - graphstarty));}
2 26 Feb 07 jari 417     protected int convertX(double x) {
2 26 Feb 07 jari 418         if (true) { //Use log scale
2 26 Feb 07 jari 419             return(int) ((x - graphstartx) * getXScale() + preXSpacing);
2 26 Feb 07 jari 420             
2 26 Feb 07 jari 421             //return (int) ((Math.log(x) - graphstartx) * getXScale() + preXSpacing);
2 26 Feb 07 jari 422             
2 26 Feb 07 jari 423         } else return(int) ((x - graphstartx) * getXScale() + preXSpacing);
2 26 Feb 07 jari 424     }
2 26 Feb 07 jari 425     
2 26 Feb 07 jari 426     protected int convertY(double y) {
2 26 Feb 07 jari 427         if (true) { //Use log scale
2 26 Feb 07 jari 428             return(int) ((graphstopy - y) * getYScale() + preYSpacing);
2 26 Feb 07 jari 429             
2 26 Feb 07 jari 430             //return (int) ((graphstopy - Math.log(y)) * getYScale() + preYSpacing);
2 26 Feb 07 jari 431             
2 26 Feb 07 jari 432         }
2 26 Feb 07 jari 433         return(int) ((graphstopy - y) * getYScale() + preYSpacing);
2 26 Feb 07 jari 434     }
2 26 Feb 07 jari 435     
2 26 Feb 07 jari 436     public void drawTick(Graphics2D g, GraphTick e) {
2 26 Feb 07 jari 437         if (e.getOrientation() == GC.HORIZONTAL) {
2 26 Feb 07 jari 438             if (e.getLabel() != "") {
2 26 Feb 07 jari 439                 drawVerticalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor(), e.getLabel(), e.getLabelColor());
2 26 Feb 07 jari 440             } else drawVerticalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor());
2 26 Feb 07 jari 441         } else if (e.getOrientation() == GC.VERTICAL) {
2 26 Feb 07 jari 442             if (e.getLabel() != "") {
2 26 Feb 07 jari 443                 drawHorizontalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor(), e.getLabel(), e.getLabelColor());
2 26 Feb 07 jari 444             } else drawHorizontalTick(g, e.getLocation(), e.getHeight(), e.getAlignment(), e.getColor());
2 26 Feb 07 jari 445         }
2 26 Feb 07 jari 446     }
2 26 Feb 07 jari 447     public void drawVerticalTick(Graphics2D g, double x, int length, int alignment, Color color) {
2 26 Feb 07 jari 448         if (x < graphstartx || x > graphstopx) /*System.out.println("X OOB")*/;
2 26 Feb 07 jari 449         else if (length > postYSpacing) /*System.out.println("Length OOB")*/;
2 26 Feb 07 jari 450         else {
2 26 Feb 07 jari 451             switch (alignment) {
2 26 Feb 07 jari 452                 case GC.C: canvas.drawLine(g, convertX(x), convertY(xAxisValue) - (int) (length / 2), convertX(x), convertY(xAxisValue) + (int) (length / 2), color); break;
2 26 Feb 07 jari 453                 case GC.N: canvas.drawLine(g, convertX(x), convertY(xAxisValue), convertX(x), convertY(xAxisValue) - length, color); break;
2 26 Feb 07 jari 454                 case GC.S: canvas.drawLine(g, convertX(x), convertY(xAxisValue), convertX(x), convertY(xAxisValue) + length, color); break;
2 26 Feb 07 jari 455             }
2 26 Feb 07 jari 456         }
2 26 Feb 07 jari 457     }
2 26 Feb 07 jari 458     
2 26 Feb 07 jari 459     public void drawVerticalTick(Graphics2D g, double x, int length, int alignment, Color color, String label, Color tickColor) {
2 26 Feb 07 jari 460         drawVerticalTick(g, x, length, alignment, color);
2 26 Feb 07 jari 461         
2 26 Feb 07 jari 462         if (true) { //Rotate labels
2 26 Feb 07 jari 463             g.rotate(- Math.PI / 2);
2 26 Feb 07 jari 464             //canvas.drawString(g, label, postYSpacing - length - (label.length() * tickFontWidth), convertX(x), labelColor, tickFont);
2 26 Feb 07 jari 465             //canvas.drawString(g, label, 750, convertX(x) + canvas.getSize().width, tickColor, tickFont);
2 26 Feb 07 jari 466             canvas.drawString(g, label, - canvas.getSize().height + postYSpacing - (label.length() * tickFontWidth) - length,
2 26 Feb 07 jari 467             convertX(x) + (tickFontHeight / 2), tickColor, tickFont);
2 26 Feb 07 jari 468             g.rotate(Math.PI / 2);
2 26 Feb 07 jari 469         } else {
2 26 Feb 07 jari 470             canvas.drawString(g, label, convertX(x) - (label.length() * tickFontWidth / 2),
2 26 Feb 07 jari 471             canvas.getSize().height - postYSpacing + length + 10, tickColor, tickFont);
2 26 Feb 07 jari 472         }
2 26 Feb 07 jari 473     }
2 26 Feb 07 jari 474     
2 26 Feb 07 jari 475     public void drawHorizontalTick(Graphics2D g, double y, int length, int alignment, Color color) {
2 26 Feb 07 jari 476         if (y < graphstarty || y > graphstopy) /*System.out.println("Y OOB")*/;
2 26 Feb 07 jari 477         else if (length > preXSpacing) /*System.out.println("Length OOB")*/;
2 26 Feb 07 jari 478         else {
2 26 Feb 07 jari 479             switch (alignment) {
2 26 Feb 07 jari 480                 case GC.C: canvas.drawLine(g, convertX(yAxisValue) - (int) (length / 2), convertY(y), convertX(yAxisValue) + (int) (length / 2), convertY(y), color); break;
2 26 Feb 07 jari 481                 case GC.E: canvas.drawLine(g, convertX(yAxisValue), convertY(y), convertX(yAxisValue) + length, convertY(y), color); break;
2 26 Feb 07 jari 482                 case GC.W: canvas.drawLine(g, convertX(yAxisValue), convertY(y), convertX(yAxisValue) - length, convertY(y), color); break;
2 26 Feb 07 jari 483             }
2 26 Feb 07 jari 484         }
2 26 Feb 07 jari 485     }
2 26 Feb 07 jari 486     
2 26 Feb 07 jari 487     public void drawHorizontalTick(Graphics2D g, double y, int length, int alignment, Color color, String label, Color tickColor) {
2 26 Feb 07 jari 488         drawHorizontalTick(g, y, length, alignment, color);
2 26 Feb 07 jari 489         canvas.drawString(g, label, startx + preXSpacing - length - (label.length() * tickFontWidth),
2 26 Feb 07 jari 490         convertY(y) + (tickFontHeight / 2), tickColor, tickFont);
2 26 Feb 07 jari 491     }
2 26 Feb 07 jari 492     
2 26 Feb 07 jari 493     
2 26 Feb 07 jari 494     public void enforceGraphBounds(Graphics2D g) {
2 26 Feb 07 jari 495         enforceGraphBounds(g, Color.white);
2 26 Feb 07 jari 496     }
2 26 Feb 07 jari 497     
2 26 Feb 07 jari 498     public void enforceGraphBounds(Graphics2D g, Color color) {
2 26 Feb 07 jari 499         int height = canvas.getSize().height;
2 26 Feb 07 jari 500         int width = canvas.getSize().width;
2 26 Feb 07 jari 501         
2 26 Feb 07 jari 502         canvas.fillRect(g, 0, 0, width, preYSpacing, color);
2 26 Feb 07 jari 503         canvas.fillRect(g, 0, height - postYSpacing, width, postYSpacing, color);
2 26 Feb 07 jari 504         canvas.fillRect(g, 0, 0, preXSpacing, height, color);
2 26 Feb 07 jari 505         canvas.fillRect(g, width - postXSpacing, 0, postXSpacing, height, color);
2 26 Feb 07 jari 506     }
2 26 Feb 07 jari 507     
2 26 Feb 07 jari 508     public void drawTitle(Graphics2D g, String title, Color titleColor) {
2 26 Feb 07 jari 509         if(subTitle == null)
2 26 Feb 07 jari 510             canvas.drawString(g, title, canvas.getSize().width / 2 - (title.length() * titleFontWidth / 2), titleFontHeight * 2, titleColor, titleFont);
2 26 Feb 07 jari 511         else {
2 26 Feb 07 jari 512             canvas.drawString(g, title, canvas.getSize().width / 2 - (title.length() * titleFontWidth / 2), (int)(titleFontHeight * 1.5), titleColor, titleFont);
2 26 Feb 07 jari 513             canvas.drawString(g, subTitle, canvas.getSize().width / 2 - (subTitle.length() * titleFontWidth / 2), titleFontHeight * 3, titleColor, titleFont);           
2 26 Feb 07 jari 514         }
2 26 Feb 07 jari 515     }
2 26 Feb 07 jari 516     
2 26 Feb 07 jari 517     public void drawXLabel(Graphics2D g, String label, Color labelColor) {
2 26 Feb 07 jari 518         canvas.drawString(g, label, canvas.getSize().width / 2 - (label.length() * labelFontWidth / 2), convertY(graphstarty) + postYSpacing - labelFontHeight, labelColor, labelFont);
2 26 Feb 07 jari 519     }
2 26 Feb 07 jari 520     
2 26 Feb 07 jari 521     public void drawYLabel(Graphics2D g, String label, Color labelColor) {
2 26 Feb 07 jari 522         /*
2 26 Feb 07 jari 523         String[] headerStrings = new String[columnVector.size()];
2 26 Feb 07 jari 524         Font headerFont = new Font("System", Font.PLAIN, 12);
2 26 Feb 07 jari 525         g.setFont(headerFont);
2 26 Feb 07 jari 526         FontMetrics hfm = g.getFontMetrics();
2 26 Feb 07 jari 527         int fontHeight = hfm.getHeight();
2 26 Feb 07 jari 528         int nudge = (int) ((double) fontHeight * .5);
2 26 Feb 07 jari 529         int maxHeight = 0;
2 26 Feb 07 jari 530          
2 26 Feb 07 jari 531         for (int i = 0; i < columnVector.size(); i++)
2 26 Feb 07 jari 532             {
2 26 Feb 07 jari 533             headerStrings[i] = ((SlideData) columnVector.elementAt(i)).getSlideDataName();
2 26 Feb 07 jari 534             maxHeight = Math.max(maxHeight, hfm.stringWidth(headerStrings[i]));
2 26 Feb 07 jari 535             }
2 26 Feb 07 jari 536          
2 26 Feb 07 jari 537         setPreferredSize(new Dimension(canvas.getSize().width, maxHeight));
2 26 Feb 07 jari 538          
2 26 Feb 07 jari 539         g.rotate(- Math.PI / 2);
2 26 Feb 07 jari 540          
2 26 Feb 07 jari 541         for (int i = 0; i < headerStrings.length; i++)
2 26 Feb 07 jari 542             {
2 26 Feb 07 jari 543             g.drawString(headerStrings[i], postYSpacing - getSize().height, preXSpacing + nudge + (canvas.getXElementSize() / 2) + canvas.getXpos(i));
2 26 Feb 07 jari 544             }
2 26 Feb 07 jari 545          
2 26 Feb 07 jari 546         g.rotate(Math.PI / 2);
2 26 Feb 07 jari 547          */
2 26 Feb 07 jari 548         g.rotate(- Math.PI / 2);
2 26 Feb 07 jari 549         canvas.drawString(g, label, startx - postYSpacing + preXSpacing - (canvas.getSize().height / 2) - (label.length() * labelFontWidth / 2), labelFontHeight, labelColor, labelFont);
2 26 Feb 07 jari 550         g.rotate(Math.PI / 2);
2 26 Feb 07 jari 551     }
2 26 Feb 07 jari 552     
2 26 Feb 07 jari 553     public void drawPoint(Graphics2D g, GraphPoint graphPoint) {
2 26 Feb 07 jari 554         drawPointAt(g, graphPoint.getX(), graphPoint.getY(), graphPoint.getColor(), graphPoint.getPointSize());
2 26 Feb 07 jari 555     }
2 26 Feb 07 jari 556     
2 26 Feb 07 jari 557     public void drawPointAt(Graphics2D g, double x, double y, Color pointColor, int pointSize) {
2 26 Feb 07 jari 558         if ((x < graphstartx || x > graphstopx) || (y < graphstarty || y > graphstopy)) /*System.out.println("X/Y OOB")*/;
2 26 Feb 07 jari 559         else canvas.fillRect(g, convertX(x) - (pointSize / 2), convertY(y) - (pointSize / 2), pointSize, pointSize, pointColor);
2 26 Feb 07 jari 560     }
2 26 Feb 07 jari 561     
2 26 Feb 07 jari 562     public void drawPoints(Graphics2D g, Vector graphPoints, int graphPointStyle) {
2 26 Feb 07 jari 563         GraphPoint graphPoint, graphPoint2 = null;
2 26 Feb 07 jari 564         
2 26 Feb 07 jari 565         switch (graphPointStyle) {
2 26 Feb 07 jari 566             case GRAPH_POINTS_SEPERATE:
2 26 Feb 07 jari 567                 for (int i = 0; i < graphPoints.size(); i++) {
2 26 Feb 07 jari 568                     graphPoint = (GraphPoint) graphPoints.elementAt(i);
2 26 Feb 07 jari 569                     drawPoint(g, graphPoint);
2 26 Feb 07 jari 570                 }
2 26 Feb 07 jari 571                 break;
2 26 Feb 07 jari 572             case GRAPH_POINTS_CONNECT:
2 26 Feb 07 jari 573                 for (int i = 0; i < graphPoints.size(); i++) {
2 26 Feb 07 jari 574                     graphPoint = (GraphPoint) graphPoints.elementAt(i);
2 26 Feb 07 jari 575                     if (i == 0) graphPoint2 = graphPoint;
2 26 Feb 07 jari 576                     drawLine(g, graphPoint2, graphPoint, Color.black);
2 26 Feb 07 jari 577                     drawPoint(g, graphPoint2);
2 26 Feb 07 jari 578                     drawPoint(g, graphPoint);
2 26 Feb 07 jari 579                     graphPoint2 = graphPoint;
2 26 Feb 07 jari 580                 }
2 26 Feb 07 jari 581                 break;
2 26 Feb 07 jari 582         }
2 26 Feb 07 jari 583     }
2 26 Feb 07 jari 584     
2 26 Feb 07 jari 585     public void drawLine(Graphics2D g, GraphLine e) {
2 26 Feb 07 jari 586         if(e.getX1() < graphstartx || e.getX1() > graphstopx ||
2 26 Feb 07 jari 587             e.getY1() < graphstarty || e.getY1() > graphstopy ||
2 26 Feb 07 jari 588             e.getX2() < graphstartx || e.getX2() > graphstopx ||
2 26 Feb 07 jari 589             e.getY2() < graphstarty || e.getY2() > graphstopy);
2 26 Feb 07 jari 590         else
2 26 Feb 07 jari 591             canvas.drawLine(g, convertX(e.getX1()), convertY(e.getY1()), convertX(e.getX2()), convertY(e.getY2()), e.getColor());
2 26 Feb 07 jari 592     }
2 26 Feb 07 jari 593     
2 26 Feb 07 jari 594     public void drawLine(Graphics2D g, GraphPoint graphPoint1, GraphPoint graphPoint2, Color lineColor) {
2 26 Feb 07 jari 595             canvas.drawLine(g, convertX(graphPoint1.getX()), convertY(graphPoint1.getY()),
2 26 Feb 07 jari 596             convertX(graphPoint2.getX()), convertY(graphPoint2.getY()), lineColor);
2 26 Feb 07 jari 597     }
2 26 Feb 07 jari 598     
2 26 Feb 07 jari 599     public void drawBar(Graphics2D g, GraphBar e) {
2 26 Feb 07 jari 600         if (e.getStyle() == GraphBar.VERTICAL) {
2 26 Feb 07 jari 601             drawVerticalHistogramBar(g, e.getLower(), e.getUpper(), e.getValue(), e.getColor(), e.getStyle());
2 26 Feb 07 jari 602         } else if (e.getStyle() == GraphBar.HORIZONTAL) {
2 26 Feb 07 jari 603             //Nothing yet
2 26 Feb 07 jari 604         }
2 26 Feb 07 jari 605     }
2 26 Feb 07 jari 606     
2 26 Feb 07 jari 607     public void drawVerticalHistogramBar(Graphics2D g, double low, double high, double value, Color barColor, int style) {
2 26 Feb 07 jari 608         if ((low < graphstartx || low > graphstopx) || (high < graphstartx || high > graphstopx)) /*System.out.println("Range OOB")*/;
2 26 Feb 07 jari 609         else if (value < graphstarty || value > graphstopy) /*System.out.println("Value OOB")*/;
2 26 Feb 07 jari 610         else {
2 26 Feb 07 jari 611             if (style == GraphBar.OUTLINE) {
2 26 Feb 07 jari 612                 canvas.drawRect(g, convertX(low), convertY(value), (int) ((high - low) * getXScale()), (int) (value * getYScale()) - 1, barColor);
2 26 Feb 07 jari 613             } else if (style == GraphBar.SOLID) {
2 26 Feb 07 jari 614                 canvas.fillRect(g, convertX(low), convertY(value), (int) ((high - low) * getXScale()) + 1, (int) (value * getYScale()) + 1, barColor);
2 26 Feb 07 jari 615             }
2 26 Feb 07 jari 616         }
2 26 Feb 07 jari 617     }
2 26 Feb 07 jari 618     
2 26 Feb 07 jari 619     public void close() {
2 26 Feb 07 jari 620         if (hasFrame()) frame.dispose();
2 26 Feb 07 jari 621     }
2 26 Feb 07 jari 622     
2 26 Feb 07 jari 623     public void toggleReferenceLines(){
2 26 Feb 07 jari 624         this.referenceLinesOn = (! this.referenceLinesOn);
2 26 Feb 07 jari 625     }
2 26 Feb 07 jari 626     
2 26 Feb 07 jari 627     public void setShowCoordinates(boolean showCoordinates){
2 26 Feb 07 jari 628         this.showCoordinates = showCoordinates;
2 26 Feb 07 jari 629     }
2 26 Feb 07 jari 630     
2 26 Feb 07 jari 631     private class EventListener implements ActionListener, KeyListener, MouseListener, MouseMotionListener, java.io.Serializable {
2 26 Feb 07 jari 632         public void actionPerformed(ActionEvent event) {
2 26 Feb 07 jari 633             popup.setVisible(false);
2 26 Feb 07 jari 634             if (event.getActionCommand() == "Close") getFrame().dispose();
2 26 Feb 07 jari 635             else if (event.getActionCommand() == "Set Boundaries") {
2 26 Feb 07 jari 636                 BoundariesDialog bd = new BoundariesDialog(getFrame(), graphstartx, graphstopx, graphstarty, graphstopy);
2 26 Feb 07 jari 637                 bd.addActionInfoListener(new ActionInfoListener() {
2 26 Feb 07 jari 638                     public void actionInfoPerformed(ActionInfoEvent event) {
2 26 Feb 07 jari 639                         Hashtable hash = event.getHashtable();
2 26 Feb 07 jari 640                         
2 26 Feb 07 jari 641                         graphstartx = Double.parseDouble((String) hash.get("lowerx"));
2 26 Feb 07 jari 642                         graphstopx = Double.parseDouble((String) hash.get("upperx"));
2 26 Feb 07 jari 643                         graphstarty = Double.parseDouble((String) hash.get("lowery"));
2 26 Feb 07 jari 644                         graphstopy = Double.parseDouble((String) hash.get("uppery"));
2 26 Feb 07 jari 645                         
2 26 Feb 07 jari 646                         setXAxisValue(graphstarty);
2 26 Feb 07 jari 647                         setYAxisValue(graphstartx);
2 26 Feb 07 jari 648                         
2 26 Feb 07 jari 649                         repaint();
2 26 Feb 07 jari 650                     }
2 26 Feb 07 jari 651                 });
2 26 Feb 07 jari 652                 bd.show();
2 26 Feb 07 jari 653             } else if (event.getActionCommand() == "Reference Lines") {
2 26 Feb 07 jari 654                 referenceLinesOn = (! referenceLinesOn);
2 26 Feb 07 jari 655                 repaint();
2 26 Feb 07 jari 656             }
2 26 Feb 07 jari 657         }
2 26 Feb 07 jari 658         public void keyPressed(KeyEvent event) {;}
2 26 Feb 07 jari 659         public void keyReleased(KeyEvent event) {;}
2 26 Feb 07 jari 660         public void keyTyped(KeyEvent event) {;}
2 26 Feb 07 jari 661         public void mouseClicked(MouseEvent event) {
2 26 Feb 07 jari 662             if(event.getModifiers() == MouseEvent.BUTTON3_MASK){
2 26 Feb 07 jari 663             popup.show(event.getComponent(), event.getX(), event.getY());   
2 26 Feb 07 jari 664             }
2 26 Feb 07 jari 665         }
2 26 Feb 07 jari 666         public void mouseDragged(MouseEvent event) {
2 26 Feb 07 jari 667         //    if(clickAndDragZoom){
2 26 Feb 07 jari 668                 int x = event.getX();
2 26 Feb 07 jari 669                 int y = event.getY();
2 26 Feb 07 jari 670                 
2 26 Feb 07 jari 671         //    }
2 26 Feb 07 jari 672         }
2 26 Feb 07 jari 673         public void mouseEntered(MouseEvent event) {;}
2 26 Feb 07 jari 674         public void mouseExited(MouseEvent event) {
2 26 Feb 07 jari 675             setXOldEvent(-1);
2 26 Feb 07 jari 676             setYOldEvent(-1);
2 26 Feb 07 jari 677             repaint();
2 26 Feb 07 jari 678         }
2 26 Feb 07 jari 679         public void mouseMoved(MouseEvent event) {
2 26 Feb 07 jari 680             int x = event.getX();
2 26 Feb 07 jari 681             int y = event.getY();
2 26 Feb 07 jari 682             setXOldEvent(x);
2 26 Feb 07 jari 683             setYOldEvent(y);
2 26 Feb 07 jari 684             repaint();
2 26 Feb 07 jari 685         }
2 26 Feb 07 jari 686         public void mousePressed(MouseEvent event) {;}
2 26 Feb 07 jari 687         public void mouseReleased(MouseEvent event) {;}
2 26 Feb 07 jari 688     }
2 26 Feb 07 jari 689 }