Java Code Examples for javax.swing.event.DocumentEvent#getType()
The following examples show how to use
javax.swing.event.DocumentEvent#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentUtilities.java From netbeans with Apache License 2.0 | 6 votes |
/** * Get string representation of an offset for debugging purposes * in form "offset[line:column]". Both lines and columns start counting from 1 * like in the editor's status bar. Tabs are expanded when counting the column. * * @param sb valid string builder to which text will be appended or null in which case * the method itself will create a string builder and it will return it. * @param evt non-null document event. * @return non-null string builder to which the description was added. * @since 1.27 */ public static StringBuilder appendEvent(StringBuilder sb, DocumentEvent evt) { if (sb == null) { sb = new StringBuilder(100); } DocumentEvent.EventType type = evt.getType(); sb.append(type).append(", "); appendOffset(sb, evt.getDocument(), evt.getOffset()); sb.append(", l=").append(evt.getLength()); // Possibly append the modification text String modText; if ((modText = getModificationText(evt)) != null) { sb.append(", modText=\""); CharSequenceUtilities.debugText(sb, modText); sb.append('"'); } return sb; }
Example 2
Source File: PlainDocumentCompatibilityRandomTest.java From netbeans with Apache License 2.0 | 6 votes |
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); }
Example 3
Source File: DocumentUtilities.java From netbeans with Apache License 2.0 | 5 votes |
/** * 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; }
Example 4
Source File: ExtPlainView.java From netbeans with Apache License 2.0 | 4 votes |
@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); } } } }
Example 5
Source File: StatusBar.java From netbeans with Apache License 2.0 | 4 votes |
public void insertUpdate(DocumentEvent evt) { if (evt.getType() == DocumentEvent.EventType.REMOVE) { // undo documentUndo(evt); } }
Example 6
Source File: StatusBar.java From netbeans with Apache License 2.0 | 4 votes |
public void removeUpdate(DocumentEvent evt) { if (evt.getType() == DocumentEvent.EventType.INSERT) { // undo documentUndo(evt); } }
Example 7
Source File: ModRootElement.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void removeUpdate(DocumentEvent evt) { if (evt.getType() == DocumentEvent.EventType.REMOVE) { changedUpdate(evt); } }
Example 8
Source File: ModRootElement.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void insertUpdate(DocumentEvent evt) { if (evt.getType() == DocumentEvent.EventType.INSERT) { changedUpdate(evt); } }