source: trunk/src/org/expeditee/items/widgets/WidgetCorner.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 6.1 KB
Line 
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
19package org.expeditee.items.widgets;
20
21import java.util.List;
22
23import org.expeditee.core.Colour;
24import org.expeditee.core.Point;
25import org.expeditee.core.bounds.PolygonBounds;
26import org.expeditee.items.Dot;
27import org.expeditee.items.ItemParentStateChangedEvent;
28import org.expeditee.items.Text;
29
30public class WidgetCorner extends Dot {
31
32 private Widget _widgetSource;
33
34 WidgetCorner(int x, int y, int id, Widget 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 setPosition(float x, float y) {
44 invalidateFill();
45 if (_widgetSource != null) { // _widgetSource == null on construction
46 if (!_widgetSource.setPositions(this, x, y)) {
47 super.setPosition(x, y);
48 }
49 }
50 else {
51 super.setPosition(x, y);
52 }
53 invalidateFill();
54 }
55
56 @Override
57 public void setXY(float x, float y) {
58 invalidateFill();
59 if (_widgetSource != null) { // _widgetSource == null on construction
60 if (!_widgetSource.setPositions(this, x, y)) {
61 super.setXY(x, y);
62 }
63 }
64 else {
65 super.setXY(x, y);
66 }
67 invalidateFill();
68 }
69
70 // @Override
71 // public void translate(Point2D origin, double ratio) {
72 // super.translate(origin, ratio);
73 // }
74
75 @Override
76 public void onParentStateChanged(ItemParentStateChangedEvent e)
77 {
78 super.onParentStateChanged(e);
79 _widgetSource.onParentStateChanged(e);
80 }
81
82 public Widget getWidgetSource() {
83 return _widgetSource;
84 }
85
86 @Override
87 public void paint()
88 {
89 // For fixed widgets, always have corner selected with connected context
90 HighlightMode tmp = _highlightMode; // save mode
91 if (_highlightMode == HighlightMode.Normal && _widgetSource.isFixedSize()) {
92 _highlightMode = HighlightMode.Connected; // draw as connected context for
93 // fixed widgets
94 }
95 super.paint();
96 _highlightMode = tmp; // restore mode
97 }
98
99 @Override
100 public void paintFill() {
101 _widgetSource.paintFill(); // only paints a fill if floating
102 }
103
104 @Override
105 public void setAnnotation(boolean val) {
106 // Ignore
107 }
108
109 @Override
110 public boolean isAnnotation() {
111 return false;
112 }
113
114 @Override
115 public String toString() {
116 return "WidgetCorner: [" + this.getX() + "," + this.getY() + "]";
117 }
118
119 @Override
120 public void setArrow(float length, double ratio, double nib_perc) {
121 }
122
123 @Override
124 public void setArrowhead(PolygonBounds arrow) {
125 }
126
127 @Override
128 public void setArrowheadLength(float length) {
129 }
130
131 @Override
132 public void setArrowheadRatio(double ratio) {
133 }
134
135 @Override
136 public void setBackgroundColor(Colour c) {
137 if (_widgetSource != null) {
138 super.setBackgroundColor(c);
139 _widgetSource.setBackgroundColor(c);
140 }
141 }
142
143 @Override
144 public void setBottomShadowColor(Colour bottom) {
145 }
146
147 @Override
148 public void setFillColor(Colour c) {
149 }
150
151 @Override
152 public void setFillPattern(String patternLink) {
153 }
154
155 @Override
156 public void toggleDashed(int amount) {
157 }
158
159 @Override
160 public void setSize(float size) {
161 }
162
163 @Override
164 public String getLink() {
165 return _widgetSource.getSource().getLink();
166 }
167
168 @Override
169 public boolean isAnchored() {
170 return _widgetSource.isAnchored();
171 }
172
173 @Override
174 public boolean isAnchoredX() {
175 return _widgetSource.isAnchoredX();
176 }
177
178 @Override
179 public boolean isAnchoredY() {
180 return _widgetSource.isAnchoredY();
181 }
182
183 public void setAnchorCornerX(Integer anchorLeft, Integer anchorRight)
184 {
185 _anchoring.setLeftAnchor(anchorLeft);
186 _anchoring.setRightAnchor(anchorRight);
187 }
188
189 public void setAnchorCornerY(Integer anchorTop, Integer anchorBottom)
190 {
191 _anchoring.setTopAnchor(anchorTop);
192 _anchoring.setBottomAnchor(anchorBottom);
193 }
194
195 @Override
196 public void setAnchorLeft(Integer anchor) {
197 _widgetSource.setAnchorLeft(anchor);
198 _anchoring.setLeftAnchor(anchor);
199 }
200
201 @Override
202 public void setAnchorRight(Integer anchor) {
203 _widgetSource.setAnchorRight(anchor);
204 _anchoring.setRightAnchor(anchor);
205 }
206
207 @Override
208 public void setAnchorTop(Integer anchor) {
209 _widgetSource.setAnchorTop(anchor);
210 _anchoring.setTopAnchor(anchor);
211 }
212
213 @Override
214 public void setAnchorBottom(Integer anchor) {
215 _widgetSource.setAnchorBottom(anchor);
216 _anchoring.setBottomAnchor(anchor);
217 }
218
219 @Override
220 public void setLink(String link) {
221 _widgetSource.setLink(link, null);
222 }
223
224 /**
225 * @param link
226 * The new frame link. Can be null (for no link)
227 *
228 * @param linker
229 * The text item creating the link. Null if not created from
230 * a text item.
231 */
232 public void setLink(String link, Text linker) {
233 _widgetSource.setLink(link, linker);
234 }
235
236 @Override
237 public void setFormula(String formula) {
238 }
239
240 @Override
241 public void setData(List<String> data) {
242 _widgetSource.setSourceData(data);
243 }
244
245 @Override
246 public boolean contains(Point p)
247 {
248 return super.contains(p) && !_widgetSource.getBounds().contains(p);
249 }
250
251 @Override
252 public void setThickness(float newThickness, boolean setConnected) {
253 if (_widgetSource != null) {
254 float minThickness = _widgetSource.getMinimumBorderThickness();
255 if (newThickness < minThickness)
256 newThickness = minThickness;
257 super.setThickness(newThickness, setConnected);
258 _widgetSource.setSourceThickness(newThickness, false);
259 }
260 }
261
262 @Override
263 public void setColor(Colour color) {
264 if (_widgetSource != null) {
265 super.setColor(color);
266 _widgetSource.setSourceBorderColor(color);
267 }
268 }
269
270 @Override
271 public String getName() {
272 return _widgetSource.getName();
273 }
274
275
276}
Note: See TracBrowser for help on using the repository browser.