Mercurial > hg > ristipolku
annotate game/IDMContainer.java @ 205:76972d900783 default tip
Fix verbose build echos.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 29 Feb 2024 21:49:56 +0200 |
parents | 20231e8bbc43 |
children |
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 |
189 | 3 * (C) Copyright 2011-2017 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); |
203
20231e8bbc43
Set IDM child widget scale when added to a container.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
29 widget.setScale(this.scale); |
75 | 30 if (iterated > 0) |
31 { | |
32 queue.add(0, widget); | |
33 modified = true; | |
34 } | |
35 else | |
36 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
|
37 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
38 |
75 | 39 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
|
40 { |
75 | 41 widget.setParent(null); |
42 if (iterated > 0) | |
43 { | |
44 queue.remove(widget); | |
45 modified = true; | |
46 } | |
47 else | |
48 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
|
49 } |
75 | 50 |
51 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
|
52 { |
75 | 53 modified = false; |
54 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
|
55 { |
75 | 56 queue = new ArrayList<IDMWidget>(); |
57 for (IDMWidget widget : children) | |
58 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
|
59 } |
75 | 60 iterated++; |
61 } | |
62 | |
63 synchronized private void endIteration() | |
64 { | |
65 if (modified && iterated == 1) | |
66 { | |
67 children = queue; | |
68 queue = null; | |
69 } | |
70 iterated--; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
75 | 73 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
|
74 { |
75 | 75 // Paint in reverse order |
76 ListIterator<IDMWidget> iter = children.listIterator(children.size()); | |
77 | |
78 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
|
79 { |
75 | 80 final IDMWidget widget = iter.previous(); |
81 widget.paint(g); | |
50 | 82 } |
83 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
84 |
75 | 85 synchronized public boolean mousePressed(MouseEvent e) |
86 { | |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
87 IDMWidget modal = getActiveModalWidget(); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
88 if (modal != null) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
89 return modal.mousePressed(e); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
90 |
75 | 91 try { |
92 beginIteration(); | |
93 for (IDMWidget widget : children) | |
94 { | |
95 if (widget.contains(e.getPoint())) | |
96 { | |
97 if (widget.mousePressed(e)) | |
98 return true; | |
99 } | |
100 } | |
101 } | |
102 finally { endIteration(); } | |
103 return false; | |
104 } | |
50 | 105 |
75 | 106 synchronized public boolean mouseReleased(MouseEvent e) |
50 | 107 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
108 IDMWidget modal = getActiveModalWidget(); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
109 if (modal != null) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
110 return modal.mouseReleased(e); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
111 |
75 | 112 try { |
113 beginIteration(); | |
114 for (IDMWidget widget : children) | |
115 { | |
116 if (widget.mouseReleased(e)) | |
117 return true; | |
118 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 } |
75 | 120 finally { endIteration(); } |
121 return false; | |
122 } | |
123 | |
124 synchronized public boolean mouseExited(MouseEvent e) | |
125 { | |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
126 IDMWidget modal = getActiveModalWidget(); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
127 if (modal != null) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
128 return modal.mouseExited(e); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
129 |
75 | 130 try { |
131 beginIteration(); | |
132 for (IDMWidget widget : children) | |
133 { | |
134 if (widget.mouseExited(e)) | |
135 return true; | |
136 } | |
137 } | |
138 finally { endIteration(); } | |
139 return false; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 |
75 | 142 synchronized public boolean mouseEntered(MouseEvent e) |
143 { | |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
144 IDMWidget modal = getActiveModalWidget(); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
145 if (modal != null) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
146 return modal.mouseEntered(e); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
147 |
75 | 148 try { |
149 beginIteration(); | |
150 for (IDMWidget widget : children) | |
151 { | |
152 if (widget.contains(e.getPoint())) | |
153 { | |
154 if (widget.mouseEntered(e)) | |
155 return true; | |
156 } | |
157 } | |
158 } | |
159 finally { endIteration(); } | |
160 return false; | |
161 } | |
162 | |
163 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
|
164 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
165 IDMWidget modal = getActiveModalWidget(); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
166 if (modal != null) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
167 return modal.keyPressed(e); |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
168 |
75 | 169 try { |
170 beginIteration(); | |
171 for (IDMWidget widget : children) | |
172 { | |
173 if (widget.keyPressed(e)) | |
174 return true; | |
175 } | |
176 } | |
177 finally { endIteration(); } | |
178 return false; | |
179 } | |
180 | |
181 synchronized public void setScale(IDMPoint scale) | |
182 { | |
188
4568c8016377
Apply scale to IDMContainers also, not only to child widgets.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
183 super.setScale(scale); |
75 | 184 beginIteration(); |
185 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
|
186 { |
75 | 187 widget.setScale(scale); |
188 } | |
189 endIteration(); | |
190 } | |
191 | |
192 synchronized public boolean hasObject(Class c) | |
193 { | |
194 for (IDMWidget widget : children) | |
195 { | |
196 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
|
197 return true; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 return false; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 } |
51 | 201 |
75 | 202 synchronized public boolean containsObject(Object o) |
51 | 203 { |
75 | 204 for (IDMWidget widget : children) |
51 | 205 { |
75 | 206 if (widget == o) |
207 return true; | |
51 | 208 } |
75 | 209 return false; |
51 | 210 } |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
211 |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
212 synchronized public IDMWidget getActiveModalWidget() |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
213 { |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
214 for (IDMWidget widget : children) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
215 { |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
216 if (widget.isModal()) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
217 return widget; |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
218 } |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
219 return null; |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
220 } |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 } |