Changeset 137 for trunk/src/org/expeditee/items/Text.java
- Timestamp:
- 07/14/08 10:05:43 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Text.java
r131 r137 38 38 public class Text extends Item { 39 39 public static String LINE_SEPARATOR = System.getProperty("line.separator"); 40 public static char[] BULLETS = {'\u2219' , '\u2218', '\u2217'}; 40 41 public static char[] BULLETS = { '\u2219', '\u2218', '\u2217' }; 42 41 43 private static char DEFAULT_BULLET = BULLETS[2]; 44 42 45 private static String DEFAULT_BULLET_STRING = DEFAULT_BULLET + " "; 43 46 44 47 private String[] _processedText = null; 45 48 … … 97 100 98 101 private int _selectionEnd = -1; 99 102 100 103 // text is broken up into lines 101 104 private StringBuffer _text = new StringBuffer(); … … 125 128 setID(id); 126 129 } 127 130 128 131 /** 129 132 * Creates a text item which is not added to the frame. 133 * 130 134 * @param text 131 135 */ … … 190 194 } 191 195 192 193 196 /** 194 197 * Sets the justification of this Text item. The given integer should … … 277 280 */ 278 281 public void removeText(String text) { 279 282 280 283 if (_text.length() > 0 && _text.indexOf(text) == 0) { 281 // invalidateAll();284 // invalidateAll(); 282 285 _text.delete(0, text.length()); 283 286 } 284 285 287 286 288 } … … 289 291 int length = _text.length(); 290 292 if (length > 0) { 291 // invalidateAll();293 // invalidateAll(); 292 294 int pos = _text.indexOf(textToRemove); 293 295 int textToRemoveLength = textToRemove.length(); … … 296 298 } 297 299 } 298 300 299 301 } 300 302 … … 366 368 */ 367 369 private char getNextBullet(char bullet) { 368 for (int i = 0; i < BULLETS.length - 1; i++){369 if (BULLETS[i]== bullet)370 return BULLETS[i +1];370 for (int i = 0; i < BULLETS.length - 1; i++) { 371 if (BULLETS[i] == bullet) 372 return BULLETS[i + 1]; 371 373 } 372 374 return BULLETS[0]; … … 374 376 375 377 private char getPreviousBullet(char bullet) { 376 for (int i = 1; i < BULLETS.length; i++){377 if (BULLETS[i]== bullet)378 for (int i = 1; i < BULLETS.length; i++) { 379 if (BULLETS[i] == bullet) 378 380 return BULLETS[i - 1]; 379 381 } … … 470 472 if (_selectionStart < 0 || _selectionEnd < 0) 471 473 return null; 472 474 473 475 invalidateAll(); 474 476 475 477 if (_selectionEnd > _text.length()) 476 478 _selectionEnd = _text.length(); … … 484 486 _text.insert(left, newText); 485 487 rebuild(true); 486 488 487 489 invalidateAll(); 488 490 … … 520 522 TextLayout current = null; 521 523 int line; 522 524 523 525 invalidateAll(); 524 526 … … 617 619 } 618 620 619 if (_text.length() == 0) {621 if (_text.length() == 0) { 620 622 rebuild(false); 621 623 return new Point2D.Float(this._x, this._y); … … 664 666 x, 665 667 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 666 668 667 669 invalidateAll(); 668 670 669 671 return new Point2D.Float(Math.round(x), Math.round(getY() + y 670 672 + caret[1])); … … 813 815 // rejustify(); 814 816 rebuild(false); 815 817 816 818 invalidateAll(); 817 819 } … … 1133 1135 private void rebuild(boolean limitWidth) { 1134 1136 // if there is no text, there is nothing to do 1135 if (_text == null || _text.length() == 0) {1136 //Frame parent = getParent();1137 //if(parent != null)1138 //parent.removeItem(this);1137 if (_text == null || _text.length() == 0) { 1138 // Frame parent = getParent(); 1139 // if(parent != null) 1140 // parent.removeItem(this); 1139 1141 return; 1140 1142 } 1141 1143 1142 1144 AttributedString paragraphText = new AttributedString(_text.toString()); 1143 1145 paragraphText.addAttribute(TextAttribute.FONT, getPaintFont()); … … 1188 1190 1189 1191 updatePolygon(); 1190 1192 1191 1193 } 1192 1194 … … 1314 1316 return; 1315 1317 } 1316 1318 1319 // check if its a vector item and paint all the vector stuff too if this 1320 // item is a free item 1321 // This will allow for dragging vectors around the place! 1322 if (hasVector() && isFloating()) { 1323 FrameGraphics.requestRefresh(false); 1324 // TODO make this use a more efficient paint method... 1325 // Have the text item return a bigger repaint area if it has an 1326 // associated vector 1327 } 1328 1317 1329 // the background is only cleared if required 1318 1330 if (getBackgroundColor() != null) { … … 1418 1430 paintLink(g); 1419 1431 } 1420 1432 1421 1433 @Override 1422 1434 protected Rectangle getLinkDrawArea() { // TODO: Revise … … 1493 1505 if (isAnnotation()) 1494 1506 return; 1495 if (!isLineEnd() && _text.length() > 0 && _text.charAt(0) == DEFAULT_BULLET) { 1507 if (!isLineEnd() && _text.length() > 0 1508 && _text.charAt(0) == DEFAULT_BULLET) { 1496 1509 newPoint.setLocation(insertText("" 1497 1510 + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1)); … … 1510 1523 newPoint.setLocation(insertText("" 1511 1524 + (char) KeyEvent.VK_BACK_SPACE, mouseX, mouseY, 1)); 1512 newPoint 1513 .setLocation(insertText( DEFAULT_BULLET_STRING,newPoint.x, newPoint.y, 0));1525 newPoint.setLocation(insertText(DEFAULT_BULLET_STRING, 1526 newPoint.x, newPoint.y, 0)); 1514 1527 } else { 1515 1528 newPoint.setLocation(insertText("" … … 1557 1570 _lineBreaker.deleteChar(inserting.getIterator(), pos); 1558 1571 } 1559 1560 1561 1572 1562 1573 } 1563 1574 … … 1727 1738 @Override 1728 1739 protected int getLinkYOffset() { 1729 if (_textLayouts.size() == 0) return 0; 1740 if (_textLayouts.size() == 0) 1741 return 0; 1730 1742 return Math.round(-(_textLayouts.get(0).getAscent() / 2)); 1731 1743 } … … 1748 1760 1749 1761 public static boolean isBulletChar(char c) { 1750 for (int i = 0; i < BULLETS.length; i++){1751 if (BULLETS[i]== c)1762 for (int i = 0; i < BULLETS.length; i++) { 1763 if (BULLETS[i] == c) 1752 1764 return true; 1753 1765 } 1754 return c == '*' || c == '+' || c == '>' || c == '-' || c == 'o';1755 } 1756 1766 return c == '*' || c == '+' || c == '>' || c == '-' || c == 'o'; 1767 } 1768 1757 1769 public boolean hasOverlay() { 1758 if (!isAnnotation() || getLink()==null)1770 if (!isAnnotation() || getLink() == null) 1759 1771 return false; 1760 return ItemUtils.startsWithTag(this, "@ao") ||ItemUtils.startsWithTag(this, "@v"); 1772 return ItemUtils.startsWithTag(this, "@ao") 1773 || ItemUtils.startsWithTag(this, "@v"); 1761 1774 } 1762 1775
Note:
See TracChangeset
for help on using the changeset viewer.