Annotation of OpenXM/src/OpenMath/PolyCalc.java, Revision 1.10
1.2 tam 1: /**
1.10 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.9 2000/03/16 12:28:42 tam Exp $
1.2 tam 3: */
4:
1.1 tam 5: import JP.ac.kobe_u.math.tam.OpenXM.*;
6: import java.applet.*;
1.5 tam 7: import java.awt.event.*;
1.1 tam 8: import java.awt.*;
9:
1.6 tam 10: class PolyCalc extends Applet implements ActionListener,Runnable{
1.5 tam 11: private String host = "localhost";
12: private int ControlPort = 1200,DataPort = 1300;
1.1 tam 13: private OpenXM oxm;
1.5 tam 14: //private Button random1_button,random2_button;
15: //private Button mul_button,remainder_button,swap_button,set_button;
1.1 tam 16: private TextField poly1,poly2;
17: private TextArea textarea;
1.6 tam 18: private Thread thread = null;
1.5 tam 19: private boolean debug = false;
1.1 tam 20: //private Text
21:
22: PolyCalc(String host,int ControlPort,int DataPort){
23: this.host = host;
24: this.ControlPort = ControlPort;
25: this.DataPort = DataPort;
26: }
27:
28: public void init(){
29: GridBagLayout gridbag = new GridBagLayout();
30: GridBagConstraints c = new GridBagConstraints();
1.5 tam 31: Button button;
1.1 tam 32:
33: //setFont();
34: setLayout(gridbag);
35:
36: c.fill = GridBagConstraints.BOTH;
37:
38: textarea = new TextArea();
39: textarea.setEditable(false);
40: c.gridwidth = GridBagConstraints.REMAINDER;
41: gridbag.setConstraints(textarea,c);
42: c.gridwidth = 1;
43: add(textarea);
44:
45: {
1.5 tam 46: Label label = new Label("poly A:");
1.1 tam 47: gridbag.setConstraints(label,c);
48: add(label);
49: }
50:
1.5 tam 51: button = new Button("generate random polynomial A");
52: button.addActionListener(this);
53: gridbag.setConstraints(button,c);
54: add(button);
1.1 tam 55:
1.5 tam 56: button = new Button("A * B");
57: button.addActionListener(this);
1.1 tam 58: c.gridwidth = GridBagConstraints.REMAINDER;
1.5 tam 59: gridbag.setConstraints(button,c);
1.1 tam 60: c.gridwidth = 1;
1.5 tam 61: add(button);
1.1 tam 62:
63: poly1 = new TextField(20);
1.5 tam 64: poly1.addActionListener(this);
1.1 tam 65: c.gridwidth = 2;
66: gridbag.setConstraints(poly1,c);
67: c.gridwidth = 1;
68: add(poly1);
69:
1.5 tam 70: button = new Button("A % B");
71: button.addActionListener(this);
1.1 tam 72: //c.gridx = 2;
73: //c.weightx = 0.0;
1.5 tam 74: gridbag.setConstraints(button,c);
75: add(button);
1.1 tam 76:
1.5 tam 77: button = new Button("swap A & B");
78: button.addActionListener(this);
1.1 tam 79: c.gridwidth = GridBagConstraints.REMAINDER;
1.5 tam 80: gridbag.setConstraints(button,c);
1.1 tam 81: c.gridwidth = 1;
1.5 tam 82: add(button);
1.1 tam 83:
84: {
1.5 tam 85: Label label = new Label("poly B:");
1.1 tam 86: gridbag.setConstraints(label,c);
87: add(label);
88: }
89:
1.5 tam 90: button = new Button("generate random polynomial B");
91: button.addActionListener(this);
92: gridbag.setConstraints(button,c);
93: add(button);
1.1 tam 94:
1.5 tam 95: button = new Button("poly1 <= poly2");
96: button.addActionListener(this);
1.1 tam 97: c.gridwidth = GridBagConstraints.REMAINDER;
1.5 tam 98: gridbag.setConstraints(button,c);
1.1 tam 99: c.gridwidth = 1;
1.5 tam 100: add(button);
1.1 tam 101:
102: poly2 = new TextField();
103: c.gridwidth = 2;
104: gridbag.setConstraints(poly2,c);
105: c.gridwidth = 1;
106: add(poly2);
1.5 tam 107:
1.6 tam 108: button = new Button("grobner base");
109: button.addActionListener(this);
110: gridbag.setConstraints(button,c);
111: add(button);
112:
1.5 tam 113: button = new Button("quit");
114: button.addActionListener(this);
115: gridbag.setConstraints(button,c);
116: add(button);
1.1 tam 117: }
118:
1.6 tam 119: public void run(){ // for debug
120: try{
121: while(true){
1.10 ! tam 122: OXmessage tmp = oxm.receive();
1.6 tam 123:
1.10 ! tam 124: textarea.append("=> "+ tmp +"\n");
1.6 tam 125: Thread.yield();
126: }
127: }catch(java.io.IOException e){}
128: }
129:
130: public void actionPerformed(ActionEvent evt) {
131: String arg = evt.getActionCommand();
1.3 tam 132:
1.5 tam 133: debug("press \""+ arg +"\" button.");
134:
1.6 tam 135: if(arg.equals("quit")){
136: }else if(arg.equals("grobner base")){
137: try{
138: debug("poly A: "+ poly1.getText());
1.9 tam 139: oxm.send(new CMO_STRING("[[("+ poly1.getText() +") ("+ poly2.getText() +")] (x,y)] gb"));
140: oxm.send(new SM(SM.SM_executeStringByLocalParser));
141: oxm.send(new SM(SM.SM_popString));
1.8 tam 142: }catch(java.io.IOException e){
143: }catch(MathcapViolation e){
144: }
1.6 tam 145: }
1.5 tam 146: /*
147: if ("first".equals(arg)) {
148: ((CardLayout)cards.getLayout()).first(cards);
149: } else if ("next".equals(arg)) {
150: ((CardLayout)cards.getLayout()).next(cards);
151: } else if ("previous".equals(arg)) {
152: ((CardLayout)cards.getLayout()).previous(cards);
153: } else if ("last".equals(arg)) {
154: ((CardLayout)cards.getLayout()).last(cards);
155: } else {
156: ((CardLayout)cards.getLayout()).show(cards,(String)arg);
157: }
158: */
159: }
1.3 tam 160:
1.1 tam 161: public void start(){
162: textarea.append("Connecting to "+ host
163: +"("+ ControlPort +","+ DataPort +")\n");
164:
165: try{
1.7 tam 166: /*
167: Runtime r = Runtime.getRuntime();
168:
169: r.exec("ox -ox ox_sm1");
170: */
1.2 tam 171: oxm = new OpenXM(host,ControlPort,DataPort);
1.3 tam 172: textarea.append("Connected.\n");
1.9 tam 173: oxm.send(new CMO_STRING("(cohom.sm1) run ;\n"));
174: oxm.send(new SM(SM.SM_executeStringByLocalParser));
1.6 tam 175:
176: thread = new Thread(this);
177: thread.start();
1.1 tam 178: }catch(java.io.IOException e){
179: textarea.append("failed.\n");
180: stop();
1.8 tam 181: }catch(MathcapViolation e){
1.1 tam 182: }
183: }
184:
1.5 tam 185: private void debug(String str){
186: if(debug){
187: System.out.println(str);
188: }
189: }
190:
1.4 tam 191: private static String usage(){
192: String ret = "";
193:
194: ret += "usage\t: java PolyCalc [options]\n";
195: ret += "options\t:\n";
196: ret += "\t -h \t show this message\n";
197: ret += "\t -host hostname \t (default localhost)\n";
198: ret += "\t -data port \t (default 1300)\n";
199: ret += "\t -control port \t (default 1200)\n";
1.5 tam 200: ret += "\t -debug \t display debug message\n";
1.4 tam 201:
202: return ret;
203: }
204:
1.1 tam 205: public static void main(String argv[]){
206: Frame frame = new Frame("Polynomial Calculator");
1.5 tam 207: //Applet applet;
208: PolyCalc applet;
1.1 tam 209: String host = "localhost";
210: int DataPort = 1300, ControlPort = 1200;
211:
212: for(int i=0;i<argv.length;i++){
213: if(argv[i].equals("-h")){
1.4 tam 214: System.out.print(usage());
1.1 tam 215: System.exit(0);
1.5 tam 216: }else if(argv[i].equals("-debug")){
217: //debug = true;
1.1 tam 218: }else if(argv[i].equals("-host")){
219: host = argv[++i];
220: }else if(argv[i].equals("-data")){
221: DataPort = Integer.valueOf(argv[++i]).intValue();
222: }else if(argv[i].equals("-control")){
223: ControlPort = Integer.valueOf(argv[++i]).intValue();
224: }else{
1.4 tam 225: System.err.println("unknown option : "+ argv[i]);
1.5 tam 226: System.err.println("");
1.4 tam 227: System.err.print(usage());
1.1 tam 228: System.exit(1);
229: }
230: }
231: applet = new PolyCalc(host,ControlPort,DataPort);
1.5 tam 232: applet.debug = true;
1.1 tam 233:
234: applet.init();
235: frame.add("Center",applet);
236: frame.pack();
237: frame.setSize(frame.getPreferredSize());
238: frame.show();
239: applet.start();
240: }
241: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>