本文整理汇总了Java中javax.swing.event.DocumentEvent.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent.getLength方法的具体用法?Java DocumentEvent.getLength怎么用?Java DocumentEvent.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.event.DocumentEvent
的用法示例。
在下文中一共展示了DocumentEvent.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void insertUpdate(DocumentEvent evt) {
documentChanged(evt);
int offset = evt.getOffset();
int length = evt.getLength();
int newStart;
int newEnd;
if (selectionStart > offset || (selectionStart == selectionEnd && selectionStart == offset)) {
newStart = selectionStart + length;
} else {
newStart = selectionStart;
}
if (selectionEnd >= offset) {
newEnd = selectionEnd + length;
} else {
newEnd = selectionEnd;
}
select(newStart, newEnd);
}
示例2: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void insertUpdate(DocumentEvent evt) {
int length = evt.getLength();
int offset = evt.getOffset();
try {
Document doc = evt.getDocument();
String text = evt.getDocument().getText(offset, length).trim();
if (text.startsWith("xmlns:")) { //NOI18N
String namespace = parseNamespace(text);
if (!declaredNamespaces.values().contains(namespace)) {
String schemaLocation = findSchemaLocation(doc, namespace);
updateSchemaLocation(doc, offset, namespace, schemaLocation);
}
evt.getDocument().removeDocumentListener(this);
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
示例3: 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();
return;
}
inSync = true;
region.sync(0);
span = region.getFirstRegionLength();
inSync = false;
requestRepaint();
}
示例4: changedUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
@Override
public void changedUpdate(DocumentEvent evt) {
if (enabled) {
UndoableEdit compoundEdit = (UndoableEdit) evt;
int offset = evt.getOffset();
int length = evt.getLength();
boolean covered = false;
if (lastModElementIndex >= 0 && lastModElementIndex < children.size()) {
covered = isCovered(offset, length);
}
if (!covered) {
// Find by binary search
lastModElementIndex = findModElementIndex(offset, false);
if (lastModElementIndex >= 0) {
covered = isCovered(offset, length);
}
}
if (!covered) {
addModElement(compoundEdit, offset, offset + length);
// lastModElementIndex populated by index of addition
}
}
}
示例5: 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();
}
}
示例6: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent e) {
int start = e.getOffset();
int len = e.getLength();
try {
String s = e.getDocument().getText(start + len - 1, 1);
lastInsertedChar = s.charAt(0);
} catch (BadLocationException e1) {
ErrorManager err = ErrorManager.getDefault();
err.notify(e1);
}
}
示例7: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent e) {
int changeStart = e.getOffset();
int changeEnd = e.getOffset() + e.getLength();
if (isAffectedByChange(changeStart, changeEnd)) {
fireHighlightsChange(changeStart, changeEnd);
}
}
示例8: becomesDamagedByRemove
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Checks whether fold's start or end guarded area become damaged by the edit
* @param f fold to check
* @param evt document event
* @return FLAG_ bitfield
*/
public static int becomesDamagedByRemove(Fold f, DocumentEvent evt, boolean zero) {
ApiPackageAccessor api = ApiPackageAccessor.get();
int fs = f.getStartOffset();
int fe = f.getEndOffset();
int gs = fs + api.foldStartGuardedLength(f);
int ge = fe - api.foldEndGuardedLength(f);
int removeStart = evt.getOffset();
int removeEnd = removeStart + evt.getLength();
if (zero) {
if (gs == fs) {
gs++;
} else {
gs = -1;
}
if (ge == fe) {
ge--;
} else {
ge = removeEnd + 1;
}
} else {
if (gs == fs) {
gs = -1;
}
if (ge == fe) {
ge = removeEnd + 1;
}
}
int ret = FLAG_NOTHING_DAMAGED;
if (removeStart < gs && removeEnd >= fs) {
ret |= FLAG_START_DAMAGED;
}
if (removeStart < fe && removeEnd > ge) {
ret |= FLAG_END_DAMAGED;
}
return ret;
}
示例9: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public final void insertUpdate(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());
}
}
示例10: documentChanged
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
private void documentChanged(DocumentEvent documentEvent) {
if(!documentDirty) {
fireSourceChanged();
}
//indicate that the synchronization between document content and the element may be broken
//not used by the model logic itself but by the "resortElements" method.
documentDirty = true;
try {
//test whether a new text was inserted before or after the root element boundaries (positions)
if(getRootElement().getStartOffset() > 0 || getRootElement().getEndOffset() < getDocument().getLength()) {
getRootElement().setStartPosition(0);
getRootElement().setEndPosition(getDocument().getLength());
}
//TODO: here we have to decide whether the document change affects
//the model and how.
int change_offset = documentEvent.getOffset();
int change_length = documentEvent.getLength();
int type = documentEvent.getType().equals(EventType.REMOVE) ? DocumentChange.REMOVE : DocumentChange.INSERT;
DocumentChange dchi = new DocumentChange(getDocument().createPosition(change_offset), change_length, type);
documentChanges.add(dchi);
if(debug) System.out.println(dchi);
}catch(BadLocationException e) {
e.printStackTrace();
}
requestModelUpdate(false);
}
示例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: 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();
}
}
}
示例13: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent e) {
int offset = e.getOffset();
int length = e.getLength();
int newDot = dot;
short changed = 0;
if (newDot >= offset) {
newDot += length;
changed |= 1;
}
int newMark = mark;
if (newMark >= offset) {
newMark += length;
changed |= 2;
}
if (changed != 0) {
if (newMark == newDot) {
setDot(newDot);
ensureValidPosition();
} else {
setDot(newMark);
if (getDot() == newMark) {
moveDot(newDot);
}
ensureValidPosition();
}
}
}
示例14: insertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent e) {
int start = e.getOffset();
int len = e.getLength();
try {
String s = e.getDocument().getText(start + len - 1, 1);
lastInsertedChar = s.charAt(0);
} catch (BadLocationException e1) {
}
}
示例15: fixOffset
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Fix the given offset according to the performed modification.
*
* @param offset >=0 offset in a document.
* @param evt document event describing change in the document.
* @return offset updated by applying the document change to the offset.
*/
public static int fixOffset(int offset, DocumentEvent evt) {
int modOffset = evt.getOffset();
if (evt.getType() == DocumentEvent.EventType.INSERT) {
if (offset >= modOffset) {
offset += evt.getLength();
}
} else if (evt.getType() == DocumentEvent.EventType.REMOVE) {
if (offset > modOffset) {
offset = Math.max(offset - evt.getLength(), modOffset);
}
}
return offset;
}