本文整理汇总了Java中javax.swing.event.DocumentEvent.getChange方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentEvent.getChange方法的具体用法?Java DocumentEvent.getChange怎么用?Java DocumentEvent.getChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.event.DocumentEvent
的用法示例。
在下文中一共展示了DocumentEvent.getChange方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: checkEventsEqual
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
private void checkEventsEqual(DocumentEvent testEvent) {
if (masterEvent.getOffset() != testEvent.getOffset()) {
fail("masterEvent.getOffset()=" + masterEvent.getOffset()
+ " != testEvent.getOffset()=" + testEvent.getOffset());
}
if (masterEvent.getLength() != testEvent.getLength()) {
fail("masterEvent.getLength()=" + masterEvent.getLength()
+ " != testEvent.getLength()=" + testEvent.getLength());
}
if (masterEvent.getType() != testEvent.getType()) {
fail("masterEvent.getType()=" + masterEvent.getType()
+ " != testEvent.getType()=" + testEvent.getType());
}
DocumentEvent.ElementChange masterChange = masterEvent.getChange(masterDoc.getDefaultRootElement());
DocumentEvent.ElementChange testChange = testEvent.getChange(testDoc.getDefaultRootElement());
checkElementChangesEqual(masterChange, testChange);
}
示例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: putEventPropertyIfSupported
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Sets a property for the document event, if the event supports the feature.
* Returns true, if the property was actually set.
*
* @param evt the event to modify
* @param key property key
* @param value property value
* @return true, if the property was set
* @since 1.59
*/
public static boolean putEventPropertyIfSupported(DocumentEvent evt, Object key, Object value) {
EventPropertiesElementChange change = (EventPropertiesElementChange)
evt.getChange(EventPropertiesElement.INSTANCE);
if (change != null) {
putEventProperty(evt, key, value);
return true;
} else {
return false;
}
}
示例6: putEventProperty
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Set a property of a given document event.
*
* @param evt non-null document event to which the property should be stored.
* @param key non-null key of the property.
* @param value for the given property.
*/
public static void putEventProperty(DocumentEvent evt, Object key, Object value) {
EventPropertiesElementChange change = (EventPropertiesElementChange)
evt.getChange(EventPropertiesElement.INSTANCE);
if (change == null) {
throw new IllegalStateException("addEventPropertyStorage() not called for evt=" + evt); // NOI18N
}
change.putProperty(key, value);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
}
}
}
示例11: 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);
}
}
示例12: fireInsertUpdate
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Alerts all listeners to this document of an insertion. This is
* overridden so we can update our syntax highlighting stuff.<p>
* The syntax highlighting stuff has to be here instead of in
* <code>insertUpdate</code> because <code>insertUpdate</code> is not
* called by the undo/redo actions, but this method is.
*
* @param e The change.
*/
@Override
protected void fireInsertUpdate(DocumentEvent e) {
cachedTokenList = null;
/*
* Now that the text is actually inserted into the content and
* element structure, we can update our token elements and "last
* tokens on lines" structure.
*/
Element lineMap = getDefaultRootElement();
DocumentEvent.ElementChange change = e.getChange(lineMap);
Element[] added = change==null ? null : change.getChildrenAdded();
int numLines = lineMap.getElementCount();
int line = lineMap.getElementIndex(e.getOffset());
int previousLine = line - 1;
int previousTokenType = (previousLine>-1 ?
lastTokensOnLines.get(previousLine) : Token.NULL);
// If entire lines were added...
if (added!=null && added.length>0) {
Element[] removed = change.getChildrenRemoved();
int numRemoved = removed!=null ? removed.length : 0;
int endBefore = line + added.length - numRemoved;
//System.err.println("... adding lines: " + line + " - " + (endBefore-1));
//System.err.println("... ... added: " + added.length + ", removed:" + numRemoved);
for (int i=line; i<endBefore; i++) {
setSharedSegment(i); // Loads line i's text into s.
int tokenType = tokenMaker.getLastTokenTypeOnLine(s, previousTokenType);
lastTokensOnLines.add(i, tokenType);
//System.err.println("--------- lastTokensOnLines.size() == " + lastTokensOnLines.getSize());
previousTokenType = tokenType;
} // End of for (int i=line; i<endBefore; i++).
// Update last tokens for lines below until they stop changing.
updateLastTokensBelow(endBefore, numLines, previousTokenType);
} // End of if (added!=null && added.length>0).
// Otherwise, text was inserted on a single line...
else {
// Update last tokens for lines below until they stop changing.
updateLastTokensBelow(line, numLines, previousTokenType);
} // End of else.
// Let all listeners know about the insertion.
super.fireInsertUpdate(e);
}
示例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: getEventProperty
import javax.swing.event.DocumentEvent; //导入方法依赖的package包/类
/**
* Get a property of a given document event.
*
* @param evt non-null document event from which the property should be retrieved.
* @param key non-null key of the property.
* @return value for the given property.
*/
public static Object getEventProperty(DocumentEvent evt, Object key) {
EventPropertiesElementChange change = (EventPropertiesElementChange)
evt.getChange(EventPropertiesElement.INSTANCE);
return (change != null) ? change.getProperty(key) : null;
}