All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.ihmc.simulationconstructionset.gui.dialogConstructors.SaveParametersGenerator Maven / Gradle / Ivy

There is a newer version: 0.25.2
Show newest version
package us.ihmc.simulationconstructionset.gui.dialogConstructors;

import java.io.FileOutputStream;
import java.io.IOException;

import javax.swing.JOptionPane;

import us.ihmc.simulationconstructionset.SimulationConstructionSet;
import us.ihmc.yoVariables.parameters.XmlParameterWriter;
import us.ihmc.yoVariables.registry.YoRegistry;

public class SaveParametersGenerator implements SaveParametersConstructor
{
   private final SimulationConstructionSet scs;
   private ParameterFileChooser fileChooser;

   public SaveParametersGenerator(SimulationConstructionSet scs)
   {
      this.scs = scs;
      fileChooser = new ParameterFileChooser();
   }

   @Override
   public void constructDialog()
   {

      if (fileChooser.showDialog(scs.getJFrame(), scs.getRootRegistry(), scs.getParameterRootPath(), scs.getDefaultParameterFile(), true))
      {
         XmlParameterWriter writer = new XmlParameterWriter();
         for (YoRegistry child : fileChooser.getRegistries())
         {
            writer.addParameters(child);
         }
         try
         {
            FileOutputStream os = new FileOutputStream(fileChooser.getFile());
            writer.write(os);
            os.close();
         }
         catch (IOException e)
         {
            JOptionPane.showMessageDialog(scs.getJFrame(),
                                          "Cannot write to " + fileChooser.getFile() + "\n" + e.getMessage(),
                                          "Cannot write to file",
                                          JOptionPane.ERROR_MESSAGE);
         }
      }

   }

   @Override
   public void closeAndDispose()
   {
      fileChooser.closeAndDispose();
      fileChooser = null;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy