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

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

Recoding of the Labels class to improve surrogate mode functionality. Surrogate mode is now maintained when you navigate from one frame to another, even if that frame has a different set of labels. Completely different sets of labels cause Expeditee to exit surrogate mode with a message to the user.

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