當前位置: 首頁>>代碼示例>>Java>>正文


Java BadLocationException.initCause方法代碼示例

本文整理匯總了Java中javax.swing.text.BadLocationException.initCause方法的典型用法代碼示例。如果您正苦於以下問題:Java BadLocationException.initCause方法的具體用法?Java BadLocationException.initCause怎麽用?Java BadLocationException.initCause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.BadLocationException的用法示例。


在下文中一共展示了BadLocationException.initCause方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isRowEmpty

import javax.swing.text.BadLocationException; //導入方法依賴的package包/類
public static boolean isRowEmpty(CharSequence text, int offset) throws BadLocationException {
    try {
        if (offset < text.length()) {
            char c = text.charAt(offset);
            if (!(c == '\n' || (c == '\r' && (offset == text.length()-1 || text.charAt(offset+1) == '\n')))) {
                return false;
            }
        }

        if (!(offset == 0 || text.charAt(offset-1) == '\n')) {
            // There's previous stuff on this line
            return false;
        }

        return true;
    } catch (Exception ex) {
        BadLocationException ble = new BadLocationException(offset + " out of " + text.length(), offset);
        ble.initCause(ex);
        throw ble;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:GsfUtilities.java

示例2: getRowStart

import javax.swing.text.BadLocationException; //導入方法依賴的package包/類
public static int getRowStart(CharSequence text, int offset) throws BadLocationException {
    try {
        // Search backwards
        for (int i = offset-1; i >= 0; i--) {
            char c = text.charAt(i);
            if (c == '\n') {
                return i+1;
            }
        }

        return 0;
    } catch (Exception ex) {
        BadLocationException ble = new BadLocationException(offset + " out of " + text.length(), offset);
        ble.initCause(ex);
        throw ble;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:GsfUtilities.java

示例3: getRowEnd

import javax.swing.text.BadLocationException; //導入方法依賴的package包/類
public static int getRowEnd(CharSequence text, int offset) throws BadLocationException {
    try {
        // Search backwards
        for (int i = offset; i < text.length(); i++) {
            char c = text.charAt(i);
            if (c == '\n') {
                return i;
            }
        }

        return text.length();
    } catch (Exception ex) {
        BadLocationException ble = new BadLocationException(offset + " out of " + text.length(), offset);
        ble.initCause(ex);
        throw ble;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:GsfUtilities.java

示例4: getText

import javax.swing.text.BadLocationException; //導入方法依賴的package包/類
/**
 * Get a portion of text of the given document as char sequence.
 * <br>
 *
 * @param doc document for which the charsequence is being obtained.
 * @param offset starting offset of the charsequence to obtain.
 * @param length length of the charsequence to obtain. It must be <code>&gt;= 0</code>
 *   and <code>&lt;doc.getLength() + 1</code>.
 * @return non-null character sequence.
 * @exception BadLocationException some portion of the given range
 *   was not a valid part of the document. The location in the exception
 *   is the first bad position encountered.
 *  <br>
 *  The returned character sequence should only be accessed under
 *  document's readlock (or writelock).
 */
public static CharSequence getText(Document doc, int offset, int length) throws BadLocationException {
    CharSequence text = getText(doc);
    try {
        return text.subSequence(offset, offset + length);
    } catch (IndexOutOfBoundsException e) {
        int badOffset = offset;
        if (offset >= 0 && offset + length > text.length()) {
            badOffset = length;
        }
        BadLocationException ble = new BadLocationException(e.getMessage(), badOffset);
        ble.initCause(e);
        throw ble;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:DocumentUtilities.java


注:本文中的javax.swing.text.BadLocationException.initCause方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。