00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00086 int m = 20;
00087
00088 int aw = 4;
00089
00090 int al = 8;
00091
00092 int yPad = 20;
00093
00094 int xPad = 20;
00095
00096 double yMax = 1.1;
00097
00098 double xMax = 100.0;
00099
00100 for (Point2D point : points) {
00101
00102 xMax = Math.max(xMax, point.getX());
00103 }
00104
00105
00106 int yArea = getSize().height - ((2 * m) + yPad);
00107
00108 int xArea = getSize().width - ((2 * m) + xPad);
00109
00110 g2.setFont(new Font("Arial", Font.PLAIN, 8 + (Math.min(xArea, yArea) / 60)));
00111 FontMetrics metrics = g2.getFontMetrics();
00112
00113 int txtH = metrics.getHeight();
00114
00115 int txtW = 0;
00116
00117
00118 int xFix = m + aw;
00119
00120 int yFix = h - (m + aw);
00121
00122
00123 g2.drawLine(xFix, m, xFix, yFix);
00124
00125 g2.drawLine(xFix, yFix, w - m, yFix);
00126
00127 g2.drawLine(m, m + al, m + aw, m);
00128 g2.drawLine(m + (2 * aw), m + al, m + aw, m);
00129
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
00134
00135
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
00142 txtW = metrics.stringWidth("1.0");
00143 g2.drawString("1.0", m - (txtW), tick1_y1 + (txtH / 2));
00144
00145
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
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
00159 g2.drawString(SequenceColumn.RELATIVE_MAGNETIZATION.getColumnName(project), m + 20, m + 10);
00160
00161 g2.drawString(SequenceColumn.STEP.getColumnName(project), (w - m) - 30, h - (m + 20));
00162
00163 txtW = metrics.stringWidth("0");
00164 g2.drawString("0", m / 2 - txtW, yFix + (m / 2) + (txtH / 2));
00165
00166
00167 int ps = (Math.min(xArea, yArea) / 60) + 4;
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 }