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

Last change on this file since 474 was 474, checked in by davidb, 11 years ago

Additional work needed to support Nibb attribute for arrowhead tip thickness

File size: 4.7 KB
Line 
1package org.expeditee.items.widgets;
2
3import java.awt.Color;
4import java.awt.Graphics2D;
5import java.awt.Polygon;
6import java.util.List;
7
8import org.expeditee.items.Dot;
9import org.expeditee.items.ItemParentStateChangedEvent;
10import org.expeditee.items.Text;
11
12public class WidgetCorner extends Dot {
13
14 private InteractiveWidget _widgetSource;
15
16 WidgetCorner(int x, int y, int id, InteractiveWidget widgetSource) {
17 super(x, y, id);
18
19 if (widgetSource == null)
20 throw new NullPointerException("widgetSource");
21 _widgetSource = widgetSource;
22 }
23
24 @Override
25 public void updatePolygon() {
26 super.updatePolygon();
27 if (_widgetSource != null)
28 _widgetSource.onBoundsChanged();
29 }
30
31 @Override
32 public void setPosition(float x, float y) {
33 invalidateFill();
34 if (_widgetSource != null) { // _widgetSource == null on construction
35 if (!_widgetSource.setPositions(this, x, y)) {
36 super.setPosition(x, y);
37 }
38 } else
39 super.setPosition(x, y);
40 invalidateFill();
41 }
42
43 @Override
44 public void setXY(float x, float y) {
45 invalidateFill();
46 if (_widgetSource != null) { // _widgetSource == null on construction
47 if (!_widgetSource.setPositions(this, x, y)) {
48 super.setXY(x, y);
49 }
50 } else
51 super.setXY(x, y);
52 invalidateFill();
53 }
54
55 // @Override
56 // public void translate(Point2D origin, double ratio) {
57 // super.translate(origin, ratio);
58 // }
59
60 @Override
61 public void onParentStateChanged(ItemParentStateChangedEvent e) {
62 super.onParentStateChanged(e);
63 _widgetSource.onParentStateChanged(e);
64 }
65
66 public InteractiveWidget getWidgetSource() {
67 return _widgetSource;
68 }
69
70 @Override
71 public void paint(Graphics2D g) {
72 // For fixed widgets, always have corner selected with connected context
73 HighlightMode tmp = _mode; // save mode
74 if (_mode == HighlightMode.Normal && _widgetSource.isFixedSize()) {
75 _mode = HighlightMode.Connected; // draw as connected context for
76 // fixed widgets
77 }
78 super.paint(g);
79 _mode = tmp; // restore mode
80 }
81
82 @Override
83 public void paintFill(Graphics2D g) {
84 _widgetSource.paintFill(g); // only paints a fill if floating
85 }
86
87 @Override
88 public void setAnnotation(boolean val) {
89 // Ignore
90 }
91
92 @Override
93 public boolean isAnnotation() {
94 return false;
95 }
96
97 @Override
98 public String toString() {
99 return "WidgetCorner: [" + this.getX() + "," + this.getY() + "]";
100 }
101
102 @Override
103 public void setArrow(float length, double ratio, double nib_perc) {
104 }
105
106 @Override
107 public void setArrowhead(Polygon arrow) {
108 }
109
110 @Override
111 public void setArrowheadLength(float length) {
112 }
113
114 @Override
115 public void setArrowheadRatio(double ratio) {
116 }
117
118 @Override
119 public void setBackgroundColor(Color c) {
120 if (_widgetSource != null) {
121 super.setBackgroundColor(c);
122 _widgetSource.setBackgroundColor(c);
123 }
124 }
125
126 @Override
127 public void setBottomShadowColor(Color bottom) {
128 }
129
130 @Override
131 public void setFillColor(Color c) {
132 }
133
134 @Override
135 public void setFillPattern(String patternLink) {
136 }
137
138 @Override
139 public void toggleDashed(int amount) {
140 }
141
142 @Override
143 public void setSize(float size) {
144 }
145
146 @Override
147 public String getLink() {
148 return _widgetSource.getSource().getLink();
149 }
150
151 @Override
152 public void setAnchorBottom(Float anchor) {
153 _widgetSource.setAnchorBottom(anchor);
154 }
155
156 @Override
157 public void setAnchorRight(Float anchor) {
158 _widgetSource.setAnchorRight(anchor);
159 }
160
161 @Override
162 public Float getAnchorBottom() {
163 return _widgetSource.getSource().getAnchorBottom();
164 }
165
166 @Override
167 public Float getAnchorRight() {
168 return _widgetSource.getSource().getAnchorRight();
169 }
170
171 @Override
172 public void setLink(String link) {
173 _widgetSource.setLink(link, null);
174 }
175
176 /**
177 * @param link
178 * The new frame link. Can be null (for no link)
179 *
180 * @param linker
181 * The text item creating the link. Null if not created from
182 * a text item.
183 */
184 public void setLink(String link, Text linker) {
185 _widgetSource.setLink(link, linker);
186 }
187
188 @Override
189 public void setFormula(String formula) {
190 }
191
192 @Override
193 public void setData(List<String> data) {
194 _widgetSource.setSourceData(data);
195 }
196
197 @Override
198 public boolean contains(int x, int y) {
199 return super.contains(x, y)
200 && !_widgetSource.getBounds().contains(x, y);
201 }
202
203 @Override
204 public void setThickness(float newThickness, boolean setConnected) {
205 if (_widgetSource != null) {
206 float minThickness = _widgetSource.getMinimumBorderThickness();
207 if (newThickness < minThickness)
208 newThickness = minThickness;
209 super.setThickness(newThickness, setConnected);
210 _widgetSource.setSourceThickness(newThickness, false);
211 }
212 }
213
214 @Override
215 public void setColor(Color color) {
216 if (_widgetSource != null) {
217 super.setColor(color);
218 _widgetSource.setSourceBorderColor(color);
219 }
220 }
221
222 @Override
223 public String getName() {
224 return _widgetSource.getName();
225 }
226
227
228}
Note: See TracBrowser for help on using the repository browser.