Search in sources :

Example 71 with BadLocationException

use of javax.swing.text.BadLocationException in project zaproxy by zaproxy.

the class HttpPanelTextArea method highlight.

protected void highlight(int start, int end) {
    Highlighter hilite = this.getHighlighter();
    HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY);
    try {
        // DOBIN
        removeAllHighlights();
        hilite.addHighlight(start, end, painter);
        this.setCaretPosition(start);
    } catch (BadLocationException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 72 with BadLocationException

use of javax.swing.text.BadLocationException in project zaproxy by zaproxy.

the class HttpPanelSyntaxHighlightTextArea method highlightEntryParser.

// Parse the TextArea data and search the HighlightEntry strings
// Highlight all found strings
private void highlightEntryParser(HighlightSearchEntry entry) {
    String text;
    int lastPos = 0;
    text = this.getText();
    Highlighter hilite = this.getHighlighter();
    HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(entry.getColor());
    while ((lastPos = text.indexOf(entry.getToken(), lastPos)) > -1) {
        try {
            hilite.addHighlight(lastPos, lastPos + entry.getToken().length(), painter);
            lastPos += entry.getToken().length();
        } catch (BadLocationException e) {
            log.warn("Could not highlight entry", e);
        }
    }
}
Also used : HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) BadLocationException(javax.swing.text.BadLocationException) DefaultHighlighter(javax.swing.text.DefaultHighlighter) Highlighter(javax.swing.text.Highlighter)

Example 73 with BadLocationException

use of javax.swing.text.BadLocationException in project intellij-community by JetBrains.

the class TestNGConfigurationModel method apply.

private void apply(TestData data, Module module) {
    data.TEST_OBJECT = type.getType();
    if (TestType.GROUP == type) {
        data.GROUP_NAME = getText(TestType.GROUP);
        data.PACKAGE_NAME = "";
        data.MAIN_CLASS_NAME = "";
        data.METHOD_NAME = "";
        data.SUITE_NAME = "";
    } else if (TestType.PACKAGE == type) {
        data.PACKAGE_NAME = getText(TestType.PACKAGE);
        data.GROUP_NAME = "";
        data.MAIN_CLASS_NAME = "";
        data.METHOD_NAME = "";
        data.SUITE_NAME = "";
    } else if (TestType.METHOD == type || TestType.CLASS == type || TestType.SOURCE == type) {
        String className = getText(TestType.CLASS);
        data.GROUP_NAME = "";
        data.SUITE_NAME = "";
        if (TestType.METHOD == type || TestType.SOURCE == type)
            data.METHOD_NAME = getText(TestType.METHOD);
        PsiClass psiClass = !getProject().isDefault() && !StringUtil.isEmptyOrSpaces(className) ? JUnitUtil.findPsiClass(className, module, getProject()) : null;
        if (psiClass != null && psiClass.isValid())
            data.setMainClass(psiClass);
        else
            data.MAIN_CLASS_NAME = className;
    } else if (TestType.SUITE == type) {
        data.SUITE_NAME = getText(TestType.SUITE);
        data.PACKAGE_NAME = "";
        data.GROUP_NAME = "";
        data.MAIN_CLASS_NAME = "";
        data.METHOD_NAME = "";
    } else if (TestType.PATTERN == type) {
        final LinkedHashSet<String> set = new LinkedHashSet<>();
        final String[] patterns = getText(TestType.PATTERN).split("\\|\\|");
        for (String pattern : patterns) {
            if (pattern.length() > 0) {
                set.add(pattern);
            }
        }
        data.setPatterns(set);
    }
    try {
        data.PROPERTIES_FILE = propertiesFileDocument.getText(0, propertiesFileDocument.getLength());
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
    try {
        data.OUTPUT_DIRECTORY = outputDirectoryDocument.getText(0, outputDirectoryDocument.getLength());
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiClass(com.intellij.psi.PsiClass) BadLocationException(javax.swing.text.BadLocationException)

Example 74 with BadLocationException

use of javax.swing.text.BadLocationException in project intellij-community by JetBrains.

the class HtmlUnknownTagInspection method createOptionsPanel.

@NotNull
protected static JComponent createOptionsPanel(@NotNull final HtmlUnknownElementInspection inspection) {
    final JPanel result = new JPanel(new BorderLayout());
    final JPanel internalPanel = new JPanel(new BorderLayout());
    result.add(internalPanel, BorderLayout.NORTH);
    final Ref<FieldPanel> panelRef = new Ref<>();
    final FieldPanel additionalAttributesPanel = new FieldPanel(null, null, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            Messages.showTextAreaDialog(panelRef.get().getTextField(), StringUtil.wordsToBeginFromUpperCase(inspection.getPanelTitle()), inspection.getClass().getSimpleName(), s -> reparseProperties(s), strings -> StringUtil.join(strings, ","));
        }
    }, null);
    ((JButton) additionalAttributesPanel.getComponent(1)).setIcon(PlatformIcons.OPEN_EDIT_DIALOG_ICON);
    panelRef.set(additionalAttributesPanel);
    additionalAttributesPanel.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            final Document document = e.getDocument();
            try {
                final String text = document.getText(0, document.getLength());
                if (text != null) {
                    inspection.updateAdditionalEntries(text.trim());
                }
            } catch (BadLocationException e1) {
                inspection.getLogger().error(e1);
            }
        }
    });
    final JCheckBox checkBox = new JCheckBox(inspection.getCheckboxTitle());
    checkBox.setSelected(inspection.isCustomValuesEnabled());
    checkBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final boolean b = checkBox.isSelected();
            if (b != inspection.isCustomValuesEnabled()) {
                inspection.enableCustomValues(b);
                additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
            }
        }
    });
    internalPanel.add(checkBox, BorderLayout.NORTH);
    internalPanel.add(additionalAttributesPanel, BorderLayout.CENTER);
    additionalAttributesPanel.setPreferredSize(new Dimension(150, additionalAttributesPanel.getPreferredSize().height));
    additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
    additionalAttributesPanel.setText(inspection.getAdditionalEntries());
    return result;
}
Also used : ActionListener(java.awt.event.ActionListener) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) NonNls(org.jetbrains.annotations.NonNls) ConfigurableTemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.ConfigurableTemplateLanguageFileViewProvider) TemplateLanguageUtil(com.intellij.psi.templateLanguages.TemplateLanguageUtil) Nls(org.jetbrains.annotations.Nls) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Messages(com.intellij.openapi.ui.Messages) DocumentEvent(javax.swing.event.DocumentEvent) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PlatformIcons(com.intellij.util.PlatformIcons) StringUtil(com.intellij.openapi.util.text.StringUtil) FileViewProvider(com.intellij.psi.FileViewProvider) FieldPanel(com.intellij.ui.FieldPanel) BadLocationException(javax.swing.text.BadLocationException) LocalQuickFixOnPsiElement(com.intellij.codeInspection.LocalQuickFixOnPsiElement) ActionEvent(java.awt.event.ActionEvent) java.awt(java.awt) ChangeTemplateDataLanguageAction(com.intellij.psi.templateLanguages.ChangeTemplateDataLanguageAction) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Function(com.intellij.util.Function) Document(javax.swing.text.Document) NotNull(org.jetbrains.annotations.NotNull) LangBundle(com.intellij.lang.LangBundle) Ref(com.intellij.openapi.util.Ref) DocumentAdapter(com.intellij.ui.DocumentAdapter) javax.swing(javax.swing) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener) FieldPanel(com.intellij.ui.FieldPanel) BadLocationException(javax.swing.text.BadLocationException) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with BadLocationException

