Changeset 124 for trunk/src/org/expeditee/items/Item.java
- Timestamp:
- 07/03/08 18:18:19 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Item.java
r123 r124 28 28 import org.expeditee.gui.FrameGraphics; 29 29 import org.expeditee.gui.FrameIO; 30 import org.expeditee.gui.FrameKeyboardActions; 30 31 import org.expeditee.gui.FrameUtils; 31 32 import org.expeditee.gui.MessageBay; … … 186 187 if (parent != null) { 187 188 dest.setID(source.getParentOrCurrentFrame().getNextItemID()); 188 } 189 //else {190 //dest.setID(source.getID());191 //}189 } 190 // else { 191 // dest.setID(source.getID()); 192 // } 192 193 } 193 194 … … 947 948 g.setColor(fillColor); 948 949 // The painting is not efficient enough for gradients... 949 //Polygon s = getEnclosedShape();950 //Rectangle b = s.getBounds();951 //GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3),952 //b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y,953 //Color.white);954 //g.setPaint(gp);955 //g.fillPolygon(s);950 // Polygon s = getEnclosedShape(); 951 // Rectangle b = s.getBounds(); 952 // GradientPaint gp = new GradientPaint((int) (b.x + b.width * 0.3), 953 // b.y, getFillColor(), (int) (b.x + b.width * 1.3), b.y, 954 // Color.white); 955 // g.setPaint(gp); 956 // g.fillPolygon(s); 956 957 g.fillPolygon(getEnclosedShape()); 957 958 } … … 1023 1024 */ 1024 1025 public void removeLine(Line line) { 1025 if (_lines.remove(line)) 1026 if (_lines.remove(line)) 1026 1027 line.invalidateAll(); 1027 1028 } … … 1177 1178 _color = c; 1178 1179 invalidateCommonTrait(ItemAppearence.ForegroundColorChanged); 1180 if (hasVector()) { 1181 //TODO make this more efficient so it only repaints the items for this vector 1182 FrameKeyboardActions.Refresh(); 1183 } 1179 1184 } 1180 1185 } … … 1213 1218 other.setFillColor(c); 1214 1219 } 1215 1220 1216 1221 invalidateCommonTrait(ItemAppearence.FillColor); 1217 1222 invalidateFill(); … … 1264 1269 for (Line line : lines) 1265 1270 line.setLinePattern(getLinePattern()); 1266 1267 1271 1268 1272 } 1269 1273 … … 1276 1280 */ 1277 1281 public void setLink(String frameName) { 1278 if (FrameIO.isValidLink(frameName)) 1282 if (FrameIO.isValidLink(frameName)) 1279 1283 _link = frameName; 1280 1284 else … … 1282 1286 + "] is not a valid frame name"); 1283 1287 // TODO make this throw exceptions etc... 1284 1288 1285 1289 invalidate(getLinkDrawArea()); 1286 1290 } … … 1341 1345 /** 1342 1346 * Invalidates this, connected lines and fill 1347 * 1343 1348 * @param trait 1344 1349 */ 1345 1350 private void invalidateCommonTraitForAll(ItemAppearence trait) { 1346 1351 invalidateCommonTrait(trait); 1347 for (Line line : getLines()) 1352 for (Line line : getLines()) 1348 1353 line.invalidateCommonTrait(trait); 1349 1354 if (_colorFill != null) { 1350 1355 invalidateFill(); // only invalidates if has fill 1351 1356 } 1352 for (XRayable x: getEnclosures()){1357 for (XRayable x : getEnclosures()) { 1353 1358 x.invalidateCommonTrait(trait); 1354 1359 } 1355 1360 1356 1361 } 1357 1358 1362 1359 1363 /** 1360 1364 * Sets the position of this item on the screen … … 1368 1372 float deltaX = x - _x; 1369 1373 float deltaY = y - _y; 1370 1371 if (deltaX == 0 && deltaY == 0) return; 1372 1374 1375 if (deltaX == 0 && deltaY == 0) 1376 return; 1377 1373 1378 invalidateCommonTraitForAll(ItemAppearence.PreMoved); 1374 1379 … … 1460 1465 1461 1466 for (Line line : getLines()) { 1462 line.updatePolygon(); 1463 } 1464 1467 line.updatePolygon(); 1468 } 1469 1465 1470 invalidateCommonTraitForAll(ItemAppearence.PostMoved); 1466 1471 1467 1472 } 1468 1473 … … 1513 1518 */ 1514 1519 public void setThickness(float thick, boolean setConnectedThickness) { 1515 1516 if (thick == _thickness) return; 1520 1521 if (thick == _thickness) 1522 return; 1517 1523 boolean bigger = thick > _thickness; 1518 1519 if (!bigger) invalidateCommonTrait(ItemAppearence.Thickness); 1520 1524 1525 if (!bigger) 1526 invalidateCommonTrait(ItemAppearence.Thickness); 1527 1521 1528 _thickness = thick; 1522 1529 // update the size of any lines … … 1524 1531 line.setThickness(thick, setConnectedThickness); 1525 1532 1526 if (bigger) invalidateCommonTrait(ItemAppearence.Thickness); 1533 if (bigger) 1534 invalidateCommonTrait(ItemAppearence.Thickness); 1527 1535 } 1528 1536 … … 1592 1600 1593 1601 public int setHighlightColor(Color c) { 1594 1602 1595 1603 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1596 1604 1597 1605 Color selColor = (c != null) ? c : DEFAULT_HIGHLIGHT; 1598 1606 if (_highlightColor != c) { … … 1602 1610 1603 1611 return Item.UNCHANGED_CURSOR; 1604 1612 1605 1613 } 1606 1614 … … 1720 1728 */ 1721 1729 public void setEnclosedList(Collection<Item> enclosed) { 1722 1730 1723 1731 boolean changed = (_enclosure == null && enclosed != null); 1724 1732 1725 1733 if (_enclosure != null && enclosed == null) { 1726 1734 invalidateFill(); 1727 1735 } 1728 1736 1729 1737 _enclosure = enclosed; 1730 1738 1731 1739 if (changed) { 1732 invalidateFill();; 1740 invalidateFill(); 1741 ; 1733 1742 } 1734 1743 } … … 1858 1867 return 0; 1859 1868 } 1860 1869 1861 1870 protected Rectangle getLinkDrawArea() { // TODO: Revise 1862 return new Rectangle(getX() - LEFT_MARGIN - 3, getY() + getLinkYOffset() - 3, 6, 6); 1871 return new Rectangle(getX() - LEFT_MARGIN - 3, getY() 1872 + getLinkYOffset() - 3, 6, 6); 1863 1873 } 1864 1874 … … 2054 2064 */ 2055 2065 public void translate(Point2D origin, double ratio) { 2056 2066 2057 2067 invalidateCommonTraitForAll(ItemAppearence.PreMoved); 2058 2068 2059 2069 _x = (float) (origin.getX() + ratio * (_x - origin.getX())); 2060 2070 _y = (float) (origin.getY() + ratio * (_y - origin.getY())); … … 2062 2072 for (Line line : getLines()) 2063 2073 line.updatePolygon(); 2064 2074 2065 2075 invalidateCommonTraitForAll(ItemAppearence.PostMoved); 2066 2076 2067 2077 } 2068 2078 … … 2092 2102 setLinePattern(new int[] { LinePatterns[i], LinePatterns[i] }); 2093 2103 } 2094 2104 2095 2105 invalidateCommonTrait(ItemAppearence.ToggleDashed); 2096 2106 return; 2097 2107 } 2098 2108 } 2099 2100 2109 2101 2110 } 2102 2111 … … 2129 2138 return _deleted; 2130 2139 } 2131 2132 /** 2133 * @return The full canvas that this item draws to. Must include highlighting bounds 2140 2141 /** 2142 * @return The full canvas that this item draws to. Must include 2143 * highlighting bounds 2134 2144 */ 2135 2145 public Rectangle[] getDrawingArea() { 2136 2137 return new Rectangle[] { 2138 ItemUtils.expandRectangle(getPolygon().getBounds(), 2139 _highlightThickness) 2140 }; 2141 2142 } 2143 2146 2147 return new Rectangle[] { ItemUtils.expandRectangle(getPolygon() 2148 .getBounds(), _highlightThickness) }; 2149 2150 } 2151 2144 2152 /** 2145 2153 * … … 2149 2157 public final boolean isInDrawingArea(Area area) { 2150 2158 for (Rectangle r : getDrawingArea()) { 2151 if (area.intersects(r)) return true; 2159 if (area.intersects(r)) 2160 return true; 2152 2161 } 2153 2162 return false; 2154 2163 } 2155 2156 /** 2157 * Completetly invalidates the item - so that it should be redrawed. 2158 * Note: This is handled internally, it should be reare to invoke this 2159 * externally 2164 2165 /** 2166 * Completetly invalidates the item - so that it should be redrawed. Note: 2167 * This is handled internally, it should be reare to invoke this externally 2160 2168 */ 2161 2169 public final void invalidateAll() { 2162 2170 invalidate(getDrawingArea()); 2163 2171 } 2164 2165 /** 2166 * Invalidates areas on the parent frame. 2167 * Purpose: to be called on specific areas of the item that needs redrawing. 2172 2173 /** 2174 * Invalidates areas on the parent frame. Purpose: to be called on specific 2175 * areas of the item that needs redrawing. 2176 * 2168 2177 * @param damagedAreas 2169 2178 */ 2170 2179 protected final void invalidate(Rectangle[] damagedAreas) { 2171 for (Rectangle r : damagedAreas) invalidate(r); 2172 } 2173 2174 /** 2175 * Invalidates areas on the parent frame. 2176 * Purpose: to be called on specific areas of the item that needs redrawing. 2180 for (Rectangle r : damagedAreas) 2181 invalidate(r); 2182 } 2183 2184 /** 2185 * Invalidates areas on the parent frame. Purpose: to be called on specific 2186 * areas of the item that needs redrawing. 2187 * 2177 2188 * @param damagedAreas 2178 2189 */ … … 2180 2191 FrameGraphics.invalidateItem(this, damagedArea); 2181 2192 } 2182 2193 2183 2194 /** 2184 2195 * Used to invalidate visual traits commonly shared by all items. 2196 * 2185 2197 * @param trait 2186 2198 */ 2187 2199 public final void invalidateCommonTrait(ItemAppearence trait) { 2188 2200 invalidate(getDamagedArea(trait)); 2189 2190 if (_colorFill != null && ( 2191 trait == ItemAppearence.Added 2192 || trait == ItemAppearence.Removed) 2193 ) { 2201 2202 if (_colorFill != null 2203 && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) { 2194 2204 invalidateFill(); 2195 2205 } 2196 2206 } 2197 2207 2198 2208 /** 2199 2209 * Invalidates fill if has one, even if no color is set. … … 2204 2214 } 2205 2215 } 2206 2207 /** 2208 * Default implementation always uses drawing area except for links, 2209 * where the link drawing area is used. Override to make item 2210 * drawing more efficient - defining only parts of the item that needs 2211 * redrawing. 2216 2217 /** 2218 * Default implementation always uses drawing area except for links, where 2219 * the link drawing area is used. Override to make item drawing more 2220 * efficient - defining only parts of the item that needs redrawing. 2212 2221 * 2213 2222 * @see Item.getDrawingArea 2214 2223 * 2215 * @param trait The visual trait that has changed. 2224 * @param trait 2225 * The visual trait that has changed. 2216 2226 * 2217 2227 * @return The damaged area according to the visual trait that has changed. 2218 2228 */ 2219 2229 protected Rectangle[] getDamagedArea(ItemAppearence trait) { 2220 2221 if (trait == ItemAppearence.LinkChanged) 2222 return new Rectangle[] {getLinkDrawArea()}; // Invalidate area where link is drawn 2223 2230 2231 if (trait == ItemAppearence.LinkChanged) 2232 return new Rectangle[] { getLinkDrawArea() }; // Invalidate area 2233 // where link is 2234 // drawn 2235 2224 2236 return getDrawingArea(); 2225 2237 … … 2229 2241 return _overlay instanceof Vector; 2230 2242 } 2231 2243 2232 2244 public boolean hasOverlay() { 2233 2245 return _overlay != null;
Note:
See TracChangeset
for help on using the changeset viewer.