List of usage examples for javax.swing.text BadLocationException getMessage
public String getMessage()
From source file:ch.zhaw.iamp.rct.ui.GrammarWindow.java
private void highlightErrorLine(int lineIndex, JTextComponent component) { String text = component.getText() + "\n"; int startPosition = 0; int endPosition = 0; for (int i = 0; i <= lineIndex; i++) { startPosition = endPosition > 0 ? endPosition + 1 : 0; endPosition = text.indexOf('\n', startPosition); }// www. j a va 2 s .c om try { DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter( Color.RED); component.getHighlighter().addHighlight(startPosition, endPosition, highlightPainter); } catch (BadLocationException ex) { System.out.println("Unable to highlight line with index " + lineIndex + ": " + ex.getMessage()); } }
From source file:org.astrojournal.logging.JTextPaneAppender.java
@Override public void append(final LogEvent event) { final String message = new String(this.getLayout().toByteArray(event)); try {/*from w w w. j a v a 2 s .c o m*/ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { if (jTextPane != null) { try { Document doc = jTextPane.getDocument(); if (event.getLevel().equals(Level.DEBUG)) { doc.insertString(doc.getLength(), message, styleSmall); } else if (event.getLevel().equals(Level.INFO)) { if (message.startsWith( AJMetaInfo.NAME.getInfo() + " " + AJMetaInfo.VERSION.getInfo())) { doc.insertString(doc.getLength(), message, styleSmallItalic); } else if (message.indexOf("Testing pdflatex") != -1) { String[] lines = message.split("\n"); doc.insertString(doc.getLength(), lines[0], styleBold); for (int i = 1; i < lines.length; i++) { doc.insertString(doc.getLength(), lines[i] + "\n", styleSmallItalic); } doc.insertString(doc.getLength(), "\n\n", styleRegular); } else if (StringUtils.countMatches(message, "\n") > 1) { doc.insertString(doc.getLength(), message, styleSmallItalic); } else if (!message.startsWith("\t")) { doc.insertString(doc.getLength(), message, styleBold); } else { doc.insertString(doc.getLength(), message, styleRegular); } } else if (event.getLevel().equals(Level.WARN)) { doc.insertString(doc.getLength(), message, styleBlue); } else { doc.insertString(doc.getLength(), message, styleRed); } } catch (BadLocationException e) { LOGGER.error(e, e); } } } catch (final Throwable t) { LOGGER.error("Unable to append log to text pane: " + t.getMessage() + ". Please see help menu for reporting this issue.", t); } } }); } catch (final IllegalStateException e) { LOGGER.error("Unable to append log to text pane: " + e.getMessage() + ". Please see help menu for reporting this issue.", e); } }
From source file:org.jwebsocket.ui.TestDialog.java
private void mLog(String aMessage) { synchronized (txaLog) { try {//from ww w . java 2 s.c o m int lMAX = 1000; int lLineCount = txaLog.getLineCount(); if (lLineCount > lMAX) { int lLinePosStart = txaLog.getLineEndOffset(0); int lLinePosEnd = txaLog.getLineEndOffset(lMAX); String lTextToReplace = txaLog.getText(lLinePosStart, txaLog.getText().length() - lLinePosStart); txaLog.replaceRange(lTextToReplace, 0, lLinePosEnd); } if (null != aMessage) { System.out.println(aMessage); } } catch (BadLocationException ex) { mLog(ex.getClass().getSimpleName() + ": " + ex.getMessage()); } } }
From source file:org.opendatakit.briefcase.ui.ScrollingStatusListDialog.java
private void appendToDocument(JTextComponent component, String msg) { Document doc = component.getDocument(); try {// w w w. j a v a2s. com doc.insertString(doc.getLength(), "\n" + msg, null); } catch (BadLocationException e) { LOG.error("Insertion failed: " + e.getMessage()); } }
From source file:org.zaproxy.zap.extension.ascan.CustomScanDialog.java
private JButton getAddCustomButton() { if (addCustomButton == null) { addCustomButton = new JButton(Constant.messages.getString("ascan.custom.button.pt.add")); addCustomButton.setEnabled(false); addCustomButton.addActionListener(new java.awt.event.ActionListener() { @Override//from w w w . j a v a 2 s .co m public void actionPerformed(java.awt.event.ActionEvent e) { // Add the selected injection point int userDefStart = getRequestField().getSelectionStart(); if (userDefStart >= 0) { int userDefEnd = getRequestField().getSelectionEnd(); Highlighter hl = getRequestField().getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED); try { Highlight hlt = (Highlight) hl.addHighlight(userDefStart, userDefEnd, painter); injectionPointModel.addElement(hlt); // Unselect the text getRequestField().setSelectionStart(userDefEnd); getRequestField().setSelectionEnd(userDefEnd); getRequestField().getCaret().setVisible(true); } catch (BadLocationException e1) { logger.error(e1.getMessage(), e1); } } } }); } return addCustomButton; }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
private JButton getAddCustomButton() { if (addCustomButton == null) { addCustomButton = new JButton(Constant.messages.getString("customFire.custom.button.pt.add")); addCustomButton.setEnabled(false); addCustomButton.addActionListener(new java.awt.event.ActionListener() { @Override/*from w ww. j a va2 s . c om*/ public void actionPerformed(java.awt.event.ActionEvent e) { // Add the selected injection point int userDefStart = getRequestField().getSelectionStart(); if (userDefStart >= 0) { int userDefEnd = getRequestField().getSelectionEnd(); Highlighter hl = getRequestField().getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED); try { Highlight hlt = (Highlight) hl.addHighlight(userDefStart, userDefEnd, painter); list.add("[" + userDefStart + "," + userDefEnd + "]:" + getRequestField().getText(userDefStart, userDefEnd - userDefStart)); injectionPointModel.addElement(hlt); // Unselect the text getRequestField().setSelectionStart(userDefEnd); getRequestField().setSelectionEnd(userDefEnd); getRequestField().getCaret().setVisible(true); } catch (BadLocationException e1) { logger.error(e1.getMessage(), e1); } } } }); } return addCustomButton; }
From source file:org.zaproxy.zap.extension.httppanel.view.syntaxhighlight.HttpPanelSyntaxHighlightTextArea.java
protected void highlight(int start, int end) { Highlighter hilite = this.getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY); try {//from w w w. jav a 2s . com // DOBIN removeAllHighlights(); hilite.addHighlight(start, end, painter); this.setCaretPosition(start); } catch (BadLocationException e) { log.error(e.getMessage(), e); } }
From source file:org.zaproxy.zap.extension.httppanel.view.syntaxhighlight.HttpPanelSyntaxHighlightTextArea.java
public Object highlight(int start, int end, HighlightPainter painter) { try {//from w w w . j a v a 2 s. c om Object highlightReference = getHighlighter().addHighlight(start, end, painter); this.setCaretPosition(start); return highlightReference; } catch (BadLocationException e) { log.error(e.getMessage(), e); } return null; }
From source file:pl.otros.logview.gui.message.editor.MessageColorizerEditor.java
public MessageColorizerEditor(PluginableElementsContainer<MessageColorizer> container, StatusObserver observer) {/* ww w . jav a2s . co m*/ this.container = container; statusObserver = observer; this.setLayout(new BorderLayout()); DefaultSyntaxKit.initKit(); editorPane = new JEditorPane(); JScrollPane comp = new JScrollPane(editorPane); JLabel propertyEditorLabel = new JLabel("Enter you message colorizer properties"); editorPane.setContentType("text/properties"); label = new JLabel(); String defaultContent = getDefaultContent(); try { editorPane.getDocument().insertString(0, defaultContent, null); } catch (BadLocationException e1) { LOGGER.severe(String.format("Can't set text: %s", e1.getMessage())); } deleyedSwingInvoke = new DelayedSwingInvoke() { @Override protected void performActionHook() { refreshView(); } }; DocumentListener documentListener = new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { deleyedSwingInvoke.performAction(); } @Override public void insertUpdate(DocumentEvent e) { deleyedSwingInvoke.performAction(); } @Override public void changedUpdate(DocumentEvent e) { } }; editorPane.getDocument().addDocumentListener(documentListener); JLabel textPaneLabel = new JLabel("Enter log message body"); textPane = new JTextPane(); textPane.getDocument().addDocumentListener(documentListener); JPanel north = new JPanel(new BorderLayout()); north.add(propertyEditorLabel, BorderLayout.NORTH); north.add(comp); JPanel south = new JPanel(new BorderLayout()); south.add(textPaneLabel, BorderLayout.NORTH); south.add(new JScrollPane(textPane)); JSplitPane jSplitPaneEditors = new JSplitPane(SwingConstants.HORIZONTAL, north, south); jSplitPaneEditors.setOneTouchExpandable(true); jSplitPaneEditors.setDividerLocation(0.5d); this.add(jSplitPaneEditors); this.add(label, BorderLayout.SOUTH); }
From source file:plugin.notes.gui.NotesView.java
private void handleBackspace() { // TODO: This sucks, clean it up Element elem;/* ww w. j av a 2s . c om*/ int pos = editor.getCaretPosition(); StyledDocument htmlDoc = editor.getStyledDocument(); try { if (pos > 0) { if ((editor.getSelectedText()) != null) { ExtendedHTMLEditorKit.delete(editor); return; } int sOffset = htmlDoc.getParagraphElement(pos).getStartOffset(); if (sOffset == editor.getSelectionStart()) { if (ExtendedHTMLEditorKit .checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.LI)) { elem = ExtendedHTMLEditorKit .getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition())); boolean content = false; int so = elem.getStartOffset(); int eo = elem.getEndOffset(); if ((so + 1) < eo) { char[] temp = editor.getText(so, eo - so).toCharArray(); for (char aTemp : temp) { if (!Character.isWhitespace(aTemp)) { content = true; } } } if (!content) { elem.getParentElement(); ExtendedHTMLEditorKit.removeTag(editor, elem); editor.setCaretPosition(sOffset - 1); return; } editor.setCaretPosition(editor.getCaretPosition() - 1); editor.moveCaretPosition(editor.getCaretPosition() - 2); editor.replaceSelection(""); return; } } editor.replaceSelection(""); } } catch (BadLocationException ble) { Logging.errorPrint(ble.getMessage(), ble); } }