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

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

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

import java.io.FileInputStream;
import java.io.IOException;

import javax.swing.JOptionPane;

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

public class LoadParametersGenerator implements LoadParametersConstructor
{
   private final SimulationConstructionSet scs;
   private ParameterFileChooser fileChooser;

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

   @Override
   public void constructDialog()
   {

      if (fileChooser.showDialog(scs.getJFrame(), scs.getRootRegistry(), scs.getParameterRootPath(), scs.getDefaultParameterFile(), false))
      {
         try
         {
            FileInputStream is = new FileInputStream(fileChooser.getFile());
            XmlParameterReader reader = new XmlParameterReader(is);
            is.close();

            for (YoRegistry child : fileChooser.getRegistries())
            {
               reader.readParametersInRegistry(child);
            }
         }
         catch (IOException e)
         {
            JOptionPane.showMessageDialog(scs.getJFrame(),
                                          "Cannot read from " + fileChooser.getFile() + "\n" + e.getMessage(),
                                          "Cannot read from file",
                                          JOptionPane.ERROR_MESSAGE);
         }
      }
   }

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy