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.quilldriver;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.net.*;
|
|
|
|
import java.util.*;
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.event.*;
|
|
|
|
import javax.swing.text.*;
|
|
|
|
import javax.swing.text.rtf.*;
|
|
|
|
|
2002-10-06 18:23:27 +00:00
|
|
|
import org.thdl.util.ThdlDebug;
|
|
|
|
import org.thdl.util.ThdlActionListener;
|
2002-10-18 16:11:50 +00:00
|
|
|
import org.thdl.util.ThdlOptions;
|
2002-10-27 19:12:13 +00:00
|
|
|
import org.thdl.tib.input.JskadKeyboardManager;
|
|
|
|
import org.thdl.tib.input.JskadKeyboardFactory;
|
|
|
|
import org.thdl.tib.input.JskadKeyboard;
|
2002-10-18 16:11:50 +00:00
|
|
|
|
|
|
|
import org.thdl.savant.JdkVersionHacks;
|
|
|
|
|
2002-10-04 04:52:41 +00:00
|
|
|
|
2002-09-28 00:53:39 +00:00
|
|
|
public class QDShell extends JFrame {
|
2002-10-27 19:12:13 +00:00
|
|
|
|
|
|
|
/** the middleman that keeps code regarding Tibetan keyboards
|
|
|
|
* clean */
|
|
|
|
private final static JskadKeyboardManager keybdMgr
|
|
|
|
= new JskadKeyboardManager(JskadKeyboardFactory.getAllAvailableJskadKeyboards());
|
|
|
|
|
2002-10-18 16:11:50 +00:00
|
|
|
/** When opening a file, this is the only extension QuillDriver
|
|
|
|
cares about. This is case-insensitive. */
|
|
|
|
protected final static String dotQuillDriver = ".xml";
|
|
|
|
|
2002-09-28 00:53:39 +00:00
|
|
|
ResourceBundle messages = null;
|
|
|
|
QD qd = null;
|
|
|
|
|
2002-10-06 18:23:27 +00:00
|
|
|
public static void main(String[] args) {
|
2002-09-28 00:53:39 +00:00
|
|
|
try {
|
2002-10-13 19:23:34 +00:00
|
|
|
ThdlDebug.attemptToSetUpLogFile("qd", ".log");
|
2002-10-06 18:23:27 +00:00
|
|
|
|
|
|
|
Locale locale;
|
|
|
|
|
|
|
|
if (args.length == 2) {
|
|
|
|
locale = new Locale(new String(args[0]), new String(args[1]));
|
|
|
|
Locale[] locales = Locale.getAvailableLocales();
|
|
|
|
for (int k=0; k<locales.length; k++)
|
|
|
|
if (locales[k].equals(locale)) {
|
|
|
|
JComponent.setDefaultLocale(locale);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
locale = Locale.getDefault();
|
2002-09-28 00:53:39 +00:00
|
|
|
|
2002-10-06 18:23:27 +00:00
|
|
|
try {
|
|
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
|
|
|
|
2002-10-06 18:23:27 +00:00
|
|
|
QDShell qdsh = new QDShell(locale);
|
|
|
|
qdsh.setVisible(true);
|
|
|
|
} catch (NoClassDefFoundError err) {
|
|
|
|
ThdlDebug.handleClasspathError("QuillDriver's CLASSPATH", err);
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
2002-10-06 18:23:27 +00:00
|
|
|
}
|
2002-09-28 00:53:39 +00:00
|
|
|
|
|
|
|
public QDShell(Locale locale) {
|
|
|
|
setTitle("QuillDriver");
|
|
|
|
|
|
|
|
// Code for Merlin
|
2002-10-18 16:11:50 +00:00
|
|
|
if (JdkVersionHacks.maximizedBothSupported(getToolkit())) {
|
2002-09-28 00:53:39 +00:00
|
|
|
setLocation(0,0);
|
|
|
|
setSize(getToolkit().getScreenSize().width,getToolkit().getScreenSize().height);
|
|
|
|
setVisible(true);
|
2002-10-18 16:11:50 +00:00
|
|
|
|
|
|
|
// call setExtendedState(Frame.MAXIMIZED_BOTH) if possible:
|
|
|
|
if (!JdkVersionHacks.maximizeJFrameInBothDirections(this)) {
|
|
|
|
throw new Error("badness at maximum: the frame state is supported, but setting that state failed. JdkVersionHacks has a bug.");
|
|
|
|
}
|
2002-09-28 00:53:39 +00:00
|
|
|
} else {
|
|
|
|
Dimension gs = getToolkit().getScreenSize();
|
|
|
|
setLocation(0,0);
|
|
|
|
setSize(new Dimension(gs.width, gs.height));
|
|
|
|
setVisible(true);
|
2002-10-18 16:11:50 +00:00
|
|
|
}
|
2002-09-28 00:53:39 +00:00
|
|
|
|
|
|
|
messages = ResourceBundle.getBundle("MessageBundle", locale);
|
|
|
|
|
|
|
|
qd = new QD(messages);
|
|
|
|
getContentPane().add(qd);
|
2002-10-18 16:11:50 +00:00
|
|
|
setJMenuBar(getQDShellMenu());
|
2002-10-25 20:18:22 +00:00
|
|
|
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
2002-09-28 00:53:39 +00:00
|
|
|
addWindowListener(new WindowAdapter () {
|
|
|
|
public void windowClosing (WindowEvent e) {
|
2002-10-25 20:18:22 +00:00
|
|
|
if (getWantSave())
|
|
|
|
getSave();
|
|
|
|
System.exit(0);
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public JMenuBar getQDShellMenu() {
|
|
|
|
JMenu projectMenu = new JMenu(messages.getString("Project"));
|
2002-10-25 20:18:22 +00:00
|
|
|
|
2002-09-28 00:53:39 +00:00
|
|
|
JMenuItem newItem = new JMenuItem(messages.getString("New"));
|
2002-10-18 16:11:50 +00:00
|
|
|
newItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
2002-10-25 20:18:22 +00:00
|
|
|
if (getWantSave())
|
|
|
|
getSave();
|
|
|
|
qd.clearProject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
JMenuItem openVideoItem = new JMenuItem(messages.getString("OpenMediaFile"));
|
|
|
|
openVideoItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
|
|
|
if (getWantSave())
|
|
|
|
getSave();
|
|
|
|
|
|
|
|
JFileChooser fc = new JFileChooser();
|
|
|
|
if (fc.showDialog(QDShell.this, messages.getString("SelectMedia")) == JFileChooser.APPROVE_OPTION) {
|
|
|
|
File mediaFile = fc.getSelectedFile();
|
|
|
|
try {
|
|
|
|
qd.newProject(mediaFile.toURL());
|
|
|
|
} catch (MalformedURLException murle) {
|
|
|
|
murle.printStackTrace();
|
|
|
|
ThdlDebug.noteIffyCode();
|
2002-10-18 16:11:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-10-25 20:18:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
JMenuItem openURLItem = new JMenuItem(messages.getString("OpenMediaURL"));
|
|
|
|
openURLItem.addActionListener(new ThdlActionListener() {
|
2002-10-06 18:23:27 +00:00
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
2002-10-25 20:18:22 +00:00
|
|
|
String url = JOptionPane.showInputDialog(QDShell.this,
|
|
|
|
messages.getString("TypeMediaURL"));
|
|
|
|
if (url != null) {
|
|
|
|
if (getWantSave())
|
|
|
|
getSave();
|
|
|
|
|
|
|
|
try {
|
|
|
|
qd.newProject(new URL(url));
|
|
|
|
} catch (MalformedURLException murle) {
|
|
|
|
murle.printStackTrace();
|
|
|
|
ThdlDebug.noteIffyCode();
|
2002-10-18 16:11:50 +00:00
|
|
|
}
|
|
|
|
}
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
|
|
|
});
|
2002-10-25 20:18:22 +00:00
|
|
|
|
|
|
|
JMenuItem openItem = new JMenuItem(messages.getString("OpenTranscript"));
|
|
|
|
openItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
|
|
|
if (getWantSave())
|
|
|
|
getSave();
|
|
|
|
|
|
|
|
JFileChooser fc = new JFileChooser();
|
|
|
|
fc.addChoosableFileFilter(new QDFileFilter());
|
|
|
|
if (fc.showDialog(QDShell.this, messages.getString("OpenTranscript")) == JFileChooser.APPROVE_OPTION) {
|
|
|
|
File transcriptFile = fc.getSelectedFile();
|
|
|
|
qd.loadTranscript(transcriptFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
2002-09-28 00:53:39 +00:00
|
|
|
JMenuItem closeItem = new JMenuItem(messages.getString("Close"));
|
2002-10-18 16:11:50 +00:00
|
|
|
closeItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
|
|
|
if (getSave())
|
|
|
|
qd.clearProject();
|
|
|
|
}
|
|
|
|
});
|
2002-10-25 20:18:22 +00:00
|
|
|
*/
|
2002-10-18 16:11:50 +00:00
|
|
|
|
2002-09-28 00:53:39 +00:00
|
|
|
JMenuItem saveItem = new JMenuItem(messages.getString("Save"));
|
2002-10-06 18:23:27 +00:00
|
|
|
saveItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
2002-10-18 16:11:50 +00:00
|
|
|
getSave();
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
JMenuItem quitItem = new JMenuItem(messages.getString("Quit"));
|
2002-10-06 18:23:27 +00:00
|
|
|
quitItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
2002-10-25 20:18:22 +00:00
|
|
|
if (getWantSave())
|
|
|
|
getSave();
|
|
|
|
System.exit(0);
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
projectMenu.add(newItem);
|
2002-10-25 20:18:22 +00:00
|
|
|
projectMenu.addSeparator();
|
|
|
|
projectMenu.add(openVideoItem);
|
|
|
|
projectMenu.add(openURLItem);
|
2002-09-28 00:53:39 +00:00
|
|
|
projectMenu.add(openItem);
|
|
|
|
projectMenu.addSeparator();
|
2002-10-25 20:18:22 +00:00
|
|
|
// projectMenu.add(closeItem);
|
|
|
|
// projectMenu.addSeparator();
|
2002-09-28 00:53:39 +00:00
|
|
|
projectMenu.add(saveItem);
|
|
|
|
projectMenu.addSeparator();
|
|
|
|
projectMenu.add(quitItem);
|
|
|
|
|
|
|
|
//Tibetan-specific value: remove in non-Tibetan version
|
|
|
|
//non-Tibetan specific version would have Transcription Language option here instead
|
2002-10-25 20:18:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Note that on the Mac, you radio buttons don't appear possible as
|
|
|
|
submenus on menu bars. They just don't show up.
|
|
|
|
|
2002-10-18 16:11:50 +00:00
|
|
|
JRadioButton[] buttons = new JRadioButton[4];
|
|
|
|
buttons[0] = new JRadioButton("THDL Extended Wylie");
|
|
|
|
buttons[1] = new JRadioButton("TCC Keyboard 1");
|
|
|
|
buttons[2] = new JRadioButton("TCC Keyboard 2");
|
|
|
|
buttons[3] = new JRadioButton("Sambhota Keymap One");
|
|
|
|
buttons[0].setActionCommand("wylie");
|
|
|
|
buttons[1].setActionCommand("tcc1");
|
|
|
|
buttons[2].setActionCommand("tcc2");
|
|
|
|
buttons[3].setActionCommand("sambhota1");
|
|
|
|
ThdlActionListener l1 = new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
|
|
|
qd.changeKeyboard(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
buttons[0].addActionListener(l1);
|
|
|
|
buttons[1].addActionListener(l1);
|
|
|
|
buttons[2].addActionListener(l1);
|
|
|
|
buttons[3].addActionListener(l1);
|
2002-09-28 00:53:39 +00:00
|
|
|
ButtonGroup bg = new ButtonGroup();
|
2002-10-18 16:11:50 +00:00
|
|
|
bg.add(buttons[0]);
|
|
|
|
bg.add(buttons[1]);
|
|
|
|
bg.add(buttons[2]);
|
|
|
|
bg.add(buttons[3]);
|
|
|
|
JPanel b1 = new JPanel(new GridLayout(0,1));
|
|
|
|
b1.add(buttons[0]);
|
|
|
|
b1.add(buttons[1]);
|
|
|
|
b1.add(buttons[2]);
|
|
|
|
b1.add(buttons[3]);
|
|
|
|
|
|
|
|
int initialKeyboard
|
|
|
|
= ThdlOptions.getIntegerOption("thdl.default.tibetan.keyboard", 0);
|
|
|
|
|
|
|
|
buttons[initialKeyboard].setSelected(true);
|
|
|
|
|
2002-10-25 20:18:22 +00:00
|
|
|
*/
|
|
|
|
|
2002-09-28 00:53:39 +00:00
|
|
|
JMenu keyboardMenu = new JMenu(messages.getString("Keyboard"));
|
2002-10-25 20:18:22 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < keybdMgr.size(); i++) {
|
|
|
|
final JskadKeyboard kbd = keybdMgr.elementAt(i);
|
|
|
|
if (kbd.hasQuickRefFile()) {
|
|
|
|
JMenuItem keybdItem = new JMenuItem(kbd.getIdentifyingString());
|
|
|
|
keybdItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
2002-10-27 19:12:13 +00:00
|
|
|
qd.changeKeyboard(kbd);
|
|
|
|
}
|
2002-10-25 20:18:22 +00:00
|
|
|
});
|
|
|
|
keyboardMenu.add(keybdItem);
|
|
|
|
}
|
|
|
|
}
|
2002-10-18 16:11:50 +00:00
|
|
|
|
|
|
|
|
2002-10-25 20:18:22 +00:00
|
|
|
JMenu mediaPlayerMenu = new JMenu(messages.getString("MediaPlayer"));
|
|
|
|
|
|
|
|
JMenuItem jmfItem = new JMenuItem("Java Media Framework");
|
|
|
|
jmfItem.addActionListener(new ThdlActionListener() {
|
2002-10-18 16:11:50 +00:00
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
2002-10-25 20:18:22 +00:00
|
|
|
qd.setMediaPlayerProperty("org.thdl.media.SmartJMFPlayer");
|
2002-10-18 16:11:50 +00:00
|
|
|
}
|
2002-10-25 20:18:22 +00:00
|
|
|
});
|
2002-10-18 16:11:50 +00:00
|
|
|
|
2002-10-25 20:18:22 +00:00
|
|
|
JMenuItem qtItem = new JMenuItem("Quicktime for Java");
|
|
|
|
qtItem.addActionListener(new ThdlActionListener() {
|
|
|
|
public void theRealActionPerformed(ActionEvent e) {
|
|
|
|
qd.setMediaPlayerProperty("org.thdl.media.SmartQT4JPlayer");
|
|
|
|
}
|
|
|
|
});
|
2002-09-28 00:53:39 +00:00
|
|
|
|
|
|
|
JMenu preferencesMenu = new JMenu(messages.getString("Preferences"));
|
|
|
|
preferencesMenu.add(keyboardMenu);
|
2002-10-18 16:11:50 +00:00
|
|
|
preferencesMenu.add(mediaPlayerMenu);
|
2002-09-28 00:53:39 +00:00
|
|
|
|
|
|
|
JMenuBar bar = new JMenuBar();
|
|
|
|
bar.add(projectMenu);
|
|
|
|
bar.add(preferencesMenu);
|
|
|
|
return bar;
|
|
|
|
}
|
2002-10-25 20:18:22 +00:00
|
|
|
private boolean getWantSave() {
|
|
|
|
if (qd.pane.getDocument().getLength() == 0 && qd.speakerTable.getRowCount() == 0)
|
|
|
|
return false; //nothing to save
|
|
|
|
|
|
|
|
if (JOptionPane.showConfirmDialog(QDShell.this, messages.getString("WantSave"), null, JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.YES_OPTION)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
private void getSave() {
|
2002-10-18 16:11:50 +00:00
|
|
|
if (qd.pane.getDocument().getLength() == 0 && qd.speakerTable.getRowCount() == 0)
|
2002-10-25 20:18:22 +00:00
|
|
|
return; //nothing to save
|
2002-09-28 00:53:39 +00:00
|
|
|
|
2002-10-18 16:11:50 +00:00
|
|
|
JFileChooser fc = new JFileChooser();
|
|
|
|
if (qd.project.getTranscript() == null) {
|
|
|
|
if (qd.project.getMedia() == null)
|
|
|
|
fc.setSelectedFile(null);
|
|
|
|
else {
|
|
|
|
String path = qd.project.getMedia().getPath();
|
|
|
|
path = path.substring(0, path.lastIndexOf('.')) + QDShell.dotQuillDriver;
|
|
|
|
fc.setSelectedFile(new File(path));
|
|
|
|
}
|
2002-10-25 20:18:22 +00:00
|
|
|
} else
|
|
|
|
fc.setSelectedFile(qd.project.getTranscript());
|
|
|
|
|
|
|
|
int op = fc.showSaveDialog(QDShell.this);
|
|
|
|
if (op == JFileChooser.APPROVE_OPTION) {
|
|
|
|
File f = fc.getSelectedFile();
|
|
|
|
qd.project.setTranscript(f);
|
|
|
|
qd.saveTranscript();
|
2002-10-18 16:11:50 +00:00
|
|
|
}
|
2002-09-28 00:53:39 +00:00
|
|
|
}
|
2002-10-18 16:11:50 +00:00
|
|
|
private class QDFileFilter extends javax.swing.filechooser.FileFilter {
|
|
|
|
// accepts all directories and all savant files
|
2002-09-28 00:53:39 +00:00
|
|
|
|
2002-10-18 16:11:50 +00:00
|
|
|
public boolean accept(File f) {
|
|
|
|
if (f.isDirectory()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return f.getName().toLowerCase().endsWith(QDShell.dotQuillDriver);
|
|
|
|
}
|
|
|
|
|
|
|
|
//the description of this filter
|
|
|
|
public String getDescription() {
|
|
|
|
return "QD File Format (" + QDShell.dotQuillDriver + ")";
|
|
|
|
}
|
|
|
|
}
|
2002-10-27 19:12:13 +00:00
|
|
|
}
|