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