| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package com.timjohnstondev.unitconverter.logic; |
| 12 | |
|
| 13 | |
import java.util.ResourceBundle; |
| 14 | |
import java.util.prefs.Preferences; |
| 15 | |
import javax.swing.ListModel; |
| 16 | |
import com.timjohnstondev.unitconverter.Launcher; |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
public final class ConfigurationLogic |
| 22 | |
{ |
| 23 | 1 | private static final ResourceBundle RESOURCES = ResourceBundle |
| 24 | |
.getBundle("com.timjohnstondev.unitconverter.view.View"); |
| 25 | |
|
| 26 | |
private ConfigurationLogic() |
| 27 | 0 | {} |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public static int getPreferenceIndex(final ListModel model, final String unitSeparator) |
| 37 | |
{ |
| 38 | 2 | int sepIndex = 0; |
| 39 | 10 | for (int i = 0; i < model.getSize(); i++) |
| 40 | |
{ |
| 41 | 8 | if (model.getElementAt(i).equals(unitSeparator)) |
| 42 | |
{ |
| 43 | 2 | sepIndex = i; |
| 44 | |
} |
| 45 | |
} |
| 46 | 2 | return sepIndex; |
| 47 | |
} |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public static String getUnitSeparatorPreference() |
| 56 | |
{ |
| 57 | 4 | final Preferences userPref = Preferences.userNodeForPackage(Launcher.class); |
| 58 | 4 | final String prefValue = userPref.get(RESOURCES.getString("UnitConverter.prefKeyUnitSeparator"), ""); |
| 59 | 4 | final String unitSeparator = prefValue != null ? prefValue : "\"*\""; |
| 60 | 4 | return unitSeparator; |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public static void setUnitSeparatorPreference(final String symbol) |
| 69 | |
{ |
| 70 | 3 | final Preferences userPref = Preferences.userNodeForPackage(Launcher.class); |
| 71 | 3 | userPref.put(RESOURCES.getString("UnitConverter.prefKeyUnitSeparator"), symbol); |
| 72 | 3 | } |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public static int getFontSizePreference(final int defaultFontSize) |
| 82 | |
{ |
| 83 | 4 | final Preferences userPref = Preferences.userNodeForPackage(Launcher.class); |
| 84 | 4 | final String prefValue = userPref.get(RESOURCES.getString("UnitConverter.prefKeyFontSize"), ""); |
| 85 | 4 | int fontSize = defaultFontSize; |
| 86 | |
|
| 87 | |
try |
| 88 | |
{ |
| 89 | 4 | fontSize = Integer.parseInt(prefValue); |
| 90 | |
} |
| 91 | 0 | catch (NumberFormatException e) |
| 92 | |
{ |
| 93 | 0 | e.getMessage(); |
| 94 | 4 | } |
| 95 | 4 | return fontSize; |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public static void setFontSizePreference(final int fontSize) |
| 104 | |
{ |
| 105 | 3 | final Preferences userPref = Preferences.userNodeForPackage(Launcher.class); |
| 106 | 3 | userPref.put(RESOURCES.getString("UnitConverter.prefKeyFontSize"), String.valueOf(fontSize)); |
| 107 | 3 | } |
| 108 | |
} |