protected void load(String fileName) { InputStream is = null; try { is = new FileInputStream(new File(fileName)); } catch (FileNotFoundException e) { return; } try { JAXBContext jc = JAXBContext.newInstance(Settings.class); Unmarshaller um = jc.createUnmarshaller(); Settings opts = (Settings) um.unmarshal(MegaMekXmlUtil.createSafeXmlSource(is)); for (Store store : opts.stores) { if (CLIENT_SETTINGS_STORE_NAME.equals(store.name)) { for (XmlProperty prop : store.preferences) { clientPreferenceStore.putValue(prop.key, prop.value); } } else { IPreferenceStore ips = getPreferenceStore(store.name); for (XmlProperty prop : store.preferences) { ips.putValue(prop.key, prop.value); } } } } catch (JAXBException | SAXException | ParserConfigurationException ex) { System.err.println("Error loading XML for client settings: " + ex.getMessage()); //$NON-NLS-1$ ex.printStackTrace(); } }
@Test public void testSaveAndLoad() throws IOException { File f = tmpFolder.newFile("test-client-settings.xml"); testMe.getPreferenceStore(PreferenceManager.CLIENT_SETTINGS_STORE_NAME).setValue(LOCALE_KEY, Locale.GERMAN.getLanguage()); testMe.getPreferenceStore(GUI_PREFERENCES_STORE).setValue(DAMAGE_LEVEL_KEY, true); testMe.save(f); assertTrue(f.exists()); assertTrue(f.length() > 0); testMe.load(f.toString()); assertEquals(Locale.GERMAN.getLanguage(), testMe.getPreferenceStore(PreferenceManager.CLIENT_SETTINGS_STORE_NAME).getString(LOCALE_KEY)); assertTrue(testMe.getPreferenceStore(GUI_PREFERENCES_STORE).getBoolean(DAMAGE_LEVEL_KEY)); }
protected ButtonOrderPreferences() { store = PreferenceManager.getInstance().getPreferenceStore( getClass().getName()); for (MovementDisplay.MoveCommand cmd : MovementDisplay.MoveCommand.values()) { store.setDefault(cmd.getCmd(), cmd.ordinal()); } for (FiringDisplay.FiringCommand cmd : FiringDisplay.FiringCommand.values()) { store.setDefault(cmd.getCmd(), cmd.ordinal()); } for (PhysicalDisplay.PhysicalCommand cmd : PhysicalDisplay.PhysicalCommand.values()) { store.setDefault(cmd.getCmd(), cmd.ordinal()); } for (TargetingPhaseDisplay.TargetingCommand cmd : TargetingPhaseDisplay.TargetingCommand.values()) { store.setDefault(cmd.getCmd(), cmd.ordinal()); } for (DeploymentDisplay.DeployCommand cmd : DeploymentDisplay.DeployCommand.values()) { store.setDefault(cmd.getCmd(), cmd.ordinal()); } }
protected GUIPreferences() { store = PreferenceManager.getInstance().getPreferenceStore( getClass().getName());