1 | /**
|
---|
2 | * WidgetCorner.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.items.widgets;
|
---|
20 |
|
---|
21 | import java.awt.Color;
|
---|
22 | import java.awt.Graphics2D;
|
---|
23 | import java.awt.Polygon;
|
---|
24 | import java.util.List;
|
---|
25 |
|
---|
26 | import org.expeditee.items.Dot;
|
---|
27 | import org.expeditee.items.ItemParentStateChangedEvent;
|
---|
28 | import org.expeditee.items.Text;
|
---|
29 |
|
---|
30 | public class WidgetCorner extends Dot {
|
---|
31 |
|
---|
32 | private InteractiveWidget _widgetSource;
|
---|
33 |
|
---|
34 | WidgetCorner(int x, int y, int id, InteractiveWidget widgetSource) {
|
---|
35 | super(x, y, id);
|
---|
36 |
|
---|
37 | if (widgetSource == null)
|
---|
38 | throw new NullPointerException("widgetSource");
|
---|
39 | _widgetSource = widgetSource;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void updatePolygon() {
|
---|
44 | super.updatePolygon();
|
---|
45 | if (_widgetSource != null)
|
---|
46 | _widgetSource.onBoundsChanged();
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public void setPosition(float x, float y) {
|
---|
51 | invalidateFill();
|
---|
52 | if (_widgetSource != null) { // _widgetSource == null on construction
|
---|
53 | if (!_widgetSource.setPositions(this, x, y)) {
|
---|
54 | super.setPosition(x, y);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | else {
|
---|
58 | super.setPosition(x, y);
|
---|
59 | }
|
---|
60 | invalidateFill();
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public void setXY(float x, float y) {
|
---|
65 | invalidateFill();
|
---|
66 | if (_widgetSource != null) { // _widgetSource == null on construction
|
---|
67 | if (!_widgetSource.setPositions(this, x, y)) {
|
---|
68 | super.setXY(x, y);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | else {
|
---|
72 | super.setXY(x, y);
|
---|
73 | }
|
---|
74 | invalidateFill();
|
---|
75 | }
|
---|
76 |
|
---|
77 | // @Override
|
---|
78 | // public void translate(Point2D origin, double ratio) {
|
---|
79 | // super.translate(origin, ratio);
|
---|
80 | // }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public void onParentStateChanged(ItemParentStateChangedEvent e) {
|
---|
84 | super.onParentStateChanged(e);
|
---|
85 | _widgetSource.onParentStateChanged(e);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public InteractiveWidget getWidgetSource() {
|
---|
89 | return _widgetSource;
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Override
|
---|
93 | public void paint(Graphics2D g) {
|
---|
94 | // For fixed widgets, always have corner selected with connected context
|
---|
95 | HighlightMode tmp = _mode; // save mode
|
---|
96 | if (_mode == HighlightMode.Normal && _widgetSource.isFixedSize()) {
|
---|
97 | _mode = HighlightMode.Connected; // draw as connected context for
|
---|
98 | // fixed widgets
|
---|
99 | }
|
---|
100 | super.paint(g);
|
---|
101 | _mode = tmp; // restore mode
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Override
|
---|
105 | public void paintFill(Graphics2D g) {
|
---|
106 | _widgetSource.paintFill(g); // only paints a fill if floating
|
---|
107 | }
|
---|
108 |
|
---|
109 | @Override
|
---|
110 | public void setAnnotation(boolean val) {
|
---|
111 | // Ignore
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Override
|
---|
115 | public boolean isAnnotation() {
|
---|
116 | return false;
|
---|
117 | }
|
---|
118 |
|
---|
119 | @Override
|
---|
120 | public String toString() {
|
---|
121 | return "WidgetCorner: [" + this.getX() + "," + this.getY() + "]";
|
---|
122 | }
|
---|
123 |
|
---|
124 | @Override
|
---|
125 | public void setArrow(float length, double ratio, double nib_perc) {
|
---|
126 | }
|
---|
127 |
|
---|
128 | @Override
|
---|
129 | public void setArrowhead(Polygon arrow) {
|
---|
130 | }
|
---|
131 |
|
---|
132 | @Override
|
---|
133 | public void setArrowheadLength(float length) {
|
---|
134 | }
|
---|
135 |
|
---|
136 | @Override
|
---|
137 | public void setArrowheadRatio(double ratio) {
|
---|
138 | }
|
---|
139 |
|
---|
140 | @Override
|
---|
141 | public void setBackgroundColor(Color c) {
|
---|
142 | if (_widgetSource != null) {
|
---|
143 | super.setBackgroundColor(c);
|
---|
144 | _widgetSource.setBackgroundColor(c);
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | @Override
|
---|
149 | public void setBottomShadowColor(Color bottom) {
|
---|
150 | }
|
---|
151 |
|
---|
152 | @Override
|
---|
153 | public void setFillColor(Color c) {
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Override
|
---|
157 | public void setFillPattern(String patternLink) {
|
---|
158 | }
|
---|
159 |
|
---|
160 | @Override
|
---|
161 | public void toggleDashed(int amount) {
|
---|
162 | }
|
---|
163 |
|
---|
164 | @Override
|
---|
165 | public void setSize(float size) {
|
---|
166 | }
|
---|
167 |
|
---|
168 | @Override
|
---|
169 | public String getLink() {
|
---|
170 | return _widgetSource.getSource().getLink();
|
---|
171 | }
|
---|
172 |
|
---|
173 | @Override
|
---|
174 | public boolean isAnchored() {
|
---|
175 | return _widgetSource.isAnchored();
|
---|
176 | }
|
---|
177 |
|
---|
178 | @Override
|
---|
179 | public boolean isAnchoredX() {
|
---|
180 | return _widgetSource.isAnchoredX();
|
---|
181 | }
|
---|
182 |
|
---|
183 | @Override
|
---|
184 | public boolean isAnchoredY() {
|
---|
185 | return _widgetSource.isAnchoredY();
|
---|
186 | }
|
---|
187 |
|
---|
188 | public void setAnchorCornerX(Float anchorLeft, Float anchorRight) {
|
---|
189 | _anchorLeft = anchorLeft;
|
---|
190 | _anchorRight = anchorRight;
|
---|
191 | }
|
---|
192 |
|
---|
193 | public void setAnchorCornerY(Float anchorTop, Float anchorBottom) {
|
---|
194 | _anchorTop = anchorTop;
|
---|
195 | _anchorBottom= anchorBottom;
|
---|
196 | }
|
---|
197 |
|
---|
198 | @Override
|
---|
199 | public void setAnchorLeft(Float anchor) {
|
---|
200 | _widgetSource.setAnchorLeft(anchor);
|
---|
201 | _anchorLeft = anchor;
|
---|
202 | _anchorRight = null;
|
---|
203 | }
|
---|
204 |
|
---|
205 | @Override
|
---|
206 | public void setAnchorRight(Float anchor) {
|
---|
207 | _widgetSource.setAnchorRight(anchor);
|
---|
208 | _anchorLeft = null;
|
---|
209 | _anchorRight = anchor;
|
---|
210 | }
|
---|
211 |
|
---|
212 | @Override
|
---|
213 | public void setAnchorTop(Float anchor) {
|
---|
214 | _widgetSource.setAnchorTop(anchor);
|
---|
215 | _anchorTop = anchor;
|
---|
216 | _anchorBottom = null;
|
---|
217 | }
|
---|
218 |
|
---|
219 | @Override
|
---|
220 | public void setAnchorBottom(Float anchor) {
|
---|
221 | _widgetSource.setAnchorBottom(anchor);
|
---|
222 | _anchorTop = null;
|
---|
223 | _anchorBottom = anchor;
|
---|
224 | }
|
---|
225 |
|
---|
226 | @Override
|
---|
227 | public void setLink(String link) {
|
---|
228 | _widgetSource.setLink(link, null);
|
---|
229 | }
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * @param link
|
---|
233 | * The new frame link. Can be null (for no link)
|
---|
234 | *
|
---|
235 | * @param linker
|
---|
236 | * The text item creating the link. Null if not created from
|
---|
237 | * a text item.
|
---|
238 | */
|
---|
239 | public void setLink(String link, Text linker) {
|
---|
240 | _widgetSource.setLink(link, linker);
|
---|
241 | }
|
---|
242 |
|
---|
243 | @Override
|
---|
244 | public void setFormula(String formula) {
|
---|
245 | }
|
---|
246 |
|
---|
247 | @Override
|
---|
248 | public void setData(List<String> data) {
|
---|
249 | _widgetSource.setSourceData(data);
|
---|
250 | }
|
---|
251 |
|
---|
252 | @Override
|
---|
253 | public boolean contains(int x, int y) {
|
---|
254 | return super.contains(x, y)
|
---|
255 | && !_widgetSource.getBounds().contains(x, y);
|
---|
256 | }
|
---|
257 |
|
---|
258 | @Override
|
---|
259 | public void setThickness(float newThickness, boolean setConnected) {
|
---|
260 | if (_widgetSource != null) {
|
---|
261 | float minThickness = _widgetSource.getMinimumBorderThickness();
|
---|
262 | if (newThickness < minThickness)
|
---|
263 | newThickness = minThickness;
|
---|
264 | super.setThickness(newThickness, setConnected);
|
---|
265 | _widgetSource.setSourceThickness(newThickness, false);
|
---|
266 | }
|
---|
267 | }
|
---|
268 |
|
---|
269 | @Override
|
---|
270 | public void setColor(Color color) {
|
---|
271 | if (_widgetSource != null) {
|
---|
272 | super.setColor(color);
|
---|
273 | _widgetSource.setSourceBorderColor(color);
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | @Override
|
---|
278 | public String getName() {
|
---|
279 | return _widgetSource.getName();
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 | }
|
---|