/** * {@inheritDoc} */ @Override public char charAt(int index) { if (index<0 || index>=length()) { throw new IndexOutOfBoundsException("Index " + index + " is not in range [0-" + length() + ")"); } try { return doc.charAt(start+index); } catch (BadLocationException ble) { throw new IndexOutOfBoundsException(ble.toString()); } }
ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int pos = area.getCaretPosition(); try { Rectangle r = area.modelToView(pos); menu.show(area, r.x, r.y); } catch (BadLocationException ex) { System.out.print(ex.toString()); } } };
/** Document itself is encoded as Unicode, but in * the document prolog is an encoding attribute. * @return java encoding names ("UTF8", "ASCII", etc.) or null if no guess */ public static String detectEncoding(Document doc) throws IOException { if (doc == null) return null; try { String text = doc.getText(0, doc.getLength() > EXPECTED_PROLOG_LENGTH ? EXPECTED_PROLOG_LENGTH : doc.getLength() ); InputStream in = new ByteArrayInputStream(text.getBytes()); return detectEncoding(in); } catch (BadLocationException ex) { throw new RuntimeException(ex.toString()); } }
/** * Sets the text of this AutoCompleteDocument to the given text. * * @param text the text that will be set for this document */ private void setText(String text) { try { // remove all text and insert the completed string delegate.remove(0, getLength()); delegate.insertString(0, text, null); } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } }
/** * Sets the text of this AutoCompleteDocument to the given text. * * @param text the text that will be set for this document */ private void setText(String text) { try { // remove all text and insert the completed string delegate.remove(0, getLength()); delegate.insertString(0, text, null); } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } }
/** * Sets the text of this AutoCompleteDocument to the given text. * * @param text the text that will be set for this document */ private void setText(String text) { try { // remove all text and insert the completed string delegate.remove(0, getLength()); delegate.insertString(0, text, null); } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } }
throw new IOException(ble.toString());
private void caretUpdate(javax.swing.event.CaretEvent evt) { try { int pos = editor.getCaretPosition(); int line = getLineOfOffset(pos); int lineStartOffset = getLineStartOffset(line); caretInfoLabel.setText((line + 1) + ":" + (pos - lineStartOffset + 1)); } catch (BadLocationException e) { caretInfoLabel.setText(e.toString()); } }
private void setText(final String text) { try { // remove all text and insert the completed string super.remove(0, getLength()); super.insertString(0, text, null); } catch (final BadLocationException e) { throw new RuntimeException(e.toString()); } }
/** * {@inheritDoc} */ @Override public char charAt(int index) { if (index<0 || index>=length()) { throw new IndexOutOfBoundsException("Index " + index + " is not in range [0-" + length() + ")"); } try { return doc.charAt(start+index); } catch (BadLocationException ble) { throw new IndexOutOfBoundsException(ble.toString()); } }
void protect(int start, int end) { try { positions.put(doc.createPosition(start), doc.createPosition(end)); } catch (BadLocationException ble) { JTerm.out.println(TextColor.ERROR, ble.toString()); } }
private void setText(final String pText) { try { // remove all text and insert the completed string super.remove(0, getLength()); super.insertString(0, pText, null); } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } }
@Override public void run() { try { StyleConstants.setForeground(chatAttr, new Color(color)); chatDoc.insertString(chatDoc.getLength(), message + "\n", chatAttr); chatTP.setCaretPosition(chatDoc.getLength()); } catch (final BadLocationException e) { LOG.log(Level.SEVERE, e.toString(), e); } } });
/** * Shows the window if the text file was opened, and scrolls to the * beginning of the text. * * {@inheritDoc} */ @Override public void setVisible(final boolean visible) { if (fileOpened) { if (visible) { try { final Rectangle r = viewerTP.modelToView(0); viewerScroll.getViewport().setViewPosition(new Point(r.x, r.y)); } catch (final BadLocationException e) { LOG.log(Level.SEVERE, e.toString()); } } super.setVisible(visible); } else { errorHandler.showError(swingMessages.getMessage("swing.textViewerDialog.errorPopup.openFile", textFile)); } }
@Override public void run() { try { StyleConstants.setForeground(chatAttr, new Color(color)); chatDoc.insertString(chatDoc.getLength(), message + "\n", chatAttr); chatTP.setCaretPosition(chatDoc.getLength()); } catch (final BadLocationException e) { LOG.log(Level.SEVERE, e.toString(), e); } } });
/** * Sets Document Text. * * @param text Document Text. */ private void setText(String text) { debug("setText(), text=" + text); try { // remove all text and insert the completed string super.remove(0, getLength()); super.insertString(0, text, null); } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } }
protected void setText(String text) { try { // remove all text and insert the completed string if (isStrictCompletion()) { super.remove(0, getLength()); super.insertString(0, text, null); } else { String existingText = super.getText(0, getLength()); int matchIndex = existingText.length() <= text.length() ? existingText.length() : text.length(); // try to find a match for (int i = 0; i < existingText.length(); i++) { if (!existingText.substring(0, matchIndex).equalsIgnoreCase(text.substring(0, matchIndex))) { matchIndex--; } } // remove the no-match part and complete with the one in Searchable super.remove(matchIndex, getLength() - matchIndex); super.insertString(matchIndex, text.substring(matchIndex), null); } } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } } }
throw new AWTError(ble.toString());
public void run () { if (ui.isDestroyed ()) { logger.removeListener (this); text.setText (""); return; } int lc = text.getLineCount (); if (lc > maxLines) { try { int startOffset = text.getLineStartOffset (maxLines); int endOffset = text.getLineEndOffset(lc-1); text.getDocument ().remove (startOffset, endOffset-startOffset); } catch (BadLocationException ex) { text.setText (ex.toString()); } } } public LogEvent log (LogEvent evt) {
@Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { int currentPosition = txtConsole.getCaretPosition(); try { String command = txtConsole.getText(commandStart, (currentPosition - commandStart - 1)); runCommand(command, false); } catch (BadLocationException e1) { callbacks.printError(e1.toString()); } catch (MalformedURLException e1) { callbacks.printError(e1.toString()); } catch (NumberFormatException e1) { callbacks.printError(e1.toString()); } } else { super.keyReleased(e); } }