APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

pack-priv Class BufferStrategyPaintManager

extends PaintManager
Class Inheritance
Imports
java.awt.*, java.awt.event.*, java.awt.image.*, java.lang.ref.WeakReference, java.util.*, com.sun.java.swing.SwingUtilities3, sun.awt.AWTAccessor, .SubRegionShowable, .SunToolkit, sun.java2d.SunGraphics2D, sun.java2d.pipe.hw.ExtendedBufferCapabilities, sun.util.logging.PlatformLogger

A PaintManager implementation that uses a BufferStrategy for rendering.
Author
Scott Violet

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
BufferStrategyPaintManager.BufferInfo

BufferInfo is used to track the BufferStrategy being used for a particular Component.

Field Summary

Modifier and TypeField and Description
private int
private int
private int
private int
private Graphics
bsg

Graphics from the BufferStrategy.

private BufferStrategyPaintManager.BufferInfo
bufferInfo

BufferInfo corresponding to root.

private ArrayList<BufferStrategyPaintManager.BufferInfo>
bufferInfos

List of BufferInfos.

private BufferStrategy
bufferStrategy

BufferStrategy currently being used.

private boolean
disposeBufferOnEnd

Set to true if the bufferInfo needs to be disposed when current paint loop is done.

private static final PlatformLogger
private boolean
painting

Indicates beginPaint has been invoked.

private JComponent
rootJ

Farthest JComponent ancestor for the current paint/copyArea.

private boolean
showing

Indicates we're in the process of showing.

private int
xOffset

Location of component being painted relative to root.

private int
yOffset

Location of component being painted relative to root.

Inherited from javax.swing.RepaintManager.PaintManager:
isRepaintingRootrepaintManager

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
accumulate(int x, int y, int w, int h)

public void
beginPaint()

Overrides javax.swing.RepaintManager.PaintManager.beginPaint.

Invoked prior to any calls to paint or copyArea.

public void
copyArea(JComponent c, Graphics g, int x, int y, int w, int h, int deltaX, int deltaY, boolean clip)

Overrides javax.swing.RepaintManager.PaintManager.copyArea.

Does a copy area on the specified region.

protected void
dispose()

Overrides javax.swing.RepaintManager.PaintManager.dispose.

Cleans up any created BufferStrategies.

private void
public void
doubleBufferingChanged(final JRootPane rootPane)

Overrides javax.swing.RepaintManager.PaintManager.doubleBufferingChanged.

Invoked when the double buffering or useTrueDoubleBuffering changes for a JRootPane.

private void
doubleBufferingChanged0(JRootPane rootPane)

Does the work for doubleBufferingChanged.

public void
endPaint()

Overrides javax.swing.RepaintManager.PaintManager.endPaint.

Invoked to indicate painting has been completed.

private Container
private boolean

Returns:

true if successful, false otherwise.
flushAccumulatedRegion
()

Renders the BufferStrategy to the screen.

private BufferStrategyPaintManager.BufferInfo
getBufferInfo(Container root)

Returns the BufferInfo for the specified root or null if one hasn't been created yet.

public boolean
paint(JComponent paintingComponent, JComponent bufferComponent, Graphics g, int x, int y, int w, int h)

Overrides javax.swing.RepaintManager.PaintManager.paint.

Paints a region of a component

private boolean

Returns:

true if should use buffering per window in painting.
prepare
(JComponent c, Container root, boolean isPaint, int x, int y, int w, int h)

Calculates information common to paint/copyArea.

private void
private void
resetDoubleBufferPerWindow()

Turns off double buffering per window.

public boolean
show(Container c, int x, int y, int w, int h)

Overrides javax.swing.RepaintManager.PaintManager.show.

Shows the specified region of the back buffer.

Inherited from javax.swing.RepaintManager.PaintManager:
isRepaintingRootpaintDoubleBufferedrepaintRoot

Field Detail

accumulatedMaxXback to summary
private int accumulatedMaxX
accumulatedMaxYback to summary
private int accumulatedMaxY
accumulatedXback to summary
private int accumulatedX
accumulatedYback to summary
private int accumulatedY
bsgback to summary
private Graphics bsg

Graphics from the BufferStrategy.

bufferInfoback to summary
private BufferStrategyPaintManager.BufferInfo bufferInfo

BufferInfo corresponding to root.

bufferInfosback to summary
private ArrayList<BufferStrategyPaintManager.BufferInfo> bufferInfos

List of BufferInfos. We don't use a Map primarily because there are typically only a handful of top level components making a Map overkill.

bufferStrategyback to summary
private BufferStrategy bufferStrategy

BufferStrategy currently being used.

disposeBufferOnEndback to summary
private boolean disposeBufferOnEnd

Set to true if the bufferInfo needs to be disposed when current paint loop is done.

LOGGERback to summary
private static final PlatformLogger LOGGER
paintingback to summary
private boolean painting

Indicates beginPaint has been invoked. This is set to true for the life of beginPaint/endPaint pair.

rootJback to summary
private JComponent rootJ

