Example usage for javax.swing.text BadLocationException BadLocationException

List of usage examples for javax.swing.text BadLocationException BadLocationException

Introduction

In this page you can find the example usage for javax.swing.text BadLocationException BadLocationException.

Prototype

public BadLocationException(String s, int offs) 

Source Link

Document

Creates a new BadLocationException object.

Usage

From source file:org.fit.cssbox.swingbox.SwingBoxEditorKit.java

private void writeImpl(Writer out, SwingBoxDocument doc, int pos, int len)
        throws BadLocationException, IOException {

    if (pos > doc.getLength() || pos < 0) {
        throw new BadLocationException("Invalid location", pos);
    }//from  w  w w  . j  a  va 2s  .  com
    if (len < 0)
        len = 0;

    ContentWriter wrt = new ContentWriter();
    StringBuilder sb = wrt.write(getCSSBoxAnalyzer().getDocument());
    out.write(sb.toString());
    out.flush();

}

From source file:org.kineticsystem.commons.data.view.FixedSizeFilter.java

/** {@inheritDoc} */
@Override//from   ww  w  .j a v  a 2 s  . co  m
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String str, AttributeSet attrs)
        throws BadLocationException {
    try {
        int newLength;
        if (str == null) {
            newLength = fb.getDocument().getLength() - length;
        } else {
            newLength = fb.getDocument().getLength() - length + str.length();
        }
        if (newLength <= maxSize) {
            fb.replace(offset, length, str, attrs);
        }
    } catch (NullPointerException ex) {
        logger.error(ex);
    } catch (BadLocationException ex) {
        throw new BadLocationException("New characters exceed max size " + "of document", offset);
    }
}

From source file:ru.gelin.fictionbook.reader.models.FBSimpleDocument.java

public String getText(int offset, int length) throws BadLocationException {
    try {// ww w  .  ja  v  a2  s. com
        return new String(content, offset, length);
    } catch (IndexOutOfBoundsException e) {
        throw new BadLocationException(e.getMessage(),
                //try to guess erroneous offset
                offset < 0 || offset >= getLength() ? offset : offset + length);
    }
}

From source file:ru.gelin.fictionbook.reader.models.FBSimpleDocument.java

public void getText(int offset, int length, Segment txt) throws BadLocationException {
    if (offset < 0) {
        throw new BadLocationException("invalid offset", offset);
    } else if (offset + length > content.length) {
        throw new BadLocationException("invalid offset", offset + length);
    } else {/*from w  w  w . ja v a 2s  . c  om*/
        txt.array = content;
        txt.offset = offset;
        txt.count = length;
    }
}

From source file:ru.gelin.fictionbook.reader.models.FBSimpleDocument.java

/**
 *  Offset of created position is constant value because this
 *  document is unmodifiable./*from  w  ww. j a v  a2  s . c o m*/
 */
public Position createPosition(int offs) throws BadLocationException {
    if (offs < 0 || offs > getLength()) {
        throw new BadLocationException("invalid offset to create position", offs);
    }
    return new FBSimplePosition(offs);
}