org.bs.mdi.swing
Class SwingView

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byorg.bs.mdi.swing.SwingView
All Implemented Interfaces:
ActionObservable, ActionObserver, ActionProcessor, ImageObserver, MenuContainer, Serializable, View

public abstract class SwingView
extends JComponent
implements View

An implementation of a View using Swing technology.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
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
SwingView()
          Creates an new view with no parent view and no associated data object.
SwingView(Data data, View parent)
          Creates a new view.
SwingView(Data data, View parent, Component wrappedComponent)
          Creates a new view, optionally wrapping a standard component.
 
Method Summary
 void actionPerformed(ActionObservable observable, Action action)
          Called from the ActionObservable when an action has been performed or redone.
 void actionUndone(ActionObservable observable, Action action)
          Called from the ActionObservable when an action has been undone.
 void addChild(View child)
          Adds a child element.
 void addObserver(ActionObserver observer)
          Registers this observer so that it will receive notification messages.
 void applyAction(Action action)
          Applies an action or perform a redo.
abstract  Action copy()
          Perform a "copy to clipboard" operation.
 int countChildren()
          Counts all child elements.
 int countObservers()
          Counts all registered observers.
abstract  Action cut()
          Perform a "cut to clipboard" operation.
abstract  void delete()
          Perform a delete operation.
 View getChild(int index)
          Gets the child element at the specified index.
 Data getData()
          Returns the Data object associated with this view.
 Document getDocument()
          Returns the document which this view is assigned to.
 View getParentView()
          Gets the parent View object, or null if there is no parent object (i.e. this is probably a RootView object).
 Component getWrappedComponent()
          Gets the component which is wrapped by this view.
 boolean isCopyPossible()
          Returns true if content can be copied to the clipboard.
 boolean isCutPossible()
          Returns true if content can be cutted to the clipboard.
 boolean isDeletePossible()
          Returns true if content can be deleted.
 boolean isObserver(ActionObserver observer)
          Determines if the given observer is currently observing this object.
 boolean isPastePossible()
          Returns true if content can be pasted from the clipboard.
 void notifyObservers(Action action, boolean undo)
          Notifies the observers about an action which has been recently performed.
abstract  void paste(Action action)
          Perform a "paste from clipboard" operation.
 void removeChild(View child)
          Removes a child element.
 void removeObserver(ActionObserver observer)
          Un-registers this observer so that it will not receive notifications any longer.
 void setCopyPossible(boolean possible)
          Enables or disables copying to the clipboard.
 void setCutPossible(boolean possible)
          Enables or disables cutting to the clipboard.
 void setData(Data data)
          Associates this View with the given Data object.
 void setDeletePossible(boolean possible)
          Enables or disables deleting operations.
 void setPastePossible(boolean possible)
          Enables or disables pasting from the clipboard.
 void setWrappedComponent(Component wrappedComponent)
          Sets the component for which this view should act as a wrapper.
abstract  void syncWithData()
          Called from the Data object to indicate that the documents data has changed.
 void undoAction(Action action)
          Perform an undo.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SwingView

public SwingView()
Creates an new view with no parent view and no associated data object.


SwingView

public SwingView(Data data,
                 View parent)
Creates a new view. Automatically calls parent.addChild(this) if parent is not null.

Parameters:
data - the data which this view should be associated with
parent - the parent view

SwingView

public SwingView(Data data,
                 View parent,
                 Component wrappedComponent)
