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 aFrameBufferis put there by calling our rendering algorithms.Each instance of
FrameBufferPanelhas a reference to aFrameBufferobject and theFrameBufferobject determines the (preferred) dimensions of theFrameBufferPanel.A
FrameBufferPanelshould be instantiated by an application that uses our renderer. The application should initialize aSceneobject with appropriate models and geometry. The application should then render theSceneinto theFrameBufferobject contained in theFrameBufferPanel.This class is meant to be instantiated as a sub-panel of a
JFrame. TheJFramemay or may not implement event listeners. If theJFramedoes implement event listeners, then the event listeners can make our renderer interactive.When a GUI event happens, any implemented event listener should update this
FrameBufferPanelby modifying aSceneobject appropriately and then having our renderer render theSceneobject 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 anImagethat will be drawn on theGraphicscontext of theFrameBufferPanel(which is aJPanel). This will display theImage, which holds theFrameBuffer's contents, in theJPanelwithin aJFrame's window.This panel may be resizeable. When this panel resizes, its
FrameBufferobject will also need to resize. ButFrameBufferobjects cannot be resized. So each time this panel resizes, a newFrameBufferobject needs to be created. TheComponentListener.componentResized(java.awt.event.ComponentEvent)event handler from theComponentListenerinterface should instantiate a newFrameBufferobject with the appropriate dimensions and then call this object'ssetFrameBuffer(renderer.framebuffer.FrameBuffer)method and pass it a reference to the newFrameBufferobject.- 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 FrameBuffergetFrameBuffer()Accessor method for theFrameBuffercurrently being used as the source for theImagepainted on thisJPanel.DimensiongetPreferredSize()protected voidpaintComponent(Graphics g)voidsetFrameBuffer(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 initialFrameBufferused by thisJPanelfbHeight- height for the initialFrameBufferused by thisJPanel
-
FrameBufferPanel
public FrameBufferPanel(int fbWidth, int fbHeight, Color bgColor)
- Parameters:
fbWidth- width for the initialFrameBufferused by thisJPanelfbHeight- height for the initialFrameBufferused by thisJPanelbgColor- backgroundColorfor the initialFrameBufferused by thisJPanel
-
-
Method Detail
-
getPreferredSize
public Dimension getPreferredSize()
- Overrides:
getPreferredSizein classJComponent
-
paintComponent
protected void paintComponent(Graphics g)
- Overrides:
paintComponentin classJComponent
-
getFrameBuffer
public FrameBuffer getFrameBuffer()
Accessor method for theFrameBuffercurrently being used as the source for theImagepainted on thisJPanel.- Returns:
- a reference to the
FrameBufferowned by thisJPanel
-
setFrameBuffer
public void setFrameBuffer(FrameBuffer fb)
Change theFrameBufferbeing used as the source for theImagepainted on thisJPanel.This will usually be in response to a call to the componentResized() event handler.
- Parameters:
fb- newFrameBufferobject for thisJPanel
-
-