FreeHEP API
Version current

org.freehep.graphics2d
Class BufferedPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.freehep.graphics2d.BufferedPanel
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
PSPanel

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,v 1.7 2005/01/21 19:24:29 duns Exp $
Author:
Mark Donszelmann
See Also:
Serialized Form
Source Code:
BufferedPanel.java

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, 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, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, resize, resize, 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
 

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().


invalidate

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


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.

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.


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.


FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.