Beispiel #1
0
 public void ecrire(Programme prog, StringBuffer buf, int indent) {
   if (isSelon()) {
     if (isSinon()) {
       Divers.ecrire(buf, "default :", indent);
       for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Instruction> iter =
               instructions.iterator();
           iter.hasNext(); ) {
         Object obj = iter.next();
         Instruction instr = (Instruction) obj;
         instr.ecrire(prog, buf, indent + 1);
       }
       Divers.ecrire(buf, "break;", indent + 1);
     } else if (isSi() || isSinonSi()) {
       String valeur = this.getValeurSelon();
       Divers.ecrire(buf, "case " + valeur + " :", indent);
       for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Instruction> iter =
               instructions.iterator();
           iter.hasNext(); ) {
         Object obj = iter.next();
         Instruction instr = (Instruction) obj;
         instr.ecrire(prog, buf, indent + 1);
       }
       Divers.ecrire(buf, "break;", indent + 1);
     }
   } else {
     if (isSi()) {
       Divers.ecrire(buf, "if " + this.getCondition() + " {", indent);
       for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Instruction> iter =
               instructions.iterator();
           iter.hasNext(); ) {
         Object obj = iter.next();
         Instruction instr = (Instruction) obj;
         instr.ecrire(prog, buf, indent + 1);
       }
       Divers.ecrire(buf, "}", indent);
     }
     if (isSinonSi()) {
       Divers.ecrire(buf, "else if " + this.getCondition() + " {", indent);
       for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Instruction> iter =
               instructions.iterator();
           iter.hasNext(); ) {
         Object obj = iter.next();
         Instruction instr = (Instruction) obj;
         instr.ecrire(prog, buf, indent + 1);
       }
       Divers.ecrire(buf, "}", indent);
     }
     if (isSinon()) {
       Divers.ecrire(buf, "else {", indent);
       for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Instruction> iter =
               instructions.iterator();
           iter.hasNext(); ) {
         Object obj = iter.next();
         Instruction instr = (Instruction) obj;
         instr.ecrire(prog, buf, indent + 1);
       }
       Divers.ecrire(buf, "}", indent);
     }
   }
 }
Beispiel #2
0
 public void ecrireEnregistrement(Programme prog, StringBuffer buf, int indent) {
   Divers.ecrire(buf, "function " + nom + "()" + " {", indent);
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter =
           proprietes.iterator();
       iter.hasNext(); ) {
     Variable prop = (Variable) iter.next();
     prop.ecrirePropriete(prog, buf, indent + 1);
   }
   Divers.ecrire(buf, "}", indent);
 }
Beispiel #3
0
 private void lireTabFormu(Programme prog, StringBuffer buf, int indent, Argument arg) {
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   // la boucle
   instr_pere.addVariable(new Variable("i1", "ENTIER"));
   Divers.ecrire(buf, "for(i1=0; i1<" + prog.getDim(1, arg) + "; i1++) {", indent);
   Argument arg1 = new Argument(arg.nom + "[i1]", arg.getTypeOfTab(), arg.mode);
   lireFormu(prog, buf, indent + 1, arg1);
   Divers.ecrire(buf, "}", indent);
 }
Beispiel #4
0
 private void declSimpleFormu(Programme prog, StringBuffer buf, int indent, Argument arg) {
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   if (arg.isEntier() || arg.isReel()) {
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "JTextField " + zone + "; ");
   } else if (arg.isTexte()) {
     this.declTexteFormu(prog, buf, indent, arg);
   } else if (arg.isBooleen()) {
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "Checkbox " + zone + "; ");
   }
 }
Beispiel #5
0
 private void constrLabelFormu(
     Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) {
   if (msg != null) {
     Divers.indenter(buf, indent);
     String label = "new JLabel(" + msg + ")";
     Divers.ecrire(buf, p_pere + ".add(" + label + ");");
   }
 }
