DESY ACOP Beans Home

com.cosylab.gui
Class IconDisplayer

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.cosylab.gui.displayers.AbstractDisplayerPanel
                      extended by com.cosylab.gui.IconDisplayer
All Implemented Interfaces:
PopupManageable, CommonDisplayer, ConvertibleDisplayer, DataConsumer, DataStateProvider, Displayer, IconDisplayer, LongConsumer, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
AcopIcon

public class IconDisplayer
extends AbstractDisplayerPanel
implements IconDisplayer

IconDisplayer is a displayer that displays icons associated with different values.

Author:
Jaka Bobnar, Cosylab
See Also:
Serialized Form

Nested Class Summary
 
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_ICON_NAME_PROPERTY
           
static java.lang.String DEFAULT_ICON_PROPERTY
           
static java.lang.String ICONS_PROPERTY
           
 
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 com.cosylab.gui.displayers.Displayer
C_EDITABLE, DATA_SOURCE
 
Fields inherited from interface com.cosylab.gui.displayers.CommonDisplayer
C_BIT_DESCRIPTIONS, C_BIT_MASK, C_COLOR, C_CONDITION_WHEN_CLEARED, C_CONDITION_WHEN_SET, C_DESCRIPTION, C_DISPLAY_NAME, C_FORMAT, C_GRAPH_MAX, C_GRAPH_MIN, C_MAXIMUM, C_MIN_STEP, C_MINIMUM, C_POSITION, C_PROPERTY_TYPE, C_SEQUENCE_LENGTH, C_UNITS
 
Fields inherited from interface com.cosylab.gui.displayers.DataStateProvider
DATA_STATE
 
Fields inherited from interface com.cosylab.gui.displayers.ConvertibleDisplayer
CONVERTER_PROPERTY
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
IconDisplayer()
          Creates new IconDisplayer.
IconDisplayer(java.io.File file)
          Creates a new IconDisplayer with the default icon loaded from a given file.
IconDisplayer(javax.swing.Icon defaultIcon)
          Creates new IconDisplayer and defines the default icon.
IconDisplayer(java.lang.String defaultIcon)
          Creates new IconDisplayer and new default icon.
 
Method Summary
 void addIcon(long value, javax.swing.Icon icon)
          Adds an icon.
 void addIcon(ValueIconPair pair)
          Associates icon with value.
 void addIcons(ValueIconPair[] icons)
          Associates icons with values.
 void cleanup()
          Performs general cleanup of displayer resources.
<D extends DataConsumer>
D
getDataConsumer(java.lang.Class<D> type)
           Returns data consumer for requested data consumer type.
 javax.swing.Icon getDefaultIcon()
          Returns default icon.
 java.lang.String getDefaultIconName()
          Returns the path to the default icon.
 ValueIconPair[] getIcons()
          Returns an array of all icons that were associated with values.
 InfoDialog getInfoDialog()
          Returns the InfoDialog for this displayer.
 PopupManager getPopupManager()
          Returns popup manager for adding popup actions.
 java.lang.Class[] getSupportedConsumerTypes()
          Returns array of supported data consumer types, which can be used as parameter and returnned with getDataCosnumer(Class) method.
 long getValue()
          Gets the value displayed by the displayer.
 boolean isEditable()
           Returns true if this displayer can interact with user and fire value updates requested by user.
 boolean isKeepRatio()
          Returns true if icons aspect ratio is kept when the icon is scaled to fit the component size or false if displayer's aspect ratio is used.
 boolean isScaleIcons()
          Returns true if icons are scaled to fit the size of the component.
static void main(java.lang.String[] args)
           
 void removeIcon(ValueIconPair icon)
          Removes icons.
 void removeIcons(ValueIconPair[] icons)
          Removes icons.
 void setBackground(java.awt.Color bg)
           
 void setCharacteristics(java.util.Map characteristics)
          Sets new dynamic value characteristics to this data consumer.
 void setDefaultIcon(java.io.File file)
          Creates and sets default icon from the given file.
 void setDefaultIcon(javax.swing.Icon newIcon)
          Sets default icon.
 void setDefaultIconName(java.lang.String filename)
          Creates and sets default icon from file name.
 void setForeground(java.awt.Color fg)
           
 void setIcons(ValueIconPair[] icons)
          Associates icons with values.
 void setKeepRatio(boolean keepRatio)
          Sets whether the icons should keep the aspect ratio if it is scale to fit the component;
 void setScaleIcons(boolean scale)
          Sets whether the icons should be scale to fit the size of the component.
 void setValue(long value)
          Sets the value displayed by the displayer.
protected  void updateIcon()
           
 void updateValue(long timestamp, long value)
          Notifys this consumer about new dynamic value update.
 
