| version 1.13, 2005/07/17 02:48:21 |
version 1.14, 2005/07/17 02:49:27 |
|
|
| /** |
/** |
| * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.12 2000/10/11 09:34:06 ohara Exp $ |
* $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.13 2005/07/17 02:48:21 takayama Exp $ |
| */ |
*/ |
| |
|
| /* |
/* |
| Line 16 import java.awt.event.*; |
|
| Line 16 import java.awt.event.*; |
|
| import java.awt.*; |
import java.awt.*; |
| |
|
| class PolyCalc extends Applet implements ActionListener,Runnable{ |
class PolyCalc extends Applet implements ActionListener,Runnable{ |
| private String host = "localhost"; |
private String host = "localhost"; |
| private int ControlPort = 1200,DataPort = 1300; |
private int ControlPort = 1200,DataPort = 1300; |
| private OpenXM oxm; |
private OpenXM oxm; |
| //private Button random1_button,random2_button; |
//private Button random1_button,random2_button; |
| //private Button mul_button,remainder_button,swap_button,set_button; |
//private Button mul_button,remainder_button,swap_button,set_button; |
| private TextField poly1,poly2; |
private TextField poly1,poly2; |
| private TextArea textarea; |
private TextArea textarea; |
| private Thread thread = null; |
private Thread thread = null; |
| private boolean debug = false; |
private boolean debug = false; |
| //private Text |
//private Text |
| |
|
| PolyCalc(String host,int ControlPort,int DataPort){ |
PolyCalc(String host,int ControlPort,int DataPort){ |
| this.host = host; |
this.host = host; |
| this.ControlPort = ControlPort; |
this.ControlPort = ControlPort; |
| this.DataPort = DataPort; |
this.DataPort = DataPort; |
| } |
} |
| |
|
| public void init(){ |
public void init(){ |
| GridBagLayout gridbag = new GridBagLayout(); |
GridBagLayout gridbag = new GridBagLayout(); |
| GridBagConstraints c = new GridBagConstraints(); |
GridBagConstraints c = new GridBagConstraints(); |
| Button button; |
Button button; |
| |
|
| //setFont(); |
//setFont(); |
| setLayout(gridbag); |
setLayout(gridbag); |
| |
|
| c.fill = GridBagConstraints.BOTH; |
c.fill = GridBagConstraints.BOTH; |
| |
|
| textarea = new TextArea(); |
textarea = new TextArea(); |
| textarea.setEditable(false); |
textarea.setEditable(false); |
| c.gridwidth = GridBagConstraints.REMAINDER; |
c.gridwidth = GridBagConstraints.REMAINDER; |
| gridbag.setConstraints(textarea,c); |
gridbag.setConstraints(textarea,c); |
| c.gridwidth = 1; |
c.gridwidth = 1; |
| add(textarea); |
add(textarea); |
| |
|
| { |
{ |
| Label label = new Label("poly A:"); |
Label label = new Label("poly A:"); |
| gridbag.setConstraints(label,c); |
gridbag.setConstraints(label,c); |
| add(label); |
add(label); |
| } |
} |
| |
|
| button = new Button("generate random polynomial A"); |
button = new Button("generate random polynomial A"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| add(button); |
add(button); |
| |
|
| button = new Button("A * B"); |
button = new Button("A * B"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| c.gridwidth = GridBagConstraints.REMAINDER; |
c.gridwidth = GridBagConstraints.REMAINDER; |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| c.gridwidth = 1; |
c.gridwidth = 1; |
| add(button); |
add(button); |
| |
|
| poly1 = new TextField(20); |
poly1 = new TextField(20); |
| poly1.addActionListener(this); |
poly1.addActionListener(this); |
| c.gridwidth = 2; |
c.gridwidth = 2; |
| gridbag.setConstraints(poly1,c); |
gridbag.setConstraints(poly1,c); |
| c.gridwidth = 1; |
c.gridwidth = 1; |
| add(poly1); |
add(poly1); |
| |
|
| button = new Button("A % B"); |
button = new Button("A % B"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| //c.gridx = 2; |
//c.gridx = 2; |
| //c.weightx = 0.0; |
//c.weightx = 0.0; |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| add(button); |
add(button); |
| |
|
| button = new Button("swap A & B"); |
button = new Button("swap A & B"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| c.gridwidth = GridBagConstraints.REMAINDER; |
c.gridwidth = GridBagConstraints.REMAINDER; |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| c.gridwidth = 1; |
c.gridwidth = 1; |
| add(button); |
add(button); |
| |
|
| { |
{ |
| Label label = new Label("poly B:"); |
Label label = new Label("poly B:"); |
| gridbag.setConstraints(label,c); |
gridbag.setConstraints(label,c); |
| add(label); |
add(label); |
| } |
} |
| |
|
| button = new Button("generate random polynomial B"); |
button = new Button("generate random polynomial B"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| add(button); |
add(button); |
| |
|
| button = new Button("poly1 <= poly2"); |
button = new Button("poly1 <= poly2"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| c.gridwidth = GridBagConstraints.REMAINDER; |
c.gridwidth = GridBagConstraints.REMAINDER; |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| c.gridwidth = 1; |
c.gridwidth = 1; |
| add(button); |
add(button); |
| |
|
| poly2 = new TextField(); |
poly2 = new TextField(); |
| c.gridwidth = 2; |
c.gridwidth = 2; |
| gridbag.setConstraints(poly2,c); |
gridbag.setConstraints(poly2,c); |
| c.gridwidth = 1; |
c.gridwidth = 1; |
| add(poly2); |
add(poly2); |
| |
|
| button = new Button("grobner base"); |
button = new Button("grobner base"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| add(button); |
add(button); |
| |
|
| button = new Button("quit"); |
button = new Button("quit"); |
| button.addActionListener(this); |
button.addActionListener(this); |
| gridbag.setConstraints(button,c); |
gridbag.setConstraints(button,c); |
| add(button); |
add(button); |
| } |
} |
| |
|
| public void run(){ // for debug |
public void run(){ // for debug |
| try{ |
try{ |
| while(true){ |
while(true){ |
| OXmessage tmp = oxm.receive(); |
OXmessage tmp = oxm.receive(); |
| |
|
| textarea.append("=> "+ tmp.getBody() +"\n"); |
textarea.append("=> "+ tmp.getBody() +"\n"); |
| Thread.yield(); |
Thread.yield(); |
| } |
} |
| }catch(java.io.IOException e){} |
}catch(java.io.IOException e){} |
| } |
} |
| |
|
| public void actionPerformed(ActionEvent evt) { |
public void actionPerformed(ActionEvent evt) { |
| String arg = evt.getActionCommand(); |
String arg = evt.getActionCommand(); |
| |
|
| debug("press \""+ arg +"\" button."); |
debug("press \""+ arg +"\" button."); |
| |
|
| if(arg.equals("quit")){ |
if(arg.equals("quit")){ |
| }else if(arg.equals("grobner base")){ |
}else if(arg.equals("grobner base")){ |
| try{ |
try{ |
| debug("poly A: "+ poly1.getText()); |
debug("poly A: "+ poly1.getText()); |
| oxm.send(new CMO_STRING("[[("+ poly1.getText() +") ("+ poly2.getText() +")] (x,y)] gb")); |
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_executeStringByLocalParser)); |
| oxm.send(new SM(SM.SM_popString)); |
oxm.send(new SM(SM.SM_popString)); |
| }catch(java.io.IOException e){ |
}catch(java.io.IOException e){ |
| }catch(MathcapViolation 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); |
| |
} |
| |
*/ |
| } |
} |
| /* |
|
| 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(){ |
public void start(){ |
| textarea.append("Connecting to "+ host |
textarea.append("Connecting to "+ host |
| +"("+ ControlPort +","+ DataPort +")\n"); |
+"("+ ControlPort +","+ DataPort +")\n"); |
| |
|
| try{ |
try{ |
| /* |
/* |
| Runtime r = Runtime.getRuntime(); |
Runtime r = Runtime.getRuntime(); |
| |
|
| r.exec("ox -ox ox_sm1"); |
r.exec("ox -ox ox_sm1"); |
| */ |
*/ |
| oxm = new OpenXM(host,ControlPort,DataPort); |
oxm = new OpenXM(host,ControlPort,DataPort); |
| textarea.append("Connected.\n"); |
textarea.append("Connected.\n"); |
| oxm.send(new CMO_STRING("[(parse) (cohom.sm1) pushfile] extension ;\n")); |
oxm.send(new CMO_STRING("[(parse) (cohom.sm1) pushfile] extension ;\n")); |
| oxm.send(new SM(SM.SM_executeStringByLocalParser)); |
oxm.send(new SM(SM.SM_executeStringByLocalParser)); |
| |
|
| thread = new Thread(this); |
thread = new Thread(this); |
| thread.start(); |
thread.start(); |
| }catch(java.io.IOException e){ |
}catch(java.io.IOException e){ |
| textarea.append("failed.\n"); |
textarea.append("failed.\n"); |
| stop(); |
stop(); |
| }catch(MathcapViolation e){ |
}catch(MathcapViolation e){ |
| |
} |
| } |
} |
| } |
|
| |
|
| private void debug(String str){ |
private void debug(String str){ |
| if(debug){ |
if(debug){ |
| System.err.println(str); |
System.err.println(str); |
| |
} |
| } |
} |
| } |
|
| |
|
| private static String usage(){ |
private static String usage(){ |
| String ret = ""; |
String ret = ""; |
| |
|
| ret += "usage\t: java PolyCalc [options]\n"; |
ret += "usage\t: java PolyCalc [options]\n"; |
| ret += "options\t:\n"; |
ret += "options\t:\n"; |
| ret += "\t -h \t show this message\n"; |
ret += "\t -h \t show this message\n"; |
| ret += "\t -host hostname \t (default localhost)\n"; |
ret += "\t -host hostname \t (default localhost)\n"; |
| ret += "\t -data port \t (default 1300)\n"; |
ret += "\t -data port \t (default 1300)\n"; |
| ret += "\t -control port \t (default 1200)\n"; |
ret += "\t -control port \t (default 1200)\n"; |
| ret += "\t -debug \t display debug message\n"; |
ret += "\t -debug \t display debug message\n"; |
| |
|
| return ret; |
return ret; |
| } |
} |
| |
|
| public static void main(String argv[]){ |
public static void main(String argv[]){ |
| Frame frame = new Frame("Polynomial Calculator"); |
Frame frame = new Frame("Polynomial Calculator"); |
| //Applet applet; |
//Applet applet; |
| PolyCalc applet; |
PolyCalc applet; |
| String host = "localhost"; |
String host = "localhost"; |
| int DataPort = 1300, ControlPort = 1200; |
int DataPort = 1300, ControlPort = 1200; |
| |
|
| for(int i=0;i<argv.length;i++){ |
for(int i=0;i<argv.length;i++){ |
| if(argv[i].equals("-h")){ |
if(argv[i].equals("-h")){ |
| System.err.print(usage()); |
System.err.print(usage()); |
| System.exit(0); |
System.exit(0); |
| }else if(argv[i].equals("-debug")){ |
}else if(argv[i].equals("-debug")){ |
| //debug = true; |
//debug = true; |
| }else if(argv[i].equals("-host")){ |
}else if(argv[i].equals("-host")){ |
| host = argv[++i]; |
host = argv[++i]; |
| }else if(argv[i].equals("-data")){ |
}else if(argv[i].equals("-data")){ |
| DataPort = Integer.valueOf(argv[++i]).intValue(); |
DataPort = Integer.valueOf(argv[++i]).intValue(); |
| }else if(argv[i].equals("-control")){ |
}else if(argv[i].equals("-control")){ |
| ControlPort = Integer.valueOf(argv[++i]).intValue(); |
ControlPort = Integer.valueOf(argv[++i]).intValue(); |
| }else{ |
}else{ |
| System.err.println("unknown option : "+ argv[i]); |
System.err.println("unknown option : "+ argv[i]); |
| System.err.println(""); |
System.err.println(""); |
| System.err.print(usage()); |
System.err.print(usage()); |
| System.exit(1); |
System.exit(1); |
| } |
} |
| } |
} |
| applet = new PolyCalc(host,ControlPort,DataPort); |
applet = new PolyCalc(host,ControlPort,DataPort); |
| applet.debug = true; |
applet.debug = true; |
| |
|
| applet.init(); |
applet.init(); |
| frame.add("Center",applet); |
frame.add("Center",applet); |
| frame.pack(); |
frame.pack(); |
| frame.setSize(frame.getPreferredSize()); |
frame.setSize(frame.getPreferredSize()); |
| frame.show(); |
frame.show(); |
| applet.start(); |
applet.start(); |
| } |
} |
| } |
} |