org.brains2b.thex
Class BinaryDocument

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

public class BinaryDocument
extends java.lang.Object
implements javax.swing.text.Document

BinaryDocument is the content provider for binary data.

The content is stored in the Elements of this Documents. These Elements are able to be loaded from the BinaryIOKit to only use when accessed.

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

Field Summary
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
BinaryDocument()
          Constructor with no content
BinaryDocument(byte[] b)
          Constructor setting byte[] as content
 
Method Summary
 void addDocumentListener(javax.swing.event.DocumentListener listener)
          
 void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
          
 javax.swing.text.Position createPosition(int offs)
          
 void documentUpdated()
          mark this document as updated and reset all changes by firing fireInsertUpdate(DocumentEvent) but no UndoableEditEvent
protected  void fireChangedUpdate(javax.swing.event.DocumentEvent de)
          fire the DocumentEvent changed for all listeners
protected  void fireInsertUpdate(javax.swing.event.DocumentEvent de)
          fire the DocumentEvent insert for all listeners
protected  void fireRemoveUpdate(javax.swing.event.DocumentEvent de)
          fire the DocumentEvent remove for all listeners
protected  void fireUndoableEdit(javax.swing.event.UndoableEditEvent ue)
          fire the UndoableEditEvent for all listeners
 byte[] getBytes(int offset, int length)
          get the content of this document as byte[]
 javax.swing.text.Element getDefaultRootElement()
          
 javax.swing.text.Position getEndPosition()
          
 java.lang.String getLastString()
          get the character that was typed as first part of a hexidecimal twosome or null if there was an equal number of valid characters entered
 int getLength()
          
 java.lang.Object getProperty(java.lang.Object key)
          
 javax.swing.text.Element[] getRootElements()
          
 javax.swing.text.Position getStartPosition()
          
 java.lang.String getText(int offset, int length)
          
 void getText(int offset, int length, javax.swing.text.Segment txt)
          
 void insertBytes(int offset, byte[] b, javax.swing.text.AttributeSet a)
          insert bytes into this document
 void insertString(int offset, java.lang.String str, javax.swing.text.AttributeSet a)
          
 void putProperty(java.lang.Object key, java.lang.Object value)
          
 void remove(int offs, int len)
          
 void removeBytes(int offset, int len)
          remove bytes from this document between offset and length
 void removeDocumentListener(javax.swing.event.DocumentListener listener)
          
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
          
 void render(java.lang.Runnable r)
          
 void replaceBytes(int offset, int length, byte[] b, javax.swing.text.AttributeSet atts)
          replace the current content at offset and length with the new byte[]
 void setLastString(java.lang.String lastString)
          set the first character of a hexidecimal twosome or null if there should not be one
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryDocument

public BinaryDocument()
Constructor with no content


BinaryDocument

public BinaryDocument(byte[] b)
Constructor setting byte[] as content

Parameters:
b - byte[]
Method Detail

addDocumentListener

public void addDocumentListener(javax.swing.event.DocumentListener listener)

Specified by:
addDocumentListener in interface javax.swing.text.Document

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)

Specified by:
addUndoableEditListener in interface javax.swing.text.Document

createPosition

public javax.swing.text.Position createPosition(int offs)
                                         throws javax.swing.text.BadLocationException

Specified by:
createPosition in interface javax.swing.text.Document
Throws:
javax.swing.text.BadLocationException

getDefaultRootElement

public javax.swing.text.Element getDefaultRootElement()

Specified by:
getDefaultRootElement in interface javax.swing.text.Document

getEndPosition

public javax.swing.text.Position getEndPosition()

Specified by:
getEndPosition in interface javax.swing.text.Document

getLength

public int getLength()

Specified by:
getLength in interface javax.swing.text.Document

getProperty

public java.lang.Object getProperty(java.lang.Object key)

Specified by:
getProperty in interface javax.swing.text.Document

getRootElements

public javax.swing.text.Element[] getRootElements()

Specified by:
getRootElements in interface javax.swing.text.Document

getStartPosition

public javax.swing.text.Position getStartPosition()

Specified by:
getStartPosition in interface javax.swing.text.Document

getText

