2002-09-28 14:42:01 +00:00
|
|
|
/*
|
|
|
|
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): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
2002-09-28 00:53:39 +00:00
|
|
|
package org.thdl.savant;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
import javax.swing.filechooser.*;
|
|
|
|
|
2002-10-06 18:23:27 +00:00
|
|
|
import org.thdl.util.ThdlDebug;
|
Added a flexible mechanism for persistent boolean-, integer-, and
string-valued preferences built atop java.util.Properties.
How it works: the jvm is asked first, and then the user's prefs file, if it exists,
then the system-wide prefs file, and then the built-in preferences. Finally, for
robustness, a default may be optionally hard-coded in the source.
I made several things configurable, too:
the default Tibetan keyboard
the default font sizes and faces
whether you want developer-only features enabled
Savant's file extension (.savant)
etc.
The only known problems are the following:
The default location for the user's preferences file is windows-specific,
arbitrary, and not in the user documentation. Likewise for the location of the
system-wide preferences file. You can change them using 'java -D', though.
There is no "Save preferences" option yet, and closing the program does
not save preferences either.
2002-10-14 04:06:05 +00:00
|
|
|
import org.thdl.util.ThdlOptions;
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The SavantFileView "sees through" a <code>*.savant</code> file and
|
|
|
|
* returns the title associated with it. A <code>*.savant</code> file
|
|
|
|
* is a properties file like the following:
|
|
|
|
* <pre>
|
|
|
|
* #Tue May 14 16:07:15 EDT 2002
|
|
|
|
* TRANSCRIPT=MST4.xml
|
|
|
|
* PROJECT=THDL
|
|
|
|
* MEDIA=MST4.mpg
|
|
|
|
* TITLE=MST Chapter 4 (video)
|
|
|
|
* </pre>
|
|
|
|
* @author Edward Garrett */
|
2002-09-28 00:53:39 +00:00
|
|
|
public class SavantFileView extends FileView {
|
2002-10-06 18:23:27 +00:00
|
|
|
/** When opening a file, this is the only extension Savant cares
|
|
|
|
about. This is case-insensitive. */
|
Added a flexible mechanism for persistent boolean-, integer-, and
string-valued preferences built atop java.util.Properties.
How it works: the jvm is asked first, and then the user's prefs file, if it exists,
then the system-wide prefs file, and then the built-in preferences. Finally, for
robustness, a default may be optionally hard-coded in the source.
I made several things configurable, too:
the default Tibetan keyboard
the default font sizes and faces
whether you want developer-only features enabled
Savant's file extension (.savant)
etc.
The only known problems are the following:
The default location for the user's preferences file is windows-specific,
arbitrary, and not in the user documentation. Likewise for the location of the
system-wide preferences file. You can change them using 'java -D', though.
There is no "Save preferences" option yet, and closing the program does
not save preferences either.
2002-10-14 04:06:05 +00:00
|
|
|
public final static String getDotSavant() {
|
|
|
|
return ThdlOptions.getStringOption("thdl.savant.file.extension",
|
|
|
|
".savant");
|
|
|
|
}
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
/** This loads <code>*.savant</code> files as properties files and
|
|
|
|
returns an associated TITLE attribute. For any other type of
|
|
|
|
file, or for a properties file that does not specify a
|
|
|
|
non-empty-string TITLE attribute, this returns null. */
|
2002-09-28 00:53:39 +00:00
|
|
|
public String getName(File f) {
|
|
|
|
if (f.isDirectory())
|
|
|
|
return null;
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
/* Unless a developer has chosen to do otherwise, examine only
|
|
|
|
*.savant files. If you don't do this, you waste a lot of
|
|
|
|
time, making any file chooser that uses this class
|
|
|
|
unresponsive. In addition, you'll cause the floppy drive
|
|
|
|
to spin up every time you refresh or cd in the file
|
|
|
|
chooser. */
|
Added a flexible mechanism for persistent boolean-, integer-, and
string-valued preferences built atop java.util.Properties.
How it works: the jvm is asked first, and then the user's prefs file, if it exists,
then the system-wide prefs file, and then the built-in preferences. Finally, for
robustness, a default may be optionally hard-coded in the source.
I made several things configurable, too:
the default Tibetan keyboard
the default font sizes and faces
whether you want developer-only features enabled
Savant's file extension (.savant)
etc.
The only known problems are the following:
The default location for the user's preferences file is windows-specific,
arbitrary, and not in the user documentation. Likewise for the location of the
system-wide preferences file. You can change them using 'java -D', though.
There is no "Save preferences" option yet, and closing the program does
not save preferences either.
2002-10-14 04:06:05 +00:00
|
|
|
if (!ThdlOptions.getBooleanOption("thdl.treat.all.files.as.dot.savant.files.regardless.of.extension")) { /* FIXME */
|
|
|
|
if (!f.getName().toLowerCase().endsWith(getDotSavant()))
|
2002-10-06 18:23:27 +00:00
|
|
|
return null;
|
|
|
|
}
|
2002-09-28 00:53:39 +00:00
|
|
|
Properties p = new Properties();
|
|
|
|
try {
|
|
|
|
p.load(new FileInputStream(f));
|
2002-10-06 18:23:27 +00:00
|
|
|
String ttl = p.getProperty("TITLE");
|
|
|
|
if (ttl.equals(""))
|
|
|
|
return null; /* We never want the user to see nothing
|
|
|
|
at all, so let the L&F file view
|
|
|
|
handle this. */
|
|
|
|
else
|
|
|
|
return ttl;
|
2002-09-28 00:53:39 +00:00
|
|
|
} catch (FileNotFoundException fnfe) {
|
|
|
|
fnfe.printStackTrace();
|
2002-10-06 18:23:27 +00:00
|
|
|
ThdlDebug.noteIffyCode();
|
2002-09-28 00:53:39 +00:00
|
|
|
} catch (IOException ioe) {
|
|
|
|
ioe.printStackTrace();
|
2002-10-06 18:23:27 +00:00
|
|
|
ThdlDebug.noteIffyCode();
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
/** Returns null always, which lets the default look-and-feel's
|
|
|
|
* FileView take over.
|
|
|
|
* @return null */
|
2002-09-28 00:53:39 +00:00
|
|
|
public String getDescription(File f) {
|
2002-10-06 18:23:27 +00:00
|
|
|
return null; // let the L&F FileView figure this out
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
/** Returns null always, which lets the default look-and-feel's
|
|
|
|
* FileView take over.
|
|
|
|
* @return null */
|
2002-09-28 00:53:39 +00:00
|
|
|
public Boolean isTraversable(File f) {
|
|
|
|
return null; // let the L&F FileView figure this out
|
|
|
|
}
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
/** Returns null always, which lets the default look-and-feel's
|
|
|
|
* FileView take over.
|
|
|
|
* @return null */
|
2002-09-28 00:53:39 +00:00
|
|
|
public String getTypeDescription(File f) {
|
2002-10-06 18:23:27 +00:00
|
|
|
return null; // let the L&F FileView figure this out
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
/* FIXME: why not same as above? */
|
2002-09-28 00:53:39 +00:00
|
|
|
/*
|
|
|
|
public Icon getIcon(File f) {
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|