2002-10-04 04:52:41 +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
2003-02-01 06:42:07 +00:00
Library ( THDL ) . Portions created by the THDL are Copyright 2001 - 2003 THDL .
2002-10-04 04:52:41 +00:00
All Rights Reserved .
Contributor ( s ) : ______________________________________ .
* /
package org.thdl.tib.input ;
import java.io.* ;
import java.net.URL ;
import java.awt.* ;
import java.awt.event.* ;
import java.awt.print.* ;
import javax.swing.plaf.basic.* ;
import javax.swing.* ;
import javax.swing.event.* ;
import javax.swing.text.* ;
import javax.swing.text.rtf.* ;
2002-10-20 08:02:16 +00:00
import java.util.Vector ;
2002-10-04 04:52:41 +00:00
import org.thdl.tib.text.* ;
2002-10-06 18:23:27 +00:00
import org.thdl.util.ThdlDebug ;
2003-06-29 03:03:07 +00:00
import org.thdl.util.RTFFixerInputStream ;
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-11-16 19:18:44 +00:00
import org.thdl.util.ThdlVersion ;
2002-10-13 19:22:56 +00:00
import org.thdl.util.StatusBar ;
import org.thdl.util.ThdlActionListener ;
2003-02-01 06:42:07 +00:00
import org.thdl.util.HTMLPane ;
2002-10-13 20:42:23 +00:00
import org.thdl.util.SimpleFrame ;
import org.thdl.util.ThdlLazyException ;
2002-10-13 19:22:56 +00:00
2003-07-05 22:25:21 +00:00
import calpa.html.CalHTMLPane ;
2002-10-06 18:23:27 +00:00
2002-10-04 04:52:41 +00:00
/ * *
* A simple Tibetan text editor . Jskad editors lack most of the
* functionality of a word - processor , but they do provide
* multiple keyboard input methods , as well as
* conversion routines to go back and forth between Extended
* Wylie and TibetanMachineWeb .
* < p >
* Jskad embeds { @link DuffPane DuffPane } , which is the editing
* window where the keyboard logic and most functionality is housed .
* < p >
* Depending on the object passed to the constructor ,
* a Jskad object can be used in either an application or an
* applet .
* @author Edward Garrett , Tibetan and Himalayan Digital Library
* @version 1 . 0
* /
public class Jskad extends JPanel implements DocumentListener {
2003-07-04 02:31:23 +00:00
/** Sets the focus to the DuffPane if possible. */
private void focusToDuffPane ( ) {
2003-07-05 02:30:00 +00:00
if ( null ! = dp & & ! dp . hasFocus ( ) ) dp . grabFocus ( ) ;
2003-07-04 02:31:23 +00:00
}
2002-10-13 19:22:56 +00:00
/ * * the name of the property a developer should set to see
low - level info on how keypresses in " Tibetan " input mode are
being interpreted * /
private final static String enableKeypressStatusProp
= " thdl.Jskad.enable.tibetan.mode.status " ;
2002-10-27 19:12:13 +00:00
/ * * the middleman that keeps code regarding Tibetan keyboards
* clean * /
2003-05-14 03:25:36 +00:00
private final static JskadKeyboardManager keybdMgr ;
static {
try {
keybdMgr
= new JskadKeyboardManager ( JskadKeyboardFactory . getAllAvailableJskadKeyboards ( ) ) ;
} catch ( Exception e ) {
throw new ThdlLazyException ( e ) ;
}
}
2002-10-27 19:12:13 +00:00
2003-10-18 18:29:46 +00:00
// private JComboBox fontFamilies, fontSizes;
private JFileChooser fileChooser ;
private javax . swing . filechooser . FileFilter rtfFilter ;
private javax . swing . filechooser . FileFilter txtFilter ;
// private int fontSize = 0;
private Object parentObject = null ;
private static int numberOfTibsRTFOpen = 0 ;
private static int x_size ;
private static int y_size ;
2002-10-04 04:52:41 +00:00
/ * *
* The text editing window which this Jskad object embeds .
* /
2003-10-18 18:29:46 +00:00
public DuffPane dp ;
2002-10-04 04:52:41 +00:00
/ * *
* Has the document been saved since it was last changed ?
* /
2003-10-18 18:29:46 +00:00
public boolean hasChanged = false ;
2002-10-04 04:52:41 +00:00
/ * *
* The filename , if any , associated with this instance of Jskad .
* /
2003-10-18 18:29:46 +00:00
public String fileName = null ;
private PreferenceWindow prefWindow ;
2002-10-04 04:52:41 +00:00
2002-10-13 19:22:56 +00:00
/** the status bar for this frame */
private StatusBar statusBar ;
2002-11-03 17:05:44 +00:00
/** Do not use this JPanel constructor. */
private Jskad ( ) { super ( ) ; }
/** Do not use this JPanel constructor. */
private Jskad ( boolean isDB ) { super ( isDB ) ; }
/** Do not use this JPanel constructor. */
private Jskad ( LayoutManager lm ) { super ( lm ) ; }
/** Do not use this JPanel constructor. */
private Jskad ( LayoutManager lm , boolean isDB ) { super ( lm , isDB ) ; }
2003-08-09 07:57:21 +00:00
/** Invokes to window to customize fonts. */
2003-10-18 18:29:46 +00:00
private void setPreferences ( )
{
if ( prefWindow = = null ) prefWindow = new PreferenceWindow ( this , dp ) ;
prefWindow . show ( ) ;
}
2002-11-18 16:12:25 +00:00
/** Saves user preferences to disk if possible. */
2003-06-21 01:26:17 +00:00
private void savePreferencesAction ( ) {
2003-07-06 16:24:29 +00:00
if ( ! clearedPrefs ) {
try {
RecentlyOpenedFilesDatabase . storeRecentlyOpenedFilePreferences ( ) ;
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 ) {
2003-06-21 01:26:17 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
2003-07-06 16:24:29 +00:00
" Could not save to your preferences file! " ,
" Error Saving Preferences " ,
JOptionPane . ERROR_MESSAGE ) ;
2003-06-21 01:26:17 +00:00
}
2002-11-18 16:12:25 +00:00
}
}
2003-07-06 16:24:29 +00:00
private static boolean clearedPrefs = false ;
2003-06-21 01:26:17 +00:00
/ * * Clears user preferences by deleting the preferences file on
disk . Prompts the user to quit and reopen Jskad . * /
private void clearPreferencesAction ( ) {
2003-07-06 16:24:29 +00:00
clearedPrefs = true ;
2003-06-21 01:26:17 +00:00
try {
ThdlOptions . clearUserPreferences ( ) ;
} catch ( IOException ioe ) {
2003-07-06 16:24:29 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
" 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 " ,
JOptionPane . YES_NO_OPTION ) ) {
exitAction ( ) ;
2003-06-21 01:26:17 +00:00
}
}
2003-07-04 03:29:25 +00:00
/** the File menu */
2003-07-04 02:31:23 +00:00
private JMenu fileMenu = null ;
2003-07-04 03:29:25 +00:00
/ * * Updates state information now that we know that fileChosen is
the most recently opened file . * /
private static void noteMostRecentlyOpenedFile ( File fileChosen ) {
2003-07-05 02:15:33 +00:00
RecentlyOpenedFilesDatabase . setMostRecentlyOpenedFile ( fileChosen ) ;
2003-07-04 03:29:25 +00:00
int i , sz = jskads . size ( ) ;
for ( i = 0 ; i < sz ; i + + ) {
( ( Jskad ) jskads . elementAt ( i ) ) . updateRecentlyOpenedFilesMenuItems ( ) ;
}
}
2003-07-04 02:31:23 +00:00
2003-07-04 03:29:25 +00:00
private void updateRecentlyOpenedFilesMenuItems ( ) {
int ic = fileMenu . getItemCount ( ) ;
while ( fileMenu . getItemCount ( ) > 8 )
fileMenu . remove ( 7 ) ;
2003-07-05 02:15:33 +00:00
int N = RecentlyOpenedFilesDatabase . getNumberOfFilesToShow ( ) ;
2003-07-04 03:29:25 +00:00
// Avoid adding duplicate entries:
boolean addedSeparator = false ;
for ( int i = 0 ; i < N ; i + + ) {
final File recentlyOpenedFile
2003-07-05 02:15:33 +00:00
= RecentlyOpenedFilesDatabase . getNthRecentlyOpenedFile ( N - i - 1 ) ;
2003-07-04 03:29:25 +00:00
if ( null ! = recentlyOpenedFile ) {
if ( ! addedSeparator ) {
fileMenu . insertSeparator ( 6 ) ;
addedSeparator = true ;
}
2003-07-05 02:15:33 +00:00
JMenuItem item = new JMenuItem ( ( N - i ) + " "
+ RecentlyOpenedFilesDatabase . getLabel ( recentlyOpenedFile ) ) ;
2003-07-04 03:29:25 +00:00
item . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
openFile ( recentlyOpenedFile ) ;
}
} ) ;
fileMenu . add ( item , 7 ) ;
}
}
2003-07-04 02:31:23 +00:00
}
2002-10-04 04:52:41 +00:00
/ * *
* @param parent the object that embeds this instance of Jskad .
* Supported objects include JFrames and JApplets . If the parent
* is a JApplet then the File menu is omitted from the menu bar .
* /
2003-10-18 18:29:46 +00:00
public Jskad ( final Object parent ) {
2002-11-03 17:05:44 +00:00
super ( ) ;
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.Jskad.disable.status.bar " ) ) {
2002-10-13 19:22:56 +00:00
statusBar = null ;
} else {
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
statusBar
= new StatusBar ( ThdlOptions . getStringOption ( " thdl.Jskad.initial.status.message " ,
" Welcome to Jskad! " ) ) ;
2002-10-13 19:22:56 +00:00
}
2003-10-18 18:29:46 +00:00
parentObject = parent ;
numberOfTibsRTFOpen + + ;
JMenuBar menuBar = new JMenuBar ( ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( parentObject instanceof JFrame | | parentObject instanceof JInternalFrame ) {
2003-03-11 01:03:19 +00:00
String whereToStart
= ThdlOptions . getStringOption ( " thdl.Jskad.working.directory " ,
null ) ;
2003-07-13 23:19:11 +00:00
try {
fileChooser
= new JFileChooser ( ( whereToStart = = null )
? null
: ( whereToStart . equals ( " " )
? null
: whereToStart ) ) ;
} catch ( NullPointerException e ) {
// This weirdness happens to me when I edit .java
// files in the midst of an 'ant clean jskad-run':
System . err . println ( " Jskad was not cleanly compiled; please rebuild! " ) ;
2004-01-17 16:51:33 +00:00
System . err . println ( " Messy details: " ) ;
System . err . println ( " " ) ;
e . printStackTrace ( System . err ) ;
2003-07-13 23:19:11 +00:00
System . exit ( 1 ) ;
}
2003-10-18 18:29:46 +00:00
rtfFilter = new RTFFilter ( ) ;
txtFilter = new TXTFilter ( ) ;
fileChooser . addChoosableFileFilter ( rtfFilter ) ;
fileMenu = new JMenu ( " File " ) ;
2004-04-24 17:49:16 +00:00
JMenuItem newItem = new JMenuItem ( " New... " ) ;
2003-10-18 18:29:46 +00:00
// newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,java.awt.Event.CTRL_MASK)); //Ctrl-n
newItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
newFile ( ) ;
}
} ) ;
fileMenu . add ( newItem ) ;
JMenuItem openItem = new JMenuItem ( " Open... " ) ;
// openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,java.awt.Event.CTRL_MASK)); //Ctrl-o
openItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
openFile ( ) ;
}
} ) ;
fileMenu . add ( openItem ) ;
if ( parentObject instanceof JFrame ) {
JMenuItem closeItem = new JMenuItem ( " Close " ) ;
closeItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-07-04 00:21:07 +00:00
if ( numberOfTibsRTFOpen = = 1 ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" You cannot close the last Jskad window. \ nUse File/Exit if you intend to exit. " ,
" Cannot close last Jskad window " ,
JOptionPane . ERROR_MESSAGE ) ;
} else {
if ( ! hasChanged | | hasChanged & & checkSave ( JOptionPane . YES_NO_CANCEL_OPTION ) ) {
Jskad . this . realCloseAction ( true ) ;
}
}
2003-10-18 18:29:46 +00:00
}
} ) ;
fileMenu . add ( closeItem ) ;
2003-06-21 02:07:51 +00:00
}
2003-10-18 18:29:46 +00:00
JMenuItem saveItem = new JMenuItem ( " Save " ) ;
// saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,java.awt.Event.CTRL_MASK)); //Ctrl-s
saveItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
if ( fileName = = null )
saveAsFile ( ) ;
else
saveFile ( ) ;
}
} ) ;
fileMenu . addSeparator ( ) ;
fileMenu . add ( saveItem ) ;
JMenuItem saveAsItem = new JMenuItem ( " Save as... " ) ;
saveAsItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
saveAsFile ( ) ;
}
} ) ;
fileMenu . add ( saveAsItem ) ;
if ( parentObject instanceof JFrame ) {
JMenuItem exitItem = new JMenuItem ( " Exit " ) ;
exitItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-06-21 02:07:51 +00:00
exitAction ( ) ;
2003-10-18 18:29:46 +00:00
}
} ) ;
fileMenu . addSeparator ( ) ;
fileMenu . add ( exitItem ) ;
}
2003-06-21 02:07:51 +00:00
2003-07-04 03:29:25 +00:00
updateRecentlyOpenedFilesMenuItems ( ) ;
2003-10-18 18:29:46 +00:00
menuBar . add ( fileMenu ) ;
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
JMenu editMenu = new JMenu ( " Edit " ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( parentObject instanceof JFrame | | parentObject instanceof JInternalFrame ) {
JMenuItem cutItem = new JMenuItem ( " Cut " ) ;
cutItem . setAccelerator ( KeyStroke . getKeyStroke ( KeyEvent . VK_X ,
2002-10-22 03:53:33 +00:00
java . awt . Event . CTRL_MASK ) ) ; //Ctrl-x
2003-10-18 18:29:46 +00:00
cutItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
cutSelection ( ) ;
}
} ) ;
editMenu . add ( cutItem ) ;
JMenuItem copyItem = new JMenuItem ( " Copy " ) ;
copyItem . setAccelerator ( KeyStroke . getKeyStroke ( KeyEvent . VK_C ,
2002-10-22 03:53:33 +00:00
java . awt . Event . CTRL_MASK ) ) ; //Ctrl-c
2003-10-18 18:29:46 +00:00
copyItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
copySelection ( ) ;
}
} ) ;
editMenu . add ( copyItem ) ;
2005-02-26 22:57:38 +00:00
JMenuItem copyAsUnicodeItem = new JMenuItem ( " Copy as Unicode " ) ;
copyAsUnicodeItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
copyAsUnicodeSelection ( ) ;
}
} ) ;
editMenu . add ( copyAsUnicodeItem ) ;
2003-10-18 18:29:46 +00:00
JMenuItem pasteItem = new JMenuItem ( " Paste " ) ;
pasteItem . setAccelerator ( KeyStroke . getKeyStroke ( KeyEvent . VK_V ,
2002-10-22 03:53:33 +00:00
java . awt . Event . CTRL_MASK ) ) ; //Ctrl-v
2003-10-18 18:29:46 +00:00
pasteItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
pasteSelection ( ) ;
}
} ) ;
editMenu . add ( pasteItem ) ;
editMenu . addSeparator ( ) ;
JMenuItem selectallItem = new JMenuItem ( " Select All " ) ;
selectallItem . setAccelerator ( KeyStroke . getKeyStroke ( KeyEvent . VK_A ,
2002-10-22 03:53:33 +00:00
java . awt . Event . CTRL_MASK ) ) ; //Ctrl-a
2003-10-18 18:29:46 +00:00
selectallItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
dp . setSelectionStart ( 0 ) ;
dp . setSelectionEnd ( dp . getDocument ( ) . getLength ( ) ) ;
}
} ) ;
editMenu . add ( selectallItem ) ;
}
2002-10-04 04:52:41 +00:00
2002-11-18 16:12:25 +00:00
{
JMenuItem preferencesItem = new JMenuItem ( " Preferences " ) ;
preferencesItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-08-09 07:57:21 +00:00
setPreferences ( ) ;
2002-11-18 16:12:25 +00:00
}
} ) ;
editMenu . addSeparator ( ) ;
editMenu . add ( preferencesItem ) ;
}
{
JMenuItem preferencesItem = new JMenuItem ( " Save preferences to " + ThdlOptions . getUserPreferencesPath ( ) ) ;
preferencesItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
savePreferencesAction ( ) ;
}
} ) ;
editMenu . add ( preferencesItem ) ;
}
2002-10-04 04:52:41 +00:00
2003-06-21 01:26:17 +00:00
{
JMenuItem preferencesItem = new JMenuItem ( " Clear preferences " ) ;
preferencesItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
clearPreferencesAction ( ) ;
}
} ) ;
editMenu . addSeparator ( ) ;
editMenu . add ( preferencesItem ) ;
}
2002-11-18 16:12:25 +00:00
menuBar . add ( editMenu ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
JMenu toolsMenu = new JMenu ( " Tools " ) ;
2002-10-04 04:52:41 +00:00
2003-07-05 21:02:46 +00:00
JMenu convertSelectionMenu = new JMenu ( " Convert Selection " ) ;
2003-10-18 18:29:46 +00:00
JMenuItem TMWWylieItem = new JMenuItem ( " Convert Tibetan to Wylie " ) ;
TMWWylieItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-11-08 23:22:06 +00:00
toTranslit ( true ) ;
2003-10-18 18:29:46 +00:00
}
} ) ;
convertSelectionMenu . add ( TMWWylieItem ) ;
2003-07-05 21:02:46 +00:00
toolsMenu . add ( convertSelectionMenu ) ;
2002-10-04 04:52:41 +00:00
2003-11-08 23:22:06 +00:00
JMenuItem TMWACIPItem = new JMenuItem ( " Convert Tibetan to ACIP " ) ;
TMWACIPItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
toTranslit ( false ) ;
}
} ) ;
convertSelectionMenu . add ( TMWACIPItem ) ;
toolsMenu . add ( convertSelectionMenu ) ;
2003-11-22 22:48:41 +00:00
JMenuItem wylieTMWItem = new JMenuItem ( " (Buggy) Convert Wylie to Tibetan " ) ;
2003-10-18 18:29:46 +00:00
wylieTMWItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-10-26 00:21:54 +00:00
toTibetan ( false , true ) ;
2003-10-18 18:29:46 +00:00
}
} ) ;
convertSelectionMenu . add ( wylieTMWItem ) ;
2003-07-05 21:02:46 +00:00
2003-10-26 00:21:54 +00:00
JMenuItem ACIPTMWItem = new JMenuItem ( " Convert ACIP to Tibetan (no warnings) " ) ;
2003-10-19 20:16:06 +00:00
ACIPTMWItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-10-26 00:21:54 +00:00
toTibetan ( true , false ) ;
2003-10-19 20:16:06 +00:00
}
} ) ;
convertSelectionMenu . add ( ACIPTMWItem ) ;
2004-05-01 20:52:22 +00:00
JMenuItem ACIPTMWWarnItem = new JMenuItem ( " Convert ACIP to Tibetan (with pedantic warnings) " ) ;
2003-10-26 00:21:54 +00:00
ACIPTMWWarnItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
toTibetan ( true , true ) ;
}
} ) ;
convertSelectionMenu . add ( ACIPTMWWarnItem ) ;
2003-07-05 21:02:46 +00:00
JMenu convertAllMenu = new JMenu ( " Convert All " ) ;
JMenuItem toTMItem = new JMenuItem ( " Convert Tibetan to TM " ) ; // DLC FIXME: do it just in the selection?
toTMItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
StringBuffer errors = new StringBuffer ( ) ;
long numAttemptedReplacements [ ] = new long [ ] { 0 } ;
boolean errorReturn
= ( ( TibetanDocument ) dp . getDocument ( ) ) . convertToTM ( 0 , - 1 , errors ,
numAttemptedReplacements ) ; // entire document
if ( errorReturn ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" At least one error occurred while converting Tibetan Machine Web \ nto Tibetan Machine. Your document is mostly converted, \ nexcept for the following glyphs, which you should replace manually \ nbefore retrying: \ n "
+ errors . toString ( ) ,
" Tibetan to TM Errors " ,
JOptionPane . PLAIN_MESSAGE ) ;
} else {
if ( numAttemptedReplacements [ 0 ] > 0 ) {
2003-06-01 23:05:32 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
2003-07-05 21:02:46 +00:00
" Converting Tibetan Machine Web to Tibetan Machine met with perfect success. " ,
" Success " ,
2003-06-01 23:05:32 +00:00
JOptionPane . PLAIN_MESSAGE ) ;
} else {
2003-07-05 21:02:46 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
" No Tibetan Machine Web was found, so nothing was converted. " ,
" Nothing to do " ,
JOptionPane . ERROR_MESSAGE ) ;
2003-06-01 23:05:32 +00:00
}
Fixed bug 617156, "DuffPane ignores setEditable(false)".
I fixed this the easy way, by checking the value of isEditable() before
cutting, pasting, or adding typed text. I may have missed a spot, but
checking at a lower level is a bit less efficient.
Fixing this the hard way, the keymaps-and-overridden-default-action way,
seems like it will make the code uglier, not cleaner. And it won't get us
closer to fixing the killer bug, 614475, "Improper Line Wrapping".
2002-10-20 05:54:29 +00:00
}
2003-07-05 21:02:46 +00:00
}
} ) ;
JMenuItem toTMWItem = new JMenuItem ( " Convert TM to Tibetan " ) ; // DLC FIXME: do it just in the selection?
toTMWItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
StringBuffer errors = new StringBuffer ( ) ;
long numAttemptedReplacements [ ] = new long [ ] { 0 } ;
boolean errorReturn
= ( ( TibetanDocument ) dp . getDocument ( ) ) . convertToTMW ( 0 , - 1 , errors ,
numAttemptedReplacements ) ; // entire document
if ( errorReturn ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" At least one error occurred while converting Tibetan Machine \ nto Tibetan Machine Web. Your document is mostly converted, \ nexcept for the following glyphs, which you should replace manually \ nbefore retrying: \ n "
+ errors . toString ( ) ,
" TM to Tibetan Errors " , JOptionPane . PLAIN_MESSAGE ) ;
} else {
if ( numAttemptedReplacements [ 0 ] > 0 ) {
2003-06-01 23:05:32 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
2003-07-05 21:02:46 +00:00
" Converting Tibetan Machine to Tibetan Machine Web met with perfect success. " ,
" Success " ,
JOptionPane . PLAIN_MESSAGE ) ;
2003-06-01 23:05:32 +00:00
} else {
2003-07-05 21:02:46 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
" No Tibetan Machine was found, so nothing was converted. " ,
" Nothing to do " ,
JOptionPane . ERROR_MESSAGE ) ;
2003-06-01 23:05:32 +00:00
}
2003-05-31 23:21:29 +00:00
}
2003-07-05 21:02:46 +00:00
}
} ) ;
2003-07-13 23:19:11 +00:00
JMenuItem toUnicodeItem = new JMenuItem ( " Convert Tibetan to Unicode " ) ; // DLC FIXME: do it just in the selection?
2003-07-05 21:02:46 +00:00
toUnicodeItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
StringBuffer errors = new StringBuffer ( ) ;
long numAttemptedReplacements [ ] = new long [ ] { 0 } ;
boolean errorReturn
= ( ( TibetanDocument ) dp . getDocument ( ) ) . convertToUnicode ( 0 , - 1 , errors ,
ThdlOptions . getStringOption ( " thdl.tmw.to.unicode.font " ) . intern ( ) ,
numAttemptedReplacements ) ; // entire document
if ( errorReturn ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" At least one error occurred while converting Tibetan Machine Web \ nto Unicode. Your document is mostly converted, \ nexcept for the following glyphs, which you should replace manually \ nbefore retrying: \ n "
+ errors . toString ( ) ,
" Tibetan to Unicode Errors " , JOptionPane . PLAIN_MESSAGE ) ;
} else {
if ( numAttemptedReplacements [ 0 ] > 0 ) {
2003-06-15 16:27:36 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
2003-07-05 21:02:46 +00:00
" Converting Tibetan Machine Web to Unicode met with perfect success. " ,
" Success " ,
JOptionPane . PLAIN_MESSAGE ) ;
2003-06-15 16:27:36 +00:00
} else {
2003-07-05 21:02:46 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
" No Tibetan Machine Web was found, so nothing was converted. " ,
" Nothing to do " ,
JOptionPane . ERROR_MESSAGE ) ;
2003-06-15 16:27:36 +00:00
}
}
2003-07-05 21:02:46 +00:00
}
} ) ;
convertAllMenu . add ( toTMItem ) ;
convertAllMenu . add ( toTMWItem ) ;
convertAllMenu . add ( toUnicodeItem ) ;
toolsMenu . add ( convertAllMenu ) ;
2003-06-29 04:18:36 +00:00
2003-10-18 18:29:46 +00:00
if ( parentObject instanceof JFrame | | parentObject instanceof JInternalFrame ) {
2003-06-29 04:18:36 +00:00
JMenuItem converterItem = new JMenuItem ( " Launch Converter... " ) ;
converterItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-06-29 16:45:15 +00:00
// ignore the return value:
ConverterGUI . realMain ( new String [ ] { } ,
System . out ,
( ( parentObject instanceof Frame )
? ( Frame ) parentObject
: null ) ) ;
2003-06-29 04:18:36 +00:00
}
} ) ;
toolsMenu . add ( converterItem ) ;
2003-07-05 21:02:46 +00:00
2003-11-09 01:25:58 +00:00
JMenuItem importItem = new JMenuItem ( " (Buggy) Import Wylie as Tibetan... " ) ;
2003-10-18 18:29:46 +00:00
importItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
importWylie ( ) ;
}
} ) ;
toolsMenu . addSeparator ( ) ;
toolsMenu . add ( importItem ) ;
2003-07-05 21:02:46 +00:00
2003-10-18 18:29:46 +00:00
JMenuItem openWithItem = new JMenuItem ( " Open With External Viewer... " ) ;
openWithItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-07-05 21:02:46 +00:00
openWithExternalViewer ( ) ;
2003-10-18 18:29:46 +00:00
}
} ) ;
toolsMenu . addSeparator ( ) ;
toolsMenu . add ( openWithItem ) ;
2003-07-05 21:02:46 +00:00
Fixed bug 617156, "DuffPane ignores setEditable(false)".
I fixed this the easy way, by checking the value of isEditable() before
cutting, pasting, or adding typed text. I may have missed a spot, but
checking at a lower level is a bit less efficient.
Fixing this the hard way, the keymaps-and-overridden-default-action way,
seems like it will make the code uglier, not cleaner. And it won't get us
closer to fixing the killer bug, 614475, "Improper Line Wrapping".
2002-10-20 05:54:29 +00:00
}
2003-05-31 23:21:29 +00:00
2003-05-18 14:14:47 +00:00
if ( ThdlOptions . getBooleanOption ( " thdl.add.developer.options.to.menu " ) ) {
toolsMenu . addSeparator ( ) ;
2003-05-31 23:21:29 +00:00
JMenuItem DevelItem = new JMenuItem ( " Toggle read-only " ) ;
2003-05-18 14:14:47 +00:00
DevelItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-05-31 23:21:29 +00:00
dp . setEditable ( ! dp . isEditable ( ) ) ;
2003-05-18 14:14:47 +00:00
}
} ) ;
toolsMenu . add ( DevelItem ) ;
}
2003-06-30 02:22:09 +00:00
// I used this when I validated the TM<->TMW mappings; I made
// dp.romanAttributeSet public to do so:
//
2003-11-29 16:22:26 +00:00
// if (ThdlOptions.getBooleanOption("thdl.add.developer.options.to.menu")) {
// toolsMenu.addSeparator();
// JMenuItem DevelItem = new JMenuItem("Insert All TM Glyphs in Doc");
// DevelItem.addActionListener(new ThdlActionListener() {
// public void theRealActionPerformed(ActionEvent e) {
// ((TibetanDocument)dp.getDocument()).insertAllTMGlyphs2();
// }
// });
// toolsMenu.add(DevelItem);
// }
2003-06-30 02:22:09 +00:00
2003-06-29 03:03:07 +00:00
if ( ThdlOptions . getBooleanOption ( " thdl.add.developer.options.to.menu " ) ) {
toolsMenu . addSeparator ( ) ;
JMenuItem DevelItem = new JMenuItem ( " Debug dump to standard output " ) ;
DevelItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
StringBuffer buf = new StringBuffer ( ) ;
( ( TibetanDocument ) dp . getDocument ( ) ) . getTextRepresentation ( 0 , - 1 , buf ) ;
System . out . println ( " The text representation of the document, for debugging, is this: \ n " + buf ) ;
}
} ) ;
toolsMenu . add ( DevelItem ) ;
}
2003-05-18 14:14:47 +00:00
if ( ThdlOptions . getBooleanOption ( " thdl.add.developer.options.to.menu " ) ) {
toolsMenu . addSeparator ( ) ;
2003-05-31 23:21:29 +00:00
JMenuItem DevelItem = new JMenuItem ( " Check for non-TMW characters " ) ; // FIXME: do it just in the selection?
2003-05-18 14:14:47 +00:00
DevelItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-05-31 23:21:29 +00:00
( ( TibetanDocument ) dp . getDocument ( ) ) . findSomeNonTMWCharacters ( 0 , - 1 ) ; // entire document.
2003-05-18 14:14:47 +00:00
}
} ) ;
toolsMenu . add ( DevelItem ) ;
}
2003-10-18 18:29:46 +00:00
menuBar . add ( toolsMenu ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
JMenu helpMenu = new JMenu ( " Help " ) ;
2002-10-04 04:52:41 +00:00
2003-02-01 06:42:07 +00:00
{
2004-04-24 17:49:16 +00:00
JMenuItem helpItem = new JMenuItem ( " Help... " ) ;
2003-02-01 06:42:07 +00:00
helpItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2003-07-05 22:25:21 +00:00
CalHTMLPane helpPane = new CalHTMLPane ( ) ;
try {
URL helpDocumentURL
= Jskad . class . getResource ( " /org/thdl/tib/input/jskad_doc.html " ) ;
helpPane . showHTMLDocument ( helpDocumentURL ) ;
} catch ( Exception ex ) {
ex . printStackTrace ( System . err ) ;
throw new ThdlLazyException ( ex ) ;
2003-02-01 06:42:07 +00:00
}
new SimpleFrame ( " Help for Jskad " , helpPane ) ;
}
} ) ;
2003-07-05 22:25:21 +00:00
helpMenu . add ( helpItem ) ;
}
{
2004-04-24 17:49:16 +00:00
JMenuItem helpItem = new JMenuItem ( " Jskad on the Web... " ) ;
2003-07-05 22:25:21 +00:00
helpItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
CalHTMLPane onlineHelpPane = new CalHTMLPane ( ) ;
try {
onlineHelpPane . showHTMLDocument ( new URL ( " http://iris.lib.virginia.edu/tibet/tools/jskad.html " ) ) ;
} catch ( Exception ex ) {
ex . printStackTrace ( System . err ) ;
throw new ThdlLazyException ( ex ) ;
}
new SimpleFrame ( " Jskad on the Web " , onlineHelpPane ) ;
}
} ) ;
helpMenu . add ( helpItem ) ;
helpMenu . addSeparator ( ) ;
2003-02-01 06:42:07 +00:00
}
2002-10-13 20:42:23 +00:00
2002-10-20 08:02:16 +00:00
for ( int i = 0 ; i < keybdMgr . size ( ) ; i + + ) {
final JskadKeyboard kbd = keybdMgr . elementAt ( i ) ;
if ( kbd . hasQuickRefFile ( ) ) {
2004-04-24 17:49:16 +00:00
JMenuItem keybdItem = new JMenuItem ( kbd . getIdentifyingString ( ) + " ... " ) ;
2002-10-20 08:02:16 +00:00
keybdItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
new SimpleFrame ( kbd . getIdentifyingString ( ) ,
kbd . getQuickRefPane ( ) ) ;
2003-02-01 06:42:07 +00:00
/ * DLC FIXME - - pressing the " Extended
2003-05-31 23:21:29 +00:00
Wylie " menu item (for example) twice
causes the first pane to become dead .
We should check to see if the first
pane exists and raise it rather than
creating a second pane . * /
2002-10-20 08:02:16 +00:00
}
} ) ;
2003-07-05 22:25:21 +00:00
helpMenu . add ( keybdItem ) ;
2002-10-20 08:02:16 +00:00
}
2002-10-13 20:42:23 +00:00
}
2003-10-18 18:29:46 +00:00
helpMenu . addSeparator ( ) ;
2002-10-13 20:42:23 +00:00
2003-02-01 06:42:07 +00:00
{
2004-04-24 17:49:16 +00:00
JMenuItem aboutItem = new JMenuItem ( " About... " ) ;
2003-02-01 06:42:07 +00:00
aboutItem . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" Copyright 2001-2003 Tibetan and Himalayan Digital Library \ n \ n " +
2003-05-31 23:21:29 +00:00
" Jskad is protected by the THDL Open Community License. \ n \ n " + /* FIXME UPDATE THE YEAR REGULARLY */
2003-10-18 18:29:46 +00:00
2003-02-01 06:42:07 +00:00
" For more information, or to download the source code \ n " +
" for Jskad, visit our web site: \ n " +
2003-05-31 23:21:29 +00:00
" http://thdl.org/ \ n " +
2003-02-01 06:42:07 +00:00
" \ n " +
2003-07-05 22:25:21 +00:00
" Portions copyright Andrew Moulden. Thanks to him for \ n " + // CalHTMLPane's license requires this.
" allowing us to display Help documents. \ n " +
" \ n " +
2003-02-01 06:42:07 +00:00
" When submitting bug reports, please indicate that the \ n " +
" time of compilation is "
+ ThdlVersion . getTimeOfCompilation ( ) + " \ n " ,
" About Jskad " , JOptionPane . PLAIN_MESSAGE ) ;
}
} ) ;
2003-07-05 22:25:21 +00:00
helpMenu . add ( aboutItem ) ;
2003-02-01 06:42:07 +00:00
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
menuBar . add ( helpMenu ) ;
2002-10-04 04:52:41 +00:00
2002-11-18 16:12:25 +00:00
/ * Initialize dp before calling
JskadKeyboard . activate ( DuffPane ) or dp . toggleLanguage ( ) . * /
if ( ThdlOptions . getBooleanOption ( Jskad . enableKeypressStatusProp ) ) {
dp = new DuffPane ( statusBar ) ;
} else {
dp = new DuffPane ( ) ;
}
2003-10-18 18:29:46 +00:00
JToolBar toolBar = new JToolBar ( ) ;
toolBar . setBorder ( null ) ;
toolBar . addSeparator ( ) ;
toolBar . add ( new JLabel ( " Input mode: " ) ) ;
toolBar . addSeparator ( ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
String [ ] input_modes = { " Tibetan " , " Roman " } ;
final JComboBox inputmethods = new JComboBox ( input_modes ) ;
2002-11-18 16:12:25 +00:00
int initialInputMethod
= ThdlOptions . getIntegerOption ( " thdl.Jskad.input.method " , 0 ) ;
if ( ! dp . isRomanEnabled ( ) & & 1 = = initialInputMethod ) {
initialInputMethod = 0 ;
System . out . println ( " Hey yo! Roman input mode is not enabled, but your preference is for Roman mode at startup. Sorry! " ) ;
ThdlDebug . noteIffyCode ( ) ;
}
try {
inputmethods . setSelectedIndex ( initialInputMethod ) ;
} catch ( IllegalArgumentException e ) {
initialInputMethod = 0 ; // Tibetan is the default.
inputmethods . setSelectedIndex ( initialInputMethod ) ;
}
// Because we start in Tibetan mode, we must toggle initially
// if the user wants it that way:
if ( 1 = = initialInputMethod & & dp . isRomanEnabled ( ) )
dp . toggleLanguage ( ) ;
2003-10-18 18:29:46 +00:00
inputmethods . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2002-11-18 16:12:25 +00:00
int si = inputmethods . getSelectedIndex ( ) ;
ThdlOptions . setUserPreference ( " thdl.Jskad.input.method " , si ) ;
2003-10-18 18:29:46 +00:00
switch ( si ) {
case 0 : //Tibetan
if ( dp . isRomanMode ( ) )
dp . toggleLanguage ( ) ;
2002-10-13 19:22:56 +00:00
statusBar . replaceStatus ( " Now inputting Tibetan script " ) ;
2003-10-18 18:29:46 +00:00
break ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
case 1 : //Roman
if ( ! dp . isRomanMode ( ) & & dp . isRomanEnabled ( ) )
dp . toggleLanguage ( ) ;
2002-10-13 19:22:56 +00:00
statusBar . replaceStatus ( " Now inputting Roman script " ) ;
2003-10-18 18:29:46 +00:00
break ;
}
}
} ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
toolBar . add ( inputmethods ) ;
toolBar . add ( Box . createHorizontalGlue ( ) ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
toolBar . add ( new JLabel ( " Keyboard: " ) ) ;
toolBar . addSeparator ( ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
final JComboBox keyboards
2002-10-20 08:02:16 +00:00
= new JComboBox ( keybdMgr . getIdentifyingStrings ( ) ) ;
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
int initialKeyboard
= ThdlOptions . getIntegerOption ( " thdl.default.tibetan.keyboard " , 0 ) ;
try {
keyboards . setSelectedIndex ( initialKeyboard ) ;
} catch ( IllegalArgumentException e ) {
2002-10-20 08:25:10 +00:00
initialKeyboard = 0 ; // good ol' Wylie
keyboards . setSelectedIndex ( initialKeyboard ) ;
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
}
2002-10-20 08:25:10 +00:00
keybdMgr . elementAt ( initialKeyboard ) . activate ( dp ) ;
2003-10-18 18:29:46 +00:00
keyboards . addActionListener ( new ThdlActionListener ( ) {
public void theRealActionPerformed ( ActionEvent e ) {
2002-11-18 16:12:25 +00:00
int ki = keyboards . getSelectedIndex ( ) ;
2003-08-09 07:57:21 +00:00
keybdMgr . elementAt ( ki ) . activate ( dp ) ;
ThdlOptions . setUserPreference ( " thdl.default.tibetan.keyboard " , ki ) ;
2003-10-18 18:29:46 +00:00
}
} ) ;
toolBar . add ( keyboards ) ;
toolBar . add ( Box . createHorizontalGlue ( ) ) ;
2002-10-04 04:52:41 +00:00
2003-07-04 02:31:23 +00:00
JScrollPane scrollingDuffPane
2003-04-14 05:22:27 +00:00
= new JScrollPane ( dp ,
JScrollPane . VERTICAL_SCROLLBAR_AS_NEEDED ,
JScrollPane . HORIZONTAL_SCROLLBAR_NEVER ) ;
2003-10-18 18:29:46 +00:00
dp . getDocument ( ) . addDocumentListener ( this ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( parentObject instanceof JFrame ) {
final JFrame parentFrame = ( JFrame ) parentObject ;
parentFrame . setJMenuBar ( menuBar ) ;
parentFrame . setDefaultCloseOperation ( WindowConstants . DO_NOTHING_ON_CLOSE ) ;
parentFrame . addWindowListener ( new WindowAdapter ( ) {
2003-07-04 02:31:23 +00:00
// We want the focus to be, at the start of the
// program and whenever Jskad gets the focus, on
// the DuffPane.
public void windowActivated ( WindowEvent e ) {
2003-07-05 02:30:00 +00:00
SwingUtilities . invokeLater ( new Runnable ( ) {
public void run ( ) {
focusToDuffPane ( ) ;
}
} ) ;
2003-07-04 02:31:23 +00:00
}
public void windowClosing ( WindowEvent e ) {
if ( ! hasChanged | | hasChanged & & checkSave ( JOptionPane . YES_NO_CANCEL_OPTION ) ) {
numberOfTibsRTFOpen - - ;
if ( numberOfTibsRTFOpen = = 0 )
System . exit ( 0 ) ; // calls our shutdown hook
else
parentFrame . dispose ( ) ;
}
}
} ) ;
2003-10-18 18:29:46 +00:00
} else if ( parentObject instanceof JInternalFrame ) {
final JInternalFrame parentFrame = ( JInternalFrame ) parentObject ;
parentFrame . setJMenuBar ( menuBar ) ;
} else if ( parentObject instanceof JApplet ) {
JApplet parentApplet = ( JApplet ) parentObject ;
parentApplet . setJMenuBar ( menuBar ) ;
2005-02-26 20:46:40 +00:00
// TODO(dchandler): disable cut and paste in the applet
// (we once did this...)
2003-10-18 18:29:46 +00:00
}
setLayout ( new BorderLayout ( ) ) ;
add ( " North " , toolBar ) ;
add ( " Center " , scrollingDuffPane ) ;
2002-10-13 19:22:56 +00:00
if ( statusBar ! = null )
add ( " South " , statusBar ) ;
2003-10-18 18:29:46 +00:00
}
private void newFile ( ) {
if ( dp . getDocument ( ) . getLength ( ) > 0 & & parentObject instanceof JFrame ) {
JFrame parentFrame = ( JFrame ) parentObject ;
JFrame newFrame = new JFrame ( " Jskad " ) ;
Point point = parentFrame . getLocationOnScreen ( ) ;
newFrame . setSize ( parentFrame . getSize ( ) . width , parentFrame . getSize ( ) . height ) ;
newFrame . setLocation ( point . x + 50 , point . y + 50 ) ;
2003-06-21 02:07:51 +00:00
Jskad jskad = new Jskad ( newFrame ) ;
jskads . add ( jskad ) ;
2003-10-18 18:29:46 +00:00
newFrame . getContentPane ( ) . add ( jskad ) ;
newFrame . setVisible ( true ) ;
}
else {
if ( parentObject instanceof JFrame ) {
JFrame parentFrame = ( JFrame ) parentObject ;
parentFrame . setTitle ( " Jskad " ) ;
}
else if ( parentObject instanceof JInternalFrame ) {
JInternalFrame parentFrame = ( JInternalFrame ) parentObject ;
parentFrame . setTitle ( " Jskad " ) ;
}
dp . newDocument ( ) ;
dp . getDocument ( ) . addDocumentListener ( Jskad . this ) ;
hasChanged = false ;
}
}
private void openFile ( ) {
2003-03-11 01:03:19 +00:00
String whereToStart
= ThdlOptions . getStringOption ( " thdl.Jskad.working.directory " ,
null ) ;
2003-07-05 02:15:33 +00:00
fileChooser
= new JFileChooser ( ( whereToStart = = null )
? null
: ( whereToStart . equals ( " " )
? null
: whereToStart ) ) ;
2003-10-18 18:29:46 +00:00
fileChooser . addChoosableFileFilter ( rtfFilter ) ;
2002-10-04 04:52:41 +00:00
2003-03-11 01:03:19 +00:00
setCursor ( Cursor . getPredefinedCursor ( Cursor . WAIT_CURSOR ) ) ;
2002-10-04 04:52:41 +00:00
2003-03-11 01:03:19 +00:00
if ( fileChooser . showOpenDialog ( this ) ! = JFileChooser . APPROVE_OPTION ) {
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
return ;
}
2002-10-04 04:52:41 +00:00
2003-07-04 02:31:23 +00:00
openFile ( fileChooser . getSelectedFile ( ) ) ;
}
/ * * Opens fileChosen for viewing and modifies the recently opened
files list . * /
private void openFile ( File fileChosen ) {
2003-03-11 01:03:19 +00:00
final String f_name = fileChosen . getAbsolutePath ( ) ;
2002-10-04 04:52:41 +00:00
2003-03-11 01:03:19 +00:00
try {
if ( dp . getDocument ( ) . getLength ( ) > 0 & & parentObject instanceof JFrame ) {
JFrame parentFrame = ( JFrame ) parentObject ;
InputStream in = new FileInputStream ( fileChosen ) ;
2003-06-29 03:03:07 +00:00
if ( ! ThdlOptions . getBooleanOption ( " thdl.do.not.fix.rtf.hex.escapes " ) )
in = new RTFFixerInputStream ( in ) ;
2003-03-11 01:03:19 +00:00
ThdlOptions . setUserPreference ( " thdl.Jskad.working.directory " ,
fileChosen . getParentFile ( ) . getAbsolutePath ( ) ) ;
JFrame newFrame = new JFrame ( f_name ) ;
Point point = parentFrame . getLocationOnScreen ( ) ;
newFrame . setSize ( x_size , y_size ) ;
newFrame . setLocation ( point . x + 50 , point . y + 50 ) ;
Jskad newRTF = new Jskad ( newFrame ) ;
2003-06-21 02:07:51 +00:00
jskads . add ( newRTF ) ;
2003-03-11 01:03:19 +00:00
newFrame . getContentPane ( ) . add ( newRTF ) ;
2003-05-14 01:34:39 +00:00
boolean error = false ;
try {
newRTF . dp . rtfEd . read ( in , newRTF . dp . getDocument ( ) , 0 ) ;
} catch ( Exception e ) {
JOptionPane . showMessageDialog ( newFrame ,
2003-06-15 19:19:23 +00:00
TibetanConverter . rtfErrorMessage ) ;
2003-05-14 01:34:39 +00:00
error = true ;
}
2003-03-11 01:03:19 +00:00
in . close ( ) ;
2003-05-14 01:34:39 +00:00
if ( error ) {
newFrame . dispose ( ) ;
numberOfTibsRTFOpen - - ;
} else {
2003-07-04 02:31:23 +00:00
noteMostRecentlyOpenedFile ( fileChosen ) ;
2003-05-28 00:40:59 +00:00
if ( ! ThdlOptions . getBooleanOption ( " thdl.Jskad.do.not.fix.curly.braces.in.rtf " ) ) {
( ( TibetanDocument ) newRTF . dp . getDocument ( ) ) . replaceTahomaCurlyBracesAndBackslashes ( 0 , - 1 ) ;
}
2003-05-14 01:34:39 +00:00
newRTF . dp . getDocument ( ) . addDocumentListener ( newRTF ) ;
newFrame . setTitle ( " Jskad: " + f_name ) ;
newRTF . fileName = new String ( f_name ) ;
newRTF . hasChanged = false ;
newRTF . dp . getCaret ( ) . setDot ( 0 ) ;
newFrame . setVisible ( true ) ;
}
2003-03-11 01:03:19 +00:00
} else {
InputStream in = new FileInputStream ( fileChosen ) ;
2003-06-29 03:03:07 +00:00
if ( ! ThdlOptions . getBooleanOption ( " thdl.do.not.fix.rtf.hex.escapes " ) )
in = new RTFFixerInputStream ( in ) ;
2003-03-11 01:03:19 +00:00
ThdlOptions . setUserPreference ( " thdl.Jskad.working.directory " ,
fileChosen . getParentFile ( ) . getAbsolutePath ( ) ) ;
dp . newDocument ( ) ;
2003-05-14 01:34:39 +00:00
boolean error = false ;
try {
dp . rtfEd . read ( in , dp . getDocument ( ) , 0 ) ;
} catch ( Exception e ) {
JOptionPane . showMessageDialog ( this ,
2003-06-15 19:19:23 +00:00
TibetanConverter . rtfErrorMessage ) ;
2003-05-14 01:34:39 +00:00
error = true ;
2003-03-11 01:03:19 +00:00
}
2003-05-14 01:34:39 +00:00
in . close ( ) ;
if ( ! error ) {
2003-07-04 02:31:23 +00:00
noteMostRecentlyOpenedFile ( fileChosen ) ;
2003-05-28 00:40:59 +00:00
if ( ! ThdlOptions . getBooleanOption ( " thdl.Jskad.do.not.fix.curly.braces.in.rtf " ) ) {
( ( TibetanDocument ) dp . getDocument ( ) ) . replaceTahomaCurlyBracesAndBackslashes ( 0 , - 1 ) ;
}
2003-05-14 01:34:39 +00:00
dp . getCaret ( ) . setDot ( 0 ) ;
dp . getDocument ( ) . addDocumentListener ( Jskad . this ) ;
hasChanged = false ;
fileName = new String ( f_name ) ;
if ( parentObject instanceof JFrame ) {
JFrame parentFrame = ( JFrame ) parentObject ;
parentFrame . setTitle ( " Jskad: " + fileName ) ;
}
else if ( parentObject instanceof JInternalFrame ) {
JInternalFrame parentFrame = ( JInternalFrame ) parentObject ;
parentFrame . setTitle ( " Jskad: " + fileName ) ;
}
2003-03-11 01:03:19 +00:00
}
}
}
catch ( FileNotFoundException fnfe ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" No such file exists. " ,
" Open File Error " ,
JOptionPane . ERROR_MESSAGE ) ;
}
catch ( IOException ioe ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" Error reading file. " ,
" Open File Error " ,
JOptionPane . ERROR_MESSAGE ) ;
}
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
2003-10-18 18:29:46 +00:00
}
/** Returns true iff the save was successful. */
private boolean saveFile ( ) {
String s = getSave ( fileName ) ;
if ( null ! = s ) {
if ( parentObject instanceof JFrame ) {
JFrame parentFrame = ( JFrame ) parentObject ;
parentFrame . setTitle ( " Jskad: " + s ) ;
fileName = new String ( s ) ;
}
else if ( parentObject instanceof JInternalFrame ) {
JInternalFrame parentFrame = ( JInternalFrame ) parentObject ;
parentFrame . setTitle ( " Jskad: " + s ) ;
fileName = new String ( s ) ;
}
return true ;
} else {
return false ;
}
}
/** Returns true iff the save was successful. */
private boolean saveAsFile ( ) {
String s = getSaveAs ( ) ;
if ( null ! = s ) {
if ( parentObject instanceof JFrame ) {
JFrame parentFrame = ( JFrame ) parentObject ;
parentFrame . setTitle ( " Jskad: " + s ) ;
fileName = new String ( s ) ;
}
else if ( parentObject instanceof JInternalFrame ) {
JInternalFrame parentFrame = ( JInternalFrame ) parentObject ;
parentFrame . setTitle ( " Jskad: " + s ) ;
fileName = new String ( s ) ;
}
return true ;
}
return false ;
}
2002-10-04 04:52:41 +00:00
2003-06-21 02:07:51 +00:00
/ * * Returns true iff the user says ( possibly after a successful
2003-06-29 20:49:30 +00:00
save ) that it is OK to destroy this Jskad widget .
@param dialogType either JOptionPane . YES_NO_CANCEL_OPTION or
JOptionPane . YES_NO_OPTION , depending on whether canceling is
different than saying no .
* /
2003-10-18 18:29:46 +00:00
private boolean checkSave ( int dialogType ) {
if ( ThdlOptions . getBooleanOption ( " thdl.Jskad.do.not.confirm.quit " ) ) {
return true ;
}
int saveFirst
= JOptionPane . showConfirmDialog ( this ,
" Do you want to save your changes? " ,
" Please select " ,
2003-06-29 20:49:30 +00:00
dialogType ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
switch ( saveFirst ) {
case JOptionPane . NO_OPTION : //don't save but do continue
return true ;
case JOptionPane . YES_OPTION : //save and continue
if ( fileName = = null )
return saveAsFile ( ) ;
else
return saveFile ( ) ;
default :
return false ;
}
}
private String getSave ( String f_name ) {
File fileChosen = new File ( f_name ) ;
try {
BufferedOutputStream out = new BufferedOutputStream ( new FileOutputStream ( fileChosen ) ) ;
dp . rtfEd . write ( out , dp . getDocument ( ) , 0 , dp . getDocument ( ) . getLength ( ) ) ;
out . flush ( ) ;
out . close ( ) ;
hasChanged = false ;
} catch ( IOException exception ) {
2003-03-11 01:03:19 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
" Cannot save to that file. " ,
" Save As Error " ,
JOptionPane . ERROR_MESSAGE ) ;
2003-10-18 18:29:46 +00:00
return null ;
} catch ( BadLocationException ble ) {
ble . printStackTrace ( ) ;
ThdlDebug . noteIffyCode ( ) ;
}
return f_name ;
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
private String getSaveAs ( ) {
setCursor ( Cursor . getPredefinedCursor ( Cursor . WAIT_CURSOR ) ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( fileName = = null )
fileChooser . setSelectedFile ( null ) ;
else
fileChooser . setSelectedFile ( new File ( fileName ) ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( fileChooser . showSaveDialog ( this ) ! = JFileChooser . APPROVE_OPTION ) {
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
return null ;
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
File fileChosen = fileChooser . getSelectedFile ( ) ;
2003-03-11 01:03:19 +00:00
ThdlOptions . setUserPreference ( " thdl.Jskad.working.directory " ,
fileChosen . getParentFile ( ) . getAbsolutePath ( ) ) ;
2003-10-18 18:29:46 +00:00
String fileName = fileChosen . getAbsolutePath ( ) ;
int i = fileName . lastIndexOf ( '.' ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( i < 0 )
fileName + = " .rtf " ;
else
fileName = fileName . substring ( 0 , i ) + " .rtf " ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
getSave ( fileName ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
fileChooser . rescanCurrentDirectory ( ) ;
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
return fileName ;
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
private void cutSelection ( ) {
2003-04-02 20:37:14 +00:00
dp . cut ( ) ;
2003-10-18 18:29:46 +00:00
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
private void copySelection ( ) {
2003-04-02 20:37:14 +00:00
dp . copy ( ) ;
2003-10-18 18:29:46 +00:00
}
2002-10-04 04:52:41 +00:00
2005-02-26 22:57:38 +00:00
private void copyAsUnicodeSelection ( ) {
dp . copyAsUnicode ( ) ;
}
2003-10-18 18:29:46 +00:00
private void pasteSelection ( ) {
dp . paste ( dp . getCaret ( ) . getDot ( ) ) ;
}
2002-10-04 04:52:41 +00:00
2003-10-26 00:21:54 +00:00
private void toTibetan ( boolean fromACIP , boolean withWarnings ) {
2003-10-18 18:29:46 +00:00
Jskad . this . setCursor ( Cursor . getPredefinedCursor ( Cursor . WAIT_CURSOR ) ) ;
2003-10-26 00:21:54 +00:00
dp . toTibetanMachineWeb ( fromACIP , withWarnings ) ;
2003-10-18 18:29:46 +00:00
Jskad . this . setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
}
2002-10-04 04:52:41 +00:00
2003-11-08 23:22:06 +00:00
private void toTranslit ( boolean toWylieNotACIP ) {
2003-10-18 18:29:46 +00:00
Jskad . this . setCursor ( Cursor . getPredefinedCursor ( Cursor . WAIT_CURSOR ) ) ;
2003-11-08 23:22:06 +00:00
if ( ! ( toWylieNotACIP
? ( ( TibetanDocument ) dp . getDocument ( ) ) . toWylie ( dp . getSelectionStart ( ) ,
dp . getSelectionEnd ( ) ,
new long [ ] { 0 } )
: ( ( TibetanDocument ) dp . getDocument ( ) ) . toACIP ( dp . getSelectionStart ( ) ,
dp . getSelectionEnd ( ) ,
new long [ ] { 0 } ) ) ) {
2003-07-01 03:43:33 +00:00
JOptionPane . showMessageDialog ( Jskad . this ,
2003-11-08 23:22:06 +00:00
" Though some "
+ ( toWylieNotACIP
? " Extended Wylie "
: " ACIP " )
+ " has been produced, it \ ncontains ugly error messages "
+ ( toWylieNotACIP
? " like \ n \" <<[[JSKAD_TMW_TO_WYLIE_ERROR_NO_SUCH_WYLIE: \ n Cannot convert DuffCode... \" . "
: " . " )
+ " \ nPlease edit the output by hand to replace all such \ ncreatures with the correct transliteration. " ,
2003-07-01 03:43:33 +00:00
" Attention Required " ,
JOptionPane . ERROR_MESSAGE ) ;
}
2003-10-18 18:29:46 +00:00
Jskad . this . setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
}
private void importWylie ( ) {
fileChooser . removeChoosableFileFilter ( rtfFilter ) ;
fileChooser . addChoosableFileFilter ( txtFilter ) ;
if ( fileChooser . showDialog ( Jskad . this , " Import Wylie " ) ! = JFileChooser . APPROVE_OPTION ) {
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
fileChooser . removeChoosableFileFilter ( txtFilter ) ;
fileChooser . addChoosableFileFilter ( rtfFilter ) ;
return ;
}
File txt_fileChosen = fileChooser . getSelectedFile ( ) ;
fileChooser . rescanCurrentDirectory ( ) ;
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
fileChooser . removeChoosableFileFilter ( txtFilter ) ;
fileChooser . addChoosableFileFilter ( rtfFilter ) ;
if ( fileChooser . showDialog ( Jskad . this , " Save as Tibetan " ) ! = JFileChooser . APPROVE_OPTION ) {
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
return ;
}
File rtf_fileChosen = fileChooser . getSelectedFile ( ) ;
fileChooser . rescanCurrentDirectory ( ) ;
setCursor ( Cursor . getPredefinedCursor ( Cursor . DEFAULT_CURSOR ) ) ;
String rtf_fileName = rtf_fileChosen . getAbsolutePath ( ) ;
int i = rtf_fileName . lastIndexOf ( '.' ) ;
if ( i < 0 )
rtf_fileName + = " .rtf " ;
else
2003-11-08 23:32:53 +00:00
rtf_fileName = rtf_fileName . substring ( 0 , i ) + " .rtf " ;
2003-10-18 18:29:46 +00:00
try {
BufferedReader in = new BufferedReader ( new FileReader ( txt_fileChosen ) ) ;
2003-04-14 05:22:27 +00:00
// FIXME: why do we need a whole DuffPane to do this?
DuffPane dp2 = new DuffPane ( ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
try {
String val = in . readLine ( ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
while ( val ! = null ) {
dp2 . toTibetanMachineWeb ( val + " \ n " , dp2 . getCaret ( ) . getDot ( ) ) ;
val = in . readLine ( ) ;
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
TibetanDocument t_doc = ( TibetanDocument ) dp2 . getDocument ( ) ;
t_doc . writeRTFOutputStream ( new FileOutputStream ( new File ( rtf_fileName ) ) ) ;
} catch ( IOException ioe ) {
2002-11-16 19:18:44 +00:00
ThdlDebug . noteIffyCode ( ) ;
2003-10-18 18:29:46 +00:00
System . out . println ( " problem reading or writing file " ) ;
}
} catch ( FileNotFoundException fnfe ) {
2003-04-14 05:22:27 +00:00
ThdlDebug . noteIffyCode ( ) ;
2003-10-18 18:29:46 +00:00
System . out . println ( " problem reading file " ) ;
}
}
2002-10-04 04:52:41 +00:00
/ * *
* Allows use of Jskad as dependent JFrame .
* Once you ' ve called this method , users will
* be able to close Jskad without shutting
* down your superordinate application .
* /
2003-10-18 18:29:46 +00:00
public void makeDependent ( ) {
numberOfTibsRTFOpen + + ;
}
2002-10-04 04:52:41 +00:00
/ * *
* Fills the editing pane with content . If the
* editing pane already has content , this method does nothing .
*
* @param wylie the string of wylie you want to
* put in the editing pane
* /
2003-10-18 18:29:46 +00:00
public void setContent ( String wylie ) {
if ( dp . getDocument ( ) . getLength ( ) > 0 )
return ;
dp . newDocument ( ) ;
dp . toTibetanMachineWeb ( wylie , 0 ) ;
}
2002-10-04 04:52:41 +00:00
/ * *
* Enables typing of Roman ( non - Tibetan ) text along
* with Tibetan .
* /
2003-10-18 18:29:46 +00:00
public void enableRoman ( ) {
dp . enableRoman ( ) ;
}
2002-10-04 04:52:41 +00:00
/ * *
* Disables typing of Roman ( non - Tibetan ) text .
* /
2003-10-18 18:29:46 +00:00
public void disableRoman ( ) {
dp . disableRoman ( ) ;
}
2002-10-04 04:52:41 +00:00
/ *
2003-10-18 18:29:46 +00:00
private void showAttributes ( int pos ) {
dp . skipUpdate = true ;
AttributeSet attr = dp . getDocument ( ) . getCharacterElement ( pos ) . getAttributes ( ) ;
String name = StyleConstants . getFontFamily ( attr ) ;
if ( ! fontName . equals ( name ) ) {
fontName = name ;
fontFamilies . setSelectedItem ( name ) ;
}
int size = StyleConstants . getFontSize ( attr ) ;
if ( fontSize ! = size ) {
fontSize = size ;
fontSizes . setSelectedItem ( Integer . toString ( fontSize ) ) ;
}
dp . skipUpdate = false ;
}
2002-10-04 04:52:41 +00:00
* /
/ * *
* Required for implementations of DocumentListener .
* Does nothing .
* /
2003-10-18 18:29:46 +00:00
public void changedUpdate ( DocumentEvent de ) {
}
2002-10-04 04:52:41 +00:00
/ * *
* Required for implementations of DocumentListener .
* Informs the object that a change in the document
* has occurred .
*
* @param de a DocumentEvent
* /
2003-10-18 18:29:46 +00:00
public void insertUpdate ( DocumentEvent de ) {
hasChanged = true ;
}
2002-10-04 04:52:41 +00:00
/ * *
* Required for implementations of DocumentListener .
* Informs the object that a change in the document
* has occurred .
*
* @param de a DocumentEvent
* /
2003-10-18 18:29:46 +00:00
public void removeUpdate ( DocumentEvent de ) {
hasChanged = true ;
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
private class RTFFilter extends javax . swing . filechooser . FileFilter {
// Accept all directories and all RTF files.
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
public boolean accept ( File f ) {
if ( f . isDirectory ( ) ) {
return true ;
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
String fName = f . getName ( ) ;
int i = fName . lastIndexOf ( '.' ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( i < 0 )
return false ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
else {
String ext = fName . substring ( i + 1 ) . toLowerCase ( ) ;
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
if ( ext . equals ( " rtf " ) )
return true ;
else
return false ;
}
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
//the description of this filter
public String getDescription ( ) {
return " Rich Text Format (.rtf) " ;
}
}
private class TXTFilter extends javax . swing . filechooser . FileFilter {
// Accept all directories and all TXT files.
public boolean accept ( File f ) {
if ( f . isDirectory ( ) ) {
return true ;
}
String fName = f . getName ( ) ;
int i = fName . lastIndexOf ( '.' ) ;
if ( i < 0 )
return false ;
else {
String ext = fName . substring ( i + 1 ) . toLowerCase ( ) ;
if ( ext . equals ( " txt " ) )
return true ;
else
return false ;
}
}
2002-10-04 04:52:41 +00:00
2003-10-18 18:29:46 +00:00
//the description of this filter
public String getDescription ( ) {
return " Text file (.txt) " ;
}
}
2002-10-04 04:52:41 +00:00
2003-06-21 02:07:51 +00:00
/ * * Closes this Jskad session without saving . If deleteFromList
is true , the jskads vector is updated so that it no longer
contains this instance . If this is the last instance open ,
the program exits . * /
private void realCloseAction ( boolean deleteFromList ) {
numberOfTibsRTFOpen - - ;
// Delete this Jskad from jskads.
if ( deleteFromList ) {
int i , sz = jskads . size ( ) ;
for ( i = 0 ; i < sz ; i + + ) {
if ( jskads . elementAt ( i ) = = this ) {
jskads . removeElementAt ( i ) ;
break ;
}
}
if ( i = = sz )
throw new Error ( " Couldn't find the Jskad session being closed in our list of open Jskad sessions! This is a bug. " ) ;
}
if ( numberOfTibsRTFOpen = = 0 )
System . exit ( 0 ) ;
else {
final JFrame parentFrame = ( JFrame ) parentObject ;
parentFrame . dispose ( ) ;
}
}
/** Stores all open Jskad sessions. */
private static Vector jskads = new Vector ( ) ;
2003-06-29 03:03:07 +00:00
/ * * Closes all Jskad windows if user confirms . After asking " Do
you want to save ? " for the modified windows, this closes them
all . If you don ' t cancel for any unsaved session , then all
sessions are closed . If you do cancel for any one , even the
last one , then all sessions remain open . * /
2003-06-21 02:07:51 +00:00
private static void exitAction ( ) {
int sz = jskads . size ( ) ;
for ( int i = 0 ; i < sz ; i + + ) {
Jskad j = ( Jskad ) jskads . elementAt ( i ) ;
2003-06-29 20:49:30 +00:00
if ( j . hasChanged & & ! j . checkSave ( JOptionPane . YES_NO_CANCEL_OPTION ) ) {
2003-06-21 02:07:51 +00:00
return ;
}
}
for ( int i = 0 ; i < sz ; i + + ) {
Jskad j = ( Jskad ) jskads . elementAt ( i ) ;
j . realCloseAction ( false ) ;
}
}
2002-10-13 20:42:23 +00:00
2003-06-29 20:49:30 +00:00
/ * * Checks if the current buffer has been modified or is not yet
saved . If so , the user is prompted to save . After that , the
current buffer is opened with a user - selected external viewer ,
which defaults to Microsoft Word if we can find it with our
naive , " I bet it lives on everybody's machine where it lives
on mine " mechanism. */
private void openWithExternalViewer ( ) {
if ( ( hasChanged & & ! checkSave ( JOptionPane . YES_NO_OPTION ) ) | | null = = fileName ) {
if ( null = = fileName ) {
JOptionPane . showMessageDialog ( Jskad . this ,
" You must save the file before opening it with an external viewer. " ,
" Cannot View Unsaved File " ,
JOptionPane . ERROR_MESSAGE ) ;
return ;
} else {
if ( JOptionPane . YES_OPTION
! = JOptionPane . showConfirmDialog ( Jskad . this ,
" Do you want to view the file as it exists on disk anyway? " ,
" Proceed Anyway? " ,
JOptionPane . YES_NO_OPTION ) )
return ;
}
}
ConvertDialog . openWithExternalViewer ( this , fileName ) ;
}
2002-10-13 20:42:23 +00:00
2002-10-04 04:52:41 +00:00
/ * *
2002-10-06 18:23:27 +00:00
* Runs Jskad . System output , including errors , is redirected to
* jskad . log in addition to appearing on the console as per usual . If
* you discover a bug , please send us an email , making sure to include
* the jskad . log file as an attachment . * /
2003-10-18 18:29:46 +00:00
public static void main ( String [ ] args ) {
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
try {
ThdlDebug . attemptToSetUpLogFile ( " jskad " , " .log " ) ;
2002-10-04 04:52:41 +00:00
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
try {
UIManager . setLookAndFeel ( UIManager . getSystemLookAndFeelClassName ( ) ) ;
}
catch ( Exception e ) {
2002-11-16 19:18:44 +00:00
ThdlDebug . noteIffyCode ( ) ;
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
}
2002-10-04 04:52:41 +00:00
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
JFrame f = new JFrame ( " Jskad " ) ;
Dimension d = f . getToolkit ( ) . getScreenSize ( ) ;
x_size = d . width / 4 * 3 ;
y_size = d . height / 4 * 3 ;
f . setSize ( x_size , y_size ) ;
f . setLocation ( d . width / 8 , d . height / 8 ) ;
2003-06-21 01:26:17 +00:00
final Jskad jskad = new Jskad ( f ) ;
2003-06-21 02:07:51 +00:00
jskads . add ( jskad ) ;
2003-06-21 01:26:17 +00:00
f . getContentPane ( ) . add ( jskad ) ;
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
f . setVisible ( true ) ;
2002-11-18 16:12:25 +00:00
/ * Make it so that any time the user exits Jskad by
* ( almost ) any means , the user ' s preferences are saved if
* the SecurityManager allows it and the path is
* correct . * /
Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) {
public void run ( ) {
2003-06-21 01:26:17 +00:00
jskad . savePreferencesAction ( ) ;
2002-11-18 16:12:25 +00:00
}
}
) ;
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
} catch ( ThdlLazyException e ) {
2002-11-16 19:18:44 +00:00
// FIXME: tell the users how to submit bug reports.
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
System . err . println ( " Jskad has a BUG: " ) ;
e . getRealException ( ) . printStackTrace ( System . err ) ;
2002-11-16 19:18:44 +00:00
System . exit ( 1 ) ;
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
}
2003-10-18 18:29:46 +00:00
}
2002-10-04 04:52:41 +00:00
}