Mercurial > hg > ristipolku
annotate game/IDMContainer.java @ 172:f664e851bc07
Delete dead member.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Mar 2017 10:19:14 +0200 |
parents | e8eeac403e5f |
children | 55ea5821c802 |
rev | line source |
---|---|
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * Ristipolku IDM widget container |
151 | 3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 */ |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 package game; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 import java.awt.*; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 import java.awt.event.*; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 import java.util.*; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
75 | 12 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 public class IDMContainer extends IDMWidget |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 { |
75 | 15 private ArrayList<IDMWidget> children, queue; |
16 private int iterated; | |
17 private boolean modified; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 public IDMContainer() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 { |
75 | 21 children = new ArrayList<IDMWidget>(); |
22 iterated = 0; | |
23 modified = false; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
25 |
75 | 26 synchronized public void add(IDMWidget widget) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 { |
75 | 28 widget.setParent(this); |
29 if (iterated > 0) | |
30 { | |
31 queue.add(0, widget); | |
32 modified = true; | |
33 } | |
34 else | |
35 children.add(widget); | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
37 |
75 | 38 synchronized public void remove(IDMWidget widget) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 { |
75 | 40 widget.setParent(null); |
41 if (iterated > 0) | |
42 { | |
43 queue.remove(widget); | |
44 modified = true; | |
45 } | |
46 else | |
47 children.remove(widget); | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 } |
75 | 49 |
50 synchronized private void beginIteration() | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 { |
75 | 52 modified = false; |
53 if (iterated == 0) | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 { |
75 | 55 queue = new ArrayList<IDMWidget>(); |
56 for (IDMWidget widget : children) | |
57 queue.add(widget); | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 } |
75 | 59 iterated++; |
60 } | |
61 | |
62 synchronized private void endIteration() | |
63 { | |
64 if (modified && iterated == 1) | |
65 { | |
66 children = queue; | |
67 queue = null; | |
68 } | |
69 iterated--; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 |
75 | 72 synchronized public void paint(Graphics2D g) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 { |
75 | 74 // Paint in reverse order |
75 ListIterator<IDMWidget> iter = children.listIterator(children.size()); | |
76 | |
77 while (iter.hasPrevious()) | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 { |
75 | 79 final IDMWidget widget = iter.previous(); |
80 widget.paint(g); | |
50 | 81 } |
82 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
83 |
75 | 84 synchronized public boolean mousePressed(MouseEvent e) |
85 { | |
86 try { | |
87 beginIteration(); | |
88 for (IDMWidget widget : children) | |
89 { | |
90 if (widget.contains(e.getPoint())) | |
91 { | |
92 if (widget.mousePressed(e)) | |
93 return true; | |
94 } | |
95 } | |
96 } | |
97 finally { endIteration(); } | |
98 return false; | |
99 } | |
50 | 100 |
75 | 101 synchronized public boolean mouseReleased(MouseEvent e) |
50 | 102 { |
75 | 103 try { |
104 beginIteration(); | |
105 for (IDMWidget widget : children) | |
106 { | |
107 if (widget.mouseReleased(e)) | |
108 return true; | |
109 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 } |
75 | 111 finally { endIteration(); } |
112 return false; | |
113 } | |
114 | |
115 synchronized public boolean mouseExited(MouseEvent e) | |
116 { | |
117 try { | |
118 beginIteration(); | |
119 for (IDMWidget widget : children) | |
120 { | |
121 if (widget.mouseExited(e)) | |
122 return true; | |
123 } | |
124 } | |
125 finally { endIteration(); } | |
126 return false; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 |
75 | 129 synchronized public boolean mouseEntered(MouseEvent e) |
130 { | |
131 try { | |
132 beginIteration(); | |
133 for (IDMWidget widget : children) | |
134 { | |
135 if (widget.contains(e.getPoint())) | |
136 { | |
137 if (widget.mouseEntered(e)) | |
138 return true; | |
139 } | |
140 } | |
141 } | |
142 finally { endIteration(); } | |
143 return false; | |
144 } | |
145 | |
146 synchronized public boolean keyPressed(KeyEvent e) | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 { |
75 | 148 try { |
149 beginIteration(); | |
150 for (IDMWidget widget : children) | |
151 { | |
152 if (widget.keyPressed(e)) | |
153 return true; | |
154 } | |
155 } | |
156 finally { endIteration(); } | |
157 return false; | |
158 } | |
159 | |
160 synchronized public void setScale(IDMPoint scale) | |
161 { | |
162 beginIteration(); | |
163 for (IDMWidget widget : children) | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 { |
75 | 165 widget.setScale(scale); |
166 } | |
167 endIteration(); | |
168 } | |
169 | |
170 synchronized public boolean hasObject(Class c) | |
171 { | |
172 for (IDMWidget widget : children) | |
173 { | |
174 if (widget.getClass() == c) | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 return true; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 return false; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 } |
51 | 179 |
75 | 180 synchronized public boolean containsObject(Object o) |
51 | 181 { |
75 | 182 for (IDMWidget widget : children) |
51 | 183 { |
75 | 184 if (widget == o) |
185 return true; | |
51 | 186 } |
75 | 187 return false; |
51 | 188 } |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 } |