[919] | 1 | /**
|
---|
| 2 | * Frame.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 |
|
---|
[4] | 19 | package org.expeditee.gui;
|
---|
| 20 |
|
---|
[1242] | 21 | import java.io.File;
|
---|
[1448] | 22 | import java.io.IOException;
|
---|
| 23 | import java.nio.file.Files;
|
---|
| 24 | import java.nio.file.Path;
|
---|
[1434] | 25 | import java.nio.file.Paths;
|
---|
[1448] | 26 | import java.nio.file.StandardCopyOption;
|
---|
[86] | 27 | import java.sql.Time;
|
---|
[4] | 28 | import java.util.ArrayList;
|
---|
[10] | 29 | import java.util.Collection;
|
---|
[4] | 30 | import java.util.Collections;
|
---|
[88] | 31 | import java.util.HashMap;
|
---|
[214] | 32 | import java.util.HashSet;
|
---|
[1426] | 33 | import java.util.Iterator;
|
---|
[108] | 34 | import java.util.LinkedHashSet;
|
---|
[4] | 35 | import java.util.LinkedList;
|
---|
| 36 | import java.util.List;
|
---|
[88] | 37 | import java.util.Map;
|
---|
[1430] | 38 | import java.util.Set;
|
---|
[4] | 39 | import java.util.Stack;
|
---|
[1407] | 40 | import java.util.stream.Collectors;
|
---|
| 41 | import java.util.stream.Stream;
|
---|
[4] | 42 |
|
---|
[86] | 43 | import org.expeditee.actions.Simple;
|
---|
[1489] | 44 | import org.expeditee.auth.AuthenticatorBrowser;
|
---|
[1488] | 45 | import org.expeditee.auth.mail.gui.MailBay;
|
---|
[1102] | 46 | import org.expeditee.core.Colour;
|
---|
| 47 | import org.expeditee.core.Image;
|
---|
| 48 | import org.expeditee.core.bounds.PolygonBounds;
|
---|
[1506] | 49 | import org.expeditee.encryption.io.EncryptedExpWriter;
|
---|
[1374] | 50 | import org.expeditee.encryption.items.EncryptionPermissionTriple;
|
---|
[1506] | 51 | import org.expeditee.encryption.items.UserAppliedEncryptionPermission;
|
---|
[1434] | 52 | import org.expeditee.encryption.items.surrogates.Label;
|
---|
[1477] | 53 | import org.expeditee.encryption.items.surrogates.Label.LabelInfo;
|
---|
| 54 | import org.expeditee.encryption.items.surrogates.Label.LabelResult;
|
---|
[1242] | 55 | import org.expeditee.gio.EcosystemManager;
|
---|
| 56 | import org.expeditee.gio.gesture.Gesture;
|
---|
| 57 | import org.expeditee.gio.gesture.Gesture.GestureType;
|
---|
[1102] | 58 | import org.expeditee.gio.gesture.StandardGestureActions;
|
---|
[1242] | 59 | import org.expeditee.gio.gesture.StandardGestureActions.StandardGestureType;
|
---|
| 60 | import org.expeditee.gio.gesture.data.RefreshGestureData;
|
---|
[1181] | 61 | import org.expeditee.gio.input.KBMInputEvent.Key;
|
---|
[1102] | 62 | import org.expeditee.gio.input.StandardInputEventListeners;
|
---|
[4] | 63 | import org.expeditee.io.Conversion;
|
---|
[1242] | 64 | import org.expeditee.io.ExpReader;
|
---|
[702] | 65 | import org.expeditee.items.Constraint;
|
---|
[4] | 66 | import org.expeditee.items.Dot;
|
---|
| 67 | import org.expeditee.items.Item;
|
---|
[778] | 68 | import org.expeditee.items.Item.HighlightMode;
|
---|
[121] | 69 | import org.expeditee.items.ItemAppearence;
|
---|
[56] | 70 | import org.expeditee.items.ItemParentStateChangedEvent;
|
---|
[4] | 71 | import org.expeditee.items.ItemUtils;
|
---|
| 72 | import org.expeditee.items.Line;
|
---|
[1402] | 73 | import org.expeditee.items.PermissionTriple;
|
---|
[1449] | 74 | import org.expeditee.items.Picture;
|
---|
[778] | 75 | import org.expeditee.items.Text;
|
---|
[454] | 76 | import org.expeditee.items.UserAppliedPermission;
|
---|
[108] | 77 | import org.expeditee.items.XRayable;
|
---|
[1102] | 78 | import org.expeditee.items.widgets.Widget;
|
---|
[198] | 79 | import org.expeditee.items.widgets.WidgetCorner;
|
---|
[570] | 80 | import org.expeditee.settings.UserSettings;
|
---|
[778] | 81 | import org.expeditee.settings.templates.TemplateSettings;
|
---|
[336] | 82 | import org.expeditee.simple.UnitTestFailedException;
|
---|
[419] | 83 | import org.expeditee.stats.Formatter;
|
---|
[72] | 84 | import org.expeditee.stats.SessionStats;
|
---|
[4] | 85 |
|
---|
| 86 | /**
|
---|
[108] | 87 | * Represents a Expeditee Frame that is displayed on the screen. Also is a
|
---|
| 88 | * registered MouseListener on the Browser, and processes any MouseEvents
|
---|
| 89 | * directly.
|
---|
[4] | 90 | *
|
---|
| 91 | * @author jdm18
|
---|
| 92 | *
|
---|
| 93 | */
|
---|
[1415] | 94 | public class Frame {
|
---|
[1102] | 95 |
|
---|
| 96 | /** The frame number to indicate this is a virtual frame. */
|
---|
| 97 | public static final int VIRTUAL_FRAME_NUMBER = -1;
|
---|
| 98 |
|
---|
| 99 | /** The background colour the frame name should take if the frame has user permission level 'none'. */
|
---|
| 100 | public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE = Colour.FromRGB255(255, 220, 220);
|
---|
| 101 | /** The background colour the frame name should take if the frame has user permission level 'followLinks'. */
|
---|
| 102 | public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS = Colour.FromRGB255(255, 230, 135);
|
---|
| 103 | /** The background colour the frame name should take if the frame has user permission level 'copy'. */
|
---|
| 104 | public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY = Colour.FromRGB255(255, 255, 155);
|
---|
| 105 | /** The background colour the frame name should take if the frame has user permission level 'createFrames'. */
|
---|
| 106 | public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES = Colour.FromRGB255(220, 255, 220);
|
---|
| 107 | /** The background colour the frame name should take if the frame has user permission level 'full'. */
|
---|
| 108 | public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL = null;
|
---|
[4] | 109 |
|
---|
[108] | 110 | private boolean _protectionChanged = false;
|
---|
[4] | 111 |
|
---|
| 112 | // The various attributes of this Frame
|
---|
| 113 | private String _frameset = null;
|
---|
| 114 |
|
---|
| 115 | private int _number = -1;
|
---|
| 116 |
|
---|
[67] | 117 | private int _version = 0;
|
---|
[4] | 118 |
|
---|
[1402] | 119 | private PermissionTriple _permissionTriple = null;
|
---|
[1374] | 120 |
|
---|
[1505] | 121 | private EncryptionPermissionTriple _frameEncryptionPermission = null;
|
---|
| 122 |
|
---|
| 123 | private EncryptionPermissionTriple _itemEncryptionPermission = null;
|
---|
[4] | 124 |
|
---|
| 125 | private String _owner = null;
|
---|
| 126 |
|
---|
| 127 | private String _creationDate = null;
|
---|
| 128 |
|
---|
| 129 | private String _modifiedUser = null;
|
---|
| 130 |
|
---|
| 131 | private String _modifiedDate = null;
|
---|
[1229] | 132 | private long _modifiedDatePrecise;
|
---|
[4] | 133 |
|
---|
| 134 | private String _frozenDate = null;
|
---|
| 135 |
|
---|
[80] | 136 | // Background color is clear
|
---|
[1102] | 137 | private Colour _background = null;
|
---|
[4] | 138 |
|
---|
[80] | 139 | // Foreground color is automatic by default
|
---|
[1102] | 140 | private Colour _foreground = null;
|
---|
[4] | 141 |
|
---|
[298] | 142 | private String path;
|
---|
[311] | 143 |
|
---|
[298] | 144 | private boolean _isLocal = true;
|
---|
[1102] | 145 |
|
---|
| 146 | /** Whether the frame has changed and therefore needs saving. */
|
---|
[4] | 147 | private boolean _change = false;
|
---|
| 148 |
|
---|
[1102] | 149 | /** Whether the frame has been saved. */
|
---|
[4] | 150 | private boolean _saved = false;
|
---|
[744] | 151 |
|
---|
[4] | 152 | // list of deleted items that can be restored
|
---|
[744] | 153 | private Stack<History> _undo = new Stack<History>();
|
---|
| 154 | private Stack<History> _redo = new Stack<History>();
|
---|
[4] | 155 |
|
---|
[1415] | 156 | private ItemsList _body = new ItemsList();
|
---|
| 157 | private ItemsList _bodyHiddenDueToPermissions = new ItemsList();
|
---|
| 158 | private ItemsList _primaryItemsBody = new ItemsList();
|
---|
| 159 | private ItemsList _surrogateItemsBody = new ItemsList();
|
---|
[4] | 160 |
|
---|
[10] | 161 | // for drawing purposes
|
---|
[1102] | 162 | private List<Widget> _iWidgets = new ArrayList<Widget>();
|
---|
[1242] | 163 |
|
---|
| 164 | // frame data
|
---|
[1326] | 165 | private List<String> _frameData = null;
|
---|
[4] | 166 |
|
---|
| 167 | private int _lineCount = 0;
|
---|
| 168 |
|
---|
| 169 | private int _itemCount = 1;
|
---|
| 170 |
|
---|
| 171 | // The frameName to display on the screen
|
---|
| 172 | private Text _frameName = null;
|
---|
| 173 |
|
---|
[115] | 174 | private Map<Overlay, Frame> _overlays = new HashMap<Overlay, Frame>();
|
---|
[4] | 175 |
|
---|
[78] | 176 | private List<Vector> _vectors = new ArrayList<Vector>();
|
---|
[4] | 177 |
|
---|
[78] | 178 | private Image _buffer = null;
|
---|
| 179 |
|
---|
[4] | 180 | private boolean _validBuffer = true;
|
---|
| 181 |
|
---|
[90] | 182 | private Time _activeTime = new Time(0);
|
---|
[86] | 183 |
|
---|
[90] | 184 | private Time _darkTime = new Time(0);
|
---|
[86] | 185 |
|
---|
[424] | 186 | private Collection<Item> _interactableItems = new LinkedHashSet<Item>();
|
---|
| 187 |
|
---|
[115] | 188 | private Collection<Item> _overlayItems = new LinkedHashSet<Item>();
|
---|
| 189 |
|
---|
| 190 | private Collection<Item> _vectorItems = new LinkedHashSet<Item>();
|
---|
| 191 |
|
---|
[778] | 192 | private Text _dotTemplate = TemplateSettings.DotTemplate.get().copy();
|
---|
[390] | 193 |
|
---|
[1139] | 194 | private Map<String, Text> _annotations = null;
|
---|
[1102] | 195 |
|
---|
| 196 | private Collection<FrameObserver> _observers = new HashSet<FrameObserver>();
|
---|
| 197 |
|
---|
[1227] | 198 | private String _encryptionLabel;
|
---|
[1505] | 199 | private String _homogeneousEncryptionLabel;
|
---|
[1506] | 200 | private List<String> _hetrogeneousEncryptionLabels = new ArrayList<String>();
|
---|
[1505] | 201 |
|
---|
[1405] | 202 | private String _groupFrameName;
|
---|
| 203 | private Frame _groupFrame = null;
|
---|
[1434] | 204 |
|
---|
| 205 | private List<String> labelsOnLastBodySet;
|
---|
[1415] | 206 |
|
---|
| 207 | public enum BodyType {
|
---|
| 208 | BodyDisplay, PrimaryBody, SurrogateBody;
|
---|
| 209 | }
|
---|
[1227] | 210 |
|
---|
[1102] | 211 | /** Default constructor, nothing is set. */
|
---|
[1242] | 212 | public Frame() {
|
---|
[4] | 213 | }
|
---|
| 214 |
|
---|
[1415] | 215 | public boolean isReadOnly() {
|
---|
[1102] | 216 | return !_frameName.hasPermission(UserAppliedPermission.full) && !_protectionChanged;
|
---|
| 217 | }
|
---|
[1489] | 218 |
|
---|
| 219 | public boolean isEncryptableFrame() {
|
---|
[1505] | 220 | boolean hasEncryptionLabel = this.getFrameEncryptionLabel() != null;
|
---|
[1489] | 221 | boolean isProfileFrame = this.getPath().equals(FrameIO.PROFILE_PATH);
|
---|
| 222 | boolean isCredentialsFrame = isProfileFrame && this.getNumber() == AuthenticatorBrowser.CREDENTIALS_FRAME;
|
---|
| 223 | return hasEncryptionLabel && !isCredentialsFrame;
|
---|
| 224 | }
|
---|
[1102] | 225 |
|
---|
[1415] | 226 | public void reset() {
|
---|
[454] | 227 | refreshItemPermissions(UserAppliedPermission.full);
|
---|
[390] | 228 | resetDot();
|
---|
[424] | 229 | SessionStats.NewFrameSession();
|
---|
[390] | 230 | }
|
---|
[424] | 231 |
|
---|
[1102] | 232 | private void resetDot()
|
---|
| 233 | {
|
---|
[979] | 234 | _dotTemplate.setColor(TemplateSettings.ColorWheel.getSafe(1));
|
---|
| 235 | _dotTemplate.setFillColor(TemplateSettings.FillColorWheel.getSafe(0));
|
---|
[390] | 236 | }
|
---|
| 237 |
|
---|
[1102] | 238 | public void nextDot()
|
---|
| 239 | {
|
---|
| 240 | _dotTemplate.setFillColor(ColorUtils.getNextColor(_dotTemplate.getFillColor(), TemplateSettings.FillColorWheel.get(), null));
|
---|
| 241 | _dotTemplate.setColor(ColorUtils.getNextColor(_dotTemplate.getColor(), TemplateSettings.ColorWheel.get(), null));
|
---|
[1181] | 242 | if (_dotTemplate.getColor() == null || _dotTemplate.getColor().equals(Colour.WHITE)) {
|
---|
| 243 | resetDot();
|
---|
| 244 | }
|
---|
[390] | 245 | }
|
---|
| 246 |
|
---|
[1102] | 247 | public Image getBuffer()
|
---|
| 248 | {
|
---|
[4] | 249 | return _buffer;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[1102] | 252 | public void setBuffer(Image newBuffer)
|
---|
| 253 | {
|
---|
[4] | 254 | _buffer = newBuffer;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[1102] | 257 | public boolean isBufferValid()
|
---|
| 258 | {
|
---|
[1181] | 259 | if (_buffer == null) {
|
---|
| 260 | return false;
|
---|
| 261 | }
|
---|
[4] | 262 |
|
---|
| 263 | return _validBuffer;
|
---|
| 264 | }
|
---|
[1408] | 265 |
|
---|
[1102] | 266 | private void setBufferValid(boolean newValue)
|
---|
| 267 | {
|
---|
[4] | 268 | _validBuffer = newValue;
|
---|
| 269 | }
|
---|
| 270 |
|
---|
[1102] | 271 | public int getNextItemID()
|
---|
| 272 | {
|
---|
[4] | 273 | return ++_itemCount;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
[1102] | 276 | public void updateIDs(List<Item> items)
|
---|
| 277 | {
|
---|
| 278 | for (Item i : items) {
|
---|
| 279 | if (!(i instanceof Line)) {
|
---|
[4] | 280 | i.setID(getNextItemID());
|
---|
[1102] | 281 | } else {
|
---|
[4] | 282 | i.setID(++_lineCount);
|
---|
[1102] | 283 | }
|
---|
| 284 | }
|
---|
[4] | 285 | }
|
---|
[67] | 286 |
|
---|
[10] | 287 | /**
|
---|
| 288 | *
|
---|
[440] | 289 | * @return The interactive widgets that are currently anchored in this frame.
|
---|
| 290 | * Hence it excludes free-widgets. Returns a copy
|
---|
[10] | 291 | */
|
---|
[1102] | 292 | public List<Widget> getInteractiveWidgets()
|
---|
| 293 | {
|
---|
| 294 | LinkedList<Widget> clone = new LinkedList<Widget>();
|
---|
[30] | 295 | clone.addAll(this._iWidgets);
|
---|
| 296 | return clone;
|
---|
[10] | 297 | }
|
---|
[4] | 298 |
|
---|
| 299 | /**
|
---|
| 300 | * Returns whether this Frame has been changed and required saving to disk.
|
---|
| 301 | *
|
---|
| 302 | * @return True if this Frame has been altered, false otherwise.
|
---|
| 303 | */
|
---|
[1102] | 304 | public boolean hasChanged()
|
---|
| 305 | {
|
---|
[4] | 306 | // virtual frames are never saved
|
---|
[1181] | 307 | if (_number == VIRTUAL_FRAME_NUMBER) {
|
---|
| 308 | return false;
|
---|
| 309 | }
|
---|
[4] | 310 |
|
---|
| 311 | return _change;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | /**
|
---|
| 315 | * Sets whether this Frame should be saved to disk.
|
---|
| 316 | *
|
---|
| 317 | * @param value
|
---|
[1102] | 318 | * True if this Frame should be saved to disk, False otherwise.
|
---|
[4] | 319 | */
|
---|
[1102] | 320 | public void setChanged(boolean value)
|
---|
| 321 | {
|
---|
[1181] | 322 | if (_change == value) {
|
---|
| 323 | return;
|
---|
| 324 | }
|
---|
[214] | 325 |
|
---|
[4] | 326 | _change = value;
|
---|
| 327 |
|
---|
[67] | 328 | if (_change) {
|
---|
[4] | 329 | setBufferValid(false);
|
---|
[7] | 330 | _saved = false;
|
---|
| 331 | }
|
---|
[4] | 332 | }
|
---|
| 333 |
|
---|
[376] | 334 | /**
|
---|
| 335 | * Notify items observing the data on this frame that the frame content has
|
---|
| 336 | * changed.
|
---|
| 337 | *
|
---|
| 338 | * @param recalculate
|
---|
| 339 | * true if the frame should be recalculated first.
|
---|
| 340 | */
|
---|
[1242] | 341 | public void notifyObservers(boolean bRecalculate) {
|
---|
[1181] | 342 | if (bRecalculate) {
|
---|
| 343 | recalculate();
|
---|
| 344 | }
|
---|
[294] | 345 | // Notify the frame listeners that the frame has changed
|
---|
[376] | 346 | /*
|
---|
| 347 | * Avoid ConcurrentMod Exceptions when user anchors an item onto this
|
---|
| 348 | * frame which is observing this frame, by NOT using foreach loop.
|
---|
| 349 | * Calling update on a dataFrameWidget resets its subjects hence
|
---|
| 350 | * changing this frames observer list.
|
---|
| 351 | */
|
---|
[1102] | 352 | Collection<FrameObserver> observersCopy = new LinkedList<FrameObserver>(_observers);
|
---|
[390] | 353 | // System.out.println(++updateCount + " update");
|
---|
[376] | 354 |
|
---|
| 355 | for (FrameObserver fl : observersCopy) {
|
---|
[1181] | 356 | if (fl.isVisible()) {
|
---|
| 357 | fl.update();
|
---|
| 358 | }
|
---|
[294] | 359 | }
|
---|
| 360 | }
|
---|
| 361 |
|
---|
[4] | 362 | // indicates the frame has changed
|
---|
[1102] | 363 | public void change()
|
---|
| 364 | {
|
---|
[4] | 365 | setChanged(true);
|
---|
[424] | 366 | _interactableItems.clear();
|
---|
[4] | 367 | }
|
---|
| 368 |
|
---|
| 369 | /**
|
---|
| 370 | * Returns an ArrayList of all Items currently on the Frame (excludes Items
|
---|
| 371 | * attached to the cursor).
|
---|
| 372 | *
|
---|
| 373 | * @return The list of Item objects that are on this Frame.
|
---|
| 374 | */
|
---|
[1415] | 375 | public List<Item> getSortedItems(boolean requireVisible) {
|
---|
[1434] | 376 | ItemsList listToLoopOver = getBody(true);
|
---|
[1415] | 377 | listToLoopOver.sort();
|
---|
| 378 | return getItems(requireVisible, listToLoopOver);
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | public List<Item> getItems(boolean requireVisible, ItemsList listToLoopOver) {
|
---|
[108] | 382 | List<Item> items = new ArrayList<Item>();
|
---|
[67] | 383 |
|
---|
[1415] | 384 | for (Item i: listToLoopOver) {
|
---|
[1181] | 385 | if (i == null) {
|
---|
| 386 | continue;
|
---|
| 387 | }
|
---|
[1102] | 388 |
|
---|
[1415] | 389 | if (meetsVisibilityRequirements(requireVisible, i)) {
|
---|
[108] | 390 | items.add(i);
|
---|
| 391 | }
|
---|
[7] | 392 | }
|
---|
[67] | 393 |
|
---|
[108] | 394 | return items;
|
---|
[4] | 395 | }
|
---|
[1415] | 396 |
|
---|
[1102] | 397 | /** TODO: Comment. cts16 */
|
---|
[1415] | 398 | public List<Item> getSortedItems()
|
---|
[1102] | 399 | {
|
---|
[1415] | 400 | return getSortedItems(false);
|
---|
[108] | 401 | }
|
---|
| 402 |
|
---|
[30] | 403 | /**
|
---|
[67] | 404 | * @param i
|
---|
| 405 | * Item to check if contained in this frame
|
---|
[30] | 406 | * @return True if this frame contains i.
|
---|
| 407 | */
|
---|
[1415] | 408 | public boolean containsItem(Item i) {
|
---|
[1181] | 409 | if (i == null) {
|
---|
| 410 | throw new NullPointerException("i");
|
---|
[1415] | 411 | }
|
---|
[1434] | 412 | return getBody(true).contains(i);
|
---|
[30] | 413 | }
|
---|
[4] | 414 |
|
---|
| 415 | /**
|
---|
[156] | 416 | * Returns a list of all the non annotation text items on the frame which
|
---|
| 417 | * are not the title or frame name or special annotation items.
|
---|
[108] | 418 | *
|
---|
| 419 | * @param includeAnnotations
|
---|
[156] | 420 | * true if annotation items without special meaning should be
|
---|
| 421 | * included
|
---|
[108] | 422 | * @param includeLineEnds
|
---|
| 423 | * true if text on the end of lines should be included in the
|
---|
| 424 | * list
|
---|
[4] | 425 | * @return the list of body text items.
|
---|
| 426 | */
|
---|
[1434] | 427 | public List<Text> getBodyTextItems(boolean includeAnnotations) {
|
---|
| 428 | ensureBody();
|
---|
| 429 |
|
---|
[4] | 430 | List<Text> bodyTextItems = new ArrayList<Text>();
|
---|
[1102] | 431 |
|
---|
[1415] | 432 | for (Item i : getSortedItems(true)) {
|
---|
[4] | 433 | // only add up normal body text items
|
---|
[1102] | 434 | if ((i instanceof Text) && ((includeAnnotations && !((Text) i).isSpecialAnnotation()) || !i.isAnnotation()) && !i.isLineEnd()) {
|
---|
[4] | 435 | bodyTextItems.add((Text) i);
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
[1102] | 438 |
|
---|
[80] | 439 | bodyTextItems.remove(getTitleItem());
|
---|
[4] | 440 |
|
---|
[67] | 441 | return bodyTextItems;
|
---|
[4] | 442 | }
|
---|
| 443 |
|
---|
[1102] | 444 | public Collection<Item> getNonAnnotationItems(boolean removeTitle)
|
---|
| 445 | {
|
---|
[196] | 446 | Collection<Item> items = new ArrayList<Item>();
|
---|
[1415] | 447 | for (Item i : getSortedItems(true)) {
|
---|
[115] | 448 | // only add up normal body text items
|
---|
[1181] | 449 | if (!i.isAnnotation()) {
|
---|
| 450 | items.add(i);
|
---|
| 451 | }
|
---|
[115] | 452 | }
|
---|
[1102] | 453 |
|
---|
[199] | 454 | if (removeTitle) {
|
---|
[196] | 455 | items.remove(getTitleItem());
|
---|
| 456 | }
|
---|
[1102] | 457 |
|
---|
[115] | 458 | return items;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[4] | 461 | /**
|
---|
| 462 | * Gets the last item on the frame that is a non annotation item but is also
|
---|
| 463 | * text.
|
---|
| 464 | *
|
---|
| 465 | * @return the last non annotation text item.
|
---|
| 466 | */
|
---|
[1102] | 467 | public Item getLastNonAnnotationTextItem()
|
---|
| 468 | {
|
---|
[1415] | 469 | List<Item> items = getSortedItems();
|
---|
[4] | 470 |
|
---|
| 471 | // find the last non-annotation text item
|
---|
| 472 | for (int i = (items.size() - 1); i >= 0; i--) {
|
---|
| 473 | Item it = items.get(i);
|
---|
| 474 |
|
---|
| 475 | if (it instanceof Text && !it.isAnnotation()) {
|
---|
[1181] | 476 | return it;
|
---|
[4] | 477 | }
|
---|
| 478 | }
|
---|
| 479 | return null;
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | /**
|
---|
| 483 | * Iterates through the list of items on the frame, and returns one with the
|
---|
| 484 | * given id if one exists, otherwise returns null.
|
---|
| 485 | *
|
---|
| 486 | * @param id
|
---|
| 487 | * The id to search for in the list of items
|
---|
| 488 | * @return The item on this frame with the given ID, or null if one is not
|
---|
| 489 | * found.
|
---|
| 490 | */
|
---|
[1434] | 491 | public Item getItemWithID(int id) {
|
---|
| 492 | for (Item i : getAllFrameItemsRaw()) {
|
---|
[1102] | 493 | if (i.getID() == id) {
|
---|
[4] | 494 | return i;
|
---|
[1102] | 495 | }
|
---|
| 496 | }
|
---|
[4] | 497 | return null;
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | /**
|
---|
| 501 | * Sets this Frame's Title which is displayed in the top left corner.
|
---|
| 502 | *
|
---|
| 503 | * @param title
|
---|
| 504 | * The title to assign to this Frame
|
---|
| 505 | */
|
---|
[1102] | 506 | public void setTitle(String title)
|
---|
| 507 | {
|
---|
[1181] | 508 | if (title == null || title.equals("")) {
|
---|
| 509 | return;
|
---|
| 510 | }
|
---|
[4] | 511 |
|
---|
| 512 | boolean oldchange = _change;
|
---|
| 513 |
|
---|
| 514 | // remove any numbering this title has
|
---|
| 515 | title = title.replaceAll("^\\d*[.] *", "");
|
---|
[80] | 516 | Text frameTitle = getTitleItem();
|
---|
[4] | 517 |
|
---|
| 518 | if (frameTitle == null) {
|
---|
[778] | 519 | if (TemplateSettings.TitleTemplate.get() == null) {
|
---|
[4] | 520 | frameTitle = new Text(getNextItemID(), title);
|
---|
| 521 | } else {
|
---|
[778] | 522 | frameTitle = TemplateSettings.TitleTemplate.get().copy();
|
---|
[4] | 523 | frameTitle.setID(this.getNextItemID());
|
---|
| 524 | frameTitle.setText(title);
|
---|
| 525 | }
|
---|
[749] | 526 | /*
|
---|
| 527 | * Need to set the parent otherwise an exception is thrown when
|
---|
| 528 | * new profile is created
|
---|
| 529 | */
|
---|
| 530 | frameTitle.setParent(this);
|
---|
| 531 | frameTitle.resetTitlePosition();
|
---|
[4] | 532 | addItem(frameTitle);
|
---|
| 533 | } else {
|
---|
[80] | 534 | // If it begins with a tag remove it
|
---|
| 535 |
|
---|
| 536 | // Remove the @ symbol if it is there
|
---|
[86] | 537 | // title = ItemUtils.StripTagSymbol(title);
|
---|
[4] | 538 | frameTitle.setText(title);
|
---|
[1102] | 539 | // If the @ symbol is followed by numbering or a bullet remove that too
|
---|
| 540 | String autoBulletText = StandardGestureActions.getAutoBullet(title);
|
---|
[1181] | 541 | if (autoBulletText.length() > 0) {
|
---|
[4] | 542 | frameTitle.stripFirstWord();
|
---|
[1181] | 543 | }
|
---|
[4] | 544 | }
|
---|
[67] | 545 | // TODO Widgets... check this out
|
---|
| 546 | // Brook: Cannot figure what is going on above... widget annot titles
|
---|
| 547 | // should be stripped always
|
---|
[1102] | 548 | if (ItemUtils.startsWithTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) {
|
---|
[10] | 549 | frameTitle.stripFirstWord();
|
---|
| 550 | }
|
---|
[4] | 551 |
|
---|
| 552 | FrameUtils.Parse(this);
|
---|
| 553 |
|
---|
| 554 | // do not save if this is the only change
|
---|
| 555 | setChanged(oldchange);
|
---|
| 556 | }
|
---|
| 557 |
|
---|
[1102] | 558 | public Text getTitleItem()
|
---|
| 559 | {
|
---|
[362] | 560 | List<Item> items = getVisibleItems();
|
---|
[1102] | 561 |
|
---|
[4] | 562 | for (Item i : items) {
|
---|
[1102] | 563 | if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get() && i.getY() < UserSettings.TitlePosition.get()) {
|
---|
[4] | 564 | return (Text) i;
|
---|
[1102] | 565 | }
|
---|
[4] | 566 | }
|
---|
| 567 |
|
---|
| 568 | return null;
|
---|
| 569 | }
|
---|
| 570 |
|
---|
[1102] | 571 | public String getTitle()
|
---|
| 572 | {
|
---|
[80] | 573 | Text title = getTitleItem();
|
---|
[1181] | 574 | if (title == null) {
|
---|
| 575 | return getName();
|
---|
| 576 | }
|
---|
[80] | 577 |
|
---|
| 578 | return title.getFirstLine();
|
---|
| 579 | }
|
---|
| 580 |
|
---|
[1290] | 581 | public Item getNameItem() {
|
---|
| 582 | //Text ret = _frameName;
|
---|
[1505] | 583 | if (this.getFrameEncryptionLabel() != null && this.getFrameEncryptionLabel().length() > 0) {
|
---|
[1290] | 584 | _frameName.setText("\uD83D\uDD12" + getFramesetName() + _number);
|
---|
| 585 | _frameName.resetFrameNamePosition();
|
---|
| 586 | }
|
---|
[4] | 587 | return _frameName;
|
---|
| 588 | }
|
---|
| 589 |
|
---|
[1102] | 590 | public Text getItemTemplate()
|
---|
| 591 | {
|
---|
| 592 | return getTemplate(TemplateSettings.ItemTemplate.get(), ItemUtils.TAG_ITEM_TEMPLATE);
|
---|
[4] | 593 | }
|
---|
| 594 |
|
---|
[1102] | 595 | public Text getAnnotationTemplate()
|
---|
| 596 | {
|
---|
| 597 | Text t = getTemplate(TemplateSettings.AnnotationTemplate.get(), ItemUtils.TAG_ANNOTATION_TEMPLATE);
|
---|
[4] | 598 |
|
---|
| 599 | if (t == null) {
|
---|
[70] | 600 | t = getItemTemplate();
|
---|
[4] | 601 | }
|
---|
| 602 |
|
---|
[70] | 603 | return t;
|
---|
[4] | 604 | }
|
---|
| 605 |
|
---|
[1102] | 606 | public Text getStatTemplate()
|
---|
| 607 | {
|
---|
[72] | 608 | SessionStats.CreatedText();
|
---|
[1102] | 609 | Text t = getTemplate(TemplateSettings.StatTemplate.get(), ItemUtils.TAG_STAT_TEMPLATE);
|
---|
[72] | 610 |
|
---|
| 611 | if (t == null) {
|
---|
| 612 | t = getItemTemplate();
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | return t;
|
---|
| 616 | }
|
---|
[664] | 617 |
|
---|
[1102] | 618 | public Item getTooltipTextItem(String tooltipText)
|
---|
| 619 | {
|
---|
[778] | 620 | return getTextItem(tooltipText, TemplateSettings.TooltipTemplate.get().copy());
|
---|
[664] | 621 | }
|
---|
[72] | 622 |
|
---|
[1102] | 623 | public Item getStatsTextItem(String itemText)
|
---|
| 624 | {
|
---|
[115] | 625 | return getTextItem(itemText, getStatTemplate());
|
---|
| 626 | }
|
---|
| 627 |
|
---|
[1102] | 628 | public Item getTextItem(String itemText)
|
---|
| 629 | {
|
---|
[115] | 630 | return getTextItem(itemText, getItemTemplate());
|
---|
| 631 | }
|
---|
| 632 |
|
---|
[1102] | 633 | private Item getTextItem(String itemText, Text template)
|
---|
| 634 | {
|
---|
[115] | 635 | Text t = template;
|
---|
[72] | 636 | // We dont want the stats to wrap at all
|
---|
[147] | 637 | // t.setMaxWidth(Integer.MAX_VALUE);
|
---|
[1102] | 638 | t.setPosition(DisplayController.getMousePosition());
|
---|
[108] | 639 | // The next line is needed to make sure the item is removed from the
|
---|
| 640 | // frame when picked up
|
---|
[90] | 641 | t.setParent(this);
|
---|
[108] | 642 | t.setText(itemText);
|
---|
[72] | 643 | return t;
|
---|
| 644 | }
|
---|
| 645 |
|
---|
[1102] | 646 | public Text getCodeCommentTemplate()
|
---|
| 647 | {
|
---|
| 648 | Text t = getTemplate(TemplateSettings.CommentTemplate.get(), ItemUtils.TAG_CODE_COMMENT_TEMPLATE);
|
---|
[4] | 649 |
|
---|
| 650 | if (t == null) {
|
---|
[70] | 651 | t = getItemTemplate();
|
---|
[4] | 652 | }
|
---|
| 653 |
|
---|
[70] | 654 | return t;
|
---|
[4] | 655 | }
|
---|
[440] | 656 |
|
---|
[4] | 657 |
|
---|
| 658 | /**
|
---|
| 659 | * Returns any items on this frame that are within the given Shape. Also
|
---|
| 660 | * returns any Items on overlay frames that are within the Shape.
|
---|
| 661 | *
|
---|
| 662 | * @param shape
|
---|
| 663 | * The Shape to search for Items in
|
---|
| 664 | * @return All Items on this Frame or overlayed Frames for which
|
---|
| 665 | * Item.intersects(shape) return true.
|
---|
| 666 | */
|
---|
[1102] | 667 | public Collection<Item> getItemsWithin(PolygonBounds poly)
|
---|
| 668 | {
|
---|
[108] | 669 | Collection<Item> results = new LinkedHashSet<Item>();
|
---|
| 670 | for (Item i : getVisibleItems()) {
|
---|
| 671 | if (i.intersects(poly)) {
|
---|
| 672 | if (i instanceof XRayable) {
|
---|
| 673 | results.addAll(i.getConnected());
|
---|
[190] | 674 | // Dont add circle centers
|
---|
| 675 | // TODO change this to be isCircle center
|
---|
| 676 | } else if (!i.hasEnclosures()) {
|
---|
[4] | 677 | results.add(i);
|
---|
[108] | 678 | }
|
---|
[4] | 679 | }
|
---|
[108] | 680 | }
|
---|
[4] | 681 |
|
---|
[1102] | 682 | for (Overlay o : _overlays.keySet()) {
|
---|
[4] | 683 | results.addAll(o.Frame.getItemsWithin(poly));
|
---|
[1102] | 684 | }
|
---|
| 685 |
|
---|
[294] | 686 | for (Item i : getVectorItems()) {
|
---|
[286] | 687 | if (i.intersects(poly)) {
|
---|
[294] | 688 | // This assumes a results is a set
|
---|
[286] | 689 | results.add(i.getEditTarget());
|
---|
| 690 | }
|
---|
| 691 | }
|
---|
[4] | 692 |
|
---|
| 693 | return results;
|
---|
| 694 | }
|
---|
| 695 |
|
---|
| 696 | /**
|
---|
| 697 | * Sets the name of this Frame to the given String, to be displayed in the
|
---|
| 698 | * upper right corner.
|
---|
| 699 | *
|
---|
| 700 | * @param name
|
---|
| 701 | * The name to use for this Frame.
|
---|
| 702 | */
|
---|
[1102] | 703 | public void setFrameset(String name)
|
---|
| 704 | {
|
---|
[4] | 705 | _frameset = name;
|
---|
| 706 | }
|
---|
| 707 |
|
---|
[1102] | 708 | public void setName(String framename)
|
---|
| 709 | {
|
---|
[4] | 710 | int num = Conversion.getFrameNumber(framename);
|
---|
[97] | 711 | String frameset = Conversion.getFramesetName(framename, false);
|
---|
[4] | 712 |
|
---|
[80] | 713 | setName(frameset, num);
|
---|
[4] | 714 | }
|
---|
| 715 |
|
---|
| 716 | /**
|
---|
| 717 | * Sets the frame number of this Frame to the given integer
|
---|
| 718 | *
|
---|
| 719 | * @param number
|
---|
| 720 | * The number to set as the frame number
|
---|
| 721 | */
|
---|
[1102] | 722 | public void setFrameNumber(int number)
|
---|
| 723 | {
|
---|
[67] | 724 | assert (number >= 0);
|
---|
| 725 |
|
---|
[1181] | 726 | if (_number == number) {
|
---|
| 727 | return;
|
---|
| 728 | }
|
---|
[67] | 729 |
|
---|
[4] | 730 | _number = number;
|
---|
| 731 | boolean oldchange = _change;
|
---|
| 732 |
|
---|
| 733 | int id;
|
---|
| 734 |
|
---|
| 735 | if (_frameName != null) {
|
---|
| 736 | id = _frameName.getID();
|
---|
[67] | 737 | } else {
|
---|
[4] | 738 | id = -1 * getNextItemID();
|
---|
[7] | 739 | }
|
---|
[1102] | 740 |
|
---|
[4] | 741 | _frameName = new Text(id);
|
---|
[13] | 742 | _frameName.setParent(this);
|
---|
[24] | 743 | _frameName.setText(getFramesetName() + _number);
|
---|
[71] | 744 | _frameName.resetFrameNamePosition();
|
---|
[4] | 745 | setChanged(oldchange);
|
---|
| 746 | }
|
---|
| 747 |
|
---|
| 748 | /**
|
---|
| 749 | * Returns the number of this Frame.
|
---|
| 750 | *
|
---|
| 751 | * @return The Frame number of this Frame or -1 if it is not set.
|
---|
| 752 | */
|
---|
[1102] | 753 | public int getNumber()
|
---|
| 754 | {
|
---|
[4] | 755 | return _number;
|
---|
| 756 | }
|
---|
| 757 |
|
---|
| 758 | /**
|
---|
[67] | 759 | * Increments the version of this Frame to the given String.
|
---|
[4] | 760 | *
|
---|
| 761 | * @param version
|
---|
| 762 | * The version to use for this Frame.
|
---|
| 763 | */
|
---|
[1102] | 764 | public void setVersion(int version)
|
---|
| 765 | {
|
---|
[4] | 766 | _version = version;
|
---|
| 767 | }
|
---|
| 768 |
|
---|
| 769 | /**
|
---|
| 770 | * Sets the protection of this Frame to the given String.
|
---|
| 771 | *
|
---|
| 772 | * @param protection
|
---|
| 773 | * The protection to use for this Frame.
|
---|
| 774 | */
|
---|
[1402] | 775 | public void setPermission(PermissionTriple permission) {
|
---|
[1407] | 776 | List<String> groupMembers = getGroupMembers();
|
---|
[1402] | 777 |
|
---|
| 778 | if (_permissionTriple != null && !_permissionTriple.getPermission(this._owner, groupMembers).equals(permission.getPermission(this._owner, groupMembers))) {
|
---|
[108] | 779 | _protectionChanged = true;
|
---|
[1102] | 780 | }
|
---|
[74] | 781 |
|
---|
[1402] | 782 | _permissionTriple = new PermissionTriple(permission);
|
---|
[108] | 783 |
|
---|
[1434] | 784 | if (getBody(false).size() > 0) {
|
---|
[1402] | 785 | refreshItemPermissions(permission.getPermission(_owner, groupMembers));
|
---|
[1181] | 786 | }
|
---|
[4] | 787 | }
|
---|
| 788 |
|
---|
| 789 | /**
|
---|
| 790 | * Sets the owner of this Frame to the given String.
|
---|
| 791 | *
|
---|
| 792 | * @param owner
|
---|
| 793 | * The owner to use for this Frame.
|
---|
| 794 | */
|
---|
[1460] | 795 | public void setOwner(String owner) {
|
---|
[4] | 796 | _owner = owner;
|
---|
[1460] | 797 | if (_frameName != null) {
|
---|
| 798 | _frameName.setOwner(owner);
|
---|
| 799 | } else {
|
---|
| 800 | if (Browser.DEBUG) {
|
---|
| 801 | System.err.println(" *** Attempted to set owner of Frame when _frameName was null. *** ");
|
---|
| 802 | }
|
---|
| 803 | }
|
---|
[4] | 804 | }
|
---|
| 805 |
|
---|
| 806 | /**
|
---|
| 807 | * Sets the created date of this Frame to the given String.
|
---|
| 808 | *
|
---|
| 809 | * @param date
|
---|
| 810 | * The date to use for this Frame.
|
---|
| 811 | */
|
---|
[1102] | 812 | public void setDateCreated(String date)
|
---|
| 813 | {
|
---|
[4] | 814 | _creationDate = date;
|
---|
| 815 | _modifiedDate = date;
|
---|
[1434] | 816 | for (Item i : getAllFrameItemsRaw()) {
|
---|
[4] | 817 | i.setDateCreated(date);
|
---|
| 818 | }
|
---|
| 819 | }
|
---|
| 820 |
|
---|
[424] | 821 | /**
|
---|
| 822 | * Resets the dates and version numbers for newly created frames.
|
---|
| 823 | *
|
---|
| 824 | */
|
---|
[1102] | 825 | public void resetDateCreated()
|
---|
| 826 | {
|
---|
[419] | 827 | setDateCreated(Formatter.getDateTime());
|
---|
[424] | 828 | resetTimes();
|
---|
| 829 | setVersion(0);
|
---|
| 830 | }
|
---|
| 831 |
|
---|
[1102] | 832 | private void resetTimes()
|
---|
| 833 | {
|
---|
[156] | 834 | setActiveTime(new Time(0));
|
---|
| 835 | setDarkTime(new Time(0));
|
---|
[4] | 836 | }
|
---|
| 837 |
|
---|
| 838 | /**
|
---|
| 839 | * Sets the last modifying user of this Frame to the given String.
|
---|
| 840 | *
|
---|
| 841 | * @param user
|
---|
| 842 | * The user to set as the last modifying user.
|
---|
| 843 | */
|
---|
[1102] | 844 | public void setLastModifyUser(String user)
|
---|
| 845 | {
|
---|
[4] | 846 | _modifiedUser = user;
|
---|
| 847 | }
|
---|
| 848 |
|
---|
| 849 | /**
|
---|
| 850 | * Sets the last modified date of this Frame to the given String.
|
---|
| 851 | *
|
---|
| 852 | * @param date
|
---|
| 853 | * The date to set as the last modified date.
|
---|
[1229] | 854 | * @param precise The millisecond precision last modified date.
|
---|
[4] | 855 | */
|
---|
[1229] | 856 | public void setLastModifyDate(String date, long precise) {
|
---|
[4] | 857 | _modifiedDate = date;
|
---|
[1229] | 858 | _modifiedDatePrecise = precise;
|
---|
[4] | 859 | }
|
---|
[1229] | 860 |
|
---|
| 861 | /**
|
---|
| 862 | * Sets the last modified date of this Frame to the given String.
|
---|
| 863 | * Used during startup. If able to be more precise then use the overloaded function.
|
---|
| 864 | *
|
---|
| 865 | * @param date
|
---|
| 866 | * The date to set as the last modified date.
|
---|
| 867 | */
|
---|
| 868 | public void setLastModifyDate(String date) {
|
---|
| 869 | _modifiedDate = date;
|
---|
| 870 | _modifiedDatePrecise = -1l;
|
---|
| 871 | }
|
---|
[4] | 872 |
|
---|
| 873 | /**
|
---|
| 874 | * Sets the last frozen date of this Frame to the given String.
|
---|
| 875 | *
|
---|
| 876 | * @param date
|
---|
| 877 | * The date to set as the last frozen date.
|
---|
| 878 | */
|
---|
[1415] | 879 | public void setFrozenDate(String date) {
|
---|
[4] | 880 | _frozenDate = date;
|
---|
| 881 | }
|
---|
| 882 |
|
---|
[1415] | 883 | public void invalidateSorted() {
|
---|
[1434] | 884 | getBody(false).invalidateSorted();
|
---|
[4] | 885 | }
|
---|
| 886 |
|
---|
| 887 | /**
|
---|
| 888 | * Adds the given Item to the body of this Frame.
|
---|
| 889 | *
|
---|
| 890 | * @param item
|
---|
| 891 | * The Item to add to this Frame.
|
---|
| 892 | */
|
---|
[1415] | 893 | public void addItem(Item item) {
|
---|
[242] | 894 | addItem(item, true);
|
---|
| 895 | }
|
---|
[247] | 896 |
|
---|
[1415] | 897 | public void addItem(Item item, boolean recalculate) {
|
---|
[1460] | 898 | if (item == null) {
|
---|
| 899 | return;
|
---|
| 900 | }
|
---|
| 901 |
|
---|
| 902 | // Get the associated encryption label if it has one. Surrogates use their primaries encryption label.
|
---|
| 903 | String encryptionLabel = item.getEncryptionLabel();
|
---|
| 904 | if (item.isSurrogate()) {
|
---|
| 905 | encryptionLabel = item.getPrimary().getEncryptionLabel();
|
---|
| 906 | }
|
---|
[1415] | 907 |
|
---|
[1460] | 908 | if (encryptionLabel == null) {
|
---|
| 909 | // If we do not have an encryption label to go off, then we cannot be a surrogate.
|
---|
| 910 | // Add item to body and primaryBody
|
---|
| 911 | addItem(item, recalculate, getBody(false));
|
---|
| 912 | addItem(item, recalculate, getPrimaryBody());
|
---|
[1415] | 913 | } else {
|
---|
[1460] | 914 | List<String> accessibleLabelsNames = Label.getAccessibleLabelsNames(getPrimaryBody());
|
---|
| 915 | if (item.isSurrogate() && accessibleLabelsNames.contains(encryptionLabel)) {
|
---|
| 916 | // .. If it is a surrogate and its encryption label is currently active, it needs to be added to surrogateBody only
|
---|
| 917 | // .. This will result in the item disappearing when placed (as it is now accessible in only surrogate mode)
|
---|
| 918 | addItem(item, recalculate, getSurrogateBody());
|
---|
| 919 | } else if (item.isSurrogate() && !accessibleLabelsNames.contains(encryptionLabel)) {
|
---|
| 920 | // .. If it is a surrogate and its encryption label is not currently active, it needs to be added to body and surrogateBody
|
---|
| 921 | // .. This will result in the item being visible on the frame.
|
---|
| 922 | addItem(item, recalculate, getBody(false));
|
---|
| 923 | addItem(item, recalculate, getSurrogateBody());
|
---|
| 924 | } else if (!item.isSurrogate() && accessibleLabelsNames.contains(encryptionLabel)) {
|
---|
| 925 | // .. If it is a primary and its encryption label is currently active, it needs to be added to body and primaryBody
|
---|
| 926 | // .. This will result in the item being visible on the frame.
|
---|
| 927 | addItem(item, recalculate, getBody(false));
|
---|
| 928 | addItem(item, recalculate, getPrimaryBody());
|
---|
| 929 | // for (Item surrogate: item.getSurrogates()) {
|
---|
| 930 | // surrogate.invalidateBounds(); // Should Item::invalidateBounds invalidate its surrogates bounds as well?
|
---|
| 931 | // }
|
---|
| 932 | } else { // !item.isSurrogate() && !accessibleLabelsNames.contains(encryptionLabel)
|
---|
| 933 | // .. If it is a primary and its encryption label is not currently active, it needs to be added to primaryBody only
|
---|
| 934 | // .. This will result in the item disappearing when placed (as the current surrogate mode does not contain its label)
|
---|
| 935 | // Note from Bryce: I am not sure this else condition will ever run, but it will not hurt.
|
---|
| 936 | addItem(item, recalculate, getPrimaryBody());
|
---|
| 937 | // for (Item surrogate: item.getSurrogates()) {
|
---|
| 938 | // surrogate.invalidateBounds();
|
---|
| 939 | // }
|
---|
| 940 | }
|
---|
[1415] | 941 | }
|
---|
| 942 | }
|
---|
| 943 |
|
---|
| 944 | protected void addItem(Item item, boolean recalculate, ItemsList list) {
|
---|
| 945 | if (item == null || item.equals(_frameName) || list.contains(item)) {
|
---|
[1181] | 946 | return;
|
---|
| 947 | }
|
---|
[4] | 948 |
|
---|
[156] | 949 | // When an annotation item is anchored the annotation list must be
|
---|
| 950 | // refreshed
|
---|
| 951 | if (item.isAnnotation()) {
|
---|
| 952 | clearAnnotations();
|
---|
| 953 | }
|
---|
| 954 |
|
---|
[1181] | 955 | if (item instanceof Line) {
|
---|
| 956 | _lineCount++;
|
---|
| 957 | }
|
---|
[67] | 958 |
|
---|
[108] | 959 | _itemCount = Math.max(_itemCount, item.getID());
|
---|
[4] | 960 |
|
---|
[1415] | 961 | list.add(item);
|
---|
[108] | 962 | item.setParent(this);
|
---|
[172] | 963 | item.setFloating(false); // esnure that it is anchored
|
---|
[190] | 964 |
|
---|
[121] | 965 | item.invalidateCommonTrait(ItemAppearence.Added);
|
---|
[4] | 966 |
|
---|
[108] | 967 | // If the item is a line end and has constraints with items already
|
---|
| 968 | // on the frame then make sure the constraints hold
|
---|
| 969 | if (item.isLineEnd()) {
|
---|
| 970 | item.setPosition(item.getPosition());
|
---|
| 971 | }
|
---|
[1415] | 972 |
|
---|
| 973 | list.invalidateSorted();
|
---|
[80] | 974 |
|
---|
[147] | 975 | // item.setMaxWidth(FrameGraphics.getMaxFrameSize().width);
|
---|
[108] | 976 | // add widget items to the list of widgets
|
---|
| 977 | if (item instanceof WidgetCorner) {
|
---|
[1102] | 978 | Widget iw = ((WidgetCorner) item).getWidgetSource();
|
---|
[108] | 979 | if (!this._iWidgets.contains(iw)) { // A set would have been
|
---|
[1102] | 980 | if (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.CTRL)) {
|
---|
[282] | 981 | _iWidgets.add(iw);
|
---|
[1102] | 982 | } else {
|
---|
[282] | 983 | _iWidgets.add(0, iw);
|
---|
[1102] | 984 | }
|
---|
[10] | 985 | }
|
---|
[108] | 986 | }
|
---|
[10] | 987 |
|
---|
[1102] | 988 | item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED));
|
---|
[67] | 989 |
|
---|
[376] | 990 | // if (recalculate && item.recalculateWhenChanged())
|
---|
| 991 | // recalculate();
|
---|
| 992 |
|
---|
[108] | 993 | change();
|
---|
[4] | 994 | }
|
---|
[1414] | 995 |
|
---|
[1415] | 996 | public void addToSurrogatesOnLoad(Item surrogate, Item parent) {
|
---|
| 997 | parent.addToSurrogates(surrogate);
|
---|
[1414] | 998 | }
|
---|
[4] | 999 |
|
---|
[1102] | 1000 | public void refreshSize()
|
---|
| 1001 | {
|
---|
[147] | 1002 | boolean bReparse = false;
|
---|
[1102] | 1003 |
|
---|
[1415] | 1004 | for (Item i : getSortedItems()) {
|
---|
[1102] | 1005 | Integer anchorLeft = i.getAnchorLeft();
|
---|
[1513] | 1006 | Integer anchorCenterX = i.getAnchorCenterX();
|
---|
[1102] | 1007 | Integer anchorRight = i.getAnchorRight();
|
---|
| 1008 | Integer anchorTop = i.getAnchorTop();
|
---|
[1513] | 1009 | Integer anchorCenterY = i.getAnchorCenterY();
|
---|
[1102] | 1010 | Integer anchorBottom = i.getAnchorBottom();
|
---|
[720] | 1011 |
|
---|
| 1012 |
|
---|
| 1013 | if (anchorLeft != null) {
|
---|
| 1014 | i.setAnchorLeft(anchorLeft);
|
---|
| 1015 | if (i.hasVector()) {
|
---|
| 1016 | bReparse = true;
|
---|
| 1017 | }
|
---|
| 1018 | }
|
---|
| 1019 |
|
---|
[1513] | 1020 | if (anchorCenterX != null) {
|
---|
| 1021 | i.setAnchorCenterX(anchorCenterX);
|
---|
| 1022 | if (i.hasVector()) {
|
---|
| 1023 | bReparse = true;
|
---|
| 1024 | }
|
---|
| 1025 | }
|
---|
| 1026 |
|
---|
[147] | 1027 | if (anchorRight != null) {
|
---|
[278] | 1028 | i.setAnchorRight(anchorRight);
|
---|
[156] | 1029 | if (i.hasVector()) {
|
---|
[147] | 1030 | bReparse = true;
|
---|
| 1031 | }
|
---|
| 1032 | }
|
---|
[720] | 1033 |
|
---|
| 1034 | if (anchorTop != null) {
|
---|
| 1035 | i.setAnchorTop(anchorTop);
|
---|
| 1036 | if (i.hasVector()) {
|
---|
| 1037 | bReparse = true;
|
---|
| 1038 | }
|
---|
| 1039 | }
|
---|
| 1040 |
|
---|
[1513] | 1041 | if (anchorCenterY != null) {
|
---|
| 1042 | i.setAnchorCenterY(anchorCenterY);
|
---|
| 1043 | if (i.hasVector()) {
|
---|
| 1044 | bReparse = true;
|
---|
| 1045 | }
|
---|
| 1046 | }
|
---|
| 1047 |
|
---|
[147] | 1048 | if (anchorBottom != null) {
|
---|
[278] | 1049 | i.setAnchorBottom(anchorBottom);
|
---|
[156] | 1050 | if (i.hasVector()) {
|
---|
[147] | 1051 | bReparse = true;
|
---|
| 1052 | }
|
---|
| 1053 | }
|
---|
[108] | 1054 | }
|
---|
[294] | 1055 |
|
---|
| 1056 | // Do the anchors on the overlays
|
---|
| 1057 | for (Overlay o : getOverlays()) {
|
---|
[278] | 1058 | o.Frame.refreshSize();
|
---|
| 1059 | }
|
---|
[294] | 1060 |
|
---|
[156] | 1061 | if (bReparse) {
|
---|
[147] | 1062 | FrameUtils.Parse(this, false);
|
---|
| 1063 | }
|
---|
[4] | 1064 |
|
---|
[71] | 1065 | _frameName.resetFrameNamePosition();
|
---|
[4] | 1066 | }
|
---|
| 1067 |
|
---|
[1415] | 1068 | public void addAllItems(Collection<Item> toAdd) {
|
---|
[1434] | 1069 | addAllItems(toAdd, getBody(false));
|
---|
| 1070 | addAllItems(toAdd, getPrimaryBody());
|
---|
[1415] | 1071 | }
|
---|
| 1072 |
|
---|
| 1073 | protected void addAllItems(Collection<Item> toAdd, ItemsList list) {
|
---|
[156] | 1074 | for (Item i : toAdd) {
|
---|
| 1075 | // If an annotation is being deleted clear the annotation list
|
---|
[1181] | 1076 | if (i.isAnnotation()) {
|
---|
| 1077 | i.getParentOrCurrentFrame().clearAnnotations();
|
---|
| 1078 | }
|
---|
[190] | 1079 | // TODO Improve efficiency when addAll is called
|
---|
[1415] | 1080 | addItem(i, true, list);
|
---|
[156] | 1081 | }
|
---|
[4] | 1082 | }
|
---|
| 1083 |
|
---|
[1415] | 1084 | public void removeAllItems(Collection<Item> toRemove) {
|
---|
[156] | 1085 | for (Item i : toRemove) {
|
---|
| 1086 | // If an annotation is being deleted clear the annotation list
|
---|
[1181] | 1087 | if (i.isAnnotation()) {
|
---|
| 1088 | i.getParentOrCurrentFrame().clearAnnotations();
|
---|
| 1089 | }
|
---|
[4] | 1090 | removeItem(i);
|
---|
[156] | 1091 | }
|
---|
[4] | 1092 | }
|
---|
| 1093 |
|
---|
[1200] | 1094 | public void removeItem(Item item) {
|
---|
[242] | 1095 | removeItem(item, true);
|
---|
| 1096 | }
|
---|
[247] | 1097 |
|
---|
[1415] | 1098 | public void removeItem(Item item, boolean recalculate) {
|
---|
[1434] | 1099 | removeItem(item, recalculate, getBody(false));
|
---|
[1415] | 1100 | if (item.isSurrogate()) {
|
---|
[1434] | 1101 | removeItem(item, recalculate, getSurrogateBody());
|
---|
[1430] | 1102 | Set<Item> primariesSurrogates = item.getPrimary().getSurrogates();
|
---|
| 1103 | primariesSurrogates.remove(item);
|
---|
[1415] | 1104 | } else {
|
---|
[1434] | 1105 | removeItem(item, recalculate, getPrimaryBody());
|
---|
[1415] | 1106 | }
|
---|
| 1107 | }
|
---|
| 1108 |
|
---|
| 1109 | protected void removeItem(Item item, boolean recalculate, ItemsList toRemoveFrom) {
|
---|
[156] | 1110 | // If an annotation is being deleted clear the annotation list
|
---|
[1181] | 1111 | if (item.isAnnotation()) {
|
---|
| 1112 | item.getParentOrCurrentFrame().clearAnnotations();
|
---|
| 1113 | }
|
---|
[156] | 1114 |
|
---|
[1415] | 1115 | if (toRemoveFrom.remove(item)) {
|
---|
[4] | 1116 | change();
|
---|
[67] | 1117 | // Remove widgets from the widget list
|
---|
| 1118 | if (item != null) {
|
---|
[1102] | 1119 | item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_REMOVED));
|
---|
| 1120 |
|
---|
[67] | 1121 | if (item instanceof WidgetCorner) {
|
---|
| 1122 | _iWidgets.remove(((WidgetCorner) item).getWidgetSource());
|
---|
| 1123 | }
|
---|
[1102] | 1124 |
|
---|
[121] | 1125 | item.invalidateCommonTrait(ItemAppearence.Removed);
|
---|
[10] | 1126 | }
|
---|
[190] | 1127 | // TODO Improve efficiency when removeAll is called
|
---|
[376] | 1128 | // if (recalculate && item.recalculateWhenChanged())
|
---|
| 1129 | // recalculate();
|
---|
[10] | 1130 | }
|
---|
[4] | 1131 | }
|
---|
| 1132 |
|
---|
| 1133 | /**
|
---|
[744] | 1134 | * Adds the given History event to the stack.
|
---|
| 1135 | * @param items The items to put in the event
|
---|
| 1136 | * @param type The type of event that occurred
|
---|
[1450] | 1137 | * @param undoDeleteAssociatedFiles TODO
|
---|
| 1138 | * @param stack The stack to add to
|
---|
[4] | 1139 | */
|
---|
[1450] | 1140 | private void addToUndo(ItemsList items, History.Type type, boolean undoDeleteAssociatedFiles) {
|
---|
[1181] | 1141 | if (items.size() < 1) {
|
---|
| 1142 | return;
|
---|
| 1143 | }
|
---|
[4] | 1144 |
|
---|
[1450] | 1145 | _undo.push(new History(items, type, undoDeleteAssociatedFiles));
|
---|
[4] | 1146 | }
|
---|
[744] | 1147 |
|
---|
[1450] | 1148 | public void addToUndoDelete(ItemsList items, boolean undoDeleteAssociatedFiles) {
|
---|
| 1149 | addToUndo(items, History.Type.deletion, undoDeleteAssociatedFiles);
|
---|
[744] | 1150 | }
|
---|
[1102] | 1151 |
|
---|
[1415] | 1152 | public void addToUndoMove(ItemsList items) {
|
---|
[1450] | 1153 | addToUndo(items, History.Type.movement, false);
|
---|
[744] | 1154 | }
|
---|
[4] | 1155 |
|
---|
[1434] | 1156 | public void undo() {
|
---|
| 1157 | boolean reparse = false;
|
---|
| 1158 | boolean recalculate = false;
|
---|
[4] | 1159 |
|
---|
[1181] | 1160 | if (_undo.size() <= 0) {
|
---|
| 1161 | return;
|
---|
| 1162 | }
|
---|
[4] | 1163 |
|
---|
[744] | 1164 | History undo = _undo.pop();
|
---|
[740] | 1165 |
|
---|
[745] | 1166 | // System.out.println("Undoing: " + undo);
|
---|
[143] | 1167 |
|
---|
[744] | 1168 | switch(undo.type) {
|
---|
| 1169 | case deletion:
|
---|
| 1170 | _redo.push(undo);
|
---|
| 1171 | for(Item i : undo.items) {
|
---|
[1450] | 1172 | if (i instanceof org.expeditee.items.Picture && undo.undoDeleteAssociatedFiles) {
|
---|
[1449] | 1173 | String destination = ((Picture) i).getPath();
|
---|
[1448] | 1174 | Path destinationPath = Paths.get(destination);
|
---|
| 1175 | Path sourcePath = Paths.get(FrameIO.TRASH_PATH).resolve(destinationPath.getFileName());
|
---|
| 1176 | try {
|
---|
| 1177 | Files.move(sourcePath, destinationPath, StandardCopyOption.ATOMIC_MOVE);
|
---|
| 1178 | } catch (IOException e) {
|
---|
| 1179 | MessageBay.displayMessage("Unable to restore image file from trash, not undoing deletion of image.");
|
---|
| 1180 | continue;
|
---|
| 1181 | }
|
---|
| 1182 | }
|
---|
[1434] | 1183 | this.addItem(i);
|
---|
| 1184 | reparse |= i.hasOverlay();
|
---|
| 1185 | recalculate |= i.recalculateWhenChanged();
|
---|
[4] | 1186 | if (i instanceof Line) {
|
---|
| 1187 | Line line = (Line) i;
|
---|
| 1188 | line.getStartItem().addLine(line);
|
---|
| 1189 | line.getEndItem().addLine(line);
|
---|
[50] | 1190 | } else {
|
---|
| 1191 | i.setOffset(0, 0);
|
---|
[4] | 1192 | }
|
---|
[744] | 1193 | }
|
---|
| 1194 | break;
|
---|
| 1195 | case movement:
|
---|
[1434] | 1196 | ItemsList body = getBody(true);
|
---|
| 1197 | ItemsList changed = new ItemsList(body);
|
---|
| 1198 | changed.retainAll(undo.items);
|
---|
[1450] | 1199 | _redo.push(new History(changed, History.Type.movement, false));
|
---|
[744] | 1200 | for(Item i : undo.items) {
|
---|
| 1201 | int index;
|
---|
[1434] | 1202 | if(i.isVisible() && (index = body.indexOf(i)) != -1) {
|
---|
| 1203 | body.set(index, i);
|
---|
[744] | 1204 | }
|
---|
| 1205 | }
|
---|
| 1206 | break;
|
---|
[4] | 1207 | }
|
---|
[1102] | 1208 |
|
---|
[4] | 1209 | change();
|
---|
[1102] | 1210 |
|
---|
| 1211 | StandardGestureActions.refreshHighlights();
|
---|
| 1212 |
|
---|
[1434] | 1213 | if (reparse) {
|
---|
[1511] | 1214 | FrameUtils.Parse(this, false, false, false);
|
---|
[424] | 1215 | } else {
|
---|
[1434] | 1216 | notifyObservers(recalculate);
|
---|
[376] | 1217 | }
|
---|
[1102] | 1218 |
|
---|
[602] | 1219 | // always request a refresh otherwise filled shapes
|
---|
| 1220 | // that were broken by a deletion and then reconnected by the undo
|
---|
| 1221 | // don't get filled until the user otherwise causes them to redraw
|
---|
[1102] | 1222 | DisplayController.requestRefresh(false);
|
---|
[923] | 1223 | // ItemUtils.EnclosedCheck(_body);
|
---|
| 1224 | ItemUtils.Justify(this);
|
---|
[4] | 1225 | }
|
---|
[744] | 1226 |
|
---|
[1102] | 1227 | public void redo()
|
---|
| 1228 | {
|
---|
[744] | 1229 | boolean bReparse = false;
|
---|
| 1230 | boolean bRecalculate = false;
|
---|
[4] | 1231 |
|
---|
[1181] | 1232 | if (_redo.size() <= 0) {
|
---|
| 1233 | return;
|
---|
| 1234 | }
|
---|
[744] | 1235 |
|
---|
| 1236 | History redo = _redo.pop();
|
---|
| 1237 |
|
---|
[745] | 1238 | // System.out.println("Redoing: " + redo);
|
---|
[744] | 1239 |
|
---|
| 1240 | switch(redo.type) {
|
---|
| 1241 | case deletion:
|
---|
| 1242 | _undo.push(redo);
|
---|
| 1243 | for(Item i : redo.items) {
|
---|
[1434] | 1244 | this.removeItem(i);
|
---|
| 1245 | //_body.remove(i);
|
---|
[744] | 1246 | bReparse |= i.hasOverlay();
|
---|
| 1247 | bRecalculate |= i.recalculateWhenChanged();
|
---|
| 1248 | if (i instanceof Line) {
|
---|
| 1249 | Line line = (Line) i;
|
---|
| 1250 | line.getStartItem().removeLine(line);
|
---|
| 1251 | line.getEndItem().removeLine(line);
|
---|
| 1252 | } else {
|
---|
| 1253 | i.setOffset(0, 0);
|
---|
| 1254 | }
|
---|
| 1255 | }
|
---|
| 1256 | break;
|
---|
| 1257 | case movement:
|
---|
[1434] | 1258 | ItemsList body = getBody(true);
|
---|
| 1259 | ItemsList changed = new ItemsList(body);
|
---|
| 1260 | changed.retainAll(redo.items);
|
---|
[1450] | 1261 | _undo.push(new History(changed, History.Type.movement, false));
|
---|
[744] | 1262 | for(Item i : redo.items) {
|
---|
| 1263 | int index;
|
---|
[1434] | 1264 | if(i.isVisible() && (index = body.indexOf(i)) != -1) {
|
---|
| 1265 | body.set(index, i);
|
---|
[744] | 1266 | }
|
---|
| 1267 | }
|
---|
| 1268 | break;
|
---|
| 1269 | }
|
---|
[1102] | 1270 |
|
---|
[744] | 1271 | change();
|
---|
[1102] | 1272 |
|
---|
| 1273 | StandardGestureActions.refreshHighlights();
|
---|
| 1274 |
|
---|
[744] | 1275 | if (bReparse) {
|
---|
[1511] | 1276 | FrameUtils.Parse(this, false, false, false);
|
---|
[744] | 1277 | } else {
|
---|
| 1278 | notifyObservers(bRecalculate);
|
---|
| 1279 | }
|
---|
[1102] | 1280 |
|
---|
[744] | 1281 | // always request a refresh otherwise filled shapes
|
---|
| 1282 | // that were broken by a deletion and then reconnected by the undo
|
---|
| 1283 | // don't get filled until the user otherwise causes them to redraw
|
---|
[1102] | 1284 | DisplayController.requestRefresh(false);
|
---|
[923] | 1285 | // ItemUtils.EnclosedCheck(_body);
|
---|
| 1286 | ItemUtils.Justify(this);
|
---|
[744] | 1287 | }
|
---|
| 1288 |
|
---|
[4] | 1289 | /**
|
---|
| 1290 | * Returns the frameset of this Frame
|
---|
| 1291 | *
|
---|
| 1292 | * @return The name of this Frame's frameset.
|
---|
| 1293 | */
|
---|
[1102] | 1294 | public String getFramesetName()
|
---|
| 1295 | {
|
---|
[4] | 1296 | return _frameset;
|
---|
| 1297 | }
|
---|
| 1298 |
|
---|
[1102] | 1299 | public String getName()
|
---|
| 1300 | {
|
---|
[24] | 1301 | return getFramesetName() + _number;
|
---|
[4] | 1302 | }
|
---|
| 1303 |
|
---|
| 1304 | /**
|
---|
| 1305 | * Returns the format version of this Frame
|
---|
| 1306 | *
|
---|
| 1307 | * @return The version of this Frame.
|
---|
| 1308 | */
|
---|
[1102] | 1309 | public int getVersion()
|
---|
| 1310 | {
|
---|
[4] | 1311 | return _version;
|
---|
| 1312 | }
|
---|
| 1313 |
|
---|
[1488] | 1314 | public boolean isBayFrameset()
|
---|
| 1315 | {
|
---|
| 1316 | boolean is_message_bay = _frameset.equalsIgnoreCase(MessageBay.MESSAGES_FRAMESET_NAME);
|
---|
| 1317 | boolean is_mail_bay = _frameset.equalsIgnoreCase(MailBay.EXPEDITEE_MAIL_FRAMESET_NAME);
|
---|
| 1318 |
|
---|
| 1319 | boolean is_bay = is_message_bay || is_mail_bay;
|
---|
| 1320 |
|
---|
| 1321 | return is_bay;
|
---|
| 1322 | }
|
---|
| 1323 |
|
---|
[1407] | 1324 | public PermissionTriple getPermission() {
|
---|
[1402] | 1325 | return _permissionTriple;
|
---|
[4] | 1326 | }
|
---|
[454] | 1327 |
|
---|
[1407] | 1328 | public UserAppliedPermission getUserAppliedPermission() {
|
---|
[454] | 1329 | return getUserAppliedPermission(UserAppliedPermission.full);
|
---|
| 1330 | }
|
---|
[4] | 1331 |
|
---|
[1407] | 1332 | public UserAppliedPermission getUserAppliedPermission(UserAppliedPermission defaultPermission) {
|
---|
[1402] | 1333 | if (_permissionTriple == null) {
|
---|
[1181] | 1334 | return defaultPermission;
|
---|
| 1335 | }
|
---|
[108] | 1336 |
|
---|
[1407] | 1337 | return _permissionTriple.getPermission(_owner, getGroupMembers());
|
---|
[108] | 1338 | }
|
---|
| 1339 |
|
---|
[1102] | 1340 | public String getOwner()
|
---|
| 1341 | {
|
---|
[4] | 1342 | return _owner;
|
---|
| 1343 | }
|
---|
| 1344 |
|
---|
[1102] | 1345 | public String getDateCreated()
|
---|
| 1346 | {
|
---|
[4] | 1347 | return _creationDate;
|
---|
| 1348 | }
|
---|
| 1349 |
|
---|
[1102] | 1350 | public String getLastModifyUser()
|
---|
| 1351 | {
|
---|
[4] | 1352 | return _modifiedUser;
|
---|
| 1353 | }
|
---|
| 1354 |
|
---|
[1229] | 1355 | public String getLastModifyDate() {
|
---|
[4] | 1356 | return _modifiedDate;
|
---|
| 1357 | }
|
---|
[1229] | 1358 |
|
---|
| 1359 | public long getLastModifyPrecise() {
|
---|
| 1360 | return _modifiedDatePrecise;
|
---|
| 1361 | }
|
---|
[4] | 1362 |
|
---|
[1102] | 1363 | public String getFrozenDate()
|
---|
| 1364 | {
|
---|
[4] | 1365 | return _frozenDate;
|
---|
| 1366 | }
|
---|
| 1367 |
|
---|
[1102] | 1368 | public void setBackgroundColor(Colour back)
|
---|
| 1369 | {
|
---|
[4] | 1370 | _background = back;
|
---|
[1102] | 1371 |
|
---|
[4] | 1372 | change();
|
---|
[143] | 1373 |
|
---|
[1102] | 1374 | if (this == DisplayController.getCurrentFrame()) {
|
---|
| 1375 | DisplayController.requestRefresh(false);
|
---|
[121] | 1376 | }
|
---|
[4] | 1377 | }
|
---|
| 1378 |
|
---|
[1102] | 1379 | public Colour getBackgroundColor()
|
---|
| 1380 | {
|
---|
[4] | 1381 | return _background;
|
---|
| 1382 | }
|
---|
| 1383 |
|
---|
[1102] | 1384 | public Colour getPaintBackgroundColor()
|
---|
| 1385 | {
|
---|
[78] | 1386 | // If null... return white
|
---|
| 1387 | if (_background == null) {
|
---|
| 1388 | return Item.DEFAULT_BACKGROUND;
|
---|
| 1389 | }
|
---|
[4] | 1390 |
|
---|
| 1391 | return _background;
|
---|
| 1392 | }
|
---|
| 1393 |
|
---|
[1102] | 1394 | public void setForegroundColor(Colour front)
|
---|
| 1395 | {
|
---|
[4] | 1396 | _foreground = front;
|
---|
[1102] | 1397 |
|
---|
[4] | 1398 | change();
|
---|
| 1399 | }
|
---|
| 1400 |
|
---|
[1102] | 1401 | public Colour getForegroundColor()
|
---|
| 1402 | {
|
---|
[4] | 1403 | return _foreground;
|
---|
| 1404 | }
|
---|
| 1405 |
|
---|
[1102] | 1406 | public Colour getPaintForegroundColor()
|
---|
| 1407 | {
|
---|
| 1408 | final int GRAY = Colour.GREY.getBlue();
|
---|
| 1409 | final int THRESHOLD = Colour.FromComponent255(10);
|
---|
[4] | 1410 |
|
---|
| 1411 | if (_foreground == null) {
|
---|
[1102] | 1412 | Colour back = getPaintBackgroundColor();
|
---|
[4] | 1413 | if (Math.abs(back.getRed() - GRAY) < THRESHOLD
|
---|
| 1414 | && Math.abs(back.getBlue() - GRAY) < THRESHOLD
|
---|
| 1415 | && Math.abs(back.getGreen() - GRAY) < THRESHOLD)
|
---|
[1102] | 1416 | {
|
---|
| 1417 | return Colour.WHITE;
|
---|
| 1418 | }
|
---|
| 1419 |
|
---|
| 1420 | Colour fore = back.inverse();
|
---|
| 1421 |
|
---|
[4] | 1422 | return fore;
|
---|
| 1423 | }
|
---|
| 1424 |
|
---|
| 1425 | return _foreground;
|
---|
| 1426 | }
|
---|
| 1427 |
|
---|
[1181] | 1428 | @Override
|
---|
[1102] | 1429 | public String toString()
|
---|
| 1430 | {
|
---|
[115] | 1431 | StringBuilder s = new StringBuilder();
|
---|
| 1432 | s.append(String.format("Name: %s%d%n", _frameset, _number));
|
---|
| 1433 | s.append(String.format("Version: %d%n", _version));
|
---|
[348] | 1434 | // s.append(String.format("Permission: %s%n", _permission.toString()));
|
---|
| 1435 | // s.append(String.format("Owner: %s%n", _owner));
|
---|
| 1436 | // s.append(String.format("Date Created: %s%n", _creationDate));
|
---|
| 1437 | // s.append(String.format("Last Mod. User: %s%n", _modifiedUser));
|
---|
| 1438 | // s.append(String.format("Last Mod. Date: %s%n", _modifiedDate));
|
---|
[1434] | 1439 | s.append(String.format("Items: %d%n", getAllFrameItemsRaw().size()));
|
---|
[115] | 1440 | return s.toString();
|
---|
[4] | 1441 | }
|
---|
| 1442 |
|
---|
[1102] | 1443 | public Text getTextAbove(Text current)
|
---|
| 1444 | {
|
---|
[156] | 1445 | Collection<Text> currentTextItems = FrameUtils.getCurrentTextItems();
|
---|
| 1446 | List<Text> toCheck = new ArrayList<Text>();
|
---|
[1102] | 1447 |
|
---|
[156] | 1448 | if (currentTextItems.contains(current)) {
|
---|
| 1449 | toCheck.addAll(currentTextItems);
|
---|
| 1450 | } else {
|
---|
| 1451 | toCheck.addAll(getTextItems());
|
---|
| 1452 | }
|
---|
[1102] | 1453 |
|
---|
[108] | 1454 | // Make sure the items are sorted
|
---|
[156] | 1455 | Collections.sort(toCheck);
|
---|
| 1456 |
|
---|
| 1457 | int ind = toCheck.indexOf(current);
|
---|
[1181] | 1458 | if (ind == -1) {
|
---|
| 1459 | return null;
|
---|
| 1460 | }
|
---|
[4] | 1461 |
|
---|
| 1462 | // loop through all items above this one, return the first match
|
---|
| 1463 | for (int i = ind - 1; i >= 0; i--) {
|
---|
[156] | 1464 | Text check = toCheck.get(i);
|
---|
[1181] | 1465 | if (FrameUtils.inSameColumn(check, current)) {
|
---|
| 1466 | return check;
|
---|
| 1467 | }
|
---|
[4] | 1468 | }
|
---|
| 1469 |
|
---|
| 1470 | return null;
|
---|
| 1471 | }
|
---|
[1102] | 1472 |
|
---|
[4] | 1473 | /**
|
---|
| 1474 | * Gets the text items that are in the same column and below a specified
|
---|
| 1475 | * item. Frame title and name are excluded from the column list.
|
---|
| 1476 | *
|
---|
| 1477 | * @param from
|
---|
| 1478 | * The Item to get the column for.
|
---|
| 1479 | */
|
---|
[1102] | 1480 | public List<Text> getColumn(Item from)
|
---|
| 1481 | {
|
---|
[4] | 1482 | // Check that this item is on the current frame
|
---|
[1434] | 1483 | if (!getBody(true).contains(from)) {
|
---|
[1181] | 1484 | return null;
|
---|
| 1485 | }
|
---|
[4] | 1486 |
|
---|
| 1487 | if (from == null) {
|
---|
| 1488 | from = getLastNonAnnotationTextItem();
|
---|
| 1489 | }
|
---|
| 1490 |
|
---|
[1181] | 1491 | if (from == null) {
|
---|
| 1492 | return null;
|
---|
| 1493 | }
|
---|
[4] | 1494 |
|
---|
[156] | 1495 | // Get the enclosedItems
|
---|
| 1496 | Collection<Text> enclosed = FrameUtils.getCurrentTextItems();
|
---|
| 1497 | List<Text> toCheck = null;
|
---|
[1102] | 1498 |
|
---|
[156] | 1499 | if (enclosed.contains(from)) {
|
---|
| 1500 | toCheck = new ArrayList<Text>();
|
---|
| 1501 | toCheck.addAll(enclosed);
|
---|
| 1502 | } else {
|
---|
| 1503 | toCheck = getBodyTextItems(true);
|
---|
| 1504 | }
|
---|
[4] | 1505 |
|
---|
[156] | 1506 | List<Text> column = new ArrayList<Text>();
|
---|
[1102] | 1507 |
|
---|
[176] | 1508 | if (toCheck.size() > 0) {
|
---|
| 1509 | // Make sure the items are sorted
|
---|
| 1510 | Collections.sort(toCheck);
|
---|
| 1511 |
|
---|
| 1512 | // Create a list of items consisting of the item 'from' and all the
|
---|
| 1513 | // items below it which are also in the same column as it
|
---|
[238] | 1514 | int index = toCheck.indexOf(from);
|
---|
| 1515 |
|
---|
[294] | 1516 | // If its the title index will be 0
|
---|
[1181] | 1517 | if (index < 0) {
|
---|
| 1518 | index = 0;
|
---|
| 1519 | }
|
---|
[238] | 1520 |
|
---|
| 1521 | for (int i = index; i < toCheck.size(); i++) {
|
---|
[176] | 1522 | Text item = toCheck.get(i);
|
---|
[1181] | 1523 | if (FrameUtils.inSameColumn(from, item)) {
|
---|
| 1524 | column.add(item);
|
---|
| 1525 | }
|
---|
[176] | 1526 | }
|
---|
[4] | 1527 | }
|
---|
| 1528 |
|
---|
| 1529 | return column;
|
---|
| 1530 | }
|
---|
| 1531 |
|
---|
| 1532 | /**
|
---|
[78] | 1533 | * Adds the given Vector to the list of vector Frames being drawn with this
|
---|
| 1534 | * Frame.
|
---|
| 1535 | *
|
---|
| 1536 | * @param vector
|
---|
| 1537 | * The Vector to add
|
---|
| 1538 | *
|
---|
| 1539 | * @throws NullPointerException
|
---|
| 1540 | * If overlay is null.
|
---|
| 1541 | */
|
---|
[1102] | 1542 | protected boolean addVector(Vector toAdd)
|
---|
| 1543 | {
|
---|
[78] | 1544 | // make sure we dont add this frame as an overlay of itself
|
---|
[1181] | 1545 | if (toAdd.Frame == this) {
|
---|
| 1546 | return false;
|
---|
| 1547 | }
|
---|
[1102] | 1548 |
|
---|
[115] | 1549 | _vectors.add(toAdd);
|
---|
[1102] | 1550 |
|
---|
[115] | 1551 | // Items must be notified that they have been added or removed from this
|
---|
[143] | 1552 | // frame via the vector...
|
---|
[286] | 1553 | int maxX = 0;
|
---|
| 1554 | int maxY = 0;
|
---|
[1102] | 1555 |
|
---|
[286] | 1556 | HighlightMode mode = toAdd.Source.getHighlightMode();
|
---|
[1181] | 1557 | if (mode != HighlightMode.None) {
|
---|
| 1558 | mode = HighlightMode.Connected;
|
---|
| 1559 | }
|
---|
[1102] | 1560 |
|
---|
| 1561 | Colour highlightColor = toAdd.Source.getHighlightColor();
|
---|
| 1562 |
|
---|
[115] | 1563 | for (Item i : ItemUtils.CopyItems(toAdd.Frame.getVectorItems(), toAdd)) {
|
---|
[1102] | 1564 | i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, toAdd.permission));
|
---|
[286] | 1565 | i.setEditTarget(toAdd.Source);
|
---|
[1102] | 1566 | i.setHighlightModeAndColour(mode, highlightColor);
|
---|
[115] | 1567 | _vectorItems.add(i);
|
---|
[121] | 1568 | i.invalidateAll();
|
---|
| 1569 | i.invalidateFill();
|
---|
[1102] | 1570 |
|
---|
[294] | 1571 | // Get the right most x and bottom most y pos
|
---|
[286] | 1572 | int itemRight = i.getX() + i.getBoundsWidth();
|
---|
[1181] | 1573 | if (itemRight > maxX) {
|
---|
| 1574 | maxX = itemRight;
|
---|
| 1575 | }
|
---|
[1102] | 1576 |
|
---|
[286] | 1577 | int itemBottom = i.getY() + i.getBoundsHeight();
|
---|
[1181] | 1578 | if (itemBottom > maxY) {
|
---|
| 1579 | maxY = itemBottom;
|
---|
| 1580 | }
|
---|
[30] | 1581 | }
|
---|
[1102] | 1582 |
|
---|
[286] | 1583 | toAdd.setSize(maxX, maxY);
|
---|
[1102] | 1584 |
|
---|
[115] | 1585 | return true;
|
---|
[4] | 1586 | }
|
---|
| 1587 |
|
---|
[1102] | 1588 | public Collection<Vector> getVectors()
|
---|
| 1589 | {
|
---|
[115] | 1590 | Collection<Vector> l = new LinkedList<Vector>();
|
---|
[78] | 1591 | l.addAll(_vectors);
|
---|
| 1592 | return l;
|
---|
| 1593 | }
|
---|
| 1594 |
|
---|
[1102] | 1595 | public Collection<Overlay> getOverlays()
|
---|
| 1596 | {
|
---|
[115] | 1597 | return new LinkedList<Overlay>(_overlays.keySet());
|
---|
[4] | 1598 | }
|
---|
[67] | 1599 |
|
---|
[30] | 1600 | /**
|
---|
[1102] | 1601 | * @return All vectors seen by this frame (including its vector's vectors).
|
---|
[78] | 1602 | */
|
---|
[1102] | 1603 | public List<Vector> getVectorsDeep()
|
---|
| 1604 | {
|
---|
[78] | 1605 | List<Vector> l = new LinkedList<Vector>();
|
---|
| 1606 | getVectorsDeep(l, this, new LinkedList<Frame>());
|
---|
| 1607 | return l;
|
---|
| 1608 | }
|
---|
| 1609 |
|
---|
[1102] | 1610 | private boolean getVectorsDeep(List<Vector> vectors, Frame vector, List<Frame> seenVectors)
|
---|
| 1611 | {
|
---|
[1181] | 1612 | if (seenVectors.contains(vector)) {
|
---|
| 1613 | return false;
|
---|
| 1614 | }
|
---|
[78] | 1615 |
|
---|
| 1616 | seenVectors.add(vector);
|
---|
| 1617 |
|
---|
[1102] | 1618 | for (Vector v : vector.getVectors()) {
|
---|
| 1619 | if (getVectorsDeep(vectors, v.Frame, seenVectors)) {
|
---|
| 1620 | vectors.add(v);
|
---|
[78] | 1621 | }
|
---|
| 1622 | }
|
---|
| 1623 |
|
---|
| 1624 | return true;
|
---|
| 1625 | }
|
---|
| 1626 |
|
---|
[1102] | 1627 | public List<Overlay> getOverlaysDeep()
|
---|
| 1628 | {
|
---|
| 1629 | List<Overlay> ret = new LinkedList<Overlay>();
|
---|
| 1630 |
|
---|
| 1631 | getOverlaysDeep(ret, new LinkedList<Frame>());
|
---|
| 1632 |
|
---|
| 1633 | return ret;
|
---|
| 1634 | }
|
---|
| 1635 |
|
---|
| 1636 | private boolean getOverlaysDeep(List<Overlay> overlays, List<Frame> seenOverlays)
|
---|
| 1637 | {
|
---|
[1181] | 1638 | if (seenOverlays.contains(this)) {
|
---|
| 1639 | return false;
|
---|
| 1640 | }
|
---|
[1102] | 1641 |
|
---|
| 1642 | seenOverlays.add(this);
|
---|
| 1643 |
|
---|
| 1644 | for (Overlay o : this.getOverlays()) {
|
---|
| 1645 | if (o.Frame.getOverlaysDeep(overlays, seenOverlays)) {
|
---|
| 1646 | overlays.add(o);
|
---|
| 1647 | }
|
---|
| 1648 | }
|
---|
| 1649 | return true;
|
---|
| 1650 | }
|
---|
| 1651 |
|
---|
| 1652 | /**
|
---|
| 1653 | * Recursive function similar to AddAllOverlayItems.
|
---|
| 1654 | *
|
---|
| 1655 | * @param widgets
|
---|
| 1656 | * The collection the widgets will be added to
|
---|
| 1657 | * @param overlay
|
---|
| 1658 | * An "overlay" frame - this initially will be the parent frame
|
---|
| 1659 | * @param seenOverlays
|
---|
| 1660 | * Used for state in the recursion stack. Pass as an empty
|
---|
| 1661 | * (non-null) list.
|
---|
| 1662 | */
|
---|
| 1663 | public List<Widget> getAllOverlayWidgets()
|
---|
| 1664 | {
|
---|
| 1665 | List<Widget> widgets = new LinkedList<Widget>();
|
---|
| 1666 |
|
---|
[1181] | 1667 | for (Overlay o : getOverlaysDeep()) {
|
---|
| 1668 | widgets.addAll(o.Frame.getInteractiveWidgets());
|
---|
| 1669 | }
|
---|
[1102] | 1670 |
|
---|
| 1671 | return widgets;
|
---|
| 1672 | }
|
---|
[30] | 1673 |
|
---|
| 1674 | /**
|
---|
| 1675 | * Gets the overlay on this frame which owns the given item.
|
---|
[67] | 1676 | *
|
---|
| 1677 | * @param item
|
---|
| 1678 | * The item - must not be null.
|
---|
[1102] | 1679 | * @return The overlay that contains the item. Null if no overlay owns the
|
---|
[67] | 1680 | * item.
|
---|
[30] | 1681 | */
|
---|
[1102] | 1682 | public Overlay getOverlayOwner(Item item)
|
---|
| 1683 | {
|
---|
[1181] | 1684 | if (item == null) {
|
---|
| 1685 | throw new NullPointerException("item");
|
---|
| 1686 | }
|
---|
[143] | 1687 |
|
---|
[115] | 1688 | for (Overlay l : getOverlays()) {
|
---|
[1181] | 1689 | if (item.getParent() == l.Frame) {
|
---|
| 1690 | return l;
|
---|
| 1691 | }
|
---|
[30] | 1692 | }
|
---|
[67] | 1693 |
|
---|
[143] | 1694 | // TODO return the correct vector... not just the first vector matching
|
---|
[1102] | 1695 | // the vector frame
|
---|
[115] | 1696 | for (Vector v : getVectors()) {
|
---|
[1181] | 1697 | if (item.getParent() == v.Frame) {
|
---|
| 1698 | return v;
|
---|
| 1699 | }
|
---|
[115] | 1700 | }
|
---|
[143] | 1701 |
|
---|
[30] | 1702 | return null;
|
---|
| 1703 | }
|
---|
| 1704 |
|
---|
[1102] | 1705 | public void clearVectors()
|
---|
| 1706 | {
|
---|
[115] | 1707 | _vectors.clear();
|
---|
[143] | 1708 |
|
---|
[121] | 1709 | for (Item i : _vectorItems) { // TODO: Rethink where this should live
|
---|
| 1710 | i.invalidateAll();
|
---|
| 1711 | i.invalidateFill();
|
---|
| 1712 | }
|
---|
[115] | 1713 | _vectorItems.clear();
|
---|
[143] | 1714 |
|
---|
[115] | 1715 | }
|
---|
| 1716 |
|
---|
[1102] | 1717 | protected boolean removeVector(Vector toRemove)
|
---|
| 1718 | {
|
---|
[1181] | 1719 | if (!_vectors.remove(toRemove)) {
|
---|
| 1720 | return false;
|
---|
| 1721 | }
|
---|
[1102] | 1722 |
|
---|
[115] | 1723 | for (Item i : toRemove.Frame.getVectorItems()) {
|
---|
[121] | 1724 | i.invalidateAll();
|
---|
| 1725 | i.invalidateFill();
|
---|
[130] | 1726 | _vectorItems.remove(i);
|
---|
[115] | 1727 | i.onParentStateChanged(new ItemParentStateChangedEvent(this,
|
---|
| 1728 | ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY,
|
---|
| 1729 | toRemove.permission));
|
---|
[143] | 1730 |
|
---|
[78] | 1731 | }
|
---|
[1102] | 1732 |
|
---|
[115] | 1733 | return true;
|
---|
[78] | 1734 | }
|
---|
| 1735 |
|
---|
[1102] | 1736 | public void clearOverlays()
|
---|
| 1737 | {
|
---|
[115] | 1738 | for (Overlay o : _overlays.keySet()) {
|
---|
[1415] | 1739 | for (Item i : o.Frame.getSortedItems()) {
|
---|
[1102] | 1740 | i.onParentStateChanged(new ItemParentStateChangedEvent(
|
---|
[145] | 1741 | this,
|
---|
| 1742 | ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY,
|
---|
| 1743 | o.permission));
|
---|
| 1744 | }
|
---|
[30] | 1745 | }
|
---|
[145] | 1746 | _overlayItems.clear();
|
---|
| 1747 | _overlays.clear();
|
---|
[115] | 1748 | assert (_overlays.isEmpty());
|
---|
[4] | 1749 | }
|
---|
| 1750 |
|
---|
[1102] | 1751 | protected boolean removeOverlay(Frame f)
|
---|
| 1752 | {
|
---|
[115] | 1753 | for (Overlay o : _overlays.keySet()) {
|
---|
| 1754 | if (o.Frame == f) {
|
---|
| 1755 | _overlays.remove(o);
|
---|
[1102] | 1756 |
|
---|
[1415] | 1757 | for (Item i : f.getSortedItems()) {
|
---|
[115] | 1758 | _overlayItems.remove(i);
|
---|
[1102] | 1759 | i.onParentStateChanged(new ItemParentStateChangedEvent(
|
---|
[115] | 1760 | this,
|
---|
| 1761 | ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY,
|
---|
| 1762 | o.permission));
|
---|
| 1763 | }
|
---|
[1102] | 1764 |
|
---|
[115] | 1765 | return true;
|
---|
| 1766 | }
|
---|
| 1767 | }
|
---|
[1102] | 1768 |
|
---|
[115] | 1769 | return false;
|
---|
| 1770 | }
|
---|
| 1771 |
|
---|
[1102] | 1772 | public void addAllVectors(List<Vector> vectors)
|
---|
| 1773 | {
|
---|
[78] | 1774 | for (Vector v : vectors) {
|
---|
[115] | 1775 | addVector(v);
|
---|
[78] | 1776 | }
|
---|
| 1777 | }
|
---|
[143] | 1778 |
|
---|
[1102] | 1779 | public void addAllOverlays(Collection<Overlay> overlays)
|
---|
| 1780 | {
|
---|
[30] | 1781 | for (Overlay o : overlays) {
|
---|
[115] | 1782 | addOverlay(o);
|
---|
[30] | 1783 | }
|
---|
[4] | 1784 | }
|
---|
| 1785 |
|
---|
[1102] | 1786 | protected boolean addOverlay(Overlay toAdd)
|
---|
| 1787 | {
|
---|
[115] | 1788 | // make sure we dont add this frame as an overlay of itself
|
---|
[1181] | 1789 | if (toAdd.Frame == this) {
|
---|
| 1790 | return false;
|
---|
| 1791 | }
|
---|
[1102] | 1792 |
|
---|
[115] | 1793 | // Dont add the overlay if there is already one for this frame
|
---|
[1181] | 1794 | if (_overlays.values().contains(toAdd.Frame)) {
|
---|
| 1795 | return false;
|
---|
| 1796 | }
|
---|
[1102] | 1797 |
|
---|
[115] | 1798 | // Add the overlay to the map of overlays on this frame
|
---|
| 1799 | _overlays.put(toAdd, toAdd.Frame);
|
---|
[1102] | 1800 |
|
---|
[115] | 1801 | // Add all the overlays from the overlay frame to this frame
|
---|
[1102] | 1802 | // TODO: Can this cause a recursion loop? If A and B are overlays of each other? cts16
|
---|
[1181] | 1803 | for (Overlay o : toAdd.Frame.getOverlays()) {
|
---|
| 1804 | addOverlay(o);
|
---|
| 1805 | }
|
---|
[115] | 1806 |
|
---|
[336] | 1807 | // Add all the vectors from the overlay frame to this frame
|
---|
[1181] | 1808 | for (Vector v : toAdd.Frame.getVectors()) {
|
---|
| 1809 | addVector(v);
|
---|
| 1810 | }
|
---|
[336] | 1811 |
|
---|
[115] | 1812 | // Now add the items for this overlay
|
---|
[1102] | 1813 | UserAppliedPermission permission = UserAppliedPermission.min(toAdd.Frame.getUserAppliedPermission(), toAdd.permission);
|
---|
[115] | 1814 |
|
---|
| 1815 | // Items must be notified that they have been added or removed from this
|
---|
| 1816 | // frame via the overlay...
|
---|
| 1817 | for (Item i : toAdd.Frame.getVisibleItems()) {
|
---|
[1102] | 1818 | i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, permission));
|
---|
[115] | 1819 | _overlayItems.add(i);
|
---|
| 1820 | }
|
---|
[336] | 1821 |
|
---|
[115] | 1822 | return true;
|
---|
| 1823 | }
|
---|
| 1824 |
|
---|
[4] | 1825 | @Override
|
---|
[1102] | 1826 | public boolean equals(Object o)
|
---|
| 1827 | {
|
---|
[4] | 1828 | if (o instanceof String) {
|
---|
[1102] | 1829 | return (String.CASE_INSENSITIVE_ORDER.compare((String) o, getName()) == 0);
|
---|
[4] | 1830 | }
|
---|
| 1831 |
|
---|
| 1832 | if (o instanceof Frame) {
|
---|
[80] | 1833 | return getName().equals(((Frame) o).getName());
|
---|
[4] | 1834 | }
|
---|
| 1835 |
|
---|
| 1836 | return super.equals(o);
|
---|
| 1837 | }
|
---|
| 1838 |
|
---|
| 1839 | /**
|
---|
| 1840 | * Merge one frames contents into another.
|
---|
| 1841 | *
|
---|
| 1842 | * @param toMergeWith
|
---|
| 1843 | */
|
---|
[1102] | 1844 | private void merge(Frame toMergeWith)
|
---|
| 1845 | {
|
---|
[1181] | 1846 | if (toMergeWith == null) {
|
---|
| 1847 | return;
|
---|
| 1848 | }
|
---|
[4] | 1849 |
|
---|
[1415] | 1850 | List<Item> copies = ItemUtils.CopyItems(toMergeWith.getSortedItems());
|
---|
[80] | 1851 | copies.remove(toMergeWith.getNameItem());
|
---|
[67] | 1852 |
|
---|
[4] | 1853 | for (Item i : copies) {
|
---|
| 1854 | if (i.getID() >= 0) {
|
---|
| 1855 | i.setID(this.getNextItemID());
|
---|
| 1856 | addItem(i);
|
---|
| 1857 | }
|
---|
| 1858 | }
|
---|
| 1859 | }
|
---|
| 1860 |
|
---|
| 1861 | /**
|
---|
[70] | 1862 | * This method is for merging frames or setting frame attributes via
|
---|
| 1863 | * injecting a text item into the frameName item.
|
---|
[4] | 1864 | *
|
---|
| 1865 | * @param toMerge
|
---|
[70] | 1866 | * @return the items that cant be merged
|
---|
[4] | 1867 | */
|
---|
[1102] | 1868 | public List<Item> merge(List<Item> toMerge)
|
---|
| 1869 | {
|
---|
[4] | 1870 | ArrayList<Item> remain = new ArrayList<Item>(0);
|
---|
| 1871 |
|
---|
| 1872 | for (Item i : toMerge) {
|
---|
[1102] | 1873 | if (!(i instanceof Text)) {
|
---|
[4] | 1874 | remain.add(i);
|
---|
[1102] | 1875 | } else {
|
---|
[97] | 1876 | if (!AttributeUtils.setAttribute(this, (Text) i)) {
|
---|
[1102] | 1877 | if (i.getLink() != null) {
|
---|
[4] | 1878 | merge(FrameIO.LoadFrame(i.getAbsoluteLink()));
|
---|
[1102] | 1879 | } else if (FrameIO.isValidFrameName(((Text) i).getFirstLine())) {
|
---|
[7] | 1880 | // If we get hear we are merging frames
|
---|
[4] | 1881 | merge(FrameIO.LoadFrame(((Text) i).getFirstLine()));
|
---|
| 1882 | }
|
---|
| 1883 | }
|
---|
| 1884 | }
|
---|
| 1885 | }
|
---|
| 1886 |
|
---|
| 1887 | return remain;
|
---|
| 1888 | }
|
---|
| 1889 |
|
---|
| 1890 | /**
|
---|
| 1891 | * Removes all non-title non-annotation items from this Frame. All removed
|
---|
| 1892 | * items are added to the backup-stack.
|
---|
[1434] | 1893 | */
|
---|
| 1894 | @Deprecated
|
---|
| 1895 | public void clearDeprecated(boolean keepAnnotations)
|
---|
[1102] | 1896 | {
|
---|
[1415] | 1897 | ItemsList newBody = new ItemsList();
|
---|
[1102] | 1898 |
|
---|
[108] | 1899 | Item title = getTitleItem();
|
---|
[1102] | 1900 |
|
---|
[108] | 1901 | if (title != null) {
|
---|
| 1902 | newBody.add(title);
|
---|
| 1903 | _body.remove(title);
|
---|
| 1904 | }
|
---|
[1102] | 1905 |
|
---|
[108] | 1906 | if (keepAnnotations) {
|
---|
| 1907 | for (Item i : _body) {
|
---|
[1181] | 1908 | if (i.isAnnotation()) {
|
---|
| 1909 | newBody.add(i);
|
---|
| 1910 | }
|
---|
[108] | 1911 | }
|
---|
| 1912 | }
|
---|
[1102] | 1913 |
|
---|
[4] | 1914 | _body.removeAll(newBody);
|
---|
[1450] | 1915 | addToUndoDelete(_body, false);
|
---|
[4] | 1916 | _body = newBody;
|
---|
[108] | 1917 | change();
|
---|
[156] | 1918 |
|
---|
[1181] | 1919 | if (!keepAnnotations && _annotations != null) {
|
---|
| 1920 | _annotations.clear();
|
---|
| 1921 | }
|
---|
[4] | 1922 | }
|
---|
[1434] | 1923 |
|
---|
| 1924 | /**
|
---|
| 1925 | * Removes all items from the Frame except the Title Item and optionally the annotations.
|
---|
| 1926 | * All removed items are added to the backup-stack.
|
---|
| 1927 | *
|
---|
| 1928 | * @param keepAnnotations true is annotations are not to be removed from the frame.
|
---|
| 1929 | */
|
---|
| 1930 | public void clear(boolean keepAnnotations) {
|
---|
| 1931 | ItemsList body = getBody(true);
|
---|
| 1932 | ItemsList deleted = new ItemsList();
|
---|
| 1933 |
|
---|
| 1934 | for (Item bodyItem: body) {
|
---|
| 1935 | boolean isAnnotationToKeep = bodyItem.isAnnotation() && keepAnnotations;
|
---|
| 1936 | boolean isFrameTitle = bodyItem.isFrameTitle();
|
---|
| 1937 | boolean isToBeRetained = isFrameTitle || isAnnotationToKeep;
|
---|
| 1938 | if (isToBeRetained) {
|
---|
| 1939 | continue;
|
---|
| 1940 | }
|
---|
| 1941 |
|
---|
| 1942 | this.removeItem(bodyItem);
|
---|
| 1943 | deleted.add(bodyItem);
|
---|
| 1944 | }
|
---|
| 1945 |
|
---|
[1450] | 1946 | addToUndoDelete(deleted, false);
|
---|
[1434] | 1947 | change();
|
---|
| 1948 |
|
---|
| 1949 | if (!keepAnnotations && _annotations != null) {
|
---|
| 1950 | _annotations.clear();
|
---|
| 1951 | }
|
---|
| 1952 | }
|
---|
[4] | 1953 |
|
---|
| 1954 | /**
|
---|
[50] | 1955 | * Creates a new text item with the given text.
|
---|
[67] | 1956 | *
|
---|
[50] | 1957 | * @param text
|
---|
| 1958 | * @return
|
---|
[4] | 1959 | */
|
---|
[1102] | 1960 | public Text createNewText(String text)
|
---|
| 1961 | {
|
---|
[4] | 1962 | Text t = createBlankText(text);
|
---|
| 1963 | t.setText(text);
|
---|
| 1964 | return t;
|
---|
| 1965 | }
|
---|
| 1966 |
|
---|
[50] | 1967 | /**
|
---|
| 1968 | * Creates a new Text Item with no text. The newly created Item is a copy
|
---|
| 1969 | * the ItemTemplate if one is present, and inherits all the attributes of
|
---|
| 1970 | * the Template
|
---|
| 1971 | *
|
---|
| 1972 | * @return The newly created Text Item
|
---|
| 1973 | */
|
---|
[1242] | 1974 | public Text createBlankText(String templateType) {
|
---|
| 1975 | File file = new File(getFramePathReal());
|
---|
| 1976 | long fileLastModified = file.lastModified();
|
---|
| 1977 | long frameLastModified = this.getLastModifyPrecise();
|
---|
| 1978 | //if (ExpReader.getVersion(getFramePathReal()) > this._version) {
|
---|
| 1979 | if (fileLastModified > frameLastModified) {
|
---|
| 1980 | GestureType refreshGestureType = StandardGestureActions.getInstance().gestureType(StandardGestureType.REFRESH);
|
---|
| 1981 | RefreshGestureData refreshGestureData = new RefreshGestureData(true, false);
|
---|
| 1982 | try {
|
---|
| 1983 | StandardGestureActions.getInstance().onGesture(new Gesture(refreshGestureType, refreshGestureData));
|
---|
| 1984 | EcosystemManager.getMiscManager().beep();
|
---|
| 1985 | } catch (NullPointerException e) {
|
---|
| 1986 | //Detected more recent data on file system than on Frame in memory. Unfortunately not in a position to cause a refresh.
|
---|
| 1987 | }
|
---|
| 1988 | }
|
---|
| 1989 |
|
---|
[72] | 1990 | SessionStats.CreatedText();
|
---|
[4] | 1991 | Text t;
|
---|
[1102] | 1992 |
|
---|
| 1993 | if (templateType.length() == 0) {
|
---|
[4] | 1994 | t = getItemTemplate().copy();
|
---|
[1102] | 1995 | } else {
|
---|
[4] | 1996 | t = getItemTemplate(templateType.charAt(0));
|
---|
[1102] | 1997 | }
|
---|
| 1998 |
|
---|
[4] | 1999 | // reset attributes
|
---|
| 2000 | t.setID(getNextItemID());
|
---|
[1102] | 2001 | t.setPosition(DisplayController.getMousePosition());
|
---|
[4] | 2002 | t.setText("");
|
---|
[47] | 2003 | t.setParent(this);
|
---|
[147] | 2004 |
|
---|
| 2005 | // Set the width if the template doesnt have a width
|
---|
| 2006 | // Make it the width of the page
|
---|
| 2007 | // t.setMaxWidth(FrameGraphics.getMaxFrameSize().width);
|
---|
[156] | 2008 | // if (t.getWidth() <= 0) {
|
---|
[376] | 2009 | // String maxWidthString = getAnnotationValue("maxwidth");
|
---|
| 2010 | // int width = FrameGraphics.getMaxFrameSize().width;
|
---|
| 2011 | // if (maxWidthString != null) {
|
---|
| 2012 | // try {
|
---|
| 2013 | // width = Math.min(width, Integer.parseInt(maxWidthString));
|
---|
| 2014 | // } catch (NumberFormatException nfe) {
|
---|
[156] | 2015 | // }
|
---|
[376] | 2016 | // }
|
---|
| 2017 | //
|
---|
| 2018 | // t.setRightMargin(width);
|
---|
| 2019 | // }
|
---|
[108] | 2020 | addItem(t);
|
---|
[4] | 2021 | return t;
|
---|
| 2022 | }
|
---|
[1242] | 2023 |
|
---|
| 2024 | /**
|
---|
| 2025 | * Returns the data associated with the frame.
|
---|
| 2026 | * @return
|
---|
| 2027 | */
|
---|
| 2028 | public List<String> getData() {
|
---|
[1324] | 2029 | return _frameData;
|
---|
[1242] | 2030 | }
|
---|
| 2031 |
|
---|
| 2032 | /**
|
---|
| 2033 | * Adds a piece of data to be associated with the frame.
|
---|
| 2034 | * @param dataItem
|
---|
| 2035 | */
|
---|
| 2036 | public void addToData(String dataItem) {
|
---|
[1326] | 2037 | if (dataItem != null) {
|
---|
| 2038 | if (_frameData == null)
|
---|
| 2039 | _frameData = new LinkedList<String>();
|
---|
| 2040 | _frameData.add(dataItem);
|
---|
| 2041 | }
|
---|
[1242] | 2042 | }
|
---|
[4] | 2043 |
|
---|
[1242] | 2044 | /**
|
---|
| 2045 | * Returns the path (String) to the .exp file that this Frame represents.
|
---|
| 2046 | * This follows redirects, meaning that it provides the actual file from which
|
---|
| 2047 | * the frames data is drawn from.
|
---|
| 2048 | * @return The path to the .exp file that this Frame represents
|
---|
| 2049 | * @see getFramePathLogical
|
---|
| 2050 | * @see getFramesetPath
|
---|
| 2051 | */
|
---|
| 2052 | public String getFramePathReal() {
|
---|
| 2053 | String framesetPath = getFramesetPath();
|
---|
| 2054 | String redirect = ExpReader.redirectTo(getFramePathLogical());
|
---|
| 2055 |
|
---|
| 2056 | if (redirect == null) {
|
---|
| 2057 | return getFramePathLogical();
|
---|
| 2058 | }
|
---|
| 2059 |
|
---|
| 2060 | while (redirect != null) {
|
---|
| 2061 | framesetPath = getFramesetPath() + redirect;
|
---|
| 2062 | redirect = ExpReader.redirectTo(redirect);
|
---|
| 2063 | }
|
---|
| 2064 | return framesetPath;
|
---|
| 2065 | }
|
---|
| 2066 |
|
---|
| 2067 | /**
|
---|
| 2068 | * Returns the path (String) to the .exp file that this Frame represents.
|
---|
| 2069 | * Does not follow redirects, opting to instead provide the logical path to this file.
|
---|
| 2070 | * @return The path to the .exp file that this Frame represents
|
---|
| 2071 | * @see getFramePathReal
|
---|
| 2072 | * @see getFramesetPath
|
---|
| 2073 | */
|
---|
| 2074 | public String getFramePathLogical() {
|
---|
| 2075 | return getFramesetPath() + this.getNumber() + ExpReader.EXTENTION;
|
---|
| 2076 | }
|
---|
| 2077 |
|
---|
| 2078 | /**
|
---|
| 2079 | * Returns the path (String) to the frameset directory that the file that this Frame represents is contained within.
|
---|
| 2080 | * @return The path to this Frames frameset directory
|
---|
| 2081 | * @see getFramesetPathLogical
|
---|
| 2082 | * @see getFramesetPathReal
|
---|
| 2083 | */
|
---|
| 2084 | public String getFramesetPath() {
|
---|
[1434] | 2085 | return Paths.get(this.getPath()).resolve(this.getFramesetName()).toString() + File.separator;
|
---|
[1242] | 2086 | }
|
---|
| 2087 |
|
---|
| 2088 | public Item createDot() {
|
---|
[1102] | 2089 | Item dot = new Dot(DisplayController.getMouseX(), DisplayController.getMouseY(), getNextItemID());
|
---|
[70] | 2090 |
|
---|
[390] | 2091 | Item template = getTemplate(_dotTemplate, ItemUtils.TAG_DOT_TEMPLATE);
|
---|
[70] | 2092 | float thickness = template.getThickness();
|
---|
[1181] | 2093 | if (thickness > 0) {
|
---|
| 2094 | dot.setThickness(template.getThickness());
|
---|
| 2095 | }
|
---|
| 2096 | if (template.getLinePattern() != null) {
|
---|
| 2097 | dot.setLinePattern(template.getLinePattern());
|
---|
| 2098 | }
|
---|
[70] | 2099 | dot.setColor(template.getColor());
|
---|
[247] | 2100 | dot.setFillColor(template.getFillColor());
|
---|
[70] | 2101 | // reset attributes
|
---|
| 2102 | dot.setParent(this);
|
---|
[1415] | 2103 | dot.setOwner(template.getOwner());
|
---|
[70] | 2104 | return dot;
|
---|
| 2105 | }
|
---|
| 2106 |
|
---|
[1102] | 2107 | private Text getTemplate(Text defaultTemplate, int templateTag)
|
---|
| 2108 | {
|
---|
[108] | 2109 | Text t = null;
|
---|
[70] | 2110 |
|
---|
| 2111 | // check for an updated template...
|
---|
[1415] | 2112 | for (Item i : this.getSortedItems()) {
|
---|
[80] | 2113 | if (ItemUtils.startsWithTag(i, templateTag)) {
|
---|
[70] | 2114 | t = (Text) i;
|
---|
| 2115 | break;
|
---|
| 2116 | }
|
---|
| 2117 | }
|
---|
| 2118 |
|
---|
[108] | 2119 | if (t == null) {
|
---|
[1181] | 2120 | if (defaultTemplate == null) {
|
---|
| 2121 | return null;
|
---|
| 2122 | }
|
---|
[1102] | 2123 |
|
---|
[108] | 2124 | t = defaultTemplate;
|
---|
| 2125 | }
|
---|
[1415] | 2126 |
|
---|
[70] | 2127 | // If the item is linked apply any attribute pairs on the child frame
|
---|
| 2128 | String link = t.getAbsoluteLink();
|
---|
[1102] | 2129 |
|
---|
[70] | 2130 | // need to get link first because copy doesnt copy the link
|
---|
| 2131 | t = t.copy();
|
---|
[1415] | 2132 | // If the template does not have a owner then it should be set to the current user.
|
---|
| 2133 | if (t.getOwner() == null) {
|
---|
| 2134 | t.setOwner(UserSettings.UserName.get());
|
---|
| 2135 | }
|
---|
[657] | 2136 | t.setTooltip(null);
|
---|
[70] | 2137 | if (link != null) {
|
---|
| 2138 | t.setLink(null);
|
---|
| 2139 | Frame childFrame = FrameIO.LoadFrame(link);
|
---|
| 2140 | if (childFrame != null) {
|
---|
| 2141 | // read in attribute value pairs
|
---|
| 2142 | for (Text attribute : childFrame.getBodyTextItems(false)) {
|
---|
[97] | 2143 | AttributeUtils.setAttribute(t, attribute);
|
---|
[70] | 2144 | }
|
---|
| 2145 | }
|
---|
| 2146 | }
|
---|
| 2147 | return t;
|
---|
| 2148 | }
|
---|
| 2149 |
|
---|
[1102] | 2150 | /**
|
---|
| 2151 | * TODO: Comment. cts16
|
---|
| 2152 | * TODO: Remove magic constants. cts16
|
---|
| 2153 | */
|
---|
| 2154 | public Text getItemTemplate(char firstChar)
|
---|
| 2155 | {
|
---|
[4] | 2156 | switch (firstChar) {
|
---|
[1102] | 2157 | case '@':
|
---|
| 2158 | return getAnnotationTemplate();
|
---|
| 2159 | case '/':
|
---|
| 2160 | case '#':
|
---|
| 2161 | return getCodeCommentTemplate();
|
---|
| 2162 | default:
|
---|
| 2163 | return getItemTemplate();
|
---|
[4] | 2164 | }
|
---|
| 2165 | }
|
---|
| 2166 |
|
---|
[1102] | 2167 | public Text createNewText()
|
---|
| 2168 | {
|
---|
[4] | 2169 | return createNewText("");
|
---|
| 2170 | }
|
---|
| 2171 |
|
---|
[1102] | 2172 | public Text addText(int x, int y, String text, String action)
|
---|
| 2173 | {
|
---|
[4] | 2174 | Text t = createNewText(text);
|
---|
| 2175 | t.setPosition(x, y);
|
---|
| 2176 | t.addAction(action);
|
---|
| 2177 | return t;
|
---|
| 2178 | }
|
---|
| 2179 |
|
---|
[1102] | 2180 | public Text addText(int x, int y, String text, String action, String link)
|
---|
| 2181 | {
|
---|
| 2182 | Text t = addText(x, y, text, action);
|
---|
[4] | 2183 | t.setLink(link);
|
---|
| 2184 | return t;
|
---|
| 2185 | }
|
---|
| 2186 |
|
---|
[1102] | 2187 | public Dot addDot(int x, int y)
|
---|
| 2188 | {
|
---|
| 2189 | Dot d = new Dot(x, y, getNextItemID());
|
---|
[4] | 2190 | addItem(d);
|
---|
| 2191 | return d;
|
---|
| 2192 | }
|
---|
| 2193 |
|
---|
[702] | 2194 | /**
|
---|
| 2195 | * Adds a rectangle to the frame
|
---|
| 2196 | *
|
---|
| 2197 | * @param x
|
---|
| 2198 | * X coordinate of the top-left corner of the rectangle
|
---|
| 2199 | * @param y
|
---|
| 2200 | * Y coordinate of the top-left corner of the rectangle
|
---|
| 2201 | * @param width
|
---|
| 2202 | * Width of the rectangle
|
---|
| 2203 | * @param height
|
---|
| 2204 | * Height of the rectangle
|
---|
| 2205 | * @param borderThickness
|
---|
| 2206 | * Thickness, in pixels, of the rectangle's border/outline
|
---|
| 2207 | * @param borderColor
|
---|
| 2208 | * Color of the rectangle's border/outline
|
---|
| 2209 | * @param fillColor
|
---|
| 2210 | * Color to fill the rectangle with
|
---|
| 2211 | */
|
---|
[1102] | 2212 | public List<Item> addRectangle(int x, int y, int width, int height, float borderThickness, Colour borderColor, Colour fillColor)
|
---|
| 2213 | {
|
---|
[702] | 2214 | List<Item> rectComponents = new ArrayList<Item>();
|
---|
| 2215 | Item[] corners = new Item[4];
|
---|
| 2216 |
|
---|
| 2217 | // Top Left
|
---|
| 2218 | corners[0] = this.createDot();
|
---|
| 2219 | corners[0].setPosition(x, y);
|
---|
| 2220 |
|
---|
| 2221 | // Top Right
|
---|
| 2222 | corners[1] = this.createDot();
|
---|
| 2223 | corners[1].setPosition(x + width, y);
|
---|
| 2224 |
|
---|
| 2225 | // Bottom Right
|
---|
| 2226 | corners[2] = this.createDot();
|
---|
| 2227 | corners[2].setPosition(x + width, y + height);
|
---|
| 2228 |
|
---|
| 2229 | // Bottom Left
|
---|
| 2230 | corners[3] = this.createDot();
|
---|
[703] | 2231 | corners[3].setPosition(x, y + height);
|
---|
[702] | 2232 |
|
---|
| 2233 | // Add corners to the collection and setting their attributes
|
---|
| 2234 | for (int i = 0; i < corners.length; i++) {
|
---|
| 2235 | corners[i].setThickness(borderThickness);
|
---|
| 2236 | corners[i].setColor(borderColor);
|
---|
| 2237 | corners[i].setFillColor(fillColor);
|
---|
| 2238 | rectComponents.add(corners[i]);
|
---|
| 2239 | }
|
---|
| 2240 |
|
---|
| 2241 | // create lines between the corners
|
---|
| 2242 | rectComponents.add(new Line(corners[0], corners[1], this.getNextItemID()));
|
---|
| 2243 | rectComponents.add(new Line(corners[1], corners[2], this.getNextItemID()));
|
---|
| 2244 | rectComponents.add(new Line(corners[2], corners[3], this.getNextItemID()));
|
---|
| 2245 | rectComponents.add(new Line(corners[3], corners[0], this.getNextItemID()));
|
---|
| 2246 |
|
---|
| 2247 | // Add constraints between each corner
|
---|
| 2248 | new Constraint(corners[0], corners[1], this.getNextItemID(), Constraint.HORIZONTAL);
|
---|
| 2249 | new Constraint(corners[2], corners[3], this.getNextItemID(), Constraint.HORIZONTAL);
|
---|
| 2250 | new Constraint(corners[1], corners[2], this.getNextItemID(), Constraint.VERTICAL);
|
---|
| 2251 | new Constraint(corners[3], corners[0], this.getNextItemID(), Constraint.VERTICAL);
|
---|
| 2252 |
|
---|
[731] | 2253 | List<Item> rect = new ArrayList<Item>(rectComponents);
|
---|
[702] | 2254 | this.addAllItems(rectComponents);
|
---|
[1102] | 2255 | StandardGestureActions.anchor(rectComponents);
|
---|
[731] | 2256 | return rect;
|
---|
[702] | 2257 | }
|
---|
| 2258 |
|
---|
[1102] | 2259 | public boolean isSaved()
|
---|
| 2260 | {
|
---|
[4] | 2261 | return _saved;
|
---|
| 2262 | }
|
---|
| 2263 |
|
---|
[1102] | 2264 | public void setSaved()
|
---|
| 2265 | {
|
---|
[4] | 2266 | _saved = true;
|
---|
| 2267 | _change = false;
|
---|
| 2268 | }
|
---|
| 2269 |
|
---|
[1102] | 2270 | public static boolean rubberbandingLine()
|
---|
| 2271 | {
|
---|
| 2272 | return FreeItems.getInstance().size() == 2 &&
|
---|
| 2273 | (FreeItems.getInstance().get(0) instanceof Line || FreeItems.getInstance().get(1) instanceof Line);
|
---|
[4] | 2274 | }
|
---|
| 2275 |
|
---|
| 2276 | /**
|
---|
| 2277 | * Tests if an item is a non title, non frame name, non special annotation
|
---|
| 2278 | * text item.
|
---|
| 2279 | *
|
---|
| 2280 | * @param it
|
---|
| 2281 | * the item to be tested
|
---|
| 2282 | * @return true if the item is a normal text item
|
---|
| 2283 | */
|
---|
[1102] | 2284 | public boolean isNormalTextItem(Item it)
|
---|
| 2285 | {
|
---|
| 2286 | if (it instanceof Text && it != getTitleItem() && it != _frameName && !((Text) it).isSpecialAnnotation()) {
|
---|
[4] | 2287 | return true;
|
---|
| 2288 | }
|
---|
| 2289 |
|
---|
| 2290 | return false;
|
---|
| 2291 | }
|
---|
| 2292 |
|
---|
| 2293 | /**
|
---|
| 2294 | * Moves the mouse to the end of the text item with a specified index.
|
---|
| 2295 | *
|
---|
| 2296 | * @param index
|
---|
| 2297 | */
|
---|
[1102] | 2298 | public boolean moveMouseToTextItem(int index)
|
---|
| 2299 | {
|
---|
[1415] | 2300 | List<Item> items = getSortedItems();
|
---|
[4] | 2301 | int itemsFound = 0;
|
---|
| 2302 | for (int i = 0; i < items.size(); i++) {
|
---|
| 2303 | Item it = items.get(i);
|
---|
[1181] | 2304 | if (isNormalTextItem(it)) {
|
---|
| 2305 | itemsFound++;
|
---|
| 2306 | }
|
---|
[4] | 2307 | if (itemsFound > index) {
|
---|
[1144] | 2308 | DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition().getX(), it.getY());
|
---|
[1102] | 2309 | DisplayController.resetCursorOffset();
|
---|
| 2310 | DisplayController.requestRefresh(true);
|
---|
[4] | 2311 | return true;
|
---|
| 2312 | }
|
---|
| 2313 | }
|
---|
| 2314 |
|
---|
| 2315 | return false;
|
---|
| 2316 | }
|
---|
| 2317 |
|
---|
| 2318 | /**
|
---|
| 2319 | * Searches for an annotation item called start to be used as the default
|
---|
| 2320 | * cursor location when TDFC occurs.
|
---|
[1102] | 2321 | *
|
---|
| 2322 | * TODO: Remove magic constants. cts16
|
---|
[4] | 2323 | */
|
---|
[1102] | 2324 | public boolean moveMouseToDefaultLocation()
|
---|
| 2325 | {
|
---|
[1415] | 2326 | List<Item> items = getSortedItems();
|
---|
[4] | 2327 |
|
---|
| 2328 | for (Item it : items) {
|
---|
| 2329 | if (it instanceof Text) {
|
---|
| 2330 | Text t = (Text) it;
|
---|
[1102] | 2331 | if (t.getText().toLowerCase().startsWith("@start") || t.getText().toLowerCase().equals("@start:")) {
|
---|
[190] | 2332 | // Used to allow users the option of putting an initial
|
---|
| 2333 | // bullet after the @start
|
---|
| 2334 | // This was replaced by width
|
---|
| 2335 | // t.stripFirstWord();
|
---|
[185] | 2336 | t.setText("");
|
---|
[4] | 2337 |
|
---|
[1181] | 2338 | if (t.getText().equals("")) {
|
---|
| 2339 | DisplayController.getCurrentFrame().removeItem(t);
|
---|
| 2340 | }
|
---|
[1102] | 2341 |
|
---|
| 2342 | if (!FreeItems.hasItemsAttachedToCursor()) {
|
---|
| 2343 | DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition());
|
---|
| 2344 | DisplayController.resetCursorOffset();
|
---|
[4] | 2345 | }
|
---|
[1102] | 2346 |
|
---|
| 2347 | DisplayController.requestRefresh(true);
|
---|
| 2348 |
|
---|
[4] | 2349 | return true;
|
---|
| 2350 | }
|
---|
| 2351 | }
|
---|
| 2352 | }
|
---|
| 2353 |
|
---|
| 2354 | return false;
|
---|
| 2355 | }
|
---|
| 2356 |
|
---|
| 2357 | /**
|
---|
| 2358 | * Gets the file name that actions should use to export files created by
|
---|
| 2359 | * running actions from this frame.
|
---|
| 2360 | *
|
---|
| 2361 | * @return the fileName if the frame contains an '@file' tag. Returns the
|
---|
| 2362 | * name of the frame if the tag isnt on the frame.
|
---|
| 2363 | */
|
---|
[1102] | 2364 | public String getExportFileName()
|
---|
| 2365 | {
|
---|
[311] | 2366 | String fileName = getExportFileTagValue();
|
---|
| 2367 |
|
---|
| 2368 | if (fileName == null) {
|
---|
| 2369 | fileName = getTitle();
|
---|
| 2370 |
|
---|
| 2371 | if (fileName == null) {
|
---|
| 2372 | fileName = getName();
|
---|
| 2373 | }
|
---|
| 2374 | }
|
---|
| 2375 |
|
---|
| 2376 | return fileName;
|
---|
[4] | 2377 | }
|
---|
| 2378 |
|
---|
[1102] | 2379 | public void toggleBackgroundColor()
|
---|
| 2380 | {
|
---|
| 2381 | setBackgroundColor(ColorUtils.getNextColor(_background, TemplateSettings.BackgroundColorWheel.get(), null));
|
---|
[4] | 2382 | }
|
---|
[72] | 2383 |
|
---|
[1102] | 2384 | public void setName(String frameset, int i)
|
---|
| 2385 | {
|
---|
[72] | 2386 | setFrameset(frameset);
|
---|
| 2387 | setFrameNumber(i);
|
---|
| 2388 | }
|
---|
| 2389 |
|
---|
| 2390 | /**
|
---|
| 2391 | * Sets the item permissions to match the protection for the frame.
|
---|
[737] | 2392 | * No longer sets item permissions, since items can have their own permissions now (but still default to frame permissions)
|
---|
[72] | 2393 | *
|
---|
| 2394 | */
|
---|
[1102] | 2395 | public void refreshItemPermissions(UserAppliedPermission maxPermission)
|
---|
| 2396 | {
|
---|
[1181] | 2397 | if(_frameName == null) {
|
---|
| 2398 | return;
|
---|
| 2399 | }
|
---|
[427] | 2400 |
|
---|
[454] | 2401 | UserAppliedPermission permission = UserAppliedPermission.min(maxPermission, getUserAppliedPermission());
|
---|
[74] | 2402 |
|
---|
| 2403 | switch (permission) {
|
---|
[108] | 2404 | case none:
|
---|
[1102] | 2405 | _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE);
|
---|
[74] | 2406 | break;
|
---|
[108] | 2407 | case followLinks:
|
---|
[1102] | 2408 | _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS);
|
---|
[74] | 2409 | break;
|
---|
[108] | 2410 | case copy:
|
---|
[1102] | 2411 | _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY);
|
---|
[74] | 2412 | break;
|
---|
[108] | 2413 | case createFrames:
|
---|
[1102] | 2414 | _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES);
|
---|
[74] | 2415 | break;
|
---|
[108] | 2416 | case full:
|
---|
[1102] | 2417 | _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL);
|
---|
[74] | 2418 | break;
|
---|
| 2419 | default:
|
---|
| 2420 | assert (false);
|
---|
| 2421 | break;
|
---|
[72] | 2422 | }
|
---|
[74] | 2423 |
|
---|
[737] | 2424 | for (Overlay o : getOverlays()) {
|
---|
[1434] | 2425 | for(Item i : o.Frame.getBody(false)) {
|
---|
[737] | 2426 | i.setOverlayPermission(o.permission);
|
---|
| 2427 | }
|
---|
[247] | 2428 | o.Frame.refreshItemPermissions(o.permission);
|
---|
[72] | 2429 | }
|
---|
| 2430 | }
|
---|
[86] | 2431 |
|
---|
[1102] | 2432 | public boolean isTestFrame()
|
---|
| 2433 | {
|
---|
[86] | 2434 | Text title = getTitleItem();
|
---|
[1181] | 2435 | if (title == null) {
|
---|
| 2436 | return false;
|
---|
| 2437 | }
|
---|
[86] | 2438 | String action = title.getFirstAction();
|
---|
[1181] | 2439 | if (action == null) {
|
---|
| 2440 | return false;
|
---|
| 2441 | }
|
---|
[86] | 2442 | action = action.toLowerCase();
|
---|
[1102] | 2443 | return action.startsWith(Simple.RUN_FRAME_ACTION) || action.startsWith(Simple.DEBUG_FRAME_ACTION);
|
---|
[86] | 2444 | }
|
---|
| 2445 |
|
---|
[1102] | 2446 | public void setActiveTime(String activeTime)
|
---|
| 2447 | {
|
---|
[86] | 2448 | try {
|
---|
[1102] | 2449 | _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60 * 60 * 1000);
|
---|
[86] | 2450 | } catch (Exception e) {
|
---|
| 2451 | _activeTime = new Time(0);
|
---|
| 2452 | }
|
---|
| 2453 | }
|
---|
[108] | 2454 |
|
---|
[1102] | 2455 | public void setActiveTime(Time activeTime)
|
---|
| 2456 | {
|
---|
[104] | 2457 | _activeTime = activeTime;
|
---|
| 2458 | }
|
---|
[108] | 2459 |
|
---|
[1102] | 2460 | public void setDarkTime(Time darkTime)
|
---|
| 2461 | {
|
---|
[104] | 2462 | _darkTime = darkTime;
|
---|
| 2463 | }
|
---|
[86] | 2464 |
|
---|
[1102] | 2465 | public void setDarkTime(String darkTime)
|
---|
| 2466 | {
|
---|
[86] | 2467 | try {
|
---|
[1102] | 2468 | _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60 * 60 * 1000);
|
---|
[86] | 2469 | } catch (Exception e) {
|
---|
| 2470 | _darkTime = new Time(0);
|
---|
| 2471 | }
|
---|
| 2472 | }
|
---|
| 2473 |
|
---|
| 2474 | /**
|
---|
[90] | 2475 | * Returns null if their is no backup frame or if it is invalid.
|
---|
[86] | 2476 | *
|
---|
[90] | 2477 | * @return the backup frame for this frame
|
---|
[86] | 2478 | */
|
---|
[1102] | 2479 | public Frame getBackupFrame()
|
---|
| 2480 | {
|
---|
[90] | 2481 | Text backupTag = _annotations.get("old");
|
---|
[1181] | 2482 | if (backupTag == null) {
|
---|
| 2483 | return null;
|
---|
| 2484 | }
|
---|
[1102] | 2485 |
|
---|
[90] | 2486 | // TODO want another way to deal with updating of annotations items
|
---|
| 2487 | // without F12 refresh
|
---|
| 2488 | // Reparse the frame if annotation item has been modified
|
---|
| 2489 | String[] processedText = backupTag.getProcessedText();
|
---|
| 2490 | if (processedText == null) {
|
---|
| 2491 | // Reparse the frame if this item has not yet been parsed
|
---|
| 2492 | FrameUtils.Parse(this);
|
---|
| 2493 | return getBackupFrame();
|
---|
| 2494 | }
|
---|
[1102] | 2495 |
|
---|
[90] | 2496 | // Now return the name of the backed up frame
|
---|
| 2497 | String link = backupTag.getAbsoluteLink();
|
---|
[1181] | 2498 | if (link == null || link.equalsIgnoreCase(getName())) {
|
---|
| 2499 | return null;
|
---|
| 2500 | }
|
---|
[86] | 2501 |
|
---|
[90] | 2502 | Frame backup = FrameIO.LoadFrame(link);
|
---|
| 2503 | return backup;
|
---|
[86] | 2504 | }
|
---|
| 2505 |
|
---|
[1102] | 2506 | public Time getDarkTime()
|
---|
| 2507 | {
|
---|
[90] | 2508 | return _darkTime;
|
---|
[86] | 2509 | }
|
---|
[108] | 2510 |
|
---|
[1102] | 2511 | public Time getActiveTime()
|
---|
| 2512 | {
|
---|
[90] | 2513 | return _activeTime;
|
---|
| 2514 | }
|
---|
[86] | 2515 |
|
---|
| 2516 | /**
|
---|
| 2517 | * Gets the number of backed up versions of this frame are saved plus 1 for
|
---|
| 2518 | * this frame.
|
---|
| 2519 | *
|
---|
| 2520 | * @return the number of frames in the backed up comet
|
---|
| 2521 | */
|
---|
[1102] | 2522 | public int getCometLength()
|
---|
| 2523 | {
|
---|
[90] | 2524 | Frame backup = getBackupFrame();
|
---|
[86] | 2525 | return 1 + (backup == null ? 0 : backup.getCometLength());
|
---|
| 2526 | }
|
---|
[87] | 2527 |
|
---|
[1102] | 2528 | public void addAnnotation(Text item)
|
---|
| 2529 | {
|
---|
[156] | 2530 | if (_annotations == null) {
|
---|
| 2531 | _annotations = new HashMap<String, Text>();
|
---|
| 2532 | }
|
---|
[1102] | 2533 |
|
---|
[88] | 2534 | // Check if this item has already been processed
|
---|
| 2535 | String[] tokens = item.getProcessedText();
|
---|
| 2536 | if (tokens != null) {
|
---|
| 2537 | if (tokens.length > 0) {
|
---|
| 2538 | _annotations.put(tokens[0], item);
|
---|
| 2539 | }
|
---|
| 2540 | return;
|
---|
| 2541 | }
|
---|
| 2542 |
|
---|
| 2543 | String text = item.getText().trim();
|
---|
| 2544 | assert (text.charAt(0) == '@');
|
---|
[1102] | 2545 |
|
---|
[88] | 2546 | // Ignore annotations with spaces after the tag symbol
|
---|
| 2547 | if (text.length() < 2 || !Character.isLetter(text.charAt(1))) {
|
---|
| 2548 | item.setProcessedText(new String[0]);
|
---|
| 2549 | return;
|
---|
| 2550 | }
|
---|
[1102] | 2551 |
|
---|
[88] | 2552 | // The separator char must come before the first non letter otherwise we
|
---|
| 2553 | // ignore the annotation item
|
---|
| 2554 | for (int i = 2; i < text.length(); i++) {
|
---|
| 2555 | char ch = text.charAt(i);
|
---|
| 2556 | if (!Character.isLetterOrDigit(ch)) {
|
---|
| 2557 | // Must have an attribute value pair
|
---|
[235] | 2558 | if (ch == AttributeValuePair.SEPARATOR_CHAR) {
|
---|
[90] | 2559 | // Get the attribute
|
---|
| 2560 | String attribute = text.substring(1, i).toLowerCase();
|
---|
| 2561 | String value = "";
|
---|
| 2562 | if (text.length() > 1 + i) {
|
---|
[199] | 2563 | value = text.substring(i + 1).trim();
|
---|
[88] | 2564 | }
|
---|
[90] | 2565 | item.setProcessedText(new String[] { attribute, value });
|
---|
[88] | 2566 | _annotations.put(attribute, item);
|
---|
| 2567 | return;
|
---|
| 2568 | } else {
|
---|
| 2569 | item.setProcessedText(new String[0]);
|
---|
| 2570 | return;
|
---|
| 2571 | }
|
---|
| 2572 | }
|
---|
| 2573 | }
|
---|
[1102] | 2574 |
|
---|
[88] | 2575 | // If it was nothing but letters and digits save the tag
|
---|
| 2576 | String lowerCaseText = text.substring(1).toLowerCase();
|
---|
[90] | 2577 | item.setProcessedText(new String[] { lowerCaseText });
|
---|
[88] | 2578 | _annotations.put(lowerCaseText, item);
|
---|
[87] | 2579 | }
|
---|
[88] | 2580 |
|
---|
[1102] | 2581 | public boolean hasAnnotation(String annotation)
|
---|
| 2582 | {
|
---|
[1181] | 2583 | if (_annotations == null) {
|
---|
| 2584 | refreshAnnotationList();
|
---|
| 2585 | }
|
---|
[1102] | 2586 |
|
---|
[88] | 2587 | return _annotations.containsKey(annotation.toLowerCase());
|
---|
[87] | 2588 | }
|
---|
[88] | 2589 |
|
---|
[199] | 2590 | /**
|
---|
| 2591 | * Returns the annotation value in full case.
|
---|
| 2592 | *
|
---|
| 2593 | * @param annotation
|
---|
| 2594 | * the annotation to retrieve the value of.
|
---|
| 2595 | * @return the annotation item value in full case or null if the annotation
|
---|
| 2596 | * is not on the frame or has no value.
|
---|
| 2597 | */
|
---|
[1102] | 2598 | public String getAnnotationValue(String annotation)
|
---|
| 2599 | {
|
---|
[1181] | 2600 | if (_annotations == null) {
|
---|
| 2601 | refreshAnnotationList();
|
---|
| 2602 | }
|
---|
[156] | 2603 |
|
---|
[88] | 2604 | Text text = _annotations.get(annotation.toLowerCase());
|
---|
[1181] | 2605 | if (text == null) {
|
---|
| 2606 | return null;
|
---|
| 2607 | }
|
---|
[88] | 2608 |
|
---|
| 2609 | String[] tokens = text.getProcessedText();
|
---|
[1102] | 2610 |
|
---|
[1181] | 2611 | if (tokens != null && tokens.length > 1) {
|
---|
| 2612 | return tokens[1];
|
---|
| 2613 | }
|
---|
[1102] | 2614 |
|
---|
[88] | 2615 | return null;
|
---|
| 2616 | }
|
---|
| 2617 |
|
---|
[1102] | 2618 | public void clearAnnotations()
|
---|
| 2619 | {
|
---|
[156] | 2620 | _annotations = null;
|
---|
[88] | 2621 | }
|
---|
[143] | 2622 |
|
---|
[1102] | 2623 | public List<Item> getVisibleItems()
|
---|
| 2624 | {
|
---|
[1415] | 2625 | return getSortedItems(true);
|
---|
[108] | 2626 | }
|
---|
| 2627 |
|
---|
[1102] | 2628 | private void refreshAnnotationList()
|
---|
| 2629 | {
|
---|
| 2630 | if (_annotations == null) {
|
---|
[156] | 2631 | _annotations = new HashMap<String, Text>();
|
---|
[1102] | 2632 | } else {
|
---|
[156] | 2633 | _annotations.clear();
|
---|
[1102] | 2634 | }
|
---|
| 2635 |
|
---|
[156] | 2636 | for (Text text : getTextItems()) {
|
---|
| 2637 | if (text.isAnnotation()) {
|
---|
| 2638 | addAnnotation(text);
|
---|
| 2639 | }
|
---|
| 2640 | }
|
---|
| 2641 | }
|
---|
| 2642 |
|
---|
[1102] | 2643 | public Collection<Text> getAnnotationItems()
|
---|
| 2644 | {
|
---|
[156] | 2645 | if (_annotations == null) {
|
---|
| 2646 | refreshAnnotationList();
|
---|
| 2647 | }
|
---|
[1102] | 2648 |
|
---|
[108] | 2649 | return _annotations.values();
|
---|
| 2650 | }
|
---|
| 2651 |
|
---|
| 2652 | /**
|
---|
| 2653 | * Gets a list of items to be saved to file by text file writers.
|
---|
| 2654 | *
|
---|
| 2655 | * @return the list of items to be saved to a text file
|
---|
| 2656 | */
|
---|
[1415] | 2657 | /*public List<Item> getItemsToSave() {
|
---|
[108] | 2658 | if (!_sorted) {
|
---|
| 2659 | Collections.sort(_body);
|
---|
| 2660 | _sorted = true;
|
---|
| 2661 | }
|
---|
| 2662 |
|
---|
| 2663 | // iWidgets are handled specially since 8 items are written as one
|
---|
[1102] | 2664 | Collection<Widget> seenWidgets = new LinkedHashSet<Widget>();
|
---|
[108] | 2665 |
|
---|
| 2666 | List<Item> toSave = new ArrayList<Item>();
|
---|
| 2667 |
|
---|
| 2668 | for (Item i : _body) {
|
---|
[1181] | 2669 | if (i == null || i.dontSave()) {
|
---|
| 2670 | continue;
|
---|
| 2671 | }
|
---|
[108] | 2672 |
|
---|
| 2673 | // Ensure only one of the WidgetCorners represent a single widget
|
---|
| 2674 | if (i instanceof WidgetCorner) {
|
---|
[1102] | 2675 | Widget iw = ((WidgetCorner) i).getWidgetSource();
|
---|
[1181] | 2676 | if (seenWidgets.contains(iw)) {
|
---|
| 2677 | continue;
|
---|
| 2678 | }
|
---|
[108] | 2679 | seenWidgets.add(iw);
|
---|
| 2680 | toSave.add(iw.getSource());
|
---|
[115] | 2681 | } else if (i instanceof XRayable) {
|
---|
| 2682 | XRayable x = (XRayable) i;
|
---|
[108] | 2683 | toSave.addAll(x.getItemsToSave());
|
---|
[1102] | 2684 | // Circle centers are items with attached enclosures
|
---|
| 2685 | } else if (i.hasEnclosures()) {
|
---|
[108] | 2686 | continue;
|
---|
[115] | 2687 | } else {
|
---|
[108] | 2688 | toSave.add(i);
|
---|
| 2689 | }
|
---|
| 2690 | }
|
---|
[294] | 2691 |
|
---|
| 2692 | for (Vector v : getVectors()) {
|
---|
[286] | 2693 | toSave.add(v.Source);
|
---|
| 2694 | }
|
---|
[294] | 2695 |
|
---|
[108] | 2696 | return toSave;
|
---|
[1415] | 2697 | }*/
|
---|
| 2698 |
|
---|
| 2699 | public List<Item> getItemsToSave() {
|
---|
| 2700 | return getItemsToSave(BodyType.PrimaryBody);
|
---|
[108] | 2701 | }
|
---|
[1413] | 2702 |
|
---|
[1434] | 2703 | /**
|
---|
| 2704 | * Returns a list of items for the specified BodyType.
|
---|
| 2705 | *
|
---|
| 2706 | * Asking for the primary or surrogate items gives you exactly those.
|
---|
| 2707 | *
|
---|
| 2708 | * Asking for the body items is a weird case because the body list is
|
---|
| 2709 | * transitory. Therefore, when asking for the body items, this
|
---|
| 2710 | * function assumes that you want all items, reguardless of if they
|
---|
| 2711 | * are primaries or surrogates. As of 20/08/2019, there are no places
|
---|
| 2712 | * in the code that asks for the body items to save.
|
---|
| 2713 | * @param type
|
---|
| 2714 | * @return
|
---|
| 2715 | */
|
---|
[1415] | 2716 | public List<Item> getItemsToSave(BodyType type) {
|
---|
| 2717 | assert(!type.equals(BodyType.BodyDisplay));
|
---|
| 2718 | switch (type) {
|
---|
| 2719 | case SurrogateBody:
|
---|
| 2720 | return getItemsToSave(_surrogateItemsBody);
|
---|
| 2721 | case BodyDisplay:
|
---|
[1434] | 2722 | return getItemsToSave(new ItemsList(getAllFrameItemsRaw()));
|
---|
[1415] | 2723 | case PrimaryBody:
|
---|
| 2724 | default:
|
---|
| 2725 | return getItemsToSave(_primaryItemsBody);
|
---|
| 2726 | }
|
---|
[1413] | 2727 | }
|
---|
[1415] | 2728 |
|
---|
| 2729 | private List<Item> getItemsToSave(ItemsList body) {
|
---|
| 2730 | body.sort();
|
---|
| 2731 | List<Widget> seenWidgets = new ArrayList<Widget>();
|
---|
| 2732 |
|
---|
| 2733 | List<Item> toSave = new ArrayList<Item>();
|
---|
| 2734 |
|
---|
| 2735 | for (Item item: body) {
|
---|
[1425] | 2736 |
|
---|
| 2737 | if (item == null || item.dontSave()) {
|
---|
| 2738 | continue;
|
---|
| 2739 | }
|
---|
| 2740 |
|
---|
[1415] | 2741 | if (item instanceof WidgetCorner) {
|
---|
| 2742 | // Save the widget source.
|
---|
| 2743 | // Each widget has multiple WidgetCorner's..ignore them if we already have the source.
|
---|
| 2744 | Widget iw = ((WidgetCorner) item).getWidgetSource();
|
---|
| 2745 | if (seenWidgets.contains(iw)) { continue; }
|
---|
| 2746 | seenWidgets.add(iw);
|
---|
| 2747 | toSave.add(iw.getSource());
|
---|
| 2748 | } else if (item instanceof XRayable) {
|
---|
| 2749 | // XRayable Items have their sources saved.
|
---|
| 2750 | XRayable x = (XRayable) item;
|
---|
| 2751 | toSave.addAll(x.getItemsToSave());
|
---|
| 2752 | } else if (item.hasEnclosures()) {
|
---|
| 2753 | // Deals with Circle objects only?
|
---|
| 2754 | continue;
|
---|
| 2755 | } else {
|
---|
| 2756 | toSave.add(item);
|
---|
| 2757 | }
|
---|
| 2758 | }
|
---|
| 2759 |
|
---|
| 2760 | return toSave;
|
---|
| 2761 | }
|
---|
[115] | 2762 |
|
---|
[1102] | 2763 | public Collection<Item> getOverlayItems()
|
---|
| 2764 | {
|
---|
[115] | 2765 | return _overlayItems;
|
---|
| 2766 | }
|
---|
| 2767 |
|
---|
| 2768 | /**
|
---|
| 2769 | * Returns true if this frame has and overlays for the specified frame.
|
---|
| 2770 | *
|
---|
| 2771 | * @param frame
|
---|
| 2772 | * @return
|
---|
| 2773 | */
|
---|
[1102] | 2774 | public boolean hasOverlay(Frame frame)
|
---|
| 2775 | {
|
---|
[115] | 2776 | return _overlays.containsValue(frame);
|
---|
| 2777 | }
|
---|
| 2778 |
|
---|
[1415] | 2779 | public Collection<Item> getAllItems() {
|
---|
[1460] | 2780 | Collection<Item> allItems = getBody(true).cloneList();
|
---|
[1242] | 2781 |
|
---|
[115] | 2782 | allItems.addAll(_overlayItems);
|
---|
| 2783 | allItems.addAll(_vectorItems);
|
---|
[1460] | 2784 | return allItems;
|
---|
[115] | 2785 | }
|
---|
| 2786 |
|
---|
[1102] | 2787 | public Collection<Item> getVectorItems()
|
---|
| 2788 | {
|
---|
[143] | 2789 | Collection<Item> vectorItems = new LinkedHashSet<Item>(_vectorItems);
|
---|
[196] | 2790 | vectorItems.addAll(getNonAnnotationItems(false));
|
---|
[115] | 2791 | return vectorItems;
|
---|
| 2792 | }
|
---|
[156] | 2793 |
|
---|
| 2794 | /**
|
---|
| 2795 | * Gets a list of all the text items on the frame.
|
---|
| 2796 | *
|
---|
| 2797 | * @return
|
---|
| 2798 | */
|
---|
[1102] | 2799 | public Collection<Text> getTextItems()
|
---|
| 2800 | {
|
---|
[156] | 2801 | Collection<Text> textItems = new ArrayList<Text>();
|
---|
[1102] | 2802 |
|
---|
[1415] | 2803 | for (Item i : getSortedItems(true)) {
|
---|
[156] | 2804 | // only add up normal body text items
|
---|
| 2805 | if ((i instanceof Text)) {
|
---|
| 2806 | textItems.add((Text) i);
|
---|
| 2807 | }
|
---|
| 2808 | }
|
---|
[1102] | 2809 |
|
---|
[156] | 2810 | return textItems;
|
---|
| 2811 | }
|
---|
[176] | 2812 |
|
---|
[1102] | 2813 | public Text getAnnotation(String annotation)
|
---|
| 2814 | {
|
---|
[1181] | 2815 | if (_annotations == null) {
|
---|
| 2816 | refreshAnnotationList();
|
---|
| 2817 | }
|
---|
[176] | 2818 |
|
---|
| 2819 | return _annotations.get(annotation.toLowerCase());
|
---|
| 2820 | }
|
---|
[190] | 2821 |
|
---|
[1102] | 2822 | public void recalculate()
|
---|
| 2823 | {
|
---|
[1415] | 2824 | for (Item i : getSortedItems()) {
|
---|
[190] | 2825 | if (i.hasFormula() && !i.isAnnotation()) {
|
---|
[176] | 2826 | i.calculate(i.getFormula());
|
---|
| 2827 | }
|
---|
| 2828 | }
|
---|
| 2829 | }
|
---|
[199] | 2830 |
|
---|
[1102] | 2831 | public void removeObserver(FrameObserver observer)
|
---|
| 2832 | {
|
---|
[214] | 2833 | _observers.remove(observer);
|
---|
[199] | 2834 | }
|
---|
[214] | 2835 |
|
---|
[1102] | 2836 | public void addObserver(FrameObserver observer)
|
---|
| 2837 | {
|
---|
[214] | 2838 | _observers.add(observer);
|
---|
| 2839 | }
|
---|
| 2840 |
|
---|
[1102] | 2841 | public void clearObservers()
|
---|
| 2842 | {
|
---|
[214] | 2843 | for (FrameObserver fl : _observers) {
|
---|
| 2844 | fl.removeSubject(this);
|
---|
| 2845 | }
|
---|
[1102] | 2846 |
|
---|
[238] | 2847 | // The frame listener will call the frames removeListener method
|
---|
| 2848 | assert (_observers.size() == 0);
|
---|
[214] | 2849 | }
|
---|
| 2850 |
|
---|
[1102] | 2851 | public Collection<Text> getNonAnnotationText(boolean removeTitle)
|
---|
| 2852 | {
|
---|
[214] | 2853 | Collection<Text> items = new LinkedHashSet<Text>();
|
---|
[1102] | 2854 |
|
---|
[1415] | 2855 | for (Item i : getSortedItems(true)) {
|
---|
[214] | 2856 | // only add up normal body text items
|
---|
| 2857 | if (i instanceof Text && !i.isAnnotation()) {
|
---|
| 2858 | items.add((Text) i);
|
---|
| 2859 | }
|
---|
| 2860 | }
|
---|
[1102] | 2861 |
|
---|
[214] | 2862 | if (removeTitle) {
|
---|
| 2863 | items.remove(getTitleItem());
|
---|
| 2864 | }
|
---|
[1102] | 2865 |
|
---|
[214] | 2866 | return items;
|
---|
| 2867 | }
|
---|
[238] | 2868 |
|
---|
[1434] | 2869 | @Deprecated
|
---|
| 2870 | public void disposeDeprecated() {
|
---|
[214] | 2871 | clearObservers();
|
---|
[1102] | 2872 |
|
---|
[238] | 2873 | for (Item i : _body) {
|
---|
[214] | 2874 | i.dispose();
|
---|
| 2875 | }
|
---|
[1102] | 2876 |
|
---|
[214] | 2877 | _frameName.dispose();
|
---|
| 2878 | _body = null;
|
---|
| 2879 | _frameName = null;
|
---|
[199] | 2880 | }
|
---|
[1434] | 2881 |
|
---|
| 2882 | /**
|
---|
| 2883 | * Disposes off all references associated with this frame.
|
---|
| 2884 | * This operation is NOT REVERSEABLE through the history.
|
---|
| 2885 | */
|
---|
| 2886 | public void dispose() {
|
---|
| 2887 | clearObservers();
|
---|
| 2888 |
|
---|
| 2889 | List<Item> allFrameItems = getAllFrameItemsRaw();
|
---|
| 2890 |
|
---|
| 2891 | for (Item i: allFrameItems) {
|
---|
| 2892 | i.dispose();
|
---|
| 2893 | }
|
---|
[286] | 2894 |
|
---|
[1434] | 2895 | _frameName.dispose();
|
---|
| 2896 | _frameName = null;
|
---|
| 2897 | getBody(false).clear();
|
---|
| 2898 | getPrimaryBody().clear();
|
---|
| 2899 | getSurrogateBody().clear();
|
---|
| 2900 | }
|
---|
| 2901 |
|
---|
[1102] | 2902 | public void parse()
|
---|
| 2903 | {
|
---|
[294] | 2904 | for (Overlay o : getOverlays()) {
|
---|
[286] | 2905 | o.Frame.parse();
|
---|
| 2906 | }
|
---|
[1102] | 2907 |
|
---|
[294] | 2908 | // Must parse the frame AFTER the overlays
|
---|
[286] | 2909 | FrameUtils.Parse(this);
|
---|
| 2910 | }
|
---|
[298] | 2911 |
|
---|
[1102] | 2912 | public void setPath(String path)
|
---|
| 2913 | {
|
---|
[298] | 2914 | this.path = path;
|
---|
| 2915 | }
|
---|
| 2916 |
|
---|
[1102] | 2917 | public String getPath()
|
---|
| 2918 | {
|
---|
[298] | 2919 | return path;
|
---|
| 2920 | }
|
---|
| 2921 |
|
---|
[1102] | 2922 | public void setLocal(boolean isLocal)
|
---|
| 2923 | {
|
---|
[298] | 2924 | this._isLocal = isLocal;
|
---|
| 2925 | }
|
---|
| 2926 |
|
---|
[1102] | 2927 | public boolean isLocal()
|
---|
| 2928 | {
|
---|
[298] | 2929 | return _isLocal;
|
---|
| 2930 | }
|
---|
[311] | 2931 |
|
---|
[1102] | 2932 | public String getExportFileTagValue()
|
---|
| 2933 | {
|
---|
[311] | 2934 | return getAnnotationValue("file");
|
---|
| 2935 | }
|
---|
[336] | 2936 |
|
---|
[1102] | 2937 | public void assertEquals(Frame frame2)
|
---|
| 2938 | {
|
---|
[336] | 2939 | // Check that all the items on the frame are the same
|
---|
| 2940 | List<Item> items1 = getVisibleItems();
|
---|
| 2941 | List<Item> items2 = frame2.getVisibleItems();
|
---|
[1102] | 2942 |
|
---|
[336] | 2943 | if (items1.size() != items2.size()) {
|
---|
[1102] | 2944 | throw new UnitTestFailedException(items1.size() + " items", items2.size() + " items");
|
---|
[336] | 2945 | } else {
|
---|
| 2946 | for (int i = 0; i < items1.size(); i++) {
|
---|
| 2947 | Item i1 = items1.get(i);
|
---|
| 2948 | Item i2 = items2.get(i);
|
---|
| 2949 | String s1 = i1.getText();
|
---|
| 2950 | String s2 = i2.getText();
|
---|
| 2951 | if (!s1.equals(s2)) {
|
---|
| 2952 | throw new UnitTestFailedException(s1, s2);
|
---|
| 2953 | }
|
---|
| 2954 | }
|
---|
| 2955 | }
|
---|
| 2956 | }
|
---|
[376] | 2957 |
|
---|
[1102] | 2958 | public boolean hasObservers()
|
---|
| 2959 | {
|
---|
[376] | 2960 | return _observers != null && _observers.size() > 0;
|
---|
| 2961 | }
|
---|
[1200] | 2962 |
|
---|
[1415] | 2963 | public Collection<Item> getBodyItemsWithInsufficientPermissions() {
|
---|
[1460] | 2964 | return _bodyHiddenDueToPermissions.cloneList();
|
---|
[1200] | 2965 | }
|
---|
| 2966 |
|
---|
| 2967 | public void moveItemToBodyHiddenDueToPermission(final Item i) {
|
---|
[1434] | 2968 | getBody(true).remove(i);
|
---|
[1200] | 2969 | _bodyHiddenDueToPermissions.add(i);
|
---|
| 2970 | }
|
---|
[1217] | 2971 |
|
---|
[1402] | 2972 | public void moveItemFromBodyHiddenDueToPermission(Item i, PermissionTriple newPermission) {
|
---|
[1217] | 2973 | if (_bodyHiddenDueToPermissions.contains(i)) {
|
---|
| 2974 | _bodyHiddenDueToPermissions.remove(i);
|
---|
| 2975 | i.setPermission(newPermission);
|
---|
[1434] | 2976 | getBody(true).add(i);
|
---|
[1217] | 2977 | }
|
---|
| 2978 | }
|
---|
[424] | 2979 |
|
---|
[1227] | 2980 | public Collection<? extends Item> getInteractableItems() {
|
---|
[424] | 2981 | /*
|
---|
| 2982 | * TODO: Cache the interactableItems list so we dont have to recreate it
|
---|
| 2983 | * every time this method is called
|
---|
| 2984 | */
|
---|
[1181] | 2985 | if (_interactableItems.size() > 0) {
|
---|
| 2986 | return _interactableItems;
|
---|
| 2987 | }
|
---|
[424] | 2988 |
|
---|
[1434] | 2989 | for (Item i : getBody(false)) {
|
---|
[1181] | 2990 | if (i == null) {
|
---|
| 2991 | continue;
|
---|
| 2992 | }
|
---|
[424] | 2993 | if (i.isVisible()) {
|
---|
| 2994 | _interactableItems.add(i);
|
---|
[1426] | 2995 | } else {
|
---|
| 2996 | Collection<? extends XRayable> enclosures = i.getEnclosures();
|
---|
| 2997 | if (enclosures != null && !enclosures.isEmpty()) {
|
---|
| 2998 | Iterator<? extends XRayable> iterator = enclosures.iterator();
|
---|
| 2999 | while (iterator.hasNext()) {
|
---|
| 3000 | _interactableItems.add(iterator.next());
|
---|
| 3001 | }
|
---|
| 3002 | }
|
---|
[424] | 3003 | }
|
---|
| 3004 | }
|
---|
| 3005 |
|
---|
| 3006 | for (Item i : _overlayItems) {
|
---|
[454] | 3007 | if (i.hasPermission(UserAppliedPermission.followLinks)) {
|
---|
[997] | 3008 | _interactableItems.add(i);
|
---|
[424] | 3009 | }
|
---|
| 3010 | }
|
---|
| 3011 |
|
---|
| 3012 | for (Item i : _vectorItems) {
|
---|
[454] | 3013 | if (i.hasPermission(UserAppliedPermission.none)) {
|
---|
[424] | 3014 | _interactableItems.add(i);
|
---|
| 3015 | }
|
---|
| 3016 | }
|
---|
| 3017 |
|
---|
| 3018 | return _interactableItems;
|
---|
| 3019 | }
|
---|
[1505] | 3020 |
|
---|
| 3021 | /** Encryption related functions start **/
|
---|
| 3022 | public String getFrameEncryptionLabel() {
|
---|
[1227] | 3023 | return _encryptionLabel;
|
---|
| 3024 | }
|
---|
| 3025 |
|
---|
[1508] | 3026 | public void setFrameEncryptionLabelOnLoad(String label) {
|
---|
| 3027 | _encryptionLabel = label;
|
---|
| 3028 | }
|
---|
| 3029 |
|
---|
[1505] | 3030 | public void setFrameEncryptionLabel(String label) {
|
---|
[1508] | 3031 | if (label == null || label.equals(EncryptedExpWriter.getLabelNone())) {
|
---|
| 3032 | _encryptionLabel = label;
|
---|
[1506] | 3033 | return;
|
---|
| 3034 | }
|
---|
| 3035 |
|
---|
| 3036 | String errorMessage = "You do not have sufficient permissions to set the encryption label to " + label + " on frame " + getName();
|
---|
| 3037 | UserAppliedEncryptionPermission p = getFrameEncryptionPermission().getPermission(this.getOwner(), this.getGroupMembers());
|
---|
| 3038 | String homogeneousEncryptionLabel = getHomogeneousEncryptionLabel();
|
---|
| 3039 | if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = getFrameEncryptionLabel(); }
|
---|
[1509] | 3040 | if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = EncryptedExpWriter.getLabelNone(); }
|
---|
[1506] | 3041 | List<String> hetrogeneousFrameOwnerLabels = getHetrogeneousFrameOwnerLabels();
|
---|
| 3042 |
|
---|
| 3043 | switch (p) {
|
---|
| 3044 | case none:
|
---|
[1507] | 3045 | MessageBay.errorMessage(errorMessage);
|
---|
[1506] | 3046 | return;
|
---|
| 3047 | case homogeneous:
|
---|
| 3048 | if (!homogeneousEncryptionLabel.equals(label)) {
|
---|
[1507] | 3049 | MessageBay.errorMessage(errorMessage);
|
---|
[1506] | 3050 | return;
|
---|
| 3051 | }
|
---|
| 3052 | break;
|
---|
| 3053 | case hetrogeneous_owner:
|
---|
| 3054 | if (!homogeneousEncryptionLabel.equals(label) && !hetrogeneousFrameOwnerLabels.contains(label)) {
|
---|
[1507] | 3055 | MessageBay.errorMessage(errorMessage);
|
---|
[1506] | 3056 | return;
|
---|
| 3057 | }
|
---|
| 3058 | break;
|
---|
| 3059 | case hetrogeneous: break;
|
---|
| 3060 | }
|
---|
| 3061 |
|
---|
[1477] | 3062 | LabelInfo labelResult = Label.getLabel(label);
|
---|
| 3063 | boolean isProfileOrNone = label.equals("Profile") || label.equals("None");
|
---|
| 3064 | if (!isProfileOrNone && !labelResult.is(LabelResult.SuccessResolveLabelToKey)) {
|
---|
| 3065 | MessageBay.displayMessage(labelResult.toString());
|
---|
| 3066 | this._encryptionLabel = null;
|
---|
| 3067 | return;
|
---|
| 3068 | }
|
---|
| 3069 |
|
---|
[1333] | 3070 | this.setChanged(true);
|
---|
[1227] | 3071 | _encryptionLabel = label;
|
---|
| 3072 | }
|
---|
[1506] | 3073 |
|
---|
| 3074 | public boolean hasEncryptionPermissionOrHigher(UserAppliedEncryptionPermission permissionLevel) {
|
---|
| 3075 | UserAppliedEncryptionPermission p = getFrameEncryptionPermission().getPermission(this.getOwner(), this.getGroupMembers());
|
---|
| 3076 | return p.ordinal() >= permissionLevel.ordinal();
|
---|
| 3077 | }
|
---|
[1374] | 3078 |
|
---|
[1505] | 3079 | public EncryptionPermissionTriple getFrameEncryptionPermission() {
|
---|
[1506] | 3080 | if (_frameEncryptionPermission == null) {
|
---|
| 3081 | _frameEncryptionPermission = EncryptionPermissionTriple.convertString("300");
|
---|
| 3082 | }
|
---|
[1505] | 3083 | return _frameEncryptionPermission;
|
---|
| 3084 | }
|
---|
| 3085 |
|
---|
| 3086 | public void setFrameEncryptionPermission(EncryptionPermissionTriple p) {
|
---|
| 3087 | _frameEncryptionPermission = p;
|
---|
| 3088 | }
|
---|
| 3089 |
|
---|
| 3090 | public String getHomogeneousEncryptionLabel() {
|
---|
| 3091 | return _homogeneousEncryptionLabel;
|
---|
| 3092 | }
|
---|
| 3093 |
|
---|
[1506] | 3094 | public List<String> getHetrogeneousFrameOwnerLabels() {
|
---|
| 3095 | if (_hetrogeneousEncryptionLabels == null) {
|
---|
| 3096 | _hetrogeneousEncryptionLabels = new ArrayList<String>();
|
---|
| 3097 | }
|
---|
| 3098 | return _hetrogeneousEncryptionLabels;
|
---|
| 3099 | }
|
---|
| 3100 |
|
---|
[1508] | 3101 | public void addToHetrogeneousFrameOwnerLabels(String label) {
|
---|
[1506] | 3102 | if (_hetrogeneousEncryptionLabels == null) {
|
---|
| 3103 | _hetrogeneousEncryptionLabels = new ArrayList<String>();
|
---|
| 3104 | }
|
---|
| 3105 | if (_hetrogeneousEncryptionLabels.contains(label)) {
|
---|
| 3106 | _hetrogeneousEncryptionLabels.remove(label);
|
---|
| 3107 | } else {
|
---|
| 3108 | _hetrogeneousEncryptionLabels.add(label);
|
---|
| 3109 | }
|
---|
| 3110 | }
|
---|
| 3111 |
|
---|
[1508] | 3112 | public void clearHetrogeneousFrameOwnerLabels() {
|
---|
| 3113 | if (_hetrogeneousEncryptionLabels != null) {
|
---|
| 3114 | _hetrogeneousEncryptionLabels.clear();
|
---|
| 3115 | }
|
---|
| 3116 | }
|
---|
| 3117 |
|
---|
| 3118 | public void setHomogeneousEncryptionLabelOnLoad(String label) {
|
---|
| 3119 | this.setChanged(true);
|
---|
| 3120 | _homogeneousEncryptionLabel = label;
|
---|
| 3121 | }
|
---|
| 3122 |
|
---|
[1505] | 3123 | public void setHomogeneousEncryptionLabel(String label) {
|
---|
| 3124 | LabelInfo labelResult = Label.getLabel(label);
|
---|
| 3125 | boolean isProfileOrNone = label.equals("Profile") || label.equals("None");
|
---|
| 3126 | if (!isProfileOrNone && !labelResult.is(LabelResult.SuccessResolveLabelToKey)) {
|
---|
| 3127 | MessageBay.displayMessage(labelResult.toString());
|
---|
[1506] | 3128 | MessageBay.displayMessage("You will not be able to set the FrameEncryptionLabel to the Homogeneous Label.");
|
---|
[1505] | 3129 | }
|
---|
| 3130 |
|
---|
| 3131 | this.setChanged(true);
|
---|
| 3132 | _homogeneousEncryptionLabel = label;
|
---|
| 3133 | }
|
---|
| 3134 |
|
---|
[1374] | 3135 | public EncryptionPermissionTriple getEncryptionPermission() {
|
---|
[1509] | 3136 | if (_itemEncryptionPermission == null) {
|
---|
| 3137 | _itemEncryptionPermission = EncryptionPermissionTriple.convertString("300");
|
---|
| 3138 | }
|
---|
[1505] | 3139 | return _itemEncryptionPermission;
|
---|
[1374] | 3140 | }
|
---|
| 3141 |
|
---|
| 3142 | public void setEncryptionPermission(EncryptionPermissionTriple p) {
|
---|
[1505] | 3143 | _itemEncryptionPermission = p;
|
---|
[1374] | 3144 | }
|
---|
[1505] | 3145 | /** Encryption related functions end **/
|
---|
[1102] | 3146 |
|
---|
[1405] | 3147 | public String getGroup() {
|
---|
| 3148 | return _groupFrameName;
|
---|
| 3149 | }
|
---|
| 3150 |
|
---|
| 3151 | public void setGroup(String _groupFrame) {
|
---|
| 3152 | this._groupFrameName = _groupFrame;
|
---|
| 3153 | this._groupFrame = null;
|
---|
| 3154 | }
|
---|
| 3155 |
|
---|
| 3156 | public Frame getGroupFrame() {
|
---|
| 3157 | if (this._groupFrame != null) {
|
---|
| 3158 | return this._groupFrame;
|
---|
[1489] | 3159 | } else if (this._groupFrameName != null){
|
---|
[1406] | 3160 | this._groupFrame = FrameIO.LoadFrame(this._groupFrameName + 1, FrameIO.GROUP_PATH);
|
---|
[1405] | 3161 | return this._groupFrame;
|
---|
[1489] | 3162 | } else {
|
---|
| 3163 | return null;
|
---|
[1405] | 3164 | }
|
---|
| 3165 | }
|
---|
| 3166 |
|
---|
| 3167 | public void setGroupFrame(Frame frame) {
|
---|
| 3168 | this._groupFrame = frame;
|
---|
| 3169 | }
|
---|
[1407] | 3170 |
|
---|
| 3171 | public List<String> getGroupMembers() {
|
---|
| 3172 | List<String> members = new ArrayList<String>();
|
---|
| 3173 | if (getGroupFrame() != null) {
|
---|
| 3174 | Collection<Text> textItems = getGroupFrame().getTextItems();
|
---|
[1508] | 3175 | String membersTag = "@members: ";
|
---|
[1407] | 3176 | Stream<Text> memberLists = textItems.stream().filter(t ->
|
---|
| 3177 | t.getText().toLowerCase().startsWith("@owner: ") ||
|
---|
[1508] | 3178 | t.getText().toLowerCase().startsWith(membersTag));
|
---|
[1407] | 3179 | for(Text t: memberLists.collect(Collectors.toList())) {
|
---|
| 3180 | if (t.getText().toLowerCase().startsWith("@owner: ")) {
|
---|
| 3181 | members.add(t.getText().substring(8));
|
---|
[1508] | 3182 | } else if (t.getText().toLowerCase().startsWith(membersTag)) {
|
---|
| 3183 | String[] split = t.getText().substring(membersTag.length()).split(",");
|
---|
[1407] | 3184 | for (String m: split) {
|
---|
| 3185 | members.add(m.trim());
|
---|
| 3186 | }
|
---|
| 3187 | }
|
---|
| 3188 | }
|
---|
| 3189 | }
|
---|
| 3190 | return members;
|
---|
| 3191 | }
|
---|
[1415] | 3192 |
|
---|
| 3193 | public boolean hasSurrogates() {
|
---|
| 3194 | return !_surrogateItemsBody.isEmpty();
|
---|
| 3195 | }
|
---|
[1405] | 3196 |
|
---|
[1415] | 3197 | private boolean meetsVisibilityRequirements(boolean requireVisible, Item i) {
|
---|
| 3198 | return i.isVisible() || (!requireVisible && !i.isDeleted());
|
---|
| 3199 | }
|
---|
| 3200 |
|
---|
[1102] | 3201 | private static final class History {
|
---|
| 3202 |
|
---|
| 3203 | public enum Type {
|
---|
| 3204 | deletion,
|
---|
| 3205 | movement
|
---|
| 3206 | }
|
---|
| 3207 |
|
---|
[1415] | 3208 | public final ItemsList items;
|
---|
[1102] | 3209 |
|
---|
| 3210 | public final Type type;
|
---|
[1450] | 3211 |
|
---|
| 3212 | public final boolean undoDeleteAssociatedFiles;
|
---|
[1102] | 3213 |
|
---|
[1450] | 3214 | public History(ItemsList changed, Type type, boolean undoDeleteAssociatedFiles)
|
---|
[1102] | 3215 | {
|
---|
[1450] | 3216 | this.undoDeleteAssociatedFiles = undoDeleteAssociatedFiles;
|
---|
[1415] | 3217 | this.items = new ItemsList(changed);
|
---|
[1102] | 3218 | this.type = type;
|
---|
| 3219 | }
|
---|
| 3220 |
|
---|
[1181] | 3221 | @Override
|
---|
[1102] | 3222 | public String toString()
|
---|
| 3223 | {
|
---|
| 3224 | return this.type.toString() + ":\n" + this.items.toString();
|
---|
| 3225 | }
|
---|
| 3226 | }
|
---|
[1415] | 3227 |
|
---|
| 3228 | protected boolean hasAnnotations() {
|
---|
| 3229 | return _annotations != null && _annotations.size() > 0;
|
---|
| 3230 | }
|
---|
| 3231 |
|
---|
[1434] | 3232 | public ItemsList getBody(boolean respectSurrogateMode) {
|
---|
| 3233 | if (respectSurrogateMode) { ensureBody(); }
|
---|
[1415] | 3234 | return _body;
|
---|
| 3235 | }
|
---|
[1434] | 3236 |
|
---|
| 3237 | private void ensureBody() {
|
---|
| 3238 | List<String> accessibleLabelsNames = Label.getAccessibleLabelsNames(getPrimaryBody());
|
---|
| 3239 | if (!accessibleLabelsNames.equals(labelsOnLastBodySet)) {
|
---|
| 3240 | this.parse();
|
---|
| 3241 | }
|
---|
| 3242 | }
|
---|
| 3243 |
|
---|
| 3244 | protected void setBody(List<Item> newBody, List<String> labelsOnSet) {
|
---|
| 3245 | _body.clear();
|
---|
| 3246 | _body.addAll(newBody);
|
---|
| 3247 | this.labelsOnLastBodySet = labelsOnSet;
|
---|
| 3248 | }
|
---|
| 3249 |
|
---|
[1480] | 3250 | public ItemsList getPrimaryBody() {
|
---|
[1415] | 3251 | return _primaryItemsBody;
|
---|
| 3252 | }
|
---|
[1502] | 3253 | public ItemsList getSurrogateBody() {
|
---|
[1415] | 3254 | return _surrogateItemsBody;
|
---|
| 3255 | }
|
---|
[1434] | 3256 |
|
---|
| 3257 |
|
---|
| 3258 | /**
|
---|
| 3259 | * Gets all the items on the frame, regardless of whether they are primary or surrogate items.
|
---|
| 3260 | *
|
---|
| 3261 | * Bryce says: This function will likely only ever be used inside Frame itself, as callers from
|
---|
| 3262 | * outside Frame should care about what the state of the Frame.
|
---|
| 3263 | * @return
|
---|
| 3264 | */
|
---|
| 3265 | private List<Item> getAllFrameItemsRaw() {
|
---|
[1460] | 3266 | List<Item> primaries = getPrimaryBody().cloneList();
|
---|
| 3267 | List<Item> surrogateBody = getSurrogateBody().cloneList();
|
---|
[1434] | 3268 | primaries.addAll(surrogateBody);
|
---|
| 3269 | List<Item> allFrameItems = primaries.stream().distinct().collect(Collectors.toList());
|
---|
| 3270 | return allFrameItems;
|
---|
| 3271 | }
|
---|
[4] | 3272 | }
|
---|