本文整理汇总了Java中javax.swing.event.DocumentEvent.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent.getOffset方法的具体用法?Java DocumentEvent.getOffset怎么用?Java DocumentEvent.getOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.event.DocumentEvent
的用法示例。
在下文中一共展示了DocumentEvent.getOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInsertUpdateRebuildOffsetRange
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Get the offset area in which the views should be rebuilt
* in reaction to insert update in the underlying document.
*
* @param evt document event for the document modification.
* @return two-item integer array containing starting and ending offset
* of the area to be rebuilt or <code>null</code> in case
* no views should be rebuilt.
*/
protected int[] getInsertUpdateRebuildOffsetRange(DocumentEvent evt) {
DocumentEvent.ElementChange lineChange = evt.getChange(evt.getDocument().getDefaultRootElement());
if (lineChange == null) {
return null;
}
int startOffset = evt.getOffset();
int endOffset = startOffset + evt.getLength();
int[] offsetRange = new int[] {startOffset, endOffset};
Element[] addedLines = lineChange.getChildrenAdded();
ElementUtilities.updateOffsetRange(addedLines, offsetRange);
Element[] removedLines = lineChange.getChildrenRemoved();
ElementUtilities.updateOffsetRange(removedLines, offsetRange);
return offsetRange;
}
示例2: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public synchronized void insertUpdate(DocumentEvent e) {
if (inSync)
return ;
//check for modifications outside the first region:
if (e.getOffset() < region.getFirstRegionStartOffset() || (e.getOffset() + e.getLength()) > region.getFirstRegionEndOffset()) {
release(true);
return;
}
inSync = true;
region.sync();
span = region.getFirstRegionLength();
ui.updateInput(getRegionText(0));
inSync = false;
requestRepaint();
}
示例3: removeUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* 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);
}
示例4: removeUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void removeUpdate(DocumentEvent e) {
int offs0 = e.getOffset();
int offs1 = offs0 + e.getLength();
int newDot = dot;
if (newDot >= offs1) {
newDot -= (offs1 - offs0);
} else if (newDot >= offs0) {
newDot = offs0;
}
int newMark = mark;
if (newMark >= offs1) {
newMark -= (offs1 - offs0);
} else if (newMark >= offs0) {
newMark = offs0;
}
if (newMark == newDot) {
setDot(newDot);
ensureValidPosition();
} else {
setDot(newMark);
if (getDot() == newMark) {
moveDot(newDot);
}
ensureValidPosition();
}
}
示例5: removeUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void removeUpdate(DocumentEvent de) {
if(!listen) return;
TextRemovedAction action = new TextRemovedAction(
new TextDelta(de.getOffset(), saveBeforeRemove.getRemoveString(de.getOffset(), de.getLength())),
pane.getStyledDocument());
actionList.add(action);
}
示例6: changedUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
super.changedUpdate(changes, a, f);
int pos = changes.getOffset();
if (pos <= getStartOffset() && (pos + changes.getLength()) >=
getEndOffset()) {
setPropertiesFromAttributes();
}
}
示例7: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void insertUpdate(DocumentEvent e) {
try {
Vector<String> vectorOfStrings = new Vector<String>();
for (int i = 0; i < getModel().getSize(); i++) {
vectorOfStrings.add(String.valueOf(getModel().getElementAt(i)));
}
Document document = e.getDocument();
String documentText = document.getText(0, document.getLength());
final String result = checkForMatch(documentText, vectorOfStrings, caseSensitive);
final String newString = (result == null) ? documentText : result;
final int startSelect = document.getLength();
final int endSelect = newString.length();
final JTextField editorComponent = (JTextField) getEditor().getEditorComponent();
if (startSelect == e.getOffset() + e.getLength()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setSelectedItem(newString);
editorComponent.getDocument().removeDocumentListener(docListener);
editorComponent.setText(newString);
editorComponent.getDocument().addDocumentListener(docListener);
Caret caret = editorComponent.getCaret();
caret.setDot(endSelect);
caret.moveDot(startSelect);
}
});
}
} catch (BadLocationException e1) {
}
}
示例8: legacyRemoveUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public UndoableEdit legacyRemoveUpdate(DocumentEvent evt) {
// The algorithm here is similar to the one in PlainDocument.removeUpdate().
// Unfortunately in case exactly a line element (or multiple line elements)
// the algorithm removes extra line that follows the end of removed area.
// That could be improved but compatibility with PlainDocument would be lost.
int removeOffset = evt.getOffset();
int removeEndOffset = removeOffset + evt.getLength();
int line0 = getElementIndex(removeOffset);
int line1 = getElementIndex(removeEndOffset);
if (line0 != line1) {
// at least one line was removed
line1++; // will remove the line where remove ends as well
Element[] removed = new Element[line1 - line0];
copyElements(line0, line1, removed, 0);
Element[] added = new Element[] {
new LineElement(this,
((LineElement)removed[0]).getStartPosition(),
((LineElement)removed[removed.length - 1]).getEndPosition()
)
};
Edit edit = new Edit(line0, removed, added);
replace(line0, removed.length, added);
return edit;
}
return null;
}
示例9: forwardUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Forwards the given <code>DocumentEvent</code> to the child views
* that need to be notified of the change to the model.
* If a child changed its requirements and the allocation
* was valid prior to forwarding the portion of the box
* from the starting child to the end of the box will
* be repainted.
*
* @param ec changes to the element this view is responsible
* for (may be <code>null</code> if there were no changes)
* @param e the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see #insertUpdate
* @see #removeUpdate
* @see #changedUpdate
* @since 1.3
*/
protected void forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e, Shape a, ViewFactory f) {
boolean wasValid = isLayoutValid(majorAxis);
super.forwardUpdate(ec, e, a, f);
// determine if a repaint is needed
if (wasValid && (! isLayoutValid(majorAxis))) {
// Repaint is needed because one of the tiled children
// have changed their span along the major axis. If there
// is a hosting component and an allocated shape we repaint.
Component c = getContainer();
if ((a != null) && (c != null)) {
int pos = e.getOffset();
int index = getViewIndexAtPosition(pos);
Rectangle alloc = getInsideAllocation(a);
if (majorAxis == X_AXIS) {
alloc.x += majorOffsets[index];
alloc.width -= majorOffsets[index];
} else {
alloc.y += minorOffsets[index];
alloc.height -= minorOffsets[index];
}
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
}
示例10: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent evt) {
if (!isIgnoreModification()) {
if (DocumentUtilities.isTypingModification(evt.getDocument()) && !isAbbrevDisabled()) {
int offset = evt.getOffset();
int length = evt.getLength();
appendTypedText(offset, length);
} else { // not typing modification -> reset abbreviation collecting
resetAbbrevChars();
}
}
}
示例11: change
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
private void change(DocumentEvent e) {
int s = e.getOffset();
int l = e.getLength();
ConsoleSection i = getInputSection();
if (isExecute() /* || (i != null && s < i.getStart()) */) {
if (progressPos != -1 && s >= progressPos) {
return;
}
textAppended(document.getLength() + 1);
} else if (inputSection != null && inputSection.getStart() < s) {
refreshInput(true, false);
}
}
示例12: changedUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public final void changedUpdate(DocumentEvent e) {
//Ensure it is consumed
e.getLength();
documentChanged();
if (e.getOffset() + e.getLength() >= getCaretPos() && (locked || !(e instanceof OutputDocument.DO))) {
//#119985 only move caret when not in editable section
OutputDocument doc = (OutputDocument)e.getDocument();
if (! (e instanceof OutputDocument.DO) && getCaretPos() >= doc.getOutputLength()) {
return ;
}
getCaret().setDot(e.getOffset() + e.getLength());
}
}
示例13: changedUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
super.changedUpdate(e, a, f);
int pos = e.getOffset();
if (pos <= getStartOffset() && (pos + e.getLength()) >=
getEndOffset()) {
RowView.this.setPropertiesFromAttributes();
}
}
示例14: removeUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void removeUpdate(DocumentEvent e) {
int changeStart = e.getOffset();
int changeEnd = e.getOffset() + e.getLength();
if (isAffectedByChange(changeStart, changeEnd)) {
fireHighlightsChange(changeStart, changeEnd);
}
}
示例15: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent e) {
// less, not less and equal
if (e.getOffset() < offset) {
offset += e.getLength();
}
}