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


Java BadLocationException类代码示例

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


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

示例1: isEmpty

import javax.swing.text.BadLocationException; //导入依赖的package包/类
private static boolean isEmpty (
    int                     ln,
    StyledDocument          document,
    Set<Integer>            whitespaces
) throws BadLocationException {
    int start = NbDocument.findLineOffset (document, ln);
    int end = document.getLength ();
    try {
        end = NbDocument.findLineOffset (document, ln + 1) - 1;
    } catch (IndexOutOfBoundsException ex) {
    }
    TokenSequence ts = Utils.getTokenSequence (document, start);
    if (ts.token () == null) return true;
    while (whitespaces.contains (ts.token ().id ().ordinal ())) {
        if (!ts.moveNext ()) return true;
        if (ts.offset () > end) return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:IndentFactory.java

示例2: createClassDisplayText

import javax.swing.text.BadLocationException; //导入依赖的package包/类
private String createClassDisplayText(AttributeValueFinder finder, String classAttrValue, int matchIndex, int matchLength) throws BadLocationException {
    StringBuilder builder = new StringBuilder();
    builder.append("&lt;bean"); // NOI18N
    String attrWithValue = getAttributeWithValue(finder, "id"); // NOI18N
    if (attrWithValue == null) {
        attrWithValue = getAttributeWithValue(finder, "name"); // NOI18N
    }
    if (attrWithValue != null) {
        builder.append(' '); // NOI18N
        builder.append(attrWithValue);
    }
    String beforeMatch = escapeAttrValue(classAttrValue.substring(0, matchIndex));
    String match = escapeAttrValue(classAttrValue.substring(matchIndex, matchIndex + matchLength));
    String afterMatch = escapeAttrValue(classAttrValue.substring(matchIndex + matchLength, classAttrValue.length()));
    if (beforeMatch != null && match != null && afterMatch != null) {
        builder.append(" class="); // NOI18N
        builder.append(beforeMatch).append("<b>").append(match).append("</b>").append(afterMatch); // NOI18N
    }
    return builder.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavaElementRefFinder.java

示例3: getPreviousWordStartInLine

import javax.swing.text.BadLocationException; //导入依赖的package包/类
private int getPreviousWordStartInLine(RSyntaxDocument doc,
		Element elem, int offs) throws BadLocationException {

	int start = elem.getStartOffset();
	int cur = offs;

	// Skip any whitespace or non-word chars
	while (cur >= start) {
		char ch = doc.charAt(cur);
		if (isIdentifierChar(ch)) {
			break;
		}
		cur--;
	}
	if (cur < start) {
		// Empty line or nothing but whitespace/non-word chars
		return -1;
	}

	return getWordStartImpl(doc, elem, cur);

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:23,代码来源:RSyntaxTextAreaEditorKit.java

示例4: toString

import javax.swing.text.BadLocationException; //导入依赖的package包/类
public String toString() {
    StringBuilder buf = new StringBuilder("Position bounds["); // NOI18N

    try {
        String content = getText();
        buf.append(begin);
        buf.append(","); // NOI18N
        buf.append(end);
        buf.append(",\""); // NOI18N
        buf.append(content);
        buf.append("\""); // NOI18N
    } catch (BadLocationException e) {
        buf.append("Invalid: "); // NOI18N
        buf.append(e.getMessage());
    }

    buf.append("]"); // NOI18N

    return buf.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:PositionBounds.java

示例5: visitReference

import javax.swing.text.BadLocationException; //导入依赖的package包/类
@Override
public DocTree visitReference(ReferenceTree node, Element p) {
    DocTrees trees = info.getDocTrees();
    Element el = trees.getElement(getCurrentPath());
    if (el != null && el.equals(toFind)) {
        int[] span = treeUtils.findNameSpan(getCurrentPath().getDocComment(), node);
        if(span != null) {
            try {
                MutablePositionRegion region = createRegion(doc, span[0], span[1]);
                usages.add(region);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    return super.visitReference(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:FindLocalUsagesQuery.java

示例6: indentLine

import javax.swing.text.BadLocationException; //导入依赖的package包/类
@Override
public int indentLine(Document doc, int offset) {
    Indent indent = Indent.get(doc);
    indent.lock();
    try {
        if (doc instanceof BaseDocument) {
            ((BaseDocument) doc).atomicLock();
        }
        try {
            Position pos = doc.createPosition(offset);
            indent.reindent(offset);
            return pos.getOffset();
        } catch (BadLocationException ble) {
            return offset;
        } finally {
            if (doc instanceof BaseDocument) {
                ((BaseDocument) doc).atomicUnlock();
            }
        }
    } finally {
        indent.unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DefaultIndentEngine.java

示例7: paint

import javax.swing.text.BadLocationException; //导入依赖的package包/类
/** This method is called by Swing to draw highlights. */
public void paint(Graphics gr, int start, int end, Shape shape, JTextComponent text) {
   Color old = gr.getColor();
   gr.setColor(color);
   try {
      Rectangle box = shape.getBounds(), a = text.getUI().modelToView(text, start), b = text.getUI().modelToView(text, end);
      if (a.y == b.y) {
         // same line (Note: furthermore, if start==end, then we draw all the way to the right edge)
         Rectangle r = a.union(b);
         gr.fillRect(r.x, r.y, (r.width<=1 ? (box.x + box.width - r.x) : r.width), r.height);
      } else {
         // Multiple lines; (Note: on first line we'll draw from "start" and extend to rightmost)
         gr.fillRect(a.x, a.y, box.x + box.width - a.x, a.height);
         if (a.y + a.height < b.y) gr.fillRect(box.x, a.y + a.height, box.width, b.y - (a.y + a.height));
         gr.fillRect(box.x, b.y, b.x - box.x, b.height);
      }
   } catch (BadLocationException e) { } // Failure to highlight is not fatal
   gr.setColor(old);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:20,代码来源:OurHighlighter.java

示例8: checkCharsetConversion

import javax.swing.text.BadLocationException; //导入依赖的package包/类
private boolean checkCharsetConversion(final String encoding) {
    boolean value = true;
    try {
        CharsetEncoder coder = Charset.forName(encoding).newEncoder();
        if (!coder.canEncode(getDocument().getText(0, getDocument().getLength()))){
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
                    NbBundle.getMessage(XmlMultiViewEditorSupport.class, "MSG_BadCharConversion",
                    new Object [] { getDataObject().getPrimaryFile().getNameExt(),
                    encoding}),
                    NotifyDescriptor.YES_NO_OPTION,
                    NotifyDescriptor.WARNING_MESSAGE);
            nd.setValue(NotifyDescriptor.NO_OPTION);
            DialogDisplayer.getDefault().notify(nd);
            if(nd.getValue() != NotifyDescriptor.YES_OPTION) {
                value = false;
            }
        }
    } catch (BadLocationException e){
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
    }
    return value;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:XmlMultiViewEditorSupport.java

示例9: run

import javax.swing.text.BadLocationException; //导入依赖的package包/类
public void run() {
    Indent indent = Indent.get(doc);
    indent.lock();
    try {
        //doc.atomicLock();
        try {
            lockAcquired = true;
            indent.reindent(0);
        } catch (BadLocationException ex) {
            fail();
        } finally {
            //doc.atomicUnlock();
        }
    } finally {
        indent.unlock();
    }
    indentFinished = true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:IndentTest.java

示例10: testQuoteAutocompletion

import javax.swing.text.BadLocationException; //导入依赖的package包/类
public void testQuoteAutocompletion() throws BadLocationException, IOException {
    //test pair autocomplete
    clear(doc);

    //test skipping closing curly bracket
    String text = "h1 { color:  } ";
    //             0123456789012345678        
    doc.insertString(0, text , null);

    pane.setCaretPosition(12);
    type('"');

    assertEquals("h1 { color: \"\" } ", getText()); //no change in the text
    //             0123456789012345678        
    assertEquals(13, pane.getCaretPosition()); //+1

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CssBracketCompleterTest.java

示例11: getNextToken

import javax.swing.text.BadLocationException; //导入依赖的package包/类
/**
 * Get token at given offet or previous one if at token boundary.
 * It does not lock the document. Returns {@code null} for invalid offsets.
 * 
 * @param offset valid position in document
 * @return Token instance
 */
public Token<XMLTokenId> getNextToken( int offset) throws BadLocationException {
    if (offset == 0) {
        offset = 1;
    }
    if (offset < 0) throw new BadLocationException("Offset " +
            offset + " cannot be less than 0.", offset);  //NOI18N
    ((AbstractDocument)document).readLock();
    try {
        TokenSequence ts = getSequence();
        synchronized (ts) {
            return getToken(ts, offset, true, null);
        }
    } finally {
        ((AbstractDocument)document).readUnlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:XMLSyntaxSupport.java

示例12: retreiveGuardedBlock

import javax.swing.text.BadLocationException; //导入依赖的package包/类
private void retreiveGuardedBlock(CodeCategory category, int index) {
    GuardedBlock gBlock = codeData.getGuardedBlock(category, index);
    if (!gBlock.isCustomizable())
        return;

    if (getGuardInfos(category)[index].customized) {
        Document doc = getDocument(category);
        int[] blockBounds = getGuardBlockBounds(category, index);
        try {
            int startPos = blockBounds[0] + gBlock.getHeaderLength();
            String code = doc.getText(startPos,
                                      blockBounds[1] - gBlock.getFooterLength() - startPos);
            gBlock.setCustomizedCode(code);
        }
        catch (BadLocationException ex) { // should not happen
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
        }
    }
    else { // reset to default code
        gBlock.setCustomizedCode(null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:CustomCodeView.java

示例13: getChars

import javax.swing.text.BadLocationException; //导入依赖的package包/类
public void getChars(int offset, int length, Segment chars)
throws BadLocationException {

    checkBounds(offset, length, length());
    
    if ((offset + length) <= gapStart) { // completely below gap
        chars.array = charArray;
        chars.offset = offset;
        
    } else if (offset >= gapStart) { // completely above gap
        chars.array = charArray;
        chars.offset = offset + gapLength;
        
    } else { // spans the gap, must copy
        chars.array = copySpanChars(offset, length);
        chars.offset = 0;
    }
    
    chars.count = length;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DocumentContent.java

示例14: keyReleased

import javax.swing.text.BadLocationException; //导入依赖的package包/类
@Override
public void keyReleased(KeyEvent ke) {
    if(ke.getSource() == frame.getjList1()) {
        if(ke.getKeyCode() == KeyEvent.VK_UP ||
            ke.getKeyCode() == KeyEvent.VK_DOWN ||
            ke.getKeyCode() == KeyEvent.VK_ENTER || 
            ke.getKeyCode() == KeyEvent.VK_CONTROL || 
            ke.getKeyCode() == KeyEvent.VK_SPACE) {                
            return;
        } 
    }
    if(ke.isControlDown() && ke.getKeyChar()== KeyEvent.VK_SPACE) {            
        try {
            giveMenuOptions();
            Point loc = new Point(
                    pane.modelToView(pane.getCaretPosition()).x,
                    pane.modelToView(pane.getCaretPosition()).y);                  
            frame.setLocation(pane.getLocationOnScreen().x + loc.x, pane.getLocationOnScreen().y + loc.y + 20);
            frame.setVisible(true);
            frame.getjList1().setSelectedIndex(0);
        } catch (BadLocationException ex) {
            Logger.getLogger(AutocompletionController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
 
开发者ID:Skypr,项目名称:BEAST,代码行数:26,代码来源:AutocompletionController.java

示例15: actionPerformed

import javax.swing.text.BadLocationException; //导入依赖的package包/类
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    Document doc = target.getDocument();
    doc.render(new Runnable() {
        @Override
        public void run() {
            FoldHierarchy hierarchy = FoldHierarchy.get(target);
            int dot = target.getCaret().getDot();
            hierarchy.lock();
            try {
                try {
                    int rowStart = javax.swing.text.Utilities.getRowStart(target, dot);
                    int rowEnd = javax.swing.text.Utilities.getRowEnd(target, dot);
                    Fold fold = getLineFold(hierarchy, dot, rowStart, rowEnd);
                    if (fold != null) {
                        hierarchy.expand(fold);
                    }
                } catch (BadLocationException ble) {
                    Exceptions.printStackTrace(ble);
                }
            } finally {
                hierarchy.unlock();
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ActionFactory.java


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