Beispiel #6
0
 private void constrSimpleFormu(
     Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) {
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   if (arg.isEntier() || arg.isReel()) {
     this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, zone + "=new JTextField(); ");
     Divers.ecrire(buf, p_pere + ".add(" + zone + ");");
   } else if (arg.isTexte()) {
     this.constrTexteFormu(prog, buf, indent, msg, p_pere, arg);
   } else if (arg.isBooleen()) {
     this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, zone + "=new Checkbox(); ");
     Divers.ecrire(buf, p_pere + ".add(" + zone + ");");
   }
 }
Beispiel #7
0
 private void constrClasseFormu(
     Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) {
   this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
   Classe cl = (Classe) arg.getClasse(prog);
   String p_zone = "p_" + arg.nom;
   p_zone = Divers.remplacer(p_zone, ".", "_");
   int nb_prop = cl.proprietes.size() - cl.compterMode("OUT");
   Divers.ecrire(buf, p_zone + "=new JPanel(new GridLayout(" + (2 * nb_prop) + "," + 1 + ")); ");
   Divers.ecrire(buf, p_pere + ".add(" + p_zone + ");");
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter =
           cl.proprietes.iterator();
       iter.hasNext(); ) {
     Variable prop = (Variable) iter.next();
     if (prop.isOut()) continue;
     String msg1 = prog.quote(prop.nom);
     Argument arg1 = new Argument(arg.nom + "." + prop.nom, prop.type, arg.mode);
     constrFormu(prog, buf, indent, msg1, p_zone, arg1);
   }
 }
Beispiel #8
0
 private void constrTabClasseFormu(
     Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) {
   this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
   Classe cl = (Classe) arg.getClasseOfTab(prog);
   Divers.indenter(buf, indent);
   String p_zone = "p_" + arg.nom;
   p_zone = Divers.remplacer(p_zone, ".", "_");
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   int nb_prop = cl.proprietes.size() - cl.compterMode("OUT");
   Divers.ecrire(buf, p_zone + "=new JPanel(new GridLayout(" + 2 + "," + nb_prop + ")); ");
   Divers.ecrire(buf, p_pere + ".add(" + p_zone + ");");
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter =
           cl.proprietes.iterator();
       iter.hasNext(); ) {
     Variable prop = (Variable) iter.next();
     if (prop.isOut()) continue;
     String msg1 = prog.quote(prop.nom);
     String label1 = "new JLabel(" + msg1 + ")";
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, p_zone + ".add(" + label1 + ");");
   }
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter =
           cl.proprietes.iterator();
       iter.hasNext(); ) {
     Variable prop = (Variable) iter.next();
     if (prop.isOut()) continue;
     instr_pere.addVariable(new Variable("ii", "ENTIER"));
     if (prop.isSimple()) {
       Argument arg1 = new Argument(arg.nom + "." + prop.nom, "TAB_" + prop.type, arg.mode);
       String msg1 = null;
       constrTabFormu(prog, buf, indent, msg1, p_zone, arg1, "ii");
     }
     if (prop.isTabSimple()) {
       Argument arg1 =
           new Argument(arg.nom + "." + prop.nom, "MAT_" + prop.getTypeOfTab(), arg.mode);
       String msg1 = null;
       constrMatFormu(prog, buf, indent, msg1, p_zone, arg1);
     }
   }
 }
