de.javagl.swogl
Class SwoglContainer

java.lang.Object
  extended by de.javagl.swogl.SwoglContainer

public final class SwoglContainer
extends java.lang.Object

This class is a container for SwoglComponents. It is responsible for the interaction and rendering of the SwoglComponents.


Method Summary
 void add(SwoglComponent swoglComponent)
          Adds the given SwoglComponent to this SwoglContainer
 IntersectionInfo computeIntersectionInfo(java.awt.Point pointInSwoglContainer)
          Compute the closest IntersectionInfo for the given point.
 java.util.List<IntersectionInfo> computeIntersectionInfos(java.awt.Point pointInSwoglContainer)
          Compute the IntersectionInfos for the given point.
 PickingInfo computePickingInfo(java.awt.Point pointInSwoglContainer)
          Compute the PickingInfo for the given point.
 Ray computePickingRay(java.awt.Point pointInSwoglContainer)
          Computes the picking Ray that results from a picking at the given point.
static SwoglContainer create(java.awt.Component visibleComponent, SwoglComponentHandler swoglComponentHandler, PickingRayComputer pickingRayComputer)
          Creates a new, empty SwoglContainer that shows the given visibleComponent.
static SwoglContainer create(java.awt.Component visibleComponent, SwoglSetup swoglSetup)
          Creates a new, empty SwoglContainer that shows the given visibleComponent and obtains the SwoglComponentHandler and PickingRayComputer from the given SwoglSetup.
static SwoglContainer create(SwoglApplication swoglApplication)
          Creates a new, empty SwoglContainer for the given SwoglApplication.
 LayoutManager3D getLayout3D()
          Returns the current LayoutManager3D
 javax.swing.JComponent getMainComponent()
          Returns the main component of this SwoglContainer.
 SwoglComponent getSwoglComponent(int index)
          Returns the SwoglComponent with the given index
 int getSwoglComponentCount()
          Returns the number of SwoglComponents that are currently present in this SwoglContainer
 void remove(int index)
          Removes the SwoglComponent with the given index
 void remove(SwoglComponent swoglComponent)
          Removes the given SwoglComponent from this SwoglContainer
 void removeAll()
          Removes all SwoglComponents
 void repaint()
          Causes a repaint of the visible component of this SwoglContainer.
 void setLayout3D(LayoutManager3D newLayoutManager3D)
          Set the LayoutManager3D that should be used by this SwoglContainer to lay out its SwoglComponents
 void setMouseEventDispatchingConditions(Condition<java.awt.event.MouseEvent> listenerDispatchingCondition, Condition<java.awt.event.MouseEvent> swoglComponentDispatchingCondition)
          Set the conditions for the dispatching of MouseEvents to either the listeners that are attached to the main component of this SwoglContainer, or to the SwoglComponents inside this SwoglContainer.
 void validate3D()
          Will cause the LayoutManager3D of this SwoglContainer to be called in order to update the layout of the SwoglComponents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static SwoglContainer create(SwoglApplication swoglApplication)
Creates a new, empty SwoglContainer for the given SwoglApplication. Finally delegates to create(Component, SwoglComponentHandler, PickingRayComputer).

Parameters:
swoglApplication - The SwoglApplication. May not be null.
Returns:
The SwoglContainer

create

public static SwoglContainer create(java.awt.Component visibleComponent,
                                    SwoglSetup swoglSetup)
Creates a new, empty SwoglContainer that shows the given visibleComponent and obtains the SwoglComponentHandler and PickingRayComputer from the given SwoglSetup. Finally delegates to create(Component, SwoglComponentHandler, PickingRayComputer).

Parameters:
visibleComponent - The visible component. May not be null.
swoglSetup - The SwoglSetup. May not be null.
Returns:
The SwoglContainer

create

public static SwoglContainer create(java.awt.Component visibleComponent,
                                    SwoglComponentHandler swoglComponentHandler,
                                    PickingRayComputer pickingRayComputer)
Creates a new, empty SwoglContainer that shows the given visibleComponent.

Note: When the visibleComponent is a lightweight component (e.g. a GLJPanel instead of a GLCanvas) then the visibleComponent may not have any MouseListeners, MouseMotionListeners or MouseWheelListeners. These listeners should instead be attached directly to the main component of this SwoglContainer.

When a SwoglComponent is added to this SwoglContainer, then the SwoglComponentHandler.handleSwoglComponent(SwoglComponent) method of the given SwoglComponentHandler will be called, and when it is removed, the SwoglComponentHandler.releaseSwoglComponent(SwoglComponent) will be called. The SwoglComponentHandler is thus responsible for maintaining the rendered state of the SwoglComponents.

