public class MarkManager extends PropertySet implements DocumentListener
Modifier and Type | Class and Description |
---|---|
static class |
MarkManager.CompareByPosition
Compares two
TextLocation s by their document position. |
Modifier and Type | Field and Description |
---|---|
boolean |
autoAddingDot |
static MarkManager.CompareByPosition |
COMPARE_BY_POSITION
A ready-to-use CompareByPosition instance.
|
XMLClipboard |
xmlClipboard |
properties
Constructor and Description |
---|
MarkManager(XMLClipboard xmlClipboard,
boolean autoAddingDot,
Document document)
Constructs a mark manager attached to specified document.
|
Modifier and Type | Method and Description |
---|---|
NodeMark |
add(Object id,
Node node)
Adds NodeMark with specified ID to specified location.
|
TextLocation |
add(Object id,
TextNode text,
int offset)
Adds TextLocation with specified ID to specified location.
|
TextLocation |
add(Object id,
TextNode text,
int offset,
boolean cursor)
Adds TextLocation with specified ID to specified location.
|
void |
addContextChangeListener(ContextChangeListener listener)
Adds specified listener.
|
void |
addMarkChangeListener(MarkChangeListener listener)
Adds specified listener.
|
void |
attributeChanged(AttributeEvent event,
int listenerIndex)
Invoked when an attribute has been added, changed, removed to/from an
element.
|
void |
beginMark()
Prevents this manager to notify its listeners when marks are changed
until
endMark() is invoked. |
boolean |
contains(Object id)
Returns
true if this manager manages mark with specified
ID. |
void |
editCompleted(EditEvent event,
int listenerIndex)
Invoked when a sequence of modifications, considered as being a whole,
is finished.
|
void |
editStarted(EditEvent event,
int listenerIndex)
Invoked when a sequence of modifications, considered as being a whole,
has started.
|
void |
elementNameChanged(ElementNameEvent event,
int listenerIndex)
Invoked after the name of a element is changed.
|
void |
endMark()
Stops preventing this manager to notify its listeners when marks are
changed.
|
void |
eventHappened(DocumentEvent event,
int listenerIndex)
Invoked by a document listener to communicate with other document
listeners.
|
Mark |
get(Object id)
Returns mark with specified ID.
|
Mark[] |
getAll()
Returns all marks managed by this manager.
|
int |
getCount()
Returns number of marks managed by this manager.
|
Document |
getDocument()
Specifies or changes the document to which this mark manager is
attached (a mark manager is a
DocumentListener ). |
TextLocation |
getDot()
Returns the dot mark if any;
null otherwise. |
TextLocation |
getMark()
Returns the mark mark if any;
null otherwise. |
NodeMark |
getSelected()
Returns the selected mark if any;
null otherwise. |
NodeMark |
getSelected2()
Returns the selected2 mark if any;
null otherwise. |
void |
inclusionUpdated(InclusionUpdatedEvent event,
int listenerIndex)
Invoked when an
Inclusion has been updated, that is, that
a sequence of contiguous included nodes has been replaced by another
sequence of contiguous included nodes. |
void |
notifyContextChangeListeners()
|
void |
notifyContextChangeListeners(ContextChangeEvent.Reason reason)
Notify context change listeners.
|
void |
processingInstructionChanged(ProcessingInstructionEvent event,
int listenerIndex)
Invoked after the target of a processing instruction is changed.
|
Mark |
remove(Object id)
Removes (unmanages) mark with specified ID.
|
void |
removeAll()
Remove all marks managed by this manager.
|
void |
removeAll(String[] idPrefixes)
Remove some marks managed by this manager.
|
void |
removeContextChangeListener(ContextChangeListener listener)
Removes specified listener.
|
void |
removeMarkChangeListener(MarkChangeListener listener)
Removes specified listener.
|
NodeMark |
set(Object id,
Node node)
Adds or moves NodeMark with specified ID to specified location.
|
TextLocation |
set(Object id,
TextNode text,
int offset)
Adds or moves TextLocation with specified ID to specified location.
|
TextLocation |
set(Object id,
TextNode text,
int offset,
boolean cursor)
Adds or moves TextLocation with specified ID to specified location.
|
void |
setDocument(Document document)
Specifies or changes the document to which this mark manager is
attached (a mark manager is a
DocumentListener ). |
void |
textChanged(TextEvent event,
int listenerIndex)
Invoked when characters have been changed in a text node (text,
comment, processing instruction).
|
void |
treeChanged(TreeEvent event,
int listenerIndex)
Invoked when a child node has been added, replaced or removed to/from
an element.
|
getProperties, getProperty, getPropertyCount, hasProperty, putProperties, putProperty, removeAllProperties, removeProperty
public final XMLClipboard xmlClipboard
public final boolean autoAddingDot
public static final MarkManager.CompareByPosition COMPARE_BY_POSITION
public MarkManager(XMLClipboard xmlClipboard, boolean autoAddingDot, Document document)
xmlClipboard
- the clipboard cache.autoAddingDot
- if true, enable the auto-add-dot featuredocument
- attach mark manager to this document.
May be null
.setDocument(com.xmlmind.xml.doc.Document)
public void setDocument(Document document)
DocumentListener
).
If this mark manager was previously attached to another document, all marks put on this document are automatically removed.
public Document getDocument()
DocumentListener
).public NodeMark set(Object id, Node node)
id
- id of mark to be added or movednode
- node to be markedpublic TextLocation set(Object id, TextNode text, int offset)
id
- id of mark to be added or movedtext
- textual node containing character to be markedoffset
- index within textual node of character to be markedpublic TextLocation set(Object id, TextNode text, int offset, boolean cursor)
id
- id of mark to be added or movedtext
- textual node containing character to be markedoffset
- index within textual node of character to be markedcursor
- if added, newly created TextLocation has cursor behaviorpublic NodeMark add(Object id, Node node)
id
- id of mark to be added or movednode
- node to be markednull
if mark with specified ID
is already managed by this managerpublic TextLocation add(Object id, TextNode text, int offset)
id
- id of mark to be added or movedtext
- textual node containing character to be markedoffset
- index within textual node of character to be markednull
if mark with specified
ID is already managed by this managerpublic TextLocation add(Object id, TextNode text, int offset, boolean cursor)
id
- id of mark to be added or movedtext
- textual node containing character to be markedoffset
- index within textual node of character to be markedcursor
- if added, newly created TextLocation has cursor behaviornull
if mark with specified
ID is already managed by this managerpublic Mark remove(Object id)
id
- ID of mark to be removed.null
if no mark with specified ID
was managed by this managerpublic void removeAll(String[] idPrefixes)
idPrefixes
- the ID prefixes of the marks to be removedpublic void removeAll()
public boolean contains(Object id)
true
if this manager manages mark with specified
ID. Returns false
otherwise.public int getCount()
public TextLocation getDot()
null
otherwise.
Newly typed characters are inserted at the dot text location. The dot text location is visualized by the caret.
public TextLocation getMark()
null
otherwise.
The text range between mark and dot, if not empty, is called the text selection.
public NodeMark getSelected()
null
otherwise.
The node range between selected and selected2 is called the node selection. If there is no selected2 mark, the node selection consists in the single node marked by selected.
public NodeMark getSelected2()
null
otherwise.
The node range between selected and selected2 is called the node selection. If there is no selected2 mark, the node selection consists in the single node marked by selected.
public Mark get(Object id)
null
if this
manager does not manage such mark.public Mark[] getAll()
public void beginMark()
endMark()
is invoked.
Calls to this method can be nested, in which case this method does nothing at all.
Commands often use this method because they often need to remove several marks (example: selected2 and mark) and at the same time, move other marks (example: selected or dot). Without beginMark/endMark, several editing context changes are reported instead of a single one. Editing context changes generally cause the application to enable or disable its menu, its toolbars, to update its status bar, its panes, etc, that is, this is generally a computation intensive operation.
public void endMark()
There must be a call to endMark for each call to
beginMark()
.
public void addMarkChangeListener(MarkChangeListener listener)
public void removeMarkChangeListener(MarkChangeListener listener)
public void addContextChangeListener(ContextChangeListener listener)
public void removeContextChangeListener(ContextChangeListener listener)
public void notifyContextChangeListeners()
public void notifyContextChangeListeners(ContextChangeEvent.Reason reason)
reason
- reason why the ContextChangeEvent
is sentpublic void editStarted(EditEvent event, int listenerIndex)
DocumentListener
editStarted
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void editCompleted(EditEvent event, int listenerIndex)
DocumentListener
editCompleted
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void textChanged(TextEvent event, int listenerIndex)
DocumentListener
textChanged
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void inclusionUpdated(InclusionUpdatedEvent event, int listenerIndex)
DocumentListener
Inclusion
has been updated, that is, that
a sequence of contiguous included nodes has been replaced by another
sequence of contiguous included nodes.inclusionUpdated
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void treeChanged(TreeEvent event, int listenerIndex)
DocumentListener
treeChanged
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void eventHappened(DocumentEvent event, int listenerIndex)
DocumentListener
eventHappened
in interface DocumentListener
event
- contains the ``message'' sent by the invoker.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void attributeChanged(AttributeEvent event, int listenerIndex)
DocumentListener
attributeChanged
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void processingInstructionChanged(ProcessingInstructionEvent event, int listenerIndex)
DocumentListener
processingInstructionChanged
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)
public void elementNameChanged(ElementNameEvent event, int listenerIndex)
DocumentListener
elementNameChanged
in interface DocumentListener
event
- contains details about what has happened.listenerIndex
- may be used to retrieve data, private to the
listener, attached to a document nodeNode.getDocumentListenerData(int)