Annotation of OpenXM/src/OpenMath/elimi.java, Revision 1.5
1.1 tam 1: /**
1.5 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/elimi.java,v 1.4 2000/03/16 09:14:52 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){
1.5 ! tam 105: OXmessage tmp;
1.1 tam 106:
107: Thread.yield();
108:
1.5 ! tam 109: tmp = oxm.receive();
! 110: System.out.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(){
201: System.out.println("Connecting to "+ host
202: +"("+ ControlPort +","+ DataPort +")");
203:
204: try{
1.2 tam 205: Runtime runtime = Runtime.getRuntime();
206:
1.3 tam 207: runtime.exec("sh -c \"xterm -name $OpenXM_HOME\"");
208: //runtime.getInputstream();
209: //runtime.getOutput();
210: //runtime.exec("sh -c \"/home/tam/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 +"\"");
1.2 tam 211:
212: Thread.sleep(3000);
213:
1.1 tam 214: oxm = new OpenXM(host,ControlPort,DataPort);
215: System.out.println("Connected.");
1.4 tam 216: oxm.send(new CMO_STRING("(cohom.sm1) run ;\n"));
217: oxm.send(new SM(SM.SM_executeStringByLocalParser));
1.1 tam 218:
219: thread = new Thread(this);
220: thread.start();
1.2 tam 221: }catch(Exception e){
1.1 tam 222: System.out.println("failed.");
223: stop();
224: }
225: }
226:
227: private void debug(String str){
228: if(debug){
229: System.err.println(str);
230: }
231: }
232:
233: private static String usage(){
234: String ret = "";
235:
236: ret += "usage\t: java PolyCalc [options]\n";
237: ret += "options\t:\n";
238: ret += "\t -h \t show this message\n";
239: ret += "\t -host hostname \t (default localhost)\n";
240: ret += "\t -data port \t (default 1300)\n";
241: ret += "\t -control port \t (default 1200)\n";
242: ret += "\t -debug \t display debug message\n";
243:
244: return ret;
245: }
246:
247: public static void main(String argv[]){
248: Frame frame = new Frame("Polynomial Calculator");
249: //Applet applet;
250: elimi applet;
251: String host = "localhost";
252: int DataPort = 1300, ControlPort = 1200;
253:
254: for(int i=0;i<argv.length;i++){
255: if(argv[i].equals("-h")){
256: System.out.print(usage());
257: System.exit(0);
258: }else if(argv[i].equals("-debug")){
259: //debug = true;
260: }else if(argv[i].equals("-host")){
261: host = argv[++i];
262: }else if(argv[i].equals("-data")){
263: DataPort = Integer.valueOf(argv[++i]).intValue();
264: }else if(argv[i].equals("-control")){
265: ControlPort = Integer.valueOf(argv[++i]).intValue();
266: }else{
267: System.err.println("unknown option : "+ argv[i]);
268: System.err.println("");
269: System.err.print(usage());
270: System.exit(1);
271: }
272: }
273: applet = new elimi(host,ControlPort,DataPort);
274: applet.debug = true;
275:
276: applet.init();
277: frame.add("Center",applet);
278: frame.pack();
279: frame.setSize(frame.getPreferredSize());
280: frame.show();
281: applet.start();
282: }
283: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>