Search in sources :

Example 66 with Element

use of javax.swing.text.Element in project processdash by dtuma.

the class PersonLookupDialog method processUserInterfaceChanges.

private void processUserInterfaceChanges(HTMLDocument htmlDoc) {
    // if we find a title in the HTML doc, use it as the title of the dialog
    Object docTitle = htmlDoc.getProperty(HTMLDocument.TitleProperty);
    if (docTitle != null)
        dialog.setTitle(String.valueOf(docTitle));
    // enlarge the dialog if necessary to fit the contents.
    Dimension pref = html.getPreferredSize();
    Dimension curr = scrollPane.getViewport().getSize();
    Dimension d = dialog.getSize();
    // First, test to see if the dialog needs to be taller.  If so,
    // enlarge it.
    double yDelta = pref.getHeight() - curr.getHeight();
    if (yDelta > 0) {
        d.height = (int) Math.min(d.height + yDelta + 1, MAX_DIALOG_HEIGHT);
        dialog.setSize(d);
        dialog.validate();
        // changing the dialog height could have caused a vertical
        // scrollbar to appear or disappear.  Just in case, get the new
        // size of the viewport so the horizontal resizing logic can use it.
        curr = scrollPane.getViewport().getSize();
    }
    // Now test to see if the dialog needs to be wider.  If so, enlarge it.
    double xDelta = pref.getWidth() - curr.getWidth();
    if (xDelta > 0) {
        d.width = (int) (d.width + xDelta + 4);
        dialog.setSize(d);
        dialog.validate();
    }
    // stays in the same location as before
    if (yDelta > 0 || xDelta > 0) {
        Point location = dialog.getLocation();
        //
        location.setLocation(Math.max(0, location.x - Math.max(0, xDelta / 2)), Math.max(0, location.y - Math.max(0, yDelta / 2)));
        dialog.setLocation(location);
    }
    // scan the HTML document, and arrange for all text fields to perform
    // a "select all" when they receive the focus.  Also, arrange for all
    // buttons to accept Enter as an activation key.
    tweakInputFields(html);
    // if one of the elements on the form has the ID "grabFocus," arrange
    // for it to receive focus immediately.
    Element e = htmlDoc.getElement("grabFocus");
    JComponent c = findComponentForInputElement(e);
    if (c != null)
        new GrabFocus(c);
}
Also used : Element(javax.swing.text.Element) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 67 with Element

use of javax.swing.text.Element in project knime-core by knime.

the class AbstractRuleParser method parse.

/**
 * {@inheritDoc}
 */
@Override
public ParseResult parse(final RSyntaxDocument doc, final String style) {
    if (isNotApplicable(style)) {
        return new DefaultParseResult(this);
    }
    DefaultParseResult res = new DefaultParseResult(this);
    Element rootElement = doc.getDefaultRootElement();
    boolean wasCatchAllRule = false;
    for (int line = 0; line < rootElement.getElementCount(); ++line) {
        String lastString = null;
        StringBuilder sb = new StringBuilder();
        // Go through the tokens
        Token token = doc.getTokenListForLine(line);
        while (token != null && token.isPaintable()) {
            String lexeme = token.getLexeme();
            // If it is an operator, make it a reserved word.
            if (getOperators().contains(lexeme)) {
                token.setType(TokenTypes.RESERVED_WORD);
                token.setLanguageIndex(0);
            }
            sb.append(lexeme);
            if (lexeme.length() > 0 && lexeme.charAt(0) == '"' && lexeme.charAt(lexeme.length() - 1) == '"') {
                lastString = lexeme;
            }
            token = token.getNextToken();
        }
        try {
            String lineText = sb.toString();
            // Check for potential error in outcomes.
            if (lineText.trim().endsWith("\"") && m_warnOnColRefsInStrings) {
                String lastContent = lastString != null && lastString.length() > 2 ? lastString.substring(1, lastString.length() - 1) : lastString;
                // ENH better check
                if (lastContent != null && lastContent.endsWith("$") && lastContent.charAt(0) == '$') {
                    DefaultParserNotice notice = new DefaultParserNotice(this, "You might be referring to a column or flow variable, although no String " + "interpolation is implemented, you might want to " + "remove the quotes around the reference.", line, doc.getTokenListForLine(line).getOffset() + lineText.lastIndexOf(lastContent), lastContent.length());
                    notice.setLevel(ParserNotice.Level.WARNING);
                    res.addNotice(notice);
                }
            }
            if (!lineText.isEmpty()) {
                wasCatchAllRule |= parseAndWarn(doc, res, wasCatchAllRule, line, lineText);
            }
        } catch (ParseException e) {
            DefaultParserNotice notice;
            if (e.getErrorOffset() >= sb.length()) {
                notice = new DefaultParserNotice(this, e.getMessage(), line);
            } else {
                notice = new DefaultParserNotice(this, e.getMessage(), line, doc.getTokenListForLine(line).getOffset() + e.getErrorOffset(), sb.length() - e.getErrorOffset());
            }
            res.addNotice(notice);
        }
    }
    return res;
}
Also used : DefaultParseResult(org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult) Element(javax.swing.text.Element) Token(org.fife.ui.rsyntaxtextarea.Token) DefaultParserNotice(org.fife.ui.rsyntaxtextarea.parser.DefaultParserNotice) ParseException(java.text.ParseException)

