Mp3dings 
20100427

de.mospace.swing
Class LookAndFeelMenu

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.AbstractButton
                  extended by javax.swing.JMenuItem
                      extended by javax.swing.JMenu
                          extended by de.mospace.swing.LookAndFeelMenu
All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants

public class LookAndFeelMenu
extends JMenu

A JMenu that lets you change the LookAndFeel of a window. The default menutitle is LnF. Use setText() to change it.

An instance of this class will detect when the UIManager's lookAndFeel property changes and will select the corresponding menu item if it exists. No further action will be taken, in particular the LookAndFeelMenu will not update the application GUI. In general, once a client creates an instance of this class it should yield control over the LookAndFeel to the LookAndFeelMenu.

There should be no problem however to have several instances of this class.

Version:
$Revision: 69 $ ($Date: 2007-10-24 23:57:43 +0200 (Mi, 24 Okt 2007) $)
Author:
Moritz Ringler
See Also:
LookAndFeelMenu(Preferences, Window, File, File, ClassLoader), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JMenu
JMenu.AccessibleJMenu, JMenu.WinListener
 
Nested classes/interfaces inherited from class javax.swing.JMenuItem
JMenuItem.AccessibleJMenuItem
 
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
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
 
Fields inherited from class javax.swing.JMenu
popupListener
 
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
LookAndFeelMenu(Preferences pref, Window w)
          Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts.
LookAndFeelMenu(Preferences pref, Window w, File lafProperties)
          Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts and uses a fallback mechanism if the user does not have write access to the JRE directories.
LookAndFeelMenu(Preferences pref, Window w, File lafProperties, File installdir)
          Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts and uses a fallback mechanism if the user does not have write access to the JRE directories.
LookAndFeelMenu(Preferences pref, Window w, File lafProperties, File installdir, ClassLoader customCL)
          Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts and uses a fallback mechanism if the user does not have write access to the JRE directories.
LookAndFeelMenu(Preferences pref, Window w, File lafProperties, File installdir, ClassLoaderProvider clp)
           
LookAndFeelMenu(Window w)
          Creates a new LookAndFeelMenu that does not remember the selected LookAndFeel between program starts.
 
Method Summary
 void setDialogParent(Component p)
           
static boolean setLookAndFeel(Preferences pref, ClassLoader loader)
          Tries to load a previously saved current LookAndFeel.
protected  boolean setLookAndFeel(String classname)
          Constructs a new LookAndFeel object, calls UIManager.setLookAndFeel(LookAndFeel laf), and consumes all eventual exceptions.
static boolean setLookAndFeel(String classname, ClassLoader loader)
          Tries to create an instance of the specified LookAndFeel class using the provided ClassLoader and calls UIManager.setLookAndFeel(LookAndFeel laf).
protected  void updateApplicationGui()
          The default implementation updates the window provided to the constructor.
 
Methods inherited from class javax.swing.JMenu
add, add, add, add, add, addMenuListener, addSeparator, applyComponentOrientation, createActionChangeListener, createActionComponent, createWinListener, doClick, fireMenuCanceled, fireMenuDeselected, fireMenuSelected, getAccessibleContext, getComponent, getDelay, getItem, getItemCount, getMenuComponent, getMenuComponentCount, getMenuComponents, getMenuListeners, getPopupMenu, getPopupMenuOrigin, getSubElements, getUIClassID, insert, insert, insert, insertSeparator, isMenuComponent, isPopupMenuVisible, isSelected, isTearOff, isTopLevelMenu, menuSelectionChanged, paramString, processKeyEvent, remove, remove, remove, removeAll, removeMenuListener, setAccelerator, setComponentOrientation, setDelay, setMenuLocation, setModel, setPopupMenuVisible, setSelected, updateUI
 
Methods inherited from class javax.swing.JMenuItem
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getMenuDragMouseListeners, getMenuKeyListeners, init, isArmed, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setArmed, setEnabled, setUI
 
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
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, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, 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, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, 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, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.swing.MenuElement
processKeyEvent, processMouseEvent
 

Constructor Detail

LookAndFeelMenu

public LookAndFeelMenu(Window w)
Creates a new LookAndFeelMenu that does not remember the selected LookAndFeel between program starts.

Equivalent to LookAndFeelMenu(null, w, null, null, null).

Parameters:
w - the window so set the look and feel of. May be null.

LookAndFeelMenu

public LookAndFeelMenu(Preferences pref,
                       Window w)
Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts.

Equivalent to LookAndFeelMenu(pref, w, null, null, null).

Parameters:
pref - the preferences node to read from and write to
w - the window so set the look and feel of, may be null

LookAndFeelMenu

public LookAndFeelMenu(Preferences pref,
                       Window w,
                       File lafProperties)
Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts and uses a fallback mechanism if the user does not have write access to the JRE directories. Look and Feel libraries will be read from and installed as jar files in the parent directory of lafProperties.

