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

Annotation of OpenXM/src/OpenMath/PolyCalc.java, Revision 1.9

1.2       tam         1: /**
1.9     ! tam         2:  * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.8 2000/01/28 06:22:01 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());
1.9     ! tam       149:        oxm.send(new CMO_STRING("[[("+ poly1.getText() +") ("+ poly2.getText() +")] (x,y)] gb"));
        !           150:        oxm.send(new SM(SM.SM_executeStringByLocalParser));
        !           151:        oxm.send(new SM(SM.SM_popString));
1.8       tam       152:       }catch(java.io.IOException e){
                    153:       }catch(MathcapViolation e){
                    154:       }
1.6       tam       155:     }
1.5       tam       156:     /*
                    157:       if ("first".equals(arg)) {
                    158:       ((CardLayout)cards.getLayout()).first(cards);
                    159:       } else if ("next".equals(arg)) {
                    160:       ((CardLayout)cards.getLayout()).next(cards);
                    161:       } else if ("previous".equals(arg)) {
                    162:       ((CardLayout)cards.getLayout()).previous(cards);
                    163:       } else if ("last".equals(arg)) {
                    164:       ((CardLayout)cards.getLayout()).last(cards);
                    165:       } else {
                    166:       ((CardLayout)cards.getLayout()).show(cards,(String)arg);
                    167:       }
                    168:       */
                    169:   }
1.3       tam       170:
1.1       tam       171:   public void start(){
                    172:     textarea.append("Connecting to "+ host
                    173:                 +"("+ ControlPort +","+ DataPort +")\n");
                    174:
                    175:     try{
1.7       tam       176:       /*
                    177:        Runtime r = Runtime.getRuntime();
                    178:
                    179:        r.exec("ox -ox ox_sm1");
                    180:        */
1.2       tam       181:       oxm = new OpenXM(host,ControlPort,DataPort);
1.3       tam       182:       textarea.append("Connected.\n");
1.9     ! tam       183:       oxm.send(new CMO_STRING("(cohom.sm1) run ;\n"));
        !           184:       oxm.send(new SM(SM.SM_executeStringByLocalParser));
1.6       tam       185:
                    186:       thread = new Thread(this);
                    187:       thread.start();
1.1       tam       188:     }catch(java.io.IOException e){
                    189:       textarea.append("failed.\n");
                    190:       stop();
1.8       tam       191:     }catch(MathcapViolation e){
1.1       tam       192:     }
                    193:   }
                    194:
1.5       tam       195:   private void debug(String str){
                    196:     if(debug){
                    197:       System.out.println(str);
                    198:     }
                    199:   }
                    200:
1.4       tam       201:   private static String usage(){
                    202:     String ret = "";
                    203:
                    204:     ret += "usage\t: java PolyCalc [options]\n";
                    205:     ret += "options\t:\n";
                    206:     ret += "\t -h \t show this message\n";
                    207:     ret += "\t -host hostname \t (default localhost)\n";
                    208:     ret += "\t -data port \t (default 1300)\n";
                    209:     ret += "\t -control port \t (default 1200)\n";
1.5       tam       210:     ret += "\t -debug \t display debug message\n";
1.4       tam       211:
                    212:     return ret;
                    213:   }
                    214:
1.1       tam       215:   public static void main(String argv[]){
                    216:     Frame frame = new Frame("Polynomial Calculator");
1.5       tam       217:     //Applet applet;
                    218:     PolyCalc applet;
1.1       tam       219:     String host = "localhost";
                    220:     int DataPort = 1300, ControlPort = 1200;
                    221:
                    222:     for(int i=0;i<argv.length;i++){
                    223:       if(argv[i].equals("-h")){
1.4       tam       224:         System.out.print(usage());
1.1       tam       225:         System.exit(0);
1.5       tam       226:       }else if(argv[i].equals("-debug")){
                    227:        //debug = true;
1.1       tam       228:       }else if(argv[i].equals("-host")){
                    229:         host = argv[++i];
                    230:       }else if(argv[i].equals("-data")){
                    231:         DataPort = Integer.valueOf(argv[++i]).intValue();
                    232:       }else if(argv[i].equals("-control")){
                    233:         ControlPort = Integer.valueOf(argv[++i]).intValue();
                    234:       }else{
1.4       tam       235:         System.err.println("unknown option : "+ argv[i]);
1.5       tam       236:         System.err.println("");
1.4       tam       237:         System.err.print(usage());
1.1       tam       238:         System.exit(1);
                    239:       }
                    240:     }
                    241:     applet = new PolyCalc(host,ControlPort,DataPort);
1.5       tam       242:     applet.debug = true;
1.1       tam       243:
                    244:     applet.init();
                    245:     frame.add("Center",applet);
                    246:     frame.pack();
                    247:     frame.setSize(frame.getPreferredSize());
                    248:     frame.show();
                    249:     applet.start();
                    250:   }
                    251: }

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