Changeset 199 for trunk/src/org/expeditee/items/Text.java
- Timestamp:
- 08/08/08 10:33:15 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Text.java
r196 r199 216 216 public void setJustification(Justification just) { 217 217 _justification = just; 218 re justify();218 rebuild(true); 219 219 } 220 220 … … 663 663 664 664 // if a rebuild is required 665 if (_lineBreaker == null) 666 rebuild(true); 667 else 668 rejustify(); 665 rebuild(true, false); 669 666 670 667 // determine the new position the cursor should have … … 1194 1191 // This needs to be fixed!! 1195 1192 private void rebuild(boolean limitWidth) { 1193 rebuild(limitWidth, true); 1194 } 1195 1196 /** 1197 * 1198 * @param limitWidth 1199 * @param newLinebreakerAlways 1200 * true if a new line breaker should always be created. 1201 */ 1202 private void rebuild(boolean limitWidth, boolean newLinebreakerAlways) { 1196 1203 // TODO make this more efficient so it only clears annotation list when 1197 1204 // it really has to … … 1212 1219 } 1213 1220 1214 AttributedString paragraphText = new AttributedString(_text.toString()); 1215 paragraphText.addAttribute(TextAttribute.FONT, getPaintFont()); 1216 _lineBreaker = new LineBreakMeasurer(paragraphText.getIterator(), 1217 new FontRenderContext(null, true, true)); 1221 if (_lineBreaker == null || newLinebreakerAlways) { 1222 AttributedString paragraphText = new AttributedString(_text 1223 .toString()); 1224 paragraphText.addAttribute(TextAttribute.FONT, getPaintFont()); 1225 _lineBreaker = new LineBreakMeasurer(paragraphText.getIterator(), 1226 new FontRenderContext(null, true, true)); 1227 } 1218 1228 1219 1229 float width = Float.MAX_VALUE; … … 1261 1271 updatePolygon(); 1262 1272 1263 }1264 1265 private void rejustify() {1266 // if there is no text, there is nothing to do1267 if (_text == null || _text.length() == 0)1268 return;1269 1270 // only recreate linebreaker if necessary1271 if (_lineBreaker == null) {1272 rebuild(true);1273 return;1274 1275 /*1276 * AttributedString paragraphText = new1277 * AttributedString(_text.toString());1278 * paragraphText.addAttribute(TextAttribute.FONT, getPaintFont());1279 * _lineBreaker = new LineBreakMeasurer(paragraphText.getIterator(),1280 * new FontRenderContext(null, true, true));1281 */1282 }1283 1284 float width = Float.MAX_VALUE;1285 if (getWidth() > 0)1286 width = getWidth();1287 // else if (getMaxWidth()>0)1288 // width = Math.max(50, getMaxWidth() - getX()1289 // - Item.MARGIN_RIGHT);1290 1291 _textLayouts.clear();1292 _lineOffsets.clear();1293 // the first line always has a 0 offset1294 _lineOffsets.add(0);1295 1296 TextLayout layout;1297 _lineBreaker.setPosition(0);1298 1299 // --- Get the output of the LineBreakMeasurer and store it in a1300 while ((layout = _lineBreaker.nextLayout(width)) != null) {1301 // for some reason lineBreaker will not break on newline1302 // characters1303 // so they have to be check manually1304 int start = _lineOffsets.get(_lineOffsets.size() - 1);1305 1306 // check through the current line for newline characters1307 for (int i = start + 1; i < _text.length(); i++) {1308 if (_text.charAt(i) == '\n') {// || c == '\t'){1309 _lineBreaker.setPosition(start);1310 layout = _lineBreaker.nextLayout(width, i, false);1311 break;1312 }1313 }1314 1315 _lineOffsets.add(_lineBreaker.getPosition());1316 1317 if (getWidth() > 0 && getJustification() == Justification.full1318 && _lineBreaker.getPosition() < _text.length())1319 layout = layout.getJustifiedLayout(width);1320 1321 _textLayouts.add(layout);1322 }1323 1324 updatePolygon();1325 1273 } 1326 1274 … … 1871 1819 @Override 1872 1820 public void calculate(String formula) { 1821 if (FrameGraphics.isXRayMode()) 1822 return; 1823 1873 1824 super.calculate(formula); 1874 1825 if (formula == null || formula.length() == 0) { … … 1879 1830 myParser.addVariables(this.getParentOrCurrentFrame()); 1880 1831 String linkedFrame = getAbsoluteLink(); 1881 // Add the relative frame variable if the item is linked1832 // Add the relative frame variable if the item is linked 1882 1833 if (linkedFrame != null) { 1883 1834 Frame frame = FrameIO.LoadFrame(linkedFrame); 1884 1835 myParser.addVariables(frame); 1885 //If the frame is linked add vector variable for the frame 1886 if(lowercaseFormula.contains("$frame")){ 1887 myParser.addVectorVariable(frame.getNonAnnotationItems(true), "$frame"); 1888 } 1889 } 1890 //Add the relative box variable if this item is a line end 1891 if (this.isLineEnd()){ 1892 //if its a line end add the enclosed stuff as an @variable 1893 if(lowercaseFormula.contains("$box")){ 1894 Collection<Item> enclosed = FrameUtils.getItemsEnclosedBy( 1895 this.getParentOrCurrentFrame(), this.getEnclosedShape()); 1836 // If the frame is linked add vector variable for the frame 1837 if (lowercaseFormula.contains("$frame")) { 1838 myParser.addVectorVariable(frame.getNonAnnotationItems(true), 1839 "$frame"); 1840 } 1841 } 1842 // Add the relative box variable if this item is a line end 1843 if (this.isLineEnd()) { 1844 // if its a line end add the enclosed stuff as an @variable 1845 if (lowercaseFormula.contains("$box")) { 1846 Collection<Item> enclosed = FrameUtils.getItemsEnclosedBy(this 1847 .getParentOrCurrentFrame(), this.getEnclosedShape()); 1896 1848 myParser.addVectorVariable(enclosed, "$box"); 1897 1849 } … … 1907 1859 } catch (Throwable e) { 1908 1860 this.setText(getFormula()); 1909 //this.setFormula(null); 1910 } 1911 } 1912 1861 // this.setFormula(null); 1862 } 1863 } 1864 1865 /** 1866 * Returns true if this text item should be recalculated when t is modified 1867 */ 1913 1868 public boolean recalculateWhenChanged() { 1914 if (!isAnnotation() && (hasFormula() || getText().contains(":") || isLineEnd())) 1869 if (!isAnnotation() 1870 && (hasFormula() || getText().contains(":") || isLineEnd())) 1915 1871 return true; 1916 1872 try {
Note:
See TracChangeset
for help on using the changeset viewer.