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);
}
}
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);
}
}
}
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);
}
}
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;
}
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) {
}
}
}
Aggregations