Annotation of OpenXM/src/OpenMath/PolyCalc.java, Revision 1.6
1.2 tam 1: /**
1.6 ! tam 2: * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.5 1999/11/02 15:58:11 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){
! 122: CMO tmp;
! 123:
! 124: Thread.yield();
! 125:
! 126: switch(oxm.receiveOXtag()){
! 127: case OpenXM.OX_COMMAND:
! 128: oxm.receiveSM();
! 129: break;
! 130:
! 131: case OpenXM.OX_DATA:
! 132: tmp = oxm.receiveCMO();
! 133: textarea.append("=> "+ tmp +"\n");
! 134: break;
! 135: }
! 136: }
! 137: }catch(java.io.IOException e){}
! 138: }
! 139:
! 140: public void actionPerformed(ActionEvent evt) {
! 141: String arg = evt.getActionCommand();
1.3 tam 142:
1.5 tam 143: debug("press \""+ arg +"\" button.");
144:
1.6 ! tam 145: if(arg.equals("quit")){
! 146: }else if(arg.equals("grobner base")){
! 147: try{
! 148: debug("poly A: "+ poly1.getText());
! 149: oxm.sendCMO(new CMO_STRING("[[("+ poly1.getText() +") ("+ poly2.getText() +")] (x,y)] gb"));
! 150: oxm.sendSM(new SM(SM.SM_executeStringByLocalParser));
! 151: oxm.sendSM(new SM(SM.SM_popString));
! 152: }catch(java.io.IOException e){}
! 153: }
1.5 tam 154: /*
155: if ("first".equals(arg)) {
156: ((CardLayout)cards.getLayout()).first(cards);
157: } else if ("next".equals(arg)) {
158: ((CardLayout)cards.getLayout()).next(cards);
159: } else if ("previous".equals(arg)) {
160: ((CardLayout)cards.getLayout()).previous(cards);
161: } else if ("last".equals(arg)) {
162: ((CardLayout)cards.getLayout()).last(cards);
163: } else {
164: ((CardLayout)cards.getLayout()).show(cards,(String)arg);
165: }
166: */
167: }
1.3 tam 168:
1.1 tam 169: public void start(){
170: textarea.append("Connecting to "+ host
171: +"("+ ControlPort +","+ DataPort +")\n");
172:
173: try{
1.2 tam 174: oxm = new OpenXM(host,ControlPort,DataPort);
1.3 tam 175: textarea.append("Connected.\n");
1.6 ! tam 176: oxm.sendCMO(new CMO_STRING("(cohom.sm1) run ;\n"));
! 177: oxm.sendSM(new SM(SM.SM_executeStringByLocalParser));
! 178:
! 179: thread = new Thread(this);
! 180: thread.start();
1.1 tam 181: }catch(java.io.IOException e){
182: textarea.append("failed.\n");
183: stop();
184: }
185: }
186:
1.5 tam 187: private void debug(String str){
188: if(debug){
189: System.out.println(str);
190: }
191: }
192:
1.4 tam 193: private static String usage(){
194: String ret = "";
195:
196: ret += "usage\t: java PolyCalc [options]\n";
197: ret += "options\t:\n";
198: ret += "\t -h \t show this message\n";
199: ret += "\t -host hostname \t (default localhost)\n";
200: ret += "\t -data port \t (default 1300)\n";
201: ret += "\t -control port \t (default 1200)\n";
1.5 tam 202: ret += "\t -debug \t display debug message\n";
1.4 tam 203:
204: return ret;
205: }
206:
1.1 tam 207: public static void main(String argv[]){
208: Frame frame = new Frame("Polynomial Calculator");
1.5 tam 209: //Applet applet;
210: PolyCalc applet;
1.1 tam 211: String host = "localhost";
212: int DataPort = 1300, ControlPort = 1200;
213:
214: for(int i=0;i<argv.length;i++){
215: if(argv[i].equals("-h")){
1.4 tam 216: System.out.print(usage());
1.1 tam 217: System.exit(0);
1.5 tam 218: }else if(argv[i].equals("-debug")){
219: //debug = true;
1.1 tam 220: }else if(argv[i].equals("-host")){
221: host = argv[++i];
222: }else if(argv[i].equals("-data")){
223: DataPort = Integer.valueOf(argv[++i]).intValue();
224: }else if(argv[i].equals("-control")){
225: ControlPort = Integer.valueOf(argv[++i]).intValue();
226: }else{
1.4 tam 227: System.err.println("unknown option : "+ argv[i]);
1.5 tam 228: System.err.println("");
1.4 tam 229: System.err.print(usage());
1.1 tam 230: System.exit(1);
231: }
232: }
233: applet = new PolyCalc(host,ControlPort,DataPort);
1.5 tam 234: applet.debug = true;
1.1 tam 235:
236: applet.init();
237: frame.add("Center",applet);
238: frame.pack();
239: frame.setSize(frame.getPreferredSize());
240: frame.show();
241: applet.start();
242: }
243: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>