Class Item3D
- Direct Known Subclasses:
Axes3D,Cube,Cylinder,GlobeCountryLines3D,LabelSet3D,Line3D,PointSet3D,PolyLine3D,Quad3D,ScatterPlot3D,Sphere,Triangle3D
Panel3D.
Item3D is the 3D analogue of MDI's 2D AItem: a self-contained
drawable that owns its own appearance properties and can be organized into a
parent/child tree so a group of items (e.g. the axes of a coordinate frame,
or the components of a composite shape) can be shown, hidden, or disposed as
a unit.
Properties
Appearance is stored as a small Properties-backed key/value bag
(LINE_WIDTH, FILLCOLOR, FILLALPHA, LINECOLOR,
LINEALPHA, TEXT_COLOR, FONT), accessed through the
typed get*/set* convenience methods. Any property that has not
been explicitly set falls back to a class-wide default.
Drawing and disposal
Subclasses implement draw(GLAutoDrawable) for their own custom
rendering, and only that GL-thread-bound method should touch the GL context.
drawItem(GLAutoDrawable) and disposeItem(GLAutoDrawable) are
called by Panel3D and are final: they invoke draw(GLAutoDrawable)/dispose(GLAutoDrawable) on this item and then
recurse into every visible child, so a subtree draws or releases its GL
resources with a single call from the panel.
Thread safety
isVisible()/setVisible(boolean) and the child list are safe
to touch from threads other than the GL rendering thread: visibility is
volatile, and addChild(Item3D)/removeChild(Item3D)
synchronize on this, the same monitor used to snapshot the child list
before iterating it during draw/dispose. Actual GL calls inside draw(GLAutoDrawable) still must only happen on the GL thread.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Panel3Dstatic final Stringproperty for fill alpha.static final Stringproperty for fill color.static final Stringproperty string for font.static final Stringproperty for line width.static final Stringproperty for line alpha.static final Stringproperty for line or frame color.static final Stringproperty for text color. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a child item.protected voidSet the default propertiesprotected voiddispose(com.jogamp.opengl.GLAutoDrawable drawable) Override to release any GL resources this item owns (textures, display lists, text renderers, etc.).final voiddisposeItem(com.jogamp.opengl.GLAutoDrawable drawable) Called by the panel3D when its GL context is being torn down.abstract voiddraw(com.jogamp.opengl.GLAutoDrawable drawable) The custom drawing methodfinal voiddrawItem(com.jogamp.opengl.GLAutoDrawable drawable) Called by the panel3D.Get a 3D propertyGet a list of the item's children, can benullGet an AWT color 3D propertyintConvenience method to get the fill alpha for this itemConvenience method to get the fill color for this itemfloatGet a float 3D propertygetFont()Convenience method to get the fontr for this itemGet an a Font 3D propertyintGet a integer 3D propertyintConvenience method to get the line (frame) alpha for this itemConvenience method to get the line (and frame)color for this itemfloatConvenience method to get the line width for this itemGet the parent Panel3D objectGet the parent item (might be null)float[]A representative point for transparent sorting, in world coordinates.Get a String 3D propertyConvenience method to get the text color for this itembooleanChecks whether we want the item to be drawn.voidset a propertyvoidremoveChild(Item3D item) Remove a child itemprotected ColorsetAlphaOfColor(Color color, int alpha) Set the alpha of a color.voidsetFillAlpha(int alpha) Convenience method to set the fill alphavoidsetFillColor(Color color) Convenience method to set the fill colorvoidConvenience method to set the fontvoidsetLineAlpha(int alpha) Convenience method to set the line (frame) alphavoidsetLineColor(Color color) Convenience method to set the line (frame) colorvoidsetLineWidth(float lineWidth) Convenience method to set the line widthvoidsetTextColor(Color textColor) Convenience method to set the text colorvoidsetVisible(boolean visible) Controls whether we want the item to be drawn.
-
Field Details
-
LINE_WIDTH
property for line width. Default is 1f- See Also:
-
FILLCOLOR
property for fill color. Default is defined below- See Also:
-
FILLALPHA
property for fill alpha. Default is defined below- See Also:
-
LINECOLOR
property for line or frame color. Default is defined below- See Also:
-
LINEALPHA
property for line alpha. Default is defined below- See Also:
-
TEXT_COLOR
property for text color. Default is defined below- See Also:
-
FONT
property string for font. Default is defined below- See Also:
-
_panel3D
-
-
Constructor Details
-
Item3D
Create a 3D item for use on a Panel3D.- Parameters:
panel3D- the owner panel 3D object
-
-
Method Details
-
defaultProperties
protected void defaultProperties()Set the default properties -
put
set a property- Parameters:
key- the keyvalue- the value
-
drawItem
public final void drawItem(com.jogamp.opengl.GLAutoDrawable drawable) Called by the panel3D. Do not overrwrite.- Parameters:
drawable- the OpenGL drawable
-
draw
public abstract void draw(com.jogamp.opengl.GLAutoDrawable drawable) The custom drawing method- Parameters:
drawable- the OpenGL drawable
-
disposeItem
public final void disposeItem(com.jogamp.opengl.GLAutoDrawable drawable) Called by the panel3D when its GL context is being torn down. Do not overwrite.Releases this item's own GL resources via
dispose(GLAutoDrawable), then recurses into children so a subtree is fully released with one call.- Parameters:
drawable- the OpenGL drawable being disposed
-
dispose
protected void dispose(com.jogamp.opengl.GLAutoDrawable drawable) Override to release any GL resources this item owns (textures, display lists, text renderers, etc.).The default implementation does nothing. Items that lazily allocate GL-backed resources — for example a JOGL
TextRenderer— should override this to release them and null out the field so a subsequentdrawcall (if any) lazily recreates it.- Parameters:
drawable- the OpenGL drawable being disposed
-
get
Get a 3D property- Parameters:
key- the name of the property- Returns:
- the object corresponding to that key, or null
- Throws:
Bad3DPropertyException- if the property is missing or not of the expected type
-
getString
Get a String 3D property- Parameters:
key- the name of the property- Returns:
- the String corresponding to that key, or null
- Throws:
Bad3DPropertyException- if the property is missing or not of the expected type
-
getColor
Get an AWT color 3D property- Parameters:
key- the name of the property- Returns:
- the (AWT) Color corresponding to that key, or null
- Throws:
Bad3DPropertyException- if the property is missing or not of the expected type
-
getFont
Get an a Font 3D property- Parameters:
key- the name of the property- Returns:
- the Font corresponding to that key, or null
- Throws:
Bad3DPropertyException- if the property is missing or not of the expected type
-
getInt
Get a integer 3D property- Parameters:
key- the name of the property- Returns:
- the Integer corresponding to that key, or null
- Throws:
Bad3DPropertyException- if the property is missing or not of the expected type
-
getFloat
Get a float 3D property- Parameters:
key- the name of the property- Returns:
- the Float corresponding to that key, or null
- Throws:
Bad3DPropertyException- if the property is missing or not of the expected type
-
getLineWidth
public float getLineWidth()Convenience method to get the line width for this item- Returns:
- the line width. (Default is 1f)
-
setLineWidth
public void setLineWidth(float lineWidth) Convenience method to set the line width- Parameters:
lineWidth- the line width.
-
getFillColor
Convenience method to get the fill color for this item- Returns:
- the fill color.
-
getFillAlpha
public int getFillAlpha()Convenience method to get the fill alpha for this item- Returns:
- the fill alpha.
-
getLineAlpha
public int getLineAlpha()Convenience method to get the line (frame) alpha for this item- Returns:
- the line (frame) alpha.
-
getLineColor
Convenience method to get the line (and frame)color for this item- Returns:
- the line (frame) color.
-
getTextColor
Convenience method to get the text color for this item- Returns:
- the text color.
-
getFont
Convenience method to get the fontr for this item- Returns:
- the font.
-
setFillColor
Convenience method to set the fill color- Parameters:
color- the fill color.
-
setLineColor
Convenience method to set the line (frame) color- Parameters:
color- the line (frame) color.
-
setFillAlpha
public void setFillAlpha(int alpha) Convenience method to set the fill alpha- Parameters:
alpha- the fill alpha [0..255].
-
setLineAlpha
public void setLineAlpha(int alpha) Convenience method to set the line (frame) alpha- Parameters:
alpha- the line (frame) alpha [0..255].
-
setTextColor
Convenience method to set the text color- Parameters:
textColor- the text color.
-
setFont
Convenience method to set the font- Parameters:
font- the text font.
-
setVisible
public void setVisible(boolean visible) Controls whether we want the item to be drawn. That is, drawing is skipped if this is false. Whether or not the item is actually visible when drawn is not controlled by this flag. This does NOT initiate a redraw,- Parameters:
visible- the visibility flag.
-
isVisible
public boolean isVisible()Checks whether we want the item to be drawn. That is, drawing is skipped if this is false. Whether or not the item is actually visible when drawn is not controlled by this flag.- Returns:
- the visibility flag.
-
getChildren
Get a list of the item's children, can benull- Returns:
- a list of the item's children
-
getParent
Get the parent item (might be null)- Returns:
- the parent
-
addChild
Add a child item.The remove-then-add (to move an existing child to the end) is performed under
synchronized(this)so it is atomic with respect tochildrenSnapshot()— a concurrent drawer/disposer can never observe the child transiently missing.- Parameters:
item- the child item
-
removeChild
Remove a child item- Parameters:
item- the chold item
-
getPanel3D
Get the parent Panel3D object- Returns:
- the parent Panel3D object
-
setAlphaOfColor
Set the alpha of a color. If it already has the given alpha it just returns the color. If not, it makes a new color with the same RGB components and the new alpha- Parameters:
color- the color to changealpha- the alpha [0..255] 0 is transparent, 255 is opaque- Returns:
- the color
-
getSortPoint
public float[] getSortPoint()A representative point for transparent sorting, in world coordinates. Default is origin. Override in items with a natural center (Sphere, Cube, Cylinder, etc.).- Returns:
- the sort point as
[x, y, z]
-