java - Get changed content in DocumentEvent -


Target:
Working with a Zedpane and HTML document I need feedback to delete images, i.e. Defined elements & lt; Img & gt; .. & lt; / Img & gt; tag.

What I tried:
For now I use DocumentListeners to respond to the document event, which is a document. Unfortunately, documented events do not contain information about straight content, so I can not tell what kind of element has been removed. It seems that what I can do is iterative over all elements of the document and Receive events (change) Call (Change)

  document.addDocumentListener {@Override public void removeUpdate (DocumentEvent arg0) {ElementIterator iter = new ElementIterator (document); Element element; While ((element = iter.next ()) = = null {ElementChange change = arg0.getChange (element); if (change! = Null) {Element [] children = change.getChildrenRemoved (); (element child: children) {Object name = child.getAttributes (). GetAttribute (StyleConstants.NameAttribute); System.out.println ((HTML.Tag) name);}}} NotifyContentChanged ();}}) for; }  

Although this solution works partially (sometimes when removing an image from sysout a p-implied a img Reporting instead) I will really appreciate other solutions Perhaps someone knows a simple way to get the string associated with the change in the document?

Solution According to the accepted answer, the following code shows the use of the document filter as viewers (in this case to remove the image).

  document.setDocumentFilter (New DocumentFilter () {@Override Public Zero Extract (FilterBypass fb, int offset, infinite length) throws badlocation expeditions (if (document.getCharacterElement (offset) .getName ( ). PAR (HTML.Tag.IMG.toString ()) {.} Super .remove (fb, offset, length);}});  

Generally the images are skipped, so that you use htmlDocument.getCharacterElement () from the range of change And check if they are images.

UPDATE: Due to disconnection in the Commons

You can add a document filter overriding () to extract () and use as a listener to get deleted pieces (actually to-to- Deleted pieces).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -