samer@0
|
1 /*
|
samer@0
|
2 * VectorPlotter.java
|
samer@0
|
3 *
|
samer@0
|
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
5 * All rights reserved.
|
samer@0
|
6 *
|
samer@0
|
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
8 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
9 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
10 */
|
samer@0
|
11
|
samer@0
|
12 package samer.maths;
|
samer@0
|
13
|
samer@0
|
14 import java.util.*;
|
samer@0
|
15 import java.awt.*;
|
samer@0
|
16 import java.awt.event.*;
|
samer@0
|
17 import samer.core.*;
|
samer@0
|
18 import samer.core.util.*;
|
samer@0
|
19 import samer.core.Agent.*;
|
samer@0
|
20 import samer.tools.*;
|
samer@0
|
21 import java.awt.image.IndexColorModel;
|
samer@0
|
22
|
samer@0
|
23 /**
|
samer@0
|
24 A Viewer that draws multiple traces: one for each element of a vector
|
samer@0
|
25 */
|
samer@0
|
26
|
samer@0
|
27 public class VectorTrace extends Trace
|
samer@0
|
28 {
|
samer@0
|
29 private Vec vec;
|
samer@0
|
30 private Renderer R;
|
samer@0
|
31 private int[] old;
|
samer@0
|
32 private Color[] cols;
|
samer@0
|
33
|
samer@0
|
34 public VectorTrace(Vec v)
|
samer@0
|
35 {
|
samer@0
|
36 IndexColorModel cmod=(IndexColorModel)Shell.get("colormap",ImageSourceBase.GREY);
|
samer@0
|
37 R=(Renderer)Shell.get("renderer",Renderer.LINE);
|
samer@0
|
38
|
samer@0
|
39 int N=v.size(), M=cmod.getMapSize();
|
samer@0
|
40 cols=new Color[N];
|
samer@0
|
41 old=new int[N];
|
samer@0
|
42 vec=v;
|
samer@0
|
43
|
samer@0
|
44 for (int i=0; i<N; i++) cols[i]=new Color(cmod.getRGB(i%M));
|
samer@0
|
45 }
|
samer@0
|
46
|
samer@0
|
47 protected void realized() { super.realized(); attach(); }
|
samer@0
|
48
|
samer@0
|
49 public void run()
|
samer@0
|
50 {
|
samer@0
|
51 super.run();
|
samer@0
|
52 Vec.Iterator it=vec.iterator();
|
samer@0
|
53 int i,j;
|
samer@0
|
54
|
samer@0
|
55 for (i=0; it.more(); i++) {
|
samer@0
|
56 j=height-map.toInt(it.next());
|
samer@0
|
57 graphics.setColor(cols[i]);
|
samer@0
|
58 R.draw(graphics,x1,x2,old[i],j,j0);
|
samer@0
|
59 old[i]=j;
|
samer@0
|
60 }
|
samer@0
|
61 }
|
samer@0
|
62 // .............. Agent bits ..............................
|
samer@0
|
63
|
samer@0
|
64 public void getCommands(Registry r)
|
samer@0
|
65 {
|
samer@0
|
66 super.getCommands(r);
|
samer@0
|
67 r.group(); r.add("line").add("fill").add("fill3d").add("steps");
|
samer@0
|
68 }
|
samer@0
|
69
|
samer@0
|
70 public void execute(String c, Environment env) throws Exception
|
samer@0
|
71 {
|
samer@0
|
72 if (c.equals("line")) { R=Renderer.LINE; }
|
samer@0
|
73 else if (c.equals("fill")) { R=Renderer.FILL; }
|
samer@0
|
74 else if (c.equals("fill3d")) { R=Renderer.FILL3D; }
|
samer@0
|
75 else if (c.equals("steps")) { R=Renderer.STEPS; }
|
samer@0
|
76 else super.execute(c,env);
|
samer@0
|
77 }
|
samer@0
|
78 }
|