source: trunk/src/org/expeditee/items/XRayable.java@ 1423

Last change on this file since 1423 was 1423, checked in by bln4, 5 years ago

When setting encryption label on a XRayable then pass that instruction along to the source.

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