]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/threedee/Java3DWindow.java
Version 8, September 2009
[GpsPrune.git] / tim / prune / threedee / Java3DWindow.java
index e65d53de50c2f70f1aca7492e5489dad343f4e11..0bde564c373fe45199aca872bdbcf49f18cf97de 100644 (file)
@@ -1,12 +1,14 @@
 package tim.prune.threedee;
 
-import java.awt.BorderLayout;
 import java.awt.FlowLayout;
+import java.awt.BorderLayout;
 import java.awt.Font;
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsEnvironment;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 import java.awt.geom.GeneralPath;
 
 import javax.media.j3d.AmbientLight;
@@ -40,7 +42,7 @@ import com.sun.j3d.utils.geometry.Cylinder;
 import com.sun.j3d.utils.geometry.Sphere;
 import com.sun.j3d.utils.universe.SimpleUniverse;
 
-import tim.prune.App;
+import tim.prune.FunctionLibrary;
 import tim.prune.I18nManager;
 import tim.prune.data.Altitude;
 import tim.prune.data.Track;
@@ -51,10 +53,10 @@ import tim.prune.data.Track;
  */
 public class Java3DWindow implements ThreeDWindow
 {
-       private App _app = null;
        private Track _track = null;
        private JFrame _parentFrame = null;
        private JFrame _frame = null;
+       private ThreeDModel _model = null;
        private OrbitBehavior _orbit = null;
        private int _altitudeCap = ThreeDModel.MINIMUM_ALTITUDE_CAP;
 
@@ -64,19 +66,16 @@ public class Java3DWindow implements ThreeDWindow
        // Constants
        private static final double INITIAL_Y_ROTATION = -25.0;
        private static final double INITIAL_X_ROTATION = 15.0;
-       private static final int INITIAL_ALTITUDE_CAP = 500;
        private static final String CARDINALS_FONT = "Arial";
        private static final int MAX_TRACK_SIZE = 2500; // threshold for warning
 
 
        /**
         * Constructor
-        * @param inApp App object to use for callbacks
         * @param inFrame parent frame
         */
-       public Java3DWindow(App inApp, JFrame inFrame)
+       public Java3DWindow(JFrame inFrame)
        {
-               _app = inApp;
                _parentFrame = inFrame;
        }
 
@@ -131,7 +130,7 @@ public class Java3DWindow implements ThreeDWindow
                {
                        if (JOptionPane.showOptionDialog(_frame,
                                        I18nManager.getText("dialog.exportpov.warningtracksize"),
-                                       I18nManager.getText("dialog.exportpov.title"), JOptionPane.OK_CANCEL_OPTION,
+                                       I18nManager.getText("function.exportpov"), JOptionPane.OK_CANCEL_OPTION,
                                        JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1])
                                == JOptionPane.OK_OPTION)
                        {
@@ -169,11 +168,12 @@ public class Java3DWindow implements ThreeDWindow
                _frame = new JFrame(I18nManager.getText("dialog.3d.title"));
                _frame.getContentPane().setLayout(new BorderLayout());
                _frame.getContentPane().add(canvas, BorderLayout.CENTER);
+               _frame.setIconImage(_parentFrame.getIconImage());
                // Make panel for render, close buttons
                JPanel panel = new JPanel();
                panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
                // Add callback button for render
-               JButton renderButton = new JButton(I18nManager.getText("menu.file.exportpov"));
+               JButton renderButton = new JButton(I18nManager.getText("function.exportpov"));
                renderButton.addActionListener(new ActionListener()
                {
                        /** Render button pressed */
@@ -185,6 +185,19 @@ public class Java3DWindow implements ThreeDWindow
                                }
                        }});
                panel.add(renderButton);
+               // Display coordinates of lat/long lines of 3d graph in separate dialog
+               JButton showLinesButton = new JButton(I18nManager.getText("button.showlines"));
+               showLinesButton.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e)
+                       {
+                               double[] latLines = _model.getLatitudeLines();
+                               double[] lonLines = _model.getLongitudeLines();
+                               LineDialog dialog = new LineDialog(_frame, latLines, lonLines);
+                               dialog.showDialog();
+                       }
+               });
+               panel.add(showLinesButton);
+               // Close button
                JButton closeButton = new JButton(I18nManager.getText("button.close"));
                closeButton.addActionListener(new ActionListener()
                {
@@ -194,20 +207,38 @@ public class Java3DWindow implements ThreeDWindow
                                _frame.dispose();
                                _frame = null;
                                _orbit = null;
-                       }});
+                       }
+               });
                panel.add(closeButton);
                _frame.getContentPane().add(panel, BorderLayout.SOUTH);
                _frame.setSize(500, 350);
                _frame.pack();
+               // Add a listener to clean up when window closed
+               _frame.addWindowListener(new WindowAdapter() {
+                       public void windowClosing(WindowEvent e)
+                       {
+                               dispose();
+                       }
+               });
 
                // show frame
-               _frame.show();
+               _frame.setVisible(true);
                if (_frame.getState() == JFrame.ICONIFIED)
                {
                        _frame.setState(JFrame.NORMAL);
                }
        }
 
+       /**
+        * Dispose of the frame and its resources
+        */
+       public void dispose()
+       {
+               if (_frame != null) {
+                       _frame.dispose();
+                       _frame = null;
+               }
+       }
 
        /**
         * Create the whole scenery from the given track
@@ -241,8 +272,6 @@ public class Java3DWindow implements ThreeDWindow
                // Base plane
                Appearance planeAppearance = null;
                Box plane = null;
-               Transform3D planeShift = null;
-               TransformGroup planeTrans = null;
                planeAppearance = new Appearance();
                planeAppearance.setMaterial(new Material(new Color3f(0.1f, 0.2f, 0.2f),
                 new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.3f, 0.4f, 0.4f),
@@ -268,15 +297,15 @@ public class Java3DWindow implements ThreeDWindow
                objTrans.addChild(createCompassPoint(I18nManager.getText("cardinal.e"), new Point3f(10f, 0f, 0f), compassFont));
 
                // create and scale model
-               ThreeDModel model = new ThreeDModel(_track);
-               model.setAltitudeCap(_altitudeCap);
-               model.scale();
+               _model = new ThreeDModel(_track);
+               _model.setAltitudeCap(_altitudeCap);
+               _model.scale();
 
                // Lat/Long lines
-               objTrans.addChild(createLatLongs(model));
+               objTrans.addChild(createLatLongs(_model));
 
                // Add points to model
-               objTrans.addChild(createDataPoints(model));
+               objTrans.addChild(createDataPoints(_model));
 
                // Create lights
                BoundingSphere bounds =
@@ -339,12 +368,12 @@ public class Java3DWindow implements ThreeDWindow
        private static Group createLatLongs(ThreeDModel inModel)
        {
                Group group = new Group();
-               int numlines = inModel.getNumLatitudeLines();
+               int numlines = inModel.getLatitudeLines().length;
                for (int i=0; i<numlines; i++)
                {
                        group.addChild(createLatLine(inModel.getScaledLatitudeLine(i), inModel.getModelSize()));
                }
-               numlines = inModel.getNumLongitudeLines();
+               numlines = inModel.getLongitudeLines().length;
                for (int i=0; i<numlines; i++)
                {
                        group.addChild(createLonLine(inModel.getScaledLongitudeLine(i), inModel.getModelSize()));
@@ -436,7 +465,7 @@ public class Java3DWindow implements ThreeDWindow
        private static Group createWaypoint(Point3d inPointPos)
        {
                Material mat = getWaypointMaterial();
-               // TODO: sort symbol scaling
+               // MAYBE: sort symbol scaling
                Sphere dot = new Sphere(0.35f); // * symbolScaling / 100f);
                return createBall(inPointPos, dot, mat);
        }
@@ -456,7 +485,7 @@ public class Java3DWindow implements ThreeDWindow
        private static Group createTrackpoint(Point3d inPointPos, byte inHeightCode)
        {
                Material mat = getTrackpointMaterial(inHeightCode);
-               // TODO: sort symbol scaling
+               // MAYBE: sort symbol scaling
                Sphere dot = new Sphere(0.2f); // * symbolScaling / 100f);
                return createBall(inPointPos, dot, mat);
        }
@@ -539,8 +568,10 @@ public class Java3DWindow implements ThreeDWindow
                Point3d result = new Point3d();
                secondTran.transform(point, result);
                firstTran.transform(result);
-               // Callback settings to App
-               _app.exportPov(result.x, result.y, result.z, _altitudeCap);
+               // Callback settings to pov export function
+               FunctionLibrary.FUNCTION_POVEXPORT.setCameraCoordinates(result.x, result.y, result.z);
+               FunctionLibrary.FUNCTION_POVEXPORT.setAltitudeCap(_altitudeCap);
+               FunctionLibrary.FUNCTION_POVEXPORT.begin();
        }
 
 
@@ -551,8 +582,8 @@ public class Java3DWindow implements ThreeDWindow
         */
        private static String getAltitudeUnitsLabel(Track inTrack)
        {
-               int altitudeFormat = inTrack.getAltitudeRange().getFormat();
-               if (altitudeFormat == Altitude.FORMAT_METRES)
+               Altitude.Format altitudeFormat = inTrack.getAltitudeRange().getFormat();
+               if (altitudeFormat == Altitude.Format.METRES)
                        return I18nManager.getText("units.metres.short");
                return I18nManager.getText("units.feet.short");
        }