01: /*******************************************************************************
02: * Copyright (c) 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.undo;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.swt.graphics.GC;
16:
17: /**
18: * A collection of boxes
19: */
20: public class Boxes {
21:
22: /*
23: * The "model," a list of boxes
24: */
25: private List boxes = new ArrayList();
26:
27: /*
28: * Constructs a box collection
29: */
30: public Boxes() {
31: super ();
32: }
33:
34: /*
35: * Add the specified box to the group of boxes.
36: */
37: public void add(Box box) {
38: boxes.add(box);
39: }
40:
41: /*
42: * Remove the specified box from the group of boxes.
43: */
44: public void remove(Box box) {
45: boxes.remove(box);
46: }
47:
48: /*
49: * Clear all the boxes from the list of boxes.
50: */
51: public void clear() {
52: boxes = new ArrayList();
53: }
54:
55: /*
56: * Return true if the group of boxes contains the specified box.
57: */
58: public boolean contains(Box box) {
59: return boxes.contains(box);
60: }
61:
62: /*
63: * Draw the boxes with the specified gc.
64: */
65: public void draw(GC gc) {
66: for (int i = 0; i < boxes.size(); i++) {
67: ((Box) boxes.get(i)).draw(gc);
68: }
69: }
70:
71: /*
72: * Return the box containing the specified x and y, or null
73: * if no box contains the point.
74: */
75: public Box getBox(int x, int y) {
76: for (int i = 0; i < boxes.size(); i++) {
77: Box box = (Box) boxes.get(i);
78: if (box.contains(x, y)) {
79: return box;
80: }
81: }
82: return null;
83: }
84:
85: /*
86: * Return the list of boxes known by this group of boxes.
87: */
88: public List getBoxes() {
89: return boxes;
90: }
91:
92: /*
93: * Set the list of boxes known by this group of boxes.
94: */
95: public void setBoxes(List boxes) {
96: this.boxes = boxes;
97: }
98:
99: }
|