Changeset 108 for trunk/src/org/expeditee/items/Item.java
- Timestamp:
- 06/27/08 16:44:21 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Item.java
r107 r108 9 9 import java.awt.Polygon; 10 10 import java.awt.Rectangle; 11 import java.awt.Stroke; 11 12 import java.awt.geom.AffineTransform; 12 13 import java.awt.geom.Area; 14 import java.awt.geom.Point2D; 15 import java.awt.geom.Rectangle2D; 13 16 import java.util.ArrayList; 14 17 import java.util.Collection; 15 18 import java.util.ConcurrentModificationException; 19 import java.util.HashSet; 16 20 import java.util.LinkedHashSet; 17 21 import java.util.LinkedList; … … 39 43 public abstract class Item implements Comparable<Item>, Runnable { 40 44 45 public static final Float DEFAULT_THICKNESS = 2f; 46 47 public static final Float MINIMUM_THICKNESS = 1f; 48 41 49 protected final int JOIN = BasicStroke.JOIN_ROUND; 42 50 43 51 protected final int CAP = BasicStroke.CAP_BUTT; 44 52 53 protected final Stroke HIGHLIGHT_STROKE = new BasicStroke( 54 MINIMUM_THICKNESS, CAP, JOIN, 4.0F); 55 45 56 // contains all dots (including this one) that form an enclosure 46 57 // if this dot is part of an enclosing shape … … 49 60 public static final int LEFT_MARGIN = 13; 50 61 62 // indicates which end the arrowhead should be drawn at 63 protected Polygon _poly = null; 64 51 65 protected boolean _connectedToAnnotation = false; 52 53 public static final int PERMISSION_NONE = 0;54 55 public static final int PERMISSION_FOLLOW_LINKS = 1;56 57 public static final int PERMISSION_COPY = 2;58 59 public static final int PERMISSION_TDFC = 3;60 61 public static final int PERMISSION_FULL = 4;62 66 63 67 public static final int NEAR_DISTANCE = 15; … … 103 107 * this Item. 104 108 */ 105 public static Color[] COLOR_WHEEL = { Color. RED, Color.BLUE, Item.GREEN,106 Color.MAGENTA, Color.YELLOW.darker(), Color.BLACK, Color.DARK_GRAY,107 Color.GRAY, Color.WHITE, null }; 108 109 public static Color[] COLOR_WHEEL = { Color.BLACK, Color.RED, Color.BLUE, 110 Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(), Color.WHITE }; 111 112 // TODO Have shift toggle through a black and white color wheel? 109 113 public static Color[] FILL_COLOR_WHEEL = { new Color(255, 150, 150), 110 114 new Color(150, 150, 255), new Color(150, 255, 150), 111 115 new Color(255, 150, 255), new Color(255, 255, 100), Color.WHITE, 112 Color.GRAY, Color.DARK_GRAY, Color.BLACK, null }; 116 Color.BLACK}; 117 /* Color.GRAY, 118 * Color.DARK_GRAY, 119 */ 113 120 114 121 public static final int UNCHANGED_CURSOR = -100; … … 167 174 168 175 dest.setParent(source.getParent()); 169 dest._mode = SelectedMode.None; 170 dest._lastMode = source._mode; 171 176 dest._mode = source._mode;// SelectedMode.None; 177 dest._visible = source._visible; 172 178 Frame parent = source.getParentOrCurrentFrame(); 173 179 // TODO MIKE says maybe we could tighten up and only give items ID's if … … 199 205 private Point _offset = new Point(0, 0); 200 206 201 pr ivatefloat _x;202 203 pr ivatefloat _y;207 protected float _x; 208 209 protected float _y; 204 210 205 211 private int _id; … … 229 235 private List<String> _actionLeaveFrame = null; 230 236 231 public int Permission = PERMISSION_FULL; 237 public Permission _permission = Permission.full; 238 239 public void setPermission(Permission permission){ 240 _permission = permission; 241 } 242 243 public boolean hasPermission(Permission permission){ 244 return _permission.ordinal() >= permission.ordinal(); 245 } 232 246 233 247 // A fill color of null represents transparent … … 256 270 257 271 // arrowhead parameters 258 private int _arrowheadLength = 0;272 private float _arrowheadLength = 0; 259 273 260 274 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO; … … 283 297 284 298 private boolean _visible = true; 285 286 private SelectedMode _lastMode = SelectedMode.None;287 299 288 300 private float _thickness = -1.0F; … … 303 315 } 304 316 305 if (_actions == null) 317 if (_actions == null){ 318 _poly = null; 306 319 _actions = new LinkedList<String>(); 320 } 307 321 _actions.add(action); 308 322 } … … 312 326 connected.add(this); 313 327 314 for ( Line line : getLines()) {315 if (!connected.contains( line))316 line.addAllConnected(connected);328 for (Item item : getConnected()) { 329 if (!connected.contains(item)) 330 item.addAllConnected(connected); 317 331 } 318 332 } … … 383 397 384 398 public void delete() { 385 setVisible(false); 386 } 387 399 _deleted = true; 400 } 401 402 @Override 388 403 public boolean equals(Object o) { 389 if (o instanceof Item) { 404 if (o == null) 405 return false; 406 if (getClass().equals(o.getClass())) { 390 407 Item i = (Item) o; 391 408 return i.getID() == getID() 392 409 && ((i.getParent() == _parent) || (i.getParent() != null && i 393 410 .getParent().equals(_parent))); 394 395 411 } else 396 412 return false; … … 463 479 } 464 480 465 public int getArrowheadLength() {481 public float getArrowheadLength() { 466 482 return _arrowheadLength; 467 483 } … … 559 575 List<Item> conn = new LinkedList<Item>(); 560 576 conn.add(this); 561 577 conn.addAll(getEnclosures()); 562 578 conn.addAll(getLines()); 563 579 return conn; … … 698 714 699 715 public Color getPaintBackgroundColor() { 700 if (_colorBackground == null) { 716 Color colorBackground = getBackgroundColor(); 717 if (colorBackground == null) { 701 718 if (getParent() != null && getParent().getBackgroundColor() != null) 702 719 return getParent().getBackgroundColor(); … … 705 722 } 706 723 707 return _colorBackground;724 return colorBackground; 708 725 } 709 726 … … 713 730 * @return The Color of this item (foreground) 714 731 */ 715 public Color getPaintColor() {732 public final Color getPaintColor() { 716 733 // If color is null then get the paint foregroundColor for the frame the 717 734 // item is on which is a color adjusted to suit the background 718 if (_color == null) { 735 Color color = getColor(); 736 737 if (color == null) { 719 738 if (getParent() != null) 720 739 return getParent().getPaintForegroundColor(); … … 727 746 } 728 747 729 return _color;748 return color; 730 749 } 731 750 … … 739 758 } 740 759 741 public Frame getParent() {760 public final Frame getParent() { 742 761 return _parent; 743 762 } 744 763 745 /** 746 * Returns the Shape that surrounds this Item representing this Item's 747 * 'gravity'. 748 * 749 * @return The Shape (rectangle) surrounding this Item, which represents 750 * this Items 'gravity'. 751 */ 752 public abstract Polygon getPolygon(); 753 754 public Point getPosition() { 764 public final Point getPosition() { 755 765 return new Point(getX(), getY()); 756 766 } … … 762 772 * @return The size of this Item. 763 773 */ 764 public int getSize() {765 return -1 ;774 public float getSize() { 775 return -1.0F; 766 776 } 767 777 … … 809 819 /** 810 820 * Checks if the given Shape intersects with the Shape around this Item. 811 * Note: Both Shape objects should be rectangles for this to work properly.812 821 * 813 822 * @param s … … 819 828 return false; 820 829 821 // return p.getBounds().intersects(getArea().getBounds());822 830 Area a = new Area(p); 823 824 831 a.intersect(this.getArea()); 832 825 833 return !a.isEmpty(); 826 834 } … … 859 867 */ 860 868 public boolean isHighlighted() { 869 if (isFloating()) 870 return false; 861 871 return _mode != SelectedMode.None; 862 872 } … … 917 927 918 928 public void paintFill(Graphics2D g) { 919 if (getFillColor() != null && getEnclosingDots() != null) { 920 g.setColor(getFillColor()); 929 Color fillColor = getFillColor(); 930 if (fillColor != null && getEnclosingDots() != null) { 931 if(isFloating()){ 932 //TODO experiment with adding alpha when picking up filled items... 933 //Slows things down quite alot!! 934 fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue()); 935 } 936 g.setColor(fillColor); 921 937 // The painting is not efficient enough for gradients... 922 938 // Shape s = getEnclosedShape(); … … 1021 1037 // Check if all the characters are digits and hence it is a relative 1022 1038 // link 1023 for (int i = 0; i < link.length(); i++) { 1024 if (!Character.isDigit(link.charAt(i))) 1025 return; 1026 } 1039 if(!FrameIO.isPositiveInteger(link)) 1040 return; 1027 1041 1028 1042 // Make it an absolute link … … 1038 1052 1039 1053 /** 1040 * Sets any action code (KMS action language)that should be associated with1054 * Sets any action code that should be associated with 1041 1055 * this Item Each entry in the list is one line of code 1042 1056 * … … 1045 1059 */ 1046 1060 public void setActions(List<String> actions) { 1061 //Want to resize the highlight box for text items if actions have been added 1062 _poly = null; 1047 1063 if (actions == null || actions.size() == 0) 1048 1064 _actions = null; … … 1075 1091 1076 1092 public void setActionMark(boolean val) { 1093 _poly = null; 1077 1094 _actionMark = val; 1078 1095 } … … 1096 1113 * The ratio of the arrow's length to its width. 1097 1114 */ 1098 public void setArrow( int length, double ratio) {1115 public void setArrow(float length, double ratio) { 1099 1116 _arrowheadLength = length; 1100 1117 _arrowheadRatio = ratio; … … 1106 1123 } 1107 1124 1108 public void setArrowheadLength( int length) {1125 public void setArrowheadLength(float length) { 1109 1126 _arrowheadLength = length; 1110 1127 updateArrowPolygon(); … … 1250 1267 1251 1268 public void setLinkMark(boolean val) { 1269 _poly = null; 1252 1270 _linkMark = val; 1253 1271 } … … 1307 1325 _y = y; 1308 1326 1327 for (Item i : getEnclosures()) { 1328 i.updatePolygon(); 1329 } 1309 1330 updatePolygon(); 1310 1331 … … 1400 1421 return; 1401 1422 assert (_parent != null); 1423 1424 if(FrameIO.isPositiveInteger(link)) 1425 return; 1426 1402 1427 // Check if the link is for the current frameset 1403 1428 if (_parent.getFramesetName().equalsIgnoreCase( … … 1411 1436 * Dots this is the thickness. 1412 1437 */ 1413 public void setSize( int size) {1438 public void setSize(float size) { 1414 1439 } 1415 1440 … … 1500 1525 else { 1501 1526 _arrowhead = new Polygon(); 1502 _arrowhead.addPoint((int) getX(), (int) getY()); 1527 _arrowhead.addPoint(Math.round(getX()), Math.round(getY())); 1528 _arrowhead.addPoint((Math.round(getX() - getArrowheadLength())), 1529 ((int) Math.round(getY() 1530 - (getArrowheadLength() * getArrowheadRatio())))); 1531 _arrowhead.addPoint(Math.round(getX()), (int) getY()); 1503 1532 _arrowhead 1504 1533 .addPoint( 1505 (int) getX() - getArrowheadLength(), 1506 (int) (getY() - (getArrowheadLength() * getArrowheadRatio()))); 1507 _arrowhead.addPoint((int) getX(), (int) getY()); 1508 _arrowhead 1509 .addPoint( 1510 (int) getX() - getArrowheadLength(), 1511 (int) (getY() + (getArrowheadLength() * getArrowheadRatio()))); 1534 (int) Math.round(getX() - getArrowheadLength()), 1535 (int) Math 1536 .round((getY() + (getArrowheadLength() * getArrowheadRatio())))); 1512 1537 } 1513 1538 } 1514 1539 1515 1540 protected abstract void updatePolygon(); 1541 1542 public void setHidden(boolean state) { 1543 this._visible = !state; 1544 } 1545 1516 1546 1517 1547 public void setVisible(boolean state) { … … 1520 1550 1521 1551 public boolean isVisible() { 1522 return _visible ;1552 return _visible && !_deleted; 1523 1553 } 1524 1554 … … 1540 1570 } 1541 1571 setSelectionColor(color); 1542 _lastMode = _mode;1543 1572 _mode = mode; 1544 }1545 1546 public void restoreLastMode(Color selectionColor) {1547 setSelectionColor(selectionColor);1548 if (_mode != SelectedMode.None)1549 return;1550 _mode = _lastMode;1551 _lastMode = SelectedMode.None;1552 1573 } 1553 1574 … … 1659 1680 } 1660 1681 1682 /** 1683 * True if this item is the end of a line. 1684 * 1685 * @return 1686 */ 1661 1687 public boolean isLineEnd() { 1688 // TODO this will need to be redone when enclosure class is added... 1689 // At the moment enclosures are only circles...we dont want circle 1690 // centers to be lineEnds 1662 1691 return _lines.size() > 0; 1692 } 1693 1694 public boolean hasEnclosures(){ 1695 return _enclosures.size() > 0; 1663 1696 } 1664 1697 … … 1717 1750 1718 1751 public void setAction(String string) { 1752 //Want to resize the highlight box for text items if actions are been added 1753 if(_actions == null || _actions.size() == 0){ 1754 _poly = null; 1755 } 1719 1756 _actions = new LinkedList<String>(); 1720 1757 _actions.add(string); … … 1732 1769 protected void paintLink(Graphics2D g) { 1733 1770 if (getLink() != null || getAction() != null) { 1771 g.setStroke(HIGHLIGHT_STROKE); 1734 1772 if (getLink() != null && getAction() != null) { 1735 1773 g.setColor(LINK_ACTION_COLOR); … … 1806 1844 return null; 1807 1845 // assert (_parent!= null); 1846 Frame parent = getParentOrCurrentFrame(); 1808 1847 if (_parent == null) { 1809 1848 // if parent is null it is an item on the message box 1810 1849 // so it must already be absolute 1811 assert (!FrameIO.isPositiveInteger(link)); 1812 return link; 1850 //assert (!FrameIO.isPositiveInteger(link)); 1851 //return link; 1852 1813 1853 } 1814 1854 1815 1855 // if its a relative link then return absolute 1816 1856 if (FrameIO.isPositiveInteger(link)) { 1817 return _parent.getFramesetName() + link;1857 return parent.getFramesetName() + link; 1818 1858 } 1819 1859 return link; … … 1828 1868 * new y position 1829 1869 */ 1830 public void setXY( int x, int y) {1870 public void setXY(float x, float y) { 1831 1871 _x = x; 1832 1872 _y = y; … … 1877 1917 1878 1918 /** 1879 * Gets the size of the enclosure that this item is part of. 1880 * @return the area of the box surrounding the enclosed shape that this item is part of 1881 */ 1882 public Integer getEnclosedArea() { 1919 * Gets the size of the enclosure that this item is part of. Used to 1920 * determine the paint order of items, with smaller items being painted 1921 * first. 1922 * 1923 * @return the area of the box surrounding the enclosed shape that this item 1924 * is part of 1925 */ 1926 public double getEnclosedArea() { 1883 1927 if (_enclosure == null) 1884 return 0; 1885 Rectangle box = getEnclosedShape().getBounds(); 1886 Integer area = box.width * box.height; 1887 1888 if (getFillColor() == null) 1889 return -area; 1890 1891 return area; 1928 return 0.0; 1929 Rectangle2D box = getEnclosedShape().getBounds2D(); 1930 return box.getWidth() * box.getHeight(); 1931 } 1932 1933 /** 1934 * Returns the Shape that surrounds this Item representing this Item's 1935 * 'gravity'. 1936 * 1937 * @return The Shape (rectangle) surrounding this Item, which represents 1938 * this Items 'gravity'. 1939 */ 1940 public final Polygon getPolygon() { 1941 if (_poly == null) 1942 updatePolygon(); 1943 1944 return new Polygon(_poly.xpoints, _poly.ypoints, _poly.npoints); 1945 } 1946 1947 /** 1948 * Shifts the position of the item along the line between this items 1949 * location and a specified point. 1950 * 1951 * @param origin 1952 * @param ratio 1953 */ 1954 public void translate(Point2D origin, double ratio) { 1955 _x = (float) (origin.getX() + ratio * (_x - origin.getX())); 1956 _y = (float) (origin.getY() + ratio * (_y - origin.getY())); 1957 updatePolygon(); 1958 for (Line line : getLines()) 1959 line.updatePolygon(); 1960 } 1961 1962 private static int[] LinePatterns = new int[] { 0, 10, 20 }; 1963 1964 /** 1965 * The rotates through a wheel of dashed lines. 1966 * 1967 * @param amount 1968 * number of rotations around the wheel to toggle by. 1969 */ 1970 public void toggleDashed(int amount) { 1971 // find the index of the current line pattern 1972 int[] currentPattern = getLinePattern(); 1973 1974 // Find the current pattern and move to the next pattern in the wheel 1975 for (int i = 0; i < LinePatterns.length; i++) { 1976 if (currentPattern == null || currentPattern[0] == LinePatterns[i]) { 1977 i += LinePatterns.length + amount; 1978 i %= LinePatterns.length; 1979 1980 // if we are at the start of the wheel make it 'null' (solid 1981 // line) 1982 if (i == 0) { 1983 setLinePattern(null); 1984 } else { 1985 setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] }); 1986 } 1987 return; 1988 } 1989 } 1990 } 1991 1992 Collection<XRayable> _enclosures = new HashSet<XRayable>(); 1993 1994 private boolean _deleted = false; 1995 1996 /** 1997 * For now there can only be one enclosure per item 1998 * @param enclosure 1999 */ 2000 public void addEnclosure(XRayable enclosure) { 2001 _enclosures.clear(); 2002 _enclosures.add(enclosure); 2003 } 2004 2005 public Collection<? extends XRayable> getEnclosures() { 2006 return _enclosures; 2007 } 2008 2009 public void removeEnclosure(Item i) { 2010 _enclosures.remove(i); 2011 2012 } 2013 2014 public boolean isDeleted() { 2015 return _deleted; 1892 2016 } 1893 2017 }
Note:
See TracChangeset
for help on using the changeset viewer.