|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sourceforge.spedit.core.XMLElementWrapper
The XMLElementWrapper
allows a JDOM Element
to appear a Swing Element
. This wrapper does not work for
JDOM Element
but works fine with the
XMLElement
subclass which has been designed for this
purpose.
It is important to note that the XMLElementWrapper
automatically notifies the document of a given element when it changes its
content.
Field Summary | |
protected int |
contentLength
|
static short |
CUT_INSIDE
Indicates that the given block should be cut inside. |
static short |
CUT_LEFT
Indicates that the given block should be cut left. |
static short |
CUT_RIGHT
Indicates that the given block should be cut right. |
static short |
DELETE
Indicates that the given block should be deleted. |
protected XMLElement |
element
|
static short |
ELEMENT_AFTER
Means that the searched element index is located after the current element. |
static short |
ELEMENT_BEFORE
Means that the searched element index is located before the current element. |
static short |
ELEMENT_THIS
Means that the searched element index does correspond to the text directly contained in the wrapped XMLElement , and not in a
child XMLElement . |
protected Position |
endPosition
|
protected XMLInformation |
information
|
static short |
LEAVE
Indicates that the given block should be left as is. |
protected Position |
startPosition
|
Constructor Summary | |
XMLElementWrapper(XMLElement element)
Constructs a new XMLElemetWrapper fron the given
XMLElement , which is a JDOM Element sublass. |
Method Summary | |
Enumeration |
children()
|
boolean |
contains(int start,
int end)
Tells whether the given range is contained withing the element. |
static String |
cutString(String s,
int offset,
int start,
int end)
Cuts the given string according to the operation adviced by the getOperation method. |
boolean |
getAllowsChildren()
|
AttributeSet |
getAttributes()
Fetches the collection of attributes this element contains. |
TreeNode |
getChildAt(int childIndex)
|
int |
getChildCount()
|
Document |
getDocument()
Fetches the document associated with this element. |
Element |
getElement(int index)
Returns the Element that is the nth of this
Element .
Note: The element indexes are different from the wrapped
element indexes, as the wrapper only counts elements that are
XMLElements. |
Element |
getElementAt(int offset)
Searches any descendant element that contains the given offset . |
int |
getElementCount()
Gets the number of child elements contained by this element. |
int |
getElementIndex(int offset)
Gets the child element index closest to the given offset. |
int |
getElementIndex(Object object)
Gets the index of the given object in the child list of this element. |
int |
getEndOffset()
Fetches the offset from the beginning of the document that this element ends at. |
int |
getIndex(TreeNode node)
|
XMLInformation |
getInformation()
Returns the information attached to this element. |
int |
getLength()
Returns the length of this element, int terms of text. |
String |
getName()
Returns the name of the given text element. |
static short |
getOperation(int offset,
int length,
int start,
int end)
Tells which operation should be made on the segmen represented by the given offset and the given length, given the fact that the cut will go from start to end exluded. |
TreeNode |
getParent()
|
Element |
getParentElement()
Returns the parents Element, which can be null if the Element is a root. |
int |
getStartOffset()
Fetches the offset from the beginning of the document that this element begins at. |
int |
getStartOffsetOf(Object object)
Returns the start offset of the given object. |
String |
getWholeText()
|
String |
getWholeText(int start,
int end)
This is an extension to the JDOM getText() method. |
XMLElement |
getXMLElement()
Returns the XMLElement that this wrapper wraps. |
boolean |
hasInformation()
Tells wether this elmement has available information. |
void |
insert(String s,
int offset,
Position.Bias bias)
Inserts the given string after or before the given offset. |
void |
insert(XMLElement elt,
int offset,
Position.Bias bias)
Inserts the given element at the given offset in the text. |
static String |
insertString(String source,
String insert,
int offset,
Position.Bias bias)
Inserts the a string into another at the specified offset. |
boolean |
isLeaf()
Returns true if the Element has no children, otherwise returns false. |
Vector |
remove(int start,
int end)
Removes the text contained between the start and end offsets, the end offset being exclusive. Elements that are fully contained withing the given range will be deleted. |
void |
setInformation(XMLInformation info)
Sets the information attached to this particular element. |
String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final short ELEMENT_BEFORE
public static final short ELEMENT_AFTER
public static final short ELEMENT_THIS
XMLElement
, and not in a
child XMLElement
.public static final short CUT_LEFT
public static final short CUT_RIGHT
public static final short CUT_INSIDE
public static final short DELETE
public static final short LEAVE
protected XMLElement element
protected XMLInformation information
protected int contentLength
protected Position startPosition
protected Position endPosition
Constructor Detail |
public XMLElementWrapper(XMLElement element)
XMLElemetWrapper
fron the given
XMLElement
, which is a JDOM Element
sublass.Method Detail |
public XMLInformation getInformation()
getInformation
in interface XMLNode
XMLInformation
instance.public void setInformation(XMLInformation info)
Sets the information attached to this particular element. In general elements of the same namespace and name share the same information reference. Using this method will set a specific XML information to this element.
You generally should'nt use this method without good reasons
;)
.
setInformation
in interface XMLNode
info
- The new information that will be attached to this element.public boolean hasInformation()
hasInformation
in interface XMLNode
public Enumeration children()
children
in interface TreeNode
public boolean getAllowsChildren()
getAllowsChildren
in interface TreeNode
public TreeNode getChildAt(int childIndex)
getChildAt
in interface TreeNode
public int getChildCount()
getChildCount
in interface TreeNode
public int getIndex(TreeNode node)
getIndex
in interface TreeNode
public TreeNode getParent()
getParent
in interface TreeNode
public int getElementCount()
getElementCount
in interface Element
public Element getElement(int index)
Returns the Element
that is the nth of this
Element
.
Note: The element indexes are different from the wrapped element indexes, as the wrapper only counts elements that are XMLElements.
getElement
in interface Element
index
- The element's index in the wrapper child
list.Element
which is the nth child of the
wrapper, can be null
if not found.public Element getElementAt(int offset)
offset
. This method is an extension of the
getElement
method, which only returns the nth element of
the XMLElement
content.offset
- is the offset of the element in the text. If
this offset is lower than getStartOffset()
or higher or
equal to getEndOffset()
then null is returned.Element
or null is offset
is out of the XMLElement bounds.public int getElementIndex(int offset)
getElementIndex
in interface Element
offset
- - the specified offset >= 0- Returns:
- Returns: the element >= 0
public int getElementIndex(Object object)
public int getStartOffset()
0
getStartOffset
in interface Element
0
in case the element is not attached to a document.public int getEndOffset()
getEndOffset
in interface Element
0
in case the element is not attached to a document.public int getLength()
getEndOffset()
and getStartOffset()
.public int getStartOffsetOf(Object object)
XMLText
to get its start offset. If the object was
not a child of the current element, then -1
is returned.object
- The object from which we want the start offset.-1
if the object is not a
child of the current element.public boolean contains(int start, int end)
public void insert(String s, int offset, Position.Bias bias)
s
- is the text that will be inserted.offset
- is the offset at which the string will
be inserted. Attention, the offset begins at the
getStartOffset()
value.bias
- tells wether the text has to be prepended,
which is Position.Bias.backward
, or appended, which is
Position.Bias.forward.For example, if you
insert("X",2,Position.Bias.forward) into
"ABCDE"
, you'll get ABCXDE
, you would
have get other ABXCDE
public void insert(XMLElement elt, int offset, Position.Bias bias)
insert
method.elt
- The XMLElement
to be inserted.offset
- The offset of insertion in the current
text. Once again the offset is absolute and not relative to the
current element.bias
- The bias as specified before.public static String insertString(String source, String insert, int offset, Position.Bias bias)
source
- is the string in which the other will be
inserted.insert
- is the string that will be inserted into
the other one.offset
- is the offset of insertion in the offset
string.bias
- is backward, this will prepend the string,
if forward it will append it.public Vector remove(int start, int end)
start
- The start offset where text deletion will
begin.end
- The first charachter that will not be
deleted after the start offset.public static short getOperation(int offset, int length, int start, int end)
start
to end
exluded.public static String cutString(String s, int offset, int start, int end)
getOperation
method.public String getWholeText()
getWholeText
in interface XMLNode
public String getWholeText(int start, int end)
getWholeText
in interface XMLNode
start
- is the start offset in the text.end
- is the end offset in the text, and is
exclusive, which means if you add getLength()
to
getStartOffset()
, you will be out of the bounds of the
current element.public AttributeSet getAttributes()
getAttributes
in interface Element
public Document getDocument()
getDocument
in interface Element
public String getName()
getName
in interface Element
public Element getParentElement()
getParentElement
in interface Element
public boolean isLeaf()
isLeaf
in interface Element
public XMLElement getXMLElement()
XMLElement
that this wrapper wraps.public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |