当前位置: 首页>>代码示例>>Java>>正文


Java BadLocationException.toString方法代码示例

本文整理汇总了Java中javax.swing.text.BadLocationException.toString方法的典型用法代码示例。如果您正苦于以下问题:Java BadLocationException.toString方法的具体用法?Java BadLocationException.toString怎么用?Java BadLocationException.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.BadLocationException的用法示例。


在下文中一共展示了BadLocationException.toString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTokenSafeOffset

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
/**
 * @param offset to be examined.
 * @return offset that will be high enough to ensure that the given offset
 *  will be covered by token that can be returned from the syntax.nextToken()
 *  assuming that the syntax will be prepared with the returned token.
 *  <BR>It's not guaranteed how much bigger the returned offset will be.
 */
static int getTokenSafeOffset(BaseDocument doc, int offset) {
    if (offset == 0) { // no valid state-info at offset 0
        return offset;
    }

    try {
        Element lineRoot = getLineRoot(doc);
        int lineIndex = lineRoot.getElementIndex(offset);
        Element lineElem = lineRoot.getElement(lineIndex);
        int lineStartOffset = lineElem.getStartOffset();
        Syntax.StateInfo stateInfo = getValidSyntaxStateInfo(doc, lineIndex);
        if (offset == lineStartOffset && stateInfo.getPreScan() == 0) {
            // can be done with the given offset
            return offset;
        }

        // go to next line and maybe further for tokens
        // crossing several lines
        int lineCount = lineRoot.getElementCount();
        while (++lineIndex < lineCount) {
            lineElem = lineRoot.getElement(lineIndex);
            stateInfo = getValidSyntaxStateInfo(doc, lineIndex);
            lineStartOffset = lineElem.getStartOffset();
            if (lineStartOffset - stateInfo.getPreScan() >= offset) {
                return lineStartOffset;
            }
        }
    } catch (BadLocationException e) {
        throw new IllegalStateException(e.toString());
    }

    return doc.getLength();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:FixLineSyntaxState.java

示例2: insertUpdate

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
@Override
protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr) {
    super.insertUpdate(chng, attr);
    DocumentUtilities.addEventPropertyStorage(chng);
    try {
        DocumentUtilities.putEventProperty(chng, String.class,
                getText(chng.getOffset(), chng.getLength()));
    } catch (BadLocationException e) {
        e.printStackTrace();
        throw new IllegalStateException(e.toString());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:TestDocument.java

示例3: removeUpdate

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
@Override
protected void removeUpdate(DefaultDocumentEvent chng) {
    super.removeUpdate(chng);
    DocumentUtilities.addEventPropertyStorage(chng);
    try {
        DocumentUtilities.putEventProperty(chng, String.class,
                getText(chng.getOffset(), chng.getLength()));
    } catch (BadLocationException e) {
        e.printStackTrace();
        throw new IllegalStateException(e.toString());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:TestDocument.java

示例4: textCharAt

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
public char textCharAt(int index) {
    synchronized (seg) {
        try {
            doc.getText(index, 1, seg);
            return seg.array[seg.offset];

        } catch (BadLocationException e) {
            throw new IllegalStateException(e.toString());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:DemoTokenUpdater.java

示例5: insertUpdate

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr) {
    super.insertUpdate(chng, attr);
    DocumentUtilities.addEventPropertyStorage(chng);
    try {
        DocumentUtilities.putEventProperty(chng, String.class,
                getText(chng.getOffset(), chng.getLength()));
    } catch (BadLocationException e) {
        e.printStackTrace();
        throw new IllegalStateException(e.toString());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ModificationTextDocument.java

示例6: removeUpdate

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
protected void removeUpdate(DefaultDocumentEvent chng) {
    super.removeUpdate(chng);
    DocumentUtilities.addEventPropertyStorage(chng);
    try {
        DocumentUtilities.putEventProperty(chng, String.class,
                getText(chng.getOffset(), chng.getLength()));
    } catch (BadLocationException e) {
        e.printStackTrace();
        throw new IllegalStateException(e.toString());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ModificationTextDocument.java

示例7: showHighlight

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
protected void showHighlight(){
  try {
    highlight = textPane.getHighlighter().addHighlight(start, end,
                                    DefaultHighlighter.DefaultPainter);
  }catch(BadLocationException ble){
    throw new GateRuntimeException(ble.toString());
  }

}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:10,代码来源:AnnotationSetsView.java

示例8: charAt

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
/**
 * {@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());
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:16,代码来源:RDocumentCharSequence.java

示例9: setDot

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
/** Sets the caret position to some position. This
 * causes removal of the active selection. If expandFold set to true
 * fold containing offset position will be expanded.
 *
 * <p>
 * <b>Note:</b> This method is deprecated and the present implementation
 * ignores values of scrollRect and scrollPolicy parameters.
 *
 * @param offset offset in the document to which the caret should be positioned.
 * @param scrollRect rectangle to which the editor window should be scrolled.
 * @param scrollPolicy the way how scrolling should be done.
 *  One of <code>EditorUI.SCROLL_*</code> constants.
 * @param expandFold whether possible fold at the caret position should be expanded.
 *
 * @deprecated use #setDot(int, boolean) preceded by <code>JComponent.scrollRectToVisible()</code>.
 */

public void setDot(int offset, Rectangle scrollRect, int scrollPolicy, boolean expandFold) {
    if (LOG_EDT.isLoggable(Level.FINE)) { // Only permit operations in EDT
        if (!SwingUtilities.isEventDispatchThread()) {
            throw new IllegalStateException("BaseCaret.setDot() not in EDT: offset=" + offset); // NOI18N
        }
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("setDot: offset=" + offset); //NOI18N
        if (LOG.isLoggable(Level.FINEST)) {
            LOG.log(Level.INFO, "setDot call stack", new Exception());
        }
    }
    
    JTextComponent c = component;
    if (c != null) {
        BaseDocument doc = (BaseDocument)c.getDocument();
        boolean dotChanged = false;
        doc.readLock();
        try {
            if (doc != null && offset >= 0 && offset <= doc.getLength()) {
                dotChanged = true;
                try {
                    caretPos = doc.createPosition(offset);
                    markPos = doc.createPosition(offset);

                    Callable<Boolean> cc = (Callable<Boolean>)c.getClientProperty("org.netbeans.api.fold.expander");
                    if (cc != null && expandFold) {
                        // the caretPos/markPos were already called.
                        // nothing except the document is locked at this moment.
                        try {
                            cc.call();
                        } catch (Exception ex) {
                            Exceptions.printStackTrace(ex);
                        }
                    }
                    if (rectangularSelection) {
                        setRectangularSelectionToDotAndMark();
                    }
                    
                } catch (BadLocationException e) {
                    throw new IllegalStateException(e.toString());
                    // setting the caret to wrong position leaves it at current position
                }
            }
        } finally {
            doc.readUnlock();
        }
        
        if (dotChanged) {
            fireStateChanged();
            dispatchUpdate(true);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:73,代码来源:BaseCaret.java

示例10: moveDot

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
/** Makes selection by moving dot but leaving mark.
 * 
 * <p>
 * <b>Note:</b> This method is deprecated and the present implementation
 * ignores values of scrollRect and scrollPolicy parameters.
 *
 * @param offset offset in the document to which the caret should be positioned.
 * @param scrollRect rectangle to which the editor window should be scrolled.
 * @param scrollPolicy the way how scrolling should be done.
 *  One of <code>EditorUI.SCROLL_*</code> constants.
 *
 * @deprecated use #setDot(int) preceded by <code>JComponent.scrollRectToVisible()</code>.
 */
public void moveDot(int offset, Rectangle scrollRect, int scrollPolicy) {
    if (LOG_EDT.isLoggable(Level.FINE)) { // Only permit operations in EDT
        if (!SwingUtilities.isEventDispatchThread()) {
            throw new IllegalStateException("BaseCaret.moveDot() not in EDT: offset=" + offset); // NOI18N
        }
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("moveDot: offset=" + offset); //NOI18N
    }

    JTextComponent c = component;
    if (c != null) {
        BaseDocument doc = (BaseDocument)c.getDocument();
        if (doc != null && offset >= 0 && offset <= doc.getLength()) {
            doc.readLock();
            try {
                int oldCaretPos = getDot();
                if (offset == oldCaretPos) { // no change
                    return;
                }
                caretPos = doc.createPosition(offset);
                if (selectionVisible) { // selection already visible
                    Utilities.getEditorUI(c).repaintBlock(oldCaretPos, offset);
                }
                if (rectangularSelection) {
                    Rectangle r = c.modelToView(offset);
                    if (rsDotRect != null) {
                        rsDotRect.y = r.y;
                        rsDotRect.height = r.height;
                    } else {
                        rsDotRect = r;
                    }
                    updateRectangularSelectionPaintRect();
                }
            } catch (BadLocationException e) {
                throw new IllegalStateException(e.toString());
                // position is incorrect
            } finally {
                doc.readUnlock();
            }
        }
        fireStateChanged();
        dispatchUpdate(true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:60,代码来源:BaseCaret.java

示例11: insertUpdate

import javax.swing.text.BadLocationException; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent evt, UndoableEdit edit, AttributeSet attr) {
        int insertOffset = evt.getOffset();
        int insertEndOffset = insertOffset + evt.getLength();
        CharSequence text = DocumentUtilities.getText(doc);
        if (insertOffset > 0) { // [Swing] marks (and elements) at offset zero do not move up
            insertOffset--;
        }
        try {
            int index = -1; // Index of the elements modification - computed lazily
            List<LineElement> addedLines = null; // Collected added lines
            LineElement removedLine = null; // Removed line element
            Position lastAddedLineEndPos = null;
            for (int offset = insertOffset; offset < insertEndOffset; offset++) {
                if (text.charAt(offset) == '\n') {
                    if (index == -1) { // Not computed yet
                        index = getElementIndex(offset);
                        removedLine = (LineElement)getElement(index);
                        lastAddedLineEndPos = removedLine.getStartPosition();
                        addedLines = new ArrayList<LineElement>(2);
                    }
                    Position lineEndPos = doc.createPosition(offset + 1);
                    addedLines.add(new LineElement(this, lastAddedLineEndPos, lineEndPos));
                    lastAddedLineEndPos = lineEndPos;
                }
            }
            if (index != -1) { // Some lines were added
                // If the text was inserted at the line boundary i.e. right after existing '\n'
                // and the ending char of the inserted text was not '\n' (otherwise
                // it would be a "clean" line insert) then there must be two line elements
                // removed.
                Position removedLineEndPos = removedLine.getEndPosition();
                int removedLineEndOffset = removedLineEndPos.getOffset();
                Element[] removed; // removed line elements
                int lastAddedLineEndOffset = lastAddedLineEndPos.getOffset();
                if (insertEndOffset == removedLineEndOffset
                        && lastAddedLineEndOffset != removedLineEndOffset
//                        && index + 1 < getElementCount()
                ) {
                    LineElement removedLine2 = (LineElement)getElement(index + 1);
                    removed = new Element[] { removedLine, removedLine2 };
                    removedLineEndPos = removedLine2.getEndPosition();
                    removedLineEndOffset = removedLineEndPos.getOffset();
                } else { // just one line removed
                    removed = new Element[] { removedLine };
                }
                if (lastAddedLineEndOffset < removedLineEndOffset) {
                    addedLines.add(new LineElement(this, lastAddedLineEndPos, removedLineEndPos));
                }

                Element[] added = new Element[addedLines.size()];
                addedLines.toArray(added);

                edit.addEdit(new Edit(index, removed, added));
                replace(index, removed.length, added);
            }
        } catch (BadLocationException e) {
            throw new IllegalStateException(e.toString());
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:60,代码来源:LineRootElement.java


注:本文中的javax.swing.text.BadLocationException.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。