Beispiel #9
0
 private void declTexteFormu(Programme prog, StringBuffer buf, int indent, Argument arg) {
   if (arg.avecTexteRadio()) {
     String zone = "zone_" + arg.nom;
     zone = Divers.remplacer(zone, ".", "_");
     String group = "group_" + arg.nom;
     group = Divers.remplacer(group, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "ButtonGroup " + group + "; ");
     String p_group = "p_" + group;
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "JPanel " + p_group + "; ");
     String[] liste = arg.getTexteRadio();
     int n = liste.length;
     for (int i = 0; i < n; i++) {
       Divers.indenter(buf, indent);
       String zone_bouton = "zone_" + liste[i] + "_" + arg.nom;
       zone_bouton = Divers.remplacer(zone_bouton, ".", "_");
       Divers.ecrire(buf, "JRadioButton " + zone_bouton + "; ");
     }
   } else if (arg.avecTexteListe()) {
     String zone = "zone_" + arg.nom;
     zone = Divers.remplacer(zone, ".", "_");
     String model = "model_" + arg.nom;
     model = Divers.remplacer(model, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "JList " + zone + "; ");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "DefaultListModel " + model + "; ");
   } else {
     String zone = "zone_" + arg.nom;
     zone = Divers.remplacer(zone, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "JTextField " + zone + "; ");
   }
 }
 void ecrireXml(StringBuffer buf, int indent) {
   Divers.ecrire(buf, "<operation", indent);
   Divers.ecrireAttrXml(buf, "nom", nom);
   Divers.ecrire(buf, ">");
   for (Iterator<ModeleParametre> iter = parametres.iterator(); iter.hasNext(); ) {
     ModeleParametre param = iter.next();
     param.ecrireXml(buf, indent + 1);
   }
   for (Iterator<ModeleVariable> iter = retours.iterator(); iter.hasNext(); ) {
     ModeleVariable retour = iter.next();
     retour.ecrireRetourXml(buf, indent + 1);
   }
   for (Iterator<ModeleVariable> iter = variables.iterator(); iter.hasNext(); ) {
     ModeleVariable var = iter.next();
     var.ecrireXml(buf, indent + 1);
   }
   for (Iterator<ModeleInstruction> iter = instructions.iterator(); iter.hasNext(); ) {
     ModeleInstruction instr = iter.next();
     instr.ecrireXml(buf, indent + 1);
   }
   Divers.ecrire(buf, "</operation>", indent);
 }
Beispiel #11
0
 private void lireMatFormu(
     Programme prog, StringBuffer buf, int indent, Argument arg, String indice1, String indice2) {
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   // les boucles
   instr_pere.addVariable(new Variable(indice1, "ENTIER"));
   instr_pere.addVariable(new Variable(indice2, "ENTIER"));
   Divers.ecrire(
       buf,
       "for(int "
           + indice1
           + "=0; "
           + indice1
           + "<"
           + prog.getDim(1, arg)
           + "; "
           + indice1
           + "++) {",
       indent);
   Divers.ecrire(
       buf,
       "for(int "
           + indice2
           + "=0; "
           + indice2
           + "<"
           + prog.getDim(2, arg)
           + "; "
           + indice2
           + "++) {",
       indent + 1);
   Argument arg1 =
       new Argument(arg.nom + "[" + indice1 + "][" + indice2 + "]", arg.getTypeOfMat(), arg.mode);
   lireFormu(prog, buf, indent + 2, arg1);
   Divers.ecrire(buf, "}", indent + 1);
   Divers.ecrire(buf, "}", indent);
 }
Beispiel #12
0
 public void ecrire(Programme prog, StringBuffer buf, int indent) {
   Divers.ecrire(buf, "function " + nom + "()" + " {", indent);
   if ((proprietes.size() > 0)) prog.commenter(buf, "proprietes", indent + 1);
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter =
           proprietes.iterator();
       iter.hasNext(); ) {
     Variable prop = (Variable) iter.next();
     prop.ecrirePropriete(prog, buf, indent + 1);
   }
   if ((operations.size() > 0)) prog.commenter(buf, "methodes", indent + 1);
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Operation> iter =
           operations.iterator();
       iter.hasNext(); ) {
     Operation oper = (Operation) iter.next();
     Divers.ecrire(buf, "this." + oper.nom + "=" + oper.nom + ";", indent + 1);
   }
   Divers.ecrire(buf, "}", indent);
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Operation> iter =
           operations.iterator();
       iter.hasNext(); ) {
     Operation oper = (Operation) iter.next();
     oper.ecrire(prog, buf, indent);
   }
 }
