]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/save/PovExporter.java
Version 9, February 2010
[GpsPrune.git] / tim / prune / save / PovExporter.java
index 6f8a32202ef227633ffa533dc62df2f6159e2007..1b0edfbab07ed76297650040a5fc151e72a5d26d 100644 (file)
@@ -17,7 +17,6 @@ import javax.swing.ButtonGroup;
 import javax.swing.JButton;
 import javax.swing.JDialog;
 import javax.swing.JFileChooser;
-import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
@@ -25,9 +24,11 @@ import javax.swing.JRadioButton;
 import javax.swing.JTextField;
 import javax.swing.SwingConstants;
 
-import tim.prune.Config;
+import tim.prune.App;
+import tim.prune.GenericFunction;
 import tim.prune.I18nManager;
 import tim.prune.UpdateMessageBroker;
+import tim.prune.config.Config;
 import tim.prune.data.Track;
 import tim.prune.load.GenericFileFilter;
 import tim.prune.threedee.LineDialog;
@@ -37,9 +38,8 @@ import tim.prune.threedee.ThreeDModel;
  * Class to export track information
  * into a specified Pov file
  */
-public class PovExporter
+public class PovExporter extends GenericFunction
 {
-       private JFrame _parentFrame = null;
        private Track _track = null;
        private JDialog _dialog = null;
        private JFileChooser _fileChooser = null;
@@ -56,17 +56,20 @@ public class PovExporter
 
        /**
         * Constructor giving frame and track
-        * @param inParentFrame parent frame
-        * @param inTrack track object to save
+        * @param inApp App object
         */
-       public PovExporter(JFrame inParentFrame, Track inTrack)
+       public PovExporter(App inApp)
        {
-               _parentFrame = inParentFrame;
-               _track = inTrack;
+               super(inApp);
+               _track = inApp.getTrackInfo().getTrack();
                // Set default camera coordinates
                _cameraX = "17"; _cameraY = "13"; _cameraZ = "-20";
        }
 
+       /** Get the name key */
+       public String getNameKey() {
+               return "function.exportpov";
+       }
 
        /**
         * Set the coordinates for the camera (can be any scale)
@@ -104,12 +107,12 @@ public class PovExporter
        /**
         * Show the dialog to select options and export file
         */
-       public void showDialog()
+       public void begin()
        {
                // Make dialog window to select angles, colours etc
                if (_dialog == null)
                {
-                       _dialog = new JDialog(_parentFrame, I18nManager.getText("dialog.exportpov.title"), true);
+                       _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true);
                        _dialog.setLocationRelativeTo(_parentFrame);
                        _dialog.getContentPane().add(makeDialogComponents());
                }
@@ -122,7 +125,7 @@ public class PovExporter
                _altitudeCapField.setText("" + _altitudeCap);
                // Show dialog
                _dialog.pack();
-               _dialog.show();
+               _dialog.setVisible(true);
        }
 
 
@@ -164,7 +167,7 @@ public class PovExporter
                JLabel fontLabel = new JLabel(I18nManager.getText("dialog.exportpov.font"));
                fontLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                centralPanel.add(fontLabel);
-               String defaultFont = Config.getPovrayFont();
+               String defaultFont = Config.getConfigString(Config.KEY_POVRAY_FONT);
                if (defaultFont == null || defaultFont.equals("")) {
                        defaultFont = DEFAULT_FONT_FILE;
                }
@@ -262,8 +265,8 @@ public class PovExporter
                        _fileChooser.setFileFilter(new GenericFileFilter("filetype.pov", new String[] {"pov"}));
                        _fileChooser.setAcceptAllFileFilterUsed(false);
                        // start from directory in config which should be set
-                       File configDir = Config.getWorkingDirectory();
-                       if (configDir != null) {_fileChooser.setCurrentDirectory(configDir);}
+                       final String configDir = Config.getConfigString(Config.KEY_TRACK_DIR);
+                       if (configDir != null) {_fileChooser.setCurrentDirectory(new File(configDir));}
                }
 
                // Allow choose again if an existing file is selected
@@ -292,7 +295,7 @@ public class PovExporter
                                        {
                                                // file saved
                                                // Store directory in config for later
-                                               Config.setWorkingDirectory(file.getParentFile());
+                                               Config.setConfigString(Config.KEY_TRACK_DIR, file.getParentFile().getAbsolutePath());
                                        }
                                        else
                                        {
@@ -356,7 +359,7 @@ public class PovExporter
                }
                catch (IOException ioe)
                {
-                       JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.failed") + ioe.getMessage(),
+                       JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.failed") + " : " + ioe.getMessage(),
                                I18nManager.getText("error.save.dialogtitle"), JOptionPane.ERROR_MESSAGE);
                }
                finally
@@ -391,6 +394,9 @@ public class PovExporter
                {
                        fontPath = DEFAULT_FONT_FILE;
                }
+               else {
+                       Config.setConfigString(Config.KEY_POVRAY_FONT, fontPath);
+               }
                // Set up output
                String[] outputLines = {
                  "global_settings { ambient_light rgb <4, 4, 4> }", "",
@@ -425,7 +431,7 @@ public class PovExporter
                  "   open",
                  "   pigment { color rgb <0.5 0.5 0.5> }",
                  "  }", "",
-                 // TODO: Export rods to POV?  How to store in data?
+                 // MAYBE: Export rods to POV?  How to store in data?
                  "#declare waypoint_sphere =",
                  "  sphere {",
                  "   <0, 0, 0>, 0.4",
@@ -511,7 +517,7 @@ public class PovExporter
                  "  pigment { color rgb <1 1 1> }",
                  "  translate <-" + (inModelSize * 1.03) + ", 0.2, 0>",
                  "}", "",
-                 // TODO: Light positions should relate to model size
+                 // MAYBE: Light positions should relate to model size
                  "// lights",
                  "light_source { <-1, 9, -4> color rgb <0.5 0.5 0.5>}",
                  "light_source { <1, 6, -14> color rgb <0.6 0.6 0.6>}",
@@ -636,11 +642,11 @@ public class PovExporter
                inWriter.write(inLineSeparator);
 
                // Loop over all the track segments
-               ArrayList segmentList = getSegmentList(inModel);
-               Iterator segmentIterator = segmentList.iterator();
+               ArrayList<ModelSegment> segmentList = getSegmentList(inModel);
+               Iterator<ModelSegment> segmentIterator = segmentList.iterator();
                while (segmentIterator.hasNext())
                {
-                       ModelSegment segment = (ModelSegment) segmentIterator.next();
+                       ModelSegment segment = segmentIterator.next();
                        int segLength = segment.getNumTrackPoints();
 
                        // if the track segment is long enough, do a cubic spline sphere sweep
@@ -787,9 +793,9 @@ public class PovExporter
         * @param inModel model containing data
         * @return list of ModelSegment objects
         */
-       private static ArrayList getSegmentList(ThreeDModel inModel)
+       private static ArrayList<ModelSegment> getSegmentList(ThreeDModel inModel)
        {
-               ArrayList segmentList = new ArrayList();
+               ArrayList<ModelSegment> segmentList = new ArrayList<ModelSegment>();
                if (inModel != null && inModel.getNumPoints() > 0)
                {
                        ModelSegment currSegment = null;