public java.lang.String getText(int offset,
                                int length)
                         throws javax.swing.text.BadLocationException

Specified by:
getText in interface javax.swing.text.Document
Throws:
javax.swing.text.BadLocationException

getText

public void getText(int offset,
                    int length,
                    javax.swing.text.Segment txt)
             throws javax.swing.text.BadLocationException

Specified by:
getText in interface javax.swing.text.Document
Throws:
javax.swing.text.BadLocationException

insertString

public void insertString(int offset,
                         java.lang.String str,
                         javax.swing.text.AttributeSet a)
                  throws javax.swing.text.BadLocationException

Specified by:
insertString in interface javax.swing.text.Document
Throws:
javax.swing.text.BadLocationException

getBytes

public byte[] getBytes(int offset,
                       int length)
                throws javax.swing.text.BadLocationException
get the content of this document as byte[]

Parameters:
offset - int start of the content to return
length - int length of the content to return
Returns:
byte[]
Throws:
javax.swing.text.BadLocationException - if the content between offset and length cannot be retrieved
See Also:
getText(int, int)

insertBytes

public void insertBytes(int offset,
                        byte[] b,
                        javax.swing.text.AttributeSet a)
                 throws javax.swing.text.BadLocationException
insert bytes into this document

Parameters:
offset - int position to insert the byte[] at
b - byte[]
a - AttributeSet not used
Throws:
javax.swing.text.BadLocationException - if the content cannot be inserted at the given offset
See Also:
insertString(int, String, AttributeSet)

putProperty

public void putProperty(java.lang.Object key,
                        java.lang.Object value)

Specified by:
putProperty in interface javax.swing.text.Document

remove

public void remove(int offs,
                   int len)
            throws javax.swing.text.BadLocationException

Specified by:
remove in interface javax.swing.text.Document
Throws:
javax.swing.text.BadLocationException

removeBytes

public void removeBytes(int offset,
                        int len)
                 throws javax.swing.text.BadLocationException
remove bytes from this document between offset and length

Parameters:
offset - int
len - int
Throws:
javax.swing.text.BadLocationException - if the content cannot be found between offset and length
See Also:
remove(int, int)

removeDocumentListener

public void removeDocumentListener(javax.swing.event.DocumentListener listener)

Specified by:
removeDocumentListener in interface javax.swing.text.Document

removeUndoableEditListener

public void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)

Specified by:
removeUndoableEditListener in interface javax.swing.text.Document

replaceBytes

public void replaceBytes(int offset,
                         int length,
                         byte[] b,
                         javax.swing.text.AttributeSet atts)
                  throws javax.swing.text.BadLocationException
replace the current content at offset and length with the new byte[]

Parameters:
offset - int position to replace the byte[] with
length - int length of content to remove
b - byte[]
atts - AttributeSet not used
Throws:
javax.swing.text.BadLocationException - if the content cannot be inserted at the given offset and length

render

public void render(java.lang.Runnable r)

Specified by:
render in interface javax.swing.text.Document

fireChangedUpdate

protected void fireChangedUpdate(javax.swing.event.DocumentEvent de)
fire the DocumentEvent changed for all listeners

Parameters:
de - DocumentEvent

fireInsertUpdate

protected void fireInsertUpdate(javax.swing.event.DocumentEvent de)
fire the DocumentEvent insert for all listeners

Parameters:
de - DocumentEvent

fireRemoveUpdate

protected void fireRemoveUpdate(javax.swing.event.DocumentEvent de)
fire the DocumentEvent remove for all listeners

Parameters:
de - DocumentEvent

fireUndoableEdit

protected void fireUndoableEdit(javax.swing.event.UndoableEditEvent ue)
fire the UndoableEditEvent for all listeners

Parameters:
ue - UndoableEditEvent

getLastString

public java.lang.String getLastString()
get the character that was typed as first part of a hexidecimal twosome or null if there was an equal number of valid characters entered

Returns:
String

setLastString

public void setLastString(java.lang.String lastString)
set the first character of a hexidecimal twosome or null if there should not be one

Parameters:
lastString - String

documentUpdated

public void documentUpdated()
mark this document as updated and reset all changes by firing fireInsertUpdate(DocumentEvent) but no UndoableEditEvent