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

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

1.2       tam         1: /**
1.14    ! takayama    2:  * $OpenXM: OpenXM/src/OpenMath/PolyCalc.java,v 1.13 2005/07/17 02:48:21 takayama Exp $
1.13      takayama    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.14    ! takayama   19:     private String host = "localhost";
        !            20:     private int ControlPort = 1200,DataPort = 1300;
        !            21:     private OpenXM oxm;
        !            22:     //private Button random1_button,random2_button;
        !            23:     //private Button mul_button,remainder_button,swap_button,set_button;
        !            24:     private TextField poly1,poly2;
        !            25:     private TextArea textarea;
        !            26:     private Thread thread = null;
        !            27:     private boolean debug = false;
        !            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();
        !            39:         Button button;
        !            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:         {
        !            54:             Label label = new Label("poly A:");
        !            55:             gridbag.setConstraints(label,c);
        !            56:             add(label);
        !            57:         }
        !            58:
        !            59:         button = new Button("generate random polynomial A");
        !            60:         button.addActionListener(this);
        !            61:         gridbag.setConstraints(button,c);
        !            62:         add(button);
        !            63:
        !            64:         button = new Button("A * B");
        !            65:         button.addActionListener(this);
        !            66:         c.gridwidth = GridBagConstraints.REMAINDER;
        !            67:         gridbag.setConstraints(button,c);
        !            68:         c.gridwidth = 1;
        !            69:         add(button);
        !            70:
        !            71:         poly1 = new TextField(20);
        !            72:         poly1.addActionListener(this);
        !            73:         c.gridwidth = 2;
        !            74:         gridbag.setConstraints(poly1,c);
        !            75:         c.gridwidth = 1;
        !            76:         add(poly1);
        !            77:
        !            78:         button = new Button("A % B");
        !            79:         button.addActionListener(this);
        !            80:         //c.gridx = 2;
        !            81:         //c.weightx = 0.0;
        !            82:         gridbag.setConstraints(button,c);
        !            83:         add(button);
        !            84:
        !            85:         button = new Button("swap A & B");
        !            86:         button.addActionListener(this);
        !            87:         c.gridwidth = GridBagConstraints.REMAINDER;
        !            88:         gridbag.setConstraints(button,c);
        !            89:         c.gridwidth = 1;
        !            90:         add(button);
        !            91:
        !            92:         {
        !            93:             Label label = new Label("poly B:");
        !            94:             gridbag.setConstraints(label,c);
        !            95:             add(label);
        !            96:         }
        !            97:
        !            98:         button = new Button("generate random polynomial B");
        !            99:         button.addActionListener(this);
        !           100:         gridbag.setConstraints(button,c);
        !           101:         add(button);
        !           102:
        !           103:         button = new Button("poly1 <= poly2");
        !           104:         button.addActionListener(this);
        !           105:         c.gridwidth = GridBagConstraints.REMAINDER;
        !           106:         gridbag.setConstraints(button,c);
        !           107:         c.gridwidth = 1;
        !           108:         add(button);
        !           109:
        !           110:         poly2 = new TextField();
        !           111:         c.gridwidth = 2;
        !           112:         gridbag.setConstraints(poly2,c);
        !           113:         c.gridwidth = 1;
        !           114:         add(poly2);
        !           115:
        !           116:         button = new Button("grobner base");
        !           117:         button.addActionListener(this);
        !           118:         gridbag.setConstraints(button,c);
        !           119:         add(button);
        !           120:
        !           121:         button = new Button("quit");
        !           122:         button.addActionListener(this);
        !           123:         gridbag.setConstraints(button,c);
        !           124:         add(button);
        !           125:     }
        !           126:
        !           127:     public void run(){ // for debug
        !           128:         try{
        !           129:             while(true){
        !           130:                 OXmessage tmp = oxm.receive();
        !           131:
        !           132:                 textarea.append("=> "+ tmp.getBody() +"\n");
        !           133:                 Thread.yield();
        !           134:             }
        !           135:         }catch(java.io.IOException e){}
        !           136:     }
        !           137:
        !           138:     public void actionPerformed(ActionEvent evt) {
        !           139:         String arg = evt.getActionCommand();
        !           140:
        !           141:         debug("press \""+ arg +"\" button.");
        !           142:
        !           143:         if(arg.equals("quit")){
        !           144:         }else if(arg.equals("grobner base")){
        !           145:             try{
        !           146:                 debug("poly A: "+ poly1.getText());
        !           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));
        !           150:             }catch(java.io.IOException e){
        !           151:             }catch(MathcapViolation e){
        !           152:             }
        !           153:         }
        !           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:     }
        !           168:
        !           169:     public void start(){
        !           170:         textarea.append("Connecting to "+ host
        !           171:                         +"("+ ControlPort +","+ DataPort +")\n");
        !           172:
        !           173:         try{
        !           174:             /*
        !           175:               Runtime r = Runtime.getRuntime();
        !           176:
        !           177:               r.exec("ox -ox ox_sm1");
        !           178:             */
        !           179:             oxm = new OpenXM(host,ControlPort,DataPort);
        !           180:             textarea.append("Connected.\n");
        !           181:             oxm.send(new CMO_STRING("[(parse) (cohom.sm1) pushfile] extension ;\n"));
        !           182:             oxm.send(new SM(SM.SM_executeStringByLocalParser));
        !           183:
        !           184:             thread = new Thread(this);
        !           185:             thread.start();
        !           186:         }catch(java.io.IOException e){
        !           187:             textarea.append("failed.\n");
        !           188:             stop();
        !           189:         }catch(MathcapViolation e){
        !           190:         }
        !           191:     }
        !           192:
        !           193:     private void debug(String str){
        !           194:         if(debug){
        !           195:             System.err.println(str);
        !           196:         }
        !           197:     }
        !           198:
        !           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";
        !           208:         ret += "\t -debug \t display debug message\n";
        !           209:
        !           210:         return ret;
        !           211:     }
        !           212:
        !           213:     public static void main(String argv[]){
        !           214:         Frame frame = new Frame("Polynomial Calculator");
        !           215:         //Applet applet;
        !           216:         PolyCalc applet;
        !           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")){
        !           222:                 System.err.print(usage());
        !           223:                 System.exit(0);
        !           224:             }else if(argv[i].equals("-debug")){
        !           225:                 //debug = true;
        !           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{
        !           233:                 System.err.println("unknown option : "+ argv[i]);
        !           234:                 System.err.println("");
        !           235:                 System.err.print(usage());
        !           236:                 System.exit(1);
        !           237:             }
        !           238:         }
        !           239:         applet = new PolyCalc(host,ControlPort,DataPort);
        !           240:         applet.debug = true;
        !           241:
        !           242:         applet.init();
        !           243:         frame.add("Center",applet);
        !           244:         frame.pack();
        !           245:         frame.setSize(frame.getPreferredSize());
        !           246:         frame.show();
        !           247:         applet.start();
        !           248:     }
1.1       tam       249: }

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