Farthest JComponent ancestor for the current paint/copyArea.

showingback to summary
private boolean showing

Indicates we're in the process of showing. All painting, on the EDT, is blocked while this is true.

xOffsetback to summary
private int xOffset

Location of component being painted relative to root.

yOffsetback to summary
private int yOffset

Location of component being painted relative to root.

Constructor Detail

BufferStrategyPaintManagerback to summary
pack-priv BufferStrategyPaintManager()

Method Detail

accumulateback to summary
private void accumulate(int x, int y, int w, int h)
beginPaintback to summary
public void beginPaint()

Overrides javax.swing.RepaintManager.PaintManager.beginPaint.

Doc from javax.swing.RepaintManager.PaintManager.beginPaint.

Invoked prior to any calls to paint or copyArea.

copyAreaback to summary
public void copyArea(JComponent c, Graphics g, int x, int y, int w, int h, int deltaX, int deltaY, boolean clip)

Overrides javax.swing.RepaintManager.PaintManager.copyArea.

Doc from javax.swing.RepaintManager.PaintManager.copyArea.

Does a copy area on the specified region.

disposeback to summary
protected void dispose()

Overrides javax.swing.RepaintManager.PaintManager.dispose.

Cleans up any created BufferStrategies.

disposeback to summary
private void dispose(List<BufferStrategyPaintManager.BufferInfo> bufferInfos)
doubleBufferingChangedback to summary
public void doubleBufferingChanged(final JRootPane rootPane)

Overrides javax.swing.RepaintManager.PaintManager.doubleBufferingChanged.

Invoked when the double buffering or useTrueDoubleBuffering changes for a JRootPane. If the rootpane is not double buffered, or true double buffering changes we throw out any cache we may have.

doubleBufferingChanged0back to summary
private void doubleBufferingChanged0(JRootPane rootPane)

Does the work for doubleBufferingChanged.

endPaintback to summary
public void endPaint()

Overrides javax.swing.RepaintManager.PaintManager.endPaint.

Doc from javax.swing.RepaintManager.PaintManager.endPaint.

Invoked to indicate painting has been completed.

fetchRootback to summary
private Container fetchRoot(JComponent c)
flushAccumulatedRegionback to summary
private boolean flushAccumulatedRegion()

Renders the BufferStrategy to the screen.

Returns:boolean

true if successful, false otherwise.

getBufferInfoback to summary
private BufferStrategyPaintManager.BufferInfo getBufferInfo(Container root)

Returns the BufferInfo for the specified root or null if one hasn't been created yet.

paintback to summary
public boolean paint(JComponent paintingComponent, JComponent bufferComponent, Graphics g, int x, int y, int w, int h)

Overrides javax.swing.RepaintManager.PaintManager.paint.

Doc from javax.swing.RepaintManager.PaintManager.paint.

Paints a region of a component

prepareback to summary
private boolean prepare(JComponent c, Container root, boolean isPaint, int x, int y, int w, int h)

Calculates information common to paint/copyArea.

Returns:boolean

true if should use buffering per window in painting.

resetAccumulatedback to summary
private void resetAccumulated()
resetDoubleBufferPerWindowback to summary
private void resetDoubleBufferPerWindow()

Turns off double buffering per window.

showback to summary
public boolean show(Container c, int x, int y, int w, int h)

Overrides javax.swing.RepaintManager.PaintManager.show.

Shows the specified region of the back buffer. This will return true if successful, false otherwise. This is invoked on the toolkit thread in response to an expose event.

javax.swing back to summary

private Class BufferStrategyPaintManager.BufferInfo

extends ComponentAdapter
implements WindowListener
Class Inheritance
All Implemented Interfaces
java.awt.event.WindowListener, java.util.EventListener

BufferInfo is used to track the BufferStrategy being used for a particular Component. In addition to tracking the BufferStrategy it will install a WindowListener and ComponentListener. When the component is hidden/iconified the buffer is marked as needing to be completely repainted.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private boolean
private WeakReference<Container>
private WeakReference<BufferStrategy>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
private BufferStrategy
createBufferStrategy()

Creates the BufferStrategy.

private BufferStrategy
createBufferStrategy(Container root, boolean isVsynced)

public void
dispose()

Cleans up and removes any references.

public BufferStrategy
getBufferStrategy(boolean
If true and the BufferStrategy is currently null, one will be created.
create
)

Returns the BufferStrategy.

public boolean
public boolean
public Container
getRoot()

Returns the Root (Window) that this BufferInfo references.

public boolean
hasBufferStrategyChanged()

Returns true if the buffer strategy of the component differs from current buffer strategy.

public boolean
isInSync()

Whether or not the contents of the buffer strategy is in sync with the window.

public void
public void
setInSync(boolean inSync)

public void
setPaintAllOnExpose(boolean paintAllOnExpose)

public void
windowActivated(WindowEvent e)

Implements java.awt.event.WindowListener.windowActivated.

Invoked when the Window is set to be the active Window.

public void
windowClosed(WindowEvent e)

Implements java.awt.event.WindowListener.windowClosed.

