public MultiLineRun(int start, int end, int delimeterSize) throws BadLocationException { if (start > end) { String msg = "Start offset is after end: "; throw new BadLocationException(msg, start); } if (delimeterSize < 1) { String msg = "Delimiters be at least size 1: " + delimeterSize; throw new IllegalArgumentException(msg); } this.start = styledDocument.createPosition(start); this.end = styledDocument.createPosition(end); this.delimeterSize = delimeterSize; }
private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics) throws BadLocationException { Rectangle r = codeArea.modelToView(rowStartOffset); if (r == null) { throw new BadLocationException("Can't get Y offset", rowStartOffset);
/** * Check the proposed text and, if it is valid, parse it as an integer value. * * @param proposedText the proposed text value * @param offset position in the document * @return the parsed integer value * @throws BadLocationException if the string did not represent a value integer */ public int checkInput(String proposedText, int offset) throws BadLocationException { int newValue = 0; if (proposedText != null && proposedText.length() > 0) { try { newValue = Integer.parseInt(proposedText); } catch (NumberFormatException ex) { throw new BadLocationException(proposedText, offset); } } return newValue; } }
/** * Get index of line for current offset (generally cursor position). * @param offset Position on the line * @return Index of the line * @throws BadLocationException */ public int getLineOfOffset(int offset) throws BadLocationException { String errorMsg = "Can't translate offset to line"; Document doc = this.getDocument(); if (offset < 0) { throw new BadLocationException(errorMsg, -1); } else if (offset > doc.getLength()) { throw new BadLocationException(errorMsg, doc.getLength() + 1); } else { Element map = doc.getDefaultRootElement(); return map.getElementIndex(offset); } }
Element line = getLineElem(doc, offs); if (line == null) { throw new BadLocationException("No word at " + offs, offs);
/** * Get position of the beginning of the line. * @param line Index of the line * @return Offset of line * @throws BadLocationException */ public int getLineStartOffset(int line) throws BadLocationException { Element map = this.getDocument().getDefaultRootElement(); if (line < 0) { throw new BadLocationException("Negative line", -1); } else if (line >= map.getElementCount()) { throw new BadLocationException("No such line", this.getDocument().getLength() + 1); } else { Element lineElem = map.getElement(line); return lineElem.getStartOffset(); } }
public char charAt(int offset) throws BadLocationException { if (offset<0 || offset>=length()) { throw new BadLocationException("Invalid offset", offset); } int g0 = getGapStart(); char[] array = (char[]) getArray(); if (offset<g0) { // below gap return array[offset]; } return array[getGapEnd() + offset - g0]; // above gap }
throw new BadLocationException("Offset " + offs + " not in " + "required range of 0-" + textArea.getDocument().getLength(), offs);
throw new BadLocationException("Invalid document position", p0); throw new BadLocationException("Invalid document position", p1);
throw new BadLocationException("Position not represented by view", pos);
throw new BadLocationException(null, pos);
private void checkOffsetNonNegative(int offset) throws BadLocationException { if (offset < 0) { throw new BadLocationException("Invalid offset=" + offset // NOI18N + " < 0; docLen=" + docLen(), offset); // NOI18N } }
@Override public void insert(int offset, String string) throws BadLocationException { if (string == null || string.length() == 0) { return; } try { buffer.insert(offset, string); fireInsertUpdate(offset, string.length()); } catch (IndexOutOfBoundsException e) { throw new BadLocationException(e.getMessage(), offset); } }
@Override public void remove(int offs, int len) throws BadLocationException { synchronized(reader) { int bufferStart = getLength() - inputBuffer.length(); if(offs < bufferStart) { throw new BadLocationException("Can only remove after " + bufferStart, offs); } super.remove(offs, len); inputBuffer.delete(offs - bufferStart, offs - bufferStart + len); } }
@Override public void remove(int offset, int length) throws BadLocationException { if (length == 0) { return; } try { buffer.delete(offset, offset + length); fireRemoveUpdate(offset, length); } catch (IndexOutOfBoundsException e) { throw new BadLocationException(e.getMessage(), offset); } }
private void checkOffsetInDoc(int offset) throws BadLocationException { checkOffsetNonNegative(offset); if (offset > docLen()) { throw new BadLocationException("Invalid offset=" + offset // NOI18N + " > docLen=" + docLen(), offset); // NOI18N } }
private void checkOffsetInContent(int offset) throws BadLocationException { checkOffsetNonNegative(offset); if (offset > length()) { throw new BadLocationException("Invalid offset=" + offset // NOI18N + " > (docLen+1)=" + docLen(), offset); // NOI18N } }
public void insertChars(int position, final char cbuf[], final int off, final int len) throws BadLocationException { if (position > length() || position < 0) { throw new BadLocationException("Invalid insert", length()); } if (off == 0) { replace(position, 0, cbuf, len); } else { char tmp[] = new char[len]; System.arraycopy(cbuf, off, tmp, 0, len); replace(position, 0, tmp, len); } } }
public char charAt(int offset) throws BadLocationException { if (offset<0 || offset>=length()) { throw new BadLocationException("Invalid offset", offset); } int g0 = getGapStart(); char[] array = (char[]) getArray(); if (offset<g0) { // below gap return array[offset]; } return array[getGapEnd() + offset - g0]; // above gap }
private void checkBoundsInContent(int offset, int length) throws BadLocationException { checkOffsetNonNegative(offset); checkLengthNonNegative(length); if (offset + length > length()) { throw new BadLocationException("Invalid (offset=" + offset + " + length=" + length + // NOI18N ")=" + (offset+length) + " > (docLen+1)=" + length(), offset + length); // NOI18N } }