001    /**
002     * Created by IntelliJ IDEA.
003     * User: Wei Wang
004     * Date: Apr 1, 2003
005     * Time: 9:59:07 PM
006     */
007    
008    package EVolve.util.settings;
009    
010    import java.io.File;
011    import java.io.IOException;
012    import java.io.RandomAccessFile;
013    
014    import javax.swing.JTextField;
015    
016    import EVolve.Scene;
017    
018    public class PhaseDetectorSetting extends Setting{
019        private static PhaseDetectorSetting instance;
020    
021        public static PhaseDetectorSetting v() {
022            if (instance == null)
023                instance = new PhaseDetectorSetting();
024            return instance;
025        }
026    
027        public void save(String tags[], JTextField contents[], String filename) {
028            this.contents = contents;
029            this.tags = tags;
030            iniFilename = getFilenameWithPath(filename);
031            save();
032        }
033    
034        public void readDataFromFile(String tags[], JTextField[] contents, String filename) {
035            String line;
036            RandomAccessFile iniFile;
037            File file = new File(getFilenameWithPath(filename));
038            if (!file.exists()) return;
039    
040            try {
041                iniFile = new RandomAccessFile(file,"r");
042                for (int i=0; i<tags.length; i++) {
043                    line = iniFile.readLine(); //skip tag
044                    line = iniFile.readLine();
045                    contents[i].setText(line.trim());
046                }
047            } catch (IOException e) {
048                Scene.showErrorMessage("Unable to read setting file \""+iniFilename+"\", or" +
049                                       "the file is corrupted.");
050                return;
051            } catch (NumberFormatException e) {
052                Scene.showErrorMessage("Format of \""+iniFilename+"\" is incorrect.");
053                return;
054            }
055    
056        }
057    
058    }