net.java.balloontip
Class BalloonTip

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 net.java.balloontip.BalloonTip
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
CustomBalloonTip

public class BalloonTip
extends javax.swing.JPanel

A balloon tip Swing component that is attached to a JComponent and uses another JComponent as contents

Author:
Bernhard Pauler, Tim Molderez, Thierry Blind
See Also:
Serialized Form

Nested Class Summary
static class BalloonTip.AttachLocation
          Where should the balloon's tip be located, relative to the attached component ; ALIGNED makes sure the balloon's edge is aligned with the attached component
static class BalloonTip.Orientation
          Should the balloon be placed above, below, right or left of the attached component?
protected  class BalloonTip.VisibilityControl
           
 
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
protected  javax.swing.JComponent attachedComponent
           
protected  javax.swing.JButton closeButton
           
protected  javax.swing.JComponent contents
           
protected  float opacity
           
protected  int padding
           
protected  BalloonTipPositioner positioner
           
protected  BalloonTipStyle style
           
protected  javax.swing.JLayeredPane topLevelContainer
           
protected  net.java.balloontip.BalloonTip.NestedViewportListener viewportListener
           
protected  BalloonTip.VisibilityControl visibilityControl
           
 
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
protected BalloonTip()
           
  BalloonTip(javax.swing.JComponent attachedComponent, javax.swing.JComponent contents, BalloonTipStyle style, BalloonTip.Orientation orientation, BalloonTip.AttachLocation attachLocation, int horizontalOffset, int verticalOffset, boolean useCloseButton)
          Constructor
  BalloonTip(javax.swing.JComponent attachedComponent, javax.swing.JComponent contents, BalloonTipStyle style, BalloonTipPositioner positioner, javax.swing.JButton closeButton)
          Constructor - the most customizable balloon tip constructor
  BalloonTip(javax.swing.JComponent attachedComponent, javax.swing.JComponent contents, BalloonTipStyle style, boolean useCloseButton)
          Constructor
  BalloonTip(javax.swing.JComponent attachedComponent, java.lang.String text)
          Constructor The simplest constructor, a balloon tip with some text and a default look
  BalloonTip(javax.swing.JComponent attachedComponent, java.lang.String text, BalloonTipStyle style, boolean useCloseButton)
          Constructor A simple constructor for a balloon tip containing text, a custom look and optionally a close button
 
Method Summary
 void addDefaultMouseListener(boolean permanentClose)
          Adds a mouse listener that will close this balloon tip when clicked.
 void closeBalloon()
          If you want to permanently close the balloon, you can use this method.
protected  void finalize()
           
protected  void forceSetVisible(boolean visible)
           
 javax.swing.JComponent getAttachedComponent()
          Retrieve the component this balloon tip is attached to
 java.awt.Rectangle getAttachedRectangle()
          Retrieves the rectangle to which this balloon tip is attached
 javax.swing.JButton getCloseButton()
          Retrieve this balloon tip's close button
 javax.swing.JComponent getContents()
          Retrieve this balloon tip's contents
static javax.swing.JButton getDefaultCloseButton()
          Creates a default close button (without any behaviour)
 float getOpacity()
          Get the opacity of this balloon tip
 int getPadding()
          Get the amount of padding in this balloon tip
 BalloonTipPositioner getPositioner()
          Retrieve the BalloonTipPositioner that is used by this balloon tip
 BalloonTipStyle getStyle()
          Get the balloon tip's style
 javax.swing.JLayeredPane getTopLevelContainer()
          Retrieve the container this balloon tip is drawn on If the balloon tip hasn't determined this container yet, null is returned
