com.lightdev.app.shtm
Class DocumentPane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.lightdev.app.shtm.DocumentPane
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener, javax.swing.event.DocumentListener

public class DocumentPane
extends javax.swing.JPanel
implements javax.swing.event.DocumentListener, javax.swing.event.ChangeListener

GUI representation of a document.

Swing already uses three types of classes to implement a model, view, controller (MVC) approach for a document:

JTextComponent - the view implementation
Document - the model implementation
EditorKit - the controller implementation

For a GUI representation of a document, additional parts are needed, such as a JScrollPane as well as listeners and fields to track the state of the document while it is represented on a GUI.

DocumentPane wraps all those elements to implement a single document centric external view to all elements.

If for instance an application wants to create a new document, it simply creates an instance of this class instead of having to implement own methods for instatiating each element (editor pane, scroll pane, etc.) separately.

See Also:
Serialized Form

Nested Class Summary
 class DocumentPane.DocumentPaneEvent
          the event object definition for DocumentPaneEvents
static interface DocumentPane.DocumentPaneListener
          interface to be implemented for being notified of changes to the name of this document
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String DEFAULT_STYLE_SHEET_NAME
          default name for style sheet, when saved
 boolean saveSuccessful
          indicator if a save operation was succesful
 java.lang.Thread saveThread
          the save thread, if a save operation is in progress
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DocumentPane()
          construct a new DocumentPane.
DocumentPane(java.net.URL docToLoad, int newDocNo)
          construct a new DocumentPane with either a new Document or an exisiting Document that is to be loaded into the DocumentPane upon construction.
 
Method Summary
 void addDocumentPaneListener(DocumentPane.DocumentPaneListener listener)
          add a DocumentPaneListener to this Document
 void changedUpdate(javax.swing.event.DocumentEvent e)
          listens to changes on the document to track whether or not the document needs to be saved.
 void createNewDocument()
          create a new HTMLDocument and attach it to the editor
 void deleteTempDir()
          remove the temporary storage created for this DocumentPane
 void fireActivated()
          fire a DocumentPaneEvent to all registered DocumentPaneListeners
 void fireNameChanged()
          fire a DocumentPaneEvent to all registered DocumentPaneListeners
 javax.swing.text.Document getDocument()
          get the document of this DocumentPane
 java.lang.String getDocumentName()
          get the name of the document of this pane.
 SHTMLEditorPane getEditor()
          get the JEditorPane of this DocumentPane
 java.io.File getImageDir()
          determine the directory this DocumentPane references image files from
 java.net.URL getOldSource()
          get the source, this document was having before its current sourceUrl was set.
 java.net.URL getSource()
          get the source this document can be loaded from
 void insertUpdate(javax.swing.event.DocumentEvent e)
          listens to inserts into the document to track whether or not the document needs to be saved.
 boolean isNewDoc()
          indicates whether or not this document was newly created and not saved so far.
 void loadDocument(java.net.URL url)
          load a document found at a certain URL.
 boolean needsSaving()
          indicates whether or not the document needs to be saved.
 void removeAllListeners()
          remove all listeners
 void removeDocumentPaneListener(DocumentPane.DocumentPaneListener listener)
          remove a DocumentPaneListener from this Document
 void removeUpdate(javax.swing.event.DocumentEvent e)
          listens to removes from the document to track whether or not the document needs to be saved.
 void saveDocument()
          saves the document to the file specified in the source of the DocumentPane and creates the associated style sheet.
 boolean saveInProgress()
          indicates whether or not a save process is in progress
 void saveStyleSheet()
          save the style sheet of this document to a CSS file.
 void setDocument(javax.swing.text.Document docToSet)
           
 void setSource(java.net.URL source)
          set the source this document is to be loaded from
 void stateChanged(javax.swing.event.ChangeEvent e)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

saveThread

public java.lang.Thread saveThread
the save thread, if a save operation is in progress


saveSuccessful

public boolean saveSuccessful
indicator if a save operation was succesful


DEFAULT_STYLE_SHEET_NAME

public static java.lang.String DEFAULT_STYLE_SHEET_NAME
default name for style sheet, when saved

Constructor Detail

DocumentPane

public DocumentPane()
construct a new DocumentPane.

