1 22 23 package info.monitorenter.gui.chart.demos; 24 25 import info.monitorenter.gui.chart.Chart2D; 26 import info.monitorenter.gui.chart.ITrace2D; 27 import info.monitorenter.gui.chart.TracePoint2D; 28 import info.monitorenter.gui.chart.traces.Trace2DBijective; 29 import info.monitorenter.gui.chart.traces.Trace2DLtd; 30 import info.monitorenter.gui.chart.traces.Trace2DLtdReplacing; 31 import info.monitorenter.gui.chart.traces.Trace2DLtdSorted; 32 import info.monitorenter.gui.chart.traces.Trace2DReplacing; 33 import info.monitorenter.gui.chart.traces.Trace2DSimple; 34 import info.monitorenter.gui.chart.traces.Trace2DSorted; 35 36 import java.awt.event.WindowAdapter ; 37 import java.awt.event.WindowEvent ; 38 39 import javax.swing.JFrame ; 40 41 42 56 public final class TraceTester { 57 58 70 static class HalfRandomPoints extends TraceTester.RandomPoints { 71 72 73 private double m_oldx = 0; 74 78 private double m_samexcount = 0; 79 80 98 HalfRandomPoints(final int minx, final int maxx, final int miny, final int maxy) { 99 super(minx, maxx, miny, maxy); 100 this.m_oldx = (maxx - minx) / 2; 101 } 102 103 106 public TracePoint2D nextPoint() { 107 if (this.m_samexcount == 10) { 108 this.m_samexcount = 0; 109 this.m_oldx = this.m_rand.nextDouble() * this.m_xrange + this.m_xmin; 110 } 111 this.m_samexcount++; 112 return new TracePoint2D(this.m_oldx, this.m_rand.nextDouble() * this.m_yrange + this.m_ymin); 113 } 114 } 115 116 124 private static class RandomPoints { 125 126 protected java.util.Random m_rand = new java.util.Random (); 127 128 129 protected double m_xmin; 130 131 132 protected double m_xrange; 133 134 135 protected double m_ymin; 136 137 138 protected double m_yrange; 139 140 158 RandomPoints(final int minx, final int maxx, final int miny, final int maxy) { 159 if (minx >= maxx) { 160 throw new IllegalArgumentException ("minx>=maxx!"); 161 } 162 if (miny >= maxy) { 163 throw new IllegalArgumentException ("miny>=maxy!"); 164 } 165 this.m_xmin = minx; 166 this.m_xrange = maxx - minx; 167 this.m_ymin = miny; 168 this.m_yrange = maxy - miny; 169 } 170 171 177 public TracePoint2D nextPoint() { 178 return new TracePoint2D(this.m_rand.nextDouble() * this.m_xrange + this.m_xmin, this.m_rand 179 .nextDouble() 180 * this.m_yrange + this.m_ymin); 181 } 182 183 } 184 185 192 public static void main(final String [] args) { 193 try { 194 Class [] traces = new Class [] {Trace2DSimple.class, Trace2DBijective.class, 195 Trace2DReplacing.class, Trace2DSorted.class, Trace2DLtd.class, Trace2DLtdReplacing.class, 196 Trace2DLtdSorted.class }; 197 RandomPoints rand = new RandomPoints(0, 3, 0, 3); 198 199 Chart2D test = new Chart2D(); 200 JFrame frame = new JFrame ("TraceTester"); 201 frame.addWindowListener(new WindowAdapter () { 202 public void windowClosing(final WindowEvent e) { 203 System.exit(0); 204 } 205 }); 206 207 frame.getContentPane().add(test); 208 frame.setSize(600, 500); 209 frame.setLocation(200, 200); 210 frame.setVisible(true); 211 ITrace2D current = null; 212 for (int i = 0; i < traces.length; i++) { 213 current = (ITrace2D) traces[i].newInstance(); 214 test.addTrace(current); 215 frame.setTitle("TraceTester: full-random, current: " + traces[i].getName()); 216 217 for (int j = 0; j < 200; j++) { 218 current.addPoint(rand.nextPoint()); 219 Thread.sleep(50); 220 } 221 Thread.sleep(2000); 222 test.removeTrace(current); 223 } 224 rand = new HalfRandomPoints(0, 3, 0, 3); 225 for (int i = 0; i < traces.length; i++) { 226 current = (ITrace2D) traces[i].newInstance(); 227 test.addTrace(current); 228 frame.setTitle("TraceTester: repeating x 10 times, current: " + traces[i].getName()); 229 230 for (int j = 0; j < 200; j++) { 231 current.addPoint(rand.nextPoint()); 232 Thread.sleep(50); 233 } 234 Thread.sleep(2000); 235 test.removeTrace(current); 236 } 237 238 System.exit(0); 239 240 } catch (Throwable f) { 241 f.printStackTrace(); 242 System.exit(0); 243 } 244 } 245 246 250 private TraceTester() { 251 } 253 254 } 255 | Popular Tags |