Changeset 1102 for trunk/src/org/expeditee/gui/FreeItems.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/FreeItems.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Polygon;22 21 import java.util.ArrayList; 23 22 import java.util.Collection; … … 29 28 import java.util.Map; 30 29 30 import org.expeditee.core.bounds.PolygonBounds; 31 31 import org.expeditee.items.Dot; 32 32 import org.expeditee.items.Item; … … 42 42 private static FreeItems _cursor = new FreeItems(); 43 43 44 private FreeItems() { 45 } 46 47 public static FreeItems getCursor() { 44 public static FreeItems getCursor() 45 { 48 46 return _cursor; 49 47 } 50 48 51 public static FreeItems getInstance() { 49 public static FreeItems getInstance() 50 { 52 51 return _instance; 53 52 } 54 53 55 @Override 56 public void clear() { 54 /** Singleton class (although there are two of them). */ 55 private FreeItems() 56 { 57 } 58 59 @Override 60 public void clear() 61 { 57 62 for (Item i : this) { 58 63 i.invalidateAll(); … … 63 68 64 69 @Override 65 public Item remove(int index) { 70 public Item remove(int index) 71 { 66 72 Item i = get(index); 67 73 remove(i); … … 70 76 71 77 @Override 72 public boolean remove(Object o) { 78 public boolean remove(Object o) 79 { 73 80 if (o instanceof Item) { 74 81 ((Item) o).invalidateAll(); 75 82 ((Item) o).invalidateFill(); 76 83 } 84 77 85 return super.remove(o); 78 86 } … … 84 92 * @return true if at least one item is attached to the cursor. 85 93 */ 86 public static boolean itemsAttachedToCursor() { 94 public static boolean hasItemsAttachedToCursor() 95 { 87 96 return getInstance().size() > 0; 88 97 } … … 94 103 * attached are text items. 95 104 */ 96 public static boolean textOnlyAttachedToCursor() {97 if (!itemsAttachedToCursor())98 99 for (Item i : getInstance()) {100 if (!(i instanceof Text)) {101 102 103 }105 public static boolean textOnlyAttachedToCursor() 106 { 107 if (!hasItemsAttachedToCursor()) return false; 108 109 for (Item i : getInstance()) { 110 if (!(i instanceof Text)) return false; 111 } 112 104 113 return true; 105 114 } 106 115 107 public static Item getItemAttachedToCursor() { 108 if (itemsAttachedToCursor()) 109 return getInstance().get(0); 116 public static Item getItemAttachedToCursor() 117 { 118 if (hasItemsAttachedToCursor()) return getInstance().get(0); 119 110 120 return null; 111 121 } 112 122 113 public static Text getTextAttachedToCursor() { 114 if (textOnlyAttachedToCursor()) 115 return (Text) getInstance().get(0); 123 public static Text getTextAttachedToCursor() 124 { 125 if (textOnlyAttachedToCursor()) return (Text) getInstance().get(0); 126 116 127 return null; 117 128 } … … 121 132 * @return the list of free text items 122 133 */ 123 public static Collection<Text> getTextItems() { 134 public static Collection<Text> getTextItems() 135 { 124 136 Collection<Text> textItems = new LinkedList<Text>(); 125 for (Item i : getInstance()) { 126 if (i instanceof Text) { 127 textItems.add((Text) i); 128 } 137 138 for (Item i : getInstance()) { 139 if (i instanceof Text) textItems.add((Text) i); 129 140 } 130 141 … … 132 143 } 133 144 134 public static Map<String, Collection<String>> getGroupedText() { 145 public static Map<String, Collection<String>> getGroupedText() 146 { 135 147 Map<String, Collection<String>> groupedText = new HashMap<String, Collection<String>>(); 148 136 149 // Go throught the lineEnds 137 150 Collection<Item> addedItems = new HashSet<Item>(); 138 151 for (Item i : getInstance()) { 139 if (!(i instanceof Text) || !i.isLineEnd()) { 140 continue; 141 } 152 if (!(i instanceof Text) || !i.isLineEnd()) continue; 153 142 154 // Check for text inside the box 143 155 Collection<String> textList = new LinkedList<String>(); … … 146 158 addedItems.add(enclosed); 147 159 } 160 148 161 if (textList.size() > 0) { 149 162 groupedText.put(i.getText(), textList); 150 163 } 151 164 } 165 152 166 // Now add the items that were not contained in any of the boxes 153 167 Collection<String> outsideList = new LinkedList<String>(); … … 157 171 } 158 172 } 173 159 174 groupedText.put("", outsideList); 160 175 … … 169 184 * @return 170 185 */ 171 private Collection<Text> getTextWithin(Item lineEnd) { 172 Polygon poly = lineEnd.getEnclosedShape(); 186 private Collection<Text> getTextWithin(Item lineEnd) 187 { 188 PolygonBounds poly = lineEnd.getEnclosedShape(); 189 173 190 Collection<Text> results = new LinkedHashSet<Text>(); 174 191 for (Item i : this) { … … 177 194 } 178 195 } 196 179 197 return results; 180 198 } 181 199 182 public static boolean hasCursor() { 200 public static boolean hasCursor() 201 { 183 202 return getCursor().size() > 0; 184 203 } 185 204 186 public static void setCursor(Collection<Item> cursor) { 205 public static void setCursor(Collection<Item> cursor) 206 { 187 207 _cursor.clear(); 188 208 _cursor.addAll(cursor); 189 209 } 190 210 191 public static boolean hasMultipleVisibleItems() { 211 public static boolean hasMultipleVisibleItems() 212 { 192 213 List<Item> toCount = new LinkedList<Item>(getInstance()); 214 193 215 int c = 0; 194 216 while(!toCount.isEmpty()) { … … 199 221 } 200 222 } 223 201 224 return false; 202 225 } 203 226 204 public static boolean isDrawingPolyLine() { 227 public static boolean isDrawingPolyLine() 228 { 205 229 List<Item> tmp = getInstance(); 230 206 231 return tmp.size() == 2 && tmp.get(0) instanceof Dot && tmp.get(1) instanceof Line; 207 232 } 233 234 /** 235 * Checks if lines are being rubber banded. 236 * 237 * @return true if the user is rubberBanding one or more lines 238 */ 239 public static boolean rubberBanding() 240 { 241 if (getInstance().size() != 2) return false; 242 243 // if rubber-banding, there will be 1 line end and the rest will be lines 244 boolean foundLineEnd = false; 245 for (Item i : getInstance()) { 246 if (i.isLineEnd()) { 247 if (foundLineEnd) return false; 248 foundLineEnd = true; 249 } else if (!(i instanceof Line) || !i.isVisible()) { 250 return false; 251 } 252 } 253 254 return true; 255 } 256 257 @Override 258 public FreeItems clone() 259 { 260 FreeItems ret = new FreeItems(); 261 ret.addAll(this); 262 return ret; 263 } 208 264 }
Note:
See TracChangeset
for help on using the changeset viewer.