use of javax.swing.text.BadLocationException in project ACS by ACS-Community.

the class FeedbackArea method append.

protected void append(String feedback) {
    Document doc = outputArea.getDocument();
    if (doc == null) {
        return;
    }
    try {
        doc.insertString(doc.getLength(), feedback, null);
    } catch (BadLocationException exc) {
    }
    int newCaretPosition = outputArea.getCaretPosition();
    int newLength = doc.getLength();
    int tooMuch = Math.max(newLength - maxLength, 0);
    if (newLength > maxLength) {
        newCaretPosition -= (newLength - maxLength);
    }
    int caretPosition;
    if (!scrollLock)
        caretPosition = doc.getLength() - tooMuch;
    else {
        if (newCaretPosition >= 0)
            caretPosition = newCaretPosition;
        else
            caretPosition = 0;
    }
    outputArea.setCaretPosition(caretPosition);
    if (newLength > maxLength) {
        try {
            doc.remove(0, newLength - maxLength);
        } catch (BadLocationException exc1) {
        }
    }
}
Also used : PlainDocument(javax.swing.text.PlainDocument) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

BadLocationException (javax.swing.text.BadLocationException)88 Document (javax.swing.text.Document)24 Element (javax.swing.text.Element)13 Point (java.awt.Point)10 IOException (java.io.IOException)9 DefaultHighlighter (javax.swing.text.DefaultHighlighter)8 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)7 Highlighter (javax.swing.text.Highlighter)7 ArrayList (java.util.ArrayList)6 DocumentEvent (javax.swing.event.DocumentEvent)6 StyledDocument (javax.swing.text.StyledDocument)6 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)5 Dimension (java.awt.Dimension)4 Rectangle (java.awt.Rectangle)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 File (java.io.File)4 Date (java.util.Date)4 Style (javax.swing.text.Style)4 HTMLDocument (javax.swing.text.html.HTMLDocument)4