Annotation of OpenXM/src/OpenMath/elimi.java, Revision 1.8
1.1 tam 1: /**
1.8 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/elimi.java,v 1.7 2000/10/11 09:34:06 ohara Exp $
1.1 tam 3: */
4:
1.7 ohara 5: import ORG.openxm.tam.*;
1.1 tam 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){
1.5 tam 105: OXmessage tmp;
1.1 tam 106:
107: Thread.yield();
108:
1.5 tam 109: tmp = oxm.receive();
1.6 ohara 110: System.err.println("=> "+ tmp);
1.1 tam 111: }
112: }catch(java.io.IOException e){}
113: }
114:
115: public void actionPerformed(ActionEvent evt) {
116: String arg = evt.getActionCommand();
117:
118: debug("press \""+ arg +"\" button.");
119:
120: if(arg.equals("quit")){
121: }else if(arg.equals("grobner base")){
122: Vector polys = new Vector(),variables = new Vector();
123:
124: try{
125: java.io.StringReader in = new java.io.StringReader(input.getText());
126: String poly,variable,com;
127: char a = 0;
128:
129: while(a != (char)-1){
130: poly = "";
131: variable = "";
132: while((a=(char)in.read()) != (char)-1 && a != '\n'){
133: //debug("read :"+(int)a);
134: if(Character.isLetter(a) ||
135: (Character.isDigit(a) && !variable.equals(""))){
136: variable += a;
137: }else if(!variable.equals("")){
138: debug("add variable:" + variable);
139: variables.addElement(variable);
140: variable = "";
141: }
142: if(!Character.isWhitespace(a)){
143: poly += a;
144: }
145: }
146: if(!variable.equals("")){
147: debug("add variable:" + variable);
148: variables.addElement(variable);
149: }
150: if(!poly.equals("")){
151: debug("read poly:"+ poly);
152: polys.addElement(poly);
153: }
154: }
155:
156: debug("poly A: "+ poly1.getText());
157: com = "[[";
158: while(!polys.isEmpty()){
159: com += "("+ polys.elementAt(0) +")";
160: polys.removeElementAt(0);
161: if(!polys.isEmpty()){
162: com += " ";
163: }
164: }
165: com += "] (";
166: while(!variables.isEmpty()){
167: Object tmp = variables.elementAt(0);
168:
169: com += tmp;
170: while(variables.removeElement(tmp)){};
171: if(!variables.isEmpty()){
172: com += ",";
173: }
174: }
175: com += ")] gb";
176:
177: debug("command: "+ com);
1.4 tam 178: oxm.send(new CMO_STRING(com));
179: oxm.send(new SM(SM.SM_executeStringByLocalParser));
180: oxm.send(new SM(SM.SM_popString));
1.5 tam 181: }catch(java.io.IOException e){
182: }catch(MathcapViolation e){
183: }
1.1 tam 184: }
185: /*
186: if ("first".equals(arg)) {
187: ((CardLayout)cards.getLayout()).first(cards);
188: } else if ("next".equals(arg)) {
189: ((CardLayout)cards.getLayout()).next(cards);
190: } else if ("previous".equals(arg)) {
191: ((CardLayout)cards.getLayout()).previous(cards);
192: } else if ("last".equals(arg)) {
193: ((CardLayout)cards.getLayout()).last(cards);
194: } else {
195: ((CardLayout)cards.getLayout()).show(cards,(String)arg);
196: }
197: */
198: }
199:
200: public void start(){
1.6 ohara 201: System.err.println("Connecting to "+ host
1.1 tam 202: +"("+ ControlPort +","+ DataPort +")");
203:
204: try{
1.2 tam 205: Runtime runtime = Runtime.getRuntime();
206:
1.8 ! tam 207: //runtime.exec("sh -c \"xterm -name $OpenXM_HOME\"");
1.3 tam 208: //runtime.getInputstream();
209: //runtime.getOutput();
1.8 ! tam 210: //runtime.exec("sh -c \"/home/tam/work/OpenXM/lib/sm1/bin/oxlog /usr/X11R6/bin/xterm -name echo ${OpenXM_HOME} /home/tam/OpenXM/lib/sm1/bin/ox -ox /home/tam/OpenXM/lib/sm1/bin/ox_sm1_forAsir -data "+ DataPort +" -control "+ ControlPort +"\"");
! 211: runtime.exec("sh -c \"xterm ox -ox ox_sm1_forAsir -data "+ DataPort +" -control "+ ControlPort +"\"");
1.2 tam 212:
213: Thread.sleep(3000);
214:
1.1 tam 215: oxm = new OpenXM(host,ControlPort,DataPort);
1.6 ohara 216: System.err.println("Connected.");
1.4 tam 217: oxm.send(new CMO_STRING("(cohom.sm1) run ;\n"));
218: oxm.send(new SM(SM.SM_executeStringByLocalParser));
1.1 tam 219:
220: thread = new Thread(this);
221: thread.start();
1.2 tam 222: }catch(Exception e){
1.6 ohara 223: System.err.println("failed.");
1.1 tam 224: stop();
225: }
226: }
227:
228: private void debug(String str){
229: if(debug){
230: System.err.println(str);
231: }
232: }
233:
234: private static String usage(){
235: String ret = "";
236:
237: ret += "usage\t: java PolyCalc [options]\n";
238: ret += "options\t:\n";
239: ret += "\t -h \t show this message\n";
240: ret += "\t -host hostname \t (default localhost)\n";
241: ret += "\t -data port \t (default 1300)\n";
242: ret += "\t -control port \t (default 1200)\n";
243: ret += "\t -debug \t display debug message\n";
244:
245: return ret;
246: }
247:
248: public static void main(String argv[]){
249: Frame frame = new Frame("Polynomial Calculator");
250: //Applet applet;
251: elimi applet;
252: String host = "localhost";
253: int DataPort = 1300, ControlPort = 1200;
254:
255: for(int i=0;i<argv.length;i++){
256: if(argv[i].equals("-h")){
1.6 ohara 257: System.err.print(usage());
1.1 tam 258: System.exit(0);
259: }else if(argv[i].equals("-debug")){
260: //debug = true;
261: }else if(argv[i].equals("-host")){
262: host = argv[++i];
263: }else if(argv[i].equals("-data")){
264: DataPort = Integer.valueOf(argv[++i]).intValue();
265: }else if(argv[i].equals("-control")){
266: ControlPort = Integer.valueOf(argv[++i]).intValue();
267: }else{
268: System.err.println("unknown option : "+ argv[i]);
269: System.err.println("");
270: System.err.print(usage());
271: System.exit(1);
272: }
273: }
274: applet = new elimi(host,ControlPort,DataPort);
275: applet.debug = true;
276:
277: applet.init();
278: frame.add("Center",applet);
279: frame.pack();
280: frame.setSize(frame.getPreferredSize());
281: frame.show();
282: applet.start();
283: }
284: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>