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,6 +130,7 @@ 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() {
|
||||||
|
if (!clearedPrefs) {
|
||||||
try {
|
try {
|
||||||
RecentlyOpenedFilesDatabase.storeRecentlyOpenedFilePreferences();
|
RecentlyOpenedFilesDatabase.storeRecentlyOpenedFilePreferences();
|
||||||
|
|
||||||
|
@ -140,26 +141,35 @@ public class Jskad extends JPanel implements DocumentListener {
|
||||||
JOptionPane.PLAIN_MESSAGE);
|
JOptionPane.PLAIN_MESSAGE);
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
System.out.println("IO Exception saving user preferences to " + ThdlOptions.getUserPreferencesPath());
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
ioe.printStackTrace();
|
"Could not save to your preferences file!",
|
||||||
ThdlDebug.noteIffyCode();
|
"Error Saving Preferences",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
|
||||||
ioe.printStackTrace();
|
|
||||||
ThdlDebug.noteIffyCode();
|
|
||||||
}
|
|
||||||
JOptionPane.showMessageDialog(Jskad.this,
|
JOptionPane.showMessageDialog(Jskad.this,
|
||||||
"You must now exit this application and restart\nbefore default preferences will take effect.",
|
"Could not delete your preferences file!",
|
||||||
|
"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",
|
"Clearing Preferences",
|
||||||
JOptionPane.PLAIN_MESSAGE);
|
JOptionPane.YES_NO_OPTION)) {
|
||||||
|
exitAction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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) {
|
||||||
|
if (null != userProperties) {
|
||||||
answer = userProperties.getProperty(optionName, "false");
|
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,8 +118,10 @@ 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) {
|
||||||
|
if (null != userProperties) {
|
||||||
answer = userProperties.getProperty(optionName, null);
|
answer = userProperties.getProperty(optionName, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,8 +174,10 @@ 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) {
|
||||||
|
if (null != userProperties) {
|
||||||
answer = userProperties.getProperty(optionName, null);
|
answer = userProperties.getProperty(optionName, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (null == answer) {
|
if (null == answer) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -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