Refine search
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); } }
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); } });
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; }
private static void moveCaretToEndOfDocument(JTextComponent jTextComponent) { if (jTextComponent.isEditable()) { Document document = jTextComponent.getDocument(); jTextComponent.setCaretPosition(document.getEndPosition().getOffset() - 1); } } }
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 }); }
@Override public void run() { try { comp.setCaretPosition(changeInfo.get(0).getEnd().getOffset()); InstantRenamePerformer.invokeInstantRename(comp, changeInfo); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } });
@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); } } });
@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); } } };
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; } }
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; }
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) { } }
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(); } }
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; } }
public int start() { return start.getOffset(); }
/** * 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); }
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(); }