Parameters:
pref - the preferences node to read from and write to
w - the window so set the look and feel of, may be null
lafProperties - a fallback properties file.
See Also:
LookAndFeelMenu(Preferences, Window, File, File, ClassLoader)

LookAndFeelMenu

public LookAndFeelMenu(Preferences pref,
                       Window w,
                       File lafProperties,
                       File installdir)
Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts and uses a fallback mechanism if the user does not have write access to the JRE directories.

Note that if installdir is null the system class loader will be used. Consider using LookAndFeelMenu(Preferences pref, Window w, File lafProperties) in this case.

Equivalent to

 LookAndFeelMenu(pref,
                 w,
                 lafProperties,
                 installdir,
                 createLibClassLoader(installdir))

Parameters:
pref - the preferences node to read from and write to
w - the window so set the look and feel of, may be null
lafProperties - a fallback properties file. Can be null.
installdir - a fallback installation directory.
See Also:
LookAndFeelMenu(Preferences, Window, File, File, ClassLoader)

LookAndFeelMenu

public LookAndFeelMenu(Preferences pref,
                       Window w,
                       File lafProperties,
                       File installdir,
                       ClassLoader customCL)
Creates a new LookAndFeelMenu that remembers the selected LookAndFeel between program starts and uses a fallback mechanism if the user does not have write access to the JRE directories.

If possible LookAndFeel jar files will be installed to the first writable directory specified by the Java system property java.ext.dirs , and information about the installed LookAndFeels will be saved in lib/swing.properties .

If the user does not have write access to the extension directories the jar files will be installed to installdir or the user will be asked for a target directory if both installdir and lafProperties are null. If only installdir is null the parent directory of lafProperties will be used as the installation target.

If lafProperties is not null information about the installed LookAndFeels will be read from both lib/swing.properties and lafProperties and saved to lib/swing.properties if possible and lafProperties otherwise.

In addition a custom class loader can be specified, which will be used exclusively to instantiate LookAndFeel classes. A suitable classloader can be created using a ClassLoaderProvider. This is necessary whenever newly installed jar files are not added to your classpath by some other mechanism outside this class.

If you save the current LookAndFeel to Preferences your Application should call setLookAndFeel(Preferences pref, ClassLoader loader) before creating its GUI.

Parameters:
pref - the preference node from which to read and to which to save the current LookAndFeel. If it is null the current LookAndFeel will be forgotten when the JVM exits.
w - the window whose LookAndFeel this LookAndFeelMenu controls. Can be null.
lafProperties - a fallback properties file. Can be null.
installdir - a fallback installation directory. Can be null.
customCL - Description of the Parameter

LookAndFeelMenu

public LookAndFeelMenu(Preferences pref,
                       Window w,
                       File lafProperties,
                       File installdir,
                       ClassLoaderProvider clp)
Method Detail

setDialogParent

public void setDialogParent(Component p)

setLookAndFeel

protected boolean setLookAndFeel(String classname)
Constructs a new LookAndFeel object, calls UIManager.setLookAndFeel(LookAndFeel laf), and consumes all eventual exceptions. This method should be used by subclasses of LookAndFeelMenu only.

Parameters:
classname - the classname of the new LookAndFeel
Returns:
false if an exception occurred true otherwise
See Also:
UIManager.setLookAndFeel(LookAndFeel laf)

setLookAndFeel

public static boolean setLookAndFeel(String classname,
                                     ClassLoader loader)
Tries to create an instance of the specified LookAndFeel class using the provided ClassLoader and calls UIManager.setLookAndFeel(LookAndFeel laf). Consumes all eventual exceptions.

This method should be used from outside this class and its subclasses only when no GUI components and in particular no instances of this class have been created.

Parameters:
classname - the classname of the new LookAndFeel
loader - the classloader that will be used to create an instance of the LookAndFeel class. If loader is null the system class loader will be used instead.
Returns:
false if an exception occurred true otherwise
See Also:
UIManager.setLookAndFeel(LookAndFeel laf)

setLookAndFeel

public static boolean setLookAndFeel(Preferences pref,
                                     ClassLoader loader)
Tries to load a previously saved current LookAndFeel. If none is found UIManager.getSystemLookAndFeelClassName() is used as a default. Consumes all eventual exceptions.

This method should be used from outside this class and its subclasses only when no GUI components and in particular no instances of this class have been created.

Parameters:
pref - the Preferences node to load the LookAndFeel from
loader - the classloader that will be used to create an instance of the LookAndFeel class. If loader is null the system class loader will be used instead.
Returns:
false if an exception occurred true otherwise
See Also:
UIManager.setLookAndFeel(LookAndFeel laf)

updateApplicationGui

protected void updateApplicationGui()
The default implementation updates the window provided to the constructor. Override this method according to your application-specific needs.


Mp3dings 
20100427