Updated the build system so that you must do a cvs checkout of the
'Fonts' module inside the 'Jskad' module. I.e., you must now have the tree like so: Jskad/ source/ dist/ Fonts/ TibetanMachineWeb/ . . . This is because the THDL tools now optionally (and by default) load the TibetanMachineWeb fonts automatically. Updated the build system so that the 'web-start-releases' and 'self-contained-dist' targets JAR up optional JARs to create double-clickable, self-contained joy. Even the TMW fonts are in the JARs now. Changed the strings describing two Jskad keyboards so that "keyboard" is no longer in the description. It's in the label next to the combo box. Jskad now saves preferences on exit or when the user selects a menu item (that is there for debugging mainly) to ~/my_thdl_preferences.txt on *nix or C:\my_thdl_preferences.txt on Win32. I don't know the correct Mac location. There's a new paradigm for telling org.thdl.util.ThdlOptions that a user preference has been changed. If, for example, a combo box is manipulated so that the ACIP keyboard is selected, then you must call a certain method in ThdlOptions.
This commit is contained in:
parent
77b8c5e424
commit
d200b03d66
12 changed files with 529 additions and 93 deletions
73
source/org/thdl/util/OperatingSystemUtils.java
Normal file
73
source/org/thdl/util/OperatingSystemUtils.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
The contents of this file are subject to the THDL Open Community License
|
||||
Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License on the THDL web site
|
||||
(http://www.thdl.org/).
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
License for the specific terms governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
||||
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
||||
All Rights Reserved.
|
||||
|
||||
Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
package org.thdl.util;
|
||||
|
||||
/** This class contains our operating-system-specific code. This
|
||||
* class is not instantiable.
|
||||
*/
|
||||
public class OperatingSystemUtils {
|
||||
|
||||
/** This means that, because of security restrictions or the like,
|
||||
* we cannot determine the OS. */
|
||||
public static final int UNKNOWN = 0;
|
||||
/** Not WIN32, not MAC -- maybe a *nix box. */
|
||||
public static final int OTHER = 1;
|
||||
/** Windows 9x, Me, 200*, or XP */
|
||||
public static final int WIN32 = 2;
|
||||
/** Mac (OS X or otherwise) */
|
||||
public static final int MAC = 3;
|
||||
|
||||
/** Do not instantiate this class. */
|
||||
private OperatingSystemUtils() { }
|
||||
|
||||
/** cached result of {@link #getOSName()} */
|
||||
private static String OSName = null;
|
||||
|
||||
/** Returns the lowercase name of the operating system, or
|
||||
* "unknown" if the operating system's identity cannot be
|
||||
* determined. */
|
||||
public static String getOSName() {
|
||||
if (null == OSName) {
|
||||
try {
|
||||
OSName = System.getProperty("os.name").toLowerCase();
|
||||
} catch (SecurityException e) {
|
||||
OSName = null;
|
||||
}
|
||||
if (null == OSName) {
|
||||
OSName = "unknown";
|
||||
}
|
||||
}
|
||||
return OSName;
|
||||
}
|
||||
|
||||
/** Returns either {@link #UNKNOWN}, {@link #WIN32}, {@link #MAC},
|
||||
* or {@link #OTHER}. */
|
||||
public static int getOSType() {
|
||||
String os = getOSName();
|
||||
if (os.startsWith("mac")) {
|
||||
return MAC;
|
||||
} else if (os.startsWith("win")) {
|
||||
return WIN32;
|
||||
} else if (os.equals("unknown")) {
|
||||
return UNKNOWN;
|
||||
} else {
|
||||
return OTHER;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -138,6 +138,7 @@ public class ThdlActionListener implements ActionListener {
|
|||
class. Handle it well so that users know what's up: */
|
||||
ThdlDebug.handleClasspathError(null, err);
|
||||
} catch (Throwable t) {
|
||||
/* FIXME: make aborting optional, and have it off by default */
|
||||
System.err.println("THDL_ERR 106: This application failed due to the following exception: ");
|
||||
t.printStackTrace(System.err);
|
||||
System.exit(1);
|
||||
|
|
|
@ -20,11 +20,14 @@ package org.thdl.util;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.thdl.util.ThdlLazyException;
|
||||
import org.thdl.util.OperatingSystemUtils;
|
||||
|
||||
/**
|
||||
* Provides a clean interface to the multi-tiered system of user
|
||||
|
@ -184,7 +187,10 @@ public final class ThdlOptions {
|
|||
}
|
||||
|
||||
private static boolean suppressErrs() {
|
||||
return false; /* FIXME--make THIS configurable. */
|
||||
return false;
|
||||
/* FIXME--make THIS configurable. It's not a simple thing,
|
||||
* though, since you can't use the usual prefences mechanism
|
||||
* because it helps to implement that mechanism. */
|
||||
}
|
||||
private static void init() {
|
||||
try {
|
||||
|
@ -246,10 +252,8 @@ public final class ThdlOptions {
|
|||
|
||||
// Get the user's properties, if they've set any:
|
||||
userProperties
|
||||
= tryToGetPropsFromFile("thdl.user.options.file",
|
||||
// FIXME this default is
|
||||
// system-dependent:
|
||||
"C:\\thdl_uopt.txt",
|
||||
= tryToGetPropsFromFile("thdl.user.options.directory", // DLC NOW FIXME: put in options.txt
|
||||
getUserPreferencesPath(),
|
||||
systemWideProperties,
|
||||
suppressErrors);
|
||||
} catch (SecurityException e) {
|
||||
|
@ -285,8 +289,13 @@ public final class ThdlOptions {
|
|||
boolean suppressErrors)
|
||||
throws FileNotFoundException, SecurityException
|
||||
{
|
||||
Properties props = defaultProps;
|
||||
String systemPropFileName = System.getProperty(pName, defaultLoc);
|
||||
|
||||
/* The empty string means "use the default location". See
|
||||
* options.txt. */
|
||||
if ("".equals(systemPropFileName))
|
||||
systemPropFileName = defaultLoc;
|
||||
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(systemPropFileName);
|
||||
|
@ -297,12 +306,12 @@ public final class ThdlOptions {
|
|||
if (!suppressErrors)
|
||||
throw e;
|
||||
} else {
|
||||
// definitely suppress this. On a Mac or
|
||||
// Unix/Linux box, this'll happen every time
|
||||
// at present. (FIXME)
|
||||
// definitely suppress this. On a Mac, I think
|
||||
// this'll happen every time at present. (FIXME)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Properties props = defaultProps;
|
||||
if (fis != null) {
|
||||
props = getPropertiesFromStream(fis,
|
||||
suppressErrors,
|
||||
|
@ -347,8 +356,112 @@ public final class ThdlOptions {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Saves the user's preferences to a file whose path is the value
|
||||
* of {@link #getUserPreferencesPath()}. You must call
|
||||
* <code>setUserPreference(..)</code> for this to be effective.
|
||||
* @throws IOException if an IO exception occurs while writing to
|
||||
* the disk. */
|
||||
public static void saveUserPreferences() throws IOException {
|
||||
if (null != userProperties) {
|
||||
userProperties.store(new FileOutputStream(getUserPreferencesPath()),
|
||||
" This file was automatically created by a THDL tool.\n"
|
||||
+ "# You may edit this file, but it will be recreated,\n"
|
||||
+ "# so your comments will be lost.\n"
|
||||
+ "# \n"
|
||||
+ "# To understand this file's contents, please see\n"
|
||||
+ "# options.txt in the JAR file.\n"
|
||||
+ "# \n"
|
||||
+ "# Note that this is the user-specific preferences file.\n"
|
||||
+ "# This tool also supports a system-specific preferences\n"
|
||||
+ "# file, which the user-specific preferences override.\n"
|
||||
+ "# \n"
|
||||
+ "# Note also that you can set a JVM preference at run-time.\n"
|
||||
+ "# Doing so will override both system- and user-specific\n"
|
||||
+ "# preferences. On many systems, you do this like so:\n"
|
||||
+ "# 'java -Dthdl.default.tibetan.font.size=36 -jar Jskad.jar'\n"
|
||||
+ "# \n"
|
||||
+ "# There is, unfortunately, no further documentation on the\n"
|
||||
+ "# preferences mechanism at this time. Yell for it!\n"
|
||||
+ "# \n"
|
||||
+ "# Created at:"); // DLC FIXME: document the preferences mechanism.
|
||||
}
|
||||
}
|
||||
|
||||
/** This returns the location of the user's preferences file.
|
||||
* This value may be overridden, by, you guessed it, a JVM,
|
||||
* built-in, or system-wide preference
|
||||
* <code>thdl.user.options.directory</code>
|
||||
*/
|
||||
public static String getUserPreferencesPath() {
|
||||
String defaultUserDir;
|
||||
switch (OperatingSystemUtils.getOSType()) {
|
||||
case OperatingSystemUtils.MAC:
|
||||
// where? DLC FIXME
|
||||
defaultUserDir = "/tmp";
|
||||
break;
|
||||
case OperatingSystemUtils.WIN32:
|
||||
defaultUserDir = "C:\\";
|
||||
break;
|
||||
default:
|
||||
//put linux etc. here
|
||||
defaultUserDir = "/tmp";
|
||||
break;
|
||||
}
|
||||
|
||||
String defaultLoc = System.getProperty("user.home", defaultUserDir);
|
||||
String systemsOverridingValue
|
||||
= System.getProperty("thdl.user.options.directory", defaultLoc);
|
||||
|
||||
return (new File(systemsOverridingValue,
|
||||
"my_thdl_preferences.txt")).getPath();
|
||||
}
|
||||
|
||||
/** In order to save preferences, this class must know that the
|
||||
* user (explicitly or implicitly) has changed a preference,
|
||||
* either through selecting something in a ComboBox, going
|
||||
* through a Preferences GUI, or the like. Calling this method
|
||||
* indicates that the user has changed an integer-valued
|
||||
* preference pref to value.
|
||||
* @param pref the preference the user is setting
|
||||
* @param value the user's new preference
|
||||
*/
|
||||
public static void setUserPreference(String pref, int value) {
|
||||
if (userProperties == null) {
|
||||
userProperties = new Properties(); // empty
|
||||
} // else leave it as is.
|
||||
userProperties.setProperty(pref, String.valueOf(value));
|
||||
}
|
||||
|
||||
/** In order to save preferences, this class must know that the
|
||||
* user (explicitly or implicitly) has changed a preference,
|
||||
* either through selecting something in a ComboBox, going
|
||||
* through a Preferences GUI, or the like. Calling this method
|
||||
* indicates that the user has changed a boolean-valued
|
||||
* preference pref to value.
|
||||
* @param pref the preference the user is setting
|
||||
* @param value the user's new preference
|
||||
*/
|
||||
public static void setUserPreference(String pref, boolean value) {
|
||||
if (userProperties == null) {
|
||||
userProperties = new Properties(); // empty
|
||||
} // else leave it as is.
|
||||
userProperties.setProperty(pref, String.valueOf(value));
|
||||
}
|
||||
|
||||
/** In order to save preferences, this class must know that the
|
||||
* user (explicitly or implicitly) has changed a preference,
|
||||
* either through selecting something in a ComboBox, going
|
||||
* through a Preferences GUI, or the like. Calling this method
|
||||
* indicates that the user has changed a String-valued preference
|
||||
* pref to value.
|
||||
* @param pref the preference the user is setting
|
||||
* @param value the user's new preference
|
||||
*/
|
||||
public static void setUserPreference(String pref, String value) {
|
||||
if (userProperties == null) {
|
||||
userProperties = new Properties(); // empty
|
||||
} // else leave it as is.
|
||||
userProperties.setProperty(pref, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue