Changeset 121 for trunk/src/org/expeditee/items/Item.java
- Timestamp:
- 07/03/08 16:48:09 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Item.java
r116 r121 5 5 import java.awt.Cursor; 6 6 import java.awt.Dimension; 7 import java.awt.GradientPaint; 7 8 import java.awt.Graphics2D; 8 9 import java.awt.Point; 9 10 import java.awt.Polygon; 10 11 import java.awt.Rectangle; 12 import java.awt.Shape; 11 13 import java.awt.Stroke; 12 14 import java.awt.geom.AffineTransform; … … 29 31 import org.expeditee.gui.FrameIO; 30 32 import org.expeditee.gui.FrameUtils; 33 import org.expeditee.gui.MessageBay; 31 34 import org.expeditee.gui.Overlay; 32 35 import org.expeditee.gui.Vector; … … 185 188 if (parent != null) { 186 189 dest.setID(source.getParentOrCurrentFrame().getNextItemID()); 187 } 190 } 191 // else { 192 // dest.setID(source.getID()); 193 // } 188 194 } 189 195 … … 254 260 private Color _color = null; 255 261 256 pr ivateColor _highlightColor = DEFAULT_HIGHLIGHT;262 protected Color _highlightColor = DEFAULT_HIGHLIGHT; 257 263 258 264 private Color _colorBackground = null; … … 525 531 } 526 532 527 protected Polygon get Circle() {533 protected Polygon getLinkPoly() { 528 534 if (_circle == null) { 529 535 int points = 16; … … 552 558 _circleCross = new Polygon(); 553 559 554 Rectangle bounds = get Circle().getBounds();560 Rectangle bounds = getLinkPoly().getBounds(); 555 561 int x1 = (int) bounds.getMinX(); 556 562 int x2 = (int) bounds.getMaxX(); … … 943 949 g.setColor(fillColor); 944 950 // The painting is not efficient enough for gradients... 945 // Shapes = getEnclosedShape();946 //Rectangle b = s.getBounds();947 //GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3),948 //b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y,949 //Color.white);950 //g.setPaint(gp);951 // g.fill(s);951 // Polygon s = getEnclosedShape(); 952 // Rectangle b = s.getBounds(); 953 // GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3), 954 // b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y, 955 // Color.white); 956 // g.setPaint(gp); 957 // g.fillPolygon(s); 952 958 g.fillPolygon(getEnclosedShape()); 953 959 } … … 994 1000 */ 995 1001 public void removeAllLines() { 1002 for (Line l : _lines) { 1003 l.invalidateAll(); 1004 } 996 1005 _lines.clear(); 997 1006 } … … 1016 1025 */ 1017 1026 public void removeLine(Line line) { 1018 _lines.remove(line); 1027 if (_lines.remove(line)) 1028 line.invalidateAll(); 1019 1029 } 1020 1030 … … 1024 1034 Simple.RunFrameAndReportError(this, new Context()); 1025 1035 Simple.ProgramFinished(); 1026 FrameGraphics.DisplayMessage(AgentStats.getStats(), GREEN);1036 MessageBay.displayMessage(AgentStats.getStats(), GREEN); 1027 1037 } catch (ConcurrentModificationException ce) { 1028 1038 Simple.ProgramFinished(); 1029 1039 ce.printStackTrace(); 1030 1040 } catch (Exception e) { 1031 FrameGraphics.LinkedErrorMessage(e.getMessage());1041 MessageBay.linkedErrorMessage(e.getMessage()); 1032 1042 Simple.ProgramFinished(); 1033 1043 } … … 1142 1152 1143 1153 public void setBackgroundColor(Color c) { 1144 _colorBackground = c; 1154 if (c != _colorBackground) { 1155 _colorBackground = c; 1156 invalidateCommonTrait(ItemAppearence.BackgroundColorChanged); 1157 } 1145 1158 } 1146 1159 … … 1163 1176 */ 1164 1177 public void setColor(Color c) { 1165 _color = c; 1178 if (c != _color) { 1179 _color = c; 1180 invalidateCommonTrait(ItemAppearence.ForegroundColorChanged); 1181 } 1166 1182 } 1167 1183 … … 1191 1207 1192 1208 public void setFillColor(Color c) { 1209 1193 1210 _colorFill = c; 1194 1211 … … 1198 1215 other.setFillColor(c); 1199 1216 } 1217 1218 invalidateCommonTrait(ItemAppearence.FillColor); 1219 invalidateFill(); 1200 1220 } 1201 1221 1202 1222 public void setFillPattern(String patternLink) { 1203 1223 _fillPattern = patternLink; 1224 invalidateCommonTrait(ItemAppearence.FillPattern); 1225 invalidateFill(); 1204 1226 } 1205 1227 … … 1244 1266 for (Line line : lines) 1245 1267 line.setLinePattern(getLinePattern()); 1268 1269 1246 1270 } 1247 1271 … … 1254 1278 */ 1255 1279 public void setLink(String frameName) { 1256 if (FrameIO.isValidLink(frameName)) 1280 if (FrameIO.isValidLink(frameName)) 1257 1281 _link = frameName; 1258 1282 else 1259 FrameGraphics.ErrorMessage("[" + frameName1283 MessageBay.errorMessage("[" + frameName 1260 1284 + "] is not a valid frame name"); 1261 1285 // TODO make this throw exceptions etc... 1286 1287 invalidate(getLinkDrawArea()); 1262 1288 } 1263 1289 … … 1266 1292 _link_frameset = frameset; 1267 1293 else 1268 FrameGraphics.ErrorMessage("[" + frameset1294 MessageBay.errorMessage("[" + frameset 1269 1295 + "] is not a valid frameset name"); 1270 1296 // TODO make this throw exceptions etc... … … 1280 1306 _link_template = template; 1281 1307 else 1282 FrameGraphics.ErrorMessage("[" + template1308 MessageBay.errorMessage("[" + template 1283 1309 + "] is not a valid frame name"); 1284 1310 // TODO make this throw exceptions etc... … … 1316 1342 1317 1343 /** 1344 * Invalidates this, connected lines and fill 1345 * @param trait 1346 */ 1347 private void invalidateCommonTraitForAll(ItemAppearence trait) { 1348 invalidateCommonTrait(trait); 1349 for (Line line : getLines()) 1350 line.invalidateCommonTrait(trait); 1351 if (_colorFill != null) { 1352 invalidateFill(); // only invalidates if has fill 1353 } 1354 for(XRayable x: getEnclosures()){ 1355 x.invalidateCommonTrait(trait); 1356 } 1357 1358 } 1359 1360 1361 /** 1318 1362 * Sets the position of this item on the screen 1319 1363 * … … 1326 1370 float deltaX = x - _x; 1327 1371 float deltaY = y - _y; 1372 1373 if (deltaX == 0 && deltaY == 0) return; 1374 1375 invalidateCommonTraitForAll(ItemAppearence.PreMoved); 1328 1376 1329 1377 _x = x; … … 1413 1461 } 1414 1462 1415 for (Line line : getLines()) 1416 line.updatePolygon(); 1463 for (Line line : getLines()) { 1464 line.updatePolygon(); 1465 } 1466 1467 invalidateCommonTraitForAll(ItemAppearence.PostMoved); 1468 1417 1469 } 1418 1470 … … 1463 1515 */ 1464 1516 public void setThickness(float thick, boolean setConnectedThickness) { 1517 1518 if (thick == _thickness) return; 1519 boolean bigger = thick > _thickness; 1520 1521 if (!bigger) invalidateCommonTrait(ItemAppearence.Thickness); 1522 1465 1523 _thickness = thick; 1466 1524 // update the size of any lines 1467 1525 for (Line line : getLines()) 1468 1526 line.setThickness(thick, setConnectedThickness); 1527 1528 if (bigger) invalidateCommonTrait(ItemAppearence.Thickness); 1469 1529 } 1470 1530 … … 1534 1594 1535 1595 public int setHighlightColor(Color c) { 1596 1536 1597 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1537 if (c != null) 1538 _highlightColor = c; 1539 else 1540 _highlightColor = DEFAULT_HIGHLIGHT; 1598 1599 Color selColor = (c != null) ? c : DEFAULT_HIGHLIGHT; 1600 if (_highlightColor != c) { 1601 _highlightColor = selColor; 1602 this.invalidateCommonTrait(ItemAppearence.HighlightColorChanged); 1603 } 1541 1604 1542 1605 return Item.UNCHANGED_CURSOR; 1606 1543 1607 } 1544 1608 … … 1589 1653 public void setHighlightMode(HighlightMode mode, Color color) { 1590 1654 setHighlightColor(color); 1591 _mode = mode; 1655 if (_mode != mode) { 1656 _mode = mode; 1657 this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged); 1658 } 1592 1659 } 1593 1660 … … 1655 1722 */ 1656 1723 public void setEnclosedList(Collection<Item> enclosed) { 1724 1725 boolean changed = (_enclosure == null && enclosed != null); 1726 1727 if (_enclosure != null && enclosed == null) { 1728 invalidateFill(); 1729 } 1730 1657 1731 _enclosure = enclosed; 1732 1733 if (changed) { 1734 invalidateFill();; 1735 } 1658 1736 } 1659 1737 … … 1773 1851 if (_actions == null || _actions.size() == 0) { 1774 1852 _poly = null; 1853 invalidateCommonTrait(ItemAppearence.LinkChanged); 1775 1854 } 1776 1855 _actions = new LinkedList<String>(); … … 1780 1859 protected int getLinkYOffset() { 1781 1860 return 0; 1861 } 1862 1863 protected Rectangle getLinkDrawArea() { // TODO: Revise 1864 return new Rectangle(getX() - LEFT_MARGIN - 3, getY() + getLinkYOffset() - 3, 6, 6); 1782 1865 } 1783 1866 … … 1804 1887 1805 1888 if (getLinkMark() && getLink() != null) { 1806 g.drawPolygon(get Circle());1889 g.drawPolygon(getLinkPoly()); 1807 1890 1808 1891 // if the link is not valid, cross out the circle … … 1812 1895 1813 1896 if (getActionMark() && getAction() != null) { 1814 g.drawPolygon(get Circle());1815 g.fillPolygon(get Circle());1897 g.drawPolygon(getLinkPoly()); 1898 g.fillPolygon(getLinkPoly()); 1816 1899 1817 1900 // if the link is not valid, cross out the circle … … 1973 2056 */ 1974 2057 public void translate(Point2D origin, double ratio) { 2058 2059 invalidateCommonTraitForAll(ItemAppearence.PreMoved); 2060 1975 2061 _x = (float) (origin.getX() + ratio * (_x - origin.getX())); 1976 2062 _y = (float) (origin.getY() + ratio * (_y - origin.getY())); … … 1978 2064 for (Line line : getLines()) 1979 2065 line.updatePolygon(); 2066 2067 invalidateCommonTraitForAll(ItemAppearence.PostMoved); 2068 1980 2069 } 1981 2070 … … 2005 2094 setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] }); 2006 2095 } 2096 2097 invalidateCommonTrait(ItemAppearence.ToggleDashed); 2007 2098 return; 2008 2099 } 2009 2100 } 2101 2102 2010 2103 } 2011 2104 … … 2037 2130 public boolean isDeleted() { 2038 2131 return _deleted; 2132 } 2133 2134 /** 2135 * @return The full canvas that this item draws to. Must include highlighting bounds 2136 */ 2137 public Rectangle[] getDrawingArea() { 2138 2139 return new Rectangle[] { 2140 ItemUtils.expandRectangle(getPolygon().getBounds(), 2141 _highlightThickness) 2142 }; 2143 2144 } 2145 2146 /** 2147 * 2148 * @param area 2149 * @return True if area intersects with this items drawing area. 2150 */ 2151 public final boolean isInDrawingArea(Area area) { 2152 for (Rectangle r : getDrawingArea()) { 2153 if (area.intersects(r)) return true; 2154 } 2155 return false; 2156 } 2157 2158 /** 2159 * Completetly invalidates the item - so that it should be redrawed. 2160 * Note: This is handled internally, it should be reare to invoke this 2161 * externally 2162 */ 2163 public final void invalidateAll() { 2164 invalidate(getDrawingArea()); 2165 } 2166 2167 /** 2168 * Invalidates areas on the parent frame. 2169 * Purpose: to be called on specific areas of the item that needs redrawing. 2170 * @param damagedAreas 2171 */ 2172 protected final void invalidate(Rectangle[] damagedAreas) { 2173 for (Rectangle r : damagedAreas) invalidate(r); 2174 } 2175 2176 /** 2177 * Invalidates areas on the parent frame. 2178 * Purpose: to be called on specific areas of the item that needs redrawing. 2179 * @param damagedAreas 2180 */ 2181 protected final void invalidate(Rectangle damagedArea) { 2182 FrameGraphics.invalidateItem(this, damagedArea); 2183 } 2184 2185 /** 2186 * Used to invalidate visual traits commonly shared by all items. 2187 * @param trait 2188 */ 2189 public final void invalidateCommonTrait(ItemAppearence trait) { 2190 invalidate(getDamagedArea(trait)); 2191 2192 if (_colorFill != null && ( 2193 trait == ItemAppearence.Added 2194 || trait == ItemAppearence.Removed) 2195 ) { 2196 invalidateFill(); 2197 } 2198 } 2199 2200 /** 2201 * Invalidates fill if has one, even if no color is set. 2202 */ 2203 public void invalidateFill() { 2204 if (isLineEnd() && _enclosure != null) { 2205 invalidate(getEnclosedShape().getBounds()); 2206 } 2207 } 2208 2209 /** 2210 * Default implementation always uses drawing area except for links, 2211 * where the link drawing area is used. Override to make item 2212 * drawing more efficient - defining only parts of the item that needs 2213 * redrawing. 2214 * 2215 * @see Item.getDrawingArea 2216 * 2217 * @param trait The visual trait that has changed. 2218 * 2219 * @return The damaged area according to the visual trait that has changed. 2220 */ 2221 protected Rectangle[] getDamagedArea(ItemAppearence trait) { 2222 2223 if (trait == ItemAppearence.LinkChanged) 2224 return new Rectangle[] {getLinkDrawArea()}; // Invalidate area where link is drawn 2225 2226 return getDrawingArea(); 2227 2039 2228 } 2040 2229 … … 2056 2245 _overlay = overlay; 2057 2246 } 2247 2058 2248 }
Note:
See TracChangeset
for help on using the changeset viewer.