01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.support;
16:
17: import java.awt.geom.AffineTransform;
18: import java.awt.geom.GeneralPath;
19: import java.awt.geom.PathIterator;
20:
21: import org.eclipse.swt.graphics.Path;
22:
23: /**
24: * Provides a single interface for interacting with swt Path objects and awt GeneralPath Objects. This is because right now Linux requires awt and other
25: * platforms use SWT.
26: *
27: * @author Jesse
28: * @since 1.1.0
29: */
30: public class PathAdapter {
31:
32: Path swtPath;
33: GeneralPath generalPath;
34:
35: public void lineTo(int x, int y) {
36: if (isPath())
37: swtPath.lineTo(x, y);
38: else
39: generalPath.lineTo(x, y);
40: }
41:
42: public void moveTo(int x, int y) {
43: if (isPath())
44: swtPath.moveTo(x, y);
45: else
46: generalPath.moveTo(x, y);
47: }
48:
49: public boolean isPath() {
50: return swtPath != null;
51: }
52:
53: public Path getPath() {
54: return swtPath;
55: }
56:
57: public PathIterator getPathIterator() {
58: if (isPath()) {
59: return new PathToPathIteratorAdapter(swtPath);
60: }
61: return generalPath.getPathIterator(AffineTransform
62: .getScaleInstance(0, 0));
63: }
64:
65: public void setPath(Path path2) {
66: swtPath = path2;
67: }
68:
69: public void setPath(GeneralPath path2) {
70: generalPath = path2;
71: }
72:
73: public void close() {
74: if (isPath())
75: swtPath.close();
76: else
77: generalPath.closePath();
78: }
79:
80: }
|