=================================================================== RCS file: /home/cvs/OpenXM/src/OpenMath/PolyCalc.java,v retrieving revision 1.1.1.1 retrieving revision 1.14 diff -u -p -r1.1.1.1 -r1.14 --- OpenXM/src/OpenMath/PolyCalc.java 1999/11/02 11:52:34 1.1.1.1 +++ OpenXM/src/OpenMath/PolyCalc.java 2005/07/17 02:49:27 1.14 @@ -1,138 +1,249 @@ -import JP.ac.kobe_u.math.tam.OpenXM.*; +/** + * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.13 2005/07/17 02:48:21 takayama Exp $ + */ + +/* + How to try. + ox -ox ox_sm1 + java PolyCalc + Input two polynomials in x and y and Press the grobner base button. + Actions for other buttons have not yet been implemented. + */ + +import ORG.openxm.tam.*; import java.applet.*; +import java.awt.event.*; import java.awt.*; -class PolyCalc extends Applet{ - private String host; - int ControlPort,DataPort; - private OpenXM oxm; - private Button random1_button,random2_button; - private Button mul_button,remainder_button,swap_button,set_button; - private TextField poly1,poly2; - private TextArea textarea; - //private Text +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 TextField poly1,poly2; + private TextArea textarea; + private Thread thread = null; + private boolean debug = false; + //private Text - PolyCalc(String host,int ControlPort,int DataPort){ - this.host = host; - this.ControlPort = ControlPort; - this.DataPort = DataPort; - } + PolyCalc(String host,int ControlPort,int DataPort){ + this.host = host; + this.ControlPort = ControlPort; + this.DataPort = DataPort; + } - public void init(){ - GridBagLayout gridbag = new GridBagLayout(); - GridBagConstraints c = new GridBagConstraints(); + public void init(){ + GridBagLayout gridbag = new GridBagLayout(); + GridBagConstraints c = new GridBagConstraints(); + Button button; - //setFont(); - setLayout(gridbag); + //setFont(); + setLayout(gridbag); - c.fill = GridBagConstraints.BOTH; + c.fill = GridBagConstraints.BOTH; - textarea = new TextArea(); - textarea.setEditable(false); - c.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints(textarea,c); - c.gridwidth = 1; - add(textarea); + textarea = new TextArea(); + textarea.setEditable(false); + c.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints(textarea,c); + c.gridwidth = 1; + add(textarea); - { - Label label = new Label("poly 1:"); - gridbag.setConstraints(label,c); - add(label); - } + { + 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"); - c.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints(mul_button,c); - c.gridwidth = 1; - add(mul_button); + button = new Button("A * B"); + button.addActionListener(this); + c.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints(button,c); + c.gridwidth = 1; + add(button); - poly1 = new TextField(20); - c.gridwidth = 2; - gridbag.setConstraints(poly1,c); - c.gridwidth = 1; - add(poly1); + 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"); - //c.gridx = 2; - //c.weightx = 0.0; - gridbag.setConstraints(remainder_button,c); - add(remainder_button); + button = new Button("A % B"); + button.addActionListener(this); + //c.gridx = 2; + //c.weightx = 0.0; + gridbag.setConstraints(button,c); + add(button); - swap_button = new Button("swap poly1 & poly2"); - c.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints(swap_button,c); - c.gridwidth = 1; - add(swap_button); + button = new Button("swap A & B"); + button.addActionListener(this); + c.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints(button,c); + c.gridwidth = 1; + add(button); - { - Label label = new Label("poly 2:"); - gridbag.setConstraints(label,c); - add(label); + { + Label label = new Label("poly B:"); + gridbag.setConstraints(label,c); + add(label); + } + + button = new Button("generate random polynomial B"); + button.addActionListener(this); + gridbag.setConstraints(button,c); + add(button); + + button = new Button("poly1 <= poly2"); + button.addActionListener(this); + c.gridwidth = GridBagConstraints.REMAINDER; + gridbag.setConstraints(button,c); + c.gridwidth = 1; + 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); } - random2_button = new Button("generate random polynomial"); - gridbag.setConstraints(random2_button,c); - add(random2_button); + public void run(){ // for debug + try{ + while(true){ + OXmessage tmp = oxm.receive(); - set_button = new Button("poly1 <= poly2"); - c.gridwidth = GridBagConstraints.REMAINDER; - gridbag.setConstraints(set_button,c); - c.gridwidth = 1; - add(set_button); + textarea.append("=> "+ tmp.getBody() +"\n"); + Thread.yield(); + } + }catch(java.io.IOException e){} + } - poly2 = new TextField(); - c.gridwidth = 2; - gridbag.setConstraints(poly2,c); - c.gridwidth = 1; - add(poly2); - } + public void actionPerformed(ActionEvent evt) { + String arg = evt.getActionCommand(); - public void start(){ - textarea.append("Connecting to "+ host - +"("+ ControlPort +","+ DataPort +")\n"); + debug("press \""+ arg +"\" button."); - try{ - oxm = new OpenXM("localhost",1200,1300); - }catch(java.io.IOException e){ - textarea.append("failed.\n"); - stop(); - return; + 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); + } + */ } - textarea.append("Connected.\n"); - } - public static void main(String argv[]){ - Frame frame = new Frame("Polynomial Calculator"); - Applet applet; - String host = "localhost"; - int DataPort = 1300, ControlPort = 1200; + public void start(){ + textarea.append("Connecting to "+ host + +"("+ ControlPort +","+ DataPort +")\n"); - for(int i=0;i