[BACK]Return to elimi.java CVS log [TXT][DIR] Up to [local] / OpenXM / src / OpenMath

Annotation of OpenXM/src/OpenMath/elimi.java, Revision 1.3

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>