本文整理了Java中javax.swing.text.BadLocationException
类的一些代码示例,展示了BadLocationException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BadLocationException
类的具体详情如下:
包路径:javax.swing.text.BadLocationException
类名称:BadLocationException
暂无
代码示例来源:origin: groovy/groovy-core
findReplaceCount = 0;
int pos = textComponent.getSelectedText() == null ?
textComponent.getCaretPosition() :
textComponent.getSelectionStart();
Document doc = textComponent.getDocument();
try {
doc.remove(pos, find.length());
doc.insertString(pos, replace, attributeSet);
ble.printStackTrace();
代码示例来源:origin: ron190/jsql-injection
public void append(JTextPane l, String text) {
try {
l.getDocument().insertString(
l.getDocument().getLength(),
(l.getDocument().getLength() == 0 ? "" : "\n") + text,
null
);
} catch (BadLocationException e) {
LOGGER.error(e.getMessage(), e);
}
}
代码示例来源:origin: ron190/jsql-injection
/**
* 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();
}
}
代码示例来源:origin: fr.inria.wimmics/kggui
public int getLineOfOffset(final JTextComponent textComponent, final int line) throws BadLocationException {
final Document doc = textComponent.getDocument();
final int lineCount = doc.getDefaultRootElement().getElementCount();
if (line < 0) {
throw new BadLocationException("Negative line", -1);
} else if (line > lineCount) {
throw new BadLocationException("No such line", doc.getLength() + 1);
} else {
Element map = doc.getDefaultRootElement();
Element lineElem = map.getElement(line);
return lineElem.getEndOffset();
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
Element map = doc.getDefaultRootElement();
int lineNum = map.getElementIndex(caretPos);
Element line = map.getElement(lineNum);
int start = line.getStartOffset();
int end = line.getEndOffset()-1; // Why always "-1"?
int len = end-start;
String s = doc.getText(start, len);
ble.printStackTrace();
代码示例来源:origin: bobbylight/RSyntaxTextArea
g.setFont(font!=null ? font : textComponent.getFont());
Document doc = textComponent.getDocument();
rootElement = doc.getDefaultRootElement();
numDocLines = rootElement.getElementCount(); // The number of lines in our document.
currentDocLineNumber = 0; // The line number of the document we're currently on.
int startingOffset = 0; // Used when a line is so long it has to be wrapped.
Element currentLine = rootElement.getElement(currentDocLineNumber);
int currentLineStart = currentLine.getStartOffset();
int currentLineEnd = currentLine.getEndOffset();
doc.getText(currentLineStart+startingOffset, currentLineEnd-(currentLineStart+startingOffset),
currentLineSeg);
} catch (BadLocationException ble) {
currentPos++;
try {
doc.getText(currentLineStart+startingOffset, currentPos, currentLineSeg);
} catch (BadLocationException ble) {
System.err.println(ble);
System.err.println("==> Range: " + (currentLineStart+startingOffset) + " - " +
(currentLineStart+startingOffset+currentPos));
ble.printStackTrace();
return Printable.NO_SUCH_PAGE;
代码示例来源:origin: bobbylight/RSyntaxTextArea
int mark = textArea.getCaret().getMark();
Document doc = textArea.getDocument();
Element root = doc.getDefaultRootElement();
int startLine = root.getElementIndex(Math.min(dot, mark));
int endLine = root.getElementIndex(Math.max(dot, mark));
Element elem = root.getElement(endLine);
if (dot == elem.getStartOffset() || mark == elem.getStartOffset()) {
moveCount--;
ble.printStackTrace();
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
return;
代码示例来源:origin: abbot/abbot
public String call() {
Document doc = component.getDocument();
try {
return doc.getText(0, doc.getLength());
} catch (BadLocationException e) {
e.printStackTrace();
return "";
}
}
});
代码示例来源:origin: bobbylight/RSyntaxTextArea
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
try {
// We use the elements instead of calling getLineOfOffset(),
// etc. to speed things up just a tad (i.e. micro-optimize).
Document document = textArea.getDocument();
int caretPosition = textArea.getCaretPosition();
Element map = document.getDefaultRootElement();
int currentLineNum = map.getElementIndex(caretPosition);
Element currentLineElement = map.getElement(currentLineNum);
// Always take -1 as we don't want to remove the newline.
int currentLineEnd = currentLineElement.getEndOffset()-1;
if (caretPosition<currentLineEnd) {
document.remove(caretPosition,
currentLineEnd-caretPosition);
}
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
代码示例来源:origin: ron190/jsql-injection
@Override
public void keyPressed(KeyEvent keyEvent) {
try {
final Element root = this.terminal.getDocument().getDefaultRootElement();
final int caretPosition = this.terminal.getCaretPosition();
command[0] =
this.terminal.getText(
root.getElement(lineNumber).getStartOffset(),
root.getElement(lineNumber).getEndOffset() - root.getElement(lineNumber).getStartOffset()
).replace(this.terminal.getPrompt(), "");
terminalCommand.setCaretPosition(terminalCommand.getDocument().getLength());
terminalCommand.action(
command[0],
this.terminal.getDocument().remove(
root.getElement(lineNumber).getStartOffset() + this.terminal.getPrompt().length(),
command[0].length() - 1
LOGGER.error(e.getMessage(), e);
代码示例来源:origin: org.netbeans.api/org-jruby
protected String getLine() {
try {
return area.getText(startPos, area.getDocument().getLength() - startPos);
} catch (BadLocationException e) {
e.printStackTrace();
}
return null;
}
代码示例来源:origin: apache/pdfbox
private String getWord(int offset)
{
try
{
int start = Utilities.getWordStart(textComponent, offset);
int end = Utilities.getWordEnd(textComponent, offset);
return textComponent.getDocument().getText(start, end - start + 1).trim();
}
catch (BadLocationException e)
{
e.printStackTrace();
}
return null;
}
代码示例来源:origin: ron190/jsql-injection
/**
* 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);
}
}
代码示例来源:origin: UISpec4J/UISpec4J
public void clear() {
UISpecAssert.assertTrue(isEditable());
Document document = jTextComponent.getDocument();
try {
document.remove(0, document.getLength());
}
catch (BadLocationException e) {
AssertAdapter.fail("Clear failed: " + e.getMessage());
}
}
代码示例来源:origin: apache/pdfbox
private void search(DocumentEvent documentEvent)
{
try
{
String word = documentEvent.getDocument().getText(0, documentEvent.getDocument().getLength());
if (word.isEmpty())
{
nextAction.setEnabled(false);
previousAction.setEnabled(false);
searchPanel.reset();
textComponent.getHighlighter().removeAllHighlights();
return;
}
search(word);
}
catch (BadLocationException e)
{
e.printStackTrace();
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
Element line = getLineElem(doc, offs);
if (line == null) {
throw new BadLocationException("No word at " + offs, offs);
int lineStart = line.getStartOffset();
if (offs==lineStart) { // Start of the line.
return offs;
int endOffs = Math.min(offs+1, doc.getLength());
String s = doc.getText(lineStart, endOffs-lineStart);
if(s != null && s.length() > 0) {
int i = s.length() - 1;
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* Reads the single character at the current position in the document.
*/
@Override
public int read() {
if(position>=document.getLength()) {
return -1; // Read past end of document.
}
try {
document.getText((int)position,1, segment);
position++;
return segment.array[segment.offset];
} catch (BadLocationException ble) {
/* Should never happen?? */
ble.printStackTrace();
return -1;
}
}
代码示例来源:origin: woder/TorchBot
private void addCom(String text){
AttributeSet attribute = attributes.get("0");
try{
int len = doc.getLength();
doc.insertString(len, text, attribute);
}catch (BadLocationException e){
e.printStackTrace();
}
chat.setCaretPosition(chat.getDocument().getLength());
}
代码示例来源:origin: org.netbeans.api/org-jruby
protected void replaceText(int start, int end, String replacement) {
try {
area.getDocument().remove(start, end - start);
area.getDocument().insertString(start, replacement, inputStyle);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
代码示例来源:origin: groovy/groovy-core
public void actionPerformed(ActionEvent ae) {
JTextComponent tComp = (JTextComponent) ae.getSource();
if (tComp.getDocument() instanceof StyledDocument) {
doc = (StyledDocument) tComp.getDocument();
try {
doc.getText(0, doc.getLength(), segment);
}
catch (Exception e) {
// should NEVER reach here
e.printStackTrace();
}
int offset = tComp.getCaretPosition();
int index = findTabLocation(offset);
buffer.delete(0, buffer.length());
buffer.append('\n');
if (index > -1) {
for (int i = 0; i < index + 4; i++) {
buffer.append(' ');
}
}
try {
doc.insertString(offset, buffer.toString(),
doc.getDefaultRootElement().getAttributes());
}
catch (BadLocationException ble) {
ble.printStackTrace();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!