Class FrameBufferPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- renderer.framebuffer.FrameBufferPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public final class FrameBufferPanel extends JPanel
This class is an interface between our renderer and the Java GUI system. This class allows our rendering code to be used as the primary renderer for Java programs. That is, this class allows us to write Java programs that use our renderer instead of the renderer built into Java's GUI library. Of course, our renderer will be much slower than the one built into Java (which uses the computer's GPU).A
FrameBufferPanel
"is a"JPanel
. AFrameBufferPanel
"has a"FrameBuffer
. And aFrameBuffer
"has a" array of pixel data. The pixel data in aFrameBuffer
is put there by calling our rendering algorithms.Each instance of
FrameBufferPanel
has a reference to aFrameBuffer
object and theFrameBuffer
object determines the (preferred) dimensions of theFrameBufferPanel
.A
FrameBufferPanel
should be instantiated by an application that uses our renderer. The application should initialize aScene
object with appropriate models and geometry. The application should then render theScene
into theFrameBuffer
object contained in theFrameBufferPanel
.This class is meant to be instantiated as a sub-panel of a
JFrame
. TheJFrame
may or may not implement event listeners. If theJFrame
does implement event listeners, then the event listeners can make our renderer interactive.When a GUI event happens, any implemented event listener should update this
FrameBufferPanel
by modifying aScene
object appropriately and then having our renderer render theScene
object into this object'sFrameBuffer
. When the renderer is done updating theFrameBuffer
, the event listener should call this object'sComponent.repaint()
method, which will lead to the calling of this object'spaintComponent(java.awt.Graphics)
method, which will pass theFrameBuffer
's pixel data to anImage
that will be drawn on theGraphics
context of theFrameBufferPanel
(which is aJPanel
). This will display theImage
, which holds theFrameBuffer
's contents, in theJPanel
within aJFrame
's window.This panel may be resizeable. When this panel resizes, its
FrameBuffer
object will also need to resize. ButFrameBuffer
objects cannot be resized. So each time this panel resizes, a newFrameBuffer
object needs to be created. TheComponentListener.componentResized(java.awt.event.ComponentEvent)
event handler from theComponentListener
interface should instantiate a newFrameBuffer
object with the appropriate dimensions and then call this object'ssetFrameBuffer(renderer.framebuffer.FrameBuffer)
method and pass it a reference to the newFrameBuffer
object.- 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
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
accessibleContext, 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
Constructors Constructor Description FrameBufferPanel(int fbWidth, int fbHeight)
FrameBufferPanel(int fbWidth, int fbHeight, Color bgColor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FrameBuffer
getFrameBuffer()
Accessor method for theFrameBuffer
currently being used as the source for theImage
painted on thisJPanel
.Dimension
getPreferredSize()
protected void
paintComponent(Graphics g)
void
setFrameBuffer(FrameBuffer fb)
-
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, 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, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, 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, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, list, list, paintComponents, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, list, list, list, paintAll, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Constructor Detail
-
FrameBufferPanel
public FrameBufferPanel(int fbWidth, int fbHeight)
- Parameters:
fbWidth
- width for the initialFrameBuffer
used by thisJPanel
fbHeight
- height for the initialFrameBuffer
used by thisJPanel
-
FrameBufferPanel
public FrameBufferPanel(int fbWidth, int fbHeight, Color bgColor)
- Parameters:
fbWidth
- width for the initialFrameBuffer
used by thisJPanel
fbHeight
- height for the initialFrameBuffer
used by thisJPanel
bgColor
- backgroundColor
for the initialFrameBuffer
used by thisJPanel
-
-
Method Detail
-
getPreferredSize
public Dimension getPreferredSize()
- Overrides:
getPreferredSize
in classJComponent
-
paintComponent
protected void paintComponent(Graphics g)
- Overrides:
paintComponent
in classJComponent
-
getFrameBuffer
public FrameBuffer getFrameBuffer()
Accessor method for theFrameBuffer
currently being used as the source for theImage
painted on thisJPanel
.- Returns:
- a reference to the
FrameBuffer
owned by thisJPanel
-
setFrameBuffer
public void setFrameBuffer(FrameBuffer fb)
Change theFrameBuffer
being used as the source for theImage
painted on thisJPanel
.This will usually be in response to a call to the componentResized() event handler.
- Parameters:
fb
- newFrameBuffer
object for thisJPanel
-
-