Beispiel #13
0
 private void declClasseFormu(Programme prog, StringBuffer buf, int indent, Argument arg) {
   String p_zone = "p_" + arg.nom;
   p_zone = Divers.remplacer(p_zone, ".", "_");
   Divers.indenter(buf, indent);
   Divers.ecrire(buf, "JPanel " + p_zone + "; ");
   Classe cl = (Classe) arg.getClasse(prog);
   for (Iterator<org.javascool.proglets.plurialgo.langages.modele.Variable> iter =
           cl.proprietes.iterator();
       iter.hasNext(); ) {
     Variable prop = (Variable) iter.next();
     if (prop.isOut()) continue;
     Argument arg1 = new Argument(arg.nom + "." + prop.nom, prop.type, arg.mode);
     declFormu(prog, buf, indent, arg1);
   }
 }
Beispiel #14
0
 private void lireSimpleFormu(Programme prog, StringBuffer buf, int indent, Argument arg) {
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   if (arg.isEntier()) {
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, arg.nom + " = Integer.parseInt( ");
     Divers.ecrire(buf, zone + ".getText() ); ");
   } else if (arg.isReel()) {
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, arg.nom + " = Double.parseDouble( ");
     Divers.ecrire(buf, zone + ".getText() ); ");
   } else if (arg.isTexte()) {
     this.lireTexteFormu(prog, buf, indent, arg);
   } else if (arg.isBooleen()) {
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, arg.nom + " = ");
     Divers.ecrire(buf, zone + ".getState(); ");
   }
 }
Beispiel #15
0
 private void lireTexteFormu(Programme prog, StringBuffer buf, int indent, Argument arg) {
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   Divers.indenter(buf, indent);
   Divers.ecrire(buf, arg.nom + " = ");
   if (arg.avecTexteRadio()) {
     Divers.ecrire(buf, "null; ");
     String[] liste = arg.getTexteRadio();
     int n = liste.length;
     for (int i = 0; i < n; i++) {
       String zone_bouton = "zone_" + liste[i] + "_" + arg.nom;
       zone_bouton = Divers.remplacer(zone_bouton, ".", "_");
       Divers.indenter(buf, indent);
       Divers.ecrire(buf, "if (" + zone_bouton + ".isSelected()) ");
       Divers.ecrire(buf, arg.nom + "=" + prog.quote(liste[i]) + "; ");
     }
   } else if (arg.avecTexteListe()) {
     Divers.ecrire(buf, "(String) " + zone + ".getSelectedValue(); ");
   } else {
     Divers.ecrire(buf, zone + ".getText(); ");
   }
 }
Beispiel #16
0
 public void ecrire(Programme prog, StringBuffer buf, int indent) {
   Divers.ecrire(buf, var + " = " + expression, indent);
 }
Beispiel #17
0
 private void constrTexteFormu(
     Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) {
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   if (arg.avecTexteRadio()) {
     String group = "group_" + arg.nom;
     group = Divers.remplacer(group, ".", "_");
     this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, group + "=new ButtonGroup(); ");
     String p_group = "p_" + group;
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, p_group + "=new JPanel(); ");
     Divers.ecrire(buf, p_pere + ".add(" + p_group + "); ");
     String[] liste = arg.getTexteRadio();
     int n = liste.length;
     for (int i = 0; i < n; i++) {
       String zone_bouton = "zone_" + liste[i] + "_" + arg.nom;
       zone_bouton = Divers.remplacer(zone_bouton, ".", "_");
       Divers.indenter(buf, indent);
       Divers.ecrire(buf, zone_bouton + " = new JRadioButton(" + prog.quote(liste[i]) + "); ");
       Divers.indenter(buf, indent);
       Divers.ecrire(buf, group + ".add(" + zone_bouton + "); ");
       Divers.indenter(buf, indent);
       Divers.ecrire(buf, p_group + ".add(" + zone_bouton + "); ");
     }
   } else if (arg.avecTexteListe()) {
     String model = "model_" + arg.nom;
     model = Divers.remplacer(model, ".", "_");
     this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, model + "=new DefaultListModel(); ");
     String[] liste = arg.getTexteListe();
     int n = liste.length;
     for (int i = 0; i < n; i++) {
       Divers.ecrire(buf, model + ".addElement(" + prog.quote(liste[i]) + ");", indent);
     }
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, zone + "=new JList(" + model + "); ");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, zone + ".setVisibleRowCount(2); ");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, p_pere + ".add(new JScrollPane(" + zone + ")); ");
   } else {
     this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, zone + "=new JTextField(); ");
     Divers.ecrire(buf, p_pere + ".add(" + zone + ");");
   }
 }
