| 24 | | public static final String settingsFileName = jergometerDirName + "/settings.xml"; |
| | 27 | public static final File oldSettingsFile = new File(jergometerDirName + "/settings.xml"); |
| | 28 | public static final File settingsFile = new File(jergometerDirName + "/settings.properties"); |
| | 29 | |
| | 30 | // BetterProperties2 constants |
| | 31 | public static final BetterProperties2.Range INT = BetterProperties2.INT; |
| | 32 | public static final BetterProperties2.Range INT_GT_0 = BetterProperties2.INT_GT_0; |
| | 33 | public static final BetterProperties2.Range DOUBLE = BetterProperties2.DOUBLE; |
| | 34 | public static final BetterProperties2.Range DOUBLE_GT_0 = BetterProperties2.DOUBLE_GT_0; |
| | 35 | public static final BetterProperties2.Range DOUBLE_0_TO_1 = BetterProperties2.DOUBLE_0_TO_1; |
| | 36 | public static final BetterProperties2.Range BOOLEAN = BetterProperties2.BOOLEAN; |
| | 37 | public static final BetterProperties2.Range STRING = BetterProperties2.STRING; |
| | 38 | public static final BetterProperties2.Range SHORTCUT = BetterProperties2.SHORTCUT; |
| | 84 | private void defineProperties() { |
| | 85 | // set default for the properties file |
| | 86 | properties.addEntry(new BetterProperties2.Comment("\n## General properties")); |
| | 87 | //properties.addEntry(new BetterProperties2.Comment(" Check for updates")); |
| | 88 | properties.addEntry(new BetterProperties2.Def("check_for_updates", BOOLEAN, "true")); |
| | 89 | properties.addEntry(new BetterProperties2.Def("last_user", STRING, null)); |
| | 90 | properties.addEntry(new BetterProperties2.Def("comport", STRING, null)); |
| | 91 | properties.addEntry(new BetterProperties2.Def("xml_editor", STRING, null)); |
| | 92 | |
| | 93 | properties.addEntry(new BetterProperties2.Comment("\n## Window properties")); |
| | 94 | properties.addEntry(new BetterProperties2.Comment(" Position, width, and height of the main window")); |
| | 95 | properties.addEntry(new BetterProperties2.Def("main_window.x", INT_GT_0, "0")); |
| | 96 | properties.addEntry(new BetterProperties2.Def("main_window.y", INT_GT_0, "0")); |
| | 97 | properties.addEntry(new BetterProperties2.Def("main_window.width", INT_GT_0, "700")); |
| | 98 | properties.addEntry(new BetterProperties2.Def("main_window.height", INT_GT_0, "500")); |
| | 99 | properties.addEntry(new BetterProperties2.Def("main_window.maximized", INT_GT_0, "" + JFrame.MAXIMIZED_BOTH)); |
| | 100 | /* |
| | 101 | properties.addEntry(new BetterProperties2.Comment(" Width of the symbols panel as part of the main window")); |
| | 102 | properties.addEntry(new BetterProperties2.Def("symbols_panel.width", DOUBLE_0_TO_1, "0.25")); |
| | 103 | properties.addEntry(new BetterProperties2.Comment(" Height of the tools panel as part of the main window")); |
| | 104 | properties.addEntry(new BetterProperties2.Def("tools_panel.height", DOUBLE_0_TO_1, "0.15")); |
| | 105 | */ |
| | 106 | |
| | 107 | properties.addEntry(new BetterProperties2.Comment("\n## Shortcuts")); |
| | 108 | properties.addEntry(new BetterProperties2.Comment(" File menu")); |
| | 109 | properties.addEntry(new BetterProperties2.Def("shortcut.new", SHORTCUT, "control N")); |
| | 110 | properties.addEntry(new BetterProperties2.Def("shortcut.open", SHORTCUT, "control O")); |
| | 111 | properties.addEntry(new BetterProperties2.Def("shortcut.save", SHORTCUT, "control S")); |
| | 112 | properties.addEntry(new BetterProperties2.Def("shortcut.close", SHORTCUT, "control W")); |
| | 113 | properties.addEntry(new BetterProperties2.Def("shortcut.exit", SHORTCUT, "")); |
| | 114 | |
| | 115 | } |
| | 116 | |
| | 119 | try { |
| | 120 | properties.load(new FileReader(settingsFile)); |
| | 121 | } catch (IOException e) { |
| | 122 | properties.loadDefaults(); |
| | 123 | e.printStackTrace(); |
| | 124 | } |
| | 125 | } else { |
| | 126 | properties.loadDefaults(); |
| | 127 | } |
| | 128 | |
| | 129 | // extract variables |
| | 130 | checkForUpdatesOnStart = properties.getBoolean("check_for_updates"); |
| | 131 | mainWindowBounds = new Rectangle( |
| | 132 | properties.getInt("main_window.x"), |
| | 133 | properties.getInt("main_window.y"), |
| | 134 | properties.getInt("main_window.width"), |
| | 135 | properties.getInt("main_window.height") |
| | 136 | ); |
| | 137 | mainWindowMaximizedState = properties.getInt("main_window.maximized"); |
| | 138 | |
| | 139 | lastUserName = properties.getString("last_user"); |
| | 140 | comPort = properties.getString("comport"); |
| | 141 | xmlEditor = properties.getString("xml_editor"); |
| | 142 | |
| | 143 | if (oldSettingsFile.exists()) { |
| 87 | | XMLElement root = new XMLElement("settings"); |
| 88 | | root.setAttribute("version", "1"); |
| 89 | | |
| 90 | | { |
| 91 | | XMLElement update = new XMLElement("update"); |
| 92 | | root.addChildElement(update); |
| 93 | | update.setAttribute("checkOnStart", checkForUpdatesOnStart ? "true" : "false"); |
| 94 | | |
| 95 | | XMLElement users = new XMLElement("users"); |
| 96 | | root.addChildElement(users); |
| 97 | | if (lastUserName != null) { |
| 98 | | users.setAttribute("lastUser", lastUserName); |
| 99 | | } |
| 100 | | |
| 101 | | XMLElement comport = new XMLElement("comport"); |
| 102 | | root.addChildElement(comport); |
| 103 | | if (comPort != null) { |
| 104 | | comport.setAttribute("name", comPort); |
| 105 | | } |
| 106 | | |
| 107 | | XMLElement xmlEditor = new XMLElement("xmlEditor"); |
| 108 | | root.addChildElement(xmlEditor); |
| 109 | | if (this.xmlEditor != null) { |
| 110 | | xmlEditor.setAttribute("name", this.xmlEditor); |
| 111 | | } |
| 112 | | } |
| 113 | | |
| | 168 | properties.setBoolean("check_for_updates", checkForUpdatesOnStart); |
| | 169 | properties.setInt("main_window.x", mainWindowBounds.x); |
| | 170 | properties.setInt("main_window.y", mainWindowBounds.y); |
| | 171 | properties.setInt("main_window.width", mainWindowBounds.width); |
| | 172 | properties.setInt("main_window.height", mainWindowBounds.height); |
| | 173 | properties.setInt("main_window.maximized", mainWindowMaximizedState); |
| | 174 | |
| | 175 | properties.setString("last_user", lastUserName); |
| | 176 | properties.setString("comport", comPort); |
| | 177 | properties.setString("xml_editor", xmlEditor); |
| | 178 | |
| | 179 | settingsFile.getParentFile().mkdirs(); |
| | 180 | try { |
| | 181 | properties.store(new FileOutputStream(settingsFile), |
| | 182 | " JErgometer properties\n" + |
| | 183 | " Default values will be automatically commented out.\n"); |
| | 184 | } catch (Exception e) { |
| | 185 | e.printStackTrace(); |
| | 186 | } |
| | 187 | |
| | 188 | /* |