1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.util;
21
22 import java.awt.AlphaComposite;
23 import java.awt.BasicStroke;
24 import java.awt.Color;
25 import java.awt.Dimension;
26 import java.awt.FlowLayout;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.Paint;
30 import java.awt.RenderingHints;
31 import java.awt.TexturePaint;
32 import java.awt.image.BufferedImage;
33
34 import java.util.Calendar;
35 import java.util.Date;
36 import java.util.HashMap;
37
38
39
40
41
42
43
44
45
46
47 public final class PaintHelper
48 {
49 private static boolean enhanced = false;
50 private static RenderingHints qualityHints = null;
51
52
53 private static HashMap<Integer, BufferedImage> networkErrorImages;
54 private static HashMap<Integer, BufferedImage> warningImages = null;
55 private static HashMap<Integer, BufferedImage> alarmImages = null;
56 private static HashMap<Integer, BufferedImage> emergencyImages = null;
57 private static HashMap<Integer, BufferedImage> clockCaseImages = null;
58 private static HashMap<Integer, BufferedImage> minutePointers = null;
59 private static HashMap<Integer, BufferedImage> hourPointers = null;
60
61 private PaintHelper()
62 {
63 super();
64 }
65
66
67
68
69
70
71
72 public static RenderingHints getAntialiasingHints()
73 {
74 if (qualityHints == null) {
75 qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
76 RenderingHints.VALUE_ANTIALIAS_ON);
77 qualityHints.put(RenderingHints.KEY_RENDERING,
78 RenderingHints.VALUE_RENDER_QUALITY);
79 }
80
81 return qualityHints;
82 }
83
84
85
86
87
88
89
90
91 public static Paint getRasterPaint(Color color)
92 {
93 BufferedImage rasterPattern = new BufferedImage(2, 2,
94 BufferedImage.TYPE_4BYTE_ABGR);
95 Graphics2D patternGraphics = rasterPattern.createGraphics();
96 patternGraphics.setComposite(AlphaComposite.getInstance(
97 AlphaComposite.SRC_OVER, (float)0.30));
98 patternGraphics.setColor(color);
99 patternGraphics.fillRect(0, 0, 1, 1);
100 patternGraphics.fillRect(1, 1, 1, 1);
101
102 return new TexturePaint(rasterPattern,
103 rasterPattern.getRaster().getBounds());
104 }
105
106
107
108
109
110
111
112
113 public static Paint getLinePaint(Color color)
114 {
115 BufferedImage rasterPattern = new BufferedImage(3, 3,
116 BufferedImage.TYPE_4BYTE_ABGR);
117 Graphics2D patternGraphics = rasterPattern.createGraphics();
118 patternGraphics.setComposite(AlphaComposite.getInstance(
119 AlphaComposite.SRC_OVER, (float)0.30));
120 patternGraphics.setColor(color);
121 patternGraphics.fillRect(0, 0, 1, 1);
122 patternGraphics.fillRect(1, 1, 1, 1);
123 patternGraphics.fillRect(2, 2, 1, 1);
124
125 return new TexturePaint(rasterPattern,
126 rasterPattern.getRaster().getBounds());
127 }
128
129
130
131
132
133
134
135 public static void paintDisabled(Graphics g)
136 {
137 paintDisabled(g, g.getClipBounds().x, g.getClipBounds().y,
138 g.getClipBounds().width, g.getClipBounds().height);
139 }
140
141
142
143
144
145
146
147
148
149
150 public static void paintDisabled(Graphics g, int x, int y, int width,
151 int height)
152 {
153 if (enhanced) paintDisabledEnhanced(g,x,y,width,height);
154 else paintDisabledPlain(g,x,y,width,height);
155 }
156
157
158
159
160
161
162
163
164 private static void paintDisabledPlain(Graphics g, int x, int y, int width, int height) {
165 Graphics2D g2D = (Graphics2D)g;
166
167 int marginX = (int)(width * 0.1);
168 int marginY = (int)(height * 0.1);
169 int strokeWidth = Math.max((int)((width + height) * 0.005),1);
170 int lX = x + marginX + strokeWidth;
171 int cX = x + (int)(width * 0.5);
172 int rX = x + width - marginX - strokeWidth;
173 int tY = y + marginY + strokeWidth;
174 int cY = y + (int)(height * 0.5);
175 int bY = y + height - marginY - strokeWidth;
176
177
178
179 g2D.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND,
180 BasicStroke.JOIN_ROUND));
181 g2D.setColor(Color.darkGray);
182
183 int[] xp = {
184 lX, lX + marginX, cX, rX - marginX, rX, rX, cX + marginX, rX, rX,
185 rX - marginX, cX, lX + marginX, lX, lX, cX - marginX, lX, lX
186 };
187 int[] yp = {
188 tY, tY, cY - marginY, tY, tY, tY + marginY, cY, bY - marginY, bY,
189 bY, cY + marginY, bY, bY, bY - marginY, cY, tY + marginY, tY
190 };
191
192 g2D.drawPolyline(xp, yp, xp.length);
193 }
194
195
196
197
198
199
200
201
202 private static void paintDisabledEnhanced(Graphics g, int x, int y, int width, int height) {
203 int marginX = (int)(width * 0.1);
204 int marginY = (int)(height * 0.1);
205 int strokeWidth = Math.max((int)((width + height) * 0.005),1);
206 int lX = x + marginX + strokeWidth;
207 int cX = x + (int)(width * 0.5);
208 int rX = x + width - marginX - strokeWidth;
209 int tY = y + marginY + strokeWidth;
210 int cY = y + (int)(height * 0.5);
211 int bY = y + height - marginY - strokeWidth;
212
213 Graphics2D g2D = (Graphics2D)g;
214 g2D.addRenderingHints(getAntialiasingHints());
215 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
216 (float)0.40));
217
218
219 g2D.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND,
220 BasicStroke.JOIN_ROUND));
221 g2D.setColor(Color.darkGray);
222
223 int[] xp = {
224 lX, lX + marginX, cX, rX - marginX, rX, rX, cX + marginX, rX, rX,
225 rX - marginX, cX, lX + marginX, lX, lX, cX - marginX, lX, lX
226 };
227 int[] yp = {
228 tY, tY, cY - marginY, tY, tY, tY + marginY, cY, bY - marginY, bY,
229 bY, cY + marginY, bY, bY, bY - marginY, cY, tY + marginY, tY
230 };
231
232 g2D.drawPolyline(xp, yp, xp.length);
233 }
234
235
236
237
238
239
240
241
242
243
244 public static void paintDark(Graphics g, int x, int y, int width, int height)
245 {
246 if (enhanced) paintDarkEnhanced(g,x,y,width,height);
247 else paintDarkPlain(g,x,y,width,height);
248 }
249
250
251
252
253
254
255
256
257 private static void paintDarkPlain(Graphics g, int x, int y, int width, int height) {
258 Graphics2D g2D = (Graphics2D)g;
259
260 int marginX = (int)(width * 0.1);
261 int marginY = (int)(height * 0.1);
262 int strokeWidth = Math.max((int)((width + height) * 0.02),1);
263 int lX = x + marginX + strokeWidth;
264 int cX = x + (int)(width * 0.5);
265 int rX = x + width - marginX - strokeWidth;
266 int tY = y + marginY + strokeWidth;
267 int cY = y + (int)(height * 0.5);
268 int bY = y + height - marginY - strokeWidth;
269
270
271
272 g2D.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND,
273 BasicStroke.JOIN_ROUND));
274 g2D.setColor(Color.BLACK);
275
276 int[] xp = {
277 lX, lX + marginX, cX, rX - marginX, rX, rX, cX + marginX, rX, rX,
278 rX - marginX, cX, lX + marginX, lX, lX, cX - marginX, lX, lX
279 };
280 int[] yp = {
281 tY, tY, cY - marginY, tY, tY, tY + marginY, cY, bY - marginY, bY,
282 bY, cY + marginY, bY, bY, bY - marginY, cY, tY + marginY, tY
283 };
284
285 g2D.drawPolyline(xp, yp, xp.length);
286 paintRectangle(g,x,y,width,height,Color.BLACK,strokeWidth*2);
287 }
288
289
290
291
292
293
294
295
296 private static void paintDarkEnhanced(Graphics g, int x, int y, int width, int height) {
297 Graphics2D g2D = (Graphics2D)g;
298 g2D.addRenderingHints(getAntialiasingHints());
299 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
300 (float)0.9));
301 g2D.setColor(Color.BLACK);
302 g2D.fillRect(x, y, width, height);
303 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0));
304 }
305
306
307
308
309
310
311 public static void paintDark(Graphics g)
312 {
313 paintDark(g, g.getClipBounds().x, g.getClipBounds().y,
314 g.getClipBounds().width, g.getClipBounds().height);
315 }
316
317
318
319
320
321
322
323
324
325 public static void paintTimeout(Graphics g, int x, int y, int clockSize,
326 Date time)
327 {
328 if (enhanced) paintTimeoutEnhanced(g,x,y,clockSize,time);
329 else paintTimeoutPlain(g,x,y,clockSize,time);
330
331 }
332
333
334
335
336
337
338
339
340 private static void paintTimeoutPlain(Graphics g, int x, int y, int clockSize, Date time) {
341 float strokeWidth = (float)(clockSize / 75.);
342 double pointerWidth = Math.max(clockSize / 36., 1);
343
344 double minutePointerLength = (clockSize * 2.8) / 8.;
345 double hourPointerLength = (clockSize * 4.4) / 16.;
346 double backPointerLength = (clockSize * 2.) / 16.;
347 int[] xs = { 0, 0, 0, 0, 0, 0 };
348 int[] ys = { 0, 0, 0, 0, 0, 0 };
349
350 Calendar calendar = Calendar.getInstance();
351 calendar.setTime(time);
352
353 int hour = calendar.get(Calendar.HOUR_OF_DAY);
354 int minute = calendar.get(Calendar.MINUTE);
355 double hourAngle = (2 * Math.PI * (hour + (minute / 60.))) / 12.;
356 double minuteAngle = (2 * Math.PI * minute) / 60.;
357
358 Graphics2D g2D = (Graphics2D)g;
359 g2D.setColor(ColorHelper.getTimeOut());
360
361
362 g2D.setStroke(new BasicStroke(strokeWidth,
363 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
364 g2D.translate(x, y);
365
366
367
368
369
370 g2D.drawOval((clockSize / 2)
371 - (int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.)),
372 (clockSize / 2)
373 - (int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.)),
374 ((int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.))) * 2,
375 ((int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.))) * 2);
376 g2D.setStroke(new BasicStroke(
377 (float)(strokeWidth * 1.3), BasicStroke.CAP_ROUND,
378 BasicStroke.JOIN_MITER));
379 for (int i = 0; i < 12; i++) {
380 xs[0] = (clockSize / 2)
381 + (int)((((clockSize * 7.) / 8.) - (2.5 * strokeWidth)) / 2. * Math
382 .cos((2 * Math.PI * i) / 12));
383 ys[0] = (clockSize / 2)
384 + (int)((((clockSize * 7.) / 8.) - (2.5 * strokeWidth)) / 2. * Math
385 .sin((2 * Math.PI * i) / 12));
386 xs[1] = (clockSize / 2)
387 + (int)((((clockSize * 6.5) / 8.) - (2.5 * strokeWidth)) / 2. * Math
388 .cos((2 * Math.PI * i) / 12));
389 ys[1] = (clockSize / 2)
390 + (int)((((clockSize * 6.5) / 8.) - (2.5 * strokeWidth)) / 2. * Math
391 .sin((2 * Math.PI * i) / 12));
392 g2D.drawLine(xs[0], ys[0], xs[1], ys[1]);
393 }
394 g2D.translate(-x, -y);
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411 g2D.setStroke(new BasicStroke((int)pointerWidth,
412 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
413 g2D.rotate(hourAngle, (int)(x + (clockSize / 2.)),
414 (int)(y + (clockSize / 2.)));
415 g2D.translate((int)(x + ((clockSize ) / 2.)),
416 (int)((y + (clockSize / 2.)) - hourPointerLength));
417
418 g2D.drawLine(0,0,0,(int)(hourPointerLength+backPointerLength));
419 g2D.translate(-(int)(x + ((clockSize ) / 2.)),
420 -(int)((y + (clockSize / 2.)) - hourPointerLength));
421 g2D.rotate(-hourAngle, (int)(x + (clockSize / 2.)),
422 (int)(y + (clockSize / 2.)));
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440 g2D.rotate(minuteAngle, (int)(x + (clockSize / 2.)),
441 (int)(y + (clockSize / 2.)));
442 g2D.translate((int)(x + ((clockSize ) / 2.)),
443 (int)((y + (clockSize / 2.)) - minutePointerLength));
444 g2D.drawLine(0,0,0,(int)(minutePointerLength+backPointerLength));
445
446 g2D.translate(-(int)(x + ((clockSize ) / 2.)),
447 -(int)((y + (clockSize / 2.)) - minutePointerLength));
448 g2D.rotate(-minuteAngle, (int)(x + (clockSize / 2.)),
449 (int)(y + (clockSize / 2.)));
450 }
451
452
453
454
455
456
457
458
459 private static void paintTimeoutEnhanced(Graphics g, int x, int y, int clockSize, Date time) {
460
461
462 float strokeWidth = (float)(clockSize / 75.);
463 double pointerWidth = Math.max(clockSize / 36., 1);
464 double pointerTipWidth = clockSize / 110.;
465 double minutePointerLength = (clockSize * 2.8) / 8.;
466 double hourPointerLength = (clockSize * 4.4) / 16.;
467 double backPointerLength = (clockSize * 2.5) / 16.;
468 int[] xs = { 0, 0, 0, 0, 0, 0 };
469 int[] ys = { 0, 0, 0, 0, 0, 0 };
470 Integer size = new Integer(clockSize);
471
472 if (clockCaseImages == null) {
473 clockCaseImages = new HashMap<Integer, BufferedImage>();
474 }
475
476 if (clockCaseImages.get(size) == null) {
477
478 BufferedImage clockCaseImage = new BufferedImage(clockSize,
479 clockSize, BufferedImage.TYPE_4BYTE_ABGR);
480 Graphics2D clockCaseGraphics = clockCaseImage.createGraphics();
481 clockCaseGraphics.addRenderingHints(getAntialiasingHints());
482 clockCaseGraphics.setComposite(AlphaComposite.getInstance(
483 AlphaComposite.SRC_OVER, (float)0.40));
484 clockCaseGraphics.setStroke(new BasicStroke(strokeWidth,
485 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
486 clockCaseGraphics.setColor(ColorHelper.getTimeOut());
487 clockCaseGraphics.drawOval((clockSize / 2)
488 - (int)((clockSize / 2.) - (strokeWidth / 2.)),
489 (clockSize / 2) - (int)((clockSize / 2.) - (strokeWidth / 2.)),
490 ((int)((clockSize / 2.) - (strokeWidth / 2.))) * 2,
491 ((int)((clockSize / 2.) - (strokeWidth / 2.))) * 2);
492 clockCaseGraphics.drawOval((clockSize / 2)
493 - (int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.)),
494 (clockSize / 2)
495 - (int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.)),
496 ((int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.))) * 2,
497 ((int)(((clockSize * 7.) / 16.) - (strokeWidth / 2.))) * 2);
498 clockCaseGraphics.setStroke(new BasicStroke(
499 (float)(strokeWidth * 1.3), BasicStroke.CAP_ROUND,
500 BasicStroke.JOIN_MITER));
501
502 for (int i = 0; i < 12; i++) {
503 xs[0] = (clockSize / 2)
504 + (int)((((clockSize * 7.) / 8.) - (2.5 * strokeWidth)) / 2. * Math
505 .cos((2 * Math.PI * i) / 12));
506 ys[0] = (clockSize / 2)
507 + (int)((((clockSize * 7.) / 8.) - (2.5 * strokeWidth)) / 2. * Math
508 .sin((2 * Math.PI * i) / 12));
509 xs[1] = (clockSize / 2)
510 + (int)((((clockSize * 6.5) / 8.) - (2.5 * strokeWidth)) / 2. * Math
511 .cos((2 * Math.PI * i) / 12));
512 ys[1] = (clockSize / 2)
513 + (int)((((clockSize * 6.5) / 8.) - (2.5 * strokeWidth)) / 2. * Math
514 .sin((2 * Math.PI * i) / 12));
515 clockCaseGraphics.drawLine(xs[0], ys[0], xs[1], ys[1]);
516 }
517
518 clockCaseImages.put(new Integer(clockSize), clockCaseImage);
519 }
520
521 if (hourPointers == null) {
522 hourPointers = new HashMap<Integer, BufferedImage>();
523 }
524
525 if (hourPointers.get(size) == null) {
526
527 BufferedImage hourPointer = new BufferedImage((int)(pointerWidth),
528 (int)(hourPointerLength + backPointerLength),
529 BufferedImage.TYPE_4BYTE_ABGR);
530 Graphics2D hourPointerGraphics = hourPointer.createGraphics();
531 hourPointerGraphics.addRenderingHints(getAntialiasingHints());
532 hourPointerGraphics.setComposite(AlphaComposite.getInstance(
533 AlphaComposite.SRC_OVER, (float)0.40));
534 hourPointerGraphics.setStroke(new BasicStroke(strokeWidth,
535 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
536 hourPointerGraphics.setColor(ColorHelper.getTimeOut());
537 xs[0] = 0;
538 ys[0] = (int)(hourPointerLength);
539 xs[1] = 0 + (int)((pointerWidth - pointerTipWidth) / 2.);
540 ys[1] = 0;
541 xs[2] = 0 + (int)((pointerWidth + pointerTipWidth) / 2.);
542 ys[2] = 0;
543 xs[3] = 0 + (int)pointerWidth;
544 ys[3] = (int)(hourPointerLength);
545 xs[4] = 0 + (int)((pointerWidth + pointerTipWidth) / 2.);
546 ys[4] = (int)(hourPointerLength + backPointerLength);
547 xs[5] = 0 + (int)((pointerWidth - pointerTipWidth) / 2.);
548 ys[5] = (int)(hourPointerLength + backPointerLength);
549
550 hourPointerGraphics.fillPolygon(xs, ys, 6);
551 hourPointers.put(size, hourPointer);
552 }
553
554 if (minutePointers == null) {
555 minutePointers = new HashMap<Integer, BufferedImage>();
556 }
557
558 if (minutePointers.get(size) == null) {
559
560 BufferedImage minutePointer = new BufferedImage((int)(pointerWidth),
561 (int)(minutePointerLength + backPointerLength),
562 BufferedImage.TYPE_4BYTE_ABGR);
563 Graphics2D minutePointerGraphics = minutePointer.createGraphics();
564 minutePointerGraphics.addRenderingHints(getAntialiasingHints());
565 minutePointerGraphics.setComposite(AlphaComposite.getInstance(
566 AlphaComposite.SRC_OVER, (float)0.40));
567 minutePointerGraphics.setStroke(new BasicStroke(strokeWidth,
568 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
569 minutePointerGraphics.setColor(ColorHelper.getTimeOut());
570 xs[0] = 0;
571 ys[0] = (int)(minutePointerLength);
572 xs[1] = (int)((pointerWidth - pointerTipWidth) / 2.);
573 ys[1] = 0;
574 xs[2] = (int)((pointerWidth + pointerTipWidth) / 2.);
575 ys[2] = 0;
576 xs[3] = (int)pointerWidth;
577 ys[3] = (int)(minutePointerLength);
578 xs[4] = (int)((pointerWidth + pointerTipWidth) / 2.);
579 ys[4] = (int)(minutePointerLength + backPointerLength);
580 xs[5] = (int)((pointerWidth - pointerTipWidth) / 2.);
581 ys[5] = (int)(minutePointerLength + backPointerLength);
582
583 minutePointerGraphics.fillPolygon(xs, ys, 6);
584 minutePointers.put(size, minutePointer);
585 }
586
587 Calendar calendar = Calendar.getInstance();
588 calendar.setTime(time);
589
590 int hour = calendar.get(Calendar.HOUR_OF_DAY);
591 int minute = calendar.get(Calendar.MINUTE);
592 double hourAngle = (2 * Math.PI * (hour + (minute / 60.))) / 12.;
593 double minuteAngle = (2 * Math.PI * minute) / 60.;
594
595 Graphics2D g2D = (Graphics2D)g;
596 g2D.addRenderingHints(getAntialiasingHints());
597 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
598 (float)1.));
599 g2D.drawImage(clockCaseImages.get(size), null, x, y);
600 g2D.rotate(hourAngle, (int)(x + (clockSize / 2.)),
601 (int)(y + (clockSize / 2.)));
602 g2D.drawImage(hourPointers.get(size), null,
603 (int)(x + ((clockSize - pointerWidth) / 2.)),
604 (int)((y + (clockSize / 2.)) - hourPointerLength));
605 g2D.rotate(-hourAngle, (int)(x + (clockSize / 2.)),
606 (int)(y + (clockSize / 2.)));
607 g2D.rotate(minuteAngle, (int)(x + (clockSize / 2.)),
608 (int)(y + (clockSize / 2.)));
609 g2D.drawImage(minutePointers.get(size), null,
610 (int)(x + ((clockSize - pointerWidth) / 2.)),
611 (int)((y + (clockSize / 2.)) - minutePointerLength));
612 g2D.rotate(-minuteAngle, (int)(x + (clockSize / 2.)),
613 (int)(y + (clockSize / 2.)));
614 }
615
616
617
618
619
620
621
622
623
624
625
626 public static void paintRectangle(Graphics g, int x, int y, int width,
627 int height, Color color, float strokeWidth)
628 {
629 if (enhanced) paintRectangelEnhanced(g,x,y,width,height,color,strokeWidth);
630 else paintRectanglePlain(g,x,y,width,height,color,strokeWidth);
631 }
632
633
634
635
636
637
638
639
640
641
642 private static void paintRectanglePlain(Graphics g, int x, int y, int width, int height, Color color, float strokeWidth) {
643 Graphics2D g2D = (Graphics2D)g;
644
645 g2D.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND,
646 BasicStroke.JOIN_MITER));
647 g2D.setColor(color);
648 g2D.drawRect(x + (int)(strokeWidth), y + (int)(strokeWidth),
649 width - ((int)strokeWidth * 2), height - ((int)strokeWidth * 2));
650 }
651
652
653
654
655
656
657
658
659
660
661 private static void paintRectangelEnhanced(Graphics g, int x, int y, int width, int height, Color color, float strokeWidth) {
662 Graphics2D g2D = (Graphics2D)g;
663 g2D.addRenderingHints(getAntialiasingHints());
664 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
665 (float)0.40));
666 g2D.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND,
667 BasicStroke.JOIN_MITER));
668 g2D.setColor(color);
669 g2D.drawRect(x + (int)(strokeWidth), y + (int)(strokeWidth),
670 width - ((int)strokeWidth * 2), height - ((int)strokeWidth * 2));
671 }
672
673
674
675
676
677
678
679 public static void paintRectangle(Graphics g, Color color, float strokeWidth)
680 {
681 paintRectangle(g, g.getClipBounds().x, g.getClipBounds().y,
682 g.getClipBounds().width, g.getClipBounds().height, color,
683 strokeWidth);
684 }
685
686
687
688
689
690
691
692
693 public static void paintWarning(Graphics g, int x, int y, int warningSize)
694 {
695 if (enhanced) paintWarningEnhanced(g,x,y,warningSize);
696 else paintWarningPlain(g,x,y,warningSize);
697 }
698
699
700
701
702
703
704
705 private static void paintWarningPlain(Graphics g, int x, int y, int warningSize) {
706 float strokeWidth = (float)(warningSize / 70.);
707 double exclamationInset = warningSize / 5;
708 double exclamationWidth = warningSize / 3.;
709 double exclamationBright = warningSize / 25.;
710 double exclamationHeight = warningSize / 2.5;
711 double exclamationArcHeight = warningSize / 15.;
712 double exclamationPointSize = warningSize / 5.;
713 double exclamationPointInset = warningSize / 1.55;
714 int[] xs = { 0, 0, 0, 0 };
715 int[] ys = { 0, 0, 0, 0 };
716
717 xs[0] = (int)((warningSize - exclamationWidth) / 2);
718 ys[0] = (int)(exclamationInset);
719 xs[1] = (int)((warningSize + exclamationWidth) / 2);
720 ys[1] = (int)(exclamationInset);
721 xs[2] = (int)((warningSize + exclamationBright) / 2);
722 ys[2] = (int)(exclamationInset + exclamationHeight);
723 xs[3] = (int)((warningSize - exclamationBright) / 2);
724 ys[3] = (int)(exclamationInset + exclamationHeight);
725
726 Graphics2D g2D = (Graphics2D)g;
727 g2D.translate(x,y);
728
729 g2D.setColor(ColorHelper.getWarning());
730 g2D.setStroke(new BasicStroke(strokeWidth,
731 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
732 g2D.drawOval((int)(strokeWidth / 2.),
733 (int)(strokeWidth / 2.), (int)(warningSize - strokeWidth),
734 (int)(warningSize - strokeWidth));
735 g2D.setStroke(new BasicStroke((int)(strokeWidth / 2.),
736 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
737 g2D.drawLine(xs[0], ys[0], xs[3], ys[3]);
738 g2D.drawLine(xs[1], ys[1], xs[2], ys[2]);
739 g2D.drawLine(xs[2], ys[2], xs[3], ys[3]);
740 g2D.drawArc(xs[0],
741 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
742 (int)exclamationArcHeight, 0, 180);
743 g2D.drawOval((int)((warningSize - exclamationPointSize) / 2),
744 (int)(exclamationPointInset), (int)exclamationPointSize,
745 (int)exclamationPointSize);
746
747 g2D.translate(-x,-y);
748 }
749
750
751
752
753
754
755
756 private static void paintWarningEnhanced(Graphics g, int x, int y, int warningSize) {
757 float strokeWidth = (float)(warningSize / 70.);
758 double exclamationInset = warningSize / 5;
759 double exclamationWidth = warningSize / 3.;
760 double exclamationBright = warningSize / 25.;
761 double exclamationHeight = warningSize / 2.5;
762 double exclamationArcHeight = warningSize / 15.;
763 double exclamationPointSize = warningSize / 5.;
764 double exclamationPointInset = warningSize / 1.55;
765 int[] xs = { 0, 0, 0, 0 };
766 int[] ys = { 0, 0, 0, 0 };
767 Integer size = new Integer(warningSize);
768
769 if (warningImages == null) {
770 warningImages = new HashMap<Integer, BufferedImage>();
771 }
772
773 if (warningImages.get(size) == null) {
774
775 BufferedImage warningImage = new BufferedImage(warningSize,
776 warningSize, BufferedImage.TYPE_4BYTE_ABGR);
777 Graphics2D warningGraphics = warningImage.createGraphics();
778 warningGraphics.addRenderingHints(getAntialiasingHints());
779 warningGraphics.setComposite(AlphaComposite.getInstance(
780 AlphaComposite.SRC_OVER, (float)0.4));
781
782 warningGraphics.setColor(ColorHelper.getWarning());
783 warningGraphics.fillOval((int)(strokeWidth / 2.),
784 (int)(strokeWidth / 2.), (int)(warningSize - strokeWidth),
785 (int)(warningSize - strokeWidth));
786
787 warningGraphics.setColor(Color.WHITE);
788 xs[0] = (int)((warningSize - exclamationWidth) / 2);
789 ys[0] = (int)(exclamationInset);
790 xs[1] = (int)((warningSize + exclamationWidth) / 2);
791 ys[1] = (int)(exclamationInset);
792 xs[2] = (int)((warningSize + exclamationBright) / 2);
793 ys[2] = (int)(exclamationInset + exclamationHeight);
794 xs[3] = (int)((warningSize - exclamationBright) / 2);
795 ys[3] = (int)(exclamationInset + exclamationHeight);
796 warningGraphics.fillPolygon(xs, ys, 4);
797 warningGraphics.fillArc(xs[0],
798 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
799 (int)exclamationArcHeight, 0, 180);
800 warningGraphics.fillOval((int)((warningSize - exclamationPointSize) / 2),
801 (int)(exclamationPointInset), (int)exclamationPointSize,
802 (int)exclamationPointSize);
803
804 warningGraphics.setColor(ColorHelper.getWarning());
805 warningGraphics.setStroke(new BasicStroke(strokeWidth,
806 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
807 warningGraphics.drawOval((int)(strokeWidth / 2.),
808 (int)(strokeWidth / 2.), (int)(warningSize - strokeWidth),
809 (int)(warningSize - strokeWidth));
810 warningGraphics.setStroke(new BasicStroke(strokeWidth / 2,
811 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
812 warningGraphics.drawLine(xs[0], ys[0], xs[3], ys[3]);
813 warningGraphics.drawLine(xs[1], ys[1], xs[2], ys[2]);
814 warningGraphics.drawLine(xs[2], ys[2], xs[3], ys[3]);
815 warningGraphics.drawArc(xs[0],
816 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
817 (int)exclamationArcHeight, 0, 180);
818 warningGraphics.drawOval((int)((warningSize - exclamationPointSize) / 2),
819 (int)(exclamationPointInset), (int)exclamationPointSize,
820 (int)exclamationPointSize);
821 warningImages.put(size, warningImage);
822 }
823
824 Graphics2D g2D = (Graphics2D)g;
825 g2D.addRenderingHints(getAntialiasingHints());
826 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
827 (float)1.));
828 g2D.drawImage(warningImages.get(size), null, x, y);
829 }
830
831
832
833
834
835
836
837
838 public static void paintAlarm(Graphics g, int x, int y, int alarmSize)
839 {
840 paintAlarm(g,x,y,alarmSize,ColorHelper.getAlarmOutline());
841 }
842
843
844
845
846
847
848
849
850 public static void paintAlarmMinor(Graphics g, int x, int y, int alarmSize)
851 {
852 paintAlarm(g,x,y,alarmSize,ColorHelper.getAlarmMinor());
853 }
854
855
856
857
858
859
860
861 public static void paintAlarmMajor(Graphics g, int x, int y, int alarmSize)
862 {
863 paintAlarm(g,x,y,alarmSize,ColorHelper.getAlarmMajor());
864 }
865
866
867
868
869
870
871
872 public static void paintAlarmInvalid(Graphics g, int x, int y, int alarmSize)
873 {
874 paintAlarm(g,x,y,alarmSize,ColorHelper.getAlarmInvalid());
875 }
876
877
878
879
880
881
882
883 private static void paintAlarm(Graphics g, int x, int y, int alarmSize, Color c)
884 {
885 if (enhanced) paintAlarmEnhanced(g,x,y,alarmSize,c);
886 else paintAlarmPlain(g,x,y,alarmSize,c);
887 }
888
889
890
891
892
893
894
895 private static void paintAlarmPlain(Graphics g, int x, int y, int alarmSize, Color c) {
896 float strokeWidth = (float)(alarmSize / 70.);
897 double exclamationInset = alarmSize / 5;
898 double exclamationWidth = alarmSize / 3.;
899 double exclamationBright = alarmSize / 25.;
900 double exclamationHeight = alarmSize / 2.5;
901 double exclamationArcHeight = alarmSize / 15.;
902 double exclamationPointSize = alarmSize / 5.;
903 double exclamationPointInset = alarmSize / 1.55;
904 int[] xs = { 0, 0, 0, 0 };
905 int[] ys = { 0, 0, 0, 0 };
906
907 xs[0] = (int)((alarmSize - exclamationWidth) / 2);
908 ys[0] = (int)(exclamationInset);
909 xs[1] = (int)((alarmSize + exclamationWidth) / 2);
910 ys[1] = (int)(exclamationInset);
911 xs[2] = (int)((alarmSize + exclamationBright) / 2);
912 ys[2] = (int)(exclamationInset + exclamationHeight);
913 xs[3] = (int)((alarmSize - exclamationBright) / 2);
914 ys[3] = (int)(exclamationInset + exclamationHeight);
915
916 Graphics2D g2D = (Graphics2D)g;
917 if (c==null) {
918 c=ColorHelper.getAlarmOutline();
919 }
920 g2D.setColor(c);
921 g2D.setStroke(new BasicStroke(strokeWidth,
922 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
923 g2D.translate(x,y);
924 g2D.drawOval((int)(strokeWidth / 2.),
925 (int)(strokeWidth / 2.), (int)(alarmSize - strokeWidth),
926 (int)(alarmSize - strokeWidth));
927 g2D.setStroke(new BasicStroke(strokeWidth / 2,
928 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
929 g2D.drawLine(xs[0], ys[0], xs[3], ys[3]);
930 g2D.drawLine(xs[1], ys[1], xs[2], ys[2]);
931 g2D.drawLine(xs[2], ys[2], xs[3], ys[3]);
932 g2D.drawArc(xs[0],
933 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
934 (int)exclamationArcHeight, 0, 180);
935 g2D.drawOval((int)((alarmSize - exclamationPointSize) / 2),
936 (int)(exclamationPointInset), (int)exclamationPointSize,
937 (int)exclamationPointSize);
938 g2D.translate(-x,-y);
939 }
940
941
942
943
944
945
946
947 private static void paintAlarmEnhanced(Graphics g, int x, int y, int alarmSize, Color c) {
948 float strokeWidth = (float)(alarmSize / 70.);
949 double exclamationInset = alarmSize / 5;
950 double exclamationWidth = alarmSize / 3.;
951 double exclamationBright = alarmSize / 25.;
952 double exclamationHeight = alarmSize / 2.5;
953 double exclamationArcHeight = alarmSize / 15.;
954 double exclamationPointSize = alarmSize / 5.;
955 double exclamationPointInset = alarmSize / 1.55;
956 int[] xs = { 0, 0, 0, 0 };
957 int[] ys = { 0, 0, 0, 0 };
958 Integer size = new Integer(alarmSize);
959
960 if (alarmImages == null) {
961 alarmImages = new HashMap<Integer, BufferedImage>();
962 }
963
964 if (alarmImages.get(size) == null) {
965
966 BufferedImage alarmImage = new BufferedImage(alarmSize, alarmSize,
967 BufferedImage.TYPE_4BYTE_ABGR);
968 Graphics2D alarmGraphics = alarmImage.createGraphics();
969 alarmGraphics.addRenderingHints(getAntialiasingHints());
970 alarmGraphics.setComposite(AlphaComposite.getInstance(
971 AlphaComposite.SRC_OVER, (float)0.4));
972
973 alarmGraphics.setColor(ColorHelper.getAlarm());
974 alarmGraphics.fillOval((int)(strokeWidth / 2.),
975 (int)(strokeWidth / 2.), (int)(alarmSize - strokeWidth),
976 (int)(alarmSize - strokeWidth));
977
978 alarmGraphics.setColor(Color.WHITE);
979 xs[0] = (int)((alarmSize - exclamationWidth) / 2);
980 ys[0] = (int)(exclamationInset);
981 xs[1] = (int)((alarmSize + exclamationWidth) / 2);
982 ys[1] = (int)(exclamationInset);
983 xs[2] = (int)((alarmSize + exclamationBright) / 2);
984 ys[2] = (int)(exclamationInset + exclamationHeight);
985 xs[3] = (int)((alarmSize - exclamationBright) / 2);
986 ys[3] = (int)(exclamationInset + exclamationHeight);
987 alarmGraphics.fillPolygon(xs, ys, 4);
988 alarmGraphics.fillArc(xs[0],
989 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
990 (int)exclamationArcHeight, 0, 180);
991 alarmGraphics.fillOval((int)((alarmSize - exclamationPointSize) / 2),
992 (int)(exclamationPointInset), (int)exclamationPointSize,
993 (int)exclamationPointSize);
994
995 if (c==null) {
996 c=ColorHelper.getAlarmOutline();
997 }
998 alarmGraphics.setColor(c);
999 alarmGraphics.setStroke(new BasicStroke(strokeWidth,
1000 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1001 alarmGraphics.drawOval((int)(strokeWidth / 2.),
1002 (int)(strokeWidth / 2.), (int)(alarmSize - strokeWidth),
1003 (int)(alarmSize - strokeWidth));
1004 alarmGraphics.setStroke(new BasicStroke(strokeWidth / 2,
1005 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1006 alarmGraphics.drawLine(xs[0], ys[0], xs[3], ys[3]);
1007 alarmGraphics.drawLine(xs[1], ys[1], xs[2], ys[2]);
1008 alarmGraphics.drawLine(xs[2], ys[2], xs[3], ys[3]);
1009 alarmGraphics.drawArc(xs[0],
1010 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
1011 (int)exclamationArcHeight, 0, 180);
1012 alarmGraphics.drawOval((int)((alarmSize - exclamationPointSize) / 2),
1013 (int)(exclamationPointInset), (int)exclamationPointSize,
1014 (int)exclamationPointSize);
1015 alarmImages.put(size, alarmImage);
1016 }
1017
1018 Graphics2D g2D = (Graphics2D)g;
1019 g2D.addRenderingHints(getAntialiasingHints());
1020 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1021 (float)1.));
1022 g2D.drawImage(alarmImages.get(size), null, x, y);
1023 }
1024
1025
1026
1027
1028
1029
1030
1031
1032 public static void paintNetworkError(Graphics g, int x, int y,
1033 int networkSize)
1034 {
1035 if (enhanced) paintNetworkErrorEnhanced(g,x,y,networkSize);
1036 else paintNetworkErrorPlain(g,x,y,networkSize);
1037 }
1038
1039
1040
1041
1042
1043
1044
1045 private static void paintNetworkErrorPlain(Graphics g, int x, int y, int networkSize) {
1046 float strokeWidth = (float)(networkSize / 70.);
1047 double crossArmLength = networkSize / 4.;
1048 double crossArmWidth = networkSize / 6.;
1049 double crossCenter = networkSize / 2.;
1050 int[] xs = new int[12];
1051 int[] ys = new int[12];
1052
1053 xs[0] = (int)(crossCenter + (crossArmWidth / 2.));
1054 ys[0] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1055 xs[1] = (int)(crossCenter - (crossArmWidth / 2.));
1056 ys[1] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1057 xs[2] = (int)(crossCenter - (crossArmWidth / 2.));
1058 ys[2] = (int)(crossCenter - (crossArmWidth / 2.));
1059 xs[3] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1060 ys[3] = (int)(crossCenter - (crossArmWidth / 2.));
1061 xs[4] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1062 ys[4] = (int)(crossCenter + (crossArmWidth / 2.));
1063 xs[5] = (int)(crossCenter - (crossArmWidth / 2.));
1064 ys[5] = (int)(crossCenter + (crossArmWidth / 2.));
1065 xs[6] = (int)(crossCenter - (crossArmWidth / 2.));
1066 ys[6] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1067 xs[7] = (int)(crossCenter + (crossArmWidth / 2.));
1068 ys[7] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1069 xs[8] = (int)(crossCenter + (crossArmWidth / 2.));
1070 ys[8] = (int)(crossCenter + (crossArmWidth / 2.));
1071 xs[9] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1072 ys[9] = (int)(crossCenter + (crossArmWidth / 2.));
1073 xs[10] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1074 ys[10] = (int)(crossCenter - (crossArmWidth / 2.));
1075 xs[11] = (int)(crossCenter + (crossArmWidth / 2.));
1076 ys[11] = (int)(crossCenter - (crossArmWidth / 2.));
1077
1078 Graphics2D g2D = ((Graphics2D)g);
1079
1080 g2D.setColor(ColorHelper.getAlarmOutline());
1081 g2D.setStroke(new BasicStroke(strokeWidth,
1082 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1083 g2D.translate(x,y);
1084 g2D.drawOval((int)(strokeWidth / 2.),
1085 (int)(strokeWidth / 2.), (int)(networkSize - strokeWidth),
1086 (int)(networkSize - strokeWidth));
1087
1088 g2D.setStroke(new BasicStroke(strokeWidth / 2,
1089 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1090 g2D.translate(crossCenter, -crossCenter / 2.4);
1091 g2D.rotate(Math.PI / 4);
1092 g2D.drawLine(xs[0], ys[0], xs[1], ys[1]);
1093 g2D.drawLine(xs[1], ys[1], xs[2], ys[2]);
1094 g2D.drawLine(xs[2], ys[2], xs[3], ys[3]);
1095 g2D.drawLine(xs[3], ys[3], xs[4], ys[4]);
1096 g2D.drawLine(xs[4], ys[4], xs[5], ys[5]);
1097 g2D.drawLine(xs[5], ys[5], xs[6], ys[6]);
1098 g2D.drawLine(xs[6], ys[6], xs[7], ys[7]);
1099 g2D.drawLine(xs[7], ys[7], xs[8], ys[8]);
1100 g2D.drawLine(xs[8], ys[8], xs[9], ys[9]);
1101 g2D.drawLine(xs[9], ys[9], xs[10], ys[10]);
1102 g2D.drawLine(xs[10], ys[10], xs[11], ys[11]);
1103 g2D.drawLine(xs[11], ys[11], xs[0], ys[0]);
1104 g2D.rotate(-Math.PI / 4);
1105 g2D.translate(-crossCenter, crossCenter / 2.4);
1106 g2D.translate(-x,-y);
1107
1108 }
1109
1110
1111
1112
1113
1114
1115
1116 private static void paintNetworkErrorEnhanced(Graphics g, int x, int y, int networkSize) {
1117 float strokeWidth = (float)(networkSize / 70.);
1118 double crossArmLength = networkSize / 4.;
1119 double crossArmWidth = networkSize / 6.;
1120 double crossCenter = networkSize / 2.;
1121 int[] xs = new int[12];
1122 int[] ys = new int[12];
1123 Integer size = new Integer(networkSize);
1124
1125 if (networkErrorImages == null) {
1126 networkErrorImages = new HashMap<Integer, BufferedImage>();
1127 }
1128
1129 if (networkErrorImages.get(size) == null) {
1130
1131 BufferedImage networkImage = new BufferedImage(networkSize,
1132 networkSize, BufferedImage.TYPE_4BYTE_ABGR);
1133 Graphics2D networkGraphics = networkImage.createGraphics();
1134 networkGraphics.addRenderingHints(getAntialiasingHints());
1135 networkGraphics.setComposite(AlphaComposite.getInstance(
1136 AlphaComposite.SRC_OVER, (float)0.4));
1137
1138 networkGraphics.setColor(ColorHelper.getAlarm());
1139 networkGraphics.fillOval((int)(strokeWidth / 2.),
1140 (int)(strokeWidth / 2.), (int)(networkSize - strokeWidth),
1141 (int)(networkSize - strokeWidth));
1142
1143 networkGraphics.setColor(Color.WHITE);
1144 networkGraphics.translate(crossCenter, -crossCenter / 2.4);
1145 networkGraphics.rotate(Math.PI / 4);
1146 xs[0] = (int)(crossCenter + (crossArmWidth / 2.));
1147 ys[0] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1148 xs[1] = (int)(crossCenter - (crossArmWidth / 2.));
1149 ys[1] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1150 xs[2] = (int)(crossCenter - (crossArmWidth / 2.));
1151 ys[2] = (int)(crossCenter - (crossArmWidth / 2.));
1152 xs[3] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1153 ys[3] = (int)(crossCenter - (crossArmWidth / 2.));
1154 xs[4] = (int)(crossCenter - crossArmLength - (crossArmWidth / 2.));
1155 ys[4] = (int)(crossCenter + (crossArmWidth / 2.));
1156 xs[5] = (int)(crossCenter - (crossArmWidth / 2.));
1157 ys[5] = (int)(crossCenter + (crossArmWidth / 2.));
1158 xs[6] = (int)(crossCenter - (crossArmWidth / 2.));
1159 ys[6] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1160 xs[7] = (int)(crossCenter + (crossArmWidth / 2.));
1161 ys[7] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1162 xs[8] = (int)(crossCenter + (crossArmWidth / 2.));
1163 ys[8] = (int)(crossCenter + (crossArmWidth / 2.));
1164 xs[9] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1165 ys[9] = (int)(crossCenter + (crossArmWidth / 2.));
1166 xs[10] = (int)(crossCenter + crossArmLength + (crossArmWidth / 2.));
1167 ys[10] = (int)(crossCenter - (crossArmWidth / 2.));
1168 xs[11] = (int)(crossCenter + (crossArmWidth / 2.));
1169 ys[11] = (int)(crossCenter - (crossArmWidth / 2.));
1170 networkGraphics.fillPolygon(xs, ys, 12);
1171
1172 networkGraphics.rotate(-Math.PI / 4);
1173 networkGraphics.translate(-crossCenter, crossCenter / 2.4);
1174 networkGraphics.setColor(ColorHelper.getAlarmOutline());
1175 networkGraphics.setStroke(new BasicStroke(strokeWidth,
1176 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1177 networkGraphics.drawOval((int)(strokeWidth / 2.),
1178 (int)(strokeWidth / 2.), (int)(networkSize - strokeWidth),
1179 (int)(networkSize - strokeWidth));
1180
1181 networkGraphics.setStroke(new BasicStroke(strokeWidth / 2,
1182 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1183 networkGraphics.translate(crossCenter, -crossCenter / 2.4);
1184 networkGraphics.rotate(Math.PI / 4);
1185 networkGraphics.drawLine(xs[0], ys[0], xs[1], ys[1]);
1186 networkGraphics.drawLine(xs[1], ys[1], xs[2], ys[2]);
1187 networkGraphics.drawLine(xs[2], ys[2], xs[3], ys[3]);
1188 networkGraphics.drawLine(xs[3], ys[3], xs[4], ys[4]);
1189 networkGraphics.drawLine(xs[4], ys[4], xs[5], ys[5]);
1190 networkGraphics.drawLine(xs[5], ys[5], xs[6], ys[6]);
1191 networkGraphics.drawLine(xs[6], ys[6], xs[7], ys[7]);
1192 networkGraphics.drawLine(xs[7], ys[7], xs[8], ys[8]);
1193 networkGraphics.drawLine(xs[8], ys[8], xs[9], ys[9]);
1194 networkGraphics.drawLine(xs[9], ys[9], xs[10], ys[10]);
1195 networkGraphics.drawLine(xs[10], ys[10], xs[11], ys[11]);
1196 networkGraphics.drawLine(xs[11], ys[11], xs[0], ys[0]);
1197
1198 networkErrorImages.put(size, networkImage);
1199 }
1200
1201 Graphics2D g2D = ((Graphics2D)g);
1202
1203 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1204 (float)1.));
1205 g2D.drawImage(networkErrorImages.get(size), null, x, y);
1206 }
1207
1208
1209
1210
1211 public static void paintEmergency(Graphics g, int x, int y,
1212 int emergencySize)
1213 {
1214 if (enhanced) paintEmergencyEnhanced(g,x,y,emergencySize);
1215 else paintEmergencyPlain(g,x,y,emergencySize);
1216
1217 }
1218
1219
1220
1221
1222
1223
1224
1225 private static void paintEmergencyPlain(Graphics g, int x, int y, int emergencySize) {
1226 float strokeWidth = (float)(emergencySize / 35.);
1227 double exclamationInset = emergencySize / 5;
1228 double exclamationWidth = emergencySize / 3.;
1229 double exclamationBright = emergencySize / 25.;
1230 double exclamationHeight = emergencySize / 2.5;
1231 double exclamationArcHeight = emergencySize / 15.;
1232 double exclamationPointSize = emergencySize / 5.;
1233 double exclamationPointInset = emergencySize / 1.55;
1234 int[] xs = { 0, 0, 0, 0 };
1235 int[] ys = { 0, 0, 0, 0 };
1236
1237 xs[0] = (int)((emergencySize - exclamationWidth) / 2);
1238 ys[0] = (int)(exclamationInset);
1239 xs[1] = (int)((emergencySize + exclamationWidth) / 2);
1240 ys[1] = (int)(exclamationInset);
1241 xs[2] = (int)((emergencySize + exclamationBright) / 2);
1242 ys[2] = (int)(exclamationInset + exclamationHeight);
1243 xs[3] = (int)((emergencySize - exclamationBright) / 2);
1244 ys[3] = (int)(exclamationInset + exclamationHeight);
1245
1246 Graphics2D g2D = ((Graphics2D)g);
1247 g2D.setColor(ColorHelper.getEmergencyOutline());
1248 g2D.setStroke(new BasicStroke(strokeWidth,
1249 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1250 g2D.translate(x,y);
1251 g2D.drawOval((int)(strokeWidth / 2.),
1252 (int)(strokeWidth / 2.), (int)(emergencySize - strokeWidth),
1253 (int)(emergencySize - strokeWidth));
1254 g2D.setStroke(new BasicStroke(strokeWidth / 2,
1255 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1256 g2D.drawLine(xs[0], ys[0], xs[3], ys[3]);
1257 g2D.drawLine(xs[1], ys[1], xs[2], ys[2]);
1258 g2D.drawLine(xs[2], ys[2], xs[3], ys[3]);
1259 g2D.drawArc(xs[0],
1260 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
1261 (int)exclamationArcHeight, 0, 180);
1262 g2D.drawOval((int)((emergencySize
1263 - exclamationPointSize) / 2), (int)(exclamationPointInset),
1264 (int)exclamationPointSize, (int)exclamationPointSize);
1265 g2D.translate(-x,-y);
1266
1267 }
1268
1269
1270
1271
1272
1273
1274
1275 private static void paintEmergencyEnhanced(Graphics g, int x, int y, int emergencySize) {
1276 float strokeWidth = (float)(emergencySize / 35.);
1277 double exclamationInset = emergencySize / 5;
1278 double exclamationWidth = emergencySize / 3.;
1279 double exclamationBright = emergencySize / 25.;
1280 double exclamationHeight = emergencySize / 2.5;
1281 double exclamationArcHeight = emergencySize / 15.;
1282 double exclamationPointSize = emergencySize / 5.;
1283 double exclamationPointInset = emergencySize / 1.55;
1284 int[] xs = { 0, 0, 0, 0 };
1285 int[] ys = { 0, 0, 0, 0 };
1286 Integer size = new Integer(emergencySize);
1287
1288 if (emergencyImages == null) {
1289 emergencyImages = new HashMap<Integer, BufferedImage>();
1290 }
1291
1292 if (emergencyImages.get(size) == null) {
1293
1294 BufferedImage emergencyImage = new BufferedImage(emergencySize,
1295 emergencySize, BufferedImage.TYPE_4BYTE_ABGR);
1296 Graphics2D emergencyGraphics = emergencyImage.createGraphics();
1297 emergencyGraphics.addRenderingHints(getAntialiasingHints());
1298 emergencyGraphics.setComposite(AlphaComposite.getInstance(
1299 AlphaComposite.SRC_OVER, (float)0.4));
1300
1301 emergencyGraphics.setColor(ColorHelper.getEmergency());
1302 emergencyGraphics.fillOval((int)(strokeWidth / 2.),
1303 (int)(strokeWidth / 2.), (int)(emergencySize - strokeWidth),
1304 (int)(emergencySize - strokeWidth));
1305
1306 emergencyGraphics.setColor(Color.WHITE);
1307 xs[0] = (int)((emergencySize - exclamationWidth) / 2);
1308 ys[0] = (int)(exclamationInset);
1309 xs[1] = (int)((emergencySize + exclamationWidth) / 2);
1310 ys[1] = (int)(exclamationInset);
1311 xs[2] = (int)((emergencySize + exclamationBright) / 2);
1312 ys[2] = (int)(exclamationInset + exclamationHeight);
1313 xs[3] = (int)((emergencySize - exclamationBright) / 2);
1314 ys[3] = (int)(exclamationInset + exclamationHeight);
1315 emergencyGraphics.fillPolygon(xs, ys, 4);
1316 emergencyGraphics.fillArc(xs[0],
1317 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
1318 (int)exclamationArcHeight, 0, 180);
1319 emergencyGraphics.fillOval((int)((emergencySize
1320 - exclamationPointSize) / 2), (int)(exclamationPointInset),
1321 (int)exclamationPointSize, (int)exclamationPointSize);
1322
1323 emergencyGraphics.setColor(ColorHelper.getEmergencyOutline());
1324 emergencyGraphics.setStroke(new BasicStroke(strokeWidth,
1325 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1326 emergencyGraphics.drawOval((int)(strokeWidth / 2.),
1327 (int)(strokeWidth / 2.), (int)(emergencySize - strokeWidth),
1328 (int)(emergencySize - strokeWidth));
1329 emergencyGraphics.setStroke(new BasicStroke(strokeWidth / 2,
1330 BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
1331 emergencyGraphics.drawLine(xs[0], ys[0], xs[3], ys[3]);
1332 emergencyGraphics.drawLine(xs[1], ys[1], xs[2], ys[2]);
1333 emergencyGraphics.drawLine(xs[2], ys[2], xs[3], ys[3]);
1334 emergencyGraphics.drawArc(xs[0],
1335 ys[0] - (int)(exclamationArcHeight / 2), (int)exclamationWidth,
1336 (int)exclamationArcHeight, 0, 180);
1337 emergencyGraphics.drawOval((int)((emergencySize
1338 - exclamationPointSize) / 2), (int)(exclamationPointInset),
1339 (int)exclamationPointSize, (int)exclamationPointSize);
1340 emergencyImages.put(size, emergencyImage);
1341 }
1342
1343 Graphics2D g2D = ((Graphics2D)g);
1344
1345 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1346 (float)1.));
1347 g2D.drawImage(emergencyImages.get(size), null, x, y);
1348 }
1349
1350
1351
1352
1353 public static void main(String[] args)
1354 {
1355 javax.swing.JApplet applet = new javax.swing.JApplet() {
1356
1357 private static final long serialVersionUID = 1L;
1358
1359 public void init()
1360 {
1361
1362 javax.swing.JPanel mPanel = new javax.swing.JPanel() {
1363
1364
1365
1366 private static final long serialVersionUID = 1L;
1367
1368 public void paintComponent(Graphics g)
1369 {
1370 super.paintComponent(g);
1371
1372 long t = System.currentTimeMillis();
1373
1374 int width = getParent().getBounds().width;
1375 int height = getParent().getBounds().height;
1376 int x = getParent().getBounds().x;
1377 int y = getParent().getBounds().y;
1378 int size1 = (int)((Math.min(width, height) * 9.2) / 10);
1379
1380 paintAlarm(g,x+(width-size1)/2,y+(height-size1)/2,size1);
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390 System.out.println("Painted in "+(System.currentTimeMillis()-t)+" ms");
1391
1392
1393 }
1394 };
1395
1396 mPanel.setVisible(true);
1397 mPanel.setOpaque(false);
1398 mPanel.setSize(new Dimension(5000, 5000));
1399
1400 javax.swing.JPanel pn = new javax.swing.JPanel();
1401 pn.setLayout(new FlowLayout());
1402 pn.add(new javax.swing.JLabel("JLabel"));
1403 pn.add(new javax.swing.JSlider());
1404 pn.add(new javax.swing.JButton("JButton"));
1405 pn.add(new javax.swing.JTextField("JTextField"));
1406 this.getContentPane().add(pn);
1407 this.getLayeredPane().add(mPanel, new Integer(101), 0);
1408 }
1409 };
1410
1411 javax.swing.JFrame frame = new javax.swing.JFrame(
1412 "paintHelper Demo Applet");
1413 frame.getContentPane().add(applet);
1414 frame.setSize(300, 150);
1415 frame.addWindowListener(new java.awt.event.WindowAdapter() {
1416 public void windowClosing(java.awt.event.WindowEvent e)
1417 {
1418 System.exit(0);
1419 }
1420 });
1421 applet.init();
1422 applet.start();
1423 frame.setVisible(true);
1424 }
1425
1426
1427
1428
1429 public static void paintBumps(Graphics g, int x, int y, int width,
1430 int height, Color light, Color dark)
1431 {
1432 int bumpRight = (x + width) - 1;
1433 int bumpBottom = (y + height) - 1;
1434
1435 g.setColor(light);
1436
1437 for (int xi = x; xi < bumpRight; xi += 4) {
1438 for (int yi = y; yi < bumpBottom; yi += 4) {
1439 g.drawLine(xi, yi, xi, yi);
1440
1441 if (((xi + 2) < bumpRight) && ((yi + 2) < bumpBottom)) {
1442 g.drawLine(xi + 2, yi + 2, xi + 2, yi + 2);
1443 }
1444 }
1445 }
1446
1447 g.setColor(dark);
1448
1449 for (int xi = x; xi < bumpRight; xi += 4) {
1450 for (int yi = y; yi < bumpBottom; yi += 4) {
1451 g.drawLine(xi + 1, yi + 1, xi + 1, yi + 1);
1452
1453 if (((xi + 2) < bumpRight) && ((yi + 2) < bumpBottom)) {
1454 g.drawLine(xi + 3, yi + 3, xi + 3, yi + 3);
1455 }
1456 }
1457 }
1458 }
1459
1460
1461
1462
1463
1464
1465
1466
1467 public static boolean isEnhanced()
1468 {
1469 return enhanced;
1470 }
1471
1472
1473
1474
1475
1476
1477
1478 public static void setEnhanced(boolean antial)
1479 {
1480 enhanced = antial;
1481 }
1482 }
1483
1484