JIDE 3.5.15

com.jidesoft.dashboard
Class GadgetPalette

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.jidesoft.dashboard.GadgetPalette
All Implemented Interfaces:
GadgetListener, ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible

public class GadgetPalette
extends JPanel
implements GadgetListener, PropertyChangeListener

The palette contains the gadget so that user can drag and drop the gadget to dashboard.

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
protected  ButtonGroup _buttonGroup
           
protected  Container _gadgetList
           
protected  JComponent _status
           
static String CONTEXT_BUTTON_ADD
          CONTEXT_BUTTON_ADD, CONTEXT_BUTTON_DONE, CONTEXT_BUTTON_DESCRIPTION are the name of the components in the GadgetPalette description panel.
static String CONTEXT_BUTTON_DESCRIPTION
           
static String CONTEXT_BUTTON_DONE
           
 
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
GadgetPalette(GadgetManager manager, GadgetPaletteInstaller installer)
           
 
Method Summary
protected  AbstractButton createButton(Gadget gadget)
           
protected  JComponent createDescriptionLabel()
           
protected  JPanel createDescriptionPanel(Component statusComponent)
          Creates the panel for the status label and two more buttons.
protected  Container createGadgetButtonContainer()
          Creates the container for the gadget buttons.
protected  AbstractButton createScrollButton(int type)
          Creates the scroll button for the SimpleScrollPane used by GadgetPalete when there aren't enough space to show all gadgets on the palette.
protected  void customizeButton(AbstractButton button)
           
 void eventHappened(GadgetEvent e)
          Invoked when a Gadget event happened
 GadgetManager getGadgetManager()
           
 GadgetPaletteInstaller getInstaller()
           
protected  String getResourceString(String key)
          Gets the localized string from resource bundle.
protected  void paintBackground(Graphics g)
          Paints the background of GadgetPalette.
protected  void paintComponent(Graphics g)
           
 void propertyChange(PropertyChangeEvent evt)
           
protected  void recreateGadgetButtons()
          Recreates the gadget buttons and add them to the containers for the gadget buttons.
 void setButtonLayout(LayoutManager layout)
          Set the layout manager for the container contains gadget buttons.
protected  void uncustomizeButton(AbstractButton button)
           
protected  void updateOpaque()
          Update opaque property to false for every child components in GadgetPalette.
 void updateUI()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
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, 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

CONTEXT_BUTTON_ADD

public static final String CONTEXT_BUTTON_ADD
CONTEXT_BUTTON_ADD, CONTEXT_BUTTON_DONE, CONTEXT_BUTTON_DESCRIPTION are the name of the components in the GadgetPalette description panel. With those names, you can easily find the corresponding component and change their behavior, like set disable, invisible or add new action listener, etc.

See Also:
Constant Field Values

CONTEXT_BUTTON_DONE

public static final String CONTEXT_BUTTON_DONE
See Also:
Constant Field Values

CONTEXT_BUTTON_DESCRIPTION

public static final String CONTEXT_BUTTON_DESCRIPTION
See Also:
Constant Field Values

_buttonGroup

protected ButtonGroup _buttonGroup

_status

protected JComponent _status

_gadgetList

protected Container _gadgetList
Constructor Detail

GadgetPalette

public GadgetPalette(GadgetManager manager,
                     GadgetPaletteInstaller installer)
Method Detail

updateOpaque

protected void updateOpaque()
Update opaque property to false for every child components in GadgetPalette. If you want to change this default behavior, you could override this method to do nothing.


createDescriptionLabel

protected JComponent createDescriptionLabel()

createGadgetButtonContainer

protected Container createGadgetButtonContainer()
Creates the container for the gadget buttons. By default, we will create a new instance of ScrollableButtonPanel, add it to SimpleScrollPane and return the scroll pane. In subsequent call to recreateGadgetButtons() method, we will create gadget buttons and add it to the ScrollableButtonPanel.

To make it easy for people to override, the default code is inlcuded below. The _gadgetList is a field of ScrollableButtonPanel.

 _gadgetList = new JPanel(new GridLayout(1, 0, 4, 4));
 JPanel panel = JideSwingUtilities.createCenterPanel(_gadgetList);
 panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
 SimpleScrollPane scrollPane = new SimpleScrollPane(_gadgetList) {
     protected AbstractButton createScrollButton(int type) {
         AbstractButton button = GadgetPalette.this.createScrollButton(type);
         if (button != null) {
             return button;
         }
         else {
             return super.createScrollButton(type);
         }
     }
 };
 scrollPane.setRepeatDelay(100);
 scrollPane.setBorder(BorderFactory.createEmptyBorder());
 return scrollPane;
 

Returns:
a scroll pane containing a ScrollableButtonPanel.

setButtonLayout

public void setButtonLayout(LayoutManager layout)
Set the layout manager for the container contains gadget buttons.

Parameters:
layout - the layout manager

recreateGadgetButtons

protected void recreateGadgetButtons()
Recreates the gadget buttons and add them to the containers for the gadget buttons. Since this method is also called when the gadgets are updated in the GadgetManager, so we need to clear the existing buttons from the container first before adding new buttons.

To make it easy for people to override, the default code is inlcuded below. The _gadgetList is a field of ScrollableButtonPanel.

 Component[] components = _gadgetList.getComponents();
 for (Component component : components) {
     if (component instanceof AbstractButton) {
         uncustomizeButton(((AbstractButton) component));
         _buttonGroup.remove(((AbstractButton) component));
     }
 }
 _gadgetList.removeAll();
 String[] elements = _manager.getGadgets();
 for (String key : elements) {
     Gadget element = _manager.getGadget(key);
     AbstractButton button = createButton(element);
     customizeButton(button);
     _gadgetList.addButton(button);
     _buttonGroup.add(button);
 }
 revalidate();
 repaint();
 


createDescriptionPanel

protected JPanel createDescriptionPanel(Component statusComponent)
Creates the panel for the status label and two more buttons. Subclass can override to add more components. By default, the layout of this panel is JideBoxLayout.

Parameters:
statusComponent - the status component.
Returns:
the panel which contains the status

createScrollButton

protected AbstractButton createScrollButton(int type)
Creates the scroll button for the SimpleScrollPane used by GadgetPalete when there aren't enough space to show all gadgets on the palette.

Parameters:
type - left or right. It could be SwingConstants.WEST or SwingConstants.EAST.
Returns:
the scroll button for the SimpleScrollPane used by GadgetPalete.

updateUI

public void updateUI()
Overrides:
updateUI in class JPanel

paintComponent

protected void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

paintBackground

protected void paintBackground(Graphics g)
Paints the background of GadgetPalette.

Parameters:
g - the Graphics instance
Since:
3.3.8

getGadgetManager

public GadgetManager getGadgetManager()

getInstaller

public GadgetPaletteInstaller getInstaller()

createButton

protected AbstractButton createButton(Gadget gadget)

customizeButton

protected void customizeButton(AbstractButton button)

uncustomizeButton

protected void uncustomizeButton(AbstractButton button)

getResourceString

protected String getResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in dashboard.properties.

Parameters:
key - the resource key.
Returns:
the localized string.

eventHappened

public void eventHappened(GadgetEvent e)
Description copied from interface: GadgetListener
Invoked when a Gadget event happened

Specified by:
eventHappened in interface GadgetListener
Parameters:
e - GadgetEvent

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

JIDE 3.5.15