本文整理了Java中javax.swing.text.Position
类的一些代码示例,展示了Position
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Position
类的具体详情如下:
包路径:javax.swing.text.Position
类名称:Position
暂无
代码示例来源:origin: SonarSource/sonarqube
private void updateScm(Component component) {
scmEditor.setText("");
Changesets changesets = reader.readChangesets(component.getRef());
if (changesets == null) {
return;
}
List<Integer> changesetIndexByLine = changesets.getChangesetIndexByLineList();
try {
int index = 0;
for (Changeset changeset : changesets.getChangesetList()) {
scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(index) + "\n", null);
scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), changeset + "\n", null);
index++;
}
scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), "\n", null);
int line = 1;
for (Integer idx : changesetIndexByLine) {
scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(line) + ": " + idx + "\n", null);
line++;
}
} catch (Exception e) {
throw new IllegalStateException("Can't read SCM for " + getNodeName(component), e);
}
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
void removeText() {
if ((p0 != null) && (p1 != null) && (p0.getOffset() != p1.getOffset())) {
try {
Document doc = c.getDocument();
doc.remove(p0.getOffset(), p1.getOffset() - p0.getOffset());
} catch (BadLocationException e) {
}
}
}
代码示例来源:origin: org.codehaus.sonar.sslr/sslr-devkit
public void actionPerformed(ActionEvent event) {
String code = "";
Document document = codeEditor.getDocument();
if (document.getLength() > 0) {
try {
code = document.getText(1, document.getEndPosition().getOffset() - 1);
} catch (BadLocationException e) {
LOG.error("Error while reading code buffer", e);
}
}
int caretOffset = codeEditor.getCaretPosition();
loadFromString(code);
codeEditor.setCaretPosition(caretOffset);
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-jsfsupport-designtime
private void tfFooterText_changed(DocumentEvent e) {
if (updating) {
return;
}
updating = true;
Object o = listDisplayed.getSelectedValue();
if (o instanceof HtmlDataTableState.DisplayColumn) {
HtmlDataTableState.DisplayColumn dc = (HtmlDataTableState.DisplayColumn)o;
Document d = e.getDocument();
try {
dc.footerText = d.getText(d.getStartPosition().getOffset(),
d.getEndPosition().getOffset()).trim();
} catch (BadLocationException x) {}
}
updating = false;
}
代码示例来源:origin: UISpec4J/UISpec4J
private static void moveCaretToEndOfDocument(JTextComponent jTextComponent) {
if (jTextComponent.isEditable()) {
Document document = jTextComponent.getDocument();
jTextComponent.setCaretPosition(document.getEndPosition().getOffset() - 1);
}
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-editor-document
public LineRootElement(Document doc) {
this.doc = doc;
assert (doc.getLength() == 0) : "Cannot start with non-empty document"; // NOI18N
Position startPos = doc.getStartPosition();
assert (startPos.getOffset() == 0) : "Document.getStartPosition()=" + startPos + " != 0";
Position endPos = doc.getEndPosition();
assert (endPos.getOffset() == 1) : "Document.getEndPosition()=" + endPos + " != 1";
Element line = new LineElement(this, startPos, endPos);
replace(0, 0, new Element[]{ line });
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-refactoring
@Override
public void run() {
try {
comp.setCaretPosition(changeInfo.get(0).getEnd().getOffset());
InstantRenamePerformer.invokeInstantRename(comp, changeInfo);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-spring-beans
@Override
public void run() {
try {
Position position = doc.createPosition(offset);
doc.remove(offset, len);
doc.insertString(position.getOffset(), finalText.toString(), null);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-spellchecker
public void run() {
try {
doc.remove(span[0].getOffset(), span[1].getOffset() - span[0].getOffset());
doc.insertString(span[0].getOffset(), proposal, null);
} catch (BadLocationException e) {
ErrorManager.getDefault().notify(e);
}
}
});
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
@Override public void run() {
try {
javax.swing.text.Position[] regions = new javax.swing.text.Position[td.printer.reindentRegions.size() * 2];
int idx = 0;
for (int[] region : td.printer.reindentRegions) {
regions[idx] = doc.createPosition(region[0]);
regions[idx + 1] = doc.createPosition(region[1]);
idx += 2;
}
for (int j = 0; j < regions.length; j += 2) {
i.reindent(regions[j].getOffset(), regions[j + 1].getOffset());
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
};
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor
protected boolean overlapsGuardedBlocks(final JTextComponent c) {
Document d = c.getDocument();
if (!(d instanceof StyledDocument)) return false;
GuardedSectionManager man = GuardedSectionManager.getInstance((StyledDocument)d);
if (man == null) return false;
for (GuardedSection s : man.getGuardedSections()) try {
if (s.contains(NbDocument.createPosition(d, c.getSelectionStart(), Bias.Backward), false)
|| s.contains(NbDocument.createPosition(d, c.getSelectionEnd(), Bias.Forward), false)
|| (s.getStartPosition().getOffset() >= c.getSelectionStart() && s.getEndPosition().getOffset() <= c.getSelectionEnd())) return true;
} catch (BadLocationException ble) {}
return false;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf
private static int writeString(BaseDocument doc, String text, int offset){
int formatLength = 0;
Indent indenter = Indent.get(doc);
Reformat formatter = Reformat.get(doc);
indenter.lock();
formatter.lock();
try {
doc.atomicLock();
try{
offset = indenter.indentNewLine(offset + 1);
doc.insertString(offset, text, null );
Position endPos = doc.createPosition(offset + text.length() - 1);
formatter.reformat(offset, endPos.getOffset());
formatLength = Math.max(0, endPos.getOffset() - offset);
}
catch(BadLocationException ex){
Exceptions.printStackTrace(ex);
}
finally {
doc.atomicUnlock();
}
} finally {
formatter.unlock();
indenter.unlock();
}
return offset + formatLength + 1;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-extension-openide
TextTransferable(JTextComponent c, int start, int end) {
this.c = c;
Document doc = c.getDocument();
try {
p0 = doc.createPosition(start);
p1 = doc.createPosition(end);
plainData = c.getSelectedText();
if (c instanceof JEditorPane) {
JEditorPane ep = (JEditorPane)c;
mimeType = ep.getContentType();
if (mimeType.startsWith("text/plain")) {
return;
}
StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());
ep.getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() - p0.getOffset());
if (mimeType.startsWith("text/html")) {
htmlData = sw.toString();
} else {
richText = sw.toString();
}
}
} catch (BadLocationException ble) {
} catch (IOException ioe) {
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-beans
protected void substituteText(JTextComponent c, int offset, int len, String toAdd) {
BaseDocument doc = (BaseDocument) c.getDocument();
CharSequence prefix = getInsertPrefix();
String text = prefix.toString();
if (toAdd != null) {
text += toAdd;
}
doc.atomicLock();
try {
Position position = doc.createPosition(offset);
doc.remove(offset, len);
doc.insertString(position.getOffset(), text.toString(), null);
} catch (BadLocationException ble) {
// nothing can be done to update
} finally {
doc.atomicUnlock();
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-navigation
public boolean attach() {
int offset = pos.getOffset();
if (offset == -1) {
return false;
}
Position endPos = document.getEndPosition();
if (endPos == null || offset >= endPos.getOffset()) {
return false;
}
if (!(document instanceof NbDocument.Annotatable)) {
return false;
}
if (getAnnotationType() == null) {
return false;
}
try {
NbDocument.addAnnotation(document, pos, -1, this);
return true;
} catch (Throwable e) {
Exceptions.printStackTrace(e);
return false;
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-languages
String getText () throws BadLocationException {
return doc.getText (start.getOffset (), end.getOffset () - start.getOffset ());
}
}
代码示例来源:origin: groovy/groovy-core
public int start() {
return start.getOffset();
}
代码示例来源:origin: bobbylight/RSyntaxTextArea
/**
* Called when the document is modified.
*
* @param e The document event.
*/
@Override
public void removeUpdate(DocumentEvent e) {
// Keep track of the first and last offset modified. Some parsers are
// smart and will only re-parse this section of the file. Note that
// for removals, only the line at the removal start needs to be
// re-parsed.
try {
int offs = e.getOffset();
if (firstOffsetModded==null || offs<firstOffsetModded.getOffset()) {
firstOffsetModded = e.getDocument().createPosition(offs);
}
if (lastOffsetModded==null || offs>lastOffsetModded.getOffset()) {
lastOffsetModded = e.getDocument().createPosition(offs);
}
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
handleDocumentEvent(e);
}
代码示例来源:origin: net.imagej/imagej-ui-swing
void removeDummySpace() {
if (dummySpace != null) try {
getDocument().remove(dummySpace.getOffset(), 1);
dummySpace = null;
}
catch (final BadLocationException e) {
updaterFrame.log.error(e);
}
}
代码示例来源:origin: UNIVALI-LITE/Portugol-Studio
private int getEndOffset(Fold fold, RSyntaxTextArea textArea)
{
try
{
Field field = Fold.class.getDeclaredField("endOffs");
field.setAccessible(true);
Position posicao = (Position) field.get(fold);
if (posicao != null)
{
return posicao.getOffset();
}
}
catch (NoSuchFieldException | SecurityException | IllegalAccessException excecao)
{
}
return textArea.getDocument().getEndPosition().getOffset();
}
内容来源于网络,如有侵权,请联系作者删除!