1
6 import java.awt.geom.*;
7 import java.awt.*;
8
9 public class Vertex implements java.io.Serializable,Comparable {
10
11 private static final long serialVersionUID = Version.getSUID();
12
13 public static String DEFFAMILY = "sans";
14
15 public Vect position;
16 public String label;
17
18 static public TextForm labelfont = null;
19 static public Size marksize =null;
20
21 public Vertex(Vect pos) {
22 position = pos;
23 }
24
25 public Vertex(Vect pos,String lab) {
26 position = pos;
27 label = lab;
28 }
29
30 public Vertex(String lab) {
31 position = new Vect(0.0,0.0,0.0);
32 label = lab;
33 }
34
35 public Vertex(Vertex v) {
36 label = v.label;
37 position = new Vect(v.position);
38 }
39
40 public void draw(java.awt.Graphics g,Matrix mat) {
41 if (label != null) {
42 double[] p = mat.XY(position);
43 g.drawString(label, (int)p[0], -(int)p[1]);
44 }
45 }
46
47 public boolean equals(Object o) {
48 return((o instanceof Vertex) && (label.compareTo(((Vertex)o).label)==0));
49 }
50
51 public String toString(){return(label);}
52
53 public int compareTo(Object o) {
54 String olab = ((Vertex)o).label;
55 char a = ' ';
56 char b = ' ';
57 int na = 0;
58 int nb = 0;
59 for (int i=0;i<label.length() && i<olab.length();i++) {
60 a = label.charAt(i);
61 b = olab.charAt(i);
62 if (Character.isDigit(a)&&Character.isDigit(b)) {
63 for (int j=i;j<olab.length() && Character.isDigit(b=olab.charAt(j));j++)
64 nb = nb*10 + b - '0';
65 while(i<label.length() && Character.isDigit(a=label.charAt(i))) {
66 na = na*10 + a - '0';
67 i++;
68 }
69 if (na<nb) return(-1);
70 if (na>nb) return(1);
71 } else {
72 if (a<b) return(-1);
73 if (a>b) return(1);
74 na = nb = 0;
75 }
76 }
77 return(label.length()-olab.length());
78 }
79
80 public void mapdraw(Graphics g, AffineTransform trans) {
81 Point2D point = mappos(trans);
82 g.drawString(label,(int)point.getX(),(int)point.getY());
83 }
84
85 public Point2D mappos(AffineTransform trans) {
86 Point2D.Double res = new Point2D.Double();
87 trans.transform(new Point2D.Double(position.X[0],position.X[1]),res);
88 return(res);
89 }
90
91 public static void paintAll(java.util.Iterator it,View view) {
92
93 if (labelfont==null)
94 labelfont = (TextForm)FileDefaultable.lookup(TextForm.class,TextForm.STATION);
95 if (marksize==null)
96 marksize = (Size)FileDefaultable.lookup(Size.class,Size.STAMARK);
97
98 Color oldc = view.draw.getColor();
99 Color fontc = labelfont.color;
100
101 double fontscale = labelfont.size.getSize(view.mapscale)/16;
102 AffineTransform oldtrans = view.draw.getTransform();
103 view.draw.scale(fontscale,fontscale);
104 AffineTransform fonttrans = view.draw.getTransform();
105 view.draw.setTransform(oldtrans);
106
107 double size = marksize.getSize(view.mapscale);
108
109 while(it.hasNext()) {
110 Vertex current = (Vertex)it.next();
111
112 boolean showmark = view.visible.isMember(current);
113 boolean showlab = (current.label!=null && view.visible.isMember(current.label));
114
115 if (showlab || showmark) {
116 Point2D pos = new Point2D.Double(current.position.X[0],current.position.X[1]);
117 view.trans.transform(pos,pos);
118
119 Rectangle clip = view.getClipBounds();
120 if (clip==null ||
121
122
123 clip.contains(pos)) {
124
125 if (showmark) {
126 GeneralPath p = new GeneralPath();
127 p.moveTo((float)(pos.getX()+2*size),(float)(pos.getY()+size));
128 p.lineTo((float)(pos.getX()-2*size),(float)(pos.getY()+size));
129 p.lineTo((float)pos.getX(),(float)(pos.getY()-2*size));
130 p.closePath();
131 view.draw.draw(p);
132 }
133
134 if (showlab) {
135 view.draw.setColor(fontc);
136 view.draw.setFont(labelfont.getFont());
137 view.draw.setTransform(fonttrans);
138 view.draw.drawString(current.label,
139 (int)(1.5*size+pos.getX()/fontscale),
140 (int)(1.5*size+pos.getY()/fontscale));
141 view.draw.setTransform(oldtrans);
142 view.draw.setColor(oldc);
143 }
144 }
145 }
146 }
147 }
148
149 }
150