1 | /**
|
---|
2 | * XRayable.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;
|
---|
20 |
|
---|
21 | import java.util.Collection;
|
---|
22 | import java.util.LinkedList;
|
---|
23 | import java.util.List;
|
---|
24 |
|
---|
25 | import org.expeditee.core.Colour;
|
---|
26 | import org.expeditee.core.Point;
|
---|
27 | import org.expeditee.encryption.core.EncryptedImage;
|
---|
28 | import org.expeditee.encryption.items.surrogates.Label;
|
---|
29 | import org.expeditee.gui.DisplayController;
|
---|
30 |
|
---|
31 | public abstract class XRayable extends Item {
|
---|
32 |
|
---|
33 | protected Text _source = null;
|
---|
34 |
|
---|
35 | public XRayable(Text source){
|
---|
36 | super();
|
---|
37 | _source = source;
|
---|
38 | source.setHidden(true);
|
---|
39 | source.addEnclosure(this);
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public Item getPrimary() {
|
---|
44 | return _source.getPrimary();
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public boolean isSurrogate() {
|
---|
49 | return _source.isSurrogate();
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public void setEncryptionLabel(String label) {
|
---|
54 | _source.setEncryptionLabel(label);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public boolean sourceIsAccessible() {
|
---|
58 | String encryptionLabel = _source.getEncryptionLabel();
|
---|
59 | if (encryptionLabel == null || encryptionLabel.isEmpty()) {
|
---|
60 | return true;
|
---|
61 | } else {
|
---|
62 | List<String> accessibleLabelsNames = Label.getAccessibleLabelsNames(this.getParent().getBody());
|
---|
63 | return accessibleLabelsNames.contains(encryptionLabel);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public Collection<Item> getItemsToSave() {
|
---|
68 | Collection<Item> toSave = new LinkedList<Item>();
|
---|
69 | toSave.add(_source);
|
---|
70 | return toSave;
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public Collection<Item> getConnected() {
|
---|
75 | Collection<Item> conn = super.getConnected();
|
---|
76 | conn.add(_source);
|
---|
77 | return conn;
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public void addAllConnected(Collection<Item> connected) {
|
---|
82 | super.addAllConnected(connected);
|
---|
83 | if (!connected.contains(_source)) {
|
---|
84 | connected.add(_source);
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * (non-Javadoc)
|
---|
90 | *
|
---|
91 | * @see org.expeditee.items.Item#merge(org.expeditee.items.Item, int, int)
|
---|
92 | */
|
---|
93 | @Override
|
---|
94 | public Item merge(Item merger, int mouseX, int mouseY) {
|
---|
95 | return merger;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Returns the Text Item that was used to create this Picture object. This
|
---|
100 | * is required when saving the Frame.
|
---|
101 | *
|
---|
102 | * @return The Text Item used to create this Picture.
|
---|
103 | */
|
---|
104 | public Text getSource() {
|
---|
105 | return _source;
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public int getID() {
|
---|
110 | return _source.getID();
|
---|
111 | }
|
---|
112 |
|
---|
113 | @Override
|
---|
114 | public void setID(int newID) {
|
---|
115 | _source.setID(newID);
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Override
|
---|
119 | public int getY() {
|
---|
120 | return _source.getY();
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Override
|
---|
124 | public int getX() {
|
---|
125 | return _source.getX();
|
---|
126 | }
|
---|
127 |
|
---|
128 | @Override
|
---|
129 | public Colour getColor() {
|
---|
130 | return _source.getColor();
|
---|
131 | }
|
---|
132 |
|
---|
133 | @Override
|
---|
134 | public void setColor(Colour c) {
|
---|
135 | _source.setColor(c);
|
---|
136 | invalidateCommonTrait(ItemAppearence.ForegroundColorChanged);
|
---|
137 | }
|
---|
138 |
|
---|
139 | @Override
|
---|
140 | public void setBackgroundColor(Colour c) {
|
---|
141 | _source.setBackgroundColor(c);
|
---|
142 | }
|
---|
143 |
|
---|
144 | @Override
|
---|
145 | public void setFillColor(Colour c) {
|
---|
146 | _source.setFillColor(c);
|
---|
147 | }
|
---|
148 |
|
---|
149 | @Override
|
---|
150 | public void setBorderColor(Colour c) {
|
---|
151 | _source.setBorderColor(c);
|
---|
152 | invalidateCommonTrait(ItemAppearence.BorderColorChanged);
|
---|
153 | }
|
---|
154 |
|
---|
155 | @Override
|
---|
156 | public void setGradientColor(Colour c) {
|
---|
157 | _source.setGradientColor(c);
|
---|
158 | }
|
---|
159 |
|
---|
160 | @Override
|
---|
161 | public void setTooltips(List<String> tooltips) {
|
---|
162 | _source.setTooltips(tooltips);
|
---|
163 | }
|
---|
164 |
|
---|
165 | @Override
|
---|
166 | public void setTooltip(String tooltip) {
|
---|
167 | _source.setTooltip(tooltip);
|
---|
168 | }
|
---|
169 |
|
---|
170 | @Override
|
---|
171 | public List<String> getTooltip() {
|
---|
172 | return _source.getTooltip();
|
---|
173 | }
|
---|
174 |
|
---|
175 | @Override
|
---|
176 | public float getThickness() {
|
---|
177 | return _source.getThickness();
|
---|
178 | }
|
---|
179 |
|
---|
180 | @Override
|
---|
181 | public Integer getAnchorLeft() {
|
---|
182 | return _source.getAnchorLeft();
|
---|
183 | }
|
---|
184 |
|
---|
185 | @Override
|
---|
186 | public Integer getAnchorRight() {
|
---|
187 | return _source.getAnchorRight();
|
---|
188 | }
|
---|
189 |
|
---|
190 | @Override
|
---|
191 | public Integer getAnchorTop() {
|
---|
192 | return _source.getAnchorTop();
|
---|
193 | }
|
---|
194 |
|
---|
195 | @Override
|
---|
196 | public Integer getAnchorBottom() {
|
---|
197 | return _source.getAnchorBottom();
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 | @Override
|
---|
202 | public Colour getBorderColor() {
|
---|
203 | return _source.getBorderColor();
|
---|
204 | }
|
---|
205 |
|
---|
206 | @Override
|
---|
207 | public void setThickness(float thick, boolean setConnected) {
|
---|
208 | this.invalidateCommonTrait(ItemAppearence.Thickness);
|
---|
209 | _source.setThickness(thick, setConnected);
|
---|
210 | this.invalidateCommonTrait(ItemAppearence.Thickness);
|
---|
211 | }
|
---|
212 |
|
---|
213 | @Override
|
---|
214 | public Colour getBackgroundColor() {
|
---|
215 | return _source.getBackgroundColor();
|
---|
216 | }
|
---|
217 |
|
---|
218 | @Override
|
---|
219 | public Colour getFillColor() {
|
---|
220 | return _source.getFillColor();
|
---|
221 | }
|
---|
222 |
|
---|
223 | @Override
|
---|
224 | public Colour getGradientColor() {
|
---|
225 | return _source.getGradientColor();
|
---|
226 | }
|
---|
227 |
|
---|
228 | @Override
|
---|
229 | public String getFillPattern() {
|
---|
230 | return _source.getFillPattern();
|
---|
231 | }
|
---|
232 |
|
---|
233 | @Override
|
---|
234 | public boolean hasLink() {
|
---|
235 | return getLink() != null;
|
---|
236 | }
|
---|
237 |
|
---|
238 | @Override
|
---|
239 | public String getLink() {
|
---|
240 | if (_source == null)
|
---|
241 | return null;
|
---|
242 | else
|
---|
243 | return _source.getLink();
|
---|
244 | }
|
---|
245 |
|
---|
246 | @Override
|
---|
247 | public void setLink(String frameName) {
|
---|
248 | if (_source == null) {
|
---|
249 | return;
|
---|
250 | }
|
---|
251 | if(frameName == null)
|
---|
252 | invalidateAll();
|
---|
253 | _source.setLink(frameName);
|
---|
254 | invalidateBounds();
|
---|
255 | //TODO: only invalidate the link bit
|
---|
256 | invalidateAll();
|
---|
257 | }
|
---|
258 |
|
---|
259 | @Override
|
---|
260 | public void setActions(List<String> action) {
|
---|
261 | if (_source == null){
|
---|
262 | return;
|
---|
263 | }
|
---|
264 | if(action == null || action.size() == 0)
|
---|
265 | invalidateAll();
|
---|
266 | _source.setActions(action);
|
---|
267 | invalidateBounds();
|
---|
268 | invalidateAll();
|
---|
269 | }
|
---|
270 |
|
---|
271 | @Override
|
---|
272 | public List<String> getAction() {
|
---|
273 | if (_source == null)
|
---|
274 | return null;
|
---|
275 | else
|
---|
276 | return _source.getAction();
|
---|
277 | }
|
---|
278 |
|
---|
279 | @Override
|
---|
280 | public void translate(Point origin, double ratio){
|
---|
281 | //_source.translate(origin, ratio);
|
---|
282 | invalidateBounds();
|
---|
283 | }
|
---|
284 |
|
---|
285 | @Override
|
---|
286 | public void setPosition(float x, float y) {
|
---|
287 | //_source.setPosition(x, y);
|
---|
288 |
|
---|
289 | }
|
---|
290 |
|
---|
291 | @Override
|
---|
292 | public boolean isAnchored() {
|
---|
293 | return _source.isAnchored();
|
---|
294 | }
|
---|
295 |
|
---|
296 | @Override
|
---|
297 | public boolean isAnchoredX() {
|
---|
298 | return _source.isAnchoredX();
|
---|
299 | }
|
---|
300 |
|
---|
301 | @Override
|
---|
302 | public boolean isAnchoredY() {
|
---|
303 | return _source.isAnchoredY();
|
---|
304 | }
|
---|
305 |
|
---|
306 | @Override
|
---|
307 | public void setAnchorTop(Integer anchor) {
|
---|
308 | _source.setAnchorTop(anchor);
|
---|
309 | if (anchor != null)
|
---|
310 | _source.setY(anchor);
|
---|
311 | }
|
---|
312 |
|
---|
313 | @Override
|
---|
314 | public void setAnchorBottom(Integer anchor) {
|
---|
315 | _source.setAnchorBottom(anchor);
|
---|
316 | if (anchor != null)
|
---|
317 | _source.setY(DisplayController.getFramePaintAreaHeight() - getHeight() - anchor);
|
---|
318 | }
|
---|
319 |
|
---|
320 |
|
---|
321 | @Override
|
---|
322 | public void setAnchorLeft(Integer anchor) {
|
---|
323 | _source.setAnchorLeft(anchor);
|
---|
324 | }
|
---|
325 |
|
---|
326 | @Override
|
---|
327 | public void setAnchorRight(Integer anchor) {
|
---|
328 | _source.setAnchorRight(anchor);
|
---|
329 | _source.setX(DisplayController.getFramePaintAreaWidth() - anchor - this.getWidth());
|
---|
330 | }
|
---|
331 |
|
---|
332 | public boolean refresh(){
|
---|
333 | return true;
|
---|
334 | }
|
---|
335 |
|
---|
336 | @Override
|
---|
337 | public void setXY(float x, float y){
|
---|
338 | _source.setXY(x, y);
|
---|
339 | }
|
---|
340 |
|
---|
341 | @Override
|
---|
342 | public boolean hasPermission(UserAppliedPermission p) {
|
---|
343 | return _source.hasPermission(p);
|
---|
344 | }
|
---|
345 |
|
---|
346 | @Override
|
---|
347 | public void setPermission(PermissionTriple permissionPair) {
|
---|
348 | _source.setPermission(permissionPair);
|
---|
349 | }
|
---|
350 | }
|
---|