blob: 59c1a17cf9263fd6c40a46fde66038aabe250cbe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*
Copyright (c) 2002 Palo Alto Research Center Incorporated. All Rights Reserved.
*/
package figures;
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
public class Group implements FigureElement {
private Collection _members;
private String _identifier;
public Group(FigureElement first) {
this._members = new ArrayList();
add(first);
}
public void add(FigureElement fe) {
_members.add(fe);
}
public Iterator members() {
return _members.iterator();
}
public void move(int dx, int dy) {
for (Iterator i = _members.iterator(); i.hasNext(); ) {
FigureElement fe = (FigureElement)i.next();
fe.move(dx, dy);
}
}
public void resetIdentifier(String identifier) {
resetIdentifier(identifier);
}
public String toString() {
if (_identifier != null) {
return _identifier;
}
StringBuffer buf = new StringBuffer("Group(");
for (Iterator i = _members.iterator(); i.hasNext(); ) {
buf.append(i.next().toString());
if (i.hasNext()) {
buf.append(", ");
}
}
buf.append(")");
return buf.toString();
}
public Rectangle getBounds() {
Rectangle previous = null;
for (Iterator i = _members.iterator(); i.hasNext(); ) {
FigureElement fe = (FigureElement)i.next();
Rectangle rect = fe.getBounds();
if (previous != null) {
previous = previous.union(rect);
} else {
previous = rect;
}
}
return previous;
}
public boolean contains(Point2D p) {
for (Iterator i = _members.iterator(); i.hasNext(); ) {
FigureElement fe = (FigureElement)i.next();
if (fe.contains(p)) return true;
}
return false;
}
public void paint(Graphics2D g2) {
for (Iterator i = _members.iterator(); i.hasNext(); ) {
FigureElement fe = (FigureElement)i.next();
fe.paint(g2);
}
}
public int size() {
return _members.size();
}
}
|