Class DrawingPanel3D

All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Printable, Serializable, EventListener, Accessible, Renderable, DrawingPanel3D, InteractionSource

public class DrawingPanel3D extends JPanel implements Renderable, DrawingPanel3D, Printable, ActionListener

Title: DrawingPanel3D

Description: The simple3D implementation of a DrawingPanel3D.

Interaction: The panel has only one target, the panel itself. If enabled, the panel issues MOUSE_ENTER, MOUSE_EXIT, MOUSE_MOVED, and MOUSE_DRAGGED InteractionEvents with target=null. When the ALT key is held, the panel also issues MOUSE_PRESSED, MOUSE_DRAGGED (again), and MOUSE_RELEASED InteractionEvents. In this second case, the getInfo() method of the event returns a double[3] with the coordinates of the point selected.

Even if the panel is disabled, the panel can be panned, zoomed and (in 3D modes) rotated and the elements in it can be enabled.

The interaction capabilities are not XML serialized.

Copyright: Open Source Physics project

Version:
June 2005
Author:
Francisco Esquembre
See Also:
  • Field Details

  • Constructor Details

    • DrawingPanel3D

      public DrawingPanel3D()
      Constructor DrawingPanel3D
  • Method Details

    • actionPerformed

      public void actionPerformed(ActionEvent evt)
      Performs an action for the update timer by rendering a new background image
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      evt -
    • paintComponent

      public void paintComponent(Graphics g)
      Paints the component by copying the offscreen image into the graphics context.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - Graphics
    • invalidate

      public void invalidate()
      Invalidates this component. This component and all parents above it are marked as needing to be laid out. This method can be called often, so it needs to execute quickly.
      Overrides:
      invalidate in class Container
      Since:
      JDK1.0
      See Also:
    • render

      public BufferedImage render(BufferedImage image)
      Description copied from interface: Renderable
      Renders a representation of the object onto an image.
      Specified by:
      render in interface DrawingPanel3D
      Specified by:
      render in interface Renderable
      Parameters:
      image - Image
      Returns:
      the image buffer
    • render

      public BufferedImage render()
      Description copied from interface: Renderable
      Renders a representation of the object onscreen.
      Specified by:
      render in interface DrawingPanel3D
      Specified by:
      render in interface Renderable
      Returns:
      BufferedImage the generated image
    • getComponent

      public Component getComponent()
      Description copied from interface: DrawingPanel3D
      Getting the pointer to the real JPanel in it
      Specified by:
      getComponent in interface DrawingPanel3D
      Returns:
      JFrame
    • setBackgroundImage

      public void setBackgroundImage(String _imageFile)
      Description copied from interface: DrawingPanel3D
      Sets the background image
      Specified by:
      setBackgroundImage in interface DrawingPanel3D
    • getBackgroundImage

      public String getBackgroundImage()
      Description copied from interface: DrawingPanel3D
      Returns the background image
      Specified by:
      getBackgroundImage in interface DrawingPanel3D
    • setPreferredMinMax

      public void setPreferredMinMax(double minX, double maxX, double minY, double maxY, double minZ, double maxZ)
      Description copied from interface: DrawingPanel3D
      Sets the preferred extrema for the panel. This resets the camera of the panel to its default.
      Specified by:
      setPreferredMinMax in interface DrawingPanel3D
      Parameters:
      minX - double
      maxX - double
      minY - double
      maxY - double
      minZ - double
      maxZ - double
      See Also:
    • getPreferredMinX

      public final double getPreferredMinX()
      Description copied from interface: DrawingPanel3D
      Gets the preferred minimum in the X coordinate
      Specified by:
      getPreferredMinX in interface DrawingPanel3D
      Returns:
      double
    • getPreferredMaxX

      public final double getPreferredMaxX()
      Description copied from interface: DrawingPanel3D
      Gets the preferred maximum in the X coordinate
      Specified by:
      getPreferredMaxX in interface DrawingPanel3D
      Returns:
      double
    • getPreferredMinY

      public final double getPreferredMinY()
      Description copied from interface: DrawingPanel3D
      Gets the preferred minimum in the Y coordinate
      Specified by:
      getPreferredMinY in interface DrawingPanel3D
      Returns:
      double
    • getPreferredMaxY

      public final double getPreferredMaxY()
      Description copied from interface: DrawingPanel3D
      Gets the preferred maximum in the Y coordinate
      Specified by:
      getPreferredMaxY in interface DrawingPanel3D
      Returns:
      double
    • getPreferredMinZ

      public final double getPreferredMinZ()
      Description copied from interface: DrawingPanel3D
      Gets the preferred minimum in the Z coordinate
      Specified by:
      getPreferredMinZ in interface DrawingPanel3D
      Returns:
      double
    • getPreferredMaxZ

      public final double getPreferredMaxZ()
      Description copied from interface: DrawingPanel3D
      Gets the preferred maximum in the Z coordinate
      Specified by:
      getPreferredMaxZ in interface DrawingPanel3D
      Returns:
      double
    • zoomToFit

      public void zoomToFit()
      Description copied from interface: DrawingPanel3D
      Sets the preferred min and max in each dimension so that all elements currently in the panel are visible.
      Specified by:
      zoomToFit in interface DrawingPanel3D
    • setSquareAspect

      public void setSquareAspect(boolean square)
      Description copied from interface: DrawingPanel3D
      Whether the panel should try to keep a square aspect. Default value is true.
      Specified by:
      setSquareAspect in interface DrawingPanel3D
      Parameters:
      square - boolean
    • isSquareAspect

      public boolean isSquareAspect()
      Description copied from interface: DrawingPanel3D
      Whether the panel tries to keep a square aspect.
      Specified by:
      isSquareAspect in interface DrawingPanel3D
      Returns:
      boolean
    • getVisualizationHints

      public VisualizationHints getVisualizationHints()
      Description copied from interface: DrawingPanel3D
      Provides the list of visualization hints that the panel uses to display the 3D scene
      Specified by:
      getVisualizationHints in interface DrawingPanel3D
      Returns:
      VisualizationHints
      See Also:
    • getCamera

      public Camera getCamera()
      Description copied from interface: DrawingPanel3D
      Provides the Camera object used to project the scene in 3D modes.
      Specified by:
      getCamera in interface DrawingPanel3D
      Returns:
      Camera
      See Also:
    • getVideoTool

      public VideoTool getVideoTool()
      Gets the video capture tool. May be null.
      Specified by:
      getVideoTool in interface DrawingPanel3D
      Returns:
      the video capture tool
    • setVideoTool

      public void setVideoTool(VideoTool videoCap)
      Sets the video capture tool. May be set to null.
      Specified by:
      setVideoTool in interface DrawingPanel3D
      Parameters:
      videoCap - the video capture tool
    • addElement

      public void addElement(Element element)
      Description copied from interface: DrawingPanel3D
      Adds an Element to this DrawingPanel3D.
      Specified by:
      addElement in interface DrawingPanel3D
      Parameters:
      element - Element
      See Also:
    • removeElement

      public void removeElement(Element element)
      Description copied from interface: DrawingPanel3D
      Removes an Element from this DrawingPanel3D
      Specified by:
      removeElement in interface DrawingPanel3D
      Parameters:
      element - Element
      See Also:
    • removeAllElements

      public void removeAllElements()
      Description copied from interface: DrawingPanel3D
      Removes all Elements from this DrawingPanel3D
      Specified by:
      removeAllElements in interface DrawingPanel3D
      See Also:
    • getElements

      public List<Element> getElements()
      Description copied from interface: DrawingPanel3D
      Gets the (cloned) list of Elements. (Should be synchronized.)
      Specified by:
      getElements in interface DrawingPanel3D
      Returns:
      cloned list
    • setScaleFactor

      public void setScaleFactor(double factorX, double factorY, double factorZ)
      Description copied from interface: DrawingPanel3D
      Sets the scale factor of the scene in X,Y,Z axis.
      Specified by:
      setScaleFactor in interface DrawingPanel3D
      Parameters:
      factorX - double
      factorY - double
      factorZ - double
    • getScaleFactorX

      public double getScaleFactorX()
      Description copied from interface: DrawingPanel3D
      Gets the scale factor in the X axis
      Specified by:
      getScaleFactorX in interface DrawingPanel3D
      Returns:
      double
    • getScaleFactorY

      public double getScaleFactorY()
      Description copied from interface: DrawingPanel3D
      Gets the scale factor in the Y axis
      Specified by:
      getScaleFactorY in interface DrawingPanel3D
      Returns:
      double
    • getScaleFactorZ

      public double getScaleFactorZ()
      Description copied from interface: DrawingPanel3D
      Gets the scale factor in the Z axis
      Specified by:
      getScaleFactorZ in interface DrawingPanel3D
      Returns:
      double
    • setAxesMode

      public void setAxesMode(int mode)
      Description copied from interface: DrawingPanel3D
      Sets the axes mode
      Specified by:
      setAxesMode in interface DrawingPanel3D
      Parameters:
      mode - int
    • getAxesMode

      public int getAxesMode()
      Description copied from interface: DrawingPanel3D
      Returns the axes mode
      Specified by:
      getAxesMode in interface DrawingPanel3D
    • setMessage

      public void setMessage(String msg)
      Shows a message in a yellow text box in the lower right hand corner.
      Parameters:
      msg -
    • setMessage

      public void setMessage(String msg, int location)
      Shows a message in a yellow text box. The location must be one of the following:
      • DrawingPanel3D.BOTTOM_LEFT;
      • DrawingPanel3D.BOTTOM_RIGHT;
      • DrawingPanel3D.TOP_RIGHT;
      • DrawingPanel3D.TOP_LEFT;
      Parameters:
      msg -
      location -
    • getInteractionTarget

      public InteractionTarget getInteractionTarget(int target)
      Description copied from interface: InteractionSource
      Gives access to one of the targets of this source. Sources should document the list of their available targets.
      Specified by:
      getInteractionTarget in interface InteractionSource
      Parameters:
      target - An integer number that identifies the target in the source.
      Returns:
      InteractionTarget
    • addInteractionListener

      public void addInteractionListener(InteractionListener listener)
      Description copied from interface: InteractionSource
      Adds the specified interaction listener to receive interaction events to any of its targets from this source.
      Specified by:
      addInteractionListener in interface InteractionSource
      Parameters:
      listener - An object that implements the InteractionListener interface
      See Also:
    • removeInteractionListener

      public void removeInteractionListener(InteractionListener listener)
      Description copied from interface: InteractionSource
      Removes the specified interaction listener
      Specified by:
      removeInteractionListener in interface InteractionSource
      See Also:
    • print

      public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException
      Specified by:
      print in interface Printable
      Throws:
      PrinterException
    • setLightEnabled

      public void setLightEnabled(boolean _state, int nlight)
      Description copied from interface: DrawingPanel3D
      Enable disable a light
      Specified by:
      setLightEnabled in interface DrawingPanel3D
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an XML.ObjectLoader to save and load object data.
      Returns:
      the XML.ObjectLoader