org.freehep.graphics2d
Class BufferedPanel

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 org.freehep.graphics2d.BufferedPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class BufferedPanel
extends JPanel
implements Serializable

This class extends JPanel by adding double buffering. This is intended to be used in situations in which redrawing the contents of the panel is expensive.

Version:
$Id: BufferedPanel.java 8584 2006-08-10 23:06:37Z duns $
Author:
Mark Donszelmann
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
 
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
BufferedPanel()
           
BufferedPanel(boolean opaque)
          Creates a new BufferedPanel with a width and height set to zero.
 
Method Summary
 Graphics getBufferedGraphics()
          Returns a pointer to the graphics (VectorGraphics) context of the buffer.
 void invalidate()
          Triggers a full repaint, since the component is not valid anymore (size change, iconized, ...)
 boolean isDisplaying()
          Returns true if the drawing is made for a PixelGraphics context, the display.
 boolean isExporting()
          Returns true if the drawing is made for a VectorGraphics context.
 boolean isPrinting()
          Returns true if the drawing is made for a PrinterGraphics context.
 void paintComponent(Graphics g)
          Paint this panel by calling paintComponent(VectorGraphics) if necessary and flushing the buffered image to the screen.
 void paintComponent(VectorGraphics vg)
          Allows for custom graphics to be painted.
 void repaint()
          Triggers a full "user" repaint.
 void setBounds(int x, int y, int w, int h)
          Resize and move a component.
 
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, 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, 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, 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, resize, resize, setBounds, setComponentOrientation, 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
 

Constructor Detail

BufferedPanel

public BufferedPanel()

BufferedPanel

public BufferedPanel(boolean opaque)
Creates a new BufferedPanel with a width and height set to zero.

Parameters:
opaque - transparent panel
Method Detail

repaint

public void repaint()
Triggers a full "user" repaint. If the "system" wants to repaint it will call the paint(Graphics) method directly, rather than scheduling a paint(Graphics) through a repaint().

Overrides:
repaint in class Component

invalidate

public void invalidate()
Triggers a full repaint, since the component is not valid anymore (size change, iconized, ...)

Overrides:
invalidate in class Container

paintComponent

public void paintComponent(Graphics g)
Paint this panel by calling paintComponent(VectorGraphics) if necessary and flushing the buffered image to the screen. This method also handles printing and exporting separately.

Overrides:
paintComponent in class JComponent
Parameters:
g - Graphics object

getBufferedGraphics

public Graphics getBufferedGraphics()
Returns a pointer to the graphics (VectorGraphics) context of the buffer. The user is NOT allowed to call dispose() on this graphics object.

NOTE: this method used to be called getGraphics, however, since the JVM paint thread may call getGraphics from paintImmediately and fails to work with our VectorGraphics context (the gc is not longer attached to the image), we decided to rename the method.


paintComponent

public void paintComponent(VectorGraphics vg)
Allows for custom graphics to be painted. Subclasses should implement real drawing here. They can ask isPrinting(), isExporting() or isDisplaying() to see where the output goes. If painting is done to a display it is done to a buffer which is kept and copied afterwards. Note that the parameter here is of class VectorGraphics rather than Graphics.


setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Resize and move a component.

Overrides:
setBounds in class Component

isPrinting

public boolean isPrinting()
Returns true if the drawing is made for a PrinterGraphics context.


isExporting

public boolean isExporting()
Returns true if the drawing is made for a VectorGraphics context.


isDisplaying

public boolean isDisplaying()
Returns true if the drawing is made for a PixelGraphics context, the display. True if not Printing and not Exporting.



Copyright © 2012. All Rights Reserved.