Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

IntensityPlot.java

Go to the documentation of this file.
00001 /*
00002  * IntensityPlot.java
00003  *
00004  * Copyright (C) 2005 Project SQUID, http://www.cs.helsinki.fi/group/squid/
00005  *
00006  * This file is part of Ikayaki.
00007  *
00008  * Ikayaki is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Ikayaki is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Ikayaki; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021  */
00022 
00023 package ikayaki.gui;
00024 
00025 import ikayaki.MeasurementStep;
00026 import ikayaki.MeasurementValue;
00027 import ikayaki.Project;
00028 
00029 import java.awt.*;
00030 import java.awt.geom.Point2D;
00031 import java.util.Vector;
00032 
00038 public class IntensityPlot extends AbstractPlot {
00039 
00043     private Vector<Point2D> points = new Vector<Point2D>();
00044 
00045     private Project project = null;
00046 
00050     public void add(MeasurementStep step) {
00051         if (step.getProject() != null) {
00052             project = step.getProject();
00053         }
00054         Double value = MeasurementValue.RELATIVE_MAGNETIZATION.getValue(step);
00055         if (value != null) {
00056             points.add(new Point2D.Double(Math.max(step.getStepValue(), 0.0), Math.max(value.doubleValue(), 0.0)));
00057         }
00058     }
00059 
00063     public void reset() {
00064         points.clear();
00065         repaint();
00066     }
00067 
00073     public int getNumMeasurements() {
00074         return points.size();
00075     }
00076 
00084     public void render(int w, int h, Graphics2D g2) {
00085         // margin
00086         int m = 20;
00087         // arrow width
00088         int aw = 4;
00089         // arrow length
00090         int al = 8;
00091         // y-axis padding from arrow top to max values
00092         int yPad = 20;
00093         // x-axis padding from arrow top to max values
00094         int xPad = 20;
00095         // minimum max value of y-axis
00096         double yMax = 1.1;
00097         // minimum max value of x-axis
00098         double xMax = 100.0;
00099 
00100         for (Point2D point : points) {
00101             //yMax = Math.max(yMax, Math.min(point.getY(),yMax));
00102             xMax = Math.max(xMax, point.getX());
00103         }
00104 
00105         // pixels on y-area
00106         int yArea = getSize().height - ((2 * m) + yPad);
00107         // pixels on x-area
00108         int xArea = getSize().width - ((2 * m) + xPad);
00109         // font for texts
00110         g2.setFont(new Font("Arial", Font.PLAIN, 8 + (Math.min(xArea, yArea) / 60)));
00111         FontMetrics metrics = g2.getFontMetrics();
00112         // text height
00113         int txtH = metrics.getHeight();
00114         // text width
00115         int txtW = 0;
00116 
00117         // x-fix
00118         int xFix = m + aw;
00119         // y-fix
00120         int yFix = h - (m + aw);
00121 
00122         // draw y-axis
00123         g2.drawLine(xFix, m, xFix, yFix);
00124         // draw x-axis
00125         g2.drawLine(xFix, yFix, w - m, yFix);
00126         // draw y-arrow
00127         g2.drawLine(m, m + al, m + aw, m);
00128         g2.drawLine(m + (2 * aw), m + al, m + aw, m);
00129         // draw x-arrow
00130         g2.drawLine((w - m) - al, (h - m) - (2 * aw), w - m, (h - m) - aw);
00131         g2.drawLine((w - m) - al, h - m, w - m, (h - m) - aw);
00132 
00133         // y-axis ticks
00134 
00135         // 1.0 tick
00136         int tick1_x1 = xFix;
00137         int tick1_y1 = yFix - new Double((1.0 / yMax) * yArea).intValue();
00138         int tick1_x2 = xFix + new Double(5 + 0.02 * xArea).intValue();
00139         int tick1_y2 = tick1_y1;
00140         g2.drawLine(tick1_x1, tick1_y1, tick1_x2, tick1_y2);
00141         // 1.0 number
00142         txtW = metrics.stringWidth("1.0");
00143         g2.drawString("1.0", m - (txtW), tick1_y1 + (txtH / 2));
00144 
00145         // x-axis max value
00146         int tickX_x1 = xFix + new Double(1.0 * xArea).intValue();
00147         int tickX_y1 = yFix;
00148         int tickX_x2 = tickX_x1;
00149         int tickX_y2 = yFix - new Double(5 + 0.02 * yArea).intValue();
00150         g2.drawLine(tickX_x1, tickX_y1, tickX_x2, tickX_y2);
00151         // max value
00152         String maxValStr = new Double(xMax).toString();
00153         txtW = metrics.stringWidth(maxValStr);
00154         g2.drawString(maxValStr, tickX_x1 - (txtW / 2), yFix + (m / 2) + (txtH / 2));
00155 
00156 
00157 
00158         // y-axis unit
00159         g2.drawString(SequenceColumn.RELATIVE_MAGNETIZATION.getColumnName(project), m + 20, m + 10);
00160         // x-axis unit
00161         g2.drawString(SequenceColumn.STEP.getColumnName(project), (w - m) - 30, h - (m + 20));
00162         // origo 0
00163         txtW = metrics.stringWidth("0");
00164         g2.drawString("0", m / 2 - txtW, yFix + (m / 2) + (txtH / 2));
00165 
00166         // draw points
00167         int ps = (Math.min(xArea, yArea) / 60) + 4; // points size
00168         for (int i = 0; i < points.size(); i++) {
00169             int x = new Double((points.elementAt(i).getX() / xMax) * xArea).intValue();
00170             int y = new Double((points.elementAt(i).getY() / yMax) * yArea).intValue();
00171             g2.fillOval((xFix + x) - (ps / 2), (yFix - y) - (ps / 2), ps, ps);
00172         }
00173         if (points.size() >= 2) {
00174             for (int i = 1; i < points.size(); i++) {
00175                 int x1 = new Double((points.elementAt(i - 1).getX() / xMax) * xArea).intValue();
00176                 int y1 = new Double((points.elementAt(i - 1).getY() / yMax) * yArea).intValue();
00177                 int x2 = new Double((points.elementAt(i).getX() / xMax) * xArea).intValue();
00178                 int y2 = new Double((points.elementAt(i).getY() / yMax) * yArea).intValue();
00179 
00180                 g2.drawLine(xFix + x1, yFix - y1, xFix + x2, yFix - y2);
00181             }
00182         }
00183 
00184     }
00185 }

Generated on Fri May 6 16:00:31 2005 for Squid by  doxygen 1.4.1