Now the handheld version supports both portrait and landscape.

This commit is contained in:
amontano 2003-03-30 17:09:09 +00:00
parent f9670233ba
commit 8565855dd1
5 changed files with 122 additions and 82 deletions

View file

@ -263,7 +263,7 @@ public class AppletScannerFilter extends JApplet implements ActionListener, Focu
} }
public void itemStateChanged(ItemEvent e) public void itemStateChanged(ItemEvent e)
{ {
sp.setEnableTibetanScript(e.getStateChange()==ItemEvent.SELECTED); sp.setWylieInput(e.getStateChange()!=ItemEvent.SELECTED);
} }
class SymComponent extends java.awt.event.ComponentAdapter class SymComponent extends java.awt.event.ComponentAdapter

View file

@ -50,7 +50,10 @@ public class DuffScannerPanel extends ScannerPanel
public DuffScannerPanel(String file) public DuffScannerPanel(String file)
{ {
super(file); super(file);
Panel panel1; Panel panel1, panel2;
panel2 = new Panel(new BorderLayout());
panel1 = getDictPanel();
if (panel1!=null) panel2.add (panel1, BorderLayout.NORTH);
panel1 = new Panel(new GridLayout(3,1)); panel1 = new Panel(new GridLayout(3,1));
/* Looks up tibcodes in directory of applet. In order /* Looks up tibcodes in directory of applet. In order
to work through a proxy store all the applet classes toghether to work through a proxy store all the applet classes toghether
@ -77,7 +80,8 @@ public class DuffScannerPanel extends ScannerPanel
panel1.add(listDef); panel1.add(listDef);
panel1.add(fullDef); panel1.add(fullDef);
add(panel1, BorderLayout.CENTER); panel2.add(panel1, BorderLayout.CENTER);
add(panel2, BorderLayout.CENTER);
showingTibetan = true; showingTibetan = true;
// tibetanFont = new Font("TibetanMachine",Font.PLAIN,36); // tibetanFont = new Font("TibetanMachine",Font.PLAIN,36);
@ -175,10 +179,10 @@ public class DuffScannerPanel extends ScannerPanel
table.repaint(); table.repaint();
} }
public void setEnableTibetanScript(boolean enabled) public void setWylieInput(boolean enabled)
{ {
CardLayout cl = (CardLayout) inputPanel.getLayout(); CardLayout cl = (CardLayout) inputPanel.getLayout();
if (enabled && !showingTibetan) if (!enabled && !showingTibetan)
{ {
String s = txtInput.getText(); String s = txtInput.getText();
/* int posEnter = s.indexOf('\n'); /* int posEnter = s.indexOf('\n');
@ -191,7 +195,7 @@ public class DuffScannerPanel extends ScannerPanel
cl.first(inputPanel); cl.first(inputPanel);
showingTibetan = true; showingTibetan = true;
} }
if (!enabled && showingTibetan) if (enabled && showingTibetan)
{ {
txtInput.setText(duffInput.getWylie()); txtInput.setText(duffInput.getWylie());
table.activateTibetan(false); table.activateTibetan(false);

View file

@ -31,6 +31,7 @@ import java.io.*;
*/ */
public abstract class ScannerPanel extends Panel implements ActionListener public abstract class ScannerPanel extends Panel implements ActionListener
{ {
private static int dictCols=4;
private Label status; private Label status;
protected Checkbox chkDicts[]; protected Checkbox chkDicts[];
Button cmdTranslate; Button cmdTranslate;
@ -40,26 +41,9 @@ public abstract class ScannerPanel extends Panel implements ActionListener
hidden through the menu. hidden through the menu.
*/ */
public ScannerPanel(String file, boolean ipaq)
{
this(file, ipaq, 4);
}
public ScannerPanel(String file) public ScannerPanel(String file)
{
this(file, false, 4);
}
public ScannerPanel(String file, int cols)
{
this(file, false, 4);
}
public ScannerPanel(String file, boolean ipaq, int cols)
{ {
boolean exito=true; boolean exito=true;
int rows, n;
setLayout(new BorderLayout()); setLayout(new BorderLayout());
status = new Label(); status = new Label();
@ -83,57 +67,58 @@ public abstract class ScannerPanel extends Panel implements ActionListener
else else
scanner = new LocalTibetanScanner(file); scanner = new LocalTibetanScanner(file);
String dictionaries[] = scanner.getDictionaryDescriptions();
if (dictionaries!=null)
{
n = dictionaries.length;
chkDicts = new Checkbox[n];
if (n>cols)
{
rows = n/cols;
if (n%cols>0) rows++;
}
else
{
cols = n;
rows = 1;
}
Panel panel2 = new Panel(new GridLayout(rows,cols));
// panel2 = new Panel();
int i;
for (i=0; i<dictionaries.length; i++)
{
if (dictionaries[i]!=null)
chkDicts[i] = new Checkbox(dictionaries[i] + " (" + Definitions.defTags[i] + ")", true);
else
chkDicts[i] = new Checkbox(Definitions.defTags[i], true);
panel2.add(chkDicts[i]);
}
panel1.add(panel2, BorderLayout.SOUTH);
}
} }
catch (Exception e) catch (Exception e)
{ {
status.setText("Dictionary could no be loaded!"); status.setText("Dictionary could no be loaded!");
exito=false; exito=false;
} }
if (ipaq) add(panel1, BorderLayout.NORTH);
{
/* panel2 = new Panel(new BorderLayout());
panel2.add(panel1, BorderLayout.CENTER);
panel2.add(copyright, BorderLayout.SOUTH);
add(panel2, BorderLayout.SOUTH);*/
add(panel1, BorderLayout.SOUTH);
}
else
{
add(panel1, BorderLayout.NORTH);
// add(copyright, BorderLayout.SOUTH);
}
if (exito) if (exito)
returnStatusToNorm(); returnStatusToNorm();
} }
protected Panel getDictPanel()
{
return getDictPanel(dictCols);
}
protected Panel getDictPanel(int dictCols)
{
int rows, n;
String dictionaries[] = scanner.getDictionaryDescriptions();
if (dictionaries!=null)
{
n = dictionaries.length;
chkDicts = new Checkbox[n];
if (n>dictCols)
{
rows = n/dictCols;
if (n%dictCols>0) rows++;
}
else
{
dictCols = n;
rows = 1;
}
Panel panel2 = new Panel(new GridLayout(rows,dictCols));
// panel2 = new Panel();
int i;
for (i=0; i<dictionaries.length; i++)
{
if (dictionaries[i]!=null)
chkDicts[i] = new Checkbox(dictionaries[i] + " (" + Definitions.defTags[i] + ")", true);
else
chkDicts[i] = new Checkbox(Definitions.defTags[i], true);
panel2.add(chkDicts[i]);
}
return panel2;
}
return null;
}
protected void doingStatus(String s) protected void doingStatus(String s)
{ {
@ -177,6 +162,6 @@ public abstract class ScannerPanel extends Panel implements ActionListener
public abstract void translate(); public abstract void translate();
public abstract void clear(); public abstract void clear();
public void setEnableTibetanScript(boolean enabled) {} public abstract void setWylieInput(boolean enabled);
public void addFocusListener(FocusListener fl) {} public void addFocusListener(FocusListener fl) {}
} }

View file

@ -33,12 +33,50 @@ import java.awt.event.*;
public class SimpleScannerPanel extends ScannerPanel public class SimpleScannerPanel extends ScannerPanel
{ {
private TextArea txtInput, txtOutput; private TextArea txtInput, txtOutput;
private Panel inputPanel;
public SimpleScannerPanel(String file) public SimpleScannerPanel(String file, boolean landscape)
{ {
super(file, true); super(file);
Panel panel1; Panel panel1, panel2;
GridBagLayout gridbag = new GridBagLayout(); inputPanel = new Panel(new CardLayout());
txtInput = new TextArea("",1,1,TextArea.SCROLLBARS_VERTICAL_ONLY);
inputPanel.add(txtInput, "1");
if (landscape) panel2 = getDictPanel(5);
else panel2 = getDictPanel(4);
if (panel2!=null)
{
inputPanel.add(panel2, "2");
}
txtOutput = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
txtOutput.setEditable(false);
panel1 = new Panel(new BorderLayout());
panel1.add(inputPanel, BorderLayout.NORTH);
panel1.add(txtOutput, BorderLayout.CENTER);
/*panel1 = new Panel (new GridLayout(2,1));
panel1.add(inputPanel);
panel1.add(txtOutput);*/
/*GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
panel1 = new Panel(gridbag);
c.weightx=1;
c.gridheight=1;
c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(inputPanel, c);
panel1.add(inputPanel);
c.gridheight=2;
c.weighty=1;
c.gridheight = GridBagConstraints.REMAINDER;
gridbag.setConstraints(txtOutput, c);
panel1.add(txtOutput);*/
/* GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
panel1 = new Panel(gridbag); panel1 = new Panel(gridbag);
c.weightx=1; c.weightx=1;
@ -46,17 +84,22 @@ public class SimpleScannerPanel extends ScannerPanel
c.gridheight=1; c.gridheight=1;
c.fill = GridBagConstraints.BOTH; c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER;
txtInput = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
txtOutput = new TextArea("",0,0,TextArea.SCROLLBARS_VERTICAL_ONLY);
txtOutput.setEditable(false);
gridbag.setConstraints(txtInput, c); gridbag.setConstraints(txtInput, c);
panel1.add(txtInput); panel1.add(txtInput);
c.gridheight = GridBagConstraints.REMAINDER; c.gridheight = GridBagConstraints.REMAINDER;
c.ipady = 70; c.ipady = 70;
gridbag.setConstraints(txtOutput, c); gridbag.setConstraints(txtOutput, c);*/
panel1.add(txtOutput);
add(panel1, BorderLayout.CENTER); add(panel1, BorderLayout.CENTER);
} }
public void setWylieInput(boolean enabled)
{
CardLayout cl = (CardLayout) inputPanel.getLayout();
if (enabled) cl.first(inputPanel);
else cl.last(inputPanel);
}
public void addFocusListener(FocusListener fl) public void addFocusListener(FocusListener fl)
{ {

View file

@ -46,7 +46,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
{ {
private ScannerPanel sp; private ScannerPanel sp;
private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear; private MenuItem mnuExit, mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuSelectAll, mnuAbout, mnuClear;
private CheckboxMenuItem tibScript; private CheckboxMenuItem tibScript, mnuDicts;
private Object objModified; private Object objModified;
private Frame frame; private Frame frame;
private Dialog diagAbout; private Dialog diagAbout;
@ -64,11 +64,12 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
frame.setBackground(Color.white); frame.setBackground(Color.white);
diagAbout = null; diagAbout = null;
usingSwing=!ipaq; usingSwing=!ipaq;
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
if (usingSwing) if (usingSwing)
sp = new DuffScannerPanel(file); sp = new DuffScannerPanel(file);
else else
sp = new SimpleScannerPanel(file); sp = new SimpleScannerPanel(file, d.width >d.height);
MenuBar mb = new MenuBar(); MenuBar mb = new MenuBar();
Menu m = new Menu ("File"); Menu m = new Menu ("File");
@ -102,15 +103,22 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
m.add(mnuClear); m.add(mnuClear);
mnuClear.addActionListener(this); mnuClear.addActionListener(this);
mb.add(m); mb.add(m);
m = new Menu("View");
if (usingSwing) if (usingSwing)
{ {
m = new Menu("View");
tibScript = new CheckboxMenuItem("Tibetan Script", true); tibScript = new CheckboxMenuItem("Tibetan Script", true);
m.add(tibScript); m.add(tibScript);
tibScript.addItemListener(this); tibScript.addItemListener(this);
mb.add(m); mnuDicts=null;
} }
else tibScript=null; else
{
mnuDicts = new CheckboxMenuItem("Dictionaries", false);
m.add(mnuDicts);
mnuDicts.addItemListener(this);
tibScript=null;
}
mb.add(m);
m = new Menu("Help"); m = new Menu("Help");
mnuAbout = new MenuItem("About..."); mnuAbout = new MenuItem("About...");
@ -125,7 +133,7 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
frame.setMenuBar(mb); frame.setMenuBar(mb);
frame.add(sp); frame.add(sp);
frame.addWindowListener(this); frame.addWindowListener(this);
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize()); frame.setSize(d);
// frame.setSize(240,320); // frame.setSize(240,320);
//else frame.setSize(500,600); //else frame.setSize(500,600);
frame.show(); frame.show();
@ -374,6 +382,6 @@ public class WindowScannerFilter implements WindowListener, FocusListener, Actio
public void itemStateChanged(ItemEvent e) public void itemStateChanged(ItemEvent e)
{ {
sp.setEnableTibetanScript(e.getStateChange()==ItemEvent.SELECTED); sp.setWylieInput(e.getStateChange()!=ItemEvent.SELECTED);
} }
} }