org.brains2b.thex
Class BinaryElement

java.lang.Object
  extended by org.brains2b.thex.BinaryElement
All Implemented Interfaces:
javax.swing.text.Element

public class BinaryElement
extends java.lang.Object
implements javax.swing.text.Element

Element for BinaryDocument

This element can be used both to contain other elements a contain the data itself

getState() determines where the actual content of this Element is kept

Version:
$Revision: 1.5 $ $Date: 2010/01/15 03:53:05 $
Author:
dennis@brains2b.nl

Constructor Summary
BinaryElement(javax.swing.text.Document document, javax.swing.text.AttributeSet attributes, byte[] b)
          Constructor
BinaryElement(javax.swing.text.Document document, javax.swing.text.AttributeSet attributes, int length)
          Constructor
 
Method Summary
 void addElement(BinaryElement element)
          add an Element to this BinaryElement
 javax.swing.text.AttributeSet getAttributes()
          
 byte[] getBytes()
          get the content for this Element
 javax.swing.text.Document getDocument()
          
 javax.swing.text.Element getElement(int index)
          
 int getElementCount()
          
 int getElementIndex(int offset)
          
 int getEndOffset()
          
 java.lang.String getName()
          
 javax.swing.text.Element getParentElement()
          
 int getStartOffset()
          
 int getState()
          get the state for this Element
 boolean isLeaf()
          
 void setBytes(byte[] bytes)
          set the content for this Element
 void setBytes(byte[] bytes, int offset, int length)
          set the content for this Element
 void setLength(int length)
          set the length for this Element
 void setState(int state)
          set the state for this Element
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryElement

public BinaryElement(javax.swing.text.Document document,
                     javax.swing.text.AttributeSet attributes,
                     int length)
Constructor

Parameters:
document - BinaryDocument, the document that contains this Element
attributes - AttributeSet currently unused
length - int length of this Element

BinaryElement

public BinaryElement(javax.swing.text.Document document,
                     javax.swing.text.AttributeSet attributes,
                     byte[] b)
Constructor

Parameters:
document - BinaryDocument, the document that contains this Element
attributes - AttributeSet currently unused
b - byte[] the content for this Element
Method Detail

getAttributes

public javax.swing.text.AttributeSet getAttributes()

Specified by:
getAttributes in interface javax.swing.text.Element

getDocument

public javax.swing.text.Document getDocument()

Specified by:
getDocument in interface javax.swing.text.Element

getElement

public javax.swing.text.Element getElement(int index)

Specified by:
getElement in interface javax.swing.text.Element

getElementCount

public int getElementCount()

Specified by:
getElementCount in interface javax.swing.text.Element

getElementIndex

public int getElementIndex(int offset)

Specified by:
getElementIndex in interface javax.swing.text.Element

getEndOffset

public int getEndOffset()

Specified by:
getEndOffset in interface javax.swing.text.Element

getName

public java.lang.String getName()

Specified by:
getName in interface javax.swing.text.Element

getParentElement

public javax.swing.text.Element getParentElement()

Specified by:
getParentElement in interface javax.swing.text.Element

getStartOffset

public int getStartOffset()

Specified by:
getStartOffset in interface javax.swing.text.Element

isLeaf

public boolean isLeaf()

Specified by:
isLeaf in interface javax.swing.text.Element

addElement

public void addElement(BinaryElement element)
add an Element to this BinaryElement

Parameters:
element - BinaryElement

setLength

public void setLength(int length)
set the length for this Element

Parameters:
length - int the length for this Element

getState

public int getState()
get the state for this Element

Returns:
int either (BinaryIOKit.ELEMENT_ALTER|BinaryIOKit.ELEMENT_OLD|BinaryIOKit.ELEMENT_MEMORY)

setState

public void setState(int state)
set the state for this Element

Parameters:
state - int either (BinaryIOKit.ELEMENT_ALTER|BinaryIOKit.ELEMENT_OLD|BinaryIOKit.ELEMENT_MEMORY)

getBytes

public byte[] getBytes()
get the content for this Element

Returns:
byte[], if there is no content EMPTY is returned

setBytes

public void setBytes(byte[] bytes)
set the content for this Element

Parameters:
bytes - byte[]

setBytes

public void setBytes(byte[] bytes,
                     int offset,
                     int length)
set the content for this Element

Parameters:
bytes - byte[]
offset - int start of the byte[] to set as content
length - int length of the byte[] to set as content