1 | /* |
---|
2 | * $Id: StrokeDrawer2.java,v 1.3 2001/12/13 00:16:16 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt; |
---|
14 | |
---|
15 | import java.awt.*; |
---|
16 | import java.awt.geom.*; |
---|
17 | |
---|
18 | /** |
---|
19 | * Implements stroke drawing using Java2D functionality. |
---|
20 | * |
---|
21 | * @author Donald Denbo |
---|
22 | * @version $Revision: 1.3 $, $Date: 2001/12/13 00:16:16 $ |
---|
23 | * @since 2.1 |
---|
24 | */ |
---|
25 | public class StrokeDrawer2 implements StrokeDrawer, Cloneable { |
---|
26 | |
---|
27 | public void drawHeavy(Graphics g, int[] xout, int[] yout, int size, |
---|
28 | LineAttribute attr) { |
---|
29 | Graphics2D g2 = (Graphics2D)g; |
---|
30 | Stroke saved = g2.getStroke(); |
---|
31 | BasicStroke stroke = new BasicStroke(attr.getWidth()); |
---|
32 | g2.setStroke(stroke); |
---|
33 | g2.drawPolyline(xout, yout, size); |
---|
34 | g2.setStroke(saved); |
---|
35 | } |
---|
36 | |
---|
37 | public void drawDashed(Graphics g, int[] xout, int[] yout, int size, |
---|
38 | LineAttribute attr) { |
---|
39 | Graphics2D g2 = (Graphics2D)g; |
---|
40 | Stroke saved = g2.getStroke(); |
---|
41 | float[] dashes = {4.0f, 4.0f}; |
---|
42 | BasicStroke stroke = new BasicStroke(1.0f, |
---|
43 | BasicStroke.CAP_SQUARE, |
---|
44 | BasicStroke.JOIN_MITER, |
---|
45 | 10.0f, |
---|
46 | dashes, |
---|
47 | 0.0f); |
---|
48 | g2.setStroke(stroke); |
---|
49 | g2.drawPolyline(xout, yout, size); |
---|
50 | g2.setStroke(saved); |
---|
51 | } |
---|
52 | |
---|
53 | public void drawStroke(Graphics g, int[] xout, int[] yout, int size, |
---|
54 | LineAttribute attr) { |
---|
55 | |
---|
56 | Graphics2D g2 = (Graphics2D)g; |
---|
57 | Stroke saved = g2.getStroke(); |
---|
58 | BasicStroke stroke; |
---|
59 | float[] arr = attr.getDashArray(); |
---|
60 | if(arr == null || (arr.length <= 1)) { |
---|
61 | stroke = new BasicStroke(attr.getWidth(), |
---|
62 | attr.getCapStyle(), |
---|
63 | attr.getMiterStyle(), |
---|
64 | attr.getMiterLimit()); |
---|
65 | } else { |
---|
66 | stroke = new BasicStroke(attr.getWidth(), |
---|
67 | attr.getCapStyle(), |
---|
68 | attr.getMiterStyle(), |
---|
69 | attr.getMiterLimit(), |
---|
70 | attr.getDashArray(), |
---|
71 | attr.getDashPhase()); |
---|
72 | } |
---|
73 | g2.setStroke(stroke); |
---|
74 | g2.drawPolyline(xout, yout, size); |
---|
75 | g2.setStroke(saved); |
---|
76 | } |
---|
77 | |
---|
78 | public void drawHighlight(Graphics g, int[] xout, int[] yout, int size, |
---|
79 | LineAttribute attr) { |
---|
80 | Graphics2D g2 = (Graphics2D)g; |
---|
81 | Stroke saved = g2.getStroke(); |
---|
82 | BasicStroke stroke = new BasicStroke(2.75f); |
---|
83 | Color col = attr.getColor(); |
---|
84 | Color rev = new Color(255 - col.getRed(), |
---|
85 | 255 - col.getGreen(), |
---|
86 | 255 - col.getBlue()); |
---|
87 | g2.setColor(rev); |
---|
88 | g2.setStroke(stroke); |
---|
89 | g2.drawPolyline(xout, yout, size); |
---|
90 | g2.setColor(col); |
---|
91 | g2.setStroke(saved); |
---|
92 | g2.drawPolyline(xout, yout, size); |
---|
93 | } |
---|
94 | |
---|
95 | } |
---|