Mercurial > hg > ristipolku
annotate game/IDMWidget.java @ 189:189cd8fe2304
Bump copyrights.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 20 Mar 2017 12:23:02 +0200 |
parents | fa9f29387cff |
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 base widget |
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 |
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 public class IDMWidget |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 { |
75 | 13 IDMWidget parent; |
14 IDMPoint pos, size, scale; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 int keyCode; |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
16 boolean modalWidget; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
17 |
171
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
18 IDMPoint textCurrPos, textCurrOffs; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
19 Paint textPaint; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
20 Font textFont; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
21 FontMetrics textMetrics; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
22 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
23 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 public IDMWidget() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 keyCode = -1; |
51 | 27 this.scale = new IDMPoint(1, 1); |
28 this.pos = new IDMPoint(0, 0); | |
75 | 29 this.size = new IDMPoint(0, 0); |
51 | 30 } |
31 | |
32 public IDMWidget(IDMPoint pos) | |
33 { | |
34 this(); | |
35 this.pos = pos; | |
36 } | |
37 | |
75 | 38 public IDMWidget(IDMPoint pos, IDMPoint size) |
39 { | |
40 this(); | |
41 this.pos = pos; | |
42 this.size = size; | |
43 } | |
44 | |
45 public void setParent(IDMWidget par) | |
46 { | |
47 this.parent = par; | |
48 } | |
49 | |
50 public void add(IDMWidget widget) | |
51 { | |
52 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
53 |
75 | 54 public void remove(IDMWidget widget) |
55 { | |
56 } | |
57 | |
58 public void setPos(IDMPoint pos) | |
51 | 59 { |
60 this.pos = pos; | |
61 } | |
62 | |
75 | 63 public void setPos(float x, float y) |
51 | 64 { |
65 this.pos = new IDMPoint(x, y); | |
66 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
67 |
75 | 68 public void setSize(IDMPoint size) |
69 { | |
70 this.size = size; | |
71 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
72 |
75 | 73 public void setSize(float w, float h) |
74 { | |
75 this.size = new IDMPoint(w, h); | |
76 } | |
51 | 77 |
78 public void setScale(IDMPoint scale) | |
79 { | |
80 this.scale = scale; | |
81 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
82 |
51 | 83 public void setScale(float x, float y) |
84 { | |
85 this.setScale(new IDMPoint(x, y)); | |
86 } | |
87 | |
88 public int getScaledX() | |
89 { | |
177
9f04e8ab180a
Make widget positions relative to parent. Implementation might be incorrect,
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
90 return (int) (pos.x * scale.x) + (parent != null ? parent.getScaledX() : 0); |
51 | 91 } |
92 | |
93 public int getScaledY() | |
94 { | |
177
9f04e8ab180a
Make widget positions relative to parent. Implementation might be incorrect,
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
95 return (int) (pos.y * scale.y) + (parent != null ? parent.getScaledY() : 0); |
75 | 96 } |
97 | |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
98 public int getScaledX(float x) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
99 { |
177
9f04e8ab180a
Make widget positions relative to parent. Implementation might be incorrect,
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
100 return (int) (x * scale.x) + (parent != null ? parent.getScaledX() : 0); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
101 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
102 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
103 public int getScaledY(float y) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
104 { |
177
9f04e8ab180a
Make widget positions relative to parent. Implementation might be incorrect,
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
105 return (int) (y * scale.y) + (parent != null ? parent.getScaledY() : 0); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
106 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
107 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
108 public int getScaledRelX(float x) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
109 { |
177
9f04e8ab180a
Make widget positions relative to parent. Implementation might be incorrect,
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
110 return (int) ((pos.x + x) * scale.x) + (parent != null ? parent.getScaledX() : 0); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
111 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
112 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
113 public int getScaledRelY(float y) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
114 { |
177
9f04e8ab180a
Make widget positions relative to parent. Implementation might be incorrect,
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
115 return (int) ((pos.y + y) * scale.y) + (parent != null ? parent.getScaledY() : 0); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
116 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
117 |
75 | 118 public int getScaledWidth() |
119 { | |
120 return (int) (size.x * scale.x); | |
121 } | |
122 | |
123 public int getScaledHeight() | |
124 { | |
125 return (int) (size.y * scale.y); | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 |
75 | 128 public boolean contains(float x, float y) |
129 { | |
130 return (x >= getScaledX() && | |
131 y >= getScaledY() && | |
132 x < getScaledX() + getScaledWidth() && | |
133 y < getScaledY() + getScaledHeight()); | |
134 } | |
135 | |
136 public boolean contains(Point where) | |
137 { | |
138 return contains(where.x, where.y); | |
139 } | |
140 | |
141 public boolean contains(IDMPoint where) | |
142 { | |
143 return contains(where.x, where.y); | |
144 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
145 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 public void paint(Graphics2D g) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
149 |
75 | 150 public boolean mousePressed(MouseEvent e) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 return false; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 |
75 | 155 public boolean mouseReleased(MouseEvent e) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 if (contains(e.getPoint())) |
75 | 158 { |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 clicked(); |
75 | 160 return true; |
161 } | |
162 return false; | |
50 | 163 } |
164 | |
75 | 165 public boolean mouseEntered(MouseEvent e) |
50 | 166 { |
75 | 167 return false; |
50 | 168 } |
169 | |
75 | 170 public boolean mouseExited(MouseEvent e) |
50 | 171 { |
75 | 172 return false; |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 // Generic key handler |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 public boolean keyPressed(KeyEvent e) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 if (e.getKeyCode() == keyCode) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 clicked(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 return true; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 else |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 return false; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
186 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 public void clicked() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 } |
171
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
190 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
191 public void setTextFont(Font font, FontMetrics metrics) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
192 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
193 textFont = font; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
194 textMetrics = metrics; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
195 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
196 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
197 public void setTextPaint(Paint paint) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
198 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
199 textPaint = paint; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
200 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
201 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
202 public void setCurrPos(IDMPoint npos) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
203 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
204 textCurrPos = npos; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
205 textCurrOffs = new IDMPoint(0, 0); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
206 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
207 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
208 public void setCurrPos(float x, float y) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
209 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
210 setCurrPos(new IDMPoint(x, y)); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
211 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
212 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
213 public void setCurrPosScaledRel(float x, float y) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
214 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
215 setCurrPos(new IDMPoint(getScaledRelX(x), getScaledRelY(y))); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
216 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
217 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
218 public void drawString(Graphics2D g, String text) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
219 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
220 Paint savePaint = g.getPaint(); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
221 g.setPaint(textPaint); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
222 g.setFont(textFont); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
223 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
224 int i = 0; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
225 while (i < text.length()) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
226 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
227 int p = text.indexOf("\n", i); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
228 boolean linefeed; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
229 String str; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
230 if (p >= i) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
231 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
232 str = text.substring(i, p); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
233 i = p + 1; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
234 linefeed = true; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
235 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
236 else |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
237 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
238 str = text.substring(i); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
239 i += str.length(); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
240 linefeed = false; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
241 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
242 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
243 g.drawString(str, textCurrPos.x + textCurrOffs.x, textCurrPos.y + textCurrOffs.y); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
244 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
245 if (linefeed) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
246 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
247 textCurrOffs.x = 0; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
248 textCurrOffs.y += textMetrics.getHeight(); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
249 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
250 else |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
251 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
252 textCurrOffs.x += textMetrics.stringWidth(str); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
253 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
254 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
255 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
256 g.setPaint(savePaint); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
257 } |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
258 |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
259 public boolean isModal() |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
260 { |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
261 return modalWidget; |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
262 } |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
263 |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
264 public void setModal(boolean m) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
265 { |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
266 modalWidget = m; |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
267 } |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
268 |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
269 public void sendMessage(String msg) |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
270 { |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
271 if (parent != null) |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
272 parent.sendMessage(msg); |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
273 } |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
274 |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
275 public String getMessage() |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
276 { |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
277 if (parent != null) |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
278 return parent.getMessage(); |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
279 else |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
280 return null; |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
281 } |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 } |