Example 68 with Element

use of javax.swing.text.Element in project blue by kunstmusik.

the class BSBCompletionProvider method getRowFirstNonWhite.

static int getRowFirstNonWhite(StyledDocument doc, int offset) throws BadLocationException {
    Element lineElement = doc.getParagraphElement(offset);
    int start = lineElement.getStartOffset();
    while (start + 1 < lineElement.getEndOffset()) {
        try {
            if (doc.getText(start, 1).charAt(0) != ' ') {
                break;
            }
        } catch (BadLocationException ex) {
            throw (BadLocationException) new BadLocationException("calling getText(" + start + ", " + (start + 1) + ") on doc of length: " + doc.getLength(), start).initCause(ex);
        }
        start++;
    }
    return start;
}
Also used : Element(javax.swing.text.Element) BadLocationException(javax.swing.text.BadLocationException)

Example 69 with Element

use of javax.swing.text.Element in project com.revolsys.open by revolsys.

the class TextPane method getLineStartOffset.

public int getLineStartOffset(final int line) {
    if (line < 0) {
        return -1;
    } else {
        final Element map = getDocument().getDefaultRootElement();
        final Element lineElem = map.getElement(line);
        if (lineElem == null) {
            return -1;
        } else {
            return lineElem.getStartOffset();
        }
    }
}
Also used : Element(javax.swing.text.Element)

Example 70 with Element

use of javax.swing.text.Element in project mdw-designer by CenturyLinkCloud.

the class ExportHelper method printHtmlParagraphsPdf.

private void printHtmlParagraphsPdf(Section section, String content, int parentLevel) throws Exception {
    if (content == null || content.length() == 0)
        return;
    String vContent = content;
    if (isBase64Encoded(content) || "true".equals(System.getProperty("mdw.designer.force.msword"))) {
        byte[] docBytes = decodeBase64(content);
        vContent = new DocxBuilder(docBytes).toHtml();
        vContent = vContent.replaceAll("&nbsp;", "&#160;");
    }
    JEditorPane documentation = new JEditorPane();
    documentation.setContentType("text/html");
    documentation.setText(vContent);
    javax.swing.text.Document swingdoc = documentation.getDocument();
    Element[] elements = swingdoc.getRootElements();
    for (Element e : elements) {
        Object gen = generateElementHtml(e, 0, normalFont);
        addSectionContentPdf(section, gen, parentLevel);
    }
}
Also used : DocxBuilder(com.centurylink.mdw.designer.utils.DocxBuilder) AbstractElement(javax.swing.text.AbstractDocument.AbstractElement) Element(javax.swing.text.Element) JEditorPane(javax.swing.JEditorPane)

Aggregations

Element (javax.swing.text.Element)100 BadLocationException (javax.swing.text.BadLocationException)35 Point (java.awt.Point)19 AttributeSet (javax.swing.text.AttributeSet)15 Document (javax.swing.text.Document)15 HTMLDocument (javax.swing.text.html.HTMLDocument)11 FontMetrics (java.awt.FontMetrics)6 Dimension (java.awt.Dimension)5 Rectangle (java.awt.Rectangle)5 View (javax.swing.text.View)5 Font (java.awt.Font)4 Insets (java.awt.Insets)4 IOException (java.io.IOException)4 AbstractDocument (javax.swing.text.AbstractDocument)4 StyledDocument (javax.swing.text.StyledDocument)4 java.awt (java.awt)3 Objects (java.util.Objects)3 javax.swing (javax.swing)3 AbstractElement (javax.swing.text.AbstractDocument.AbstractElement)3 HTML (javax.swing.text.html.HTML)3