Jskad/source/org/thdl/quilldriver/QDShell.java
dchandler 635b707067 Thanks to the TeeStream, standard output and standard error are now
written to, in addition to writing to the .log file.
2002-10-04 04:52:41 +00:00

184 lines
5.2 KiB
Java

/*
The contents of this file are subject to the THDL Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the THDL web site
(http://www.thdl.org/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is the Tibetan and Himalayan Digital
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.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.*;
import org.thdl.util.TeeStream;
public class QDShell extends JFrame {
ResourceBundle messages = null;
QD qd = null;
public static void main(String[] args) {
try {
PrintStream psOut
= new TeeStream(System.out,
new PrintStream(new FileOutputStream("qd.log")));
PrintStream psErr
= new TeeStream(System.err,
new PrintStream(new FileOutputStream("qd.log")));
System.setErr(psErr);
System.setOut(psOut);
}
catch (Exception e) {
}
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();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
}
QDShell qdsh = new QDShell(locale);
qdsh.setVisible(true);
}
public QDShell(Locale locale) {
setTitle("QuillDriver");
/*
// Code for Merlin
if (getToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
{
setLocation(0,0);
setSize(getToolkit().getScreenSize().width,getToolkit().getScreenSize().height);
setVisible(true);
setExtendedState(Frame.MAXIMIZED_BOTH);
} else {
*/
Dimension gs = getToolkit().getScreenSize();
setLocation(0,0);
setSize(new Dimension(gs.width, gs.height));
setVisible(true);
// }
messages = ResourceBundle.getBundle("MessageBundle", locale);
setJMenuBar(getQDShellMenu());
qd = new QD(messages);
getContentPane().add(qd);
addWindowListener(new WindowAdapter () {
public void windowClosing (WindowEvent e) {
qd.getSave();
//should only system exit if no cancel!!
System.exit(0);
}
});
}
public JMenuBar getQDShellMenu() {
JMenu projectMenu = new JMenu(messages.getString("Project"));
JMenuItem newItem = new JMenuItem(messages.getString("New"));
JMenuItem openItem = new JMenuItem(messages.getString("Open"));
openItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
qd.getOpen();
}
});
JMenuItem closeItem = new JMenuItem(messages.getString("Close"));
JMenuItem saveItem = new JMenuItem(messages.getString("Save"));
saveItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
qd.getSave();
}
});
JMenuItem quitItem = new JMenuItem(messages.getString("Quit"));
quitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
qd.getSave();
//should only system exit if no cancel!!
System.exit(0);
}
});
projectMenu.add(newItem);
projectMenu.add(openItem);
projectMenu.add(closeItem);
projectMenu.addSeparator();
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
JRadioButton wylieButton = new JRadioButton("THDL Extended Wylie");
JRadioButton sambhotaButton = new JRadioButton("Sambhota Keymap One");
JRadioButton tcc1Button = new JRadioButton("TCC Keyboard 1");
JRadioButton tcc2Button = new JRadioButton("TCC Keyboard 2");
wylieButton.setActionCommand("wylie");
sambhotaButton.setActionCommand("sambhota1");
tcc1Button.setActionCommand("tcc1");
tcc2Button.setActionCommand("tcc2");
RadioListener l = new RadioListener();
wylieButton.addActionListener(l);
sambhotaButton.addActionListener(l);
tcc1Button.addActionListener(l);
tcc2Button.addActionListener(l);
wylieButton.setSelected(true);
ButtonGroup bg = new ButtonGroup();
bg.add(wylieButton);
bg.add(sambhotaButton);
bg.add(tcc1Button);
bg.add(tcc2Button);
JPanel buttons = new JPanel(new GridLayout(0,1));
buttons.add(wylieButton);
buttons.add(sambhotaButton);
buttons.add(tcc1Button);
buttons.add(tcc2Button);
JMenu keyboardMenu = new JMenu(messages.getString("Keyboard"));
keyboardMenu.add(buttons);
JMenu preferencesMenu = new JMenu(messages.getString("Preferences"));
preferencesMenu.add(keyboardMenu);
JMenuBar bar = new JMenuBar();
bar.add(projectMenu);
bar.add(preferencesMenu);
return bar;
}
class RadioListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
qd.changeKeyboard(e);
}
}
}