Ignore:
Timestamp:
08/08/08 10:33:15 (16 years ago)
Author:
ra33
Message:

Added functionality allowing users to do PieCharts, also charts now listen for changes on the dataFrame and refresh when needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Text.java

    r196 r199  
    216216        public void setJustification(Justification just) {
    217217                _justification = just;
    218                 rejustify();
     218                rebuild(true);
    219219        }
    220220
     
    663663
    664664                        // if a rebuild is required
    665                         if (_lineBreaker == null)
    666                                 rebuild(true);
    667                         else
    668                                 rejustify();
     665                        rebuild(true, false);
    669666
    670667                        // determine the new position the cursor should have
     
    11941191        // This needs to be fixed!!
    11951192        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) {
    11961203                // TODO make this more efficient so it only clears annotation list when
    11971204                // it really has to
     
    12121219                }
    12131220
    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                }
    12181228
    12191229                float width = Float.MAX_VALUE;
     
    12611271                updatePolygon();
    12621272
    1263         }
    1264 
    1265         private void rejustify() {
    1266                 // if there is no text, there is nothing to do
    1267                 if (_text == null || _text.length() == 0)
    1268                         return;
    1269 
    1270                 // only recreate linebreaker if necessary
    1271                 if (_lineBreaker == null) {
    1272                         rebuild(true);
    1273                         return;
    1274 
    1275                         /*
    1276                          * AttributedString paragraphText = new
    1277                          * 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 offset
    1294                 _lineOffsets.add(0);
    1295 
    1296                 TextLayout layout;
    1297                 _lineBreaker.setPosition(0);
    1298 
    1299                 // --- Get the output of the LineBreakMeasurer and store it in a
    1300                 while ((layout = _lineBreaker.nextLayout(width)) != null) {
    1301                         // for some reason lineBreaker will not break on newline
    1302                         // characters
    1303                         // so they have to be check manually
    1304                         int start = _lineOffsets.get(_lineOffsets.size() - 1);
    1305 
    1306                         // check through the current line for newline characters
    1307                         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.full
    1318                                         && _lineBreaker.getPosition() < _text.length())
    1319                                 layout = layout.getJustifiedLayout(width);
    1320 
    1321                         _textLayouts.add(layout);
    1322                 }
    1323 
    1324                 updatePolygon();
    13251273        }
    13261274
     
    18711819        @Override
    18721820        public void calculate(String formula) {
     1821                if (FrameGraphics.isXRayMode())
     1822                        return;
     1823
    18731824                super.calculate(formula);
    18741825                if (formula == null || formula.length() == 0) {
     
    18791830                myParser.addVariables(this.getParentOrCurrentFrame());
    18801831                String linkedFrame = getAbsoluteLink();
    1881                 //Add the relative frame variable if the item is linked
     1832                // Add the relative frame variable if the item is linked
    18821833                if (linkedFrame != null) {
    18831834                        Frame frame = FrameIO.LoadFrame(linkedFrame);
    18841835                        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());
    18961848                                myParser.addVectorVariable(enclosed, "$box");
    18971849                        }
     
    19071859                } catch (Throwable e) {
    19081860                        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         */
    19131868        public boolean recalculateWhenChanged() {
    1914                 if (!isAnnotation() && (hasFormula() || getText().contains(":") || isLineEnd()))
     1869                if (!isAnnotation()
     1870                                && (hasFormula() || getText().contains(":") || isLineEnd()))
    19151871                        return true;
    19161872                try {
Note: See TracChangeset for help on using the changeset viewer.