jview
Class JApplicationSwitcher

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 jview.JApplicationSwitcher
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ExitCleaning, Initializable, PriorityListener, ResourceAware, ResourceComposed
Direct Known Subclasses:
JRemoteSwitcher

public class JApplicationSwitcher
extends JPanel
implements ResourceComposed, Initializable, PriorityListener, ExitCleaning

An application switcher provides a set of applications, i.e. objects than can be constructed from properties and supply a component via the ComponentPresenting interface. It uses a card layout to display only a single component at a time and is itself a JPanel. Due to unfortunate coding, the linkage of name to components in the CardLayout is non-transparent (can only switch to a component, but not query for), we buffer that and provide a method getComponent(java.lang.String) .info.getAsLong(KEY_INACTIVETIME) Switches can occur, if show(java.lang.String) is called, cycling can be done with next() and previous(). Its main application is in combination with RMI enabled code.

It either honors different priorities of the components to display in idle mode, or switch randomly between components. While for the former one the switcher is a priority listener, the second also works with equal-rank priorities.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  boolean active
          Active or inactive mode.
private  Map<String,Component> components
          No access to the card-layout cards, thus we have to keep track.
private static boolean DEFALLOWPRIORITY
          Default we allow priority switches.
private static int DEFHIDDENMODIFIERS
          No modifiers for default.
private static int DEFHIDDENSIZE
          Default size.
private static int DEFHIDDENSWITCH
          Default no hidden buttons for clicking thru card layout.
private static long DEFINACTIVETIME
          Default inactive time in ms.
private static long DEFSWITCHTIME
          Default inactive time in ms.
private  JPanel hidden
          This panel is a hiding panel and should be added to the main frame.
private  TimerTask inactive
          The timer task that renders us inactive.
private  ResourceSupplying info
          My properties, composed from a PropertyBundles.
static String KEY_ALLOWPRIORITY
          If true, we allow priority-based switch if we are in inactive phase.
static String KEY_APPLICATIONS
          The key that links names to properties of Displayables.
static String KEY_HIDDENMODIFIERS
          If none-zero, it represents a modifier mask to show the hidden panel.
static String KEY_HIDDENSIZE
          If this points to a valid GridBagConstraint, we add hiding buttons.
static String KEY_HIDDENSWITCH
          If this points to a valid GridBagConstraint, we add hiding buttons.
static String KEY_INACTIVETIME
          After last components switch, it takes this time until we're inactive.
static String KEY_SWITCHTIME
          On random switches the time between those.
private  Map<String,Icon> names
          A list of all names that were sucessfully added to the layout.
private  Map<String,PriorityCaster> nettle
          The priority caster that wants to be displayed.
private  Map<String,Integer> nettleprior
          Their latest priorities.
private  String nextrank
          The name of the second-highest component.
private  int priority
          Priority of the currently shown object, or zero if not applicable.
private  int second
          The second-rank priority.
private  String showing
          The name of the component shown.
 
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
JApplicationSwitcher(Map<String,String> prop)
          Constructs a new webcam grid.
 
Method Summary
private  void addIt(Component c, String key, Icon i)
          Adds this component, and stores a reference.
protected  void createRepresentation()
          Delivers the central component.
 void exit()
          On exit, we deregister and close our timer.
 Map<String,Icon> getAllComponents()
          Returns a list of all components names in this card.
 Component getComponent(String id)
          Returns the component of the given name in this panel.
 ResourceSupplying getComposedProperties()
          Returns the ResourceSupplyings this frame refers to.
protected  Component getHiddenPanel()
          Returns the hidden panel with the switch buttons, if available.
private  KeyValue<String,Integer> getHighest(String exclude)
          We look in our prioity caster to get the second highest priority.
private  TimerTask getPriorityTask()
          Returns a task that shows the highest priority if called.
private  TimerTask getRandomTask()
          Returns a task that randomly switches to an application if called.
 void init()
          On init, we create our representation.
 void next()
          Switches to the next card.
 void previous()
          Switches to the previous card.
 void priorityChanged(String castername, int newprior)
          Called by prioiry casters if their priority has changed.
 void setComposedProperties(ResourceSupplying prop)
          Sets a ResourceSupplying object as a composite of the canvas.
 boolean show(String id)
          Switches to the card of the given name.
 
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, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_APPLICATIONS

public static final String KEY_APPLICATIONS
The key that links names to properties of Displayables.

See Also:
Constant Field Values

KEY_ALLOWPRIORITY

public static final String KEY_ALLOWPRIORITY
If true, we allow priority-based switch if we are in inactive phase.

See Also:
Constant Field Values

KEY_INACTIVETIME

public static final String KEY_INACTIVETIME
After last components switch, it takes this time until we're inactive.

See Also:
Constant Field Values

KEY_SWITCHTIME

public static final String KEY_SWITCHTIME
On random switches the time between those.

See Also:
Constant Field Values

KEY_HIDDENSWITCH

public static final String KEY_HIDDENSWITCH
If this points to a valid GridBagConstraint, we add hiding buttons.

See Also:
Constant Field Values

KEY_HIDDENSIZE

public static final String KEY_HIDDENSIZE
If this points to a valid GridBagConstraint, we add hiding buttons.

See Also:
Constant Field Values

KEY_HIDDENMODIFIERS

public static final String KEY_HIDDENMODIFIERS
If none-zero, it represents a modifier mask to show the hidden panel.

See Also:
Constant Field Values

DEFALLOWPRIORITY

private static final boolean DEFALLOWPRIORITY
Default we allow priority switches.

See Also:
Constant Field Values

DEFINACTIVETIME

private static final long DEFINACTIVETIME
Default inactive time in ms.

See Also:
Constant Field Values

DEFSWITCHTIME

private static final long DEFSWITCHTIME
Default inactive time in ms.

See Also:
Constant Field Values

DEFHIDDENSWITCH

private static final int DEFHIDDENSWITCH
Default no hidden buttons for clicking thru card layout.

See Also:
Constant Field Values

DEFHIDDENSIZE

private static final int DEFHIDDENSIZE
Default size.

See Also:
Constant Field Values

DEFHIDDENMODIFIERS

private static final int DEFHIDDENMODIFIERS
No modifiers for default.

See Also:
Constant Field Values

info

private ResourceSupplying info
My properties, composed from a PropertyBundles.


names

private Map<String,Icon> names
A list of all names that were sucessfully added to the layout.


components

private Map<String,Component> components
No access to the card-layout cards, thus we have to keep track.


nettle

private Map<String,PriorityCaster> nettle
The priority caster that wants to be displayed.


nettleprior

private Map<String,Integer> nettleprior
Their latest priorities.


active

private boolean active
Active or inactive mode.


priority

private int priority
Priority of the currently shown object, or zero if not applicable.


showing

private String showing
The name of the component shown.


second

private int second
The second-rank priority.


nextrank

private String nextrank
The name of the second-highest component.


inactive

private TimerTask inactive
The timer task that renders us inactive.


hidden

private JPanel hidden
This panel is a hiding panel and should be added to the main frame.

Constructor Detail

JApplicationSwitcher

public JApplicationSwitcher(Map<String,String> prop)
Constructs a new webcam grid.

Method Detail

init

public void init()
On init, we create our representation.

Specified by:
init in interface Initializable

setComposedProperties

public void setComposedProperties(ResourceSupplying prop)
Sets a ResourceSupplying object as a composite of the canvas. Defaults the necessary parameter.

Specified by:
setComposedProperties in interface ResourceAware

getComposedProperties

public ResourceSupplying getComposedProperties()
Returns the ResourceSupplyings this frame refers to.

Specified by:
getComposedProperties in interface ResourceComposed

createRepresentation

protected void createRepresentation()
Delivers the central component.


priorityChanged

public void priorityChanged(String castername,
                            int newprior)
Called by prioiry casters if their priority has changed. If we are active, we record this caster plus its name for a possible switch if we get inactive. If we are inactive, we switch to this component, if the issued priority is higher than the current.

Specified by:
priorityChanged in interface PriorityListener

getHiddenPanel

protected Component getHiddenPanel()
Returns the hidden panel with the switch buttons, if available.


addIt

private void addIt(Component c,
                   String key,
                   Icon i)
Adds this component, and stores a reference.


next

public void next()
Switches to the next card.


previous

public void previous()
Switches to the previous card.


getComponent

public Component getComponent(String id)
Returns the component of the given name in this panel. Unfortunately, the CardLayout does not provide this essential method.


show

public boolean show(String id)
Switches to the card of the given name.


getAllComponents

public Map<String,Icon> getAllComponents()
Returns a list of all components names in this card.


exit

public void exit()
On exit, we deregister and close our timer.

Specified by:
exit in interface ExitCleaning

getHighest

private KeyValue<String,Integer> getHighest(String exclude)
We look in our prioity caster to get the second highest priority.


getPriorityTask

private TimerTask getPriorityTask()
Returns a task that shows the highest priority if called.


getRandomTask

private TimerTask getRandomTask()
Returns a task that randomly switches to an application if called.