Class JXTipOfTheDay
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.jdesktop.swingx.JXPanel
-
- org.jdesktop.swingx.JXTipOfTheDay
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.Scrollable,AlphaPaintable,BackgroundPaintable
@JavaBean public class JXTipOfTheDay extends JXPanel
Provides the "Tip of The Day" pane and dialog.
Tips are retrieved from the
TipOfTheDayModel. In the most common usage, a tip (as returned byTipOfTheDayModel.Tip.getTip()) is just aString. However, the return type of this method is actuallyObject. Its interpretation depends on its type:- Component
- The
Componentis displayed in the dialog. - Icon
- The
Iconis wrapped in aJLabeland displayed in the dialog. - others
- The object is converted to a
Stringby calling itstoStringmethod. The result is wrapped in aJEditorPaneorJTextAreaand displayed.
JXTipOfTheDayfinds its tips in itsTipOfTheDayModel. Such model can be programmatically built usingDefaultTipOfTheDayModelandDefaultTipbut theTipLoaderprovides a convenient method to build a model and its tips from aPropertiesobject.Example:
Let's consider a file tips.properties with the following content:
To load and display the tips:tip.1.description=This is the first time! Plain text. tip.2.description=<html>This is <b>another tip</b>, it uses HTML! tip.3.description=A third oneProperties tips = new Properties(); tips.load(new FileInputStream("tips.properties")); TipOfTheDayModel model = TipLoader.load(tips); JXTipOfTheDay totd = new JXTipOfTheDay(model); totd.showDialog(someParentComponent);Additionally,
JXTipOfTheDayfeatures an option enabling the end-user to choose to not display the "Tip Of The Day" dialog. This user choice can be stored in the userPreferencesbutJXTipOfTheDayalso supports custom storage through theJXTipOfTheDay.ShowOnStartupChoiceinterface.
In this code, the first time showDialog is called, the dialog will be made visible and the user will have the choice to not display it again in the future (usually this is controlled by a checkbox "Show tips on startup"). If the user unchecks the option, subsequent calls to showDialog will not display the dialog. As the choice is saved in the user Preferences, it will persist when the application is relaunched.Preferences userPreferences = Preferences.userRoot().node("myApp"); totd.showDialog(someParentComponent, userPreferences);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJXTipOfTheDay.ShowOnStartupChoiceUsed in conjunction with theshowDialog(Component, ShowOnStartupChoice)to save the "Show tips on startup" choice.-
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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCURRENT_TIP_CHANGED_KEYUsed when generating PropertyChangeEvents for the "currentTip" propertyprivate intcurrentTipprivate TipOfTheDayModelmodelstatic java.lang.StringPREFERENCE_KEYKey used to store the status of the "Show tip on startup" checkbox"static java.lang.StringuiClassIDJXTipOfTheDay pluggable UI key swingx/TipOfTheDayUI-
Fields inherited from class org.jdesktop.swingx.JXPanel
fakeTransparent
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description JXTipOfTheDay()Constructs a newJXTipOfTheDaywith an empty TipOfTheDayModelJXTipOfTheDay(TipOfTheDayModel model)Constructs a newJXTipOfTheDayshowing tips from the given TipOfTheDayModel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.swing.JDialogcreateDialog(java.awt.Component parentComponent, JXTipOfTheDay.ShowOnStartupChoice choice)static voidforceShowOnStartup(java.util.prefs.Preferences showOnStartupPref)Removes the value set for "ShowTipOnStartup" in the given Preferences to ensure the dialog shown by a later call toshowDialog(Component, Preferences)will be visible to the user.intgetCurrentTip()TipOfTheDayModelgetModel()TipOfTheDayUIgetUI()Gets the UI object which implements the L&F for this component.java.lang.StringgetUIClassID()Returns the name of the L&F class that renders this component.static booleanisShowingOnStartup(java.util.prefs.Preferences showOnStartupPref)voidnextTip()Shows the next tip in the list.voidpreviousTip()Shows the previous tip in the list.voidsetCurrentTip(int currentTip)Sets the index of the tip to showvoidsetModel(TipOfTheDayModel model)voidsetUI(TipOfTheDayUI ui)Sets the L&F object that renders this component.voidshowDialog(java.awt.Component parentComponent)Pops up a "Tip of the day" dialog.booleanshowDialog(java.awt.Component parentComponent, java.util.prefs.Preferences showOnStartupPref)Pops up a "Tip of the day" dialog.booleanshowDialog(java.awt.Component parentComponent, java.util.prefs.Preferences showOnStartupPref, boolean force)Pops up a "Tip of the day" dialog.booleanshowDialog(java.awt.Component parentComponent, JXTipOfTheDay.ShowOnStartupChoice choice)Pops up a "Tip of the day" dialog.booleanshowDialog(java.awt.Component parentComponent, JXTipOfTheDay.ShowOnStartupChoice choice, boolean force)Pops up a "Tip of the day" dialog.voidupdateUI()Notification from theUIManagerthat the L&F has changed.-
Methods inherited from class org.jdesktop.swingx.JXPanel
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, installRepaintManager, isAlpha, isInheritAlpha, isOpaque, isOpaquePatch, isPaintBorderInsets, isPaintingBackground, isPaintingOrigin, isPatch, isTransparentBackground, paint, paintComponent, paintComponentPatch, setAlpha, setBackgroundPainter, setInheritAlpha, setOpaque, setOpaquePatch, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint, uninstallRepaintManager
-
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
uiClassID
public static final java.lang.String uiClassID
JXTipOfTheDay pluggable UI key swingx/TipOfTheDayUI- See Also:
- Constant Field Values
-
PREFERENCE_KEY
public static final java.lang.String PREFERENCE_KEY
Key used to store the status of the "Show tip on startup" checkbox"- See Also:
- Constant Field Values
-
CURRENT_TIP_CHANGED_KEY
public static final java.lang.String CURRENT_TIP_CHANGED_KEY
Used when generating PropertyChangeEvents for the "currentTip" property- See Also:
- Constant Field Values
-
model
private TipOfTheDayModel model
-
currentTip
private int currentTip
-
-
Constructor Detail
-
JXTipOfTheDay
public JXTipOfTheDay()
Constructs a newJXTipOfTheDaywith an empty TipOfTheDayModel
-
JXTipOfTheDay
public JXTipOfTheDay(TipOfTheDayModel model)
Constructs a newJXTipOfTheDayshowing tips from the given TipOfTheDayModel.- Parameters:
model-
-
-
Method Detail
-
updateUI
public void updateUI()
Notification from theUIManagerthat the L&F has changed. Replaces the current UI object with the latest version from theUIManager.- Overrides:
updateUIin classjavax.swing.JPanel- See Also:
JComponent.updateUI()
-
setUI
public void setUI(TipOfTheDayUI ui)
Sets the L&F object that renders this component.- Parameters:
ui- theTipOfTheDayUIL&F object- See Also:
UIDefaults.getUI(javax.swing.JComponent)
-
getUI
public TipOfTheDayUI getUI()
Gets the UI object which implements the L&F for this component.- Overrides:
getUIin classjavax.swing.JPanel- Returns:
- the TipOfTheDayUI object that implements the TipOfTheDayUI L&F
-
getUIClassID
public java.lang.String getUIClassID()
Returns the name of the L&F class that renders this component.- Overrides:
getUIClassIDin classjavax.swing.JPanel- Returns:
- the string
uiClassID - See Also:
JComponent.getUIClassID(),UIDefaults.getUI(javax.swing.JComponent)
-
getModel
public TipOfTheDayModel getModel()
-
setModel
public void setModel(TipOfTheDayModel model)
-
getCurrentTip
public int getCurrentTip()
-
setCurrentTip
public void setCurrentTip(int currentTip)
Sets the index of the tip to show- Parameters:
currentTip-- Throws:
java.lang.IllegalArgumentException- if currentTip is not within the bounds [0, getModel().getTipCount()[.
-
nextTip
public void nextTip()
Shows the next tip in the list. It cycles the tip list.
-
previousTip
public void previousTip()
Shows the previous tip in the list. It cycles the tip list.
-
showDialog
public void showDialog(java.awt.Component parentComponent) throws java.awt.HeadlessExceptionPops up a "Tip of the day" dialog.- Parameters:
parentComponent-- Throws:
java.awt.HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
GraphicsEnvironment.isHeadless()
-
showDialog
public boolean showDialog(java.awt.Component parentComponent, java.util.prefs.Preferences showOnStartupPref) throws java.awt.HeadlessExceptionPops up a "Tip of the day" dialog. Additionally, it saves the state of the "Show tips on startup" checkbox in a key named "ShowTipOnStartup" in the given Preferences.- Parameters:
parentComponent-showOnStartupPref-- Returns:
- true if the user chooses to see the tips again, false otherwise.
- Throws:
java.awt.HeadlessException- if GraphicsEnvironment.isHeadless() returns true.java.lang.IllegalArgumentException- if showOnStartupPref is null- See Also:
GraphicsEnvironment.isHeadless()
-
showDialog
public boolean showDialog(java.awt.Component parentComponent, java.util.prefs.Preferences showOnStartupPref, boolean force) throws java.awt.HeadlessExceptionPops up a "Tip of the day" dialog. Additionally, it saves the state of the "Show tips on startup" checkbox in a key named "ShowTipOnStartup" in the given Preferences.- Parameters:
parentComponent-showOnStartupPref-force- if true, the dialog is displayed even if the Preferences is set to hide the dialog- Returns:
- true if the user chooses to see the tips again, false otherwise.
- Throws:
java.awt.HeadlessException- if GraphicsEnvironment.isHeadless() returns true.java.lang.IllegalArgumentException- if showOnStartupPref is null- See Also:
GraphicsEnvironment.isHeadless()
-
showDialog
public boolean showDialog(java.awt.Component parentComponent, JXTipOfTheDay.ShowOnStartupChoice choice)Pops up a "Tip of the day" dialog. Ifchoiceis not null, the method first checks ifJXTipOfTheDay.ShowOnStartupChoice.isShowingOnStartup()is true before showing the dialog. Additionally, it saves the state of the "Show tips on startup" checkbox using the givenJXTipOfTheDay.ShowOnStartupChoiceobject.- Parameters:
parentComponent-choice-- Returns:
- true if the user chooses to see the tips again, false otherwise.
- Throws:
java.awt.HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
GraphicsEnvironment.isHeadless()
-
showDialog
public boolean showDialog(java.awt.Component parentComponent, JXTipOfTheDay.ShowOnStartupChoice choice, boolean force)Pops up a "Tip of the day" dialog. Ifchoiceis not null, the method first checks ifforceis true or ifJXTipOfTheDay.ShowOnStartupChoice.isShowingOnStartup()is true before showing the dialog. Additionally, it saves the state of the "Show tips on startup" checkbox using the givenJXTipOfTheDay.ShowOnStartupChoiceobject.- Parameters:
parentComponent-choice-force- if true, the dialog is displayed even ifJXTipOfTheDay.ShowOnStartupChoice.isShowingOnStartup()is false- Returns:
- true if the user chooses to see the tips again, false otherwise.
- Throws:
java.awt.HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
GraphicsEnvironment.isHeadless()
-
isShowingOnStartup
public static boolean isShowingOnStartup(java.util.prefs.Preferences showOnStartupPref)
- Parameters:
showOnStartupPref-- Returns:
- true if the key named "ShowTipOnStartup" is not set to false
-
forceShowOnStartup
public static void forceShowOnStartup(java.util.prefs.Preferences showOnStartupPref)
Removes the value set for "ShowTipOnStartup" in the given Preferences to ensure the dialog shown by a later call toshowDialog(Component, Preferences)will be visible to the user.- Parameters:
showOnStartupPref-
-
createDialog
protected javax.swing.JDialog createDialog(java.awt.Component parentComponent, JXTipOfTheDay.ShowOnStartupChoice choice)CallsTipOfTheDayUI.createDialog(Component, JXTipOfTheDay.ShowOnStartupChoice). This method can be overriden in order to control things such as the placement of the dialog or its title.- Parameters:
parentComponent-choice-- Returns:
- a JDialog to show this TipOfTheDay pane
-
-