=================================================================== RCS file: /home/cvs/OpenXM/src/OpenMath/PolyCalc.java,v retrieving revision 1.1.1.1 retrieving revision 1.12 diff -u -p -r1.1.1.1 -r1.12 --- OpenXM/src/OpenMath/PolyCalc.java 1999/11/02 11:52:34 1.1.1.1 +++ OpenXM/src/OpenMath/PolyCalc.java 2000/10/11 09:34:06 1.12 @@ -1,15 +1,22 @@ -import JP.ac.kobe_u.math.tam.OpenXM.*; +/** + * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.11 2000/10/11 08:32:13 ohara Exp $ + */ + +import ORG.openxm.tam.*; import java.applet.*; +import java.awt.event.*; import java.awt.*; -class PolyCalc extends Applet{ - private String host; - int ControlPort,DataPort; +class PolyCalc extends Applet implements ActionListener,Runnable{ + private String host = "localhost"; + private int ControlPort = 1200,DataPort = 1300; private OpenXM oxm; - private Button random1_button,random2_button; - private Button mul_button,remainder_button,swap_button,set_button; + //private Button random1_button,random2_button; + //private Button mul_button,remainder_button,swap_button,set_button; private TextField poly1,poly2; private TextArea textarea; + private Thread thread = null; + private boolean debug = false; //private Text PolyCalc(String host,int ControlPort,int DataPort){ @@ -21,6 +28,7 @@ class PolyCalc extends Applet{ public void init(){ GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); + Button button; //setFont(); setLayout(gridbag); @@ -35,86 +43,178 @@ class PolyCalc extends Applet{ add(textarea); { - Label label = new Label("poly 1:"); + Label label = new Label("poly A:"); gridbag.setConstraints(label,c); add(label); } - random1_button = new Button("generate random polynomial"); - gridbag.setConstraints(random1_button,c); - add(random1_button); + button = new Button("generate random polynomial A"); + button.addActionListener(this); + gridbag.setConstraints(button,c); + add(button); - mul_button = new Button("poly1 * poly2"); + button = new Button("A * B"); + button.addActionListener(this); c.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints(mul_button,c); + gridbag.setConstraints(button,c); c.gridwidth = 1; - add(mul_button); + add(button); poly1 = new TextField(20); + poly1.addActionListener(this); c.gridwidth = 2; gridbag.setConstraints(poly1,c); c.gridwidth = 1; add(poly1); - remainder_button = new Button("poly1 % poly2"); + button = new Button("A % B"); + button.addActionListener(this); //c.gridx = 2; //c.weightx = 0.0; - gridbag.setConstraints(remainder_button,c); - add(remainder_button); + gridbag.setConstraints(button,c); + add(button); - swap_button = new Button("swap poly1 & poly2"); + button = new Button("swap A & B"); + button.addActionListener(this); c.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints(swap_button,c); + gridbag.setConstraints(button,c); c.gridwidth = 1; - add(swap_button); + add(button); { - Label label = new Label("poly 2:"); + Label label = new Label("poly B:"); gridbag.setConstraints(label,c); add(label); } - random2_button = new Button("generate random polynomial"); - gridbag.setConstraints(random2_button,c); - add(random2_button); + button = new Button("generate random polynomial B"); + button.addActionListener(this); + gridbag.setConstraints(button,c); + add(button); - set_button = new Button("poly1 <= poly2"); + button = new Button("poly1 <= poly2"); + button.addActionListener(this); c.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints(set_button,c); + gridbag.setConstraints(button,c); c.gridwidth = 1; - add(set_button); + add(button); poly2 = new TextField(); c.gridwidth = 2; gridbag.setConstraints(poly2,c); c.gridwidth = 1; add(poly2); + + button = new Button("grobner base"); + button.addActionListener(this); + gridbag.setConstraints(button,c); + add(button); + + button = new Button("quit"); + button.addActionListener(this); + gridbag.setConstraints(button,c); + add(button); } + public void run(){ // for debug + try{ + while(true){ + OXmessage tmp = oxm.receive(); + + textarea.append("=> "+ tmp +"\n"); + Thread.yield(); + } + }catch(java.io.IOException e){} + } + + public void actionPerformed(ActionEvent evt) { + String arg = evt.getActionCommand(); + + debug("press \""+ arg +"\" button."); + + if(arg.equals("quit")){ + }else if(arg.equals("grobner base")){ + try{ + debug("poly A: "+ poly1.getText()); + oxm.send(new CMO_STRING("[[("+ poly1.getText() +") ("+ poly2.getText() +")] (x,y)] gb")); + oxm.send(new SM(SM.SM_executeStringByLocalParser)); + oxm.send(new SM(SM.SM_popString)); + }catch(java.io.IOException e){ + }catch(MathcapViolation e){ + } + } + /* + if ("first".equals(arg)) { + ((CardLayout)cards.getLayout()).first(cards); + } else if ("next".equals(arg)) { + ((CardLayout)cards.getLayout()).next(cards); + } else if ("previous".equals(arg)) { + ((CardLayout)cards.getLayout()).previous(cards); + } else if ("last".equals(arg)) { + ((CardLayout)cards.getLayout()).last(cards); + } else { + ((CardLayout)cards.getLayout()).show(cards,(String)arg); + } + */ + } + public void start(){ textarea.append("Connecting to "+ host +"("+ ControlPort +","+ DataPort +")\n"); try{ - oxm = new OpenXM("localhost",1200,1300); + /* + Runtime r = Runtime.getRuntime(); + + r.exec("ox -ox ox_sm1"); + */ + oxm = new OpenXM(host,ControlPort,DataPort); + textarea.append("Connected.\n"); + oxm.send(new CMO_STRING("(cohom.sm1) run ;\n")); + oxm.send(new SM(SM.SM_executeStringByLocalParser)); + + thread = new Thread(this); + thread.start(); }catch(java.io.IOException e){ textarea.append("failed.\n"); stop(); - return; + }catch(MathcapViolation e){ } - textarea.append("Connected.\n"); } + private void debug(String str){ + if(debug){ + System.err.println(str); + } + } + + private static String usage(){ + String ret = ""; + + ret += "usage\t: java PolyCalc [options]\n"; + ret += "options\t:\n"; + ret += "\t -h \t show this message\n"; + ret += "\t -host hostname \t (default localhost)\n"; + ret += "\t -data port \t (default 1300)\n"; + ret += "\t -control port \t (default 1200)\n"; + ret += "\t -debug \t display debug message\n"; + + return ret; + } + public static void main(String argv[]){ Frame frame = new Frame("Polynomial Calculator"); - Applet applet; + //Applet applet; + PolyCalc applet; String host = "localhost"; int DataPort = 1300, ControlPort = 1200; for(int i=0;i