The given PickingRayComputer will be used to compute the picking ray for the interaction with the SwoglComponents: When a MouseEvent occurs on this SwoglContainer, then the pickingRayComputer will be used to compute the picking ray which will be intersected with the SwoglComponents, and if a SwoglComponent is hit, then the MouseEvent will be passed to the SwoglComponent according to the Conditions that have been specified using setMouseEventDispatchingConditions(Condition, Condition). By default, both conditions are true.

Parameters:
visibleComponent - The visible component. May not be null.
swoglComponentHandler - The SwoglComponentHandler. May not be null.
pickingRayComputer - The picking ray computer. May not be null.
Returns:
The SwoglContainer

getMainComponent

public javax.swing.JComponent getMainComponent()
Returns the main component of this SwoglContainer. This component will only show the visibleComponent (although it will contain other, hidden components)

Returns:
The main component of this SwoglContainer

setMouseEventDispatchingConditions

public void setMouseEventDispatchingConditions(Condition<java.awt.event.MouseEvent> listenerDispatchingCondition,
                                               Condition<java.awt.event.MouseEvent> swoglComponentDispatchingCondition)
Set the conditions for the dispatching of MouseEvents to either the listeners that are attached to the main component of this SwoglContainer, or to the SwoglComponents inside this SwoglContainer. If either of the conditions is 'null', then the negation of the other condition will be used in this place. If both conditions are null, then the conditions are set to the 'true' condition, accepting all events.

Parameters:
listenerDispatchingCondition - The condition that checks whether an event should be dispatched to the listeners that are attached to the main component.
swoglComponentDispatchingCondition - The condition that checks whether an event should be dispatched to the SwoglComponents

computePickingRay

public Ray computePickingRay(java.awt.Point pointInSwoglContainer)
Computes the picking Ray that results from a picking at the given point. The direction of the returned ray is normalized.

Parameters:
pointInSwoglContainer - The point inside this SwoglContainer
Returns:
The picking ray

computeIntersectionInfos

public java.util.List<IntersectionInfo> computeIntersectionInfos(java.awt.Point pointInSwoglContainer)
Compute the IntersectionInfos for the given point. A picking ray will be computed and intersected with all SwoglComponents. For each intersection, an IntersectionInfo will be created. An unmodifiable (possibly empty) list of all IntersectionInfos will be returned. The list will contain the IntersectionInfos ordered by their distance along the picking ray, with the closest intersection first.

Parameters:
pointInSwoglContainer - The point inside this SwoglContainer
Returns:
The resulting IntersectionInfos

computeIntersectionInfo

public IntersectionInfo computeIntersectionInfo(java.awt.Point pointInSwoglContainer)
Compute the closest IntersectionInfo for the given point. A picking ray will be computed and intersected with all SwoglComponents. If the ray intersects at least one SwoglComponent, then the IntersectionInfo for the closest intersection will be returned. Otherwise, null will be returned.

Parameters:
pointInSwoglContainer - The point inside this SwoglContainer
Returns:
The closest IntersectionInfo, or null

computePickingInfo

public PickingInfo computePickingInfo(java.awt.Point pointInSwoglContainer)
Compute the PickingInfo for the given point. A picking ray will be computed and intersected with all SwoglComponents. If at least one SwoglComponent is hit by the ray, then the PickingInfo describing the closest hit point will be returned.

Parameters:
pointInSwoglContainer - The point inside this SwoglContainer
Returns:
The resulting PickingInfo, or null

setLayout3D

public void setLayout3D(LayoutManager3D newLayoutManager3D)
Set the LayoutManager3D that should be used by this SwoglContainer to lay out its SwoglComponents

Parameters:
newLayoutManager3D - The LayoutManager3D to use

getLayout3D

public LayoutManager3D getLayout3D()
Returns the current LayoutManager3D

Returns:
The current LayoutManager3D

validate3D

public void validate3D()
Will cause the LayoutManager3D of this SwoglContainer to be called in order to update the layout of the SwoglComponents. Will do nothing if there currently is no layout manager set.

This method may be called from any thread.


add

public void add(SwoglComponent swoglComponent)
Adds the given SwoglComponent to this SwoglContainer

Parameters:
swoglComponent - The SwoglComponent to add

remove

public void remove(SwoglComponent swoglComponent)
Removes the given SwoglComponent from this SwoglContainer

Parameters:
swoglComponent - The SwoglComponent to remove

remove

public void remove(int index)
Removes the SwoglComponent with the given index

Parameters:
index - The index of the SwoglComponent to remove

removeAll

public void removeAll()
Removes all SwoglComponents


getSwoglComponentCount

public int getSwoglComponentCount()
Returns the number of SwoglComponents that are currently present in this SwoglContainer

Returns:
The number of SwoglComponents in this SwoglContainer

getSwoglComponent

public SwoglComponent getSwoglComponent(int index)
Returns the SwoglComponent with the given index

Parameters:
index - The index of the SwoglComponent
Returns:
The SwoglComponent with the given index

repaint

public void repaint()
Causes a repaint of the visible component of this SwoglContainer.