Package com.ardor3d.extension.ui.text

Examples of com.ardor3d.extension.ui.text.StyleSpan


                tagStatus = TagStatus.NONE;
                // interpret tag:
                // BOLD
                if ("b".equalsIgnoreCase(currTagText)) {
                    // start a new bold span
                    buildingSpans.add(new StyleSpan(StyleConstants.KEY_BOLD, Boolean.TRUE, index, 0));
                } else if ("/b".equalsIgnoreCase(currTagText)) {
                    // find last BOLD entry and add length
                    endSpan(StyleConstants.KEY_BOLD, store, index, buildingSpans);
                }

                // ITALICS
                else if ("i".equalsIgnoreCase(currTagText)) {
                    // start a new italics span
                    buildingSpans.add(new StyleSpan(StyleConstants.KEY_ITALICS, Boolean.TRUE, index, 0));
                } else if ("/i".equalsIgnoreCase(currTagText)) {
                    // find last ITALICS entry and add length
                    endSpan(StyleConstants.KEY_ITALICS, store, index, buildingSpans);
                }

                // COLOR
                else if (currTagText.toLowerCase().startsWith("c=")) {
                    // start a new color span
                    try {
                        // parse a color
                        final String c = currTagText.substring(2);
                        buildingSpans.add(new StyleSpan(StyleConstants.KEY_COLOR, ColorRGBA.parseColor(c, null), index,
                                0));
                    } catch (final Exception e) {
                        e.printStackTrace();
                    }
                } else if ("/c".equalsIgnoreCase(currTagText)) {
                    // find last BOLD entry and add length
                    endSpan(StyleConstants.KEY_COLOR, store, index, buildingSpans);
                }

                // SIZE
                else if (currTagText.toLowerCase().startsWith("size=")) {
                    // start a new size span
                    try {
                        // parse a size
                        final int i = Integer.parseInt(currTagText.substring(5));
                        buildingSpans.add(new StyleSpan(StyleConstants.KEY_SIZE, i, index, 0));
                    } catch (final Exception e) {
                        e.printStackTrace();
                    }
                } else if ("/size".equalsIgnoreCase(currTagText)) {
                    // find last SIZE entry and add length
                    endSpan(StyleConstants.KEY_SIZE, store, index, buildingSpans);
                }

                // FAMILY
                else if (currTagText.toLowerCase().startsWith("f=")) {
                    // start a new family span
                    final String family = currTagText.substring(2);
                    buildingSpans.add(new StyleSpan(StyleConstants.KEY_FAMILY, family, index, 0));
                } else if ("/f".equalsIgnoreCase(currTagText)) {
                    // find last FAMILY entry and add length
                    endSpan(StyleConstants.KEY_FAMILY, store, index, buildingSpans);
                } else {
                    // not really a tag, so put it back.
                    rVal.append('[');
                    rVal.append(currTagText);
                    rVal.append(']');
                    tagStatus = TagStatus.NONE;
                }

                currTagText = "";
                continue;
            }

            // anything else
            rVal.append(token);
            index += token.length();
        }

        // close any remaining open tags
        while (!buildingSpans.isEmpty()) {
            final StyleSpan span = buildingSpans.getLast();
            endSpan(span.getStyle(), store, index, buildingSpans);
        }

        // return plain text
        return rVal.toString();
    }
View Full Code Here


    }

    private void endSpan(final String key, final List<StyleSpan> store, final int index,
            final LinkedList<StyleSpan> buildingSpans) {
        for (final Iterator<StyleSpan> it = buildingSpans.descendingIterator(); it.hasNext();) {
            final StyleSpan next = it.next();
            if (key.equals(next.getStyle())) {
                next.setSpanLength(index - next.getSpanStart());
                store.add(next);
                it.remove();
                break;
            }
        }
View Full Code Here

        // go through all chars and add starts and ends
        for (int index = 0, max = plainText.length(); index < max; index++) {
            // close markup
            while (!ends.isEmpty()) {
                final StyleSpan span = ends.get(0);
                if (span.getSpanStart() + span.getSpanLength() == index) {
                    builder.append(getMarkup(span, true));
                    ends.remove(0);
                } else {
                    break;
                }
            }

            // add starts
            while (!starts.isEmpty()) {
                final StyleSpan span = starts.get(0);
                if (span.getSpanStart() == index) {
                    builder.append(getMarkup(span, false));
                    ends.add(span);
                    starts.remove(0);
                    Collections.sort(ends, endSorter);
                } else {
                    break;
                }
            }

            builder.append(plainText.charAt(index));
        }

        // close any remaining markup:
        while (!ends.isEmpty()) {
            final StyleSpan span = ends.get(0);
            builder.append(getMarkup(span, true));
            ends.remove(0);
        }

        return builder.toString();
View Full Code Here

TOP

Related Classes of com.ardor3d.extension.ui.text.StyleSpan

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.