Beispiel #18
0
 private void constrMatFormu(
     Programme prog, StringBuffer buf, int indent, String msg, String p_pere, Argument arg) {
   this.constrLabelFormu(prog, buf, indent, msg, p_pere, arg);
   Divers.indenter(buf, indent);
   String p_zone = "p_" + arg.nom;
   p_zone = Divers.remplacer(p_zone, ".", "_");
   Divers.ecrire(
       buf,
       p_zone
           + "=new JPanel(new GridLayout("
           + prog.getMaxTab()
           + ","
           + prog.getMaxTab()
           + ")); ");
   Divers.ecrire(buf, p_pere + ".add(" + p_zone + "); ");
   String zone = "zone_" + arg.nom;
   zone = Divers.remplacer(zone, ".", "_");
   if (arg.isMatBooleens()) {
     Divers.indenter(buf, indent);
     Divers.ecrire(
         buf, zone + "=new Checkbox [" + prog.getMaxTab() + "][" + prog.getMaxTab() + "]; ");
   } else if (arg.isMatTextes() && arg.avecTexteRadio()) {
     String group = "group_" + arg.nom;
     group = Divers.remplacer(group, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(
         buf, group + "=new ButtonGroup[" + prog.getMaxTab() + "][" + prog.getMaxTab() + "]; ");
     String p_group = "p_" + group;
     Divers.indenter(buf, indent);
     Divers.ecrire(
         buf, p_group + "=new JPanel[ " + prog.getMaxTab() + "][" + prog.getMaxTab() + "]; ");
     String[] liste = arg.getTexteRadio();
     int n = liste.length;
     for (int i = 0; i < n; i++) {
       String zone_bouton = "zone_" + liste[i] + "_" + arg.nom;
       zone_bouton = Divers.remplacer(zone_bouton, ".", "_");
       Divers.indenter(buf, indent);
       Divers.ecrire(
           buf,
           zone_bouton
               + "=new JRadioButton[ "
               + prog.getMaxTab()
               + "]["
               + prog.getMaxTab()
               + "]; ");
     }
   } else if (arg.isMatTextes() && arg.avecTexteListe()) {
     String model = "model_" + arg.nom;
     model = Divers.remplacer(model, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(
         buf, zone + "=new JList [" + prog.getMaxTab() + "][" + prog.getMaxTab() + "]; ");
     Divers.indenter(buf, indent);
     Divers.ecrire(
         buf,
         model + "=new DefaultListModel [" + prog.getMaxTab() + "][" + prog.getMaxTab() + "]; ");
   } else {
     Divers.indenter(buf, indent);
     Divers.ecrire(
         buf, zone + "=new JTextField [" + prog.getMaxTab() + "][" + prog.getMaxTab() + "]; ");
   }
   // les boucles
   arg.addVariable(new Variable("i1", "ENTIER"));
   arg.addVariable(new Variable("j1", "ENTIER"));
   Divers.ecrire(buf, "for(int i1=0; i1<" + prog.getMaxTab() + "; i1++) {", indent);
   Divers.ecrire(buf, "for(int j1=0; j1<" + prog.getMaxTab() + "; j1++) {", indent + 1);
   String msg1 = null;
   Argument arg1 = new Argument(arg.nom + "[i1][j1]", arg.getTypeOfMat(), arg.mode);
   constrFormu(prog, buf, indent + 2, msg1, p_zone, arg1);
   Divers.ecrire(buf, "}", indent + 1);
   Divers.ecrire(buf, "}", indent);
 }