Small changes w.r.t. clearing preferences. Some code cleanup.
This commit is contained in:
parent
086f4bb6ec
commit
d88141512b
3 changed files with 59 additions and 27 deletions
|
@ -25,11 +25,16 @@ thdl.number.of.recently.opened.files.to.show = 4
|
||||||
# a recently opened file?
|
# a recently opened file?
|
||||||
thdl.max.chars.in.recently.opened.file.name = 40
|
thdl.max.chars.in.recently.opened.file.name = 40
|
||||||
|
|
||||||
# Set this to the full path of the user preferences file, or to the
|
# Set this to the full path of the directory containing the user
|
||||||
# empty string if you wish to use the default values, which are
|
# preferences file my_thdl_preferences.txt, or to the empty string if
|
||||||
# system-specific.
|
# you wish to use the default values, which are system-specific.
|
||||||
thdl.user.options.directory =
|
thdl.user.options.directory =
|
||||||
|
|
||||||
|
# Set this to the full path of the system-wide preferences file if you
|
||||||
|
# wish to use a system-wide preferences file to customize THDL tools
|
||||||
|
# for your site. Users' preferences override system-wide preferences.
|
||||||
|
thdl.system.wide.options.file =
|
||||||
|
|
||||||
# Set this to true if you want more messages (probably on the console)
|
# Set this to true if you want more messages (probably on the console)
|
||||||
# about what's going on.
|
# about what's going on.
|
||||||
thdl.verbose = false
|
thdl.verbose = false
|
||||||
|
|
|
@ -130,36 +130,46 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
|
|
||||||
/** Saves user preferences to disk if possible. */
|
/** Saves user preferences to disk if possible. */
|
||||||
private void savePreferencesAction() {
|
private void savePreferencesAction() {
|
||||||
try {
|
if (!clearedPrefs) {
|
||||||
RecentlyOpenedFilesDatabase.storeRecentlyOpenedFilePreferences();
|
try {
|
||||||
|
RecentlyOpenedFilesDatabase.storeRecentlyOpenedFilePreferences();
|
||||||
|
|
||||||
if (!ThdlOptions.saveUserPreferences()) {
|
if (!ThdlOptions.saveUserPreferences()) {
|
||||||
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
|
"You previously cleared preferences,\nso you cannot now save them.",
|
||||||
|
"Cannot Save User Preferences",
|
||||||
|
JOptionPane.PLAIN_MESSAGE);
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
JOptionPane.showMessageDialog(Jskad.this,
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
"You previously cleared preferences,\nso you cannot now save them.",
|
"Could not save to your preferences file!",
|
||||||
"Cannot Save User Preferences",
|
"Error Saving Preferences",
|
||||||
JOptionPane.PLAIN_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
|
||||||
System.out.println("IO Exception saving user preferences to " + ThdlOptions.getUserPreferencesPath());
|
|
||||||
ioe.printStackTrace();
|
|
||||||
ThdlDebug.noteIffyCode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean clearedPrefs = false;
|
||||||
/** Clears user preferences by deleting the preferences file on
|
/** Clears user preferences by deleting the preferences file on
|
||||||
disk. Prompts the user to quit and reopen Jskad. */
|
disk. Prompts the user to quit and reopen Jskad. */
|
||||||
private void clearPreferencesAction() {
|
private void clearPreferencesAction() {
|
||||||
|
clearedPrefs = true;
|
||||||
try {
|
try {
|
||||||
ThdlOptions.clearUserPreferences();
|
ThdlOptions.clearUserPreferences();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.out.println("IO Exception deleting user preferences file " + ThdlOptions.getUserPreferencesPath());
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
ioe.printStackTrace();
|
"Could not delete your preferences file!",
|
||||||
ThdlDebug.noteIffyCode();
|
"Error Clearing Preferences",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (JOptionPane.YES_OPTION
|
||||||
|
== JOptionPane.showConfirmDialog(Jskad.this,
|
||||||
|
"You must exit and restart before default preferences\nwill take effect.\n\nExit now?",
|
||||||
|
"Clearing Preferences",
|
||||||
|
JOptionPane.YES_NO_OPTION)) {
|
||||||
|
exitAction();
|
||||||
}
|
}
|
||||||
JOptionPane.showMessageDialog(Jskad.this,
|
|
||||||
"You must now exit this application and restart\nbefore default preferences will take effect.",
|
|
||||||
"Clearing Preferences",
|
|
||||||
JOptionPane.PLAIN_MESSAGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** the File menu */
|
/** the File menu */
|
||||||
|
|
|
@ -83,12 +83,17 @@ public class ThdlOptions {
|
||||||
// Look to the System first.
|
// Look to the System first.
|
||||||
String answer = getSystemValue(optionName);
|
String answer = getSystemValue(optionName);
|
||||||
if (answer == null) {
|
if (answer == null) {
|
||||||
answer = userProperties.getProperty(optionName, "false");
|
if (null != userProperties) {
|
||||||
|
answer = userProperties.getProperty(optionName, "false");
|
||||||
|
} else {
|
||||||
|
answer = "false";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return answer.equalsIgnoreCase("true");
|
return answer.equalsIgnoreCase("true");
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXMEDOC
|
/** Returns the value of the system property optionName, or null
|
||||||
|
if that value is not set. */
|
||||||
private static String getSystemValue(String optionName) {
|
private static String getSystemValue(String optionName) {
|
||||||
// Look to the System first.
|
// Look to the System first.
|
||||||
String answer = null;
|
String answer = null;
|
||||||
|
@ -113,7 +118,9 @@ public class ThdlOptions {
|
||||||
// Look to the System first.
|
// Look to the System first.
|
||||||
String answer = getSystemValue(optionName);
|
String answer = getSystemValue(optionName);
|
||||||
if (answer == null) {
|
if (answer == null) {
|
||||||
answer = userProperties.getProperty(optionName, null);
|
if (null != userProperties) {
|
||||||
|
answer = userProperties.getProperty(optionName, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +174,9 @@ public class ThdlOptions {
|
||||||
// Look to the System first.
|
// Look to the System first.
|
||||||
String answer = getSystemValue(optionName);
|
String answer = getSystemValue(optionName);
|
||||||
if (answer == null) {
|
if (answer == null) {
|
||||||
answer = userProperties.getProperty(optionName, null);
|
if (null != userProperties) {
|
||||||
|
answer = userProperties.getProperty(optionName, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (null == answer) {
|
if (null == answer) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -262,7 +271,7 @@ public class ThdlOptions {
|
||||||
|
|
||||||
// Get the user's properties, if they've set any:
|
// Get the user's properties, if they've set any:
|
||||||
userProperties
|
userProperties
|
||||||
= tryToGetPropsFromFile("thdl.user.options.directory", // DLC NOW FIXME: put in options.txt
|
= tryToGetPropsFromFile("thdl.user.options.directory",
|
||||||
getUserPreferencesPath(),
|
getUserPreferencesPath(),
|
||||||
systemWideProperties,
|
systemWideProperties,
|
||||||
suppressErrors);
|
suppressErrors);
|
||||||
|
@ -326,6 +335,11 @@ public class ThdlOptions {
|
||||||
props = getPropertiesFromStream(fis,
|
props = getPropertiesFromStream(fis,
|
||||||
suppressErrors,
|
suppressErrors,
|
||||||
defaultProps);
|
defaultProps);
|
||||||
|
try {
|
||||||
|
fis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// suppress this error.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
@ -345,11 +359,14 @@ public class ThdlOptions {
|
||||||
return getPropertiesFromStream(in, suppressErrors, defaults);
|
return getPropertiesFromStream(in, suppressErrors, defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXMEDOC
|
/** Returns a Properties object whose default values come from
|
||||||
|
defaults if defaults is non-null. The properties specified in
|
||||||
|
the properties file from which in is open for reading override
|
||||||
|
the default property values. If suppressErrors is true, then
|
||||||
|
this routine tries to always avoid failure. */
|
||||||
private static Properties getPropertiesFromStream(InputStream in,
|
private static Properties getPropertiesFromStream(InputStream in,
|
||||||
boolean suppressErrors,
|
boolean suppressErrors,
|
||||||
Properties defaults)
|
Properties defaults)
|
||||||
throws NullPointerException
|
|
||||||
{
|
{
|
||||||
Properties options;
|
Properties options;
|
||||||
if (defaults == null)
|
if (defaults == null)
|
||||||
|
|
Loading…
Reference in a new issue