A document still has to be either created or loaded after using this constructor, so it is better to use the constructor doing this right away instead.


DocumentPane

public DocumentPane(java.net.URL docToLoad,
                    int newDocNo)
construct a new DocumentPane with either a new Document or an exisiting Document that is to be loaded into the DocumentPane upon construction.

Parameters:
docToLoad - the document to be loaded. If this is null, a new Document is created upon construction of the DocumentPane
newDocNo - the number a new document shall have in the title as long as it is not saved (such as in 'Untitled1'). If an existing document shall be loaded, this number is ignored
Method Detail

getEditor

public SHTMLEditorPane getEditor()
get the JEditorPane of this DocumentPane

Returns:
the JEditorPane of this DocumentPane

createNewDocument

public void createNewDocument()
create a new HTMLDocument and attach it to the editor


setDocument

public void setDocument(javax.swing.text.Document docToSet)

deleteTempDir

public void deleteTempDir()
remove the temporary storage created for this DocumentPane


loadDocument

public void loadDocument(java.net.URL url)
load a document found at a certain URL.

Parameters:
url - the URL to look for the document

saveDocument

public void saveDocument()
                  throws DocNameMissingException
saves the document to the file specified in the source of the DocumentPane and creates the associated style sheet. The actual save process only is done, when there is a name to save to. The class(es) calling this method have to make sure that a name for new documents is requested from the user, for instance. The desired name and location for the save need then to be set using method setSource prior to a call to this method

Throws:
DocNameMissingException - to ensure the caller gets notified that a save did not take place because of a missing name and location

getImageDir

public java.io.File getImageDir()
determine the directory this DocumentPane references image files from

Returns:
the directory image files referenced by this DocumentPane are found

saveInProgress

public boolean saveInProgress()
indicates whether or not a save process is in progress

Returns:
true, if a save process is going on, else false

saveStyleSheet

public void saveStyleSheet()
                    throws java.io.IOException
save the style sheet of this document to a CSS file.

With stage 8 this saves a style sheet by merging with an existing one with the same name/location. Styles in this style sheet overwrite styles in the existing style sheet.

Throws:
java.io.IOException

getDocumentName

public java.lang.String getDocumentName()
get the name of the document of this pane.

Returns:
the name of the document

needsSaving

public boolean needsSaving()
indicates whether or not the document needs to be saved.

Returns:
true, if changes need to be saved

setSource

public void setSource(java.net.URL source)
set the source this document is to be loaded from

This is only to be used when it is made sure, that the document is saved at the location specified by 'source'.

Parameters:
the - URL of the source this document is to be loaded from

getOldSource

public java.net.URL getOldSource()
get the source, this document was having before its current sourceUrl was set.

Returns:
the source URL before a name change

getSource

public java.net.URL getSource()
get the source this document can be loaded from

Returns:
the URL this document can be loaded from

isNewDoc

public boolean isNewDoc()
indicates whether or not this document was newly created and not saved so far.

Returns:
true, if this is a new document that has not been saved so far

getDocument

public javax.swing.text.Document getDocument()
get the document of this DocumentPane

Returns:
the Document of this DocumentPane

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
listens to inserts into the document to track whether or not the document needs to be saved.

Specified by:
insertUpdate in interface javax.swing.event.DocumentListener

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
listens to removes from the document to track whether or not the document needs to be saved.

Specified by:
removeUpdate in interface javax.swing.event.DocumentListener

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
listens to changes on the document to track whether or not the document needs to be saved.

Specified by:
changedUpdate in interface javax.swing.event.DocumentListener

addDocumentPaneListener

public void addDocumentPaneListener(DocumentPane.DocumentPaneListener listener)
add a DocumentPaneListener to this Document

Parameters:
listener - the listener object to add

removeDocumentPaneListener

public void removeDocumentPaneListener(DocumentPane.DocumentPaneListener listener)
remove a DocumentPaneListener from this Document

Parameters:
listener - the listener object to remove

fireNameChanged

public void fireNameChanged()
fire a DocumentPaneEvent to all registered DocumentPaneListeners


fireActivated

public void fireActivated()
fire a DocumentPaneEvent to all registered DocumentPaneListeners


removeAllListeners

public void removeAllListeners()
remove all listeners