Annotation of OpenXM/src/OpenMath/elimi.java, Revision 1.1
1.1 ! tam 1: /**
! 2: * $OpenXM$
! 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{
! 211: oxm = new OpenXM(host,ControlPort,DataPort);
! 212: System.out.println("Connected.");
! 213: oxm.sendCMO(new CMO_STRING("(cohom.sm1) run ;\n"));
! 214: oxm.sendSM(new SM(SM.SM_executeStringByLocalParser));
! 215:
! 216: thread = new Thread(this);
! 217: thread.start();
! 218: }catch(java.io.IOException e){
! 219: System.out.println("failed.");
! 220: stop();
! 221: }
! 222: }
! 223:
! 224: private void debug(String str){
! 225: if(debug){
! 226: System.err.println(str);
! 227: }
! 228: }
! 229:
! 230: private static String usage(){
! 231: String ret = "";
! 232:
! 233: ret += "usage\t: java PolyCalc [options]\n";
! 234: ret += "options\t:\n";
! 235: ret += "\t -h \t show this message\n";
! 236: ret += "\t -host hostname \t (default localhost)\n";
! 237: ret += "\t -data port \t (default 1300)\n";
! 238: ret += "\t -control port \t (default 1200)\n";
! 239: ret += "\t -debug \t display debug message\n";
! 240:
! 241: return ret;
! 242: }
! 243:
! 244: public static void main(String argv[]){
! 245: Frame frame = new Frame("Polynomial Calculator");
! 246: //Applet applet;
! 247: elimi applet;
! 248: String host = "localhost";
! 249: int DataPort = 1300, ControlPort = 1200;
! 250:
! 251: for(int i=0;i<argv.length;i++){
! 252: if(argv[i].equals("-h")){
! 253: System.out.print(usage());
! 254: System.exit(0);
! 255: }else if(argv[i].equals("-debug")){
! 256: //debug = true;
! 257: }else if(argv[i].equals("-host")){
! 258: host = argv[++i];
! 259: }else if(argv[i].equals("-data")){
! 260: DataPort = Integer.valueOf(argv[++i]).intValue();
! 261: }else if(argv[i].equals("-control")){
! 262: ControlPort = Integer.valueOf(argv[++i]).intValue();
! 263: }else{
! 264: System.err.println("unknown option : "+ argv[i]);
! 265: System.err.println("");
! 266: System.err.print(usage());
! 267: System.exit(1);
! 268: }
! 269: }
! 270: applet = new elimi(host,ControlPort,DataPort);
! 271: applet.debug = true;
! 272:
! 273: applet.init();
! 274: frame.add("Center",applet);
! 275: frame.pack();
! 276: frame.setSize(frame.getPreferredSize());
! 277: frame.show();
! 278: applet.start();
! 279: }
! 280: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>