Annotation of OpenXM/src/OpenMath/elimi.java, Revision 1.2
1.1 tam 1: /**
1.2 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/elimi.java,v 1.1 1999/11/10 21:25:48 tam Exp $
1.1 tam 3: */
4:
5: import JP.ac.kobe_u.math.tam.OpenXM.*;
6: import java.applet.*;
7: import java.awt.event.*;
8: import java.awt.*;
9: import java.util.Vector;
10:
11: class elimi extends Applet implements ActionListener,Runnable{
12: private String host = "localhost";
13: private int ControlPort = 1200,DataPort = 1300;
14: private OpenXM oxm;
15: private TextField poly1,poly2;
16: private TextArea input,output;
17: private Thread thread = null;
18: private boolean debug = false;
19:
20: elimi(String host,int ControlPort,int DataPort){
21: this.host = host;
22: this.ControlPort = ControlPort;
23: this.DataPort = DataPort;
24: }
25:
26: public void init(){
27: GridBagLayout gridbag = new GridBagLayout();
28: GridBagConstraints c = new GridBagConstraints();
29: Button button;
30:
31: //setFont();
32: setLayout(gridbag);
33:
34: c.fill = GridBagConstraints.BOTH;
35:
36: {
37: Label label = new Label("input polynomials");
38: c.gridwidth = 2;
39: gridbag.setConstraints(label,c);
40: c.gridwidth = 1;
41: add(label);
42:
43: label = new Label("outputs");
44: c.gridwidth = GridBagConstraints.REMAINDER;
45: gridbag.setConstraints(label,c);
46: c.gridwidth = 1;
47: add(label);
48: }
49:
50: input = new TextArea(10,40);
51: input.setEditable(true);
52: c.gridwidth = 2;
53: gridbag.setConstraints(input,c);
54: c.gridwidth = 1;
55: add(input);
56:
57: output = new TextArea(10,40);
58: output.setEditable(false);
59: c.gridwidth = GridBagConstraints.REMAINDER;
60: gridbag.setConstraints(output,c);
61: c.gridwidth = 1;
62: add(output);
63:
64: poly1 = new TextField(20);
65: poly1.addActionListener(this);
66: c.gridwidth = 2;
67: gridbag.setConstraints(poly1,c);
68: c.gridwidth = 1;
69: add(poly1);
70:
71: button = new Button("swap A & B");
72: button.addActionListener(this);
73: c.gridwidth = GridBagConstraints.REMAINDER;
74: gridbag.setConstraints(button,c);
75: c.gridwidth = 1;
76: add(button);
77:
78: {
79: Label label = new Label("poly B:");
80: gridbag.setConstraints(label,c);
81: add(label);
82: }
83:
84: button = new Button("poly1 <= poly2");
85: button.addActionListener(this);
86: c.gridwidth = GridBagConstraints.REMAINDER;
87: gridbag.setConstraints(button,c);
88: c.gridwidth = 1;
89: add(button);
90:
91: button = new Button("grobner base");
92: button.addActionListener(this);
93: gridbag.setConstraints(button,c);
94: add(button);
95:
96: button = new Button("quit");
97: button.addActionListener(this);
98: gridbag.setConstraints(button,c);
99: add(button);
100: }
101:
102: public void run(){ // for debug
103: try{
104: while(true){
105: CMO tmp;
106:
107: Thread.yield();
108:
109: switch(oxm.receiveOXtag()){
110: case OpenXM.OX_COMMAND:
111: oxm.receiveSM();
112: break;
113:
114: case OpenXM.OX_DATA:
115: tmp = oxm.receiveCMO();
116: System.out.println("=> "+ tmp);
117: break;
118: }
119: }
120: }catch(java.io.IOException e){}
121: }
122:
123: public void actionPerformed(ActionEvent evt) {
124: String arg = evt.getActionCommand();
125:
126: debug("press \""+ arg +"\" button.");
127:
128: if(arg.equals("quit")){
129: }else if(arg.equals("grobner base")){
130: Vector polys = new Vector(),variables = new Vector();
131:
132: try{
133: java.io.StringReader in = new java.io.StringReader(input.getText());
134: String poly,variable,com;
135: char a = 0;
136:
137: while(a != (char)-1){
138: poly = "";
139: variable = "";
140: while((a=(char)in.read()) != (char)-1 && a != '\n'){
141: //debug("read :"+(int)a);
142: if(Character.isLetter(a) ||
143: (Character.isDigit(a) && !variable.equals(""))){
144: variable += a;
145: }else if(!variable.equals("")){
146: debug("add variable:" + variable);
147: variables.addElement(variable);
148: variable = "";
149: }
150: if(!Character.isWhitespace(a)){
151: poly += a;
152: }
153: }
154: if(!variable.equals("")){
155: debug("add variable:" + variable);
156: variables.addElement(variable);
157: }
158: if(!poly.equals("")){
159: debug("read poly:"+ poly);
160: polys.addElement(poly);
161: }
162: }
163:
164: debug("poly A: "+ poly1.getText());
165: com = "[[";
166: while(!polys.isEmpty()){
167: com += "("+ polys.elementAt(0) +")";
168: polys.removeElementAt(0);
169: if(!polys.isEmpty()){
170: com += " ";
171: }
172: }
173: com += "] (";
174: while(!variables.isEmpty()){
175: Object tmp = variables.elementAt(0);
176:
177: com += tmp;
178: while(variables.removeElement(tmp)){};
179: if(!variables.isEmpty()){
180: com += ",";
181: }
182: }
183: com += ")] gb";
184:
185: debug("command: "+ com);
186: oxm.sendCMO(new CMO_STRING(com));
187: oxm.sendSM(new SM(SM.SM_executeStringByLocalParser));
188: oxm.sendSM(new SM(SM.SM_popString));
189: }catch(java.io.IOException e){}
190: }
191: /*
192: if ("first".equals(arg)) {
193: ((CardLayout)cards.getLayout()).first(cards);
194: } else if ("next".equals(arg)) {
195: ((CardLayout)cards.getLayout()).next(cards);
196: } else if ("previous".equals(arg)) {
197: ((CardLayout)cards.getLayout()).previous(cards);
198: } else if ("last".equals(arg)) {
199: ((CardLayout)cards.getLayout()).last(cards);
200: } else {
201: ((CardLayout)cards.getLayout()).show(cards,(String)arg);
202: }
203: */
204: }
205:
206: public void start(){
207: System.out.println("Connecting to "+ host
208: +"("+ ControlPort +","+ DataPort +")");
209:
210: try{
1.2 ! tam 211: Runtime runtime = Runtime.getRuntime();
! 212:
! 213: runtime.exec("/home/tam/OpenXM/lib/sm1/bin/oxlog /usr/X11R6/bin/xterm -icon -e /home/tam/OpenXM/lib/sm1/bin/ox -ox /home/tam/OpenXM/lib/sm1/bin/ox_sm1_forAsir -data "+ DataPort +" -control "+ ControlPort);
! 214:
! 215: Thread.sleep(3000);
! 216:
1.1 tam 217: oxm = new OpenXM(host,ControlPort,DataPort);
218: System.out.println("Connected.");
219: oxm.sendCMO(new CMO_STRING("(cohom.sm1) run ;\n"));
220: oxm.sendSM(new SM(SM.SM_executeStringByLocalParser));
221:
222: thread = new Thread(this);
223: thread.start();
1.2 ! tam 224: }catch(Exception e){
1.1 tam 225: System.out.println("failed.");
226: stop();
227: }
228: }
229:
230: private void debug(String str){
231: if(debug){
232: System.err.println(str);
233: }
234: }
235:
236: private static String usage(){
237: String ret = "";
238:
239: ret += "usage\t: java PolyCalc [options]\n";
240: ret += "options\t:\n";
241: ret += "\t -h \t show this message\n";
242: ret += "\t -host hostname \t (default localhost)\n";
243: ret += "\t -data port \t (default 1300)\n";
244: ret += "\t -control port \t (default 1200)\n";
245: ret += "\t -debug \t display debug message\n";
246:
247: return ret;
248: }
249:
250: public static void main(String argv[]){
251: Frame frame = new Frame("Polynomial Calculator");
252: //Applet applet;
253: elimi applet;
254: String host = "localhost";
255: int DataPort = 1300, ControlPort = 1200;
256:
257: for(int i=0;i<argv.length;i++){
258: if(argv[i].equals("-h")){
259: System.out.print(usage());
260: System.exit(0);
261: }else if(argv[i].equals("-debug")){
262: //debug = true;
263: }else if(argv[i].equals("-host")){
264: host = argv[++i];
265: }else if(argv[i].equals("-data")){
266: DataPort = Integer.valueOf(argv[++i]).intValue();
267: }else if(argv[i].equals("-control")){
268: ControlPort = Integer.valueOf(argv[++i]).intValue();
269: }else{
270: System.err.println("unknown option : "+ argv[i]);
271: System.err.println("");
272: System.err.print(usage());
273: System.exit(1);
274: }
275: }
276: applet = new elimi(host,ControlPort,DataPort);
277: applet.debug = true;
278:
279: applet.init();
280: frame.add("Center",applet);
281: frame.pack();
282: frame.setSize(frame.getPreferredSize());
283: frame.show();
284: applet.start();
285: }
286: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>