com.jstatcom.model
Class ModelPanel

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.jstatcom.model.ModelPanel
All Implemented Interfaces:
Card, SymbolScope, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
TSCalculator, TSSel

public class ModelPanel
extends javax.swing.JPanel
implements SymbolScope, Card

Panel to be used by components that need access to the symbol table hierarchy. The global and local symbol tables can be accessed via global and local.

The global symbol table is typically held by a ModelFrame and stores data that must be shared by all panels belonging to a model frame.

The global symbol table is found by traversing the component hierarchy on addNotify. The next SymbolScope instance is queried for global. If no parent component is a SymbolScope, then local is used for global.

The local symbol table is used to store data that is only visible to this component, but that should be displayed in the SymbolTree to make it transparent for viewing, saving and debugging.

If this component is used in a CardDisplayPanel, subclasses can overwrite shown to define the behaviour when this panel is displayed or hidden. This is often a good time to collect user specification and prepare data that is required by another panel.

All ModelPanel instances are registered with JHelpContextMgr for context sensitive help. The respective help IDs can be set in an XML file.

Author:
Markus Kraetzig
See Also:
CardDisplayPanel, ModelFrame, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
ModelPanel()
          Creates a ModelPanel.
ModelPanel(java.awt.LayoutManager layout)
          Creates a ModelPanel with a layout manager.
 
Method Summary
 void addNotify()
          Calls supermethod and finds parent instance of SymbolScope.
static SymbolScope findParentScope(java.awt.Component comp)
          Finds the next parent that is a SymbolScope.
 SymbolTable global()
          Gets the global symbol table from the closest parent component that implements SymbolScope.
 SymbolTable local()
          Gets the local symbol table that is only visible to this panel.
 void shown(boolean isShown)
          Empty default imlementation for Card interface.
 SymbolTable upper()
          Gets the local symbol table from the closest parent component that implements SymbolScope.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModelPanel

public ModelPanel()
Creates a ModelPanel.


ModelPanel

public ModelPanel(java.awt.LayoutManager layout)
Creates a ModelPanel with a layout manager.

Parameters:
layout -
Method Detail

addNotify

public void addNotify()
Calls supermethod and finds parent instance of SymbolScope. If no parent scope can be found, global and local will return the same SymbolTable, meaning that this component will hold the global table.

Overrides:
addNotify in class javax.swing.JComponent

upper

public SymbolTable upper()
Gets the local symbol table from the closest parent component that implements SymbolScope. If there is no parent implementing SymbolScope, the global, upper and local symbol table are the same.

It might happen that this method is called before this component is added to the component hierarchy. In this case an initialized symbol table is returned. If the upper table changed after adding this to the hierarchy, all symbols from that table are copied to the new upper table and the reference changes. The remaining table is cleared and will not be displayed in the SymbolTree anymore.

Specified by:
upper in interface SymbolScope
Returns:
the upper symbol table
Throws:
java.lang.RuntimeException - if global of a parent SymbolScope returns null

global

public SymbolTable global()
Gets the global symbol table from the closest parent component that implements SymbolScope. If there is no parent implementing SymbolScope, the global, upper and local symbol table are the same.

It might happen that this method is called before this component is added to the component hierarchy. In this case an initialized symbol table is returned. If the global table changed after adding this to the hierarchy, all symbols from that table are copied to the new global table and the reference changes. The remaining table is cleared and will not be displayed in the SymbolTree anymore.

Specified by:
global in interface SymbolScope
Returns:
the global symbol table
Throws:
java.lang.RuntimeException - if global of a parent SymbolScope returns null

local

public SymbolTable local()
Gets the local symbol table that is only visible to this panel. The name of this symbol table is equal to getName. If the name is empty, the classname is used instead. The parent is the upper symbol table.

Specified by:
local in interface SymbolScope
Returns:
the local symbol table

shown

public void shown(boolean isShown)
Empty default imlementation for Card interface. This method is only invoked if this component is shown or hidden by a CardDisplayPanel.

Specified by:
shown in interface Card
Parameters:
isShown - true if shown in CardDisplayPanel, false if hidden

findParentScope

public static SymbolScope findParentScope(java.awt.Component comp)
Finds the next parent that is a SymbolScope. The result might be null, if this method is called on components that are not added to a component hierarchy yet. In that case the method must be run again on addNotify.

The result can be queried for local or global to access the symbol table.

If the calling component does not find a SymbolScope instance in the hierarchy even after addNotify was called, is has to deal with the situation by either firing an exception or by creating a new symbol table.

Parameters:
comp - the component to start traversing the component hierarchy from
Returns:
the component that is instance of SymbolScope
Throws:
java.lang.IllegalArgumentException - if (comp == null)