set default values after loading config for any missing keys
this fixes probably my main gripe with the existing XML serialization code (at least as far as loading settings is concerned).
This commit is contained in:
parent
7a59e40b38
commit
b26e0ecf5e
|
@ -193,95 +193,99 @@ public class Settings {
|
||||||
*/
|
*/
|
||||||
private static void retrieve() {
|
private static void retrieve() {
|
||||||
global = Configuration.newInstance( new File(UserSettings.getSettingsPath() + File.separator + "llanfair.xml" ) );
|
global = Configuration.newInstance( new File(UserSettings.getSettingsPath() + File.separator + "llanfair.xml" ) );
|
||||||
if ( global.isEmpty() ) {
|
|
||||||
setDefaultValues();
|
setDefaultValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setDefault(String key, Object value, boolean force) {
|
||||||
|
if (force || !global.contains(key))
|
||||||
|
global.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills the global configuration with every property, assigning them their
|
* Sets default values in the global configuration for each property which is
|
||||||
* default value. This method can be called even when the global
|
* missing (key is not present). Existing values are preserved (even nulls).
|
||||||
* configuration is not empty, and will thus function as a reset.
|
|
||||||
*/
|
*/
|
||||||
private static void setDefaultValues() {
|
private static void setDefaultValues() {
|
||||||
global.put( alwaysOnTop.key, true );
|
boolean force = false;
|
||||||
global.put( language.key, Locale.ENGLISH );
|
|
||||||
global.put( viewerLanguage.key, Locale.ENGLISH );
|
|
||||||
global.put( recentFiles.key, new ArrayList<String>() );
|
|
||||||
global.put( coordinates.key, null );
|
|
||||||
global.put( dimension.key, null );
|
|
||||||
global.put( compareMethod.key, Compare.BEST_OVERALL_RUN );
|
|
||||||
global.put( accuracy.key, Accuracy.TENTH );
|
|
||||||
global.put( warnOnReset.key, true );
|
|
||||||
global.put( windowUserResizable.key, true );
|
|
||||||
global.put( windowWidth.key, null );
|
|
||||||
|
|
||||||
global.put( colorBackground.key, Color.decode("0x000000") );
|
setDefault( alwaysOnTop.key, true, force );
|
||||||
global.put( colorForeground.key, Color.decode( "0xc0c0c0" ) );
|
setDefault( language.key, Locale.ENGLISH, force );
|
||||||
global.put( colorTime.key, Color.decode( "0xffffff" ) );
|
setDefault( viewerLanguage.key, Locale.ENGLISH, force );
|
||||||
global.put( colorTimer.key, Color.decode( "0x22cc22" ) );
|
setDefault( recentFiles.key, new ArrayList<String>(), force );
|
||||||
global.put( colorNegativeTime.key, Color.decode ("0x808080" ) );
|
setDefault( coordinates.key, null, force );
|
||||||
global.put( colorTimeGainedWhileAhead.key, Color.decode( "0x6295fc" ) );
|
setDefault( dimension.key, null, force );
|
||||||
global.put( colorTimeLostWhileAhead.key, Color.decode( "0x99ccff" ) );
|
setDefault( compareMethod.key, Compare.BEST_OVERALL_RUN, force );
|
||||||
global.put( colorTimeGainedWhileBehind.key, Color.decode( "0xff8e8e" ) );
|
setDefault( accuracy.key, Accuracy.TENTH, force );
|
||||||
global.put( colorTimeLostWhileBehind.key, Color.decode( "0xe82323" ) );
|
setDefault( warnOnReset.key, true, force );
|
||||||
global.put( colorNewRecord.key, Color.decode( "0xf0b012" ) );
|
setDefault( windowUserResizable.key, true, force );
|
||||||
global.put( colorTitle.key, Color.decode( "0xf0b012" ) );
|
setDefault( windowWidth.key, null, force );
|
||||||
global.put( colorSubTitle.key, Color.decode( "0xffffff" ) );
|
|
||||||
global.put( colorHighlight.key, Color.decode( "0xffffff" ) );
|
|
||||||
global.put( colorSeparators.key, Color.decode( "0x666666" ) );
|
|
||||||
|
|
||||||
global.put( useGlobalHotkeys.key, false );
|
setDefault( colorBackground.key, Color.decode("0x000000"), force );
|
||||||
global.put( hotkeySplit.key, -1 );
|
setDefault( colorForeground.key, Color.decode( "0xc0c0c0" ), force );
|
||||||
global.put( hotkeyUnsplit.key, -1 );
|
setDefault( colorTime.key, Color.decode( "0xffffff" ), force );
|
||||||
global.put( hotkeySkip.key, -1 );
|
setDefault( colorTimer.key, Color.decode( "0x22cc22" ), force );
|
||||||
global.put( hotkeyReset.key, -1 );
|
setDefault( colorNegativeTime.key, Color.decode ("0x808080" ), force );
|
||||||
global.put( hotkeyStop.key, -1 );
|
setDefault( colorTimeGainedWhileAhead.key, Color.decode( "0x6295fc" ), force );
|
||||||
global.put( hotkeyPause.key, -1 );
|
setDefault( colorTimeLostWhileAhead.key, Color.decode( "0x99ccff" ), force );
|
||||||
global.put( hotkeyLock.key, -1 );
|
setDefault( colorTimeGainedWhileBehind.key, Color.decode( "0xff8e8e" ), force );
|
||||||
|
setDefault( colorTimeLostWhileBehind.key, Color.decode( "0xe82323" ), force );
|
||||||
|
setDefault( colorNewRecord.key, Color.decode( "0xf0b012" ), force );
|
||||||
|
setDefault( colorTitle.key, Color.decode( "0xf0b012" ), force );
|
||||||
|
setDefault( colorSubTitle.key, Color.decode( "0xffffff" ), force );
|
||||||
|
setDefault( colorHighlight.key, Color.decode( "0xffffff" ), force );
|
||||||
|
setDefault( colorSeparators.key, Color.decode( "0x666666" ), force );
|
||||||
|
|
||||||
global.put( headerShowSubtitle.key, true );
|
setDefault( useGlobalHotkeys.key, false, force );
|
||||||
global.put( headerShowTitle.key, true );
|
setDefault( hotkeySplit.key, -1, force );
|
||||||
global.put( headerShowAttempts.key, true );
|
setDefault( hotkeyUnsplit.key, -1, force );
|
||||||
global.put( headerTitleFont.key, Font.decode( "Arial-14" ) );
|
setDefault( hotkeySkip.key, -1, force );
|
||||||
global.put( headerSubTitleFont.key, Font.decode( "Arial-12" ) );
|
setDefault( hotkeyReset.key, -1, force );
|
||||||
|
setDefault( hotkeyStop.key, -1, force );
|
||||||
|
setDefault( hotkeyPause.key, -1, force );
|
||||||
|
setDefault( hotkeyLock.key, -1, force );
|
||||||
|
|
||||||
global.put( historyRowCount.key, 8 );
|
setDefault( headerShowSubtitle.key, true, force );
|
||||||
global.put( historyTabular.key, true );
|
setDefault( headerShowTitle.key, true, force );
|
||||||
global.put( historyBlankRows.key, false );
|
setDefault( headerShowAttempts.key, true, force );
|
||||||
global.put( historyMultiline.key, false );
|
setDefault( headerTitleFont.key, Font.decode( "Arial-14" ), force );
|
||||||
global.put( historyMerge.key, Merge.LIVE );
|
setDefault( headerSubTitleFont.key, Font.decode( "Arial-12" ), force );
|
||||||
global.put( historyLiveTimes.key, true );
|
|
||||||
global.put( historyDeltas.key, true );
|
|
||||||
global.put( historyIcons.key, true );
|
|
||||||
global.put( historyIconSize.key, 16 );
|
|
||||||
global.put( historyOffset.key, 0 );
|
|
||||||
global.put( historyAlwaysShowLast.key, true );
|
|
||||||
global.put( historySegmentFont.key, Font.decode( "Arial-12" ) );
|
|
||||||
global.put( historyTimeFont.key, Font.decode( "Arial-11" ) );
|
|
||||||
|
|
||||||
global.put( coreAccuracy.key, Accuracy.HUNDREDTH );
|
setDefault( historyRowCount.key, 8, force );
|
||||||
global.put( coreShowIcons.key, true );
|
setDefault( historyTabular.key, true, force );
|
||||||
global.put( coreIconSize.key, 40 );
|
setDefault( historyBlankRows.key, false, force );
|
||||||
global.put( coreShowSegmentName.key, true );
|
setDefault( historyMultiline.key, false, force );
|
||||||
global.put( coreShowSplitTime.key, false );
|
setDefault( historyMerge.key, Merge.LIVE, force );
|
||||||
global.put( coreShowSegmentTime.key, true );
|
setDefault( historyLiveTimes.key, true, force );
|
||||||
global.put( coreShowBestTime.key, true );
|
setDefault( historyDeltas.key, true, force );
|
||||||
global.put( coreShowSegmentTimer.key, true );
|
setDefault( historyIcons.key, true, force );
|
||||||
global.put( coreTimerFont.key, Font.decode( "Digitalism-32" ) );
|
setDefault( historyIconSize.key, 16, force );
|
||||||
global.put( coreSegmentTimerFont.key, Font.decode( "Digitalism-18" ) );
|
setDefault( historyOffset.key, 0, force );
|
||||||
global.put( coreFont.key, Font.decode( "Arial-12" ) );
|
setDefault( historyAlwaysShowLast.key, true, force );
|
||||||
global.put( coreOtherTimeFont.key, Font.decode( "Arial-11" ) );
|
setDefault( historySegmentFont.key, Font.decode( "Arial-12" ), force );
|
||||||
|
setDefault( historyTimeFont.key, Font.decode( "Arial-11" ), force );
|
||||||
|
|
||||||
global.put( graphDisplay.key, true );
|
setDefault( coreAccuracy.key, Accuracy.HUNDREDTH, force );
|
||||||
global.put( graphScale.key, 3.0F );
|
setDefault( coreShowIcons.key, true, force );
|
||||||
|
setDefault( coreIconSize.key, 40, force );
|
||||||
|
setDefault( coreShowSegmentName.key, true, force );
|
||||||
|
setDefault( coreShowSplitTime.key, false, force );
|
||||||
|
setDefault( coreShowSegmentTime.key, true, force );
|
||||||
|
setDefault( coreShowBestTime.key, true, force );
|
||||||
|
setDefault( coreShowSegmentTimer.key, true, force );
|
||||||
|
setDefault( coreTimerFont.key, Font.decode( "Digitalism-32" ), force );
|
||||||
|
setDefault( coreSegmentTimerFont.key, Font.decode( "Digitalism-18" ), force );
|
||||||
|
setDefault( coreFont.key, Font.decode( "Arial-12" ), force );
|
||||||
|
setDefault( coreOtherTimeFont.key, Font.decode( "Arial-11" ), force );
|
||||||
|
|
||||||
global.put( footerDisplay.key, true );
|
setDefault( graphDisplay.key, true, force );
|
||||||
global.put( footerVerbose.key, true );
|
setDefault( graphScale.key, 3.0F, force );
|
||||||
global.put( footerUseSplitData.key, false );
|
|
||||||
global.put( footerShowBestTime.key, true );
|
setDefault( footerDisplay.key, true, force );
|
||||||
global.put( footerMultiline.key, true );
|
setDefault( footerVerbose.key, true, force );
|
||||||
global.put( footerShowDeltaLabels.key, true );
|
setDefault( footerUseSplitData.key, false, force );
|
||||||
|
setDefault( footerShowBestTime.key, true, force );
|
||||||
|
setDefault( footerMultiline.key, true, force );
|
||||||
|
setDefault( footerShowDeltaLabels.key, true, force );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in a new issue