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

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

1.2       tam         1: /**
1.13    ! takayama    2:  * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.12 2000/10/11 09:34:06 ohara Exp $
        !             3:  */
        !             4:
        !             5: /*
        !             6:    How to try.
        !             7:     ox -ox ox_sm1
        !             8:     java PolyCalc
        !             9:     Input two polynomials in x and y  and Press the grobner base button.
        !            10:     Actions for other buttons have not yet been implemented.
1.2       tam        11:  */
                     12:
1.12      ohara      13: import ORG.openxm.tam.*;
1.1       tam        14: import java.applet.*;
1.5       tam        15: import java.awt.event.*;
1.1       tam        16: import java.awt.*;
                     17:
1.6       tam        18: class PolyCalc extends Applet implements ActionListener,Runnable{
1.5       tam        19:   private String host = "localhost";
                     20:   private int ControlPort = 1200,DataPort = 1300;
1.1       tam        21:   private OpenXM oxm;
1.5       tam        22:   //private Button random1_button,random2_button;
                     23:   //private Button mul_button,remainder_button,swap_button,set_button;
1.1       tam        24:   private TextField poly1,poly2;
                     25:   private TextArea textarea;
1.6       tam        26:   private Thread thread = null;
1.5       tam        27:   private boolean debug = false;
1.1       tam        28:   //private Text
                     29:
                     30:   PolyCalc(String host,int ControlPort,int DataPort){
                     31:     this.host = host;
                     32:     this.ControlPort = ControlPort;
                     33:     this.DataPort = DataPort;
                     34:   }
                     35:
                     36:   public void init(){
                     37:     GridBagLayout gridbag = new GridBagLayout();
                     38:     GridBagConstraints c = new GridBagConstraints();
1.5       tam        39:     Button button;
1.1       tam        40:
                     41:     //setFont();
                     42:     setLayout(gridbag);
                     43:
                     44:     c.fill = GridBagConstraints.BOTH;
                     45:
                     46:     textarea = new TextArea();
                     47:     textarea.setEditable(false);
                     48:     c.gridwidth = GridBagConstraints.REMAINDER;
                     49:     gridbag.setConstraints(textarea,c);
                     50:     c.gridwidth = 1;
                     51:     add(textarea);
                     52:
                     53:     {
1.5       tam        54:       Label label = new Label("poly A:");
1.1       tam        55:       gridbag.setConstraints(label,c);
                     56:       add(label);
                     57:     }
                     58:
1.5       tam        59:     button = new Button("generate random polynomial A");
                     60:     button.addActionListener(this);
                     61:     gridbag.setConstraints(button,c);
                     62:     add(button);
1.1       tam        63:
1.5       tam        64:     button = new Button("A * B");
                     65:     button.addActionListener(this);
1.1       tam        66:     c.gridwidth = GridBagConstraints.REMAINDER;
1.5       tam        67:     gridbag.setConstraints(button,c);
1.1       tam        68:     c.gridwidth = 1;
1.5       tam        69:     add(button);
1.1       tam        70:
                     71:     poly1 = new TextField(20);
1.5       tam        72:     poly1.addActionListener(this);
1.1       tam        73:     c.gridwidth = 2;
                     74:     gridbag.setConstraints(poly1,c);
                     75:     c.gridwidth = 1;
                     76:     add(poly1);
                     77:
1.5       tam        78:     button = new Button("A % B");
                     79:     button.addActionListener(this);
1.1       tam        80:     //c.gridx = 2;
                     81:     //c.weightx = 0.0;
1.5       tam        82:     gridbag.setConstraints(button,c);
                     83:     add(button);
1.1       tam        84:
1.5       tam        85:     button = new Button("swap A & B");
                     86:     button.addActionListener(this);
1.1       tam        87:     c.gridwidth = GridBagConstraints.REMAINDER;
1.5       tam        88:     gridbag.setConstraints(button,c);
1.1       tam        89:     c.gridwidth = 1;
1.5       tam        90:     add(button);
1.1       tam        91:
                     92:     {
1.5       tam        93:       Label label = new Label("poly B:");
1.1       tam        94:       gridbag.setConstraints(label,c);
                     95:       add(label);
                     96:     }
                     97:
1.5       tam        98:     button = new Button("generate random polynomial B");
                     99:     button.addActionListener(this);
                    100:     gridbag.setConstraints(button,c);
                    101:     add(button);
1.1       tam       102:
1.5       tam       103:     button = new Button("poly1 <= poly2");
                    104:     button.addActionListener(this);
1.1       tam       105:     c.gridwidth = GridBagConstraints.REMAINDER;
1.5       tam       106:     gridbag.setConstraints(button,c);
1.1       tam       107:     c.gridwidth = 1;
1.5       tam       108:     add(button);
1.1       tam       109:
                    110:     poly2 = new TextField();
                    111:     c.gridwidth = 2;
                    112:     gridbag.setConstraints(poly2,c);
                    113:     c.gridwidth = 1;
                    114:     add(poly2);
1.5       tam       115:
1.6       tam       116:     button = new Button("grobner base");
                    117:     button.addActionListener(this);
                    118:     gridbag.setConstraints(button,c);
                    119:     add(button);
                    120:
1.5       tam       121:     button = new Button("quit");
                    122:     button.addActionListener(this);
                    123:     gridbag.setConstraints(button,c);
                    124:     add(button);
1.1       tam       125:   }
                    126:
1.6       tam       127:   public void run(){ // for debug
                    128:     try{
                    129:       while(true){
1.10      tam       130:         OXmessage tmp = oxm.receive();
1.6       tam       131:
1.13    ! takayama  132:        textarea.append("=> "+ tmp.getBody() +"\n");
1.6       tam       133:         Thread.yield();
                    134:       }
                    135:     }catch(java.io.IOException e){}
                    136:   }
                    137:
                    138:   public void actionPerformed(ActionEvent evt) {
                    139:     String arg = evt.getActionCommand();
1.3       tam       140:
1.5       tam       141:     debug("press \""+ arg +"\" button.");
                    142:
1.6       tam       143:     if(arg.equals("quit")){
                    144:     }else if(arg.equals("grobner base")){
                    145:       try{
                    146:        debug("poly A: "+ poly1.getText());
1.9       tam       147:        oxm.send(new CMO_STRING("[[("+ poly1.getText() +") ("+ poly2.getText() +")] (x,y)] gb"));
                    148:        oxm.send(new SM(SM.SM_executeStringByLocalParser));
                    149:        oxm.send(new SM(SM.SM_popString));
1.8       tam       150:       }catch(java.io.IOException e){
                    151:       }catch(MathcapViolation e){
                    152:       }
1.6       tam       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.13    ! takayama  181:       oxm.send(new CMO_STRING("[(parse) (cohom.sm1) pushfile] extension ;\n"));
1.9       tam       182:       oxm.send(new SM(SM.SM_executeStringByLocalParser));
1.6       tam       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();
1.8       tam       189:     }catch(MathcapViolation e){
1.1       tam       190:     }
                    191:   }
                    192:
1.5       tam       193:   private void debug(String str){
                    194:     if(debug){
1.11      ohara     195:       System.err.println(str);
1.5       tam       196:     }
                    197:   }
                    198:
1.4       tam       199:   private static String usage(){
                    200:     String ret = "";
                    201:
                    202:     ret += "usage\t: java PolyCalc [options]\n";
                    203:     ret += "options\t:\n";
                    204:     ret += "\t -h \t show this message\n";
                    205:     ret += "\t -host hostname \t (default localhost)\n";
                    206:     ret += "\t -data port \t (default 1300)\n";
                    207:     ret += "\t -control port \t (default 1200)\n";
1.5       tam       208:     ret += "\t -debug \t display debug message\n";
1.4       tam       209:
                    210:     return ret;
                    211:   }
                    212:
1.1       tam       213:   public static void main(String argv[]){
                    214:     Frame frame = new Frame("Polynomial Calculator");
1.5       tam       215:     //Applet applet;
                    216:     PolyCalc applet;
1.1       tam       217:     String host = "localhost";
                    218:     int DataPort = 1300, ControlPort = 1200;
                    219:
                    220:     for(int i=0;i<argv.length;i++){
                    221:       if(argv[i].equals("-h")){
1.11      ohara     222:         System.err.print(usage());
1.1       tam       223:         System.exit(0);
1.5       tam       224:       }else if(argv[i].equals("-debug")){
                    225:        //debug = true;
1.1       tam       226:       }else if(argv[i].equals("-host")){
                    227:         host = argv[++i];
                    228:       }else if(argv[i].equals("-data")){
                    229:         DataPort = Integer.valueOf(argv[++i]).intValue();
                    230:       }else if(argv[i].equals("-control")){
                    231:         ControlPort = Integer.valueOf(argv[++i]).intValue();
                    232:       }else{
1.4       tam       233:         System.err.println("unknown option : "+ argv[i]);
1.5       tam       234:         System.err.println("");
1.4       tam       235:         System.err.print(usage());
1.1       tam       236:         System.exit(1);
                    237:       }
                    238:     }
                    239:     applet = new PolyCalc(host,ControlPort,DataPort);
1.5       tam       240:     applet.debug = true;
1.1       tam       241:
                    242:     applet.init();
                    243:     frame.add("Center",applet);
                    244:     frame.pack();
                    245:     frame.setSize(frame.getPreferredSize());
                    246:     frame.show();
                    247:     applet.start();
                    248:   }
                    249: }

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