下面列出了javax.swing.event.DocumentEvent#getOffset() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
public void removeUpdate(DocumentEvent e) {
int changeStart = e.getOffset();
int changeEnd = e.getOffset() + e.getLength();
if (isAffectedByChange(changeStart, changeEnd)) {
fireHighlightsChange(changeStart, changeEnd);
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
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();
}
}
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();
}
}
/**
* 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);
}
}
}
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();
}
}
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();
}
}
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();
}
}
public @Override void removeUpdate(DocumentEvent evt) {
JTextComponent c = component;
if (c != null) {
int offset = evt.getOffset();
runTransaction(CaretTransaction.RemoveType.DOCUMENT_REMOVE, offset, null, null);
modifiedUpdate(evt, offset, offset, offset);
}
}
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) {
}
}
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();
}
}
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();
}
}
public void insertUpdate(DocumentEvent ev) {
if (ev.getLength() != 1) {
return;
}
int pos = ev.getOffset();
String content = null;
try {
content = textArea.getText(0, pos + 1);
} catch (BadLocationException e) {
e.printStackTrace();
}
// Find where the word starts
int w;
for (w = pos; w >= 0; w--) {
if (!Character.isLetter(content.charAt(w))) {
break;
}
}
if (pos - w < 2) {
// Too few chars
return;
}
String prefix = content.substring(w + 1).toLowerCase();
int n = Collections.binarySearch(words, prefix);
if (n < 0 && -n <= words.size()) {
String match = words.get(-n - 1);
if (match.startsWith(prefix)) {
// A completion is found
String completion = match.substring(pos - w);
// We cannot modify Document from within notification,
// so we submit a task that does the change later
SwingUtilities.invokeLater(new CompletionTask(completion, pos + 1));
}
} else {
// Nothing found
mode = Mode.INSERT;
}
}
/**
* Notify the EditHistory of a document edit (insert).
*/
public void insertUpdate(final DocumentEvent e) {
int pos = e.getOffset();
int length = e.getLength();
insertUpdate(pos, length);
}
void preRemoveCheckDamaged(Fold fold, DocumentEvent evt, Collection damaged) {
int removeOffset = evt.getOffset();
int endRemove = removeOffset + evt.getLength();
int childIndex = FoldUtilitiesImpl.findFoldStartIndex(fold, removeOffset, true);
if (childIndex == -1) {
if (fold.getFoldCount() == 0) {
return;
}
Fold first = fold.getFold(0);
if (first.getStartOffset() <= endRemove) {
childIndex = 0;
} else {
return;
}
}
// Check if previous fold was affected too
if (childIndex >= 1) {
Fold prevChildFold = fold.getFold(childIndex - 1);
if (prevChildFold.getEndOffset() == removeOffset) {
preRemoveCheckDamaged(prevChildFold, evt, damaged);
}
}
boolean removed;
boolean startsWithin = false;
do {
int flag;
Fold childFold = fold.getFold(childIndex);
startsWithin = childFold.getStartOffset() < removeOffset &&
childFold.getEndOffset() <= endRemove;
removed = false;
if (FoldUtilitiesImpl.becomesEmptyAfterRemove(childFold, evt)) {
damaged.add(OPERATION_EMPTY | FoldUtilitiesImpl.FLAG_START_DAMAGED | FoldUtilitiesImpl.FLAG_END_DAMAGED);
damaged.add(childFold);
preRemoveCheckDamaged(childFold, evt, damaged); // nest prior removing
removed = true;
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("preRemoveCheck: removed empty " // NOI18N
+ childFold + '\n');
}
} else if ((flag = FoldUtilitiesImpl.becomesDamagedByRemove(childFold, evt, false)) != 0) {
damaged.add(OPERATION_DAMAGE | flag);
damaged.add(childFold);
preRemoveCheckDamaged(childFold, evt, damaged); // nest prior removing
removed = true;
if (LOG.isLoggable(Level.FINE)) {
LOG.finer("preRemoveCheck: removed damaged " // NOI18N
+ childFold + '\n');
}
} else if (childFold.getFoldCount() > 0) { // check children
// Some children could be damaged even if this one was not
preRemoveCheckDamaged(childFold, evt, damaged);
}
// Check whether the expand is necessary
if (!removed) { // only if not removed yet
if (childFold.isCollapsed() && ((flag = FoldUtilitiesImpl.becomesDamagedByRemove(childFold, evt, true)) > 0)) {
damaged.add(OPERATION_COLLAPSE | flag);
damaged.add(childFold);
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("preRemoveCheck: expansion needed " // NOI18N
+ childFold + '\n');
}
} else {
damaged.add(OPERATION_UPDATE);
damaged.add(childFold);
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("preRemoveCheck: removeUpdate call " // NOI18N
+ childFold + '\n');
}
}
}
childIndex++;
} while ((startsWithin || removed) && childIndex < fold.getFoldCount());
}