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

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

1.2       tam         1: /**
1.7     ! tam         2:  * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.6 1999/11/10 21:25:48 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.7     ! tam       174:       /*
        !           175:        Runtime r = Runtime.getRuntime();
        !           176:
        !           177:        r.exec("ox -ox ox_sm1");
        !           178:        */
1.2       tam       179:       oxm = new OpenXM(host,ControlPort,DataPort);
1.3       tam       180:       textarea.append("Connected.\n");
1.6       tam       181:       oxm.sendCMO(new CMO_STRING("(cohom.sm1) run ;\n"));
                    182:       oxm.sendSM(new SM(SM.SM_executeStringByLocalParser));
                    183:
                    184:       thread = new Thread(this);
                    185:       thread.start();
1.1       tam       186:     }catch(java.io.IOException e){
                    187:       textarea.append("failed.\n");
                    188:       stop();
                    189:     }
                    190:   }
                    191:
1.5       tam       192:   private void debug(String str){
                    193:     if(debug){
                    194:       System.out.println(str);
                    195:     }
                    196:   }
                    197:
1.4       tam       198:   private static String usage(){
                    199:     String ret = "";
                    200:
                    201:     ret += "usage\t: java PolyCalc [options]\n";
                    202:     ret += "options\t:\n";
                    203:     ret += "\t -h \t show this message\n";
                    204:     ret += "\t -host hostname \t (default localhost)\n";
                    205:     ret += "\t -data port \t (default 1300)\n";
                    206:     ret += "\t -control port \t (default 1200)\n";
1.5       tam       207:     ret += "\t -debug \t display debug message\n";
1.4       tam       208:
                    209:     return ret;
                    210:   }
                    211:
1.1       tam       212:   public static void main(String argv[]){
                    213:     Frame frame = new Frame("Polynomial Calculator");
1.5       tam       214:     //Applet applet;
                    215:     PolyCalc applet;
1.1       tam       216:     String host = "localhost";
                    217:     int DataPort = 1300, ControlPort = 1200;
                    218:
                    219:     for(int i=0;i<argv.length;i++){
                    220:       if(argv[i].equals("-h")){
1.4       tam       221:         System.out.print(usage());
1.1       tam       222:         System.exit(0);
1.5       tam       223:       }else if(argv[i].equals("-debug")){
                    224:        //debug = true;
1.1       tam       225:       }else if(argv[i].equals("-host")){
                    226:         host = argv[++i];
                    227:       }else if(argv[i].equals("-data")){
                    228:         DataPort = Integer.valueOf(argv[++i]).intValue();
                    229:       }else if(argv[i].equals("-control")){
                    230:         ControlPort = Integer.valueOf(argv[++i]).intValue();
                    231:       }else{
1.4       tam       232:         System.err.println("unknown option : "+ argv[i]);
1.5       tam       233:         System.err.println("");
1.4       tam       234:         System.err.print(usage());
1.1       tam       235:         System.exit(1);
                    236:       }
                    237:     }
                    238:     applet = new PolyCalc(host,ControlPort,DataPort);
1.5       tam       239:     applet.debug = true;
1.1       tam       240:
                    241:     applet.init();
                    242:     frame.add("Center",applet);
                    243:     frame.pack();
                    244:     frame.setSize(frame.getPreferredSize());
                    245:     frame.show();
                    246:     applet.start();
                    247:   }
                    248: }

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