Creates a new view, optionally wrapping a standard component. If wrappedComponent is not null, this view will act as a wrapper for this component (the wrappedComponent will be added to this view and can be accessed using getWrappedComponent(). If parent is not null, this constructor automaically calls parent.addChild(this).

Parameters:
data - the data which this view should be associated with
parent - the parent view
wrappedComponent - the component to be wrapped by this view
Method Detail

getWrappedComponent

public Component getWrappedComponent()
Gets the component which is wrapped by this view.

Returns:
the wrapped component

setWrappedComponent

public void setWrappedComponent(Component wrappedComponent)
Sets the component for which this view should act as a wrapper.

Parameters:
wrappedComponent - the component to be wrapped

getDocument

public Document getDocument()
Description copied from interface: View
Returns the document which this view is assigned to. This is just a convenience function which is roughly equivalent to getData().getDocument.

Specified by:
getDocument in interface View
Returns:
the document

setData

public void setData(Data data)
Description copied from interface: View
Associates this View with the given Data object. This method also makes this view observe the data as well as the data observe the view.

Specified by:
setData in interface View
Parameters:
data - the Data object

getData

public Data getData()
Description copied from interface: View
Returns the Data object associated with this view.

Specified by:
getData in interface View
Returns:
the corresponding Data object

getParentView

public View getParentView()
Description copied from interface: View
Gets the parent View object, or null if there is no parent object (i.e. this is probably a RootView object).

Specified by:
getParentView in interface View
Returns:
the parent object

addChild

public void addChild(View child)
Description copied from interface: View
Adds a child element.

Specified by:
addChild in interface View
Parameters:
child - the child element

removeChild

public void removeChild(View child)
Description copied from interface: View
Removes a child element.

Specified by:
removeChild in interface View
Parameters:
child - the child element

countChildren

public int countChildren()
Description copied from interface: View
Counts all child elements.

Specified by:
countChildren in interface View
Returns:
the number of child elements

getChild

public View getChild(int index)
Description copied from interface: View
Gets the child element at the specified index.

Specified by:
getChild in interface View
Parameters:
index - the index
Returns:
the child element at the specified position

copy

public abstract Action copy()
Description copied from interface: View
Perform a "copy to clipboard" operation. Converts the currently selected information to an action object and returns it.

Specified by:
copy in interface View
Returns:
the action object containing the copied information

cut

public abstract Action cut()
Description copied from interface: View
Perform a "cut to clipboard" operation. Converts the currently selected information to an action object and returns it.

Specified by:
cut in interface View
Returns:
the action object containing the cutted information

paste

public abstract void paste(Action action)
Description copied from interface: View
Perform a "paste from clipboard" operation. The information to be pasted is delivered via the "action" parameter.

Specified by:
paste in interface View
Parameters:
action - the action object containing the information to be pasted

delete

public abstract void delete()
Description copied from interface: View
Perform a delete operation.

Specified by:
delete in interface View

isCopyPossible

public final boolean isCopyPossible()
Description copied from interface: View
Returns true if content can be copied to the clipboard.

Specified by:
isCopyPossible in interface View
Returns:
true if a copy operation is possible

isCutPossible

public final boolean isCutPossible()
Description copied from interface: View
Returns true if content can be cutted to the clipboard.

Specified by:
isCutPossible in interface View
Returns:
true if a cut operation is possible

isPastePossible

public final boolean isPastePossible()
Description copied from interface: View
Returns true if content can be pasted from the clipboard.

Specified by:
isPastePossible in interface View
Returns:
true if a paste operation is possible

isDeletePossible

public final boolean isDeletePossible()
Description copied from interface: View
Returns true if content can be deleted.

Specified by:
isDeletePossible in interface View
Returns:
true if a delete operation is possible

setCopyPossible

public void setCopyPossible(boolean possible)
Description copied from interface: View
Enables or disables copying to the clipboard.

Specified by:
setCopyPossible in interface View
Parameters:
possible - true if copying is possible, false otherwise

setCutPossible

public void setCutPossible(boolean possible)
Description copied from interface: View
Enables or disables cutting to the clipboard.

Specified by:
setCutPossible in interface View
Parameters:
possible - true if cutting is possible, false otherwise

setPastePossible

public void setPastePossible(boolean possible)
Description copied from interface: View
Enables or disables pasting from the clipboard.

Specified by:
setPastePossible in interface View
Parameters:
possible - true if pasting is possible, false otherwise

setDeletePossible

public void setDeletePossible(boolean possible)
Description copied from interface: View
Enables or disables deleting operations.

Specified by:
setDeletePossible in interface View
Parameters:
possible - true if deleting is possible, false otherwise

syncWithData

public abstract void syncWithData()
Description copied from interface: View
Called from the Data object to indicate that the documents data has changed.

The view update or redraw its contents the reflect that changes.

Specified by:
syncWithData in interface View

addObserver

public void addObserver(ActionObserver observer)
Description copied from interface: ActionObservable
Registers this observer so that it will receive notification messages.

Specified by:
addObserver in interface ActionObservable
Parameters:
observer - the observer to be registered

removeObserver

public void removeObserver(ActionObserver observer)
Description copied from interface: ActionObservable
Un-registers this observer so that it will not receive notifications any longer.

Specified by:
removeObserver in interface ActionObservable
Parameters:
observer - the observer to be un-registered

countObservers

public int countObservers()
Description copied from interface: ActionObservable
Counts all registered observers.

Specified by:
countObservers in interface ActionObservable
Returns:
the number of registered observers.

isObserver

public boolean isObserver(ActionObserver observer)
Description copied from interface: ActionObservable
Determines if the given observer is currently observing this object.

Specified by:
isObserver in interface ActionObservable
Parameters:
observer - the observer
Returns:
true if the observer is currently observing this object, false otherwise

notifyObservers

public void notifyObservers(Action action,
                            boolean undo)
Description copied from interface: ActionObservable
Notifies the observers about an action which has been recently performed. Note that the implementation may use threading to deliver the notification messages.

Specified by:
notifyObservers in interface ActionObservable
Parameters:
action - the action which has been performed
undo - true if the action has been undone, false otherwise

actionPerformed

public void actionPerformed(ActionObservable observable,
                            Action action)
Description copied from interface: ActionObserver
Called from the ActionObservable when an action has been performed or redone.

Specified by:
actionPerformed in interface ActionObserver
Parameters:
observable - the observable which this notification originated from
action - the action which has been performed

actionUndone

public void actionUndone(ActionObservable observable,
                         Action action)
Description copied from interface: ActionObserver
Called from the ActionObservable when an action has been undone.

Specified by:
actionUndone in interface ActionObserver
Parameters:
observable - the observable which this notification originated from
action - the action which has been undone

applyAction

public void applyAction(Action action)
Description copied from interface: ActionProcessor
Applies an action or perform a redo.

Specified by:
applyAction in interface ActionProcessor
Parameters:
action - the action to be applied or redone

undoAction

public void undoAction(Action action)
Description copied from interface: ActionProcessor
Perform an undo.

Specified by:
undoAction in interface ActionProcessor
Parameters:
action - the action to be undone