Changeset 613
- Timestamp:
- 12/12/13 16:43:55 (11 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/AttributeUtils.java
r601 r613 271 271 _Attrib.put("Justification", Text.class.getMethod("getJustification"), 272 272 Text.class.getMethod("setJustification", pJustification)); 273 _Attrib.put("AutoWrap", Text.class.getMethod("getAutoWrapToSave"), 274 Text.class.getMethod("setAutoWrap", pBool)); 273 275 274 276 // Aliases for attribute setting -
trunk/src/org/expeditee/io/DefaultFrameReader.java
r584 r613 122 122 _ItemTags.put('w', Text.class.getMethod("setWidth", pIntO)); 123 123 _ItemTags.put('k', Text.class.getMethod("setJustification", pJustification)); 124 _ItemTags.put('r', Text.class.getMethod("setAutoWrap", pBool)); 124 125 125 126 _ItemTags.put('h', Item.class.getMethod("setThickness", pFloat)); -
trunk/src/org/expeditee/io/DefaultFrameWriter.java
r459 r613 118 118 _ItemTags.put("w", Text.class.getMethod("getWidthToSave", param)); 119 119 _ItemTags.put("k", Text.class.getMethod("getJustification", param)); 120 _ItemTags.put("r", Text.class.getMethod("getAutoWrapToSave", param)); 120 121 121 122 _ItemTags.put("h", Item.class.getMethod("getThickness", param)); -
trunk/src/org/expeditee/items/Text.java
r594 r613 37 37 import org.expeditee.gui.FrameMouseActions; 38 38 import org.expeditee.gui.FrameUtils; 39 import org.expeditee.gui.FreeItems; 39 40 import org.expeditee.math.ExpediteeJEP; 41 import org.expeditee.settings.UserSettings; 40 42 import org.nfunk.jep.Node; 41 43 … … 122 124 123 125 private int _selectionEnd = -1; 126 127 // whether autowrap is on/off for this item 128 protected boolean _autoWrap = false; 124 129 125 130 // text is broken up into lines … … 1408 1413 } 1409 1414 1410 float width = Float.MAX_VALUE;1415 /* float width = Float.MAX_VALUE; 1411 1416 1412 1417 if (limitWidth) { … … 1415 1420 // width = Math.max(50, getMaxWidth() - getX() 1416 1421 // - Item.MARGIN_RIGHT); 1417 } 1422 } */ 1418 1423 1419 1424 _textLayouts.clear(); … … 1423 1428 1424 1429 TextLayout layout; 1430 1431 float width; 1432 float lineHeight = Float.NaN; 1433 List<Point[]> lines = null; 1434 1435 if(_autoWrap || UserSettings.AutoWrap) { 1436 lines = new LinkedList<Point[]>(); 1437 if(DisplayIO.getCurrentFrame() == null) { 1438 return; 1439 } 1440 for(Item item : DisplayIO.getCurrentFrame().getItems()) { 1441 if(item instanceof Line) { 1442 lines.add(new Point[] { ((Line) item).getStartItem().getPosition(), ((Line) item).getEndItem().getPosition() }); 1443 } 1444 if(item instanceof Picture) { 1445 lines.add(new Point[] { item.getPosition(), new Point(item.getX(), item.getY() + item.getHeight()) }); 1446 } 1447 } 1448 for(Item item : FreeItems.getInstance()) { 1449 if(item instanceof Line) { 1450 lines.add(new Point[] { ((Line) item).getStartItem().getPosition(), ((Line) item).getEndItem().getPosition() }); 1451 } 1452 if(item instanceof Picture) { 1453 lines.add(new Point[] { item.getPosition(), new Point(item.getX(), item.getY() + item.getHeight()) }); 1454 } 1455 } 1456 width = getLineWidth(getX(), getY(), lines); 1457 1458 if(width < 100) { 1459 width = 100; 1460 } 1461 } else { 1462 width = Float.MAX_VALUE; 1463 if (limitWidth) { 1464 width = getAbsoluteWidth(); 1465 // else if (getMaxWidth() > 0) 1466 // width = Math.max(50, getMaxWidth() - getX() 1467 // - Item.MARGIN_RIGHT); 1468 } 1469 } 1470 1425 1471 _lineBreaker.setPosition(0); 1426 1472 1427 1473 // --- Get the output of the LineBreakMeasurer and store it in a 1428 1474 while ((layout = _lineBreaker.nextLayout(width)) != null) { 1475 1429 1476 // lineBreaker does not break on newline 1430 1477 // characters so they have to be check manually 1431 1478 int start = _lineOffsets.get(_lineOffsets.size() - 1); 1432 1479 1480 // int y = getY() + (getLineDrop(layout) * (_lineOffsets.size() - 1) 1481 1433 1482 // check through the current line for newline characters 1434 1483 for (int i = start + 1; i < _text.length(); i++) { … … 1447 1496 1448 1497 _textLayouts.add(layout); 1498 1499 if(_autoWrap || UserSettings.AutoWrap) { 1500 if(lineHeight != Float.NaN) { 1501 lineHeight = getLineDrop(layout); 1502 } 1503 width = getLineWidth(getX(), getY() + (lineHeight * (_lineOffsets.size() - 1)), lines); 1504 if(width < 100) { 1505 width = 100; 1506 } 1507 } 1449 1508 } 1450 1509 1451 1510 updatePolygon(); 1452 1511 1512 } 1513 1514 private float getLineWidth(int x, float y, List<Point[]> lines) { 1515 float width = FrameGraphics.getMaxFrameSize().width; 1516 for(Point[] l : lines) { 1517 // check for lines that cross over our y 1518 if((l[0].y >= y && l[1].y <= y) || (l[0].y <= y && l[1].y >= y)) { 1519 float dX = l[0].x - l[1].x; 1520 float dY = l[0].y - l[1].y; 1521 float newWidth; 1522 if(dX == 0) { 1523 newWidth = l[0].x; 1524 } else if(dY == 0) { 1525 newWidth = Math.min(l[0].x, l[1].x); 1526 } else { 1527 // System.out.print("gradient: " + (dY / dX)); 1528 newWidth = l[0].x + (y - l[0].y) * dX / dY; 1529 } 1530 // System.out.println("dY:" + dY + " dX:" + dX + " width:" + newWidth); 1531 if(newWidth < x) { 1532 continue; 1533 } 1534 if(newWidth < width) { 1535 width = newWidth; 1536 } 1537 } 1538 } 1539 return width - x; 1453 1540 } 1454 1541 … … 1556 1643 if (_text == null || _text.length() == 0) 1557 1644 return; 1558 1559 if (_textLayouts.size() < 1) { 1645 1646 if(_autoWrap || UserSettings.AutoWrap) { 1647 invalidateAll(); 1648 1649 rebuild(true); 1650 } else if (_textLayouts.size() < 1) { 1560 1651 rebuild(true); 1561 1652 // System.out.println("Error: " + _text); … … 2020 2111 2021 2112 public void justify(boolean fixWidth) { 2113 2114 // if autowrap is on, wrapping is done every time we draw 2115 if(UserSettings.AutoWrap) { 2116 return; 2117 } 2118 2022 2119 Integer width = FrameGraphics.getMaxFrameSize().width; 2023 2120 … … 2336 2433 return getText().split("\\s+")[0]; 2337 2434 } 2435 2436 public boolean getAutoWrap() { 2437 return _autoWrap; 2438 } 2439 2440 // workaround since true is the default value and would not be displayed normally 2441 public String getAutoWrapToSave() { 2442 if(!_autoWrap) { 2443 return null; 2444 } 2445 return "true"; 2446 } 2447 2448 public void setAutoWrap(boolean autoWrap) { 2449 _autoWrap = autoWrap; 2450 } 2338 2451 }
Note:
See TracChangeset
for help on using the changeset viewer.