Changeset 156 for trunk/src/org/expeditee/gui/Frame.java
- Timestamp:
- 07/25/08 09:24:45 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/Frame.java
r154 r156 237 237 } 238 238 239 public List<Text> getVisibleTextItems() {240 List<Text> textItems = new ArrayList<Text>();241 for (Item i : getItems(true)) {242 // only add up normal body text items243 if (i instanceof Text) {244 textItems.add((Text) i);245 }246 }247 return textItems;248 }249 250 239 public List<Item> getItems() { 251 240 return getItems(false); … … 264 253 265 254 /** 266 * Gets a list of all the non annotation text items on the frame, excluding267 * the title and frame name.255 * Returns a list of all the non annotation text items on the frame which 256 * are not the title or frame name or special annotation items. 268 257 * 269 258 * @param includeAnnotations 270 * true if annotations should be included in the list 271 * @return list of text items 272 */ 273 public List<Text> getBodyTextItems(boolean includeAnnotations) { 274 return getBodyTextItems(includeAnnotations, false); 275 } 276 277 /** 278 * Returns a list of all the non annotation text items on the frame which 279 * are not the title or frame name. 280 * 259 * true if annotation items without special meaning should be 260 * included 281 261 * @param includeLineEnds 282 262 * true if text on the end of lines should be included in the … … 284 264 * @return the list of body text items. 285 265 */ 286 public List<Text> getBodyTextItems(boolean includeAnnotations, 287 boolean includeLineEnds) { 266 public List<Text> getBodyTextItems(boolean includeAnnotations) { 288 267 List<Text> bodyTextItems = new ArrayList<Text>(); 289 268 for (Item i : getItems(true)) { 290 269 // only add up normal body text items 291 270 if ((i instanceof Text) 292 && (includeAnnotations || !i.isAnnotation()) 293 && (includeLineEnds || !i.isLineEnd())) { 271 && ((includeAnnotations && !((Text) i) 272 .isSpecialAnnotation()) || !i.isAnnotation()) 273 && !i.isLineEnd()) { 294 274 bodyTextItems.add((Text) i); 295 275 } … … 617 597 public void resetDateCreated() { 618 598 setDateCreated(Logger.EasyDateFormat("ddMMMyyyy:HHmm")); 599 setActiveTime(new Time(0)); 600 setDarkTime(new Time(0)); 601 setVersion(0); 619 602 } 620 603 … … 662 645 if (item == null || item.equals(_frameName) || _body.contains(item)) 663 646 return; 647 648 // When an annotation item is anchored the annotation list must be 649 // refreshed 650 if (item.isAnnotation()) { 651 clearAnnotations(); 652 } 664 653 665 654 if (item instanceof Line) … … 706 695 if (anchorRight != null) { 707 696 i.setX(width - anchorRight); 708 if (i.hasVector()){697 if (i.hasVector()) { 709 698 bReparse = true; 710 699 } … … 712 701 if (anchorBottom != null) { 713 702 i.setY(height - anchorBottom); 714 if (i.hasVector()){703 if (i.hasVector()) { 715 704 bReparse = true; 716 705 } 717 706 } 718 707 } 719 if (bReparse){708 if (bReparse) { 720 709 FrameUtils.Parse(this, false); 721 710 } … … 725 714 726 715 public void addAllItems(Collection<Item> toAdd) { 727 for (Item i : toAdd) 716 for (Item i : toAdd) { 717 // If an annotation is being deleted clear the annotation list 718 if (i.isAnnotation()) 719 i.getParentOrCurrentFrame().clearAnnotations(); 728 720 addItem(i); 721 } 729 722 } 730 723 731 724 public void removeAllItems(Collection<Item> toRemove) { 732 for (Item i : toRemove) 725 for (Item i : toRemove) { 726 // If an annotation is being deleted clear the annotation list 727 if (i.isAnnotation()) 728 i.getParentOrCurrentFrame().clearAnnotations(); 733 729 removeItem(i); 730 } 734 731 } 735 732 736 733 public void removeItem(Item item) { 734 // If an annotation is being deleted clear the annotation list 735 if (item.isAnnotation()) 736 item.getParentOrCurrentFrame().clearAnnotations(); 737 737 738 if (_body.remove(item)) { 738 739 change(); … … 954 955 } 955 956 956 public Item getItemAbove(Item current) { 957 public Text getTextAbove(Text current) { 958 Collection<Text> currentTextItems = FrameUtils.getCurrentTextItems(); 959 List<Text> toCheck = new ArrayList<Text>(); 960 if (currentTextItems.contains(current)) { 961 toCheck.addAll(currentTextItems); 962 } else { 963 toCheck.addAll(getTextItems()); 964 } 957 965 // Make sure the items are sorted 958 Collections.sort(_body); 959 int ind = _body.indexOf(current); 966 Collections.sort(toCheck); 967 968 int ind = toCheck.indexOf(current); 960 969 if (ind == -1) 961 970 return null; … … 963 972 // loop through all items above this one, return the first match 964 973 for (int i = ind - 1; i >= 0; i--) { 965 Item check = _body.get(i);966 if ( check.isVisible() &&FrameUtils.inSameColumn(check, current))974 Text check = toCheck.get(i); 975 if (FrameUtils.inSameColumn(check, current)) 967 976 return check; 968 977 } … … 992 1001 * The Item to get the column for. 993 1002 */ 994 public List< Item> getColumn(Item from) {1003 public List<Text> getColumn(Item from) { 995 1004 // Check that this item is on the current frame 996 1005 if (!_body.contains(from)) 997 1006 return null; 998 1007 999 // Make sure the items are sorted1000 Collections.sort(_body);1001 1002 1008 if (from == null) { 1003 1009 from = getLastNonAnnotationTextItem(); … … 1007 1013 return null; 1008 1014 1009 List<Item> column = new ArrayList<Item>(); 1015 // Get the enclosedItems 1016 Collection<Text> enclosed = FrameUtils.getCurrentTextItems(); 1017 List<Text> toCheck = null; 1018 if (enclosed.contains(from)) { 1019 toCheck = new ArrayList<Text>(); 1020 toCheck.addAll(enclosed); 1021 } else { 1022 toCheck = getBodyTextItems(true); 1023 } 1024 1025 // Make sure the items are sorted 1026 Collections.sort(toCheck); 1027 1028 List<Text> column = new ArrayList<Text>(); 1010 1029 1011 1030 // Create a list of items consisting of the item 'from' and all the 1012 1031 // items below it which are also in the same column as it 1013 for (int i = _body.indexOf(from); i < _body.size(); i++) { 1014 Item item = _body.get(i); 1015 if (item.isVisible() && isNormalTextItem(item)) { 1016 if (FrameUtils.inSameColumn(from, item)) 1017 column.add(item); 1018 } 1032 for (int i = toCheck.indexOf(from); i < toCheck.size(); i++) { 1033 Text item = toCheck.get(i); 1034 if (FrameUtils.inSameColumn(from, item)) 1035 column.add(item); 1019 1036 } 1020 1037 … … 1314 1331 _body = newBody; 1315 1332 change(); 1333 1334 if (!keepAnnotations) 1335 _annotations.clear(); 1316 1336 } 1317 1337 … … 1352 1372 // Make it the width of the page 1353 1373 // t.setMaxWidth(FrameGraphics.getMaxFrameSize().width); 1354 // if (t.getWidth() <= 0) {1355 1356 // }1374 // if (t.getWidth() <= 0) { 1375 t.setRightMargin(FrameGraphics.getMaxFrameSize().width); 1376 // } 1357 1377 addItem(t); 1358 1378 return t; … … 1460 1480 && (FreeItems.getInstance().get(0) instanceof Line || FreeItems 1461 1481 .getInstance().get(1) instanceof Line); 1462 }1463 1464 public static boolean itemAttachedToCursor() {1465 return FreeItems.getInstance().size() > 0;1466 }1467 1468 public static boolean textItemAttachedToCursor() {1469 return itemAttachedToCursor()1470 && FreeItems.getInstance().get(0) instanceof Text;1471 }1472 1473 // TODO move this method to FreeItems1474 public static Item getItemAttachedToCursor() {1475 if (itemAttachedToCursor())1476 return FreeItems.getInstance().get(0);1477 1478 return null;1479 1482 } 1480 1483 … … 1548 1551 if (t.getText().equals("")) 1549 1552 DisplayIO.getCurrentFrame().removeItem(t); 1550 if (!Fr ame.itemAttachedToCursor()) {1553 if (!FreeItems.itemAttachedToCursor()) { 1551 1554 DisplayIO.setCursorPosition(((Text) it) 1552 1555 .getParagraphEndPosition()); … … 1710 1713 1711 1714 public void addAnnotation(Text item) { 1715 if (_annotations == null) { 1716 _annotations = new HashMap<String, Text>(); 1717 } 1712 1718 // Check if this item has already been processed 1713 1719 String[] tokens = item.getProcessedText(); … … 1755 1761 1756 1762 public boolean hasAnnotation(String annotation) { 1763 if (_annotations == null) 1764 refreshAnnotationList(); 1757 1765 return _annotations.containsKey(annotation.toLowerCase()); 1758 1766 } 1759 1767 1760 1768 public String getAnnotationValue(String annotation) { 1769 if (_annotations == null) 1770 refreshAnnotationList(); 1771 1761 1772 Text text = _annotations.get(annotation.toLowerCase()); 1762 1773 if (text == null) … … 1769 1780 } 1770 1781 1771 Map<String, Text> _annotations = n ew HashMap<String, Text>();1782 Map<String, Text> _annotations = null; 1772 1783 1773 1784 public void clearAnnotations() { 1774 _annotations .clear();1785 _annotations = null; 1775 1786 } 1776 1787 … … 1779 1790 } 1780 1791 1792 private void refreshAnnotationList() { 1793 if (_annotations == null) 1794 _annotations = new HashMap<String, Text>(); 1795 else 1796 _annotations.clear(); 1797 for (Text text : getTextItems()) { 1798 if (text.isAnnotation()) { 1799 addAnnotation(text); 1800 } 1801 } 1802 } 1803 1781 1804 public Collection<Text> getAnnotationItems() { 1805 if (_annotations == null) { 1806 refreshAnnotationList(); 1807 } 1782 1808 return _annotations.values(); 1783 1809 } … … 1851 1877 return vectorItems; 1852 1878 } 1879 1880 /** 1881 * Gets a list of all the text items on the frame. 1882 * 1883 * @return 1884 */ 1885 public Collection<Text> getTextItems() { 1886 Collection<Text> textItems = new ArrayList<Text>(); 1887 for (Item i : getItems(true)) { 1888 // only add up normal body text items 1889 if ((i instanceof Text)) { 1890 textItems.add((Text) i); 1891 } 1892 } 1893 return textItems; 1894 } 1853 1895 }
Note:
See TracChangeset
for help on using the changeset viewer.