org.tbee.swing
Class JViewportWatermark

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JViewport
                  extended by org.tbee.swing.JViewportWatermark
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class JViewportWatermark
extends JViewport

An extension of javax.swing.JViewport that allows pluggable custom painting of its background and foreground. Since the painting is done on the viewport itself, it will not scroll when the view is scrolled. The resulting effect is that the view seems to float in space between the fixed background and foreground.

It is important to remember to set the opacity of the component that this viewport displays to false, so that the viewport's background can show through.

Example of use with a JEditorPane:

 JEditorPane ep = new JEditorPane();
 
 // important so that we can see through the JEditorPane
 ep.setOpaque(false);
 
 JScrollPane sp = new JScrollPane();
 WatermarkViewport vp = new WatermarkViewport(bgPainter, fgPainter);
 vp.setView(ep);
 sp.setViewport(vp);
 

Version:
$Revision: 1.2 $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JViewport
JViewport.AccessibleJViewport, JViewport.ViewListener
 
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
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Fields inherited from class javax.swing.JViewport
backingStore, BACKINGSTORE_SCROLL_MODE, backingStoreImage, BLIT_SCROLL_MODE, isViewSizeSet, lastPaintPosition, scrollUnderway, SIMPLE_SCROLL_MODE
 
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
JViewportWatermark(WatermarkPainter bgPainter, WatermarkPainter fgPainter)
          Creates a WatermarkViewport with the specified background and foreground painters.
 
Method Summary
 WatermarkPainter getBackgroundPainter()
          Return the painter that paints the background.
 WatermarkPainter getForegroundPainter()
          Return the painter that paints the foreground.
static void main(String[] args)
           
 void paintChildren(Graphics g)
          overriding paintChildren allows us to paint the custom foreground above the scrolling content
 void paintComponent(Graphics g)
          overriding paintComponent allows us to paint the custom background below the scrolling content.
 void setBackgroundPainter(WatermarkPainter painter)
          Set the painter to use to paint the background.
 void setForegroundPainter(WatermarkPainter painter)
          Set the painter to use to paint the foregreound.
 
Methods inherited from class javax.swing.JViewport
addChangeListener, addImpl, computeBlit, createLayoutManager, createViewListener, firePropertyChange, fireStateChanged, getAccessibleContext, getChangeListeners, getExtentSize, getInsets, getInsets, getScrollMode, getUI, getUIClassID, getView, getViewPosition, getViewRect, getViewSize, isBackingStoreEnabled, isOptimizedDrawingEnabled, paint, paramString, remove, removeChangeListener, repaint, reshape, scrollRectToVisible, setBackingStoreEnabled, setBorder, setExtentSize, setScrollMode, setUI, setView, setViewPosition, setViewSize, toViewCoordinates, toViewCoordinates, 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, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, 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, 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, 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, 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

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values
Constructor Detail

JViewportWatermark

public JViewportWatermark(WatermarkPainter bgPainter,
                          WatermarkPainter fgPainter)
Creates a WatermarkViewport with the specified background and foreground painters.

Parameters:
bgPainter - the painter that will paint the background
fgPainter - the painter that will paint the foreground
Method Detail

paintComponent

public void paintComponent(Graphics g)
overriding paintComponent allows us to paint the custom background below the scrolling content.

Overrides:
paintComponent in class JComponent

paintChildren

public void paintChildren(Graphics g)
overriding paintChildren allows us to paint the custom foreground above the scrolling content

Overrides:
paintChildren in class JComponent

setBackgroundPainter

public void setBackgroundPainter(WatermarkPainter painter)
Set the painter to use to paint the background.

Parameters:
painter - the painter that will paint the background

setForegroundPainter

public void setForegroundPainter(WatermarkPainter painter)
Set the painter to use to paint the foregreound.

Parameters:
painter - the painter that will paint the foreground

getBackgroundPainter

public WatermarkPainter getBackgroundPainter()
Return the painter that paints the background.

Returns:
the painter used for the background

getForegroundPainter

public WatermarkPainter getForegroundPainter()
Return the painter that paints the foreground.

Returns:
the painter used for the foreground

main

public static void main(String[] args)


Copyright © 2012 KnowledgePlaza. All Rights Reserved.