protected  boolean isAttachedComponentShowing()
           
 void paintComponent(java.awt.Graphics g)
           
 void refreshLocation()
          Refreshes the balloon tip's location (Is able to update balloon tip's location even if the balloon tip is not shown.)
 void setAttachedComponent(javax.swing.JComponent newComponent)
          Change the component this balloon tip is attached to (The top-level container will be re-determined during this process; if you set it manually, you'll have to set it again...)
 void setCloseButton(javax.swing.JButton button)
          Sets this balloon tip's close button (which will call closeBalloon() when clicked) You don't need add any behaviour to the button yourself; this is added for you.
 void setCloseButton(javax.swing.JButton button, boolean permanentClose, boolean noDefault)
          Sets this balloon tip's close button
 void setContents(javax.swing.JComponent contents)
          Sets the contents of this balloon tip (Calling this method will fire a "contents" property change event.)
static void setDefaultCloseButtonIcons(javax.swing.Icon normal, javax.swing.Icon pressed, javax.swing.Icon rollover)
          Set the icons for the default close button (This only affects balloon tips created after calling this method.)
 void setOpacity(float opacity)
          Sets the opacity of this balloon tip and repaints it Note: Setting the opacity to 0 won't make isVisible() return false.
 void setPadding(int padding)
          Set the amount of padding in this balloon tip (by attaching an empty border to the balloon tip's contents...)
 void setPositioner(BalloonTipPositioner positioner)
          Set a new BalloonTipPositioner, repsonsible for the balloon tip's positioning (Calling this method will fire a "positioner" property change event.)
 void setStyle(BalloonTipStyle style)
          Set the balloon tip's style (Calling this method will fire a "style" property change event.)
 void setTopLevelContainer(javax.swing.JLayeredPane tlc)
          Set the container on which this balloon tip should be drawn
protected  void setup(javax.swing.JComponent attachedComponent, javax.swing.JComponent contents, BalloonTipStyle style, BalloonTipPositioner positioner, javax.swing.JButton closeButton)
           
protected  BalloonTipPositioner setupPositioner(BalloonTip.Orientation orientation, BalloonTip.AttachLocation attachLocation, int horizontalOffset, int verticalOffset)
           
 void setVisible(boolean visible)
          Set this balloon tip's visibility
 
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, 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, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

contents

protected javax.swing.JComponent contents

closeButton

protected javax.swing.JButton closeButton

visibilityControl

protected BalloonTip.VisibilityControl visibilityControl

style

protected BalloonTipStyle style

padding

protected int padding

opacity

protected float opacity

positioner

protected BalloonTipPositioner positioner

topLevelContainer

protected javax.swing.JLayeredPane topLevelContainer

attachedComponent

protected javax.swing.JComponent attachedComponent

viewportListener

protected net.java.balloontip.BalloonTip.NestedViewportListener viewportListener
Constructor Detail

BalloonTip

public BalloonTip(javax.swing.JComponent attachedComponent,
                  java.lang.String text)
Constructor The simplest constructor, a balloon tip with some text and a default look

Parameters:
attachedComponent - attach the balloon tip to this component (may not be null)
text - the contents of the balloon tip (may contain HTML)

BalloonTip

public BalloonTip(javax.swing.JComponent attachedComponent,
                  java.lang.String text,
                  BalloonTipStyle style,
                  boolean useCloseButton)
Constructor A simple constructor for a balloon tip containing text, a custom look and optionally a close button

Parameters:
attachedComponent - attach the balloon tip to this component (may not be null)
text - the contents of the balloon tip (may contain HTML)
style - the balloon tip's looks (may not be null)
useCloseButton - if true, the balloon tip gets a default close button

BalloonTip

public BalloonTip(javax.swing.JComponent attachedComponent,
                  javax.swing.JComponent contents,
                  BalloonTipStyle style,
                  boolean useCloseButton)
Constructor

Parameters:
attachedComponent - attach the balloon tip to this component (may not be null)
contents - the balloon tip's contents (may be null)
style - the balloon tip's looks (may not be null)
useCloseButton - if true, the balloon tip gets a close button

BalloonTip

public BalloonTip(javax.swing.JComponent attachedComponent,
                  javax.swing.JComponent contents,
                  BalloonTipStyle style,
                  BalloonTip.Orientation orientation,
                  BalloonTip.AttachLocation attachLocation,
                  int horizontalOffset,
                  int verticalOffset,
                  boolean useCloseButton)
Constructor

Parameters:
attachedComponent - attach the balloon tip to this component (may not be null)
contents - the balloon tip's contents (may be null)
style - the balloon tip's looks (may not be null)
orientation - orientation of the balloon tip
attachLocation - location of the balloon's tip within the attached component
horizontalOffset - horizontal offset for the balloon's tip
verticalOffset - vertical offset for the balloon's tip
useCloseButton - if true, the balloon tip gets a close button

BalloonTip

public BalloonTip(javax.swing.JComponent attachedComponent,
                  javax.swing.JComponent contents,
                  BalloonTipStyle style,
                  BalloonTipPositioner positioner,
                  javax.swing.JButton closeButton)
Constructor - the most customizable balloon tip constructor

Parameters:
attachedComponent - attach the balloon tip to this component (may not be null)
contents - the contents of the balloon tip (may be null)
style - the balloon tip's looks (may not be null)
positioner - determines the way the balloon tip is positioned (may not be null)
closeButton - the close button to be used for the balloon tip (may be null)

BalloonTip

protected BalloonTip()
Method Detail

setContents

public void setContents(javax.swing.JComponent contents)
Sets the contents of this balloon tip (Calling this method will fire a "contents" property change event.)

Parameters:
contents - a JComponent that represents the balloon tip's contents If the contents is null, the balloon tip will not be shown

getContents

public javax.swing.JComponent getContents()
Retrieve this balloon tip's contents

Returns:
the JComponent representing the contents of this balloon tip (can be null)

setPadding

public void setPadding(int padding)
Set the amount of padding in this balloon tip (by attaching an empty border to the balloon tip's contents...)

Parameters:
padding - the amount of padding in pixels

getPadding

public int getPadding()
Get the amount of padding in this balloon tip

Returns:
the amount of padding in pixels

setStyle

public void setStyle(BalloonTipStyle style)
Set the balloon tip's style (Calling this method will fire a "style" property change event.)

Parameters:
style - a BalloonTipStyle (may not be null)

getStyle

public BalloonTipStyle getStyle()
Get the balloon tip's style

Returns:
the balloon tip's style

setPositioner

public void setPositioner(BalloonTipPositioner positioner)
Set a new BalloonTipPositioner, repsonsible for the balloon tip's positioning (Calling this method will fire a "positioner" property change event.)

Parameters:
positioner - a BalloonTipPositioner (may not be null)

getPositioner

public BalloonTipPositioner getPositioner()
Retrieve the BalloonTipPositioner that is used by this balloon tip

Returns:
The balloon tip's positioner

closeBalloon

public void closeBalloon()
If you want to permanently close the balloon, you can use this method. (It will be called automatically once Java's garbage collector can clean up this balloon tip...) Please note, you shouldn't use this instance anymore after calling this method! (If you just want to hide the balloon tip, simply use setVisible(false);)


setCloseButton

public void setCloseButton(javax.swing.JButton button)
Sets this balloon tip's close button (which will call closeBalloon() when clicked) You don't need add any behaviour to the button yourself; this is added for you.

Parameters:
button - the new close button; if null, the balloon tip's close button is removed (if it had one)

setCloseButton

public void setCloseButton(javax.swing.JButton button,
                           boolean permanentClose,
                           boolean noDefault)
Sets this balloon tip's close button

Parameters:
button - the new close button; if null, the balloon tip's close button is removed (if it had one)
permanentClose - if true, the default behaviour of the button is to close the balloon tip permanently by calling closeBalloon() if false, the default behaviour is to just hide the balloon tip by calling setVisible(false)
noDefault - if true, no default behaviour is added and you'll have to set it yourself

getCloseButton

public javax.swing.JButton getCloseButton()
Retrieve this balloon tip's close button

Returns:
the close button (null if not present)

getDefaultCloseButton

public static javax.swing.JButton getDefaultCloseButton()
Creates a default close button (without any behaviour)

Returns:
the close button

setDefaultCloseButtonIcons

public static void setDefaultCloseButtonIcons(javax.swing.Icon normal,
                                              javax.swing.Icon pressed,
                                              javax.swing.Icon rollover)
Set the icons for the default close button (This only affects balloon tips created after calling this method.)

Parameters:
normal - regular icon
pressed - icon when clicked
rollover - icon when hovering over the button

addDefaultMouseListener

public void addDefaultMouseListener(boolean permanentClose)
Adds a mouse listener that will close this balloon tip when clicked.

Parameters:
permanentClose - if true, the default behaviour is to close the balloon tip permanently by calling closeBalloon() if false, the default behaviour is to just hide the balloon tip by calling setVisible(false)

setAttachedComponent

public void setAttachedComponent(javax.swing.JComponent newComponent)
Change the component this balloon tip is attached to (The top-level container will be re-determined during this process; if you set it manually, you'll have to set it again...) (Calling this method will fire an "attachedComponent" property change event.)

Parameters:
newComponent - the new component to attach to (may not be null)
Throws:
java.lang.NullPointerException - if parameter newComponent is null

getAttachedComponent

public javax.swing.JComponent getAttachedComponent()
Retrieve the component this balloon tip is attached to

Returns:
The attached component

setTopLevelContainer

public void setTopLevelContainer(javax.swing.JLayeredPane tlc)
Set the container on which this balloon tip should be drawn

Parameters:
tlc - the top-level container; must be valid (isValid() must return true) () (may not be null)

getTopLevelContainer

public javax.swing.JLayeredPane getTopLevelContainer()
Retrieve the container this balloon tip is drawn on If the balloon tip hasn't determined this container yet, null is returned

Returns:
The balloon tip's top level container

getAttachedRectangle

public java.awt.Rectangle getAttachedRectangle()
Retrieves the rectangle to which this balloon tip is attached

Returns:
the rectangle to which this balloon tip is attached, in the coordinate system of the balloon tip

refreshLocation

public void refreshLocation()
Refreshes the balloon tip's location (Is able to update balloon tip's location even if the balloon tip is not shown.)


setOpacity

public void setOpacity(float opacity)
Sets the opacity of this balloon tip and repaints it Note: Setting the opacity to 0 won't make isVisible() return false.

Parameters:
opacity - the opacity, where 0.0f is completely invisible and 1.0f is opaque

getOpacity

public float getOpacity()
Get the opacity of this balloon tip

Returns:
the opacity, where 0.0f is completely invisible and 1.0f is opaque

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

setVisible

public void setVisible(boolean visible)
Set this balloon tip's visibility

Overrides:
setVisible in class javax.swing.JComponent
Parameters:
visible - visible if true (and if the listeners associated with this balloon tip have no reason to hide the balloon tip! For example, it makes no sense to show balloon tip if the component it's attached to is hidden...); invisible otherwise

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

forceSetVisible

protected void forceSetVisible(boolean visible)

isAttachedComponentShowing

protected boolean isAttachedComponentShowing()

setupPositioner

protected BalloonTipPositioner setupPositioner(BalloonTip.Orientation orientation,
                                               BalloonTip.AttachLocation attachLocation,
                                               int horizontalOffset,
                                               int verticalOffset)

setup

protected void setup(javax.swing.JComponent attachedComponent,
                     javax.swing.JComponent contents,
                     BalloonTipStyle style,
                     BalloonTipPositioner positioner,
                     javax.swing.JButton closeButton)


http://balloontip.java.net/