mev-4.0.01/source/org/tigr/microarray/mev/cgh/CGHGuiObj/CGHBrowser/CGHPaintableChart.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2  * CGHPaintableChart.java
2 26 Feb 07 jari 3  *
2 26 Feb 07 jari 4  * Created on December 29, 2002, 1:06 AM
2 26 Feb 07 jari 5  */
2 26 Feb 07 jari 6
2 26 Feb 07 jari 7 package org.tigr.microarray.mev.cgh.CGHGuiObj.CGHBrowser;
2 26 Feb 07 jari 8
2 26 Feb 07 jari 9 import java.awt.Color;
2 26 Feb 07 jari 10 import java.awt.Graphics;
2 26 Feb 07 jari 11 import java.awt.Point;
2 26 Feb 07 jari 12 import java.awt.Rectangle;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import com.klg.jclass.chart.JCAxis;
2 26 Feb 07 jari 15 import com.klg.jclass.chart.beans.SimpleChart;
2 26 Feb 07 jari 16
2 26 Feb 07 jari 17 /**
2 26 Feb 07 jari 18  *
2 26 Feb 07 jari 19  * @author  Adam Margolin
2 26 Feb 07 jari 20  * @author Raktim Sinha
2 26 Feb 07 jari 21  */
2 26 Feb 07 jari 22
2 26 Feb 07 jari 23 public class CGHPaintableChart extends SimpleChart{
2 26 Feb 07 jari 24     Rectangle currentRect = null;
2 26 Feb 07 jari 25     Rectangle rectToDraw = null;
2 26 Feb 07 jari 26     Rectangle previousRectDrawn = new Rectangle();
2 26 Feb 07 jari 27
2 26 Feb 07 jari 28     int startIndex;
2 26 Feb 07 jari 29     int stopIndex;
2 26 Feb 07 jari 30
2 26 Feb 07 jari 31     /** Creates a new instance of CGHPaintableChart */
2 26 Feb 07 jari 32     public CGHPaintableChart() {
2 26 Feb 07 jari 33         super();
2 26 Feb 07 jari 34     }
2 26 Feb 07 jari 35
2 26 Feb 07 jari 36     public void paint(Graphics g){
2 26 Feb 07 jari 37         super.paint(g);
2 26 Feb 07 jari 38         paintRect(g);
2 26 Feb 07 jari 39     }
2 26 Feb 07 jari 40
2 26 Feb 07 jari 41     public void paintRect(Graphics g){
2 26 Feb 07 jari 42         updateRect();
2 26 Feb 07 jari 43         //If currentRect exists, paint a box on top.
2 26 Feb 07 jari 44         if (currentRect != null) {
2 26 Feb 07 jari 45             //Draw a rectangle on top of the image.
2 26 Feb 07 jari 46
2 26 Feb 07 jari 47             g.setColor(Color.white);
2 26 Feb 07 jari 48             g.setXORMode(Color.yellow); //Color of line varies
2 26 Feb 07 jari 49
2 26 Feb 07 jari 50             g.fillRect(currentRect.x, currentRect.y,
2 26 Feb 07 jari 51             currentRect.width, currentRect.height - 1);
2 26 Feb 07 jari 52         }
2 26 Feb 07 jari 53     }
2 26 Feb 07 jari 54
2 26 Feb 07 jari 55
2 26 Feb 07 jari 56     public void setSelectedCoordinates(int pointIndex){
2 26 Feb 07 jari 57         startIndex = pointIndex;
2 26 Feb 07 jari 58         stopIndex = -1;
2 26 Feb 07 jari 59         repaint();
2 26 Feb 07 jari 60         //updateRect();
2 26 Feb 07 jari 61     }
2 26 Feb 07 jari 62
2 26 Feb 07 jari 63     public void updateRect(){
2 26 Feb 07 jari 64         if(startIndex == -1){
2 26 Feb 07 jari 65             return;
2 26 Feb 07 jari 66         }
2 26 Feb 07 jari 67
2 26 Feb 07 jari 68         if(stopIndex == -1){
2 26 Feb 07 jari 69             highlightPoint();
2 26 Feb 07 jari 70         }else{
2 26 Feb 07 jari 71             highlightRegion();
2 26 Feb 07 jari 72         }
2 26 Feb 07 jari 73     }
2 26 Feb 07 jari 74
2 26 Feb 07 jari 75     public void highlightPoint(){
2 26 Feb 07 jari 76         try{
2 26 Feb 07 jari 77             JCAxis yaxis = this.getDataView(0).getYAxis();
2 26 Feb 07 jari 78
2 26 Feb 07 jari 79             // Get the region bounded by the Plot area and the selected area
2 26 Feb 07 jari 80             Point point = this.unpick(startIndex, getDataView(0).getSeries(0));
2 26 Feb 07 jari 81             int x = point.x - 5;
2 26 Feb 07 jari 82             int width = 10;
2 26 Feb 07 jari 83
2 26 Feb 07 jari 84             Point topY = this.getDataView(0).unmap(point.getX(), yaxis.getMax());
2 26 Feb 07 jari 85             Point bottomY = this.getDataView(0).unmap(point.getY(), yaxis.getMin());
2 26 Feb 07 jari 86             int y = (int) topY.getY();
2 26 Feb 07 jari 87             int height = (int) (bottomY.getY() - topY.getY());
2 26 Feb 07 jari 88
2 26 Feb 07 jari 89             currentRect = new Rectangle(x, y, width, height);
2 26 Feb 07 jari 90             //repaint();
2 26 Feb 07 jari 91
2 26 Feb 07 jari 92         }catch (NullPointerException e){
2 26 Feb 07 jari 93             e.printStackTrace();
2 26 Feb 07 jari 94             System.out.println("Paintable char set selected coords npe");
2 26 Feb 07 jari 95         }
2 26 Feb 07 jari 96     }
2 26 Feb 07 jari 97
2 26 Feb 07 jari 98
2 26 Feb 07 jari 99     public void setSelectedCoordinates(int startIndex, int stopIndex){
2 26 Feb 07 jari 100         this.startIndex = startIndex;
2 26 Feb 07 jari 101         this.stopIndex = stopIndex;
2 26 Feb 07 jari 102         repaint();
2 26 Feb 07 jari 103         //updateRect();
2 26 Feb 07 jari 104     }
2 26 Feb 07 jari 105
2 26 Feb 07 jari 106     public void highlightRegion(){
2 26 Feb 07 jari 107         try{
2 26 Feb 07 jari 108             JCAxis yaxis = this.getDataView(0).getYAxis();
2 26 Feb 07 jari 109
2 26 Feb 07 jari 110             // Get the region bounded by the Plot area and the selected area
2 26 Feb 07 jari 111             Point pointStart = this.unpick(startIndex, getDataView(0).getSeries(0));
2 26 Feb 07 jari 112             Point pointStop = this.unpick(stopIndex, getDataView(0).getSeries(0));
2 26 Feb 07 jari 113             int x = pointStart.x;
2 26 Feb 07 jari 114             int xStop = pointStop.x;
2 26 Feb 07 jari 115             int width = xStop - x;
2 26 Feb 07 jari 116
2 26 Feb 07 jari 117             Point topY = this.getDataView(0).unmap(pointStart.getX(), yaxis.getMax());
2 26 Feb 07 jari 118             Point bottomY = this.getDataView(0).unmap(pointStart.getY(), yaxis.getMin());
2 26 Feb 07 jari 119             int y = (int) topY.getY();
2 26 Feb 07 jari 120             int height = (int) (bottomY.getY() - topY.getY());
2 26 Feb 07 jari 121             currentRect = new Rectangle(x, y, width, height);
2 26 Feb 07 jari 122             //repaint();
2 26 Feb 07 jari 123         }catch (NullPointerException e){
2 26 Feb 07 jari 124             e.printStackTrace();
2 26 Feb 07 jari 125             //System.out.println("Paintable char set selected coords npe");
2 26 Feb 07 jari 126         }
2 26 Feb 07 jari 127     }
2 26 Feb 07 jari 128
2 26 Feb 07 jari 129     public void deleteRect(){
2 26 Feb 07 jari 130         currentRect = null;
2 26 Feb 07 jari 131         startIndex = -1;
2 26 Feb 07 jari 132         stopIndex = -1;
2 26 Feb 07 jari 133     }
2 26 Feb 07 jari 134 }