/Users/lyon/j4p/src/ip/transforms/Points.java
|
1 package ip.transforms;
2
3
4 import java.awt.*;
5 import java.util.Enumeration;
6 import java.util.Vector;
7
8
9 public class Points {
10 private Vector pointVector = new Vector();
11 private Enumeration pointEnumeration = null;
12
13 public void addPoint(Point p) {
14 pointVector.addElement(p);
15 }
16
17 public Point getPointAt(int i) {
18 return (Point) pointVector.elementAt(i);
19 }
20
21 public boolean hasMorePoints() {
22 if (pointEnumeration == null) pointEnumeration = getEnumeration();
23 return pointEnumeration.hasMoreElements();
24 }
25
26 public Point nextPoint() {
27 if (pointEnumeration == null) pointEnumeration = getEnumeration();
28 if (!hasMorePoints()) return null;
29 return (Point) pointEnumeration.nextElement();
30 }
31
32 private Enumeration getEnumeration() {
33 return pointVector.elements();
34 }
35
36 public int getSize() {
37 return pointVector.size();
38 }
39
40 public void drawUserPoints(Graphics g) {
41 for (int i = 0; i < getSize(); i++) {
42 Point p = getPointAt(i);
43 g.drawLine(p.x - 1, p.y - 1, p.x + 1, p.y + 1);
44 g.drawLine(p.x + 1, p.y - 1, p.x - 1, p.y + 1);
45 }
46 }
47
48 public static boolean isRangeValid(Point p1, Point p2, Dimension d) {
49 return isRangeValid(p1, d) && isRangeValid(p2, d);
50 }
51
52 public static boolean isRangeValid(Point p, Dimension d) {
53 return (p.x >= 0) && (p.y >= 0) && (p.x < d.width) && (p.y < d.height);
54 }
55
56
57 }
58
59
60
61