Package periman

Source Code of periman.Configuration

package periman;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
import com.thoughtworks.xstream.InitializationException;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.XStreamException;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class Configuration {
  private String fileName;
  private String outputDest; // the path for saving the results.
  private DefaultListModel forms = new DefaultListModel();
 
 
 
  Configuration(String fn)
  {
    fileName = fn;
  }
 
  @Override
  public boolean equals(Object o){
    if( o == this )
      return true;
   
    if(!(o instanceof Configuration))
      return false;
   
    Configuration c = (Configuration)o;
    return c.fileName.equals(fileName) &&
        c.forms.equals(forms) &&
        c.outputDest.equals(outputDest);
  }
 
  @Override public int hashCode() {
    int result = 17;
    result = 31 * result + fileName.hashCode();
    result = 31 * result + forms.hashCode();
    result = 31 * result + outputDest.hashCode();
    return result;
  }

  public String getFileName() {   
    return fileName;
  }
 
  public void setFileName(String s)
  {
    fileName = s;
  }

  public void addForm(String f) {
    forms.addElement(f);
   
  }

  public void removeForm(int sel) {
    forms.remove( sel );   
  }
 
  public void clearFormsModel()
  {
    forms.clear();
  }

  public ListModel getForms() {   
    return forms;
  }

  public void setOutputDestination(String text) {
    outputDest = text;
   
  }

  public String getOutputDestination() {
    return outputDest;
  }
 
  public static Configuration load(final String fp_confFilePath)
  {
    Configuration c = null;
    try{
      XStream xstream = new XStream( new DomDriver() );
      FileReader fr = new FileReader(fp_confFilePath);
      c =  (Configuration)xstream.fromXML(fr);     
    }
    catch(InitializationException e)
    {
      JOptionPane.showMessageDialog( null, e.getMessage());
    }
    catch(XStreamException e)
    {
      JOptionPane.showMessageDialog( null, e.getMessage());
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog( null, e.getMessage());
    }
   
    return c;
  }
 
  public boolean save(final String p)
  {
    XStream xstream = new XStream(new DomDriver());
   
    try {
      FileWriter fw = new FileWriter(p);
           xstream.toXML( this , fw );
        }
    catch (IOException ex) {
        JOptionPane.showMessageDialog( null, ex.getMessage());
        return false;
        }
        catch(XStreamException ex){
          JOptionPane.showMessageDialog( null, ex.getMessage());
          return false;
        }
       
        return true;
  }
 
}
TOP

Related Classes of periman.Configuration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.