Methods inherited from class com.cosylab.gui.displayers.AbstractDisplayerPanel
destroy, getConverter, getCustomizer, getDataSource, getDataState, getDefaultDataConsumer, getSupportedCharacteristics, getTitle, getTitleLabel, getTitleMaximumFontSize, getTitleMinimumFontSize, isPopupEnabled, isSuspended, isTitleVisible, resume, setConverter, setDataSource, setPopupEnabled, setTitle, setTitleMaximumFontSize, setTitleMinimumFontSize, setTitleVisible, suspend, updateDataState
 
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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, 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
 
Methods inherited from interface com.cosylab.gui.displayers.Displayer
getDataSource, getTitle, setDataSource, setTitle
 
Methods inherited from interface com.cosylab.gui.displayers.CommonDisplayer
isSuspended, resume, suspend
 
Methods inherited from interface com.cosylab.gui.displayers.DataStateProvider
addPropertyChangeListener, addPropertyChangeListener, getDataState, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface com.cosylab.gui.displayers.DataConsumer
getDefaultDataConsumer, getName, getSupportedCharacteristics, updateDataState
 

Field Detail

ICONS_PROPERTY

public static final java.lang.String ICONS_PROPERTY
See Also:
Constant Field Values

DEFAULT_ICON_PROPERTY

public static final java.lang.String DEFAULT_ICON_PROPERTY
See Also:
Constant Field Values

DEFAULT_ICON_NAME_PROPERTY

public static final java.lang.String DEFAULT_ICON_NAME_PROPERTY
See Also:
Constant Field Values
Constructor Detail

IconDisplayer

public IconDisplayer()
Creates new IconDisplayer.


IconDisplayer

public IconDisplayer(javax.swing.Icon defaultIcon)
Creates new IconDisplayer and defines the default icon.

Parameters:
defaultIcon - Default icon to set.

IconDisplayer

public IconDisplayer(java.lang.String defaultIcon)
Creates new IconDisplayer and new default icon. This constructor will create a new icon from the given path. The path has to be in the classpath of the project for the icon to be generated. If the path points to an explicit file in the local system the icon displayer will generate the icon, but will fail if the file does not exist.

Parameters:
defaultIcon - the name of default icon in classpath to use

IconDisplayer

public IconDisplayer(java.io.File file)
Creates a new IconDisplayer with the default icon loaded from a given file. This file does not need to be in the classpath of the project.

Parameters:
file - the icon image file
Method Detail

getIcons

public ValueIconPair[] getIcons()
Description copied from interface: IconDisplayer
Returns an array of all icons that were associated with values.

Specified by:
getIcons in interface IconDisplayer
Returns:

setIcons

public void setIcons(ValueIconPair[] icons)
Description copied from interface: IconDisplayer
Associates icons with values. This method overrides all previously loaded icons.

Specified by:
setIcons in interface IconDisplayer

addIcons

public void addIcons(ValueIconPair[] icons)
Description copied from interface: IconDisplayer
Associates icons with values. This methods adds icons to previously loded inventory and overrides only those values that were loaded before and now is a different values associated with them.

Specified by:
addIcons in interface IconDisplayer

removeIcons

public void removeIcons(ValueIconPair[] icons)
Description copied from interface: IconDisplayer
Removes icons.

Specified by:
removeIcons in interface IconDisplayer

removeIcon

public void removeIcon(ValueIconPair icon)
Description copied from interface: IconDisplayer
Removes icons.

Specified by:
removeIcon in interface IconDisplayer

addIcon

public void addIcon(long value,
                    javax.swing.Icon icon)
Adds an icon. This method is the same as addIcon(ValueIconPair) using the new ValueIconPair(value, icon).

Parameters:
value -
icon -

addIcon

public void addIcon(ValueIconPair pair)
Description copied from interface: IconDisplayer
Associates icon with value. This methods adds icon to previously loded inventory.

Specified by:
addIcon in interface IconDisplayer

setBackground

public void setBackground(java.awt.Color bg)
Overrides:
setBackground in class AbstractDisplayerPanel

setForeground

public void setForeground(java.awt.Color fg)
Overrides:
setForeground in class AbstractDisplayerPanel

setValue

public void setValue(long value)
Description copied from interface: IconDisplayer
Sets the value displayed by the displayer. This method may be invoked only by the adapter delivering a new value from the modeling layer.

Specified by:
setValue in interface IconDisplayer
Parameters:
value - new value to be displayed

updateIcon

protected void updateIcon()

getValue

public long getValue()
Description copied from interface: IconDisplayer
Gets the value displayed by the displayer. This method can be invoked by any object and will probably most often be invoked by the GUI rendition code.

Specified by:
getValue in interface IconDisplayer
Returns:
double currently displayed value

setDefaultIconName

public void setDefaultIconName(java.lang.String filename)
Creates and sets default icon from file name. Default icon will be used when no condition is met. The given filename should point to a file inside the classpath of the project.

Parameters:
filename -

setDefaultIcon

public void setDefaultIcon(java.io.File file)
Creates and sets default icon from the given file. The file can point to any location on the computer as long as it is accessible by the current user's rights.

Parameters:
file - the image file

setDefaultIcon

public void setDefaultIcon(javax.swing.Icon newIcon)
Sets default icon. Default icon will be used when no condition is met.

Specified by:
setDefaultIcon in interface IconDisplayer
Parameters:
newIcon - New icon to use. May be null.

getDefaultIconName

public java.lang.String getDefaultIconName()
Returns the path to the default icon.

Returns:

getDefaultIcon

public javax.swing.Icon getDefaultIcon()
Returns default icon. Default icon is used when no condition is met.

Specified by:
getDefaultIcon in interface IconDisplayer
Returns:
Instance of default icon or null.

isEditable

public boolean isEditable()
Description copied from interface: Displayer

Returns true if this displayer can interact with user and fire value updates requested by user. If displayer is editable, mus implement DataSource interface.

Displayers, which does not support value editing will return allways false. Displayers which support value editing MUST implement also setter setEditable(booelan).

Specified by:
isEditable in interface Displayer
Returns:
true if this displayer can receive value change requestes by user

updateValue

public void updateValue(long timestamp,
                        long value)
                 throws CommonException
Description copied from interface: LongConsumer
Notifys this consumer about new dynamic value update.

Specified by:
updateValue in interface LongConsumer
Parameters:
timestamp - the time of dynamic value event
value - new value
Throws:
CommonException

setCharacteristics

public void setCharacteristics(java.util.Map characteristics)
Description copied from interface: DataConsumer
Sets new dynamic value characteristics to this data consumer. This is usually called only at initializaation, before first data state or value is updated. Usually carries characteristics such as value minimum or maximum. Name and meaning of atributes is defined with contract betwean data consumer and source implementation.

Specified by:
setCharacteristics in interface DataConsumer
Parameters:
characteristics - the Map with attri

getSupportedConsumerTypes

public java.lang.Class[] getSupportedConsumerTypes()
Description copied from interface: DataConsumer
Returns array of supported data consumer types, which can be used as parameter and returnned with getDataCosnumer(Class) method.

Specified by:
getSupportedConsumerTypes in interface DataConsumer
Returns:
array of supported data consumer types

getDataConsumer

public <D extends DataConsumer> D getDataConsumer(java.lang.Class<D> type)
Description copied from interface: DataConsumer

Returns data consumer for requested data consumer type. If this data consumer does not support required data consumer, null is returned.

If this data cosnumer does not support specific data consumer type, then it means, that it is not desirable to cast data of that type to any by this consumer supported data consumer types.

Specified by:
getDataConsumer in interface DataConsumer
Parameters:
type - Class of specific data consumer (e.g. DoubleConsumer)
Returns:
implementation of required data consumer or null if not supported

cleanup

public void cleanup()
Description copied from interface: CommonDisplayer
Performs general cleanup of displayer resources. All by displayer issued object are not valid any more after cleanup. Displayer positions itself in initial state and DataState is changed to NOT_INITIALIZED state.

Specified by:
cleanup in interface CommonDisplayer
Overrides:
cleanup in class AbstractDisplayerPanel

getInfoDialog

public InfoDialog getInfoDialog()
Returns the InfoDialog for this displayer.

Returns:

getPopupManager

public PopupManager getPopupManager()
Description copied from class: AbstractDisplayerPanel
Returns popup manager for adding popup actions.

Specified by:
getPopupManager in interface PopupManageable
Overrides:
getPopupManager in class AbstractDisplayerPanel
Returns:
returns popup manager, which manages popup menu
See Also:
PopupManageable.getPopupManager()

isKeepRatio

public boolean isKeepRatio()
Returns true if icons aspect ratio is kept when the icon is scaled to fit the component size or false if displayer's aspect ratio is used.

Returns:
true if icons are scaled

setKeepRatio

public void setKeepRatio(boolean keepRatio)
Sets whether the icons should keep the aspect ratio if it is scale to fit the component;

Parameters:
keepRatio - true if aspect ratio of the icons is kept

setScaleIcons

public void setScaleIcons(boolean scale)
Sets whether the icons should be scale to fit the size of the component.

Parameters:
scale - true if icons are scaled to fit

isScaleIcons

public boolean isScaleIcons()
Returns true if icons are scaled to fit the size of the component.

Returns:

main

public static void main(java.lang.String[] args)


Copyright © 2010. All Rights Reserved.