1 import java
.util
.Observable
;
2 import java
.util
.Observer
;
11 final static long serialVersionUID
= 1L;
15 protected double xScale
;
16 protected double yScale
;
17 protected int[] xPoints
;
18 protected int[] yPoints
;
19 protected int[] xScaledPoints
;
20 protected int[] yScaledPoints
;
21 protected final int border
= 20;
23 protected Environment env
;
24 protected Graph graph
;
25 protected Coordinate coordinate
;
31 public AntView(int rect_dim
) {
32 this(rect_dim
, rect_dim
, 10*rect_dim
, 10*rect_dim
);
38 this(rect_dim
, rect_dim
, wsize
, wsize
);
48 POINTS
= new Color
[xdim
][ydim
];
49 DATA
= new Double
[xdim
][ydim
];
50 for (int x
= 0; x
< xdim
; x
++) {
51 for (int y
= 0; y
< ydim
; y
++) {
52 POINTS
[x
][y
] = new Color(255,255,255);
57 JFrame f
= new JFrame("Calendar");
59 f
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
61 Container cp
= f
.getContentPane();
62 cp
.setBackground(Color
.white
);
63 cp
.add("Center", this);
66 f
.setSize(new Dimension(wxsize
,wysize
));
71 public Color
getPOINT(int x
, int y
) {
72 if (x
< XDIM
&& y
< YDIM
&& x
>= 0 && y
>= 0)
73 return this.POINTS
[x
][y
];
78 public void setPOINT(int x
, int y
, Color color
) {
79 if (x
< XDIM
&& y
< YDIM
&& x
>= 0 && y
>= 0)
80 this.POINTS
[x
][y
] = color
;
85 public Double
getDATA(int x
, int y
) {
86 if (x
< XDIM
&& y
< YDIM
&& x
>= 0 && y
>= 0)
87 return this.DATA
[x
][y
];
92 public void setDATA(int x
, int y
, Double val
) {
93 if (x
< XDIM
&& y
< YDIM
&& x
>= 0 && y
>= 0)
94 this.DATA
[x
][y
] = val
;
99 public void paint(Graphics g
) {
100 this.setBackground(Color
.getColor("OPAQUE"));
104 public void update() {
105 this.update(this.getGraphics());
108 public void update(Graphics g
) {
109 Graphics2D g2
= (Graphics2D
)g
;
111 Dimension d
= getSize();
113 XPSIZE
= d
.width
/ XDIM
;
114 YPSIZE
= d
.height
/ YDIM
;
116 XBORDER
= XPSIZE
/10 + 1;
117 YBORDER
= YPSIZE
/10 + 1;
121 for (int x
= 0; x
< XDIM
; x
++) {
122 for (int y
= 0; y
< YDIM
; y
++) {
123 g2
.setColor(POINTS
[x
][y
]);
124 g2
.fillRect(x
* (XPSIZE
+ YBORDER
),
125 y
* (YPSIZE
+ YBORDER
), XPSIZE
, YPSIZE
);
130 public void calibrate() {
132 double min
= Double
.MAX_VALUE
, max
= Double
.MIN_VALUE
;
134 for (int x
= 0; x
< XDIM
; x
++) {
135 for (int y
= 0; y
< YDIM
; y
++) {
136 double dval
= getDATA(x
, y
);
144 this.dataRange
= max
- min
;
148 public void calibrate(double max
, double min
) {
149 this.dataRange
= max
- min
;
152 /* no @Override or x10c will complain! */
153 public void update(Observable o
, Object arg
) {
155 int[] Tour
= (int[])arg
;
157 this.setDATA(i
, i
, 1.0);
158 this.setPOINT(i
, i
, new Color( 0 ) );
165 public void drawCities(Graphics2D g2
) {
167 g2
.setColor(new Color(0, 0, 128));
169 for (int c
= 0; c
< graph
.getNumOfCities(); c
++) {
170 g2
.fillOval(xScaledPoints
[c
] - 8, yScaledPoints
[c
] - 8, 16, 16);
174 public void drawCityWeb(Graphics2D g2
) {
175 g2
.setColor(new Color(210, 210, 210));
176 g2
.setStroke(new BasicStroke(0.25f
));
178 for (int c1
= 0; c1
< graph
.getNumOfCities(); c1
++) {
179 for (int c2
= 0; c2
< graph
.getNumOfCities(); c2
++) {
180 g2
.drawLine(xScaledPoints
[c1
], yScaledPoints
[c1
], xScaledPoints
[c2
], yScaledPoints
[c2
]);
185 public void drawTourLines(Graphics2D g2
, int[] minTourXpoints
, int[] minTourYpoints
) {
186 g2
.setColor(new Color(200, 20, 20));
187 g2
.setStroke(new BasicStroke(1.75f
));
188 g2
.drawPolyline(minTourXpoints
, minTourYpoints
, graph
.getNumOfCities() + 1);