Invoked when a window has been closed as the result of calling dispose on the window.

public void
windowClosing(WindowEvent e)

Implements java.awt.event.WindowListener.windowClosing.

Invoked when the user attempts to close the window from the window's system menu.

public void
windowDeactivated(WindowEvent e)

Implements java.awt.event.WindowListener.windowDeactivated.

Invoked when a Window is no longer the active Window.

public void
windowDeiconified(WindowEvent e)

Implements java.awt.event.WindowListener.windowDeiconified.

Invoked when a window is changed from a minimized to a normal state.

public void
windowIconified(WindowEvent e)

Implements java.awt.event.WindowListener.windowIconified.

Invoked when a window is changed from a normal to a minimized state.

public void
windowOpened(WindowEvent e)

Implements java.awt.event.WindowListener.windowOpened.

Invoked the first time a window is made visible.

Inherited from java.awt.event.ComponentAdapter:
componentMovedcomponentResizedcomponentShown

Field Detail

contentsLostDuringExposeback to summary
private boolean contentsLostDuringExpose
inSyncback to summary
private boolean inSync
paintAllOnExposeback to summary
private boolean paintAllOnExpose
rootback to summary
private WeakReference<Container> root
weakBSback to summary
private WeakReference<BufferStrategy> weakBS

Constructor Detail

BufferInfoback to summary
public BufferInfo(Container root)

Method Detail

componentHiddenback to summary
public void componentHidden(ComponentEvent e)

Overrides java.awt.event.ComponentAdapter.componentHidden.

Implements java.awt.event.ComponentListener.componentHidden.

Doc from java.awt.event.ComponentAdapter.componentHidden.

Invoked when the component has been made invisible.

createBufferStrategyback to summary
private BufferStrategy createBufferStrategy()

Creates the BufferStrategy. If the appropriate system property has been set we'll try for flip first and then we'll try for blit.

createBufferStrategyback to summary
private BufferStrategy createBufferStrategy(Container root, boolean isVsynced)
disposeback to summary
public void dispose()

Cleans up and removes any references.

getBufferStrategyback to summary
public BufferStrategy getBufferStrategy(boolean create)

Returns the BufferStrategy. This will return null if the BufferStrategy hasn't been created and create is false, or if there is a problem in creating the BufferStrategy.

Parameters
create:boolean

If true and the BufferStrategy is currently null, one will be created.

getContentsLostDuringExposeback to summary
public boolean getContentsLostDuringExpose()
getPaintAllOnExposeback to summary
public boolean getPaintAllOnExpose()
getRootback to summary
public Container getRoot()

Returns the Root (Window) that this BufferInfo references.

hasBufferStrategyChangedback to summary
public boolean hasBufferStrategyChanged()

Returns true if the buffer strategy of the component differs from current buffer strategy.

isInSyncback to summary
public boolean isInSync()

Whether or not the contents of the buffer strategy is in sync with the window. This is set to true when the root pane paints all, and false when contents are lost/restored.

setContentsLostDuringExposeback to summary
public void setContentsLostDuringExpose(boolean value)
setInSyncback to summary
public void setInSync(boolean inSync)
setPaintAllOnExposeback to summary
public void setPaintAllOnExpose(boolean paintAllOnExpose)
windowActivatedback to summary
public void windowActivated(WindowEvent e)

Implements java.awt.event.WindowListener.windowActivated.

Doc from java.awt.event.WindowListener.windowActivated.

Invoked when the Window is set to be the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

windowClosedback to summary
public void windowClosed(WindowEvent e)

Implements java.awt.event.WindowListener.windowClosed.

Doc from java.awt.event.WindowListener.windowClosed.

Invoked when a window has been closed as the result of calling dispose on the window.

windowClosingback to summary
public void windowClosing(WindowEvent e)

Implements java.awt.event.WindowListener.windowClosing.

Doc from java.awt.event.WindowListener.windowClosing.

Invoked when the user attempts to close the window from the window's system menu.

windowDeactivatedback to summary
public void windowDeactivated(WindowEvent e)

Implements java.awt.event.WindowListener.windowDeactivated.

Doc from java.awt.event.WindowListener.windowDeactivated.

Invoked when a Window is no longer the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

windowDeiconifiedback to summary
public void windowDeiconified(WindowEvent e)

Implements java.awt.event.WindowListener.windowDeiconified.

Doc from java.awt.event.WindowListener.windowDeiconified.

Invoked when a window is changed from a minimized to a normal state.

windowIconifiedback to summary
public void windowIconified(WindowEvent e)

Implements java.awt.event.WindowListener.windowIconified.

Doc from java.awt.event.WindowListener.windowIconified.

Invoked when a window is changed from a normal to a minimized state. For many platforms, a minimized window is displayed as the icon specified in the window's iconImage property.

windowOpenedback to summary
public void windowOpened(WindowEvent e)

Implements java.awt.event.WindowListener.windowOpened.

Doc from java.awt.event.WindowListener.windowOpened.

Invoked the first time a window is made visible.