2002-10-03 19:28:09 +00:00
|
|
|
/*
|
|
|
|
The contents of this file are subject to the AMP 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 AMP web site
|
|
|
|
(http://www.tibet.iteso.mx/Guatemala/).
|
|
|
|
|
|
|
|
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 Andres Montano Pellegrini. Portions
|
|
|
|
created by Andres Montano Pellegrini are Copyright 2001 Andres Montano
|
|
|
|
Pellegrini. All Rights Reserved.
|
|
|
|
|
|
|
|
Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.thdl.tib.scanner;
|
2005-07-11 03:10:32 +00:00
|
|
|
import java.awt.BorderLayout;
|
|
|
|
import java.awt.CardLayout;
|
|
|
|
import java.awt.Font;
|
|
|
|
import java.awt.Frame;
|
|
|
|
import java.awt.GridLayout;
|
|
|
|
import java.awt.List;
|
|
|
|
import java.awt.Panel;
|
|
|
|
import java.awt.TextArea;
|
|
|
|
import java.awt.event.FocusListener;
|
|
|
|
import java.awt.event.ItemEvent;
|
|
|
|
import java.awt.event.ItemListener;
|
2002-10-03 19:28:09 +00:00
|
|
|
|
2002-11-03 08:56:11 +00:00
|
|
|
/** A non-Swing graphical interfase to be used by applications
|
|
|
|
running on platforms that don't support Swing,
|
|
|
|
to input a Tibetan text (in Roman script only) and
|
|
|
|
display the words (in Roman script only) with their
|
|
|
|
definitions (in Roman script).
|
|
|
|
|
|
|
|
@author Andrés Montano Pellegrini
|
|
|
|
@see WindowScannerFilter
|
|
|
|
*/
|
|
|
|
|
2003-08-03 06:29:08 +00:00
|
|
|
public class SimpleScannerPanel extends ScannerPanel implements ItemListener
|
2002-10-03 19:28:09 +00:00
|
|
|
{
|
|
|
|
private TextArea txtInput, txtOutput;
|
2003-08-03 06:29:08 +00:00
|
|
|
private Panel cardPanel;
|
|
|
|
private List listDefs;
|
|
|
|
private Word wordArray[];
|
|
|
|
private int lenPreview;
|
2004-12-23 19:31:26 +00:00
|
|
|
private boolean landscape;
|
2002-10-03 19:28:09 +00:00
|
|
|
|
2003-03-30 17:09:09 +00:00
|
|
|
public SimpleScannerPanel(String file, boolean landscape)
|
2002-10-03 19:28:09 +00:00
|
|
|
{
|
2003-03-30 17:09:09 +00:00
|
|
|
super(file);
|
|
|
|
Panel panel1, panel2;
|
2004-12-23 19:31:26 +00:00
|
|
|
Font defFont;
|
|
|
|
|
|
|
|
this.landscape = landscape;
|
2003-08-03 06:29:08 +00:00
|
|
|
cardPanel = new Panel(new CardLayout());
|
2003-03-30 17:09:09 +00:00
|
|
|
|
2004-12-23 19:31:26 +00:00
|
|
|
lenPreview = PocketWindowScannerFilter.getParsePaneCols(landscape);
|
2003-08-03 06:29:08 +00:00
|
|
|
wordArray=null;
|
|
|
|
|
|
|
|
// panel1 = new Panel(new GridLayout(3, 1));
|
2003-03-30 17:09:09 +00:00
|
|
|
|
2003-08-03 06:29:08 +00:00
|
|
|
// txtInput = new TextArea("",1,1,TextArea.SCROLLBARS_VERTICAL_ONLY);
|
2004-08-13 04:47:35 +00:00
|
|
|
|
|
|
|
panel1 = new Panel(new BorderLayout());
|
|
|
|
panel2 = new Panel(new GridLayout(2, 1));
|
|
|
|
|
2004-12-23 19:31:26 +00:00
|
|
|
defFont = WindowScannerFilter.getTHDLFont();
|
|
|
|
|
|
|
|
txtInput = new TextArea("", 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
|
|
|
|
txtInput.setFont(defFont);
|
|
|
|
|
2004-08-13 04:47:35 +00:00
|
|
|
listDefs = new List();
|
|
|
|
|
2004-12-23 19:31:26 +00:00
|
|
|
txtOutput = new TextArea("", 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
|
|
|
|
txtOutput.setFont(defFont);
|
|
|
|
|
|
|
|
if (landscape)
|
2004-08-13 04:47:35 +00:00
|
|
|
{
|
2004-12-23 19:31:26 +00:00
|
|
|
txtOutput.setRows(WindowScannerFilter.getOutputPaneRows());
|
|
|
|
|
2004-08-13 04:47:35 +00:00
|
|
|
panel2.add(txtInput);
|
|
|
|
panel2.add(listDefs);
|
|
|
|
|
|
|
|
panel1.add(panel2, BorderLayout.CENTER);
|
2004-12-23 19:31:26 +00:00
|
|
|
panel1.add(txtOutput, BorderLayout.SOUTH);
|
2004-08-13 04:47:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-23 19:31:26 +00:00
|
|
|
txtInput.setRows(WindowScannerFilter.getInputPaneRows());
|
|
|
|
|
|
|
|
panel2.add(txtInput);
|
2004-08-13 04:47:35 +00:00
|
|
|
panel2.add(listDefs);
|
2004-12-23 19:31:26 +00:00
|
|
|
|
|
|
|
panel1.add(panel2, BorderLayout.NORTH);
|
|
|
|
panel1.add(txtOutput, BorderLayout.CENTER);
|
2004-08-13 04:47:35 +00:00
|
|
|
}
|
2004-12-23 19:31:26 +00:00
|
|
|
|
2003-08-03 06:29:08 +00:00
|
|
|
listDefs.setMultipleMode(false);
|
|
|
|
listDefs.addItemListener(this);
|
2003-03-30 17:09:09 +00:00
|
|
|
|
2004-08-13 04:47:35 +00:00
|
|
|
txtOutput.setEditable(false);
|
|
|
|
|
2003-08-03 06:29:08 +00:00
|
|
|
cardPanel.add(panel1, "1");
|
2003-03-30 17:09:09 +00:00
|
|
|
|
2003-08-03 06:29:08 +00:00
|
|
|
// FIXME: values shouldn't be hardwired
|
|
|
|
if (landscape) panel2 = getDictPanel(2);
|
|
|
|
else panel2 = getDictPanel(1);
|
|
|
|
if (panel2!=null)
|
|
|
|
{
|
|
|
|
cardPanel.add(panel2, "2");
|
|
|
|
}
|
2003-03-30 17:09:09 +00:00
|
|
|
|
2004-08-13 04:47:35 +00:00
|
|
|
add(cardPanel, BorderLayout.CENTER);
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
2003-03-30 17:09:09 +00:00
|
|
|
|
2003-08-03 06:29:08 +00:00
|
|
|
public void itemStateChanged(ItemEvent e)
|
|
|
|
{
|
|
|
|
int n = listDefs.getSelectedIndex();
|
|
|
|
if (n>-1) txtOutput.setText(wordArray[n].toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-30 17:09:09 +00:00
|
|
|
public void setWylieInput(boolean enabled)
|
|
|
|
{
|
2003-08-03 06:29:08 +00:00
|
|
|
CardLayout cl = (CardLayout) cardPanel.getLayout();
|
|
|
|
if (enabled) cl.first(cardPanel);
|
|
|
|
else cl.last(cardPanel);
|
2003-03-30 17:09:09 +00:00
|
|
|
}
|
|
|
|
|
2002-10-03 19:28:09 +00:00
|
|
|
|
|
|
|
public void addFocusListener(FocusListener fl)
|
|
|
|
{
|
|
|
|
txtInput.addFocusListener(fl);
|
|
|
|
txtOutput.addFocusListener(fl);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void printAllDefs()
|
|
|
|
{
|
|
|
|
int i;
|
2003-08-03 06:29:08 +00:00
|
|
|
wordArray = scanner.getWordArray();
|
|
|
|
String preview;
|
2002-10-03 19:28:09 +00:00
|
|
|
|
2003-08-03 06:29:08 +00:00
|
|
|
listDefs.removeAll();
|
|
|
|
|
|
|
|
for(i=0; i<wordArray.length; i++)
|
|
|
|
{
|
2004-08-13 04:47:35 +00:00
|
|
|
preview = wordArray[i].getWordDefPreview();
|
2003-08-03 06:29:08 +00:00
|
|
|
if (preview.length()>lenPreview) preview = preview.substring(0,lenPreview);
|
|
|
|
listDefs.add(preview);
|
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clear()
|
|
|
|
{
|
|
|
|
txtInput.setText("");
|
|
|
|
txtOutput.setText("");
|
2003-08-03 06:29:08 +00:00
|
|
|
listDefs.removeAll();
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void translate()
|
|
|
|
{
|
|
|
|
String in;
|
|
|
|
setDicts(scanner.getDictionarySource());
|
|
|
|
in = txtInput.getText();
|
|
|
|
doingStatus("Translating...");
|
|
|
|
if (!in.equals(""))
|
|
|
|
{
|
|
|
|
txtOutput.setText("");
|
|
|
|
scanner.scanBody(in);
|
|
|
|
scanner.finishUp();
|
|
|
|
printAllDefs();
|
|
|
|
scanner.clearTokens();
|
|
|
|
returnStatusToNorm();
|
|
|
|
}
|
2004-12-23 19:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPreferences(Frame owner)
|
|
|
|
{
|
|
|
|
PocketPreferenceWindow ppw = new PocketPreferenceWindow(owner, landscape);
|
|
|
|
Font font;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ppw.dataInputed())
|
|
|
|
{
|
|
|
|
lenPreview = PocketWindowScannerFilter.getParsePaneCols(landscape);
|
|
|
|
font = WindowScannerFilter.getTHDLFont();
|
|
|
|
if (landscape) txtOutput.setRows(WindowScannerFilter.getOutputPaneRows());
|
|
|
|
else txtInput.setRows(WindowScannerFilter.getInputPaneRows());
|
|
|
|
status.setFont(font);
|
|
|
|
cmdTranslate.setFont(font);
|
|
|
|
txtInput.setFont(font);
|
|
|
|
listDefs.setFont(font);
|
|
|
|
txtOutput.setFont(font);
|
|
|
|
for (i=0; i<chkDicts.length; i++)
|
|
|
|
chkDicts[i].setFont(font);
|
|
|
|
setFont(font);
|
|
|
|
owner.setFont(font);
|
|
|
|
validate();
|
|
|
|
owner.validate();
|
|
|
|
}
|
|
|
|
ppw.dispose();
|
|
|
|
}
|
2002-10-03 19:28:09 +00:00
|
|
|
}
|