本文整理汇总了Java中javax.swing.event.DocumentEvent.ElementChange方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent.ElementChange方法的具体用法?Java DocumentEvent.ElementChange怎么用?Java DocumentEvent.ElementChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.event.DocumentEvent
的用法示例。
在下文中一共展示了DocumentEvent.ElementChange方法的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: getRemoveUpdateRebuildOffsetRange
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[] getRemoveUpdateRebuildOffsetRange(DocumentEvent evt) {
DocumentEvent.ElementChange lineChange = evt.getChange(evt.getDocument().getDefaultRootElement());
if (lineChange == null) {
return null;
}
int startOffset = evt.getOffset();
int endOffset = startOffset;
int[] offsetRange = new int[] {startOffset, endOffset};
Element[] addedLines = lineChange.getChildrenAdded();
ElementUtilities.updateOffsetRange(addedLines, offsetRange);
Element[] removedLines = lineChange.getChildrenRemoved();
ElementUtilities.updateOffsetRange(removedLines, offsetRange);
return offsetRange;
}
示例3: getChange
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public @Override DocumentEvent.ElementChange getChange(Element elem) {
// Super of getChange()
if (changeLookup2 != null) {
return (DocumentEvent.ElementChange) changeLookup2.get(elem);
}
int n = edits.size();
for (int i = 0; i < n; i++) {
Object o = edits.elementAt(i);
if (o instanceof DocumentEvent.ElementChange) {
DocumentEvent.ElementChange c = (DocumentEvent.ElementChange) o;
if (c.getElement() == elem) {
return c;
}
}
}
return null;
// End super of getChange()
}
示例4: documentChanged
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
protected void documentChanged(DocumentEvent evt) {
DocumentEvent.ElementChange ch = evt.getChange(document.getDefaultRootElement());
int count;
if (ch == null) {
count = 0;
} else {
count = ch.getChildrenAdded().length - ch.getChildrenRemoved().length;
}
int line = getLineOfOffset(evt.getOffset());
if (count == 0) {
painter.invalidateLine(line);
}
// do magic stuff
else if (line < firstLine) {
setFirstLine(firstLine + count);
}
// end of magic stuff
else {
painter.invalidateLineRange(line, firstLine + visibleLines);
updateScrollBars();
}
}
示例5: testDocumentEvents
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
public void testDocumentEvents() throws Exception {
System.out.println("testDocumentEvents");
OutWriter ow = new OutWriter ();
OutputDocument doc = new OutputDocument (ow);
ODListener od = new ODListener();
doc.addDocumentListener(od);
for (int i=0; i < 100; i++) {
ow.println("This is string " + i);
}
// SwingUtilities.invokeAndWait (new Runnable() {
// public void run(){
// System.currentTimeMillis();
// }
// });
ow.flush();
//Thread.currentThread().sleep(1500);
DocumentEvent de = od.getEvent();
assertTrue ("Event should have been fired", de != null);
int elCount = doc.getElementCount();
assertTrue ("Element count should be 101 after printing 100 lines, " +
"not " + elCount,
elCount == 101);
DocumentEvent.ElementChange ec = de.getChange(doc);
Element[] added = ec.getChildrenAdded();
assertNotNull("Children added should not be null", added);
// assertTrue("Number of children added should be 100, not " + added.length, added.length == 100);
// assertTrue ("Index of change should be 0, not " + ec.getIndex(), ec.getIndex() == 0);
}
示例6: forwardUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
protected void forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e, Shape a, ViewFactory f) {
super.forwardUpdate(ec, e, a, f);
// A change in any of the table cells usually effects the whole table,
// so redraw it all!
if (a != null) {
Component c = getContainer();
if (c != null) {
Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
a.getBounds();
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
}
示例7: fireInsertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* We overwrite this method to update the token marker state immediately so that any event
* listeners get a consistent token marker.
*/
@Override
protected void fireInsertUpdate(DocumentEvent evt) {
if (tokenMarker != null) {
DocumentEvent.ElementChange ch = evt.getChange(getDefaultRootElement());
if (ch != null) {
tokenMarker.insertLines(ch.getIndex() + 1, ch.getChildrenAdded().length - ch.getChildrenRemoved().length);
}
}
super.fireInsertUpdate(evt);
}
示例8: fireRemoveUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* We overwrite this method to update the token marker state immediately so that any event
* listeners get a consistent token marker.
*/
@Override
protected void fireRemoveUpdate(DocumentEvent evt) {
if (tokenMarker != null) {
DocumentEvent.ElementChange ch = evt.getChange(getDefaultRootElement());
if (ch != null) {
tokenMarker.deleteLines(ch.getIndex() + 1, ch.getChildrenRemoved().length - ch.getChildrenAdded().length);
}
}
super.fireRemoveUpdate(evt);
}
示例9: forwardUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
protected void forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e, Shape a, ViewFactory f) {
super.forwardUpdate(ec, e, a, f);
// A change in any of the table cells usually effects the whole table,
// so redraw it all!
if (a != null) {
Component c = getContainer();
if (c != null) {
Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
a.getBounds();
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
}
示例10: 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);
}
}
}
示例11: updateDamage
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
@Override
protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
Document doc = getDocument();
if (!(doc instanceof Document)) {
super.updateDamage(changes, a, f);
return;
}
if (longestLineLength == -1) {
calcLongestLineLength();
}
Component host = getContainer();
updateMetrics();
Element elem = getElement();
DocumentEvent.ElementChange ec = changes.getChange(elem);
Element[] added = (ec != null) ? ec.getChildrenAdded() : null;
Element[] removed = (ec != null) ? ec.getChildrenRemoved() : null;
if (((added != null) && (added.length > 0)) ||
((removed != null) && (removed.length > 0))) {
// lines were added or removed...
if (added != null) {
for (int i = 0; i < added.length; i++) {
int w = getLineWidth(added[i]);
if (w > longestLineLength) {
longestLineLength = w;
longestLine = added[i];
}
}
}
if (removed != null) {
for (int i = 0; i < removed.length; i++) {
if (removed[i] == longestLine) {
calcLongestLineLength();
break;
}
}
}
preferenceChanged(null, true, true);
host.repaint();
} else {
Element map = getElement();
int line = map.getElementIndex(changes.getOffset());
damageLineRange(line, line, a, host);
if (changes.getType() == DocumentEvent.EventType.INSERT) {
// check to see if the line is longer than current longest line.
Element e = map.getElement(line);
int lineLen = getLineWidth(e);
if (e == longestLine) {
preferenceChanged(null, true, false);
} else if (lineLen > longestLineLength) {
longestLineLength = lineLen;
longestLine = e;
preferenceChanged(null, true, false);
}
} else if (changes.getType() == DocumentEvent.EventType.REMOVE) {
if (map.getElement(line) == longestLine) {
// removed from longest line... recalc
calcLongestLineLength();
preferenceChanged(null, true, false);
}
}
}
}
示例12: assertEventsIdentical
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
private void assertEventsIdentical (Document styled, OutputDocument doc, DocumentEvent styEvent, DocumentEvent docEvent) throws Exception {
int docOffset = docEvent.getOffset();
int styOffset = styEvent.getOffset();
int docLength = docEvent.getLength();
int styLength = styEvent.getLength();
assertTrue ("OutputDocument event offset is " + docOffset + " but " +
"offset of identical change to a StyledDocument is " + styOffset,
docOffset == styOffset);
assertTrue ("OutputDocument event length is " + docLength + " but " +
"length from identical change to a StyledDocument is " +
styLength, styLength == docLength);
DocumentEvent.ElementChange docEc = docEvent.getChange(doc);
DocumentEvent.ElementChange styEc = styEvent.getChange(styled.getDefaultRootElement());
int docIndex = docEc.getIndex();
int styIndex = styEc.getIndex();
Element[] docAdded = docEc.getChildrenAdded();
Element[] styAdded = styEc.getChildrenAdded();
assertTrue ("Index of change in OutputDocument was " + docIndex + " but" +
" an identical change on a StyledDocument returns " + styIndex,
styIndex == docIndex);
/*assertTrue ("OutputDocument returned an array of " + docAdded.length +
" affected elements, but an identical change on a StyledDocument " +
"produces an array of " + styAdded.length, styAdded.length ==
docAdded.length);*/
for (int i=0; i < styAdded.length; i++) {
int docStartOffset = docAdded[i].getStartOffset();
int styStartOffset = styAdded[i].getStartOffset();
assertTrue ("Start offset of element " + i + " from " +
"OutputDocument.ODDEvent.EC is " + docStartOffset + " but " +
"offset from identical change in a StyledDocument is " +
styStartOffset, styStartOffset == docStartOffset);
int docEndOffset = docAdded[i].getEndOffset();
int styEndOffset = styAdded[i].getEndOffset();
assertTrue ("End offset of element " + i + " from " +
"OutputDocument.ODDEvent.EC is " + docStartOffset + " but " +
"offset from identical change in a StyledDocument is " +
styEndOffset, styEndOffset == docEndOffset);
String styTxt = styled.getText(styAdded[i].getStartOffset(), styAdded[i].getEndOffset() - styAdded[i].getStartOffset());
String docTxt = styled.getText(styAdded[i].getStartOffset(), styAdded[i].getEndOffset() - styAdded[i].getStartOffset());
assertEquals("Element " + i + " text from styled document is " +
styTxt + " but OutputDocument return " + docTxt + " for the " +
"same indices", styTxt, docTxt);
}
}
示例13: updateChildren
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Update the child views in response to a
* document event.
*/
void updateChildren(DocumentEvent e, Shape a) {
Element elem = getElement();
DocumentEvent.ElementChange ec = e.getChange(elem);
// This occurs when syntax highlighting only changes on lines
// (i.e. beginning a multiline comment).
if (e.getType()==DocumentEvent.EventType.CHANGE) {
//System.err.println("Updating the damage due to a CHANGE event...");
// FIXME: Make me repaint more intelligently.
getContainer().repaint();
//damageLineRange(startLine,endLine, a, host);
}
else if (ec != null) {
// the structure of this element changed.
Element[] removedElems = ec.getChildrenRemoved();
Element[] addedElems = ec.getChildrenAdded();
View[] added = new View[addedElems.length];
for (int i = 0; i < addedElems.length; i++) {
added[i] = new WrappedLine(addedElems[i]);
}
//System.err.println("Replacing " + removedElems.length +
// " children with " + addedElems.length);
replace(ec.getIndex(), removedElems.length, added);
// should damge a little more intelligently.
if (a != null) {
preferenceChanged(null, true, true);
getContainer().repaint();
}
}
// update font metrics which may be used by the child views
updateMetrics();
}
示例14: updateChildren
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
protected boolean updateChildren(DocumentEvent.ElementChange ec,
DocumentEvent e, ViewFactory f) {
return false;
}
示例15: updateLayout
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Update the layout in response to receiving notification of
* change from the model. This is implemented to note the
* change on the ChildLocator so that offsets of the children
* will be correctly computed.
*
* @param ec changes to the element this view is responsible
* for (may be null if there were no changes).
* @param e the change information from the associated document
* @param a the current allocation of the view
* @see #insertUpdate
* @see #removeUpdate
* @see #changedUpdate
*/
protected void updateLayout(DocumentEvent.ElementChange ec,
DocumentEvent e, Shape a) {
if (ec != null) {
// the newly inserted children don't have a valid
// offset so the child locator needs to be messaged
// that the child prior to the new children has
// changed size.
int index = Math.max(ec.getIndex() - 1, 0);
ChildState cs = getChildState(index);
locator.childChanged(cs);
}
}