Changeset 247 for trunk/src/org/expeditee/items/Text.java
- Timestamp:
- 08/22/08 10:54:44 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Text.java
r242 r247 5 5 import java.awt.Dimension; 6 6 import java.awt.Font; 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.event.KeyEvent; … … 33 35 import org.expeditee.gui.FrameKeyboardActions; 34 36 import org.expeditee.gui.FrameMouseActions; 37 import org.expeditee.gui.FrameUtils; 35 38 import org.expeditee.math.ExpediteeJEP; 36 39 import org.nfunk.jep.Node; … … 255 258 invalidateAll(); 256 259 _text = new StringBuffer(text); 257 rebuild( false);260 rebuild(true); 258 261 invalidateAll(); 259 262 } … … 283 286 */ 284 287 public void prependText(String text) { 288 285 289 _text.insert(0, text); 286 290 rebuild(false); … … 295 299 */ 296 300 public void removeText(String text) { 297 298 301 if (_text.length() > 0 && _text.indexOf(text) == 0) { 299 // invalidateAll(); 302 //Need the invalidate all for dateStamp toggling 303 invalidateAll(); 300 304 _text.delete(0, text.length()); 301 305 } … … 1389 1393 if (getBackgroundColor() != null) { 1390 1394 Color bgc = getBackgroundColor(); 1391 if (_alpha > 0) 1395 if (_alpha > 0){ 1392 1396 bgc = new Color(bgc.getRed(), bgc.getGreen(), bgc.getBlue(), 1393 1397 _alpha); 1398 } 1394 1399 g.setColor(bgc); 1395 g.fill(getPolygon()); 1396 } 1397 1400 1401 Color gradientColor = getGradientColor(); 1402 if (gradientColor != null) { 1403 // The painting is not efficient enough for gradients... 1404 Shape s = getPolygon(); 1405 if (s != null) { 1406 Rectangle b = s.getBounds(); 1407 GradientPaint gp = new GradientPaint( 1408 (int) (b.x + b.width * 0.3), b.y, bgc, 1409 (int) (b.x + b.width * 1.3), b.y, gradientColor); 1410 g.setPaint(gp); 1411 } 1412 } 1413 1414 g.fillPolygon(getPolygon()); 1415 } 1416 1398 1417 if (hasVisibleBorder()) { 1399 1418 g.setColor(getPaintBorderColor()); … … 1402 1421 g.drawPolygon(getPolygon()); 1403 1422 } 1404 1423 1405 1424 if (isHighlighted()) { 1406 1425 g.setColor(getPaintHighlightColor()); … … 1567 1586 } 1568 1587 } 1588 FrameUtils.setLastEdited(this); 1569 1589 rebuild(true); 1570 1590 DisplayIO.setCursorPosition(newPoint.x, newPoint.y, false); … … 1831 1851 } 1832 1852 1833 public void setRightMargin(int i) {1834 setWidth(i - getX() - Item.MARGIN_LEFT);1835 }1836 1837 1853 @Override 1838 1854 public void calculate(String formula) { … … 1846 1862 String lowercaseFormula = formula.toLowerCase(); 1847 1863 ExpediteeJEP myParser = new ExpediteeJEP(); 1864 1865 int nextVarNo = 1; 1866 1848 1867 // Add variables from the containing rectangle if the item being 1849 1868 // calculated is inside the enclosing rectangle 1850 1869 Collection<Item> enclosed = getItemsInSameEnclosure(); 1851 1870 for (Item i : enclosed) { 1852 if (i instanceof Text) { 1871 if(i == this) 1872 continue; 1873 if (i instanceof Text && !i.isAnnotation()) { 1853 1874 AttributeValuePair pair = new AttributeValuePair(i.getText()); 1854 1875 if (pair.hasPair()) { 1855 1876 try { 1856 myParser.addVariable(pair.getAttribute(), pair 1857 .getDoubleValue()); 1877 double value = pair 1878 .getDoubleValue(); 1879 myParser.addVariable(pair.getAttribute(), value); 1880 //myParser.addVariable("$" + nextVarNo++, value); 1881 } catch (NumberFormatException nfe) { 1882 continue; 1883 } catch (Exception e) { 1884 e.printStackTrace(); 1885 } 1886 }else{ 1887 try { 1888 double value = pair 1889 .getDoubleValue(); 1890 myParser.addVariable("$" + nextVarNo++, value); 1891 } catch (NumberFormatException nfe) { 1892 continue; 1858 1893 } catch (Exception e) { 1859 1894 e.printStackTrace(); … … 1898 1933 1899 1934 /** 1900 * Gets items which are in the same enclosure as this item. 1901 * TODO: Improve the efficiency of this method 1935 * Gets items which are in the same enclosure as this item. TODO: Improve 1936 * the efficiency of this method 1937 * 1902 1938 * @return 1903 1939 */ … … 1910 1946 // Go through all the enclosures looking for one that includes this 1911 1947 // shape 1912 if (!seen.contains(i) && 1948 if (!seen.contains(i) && i.isEnclosed()) { 1913 1949 seen.addAll(i.getEnclosingDots()); 1914 1950 Collection<Item> enclosed = i.getEnclosedItems(); 1915 //Check if we have found an enclosure containing this item 1916 //Check it is smaller than any other enclosure found containing this item 1917 if(enclosed.contains(this) && i.getEnclosedArea() < enclosureArea){ 1951 // Check if we have found an enclosure containing this item 1952 // Check it is smaller than any other enclosure found containing 1953 // this item 1954 if (enclosed.contains(this) 1955 && i.getEnclosedArea() < enclosureArea) { 1918 1956 sameEnclosure = enclosed; 1919 1957 } … … 1921 1959 } 1922 1960 1923 if (sameEnclosure == null)1961 if (sameEnclosure == null) 1924 1962 return new LinkedList<Item>(); 1925 1963 1926 1964 return sameEnclosure; 1927 1965 } 1928 1966 1929 1967 /** 1930 * Returns true if this text item should be recalculated when t is modified1968 * Returns true if this text item should be recalculated when it is modified 1931 1969 */ 1932 1970 public boolean recalculateWhenChanged() { 1933 if ( !isAnnotation()1934 && (hasFormula() || getText().contains(":") || isLineEnd()))1971 if (/*!isAnnotation() 1972 && */(hasFormula() || getText().contains(":") || isLineEnd())) 1935 1973 return true; 1936 1974 try {
Note:
See TracChangeset
for help on using the changeset viewer.