Added the following features: now starts with focus on the input pane, shortcut ctrl+T to translate, and after translating focus is automatically set on the first element.

This commit is contained in:
amontano 2005-08-27 01:51:40 +00:00
parent 58819cf43d
commit efec654ee8
5 changed files with 58 additions and 45 deletions

View file

@ -157,6 +157,11 @@ public class DuffScannerPanel extends ScannerPanel implements ItemListener
toolBar.add(keyboard);
}
public void setFocusToInput()
{
duffInput.requestFocusInWindow();
}
public void addFocusListener(FocusListener fl)
{
txtInput.addFocusListener(fl);
@ -235,41 +240,42 @@ public class DuffScannerPanel extends ScannerPanel implements ItemListener
public void translate()
{
String in;
setDicts(scanner.getDictionarySource());
String in;
setDicts(scanner.getDictionarySource());
in = "";
if (showingTibetan)
in = duffInput.getWylie(new boolean[] { false });
else
in = "";
if (showingTibetan)
in = duffInput.getWylie(new boolean[] { false });
else
in = txtInput.getText();
if (!in.equals(""))
{
doingStatus("Translating...");
scanner.scanBody(in);
scanner.finishUp();
model.newSearch(scanner.getWordArray());
//printAllDefs();
scanner.clearTokens();
returnStatusToNorm();
fullDef.setText("");
/*ListSelectionModel lsm = (ListSelectionModel)table.getSelectionModel();
if (!lsm.isSelectionEmpty())
{
int selectedRow = lsm.getMinSelectionIndex();
//TableModel tm = table.getModel();
if (selectedRow<model.getRowCount())
fullDef.setText(model.getValueAt(selectedRow, 1).toString());
}*/
}
else
{
model.newSearch(null);
fullDef.setText("");
}
table.tableChanged(new TableModelEvent(model));
if (!in.equals(""))
{
doingStatus("Translating...");
scanner.scanBody(in);
scanner.finishUp();
model.newSearch(scanner.getWordArray());
//printAllDefs();
scanner.clearTokens();
returnStatusToNorm();
fullDef.setText("");
/*ListSelectionModel lsm = (ListSelectionModel)table.getSelectionModel();
if (!lsm.isSelectionEmpty())
{
int selectedRow = lsm.getMinSelectionIndex();
//TableModel tm = table.getModel();
if (selectedRow<model.getRowCount())
fullDef.setText(model.getValueAt(selectedRow, 1).toString());
}*/
}
else
{
model.newSearch(null);
fullDef.setText("");
}
table.tableChanged(new TableModelEvent(model));
table.repaint();
if (table.getRowCount()>0) table.setRowSelectionInterval(0,0);
}
public void setWylieInput(boolean enabled)

View file

@ -215,5 +215,6 @@ public abstract class ScannerPanel extends Panel implements ActionListener
public abstract void translate();
public abstract void clear();
public abstract void setWylieInput(boolean enabled);
public abstract void setFocusToInput();
public void addFocusListener(FocusListener fl) {}
}

View file

@ -116,6 +116,11 @@ public class SimpleScannerPanel extends ScannerPanel implements ItemListener
add(cardPanel, BorderLayout.CENTER);
}
public void setFocusToInput()
{
txtInput.requestFocusInWindow();
}
public void itemStateChanged(ItemEvent e)
{
int n = listDefs.getSelectedIndex();

View file

@ -18,21 +18,11 @@ Contributor(s): ______________________________________.
package org.thdl.tib.scanner;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.TextArea;
import java.awt.TextComponent;
import java.awt.Toolkit;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.*;
import java.io.IOException;
import javax.swing.JOptionPane;
@ -145,6 +135,12 @@ public class SwingWindowScannerFilter extends WindowScannerFilter
mnuDicts=null;
mb.add(m);
m = new Menu("Tools");
mnuTranslate = new MenuItem ("Translate");
mnuTranslate.setShortcut(new MenuShortcut(KeyEvent.VK_T));
mnuTranslate.addActionListener(this);
m.add(mnuTranslate);
mb.add(m);
m = new Menu("Help");
@ -191,6 +187,7 @@ public class SwingWindowScannerFilter extends WindowScannerFilter
//else mainWindow.setSize(500,600);
mainWindow.show();
mainWindow.toFront();
sp.setFocusToInput();
if (!ThdlOptions.getBooleanOption(AboutDialog.windowAboutOption))
{
@ -323,6 +320,10 @@ public class SwingWindowScannerFilter extends WindowScannerFilter
}
}
else if (clicked == mnuTranslate)
{
sp.translate();
}
else
{
if (objModified==null) return;

View file

@ -54,7 +54,7 @@ public abstract class WindowScannerFilter implements WindowListener, FocusListen
protected static String defaultOutputRows = "thdl.scanner.output-pane.rows";
protected ScannerPanel sp;
protected MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref;
protected MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear, mnuOpen, mnuPreferences, mnuSavePref, mnuTranslate;
protected CheckboxMenuItem mnuDicts;
protected Object objModified;
protected AboutDialog diagAbout;