Index: topia/src/java/org/codelutin/topia/generators/ui/UIModelToUICallbackSwingGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ui/UIModelToUICallbackSwingGenerator.java:1.1 --- /dev/null Wed Jun 9 11:00:20 2004 +++ topia/src/java/org/codelutin/topia/generators/ui/UIModelToUICallbackSwingGenerator.java Wed Jun 9 11:00:15 2004 @@ -0,0 +1,87 @@ +/* *##% + * Copyright (C) 2002, 2003 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * UIModelToUICallbackSwingGenerator.java + * + * Created: Jun 1, 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/06/09 11:00:15 $ + * par : $Author: mazelier $ + */ + +package org.codelutin.topia.generators.ui; + +import java.io.Writer; +import java.io.IOException; +import java.io.File; + +import org.codelutin.generator.models.ui.*; +import org.codelutin.generator.models.ui.xml.*; +import org.codelutin.generator.UIModelGenerator; + +import java.util.Iterator; +import org.codelutin.topia.Util; + +public class UIModelToUICallbackSwingGenerator extends UIModelGenerator { // UIModelToUICallbackSwingGenerator + + /** + * Methode qui permet de generer une interface UICallback a partir de UIModel + */ + public String getFilenameForUIModel(UIModel model) { + String name = model.getRoot().getName(); + return model.getPackage().replace('.', File.separatorChar) + Util.toUpperCaseFirstLetter(name) + "UICallback.java"; + } + + /** + * Methode qui permet de generer une interface UICallback a partir de UIModel + */ + public void generateFromUIModel(Writer output, UIModel model) + throws IOException { + // ------------- File Header + if (!model.getPackage().equals("")) { +/*{ + package <%=model.getPackage()%>; +}*/ + } + // ------------- Imports +/*{ + import org.codelutin.topia.TopiaException; + + public interface <%= Util.toUpperCaseFirstLetter(model.getRoot().getName()) %>UICallback { +}*/ + for(Iterator o = model.getObjects().iterator(); o.hasNext();) { + UIModelObject object = (UIModelObject)o.next(); + for(Iterator i = object.getEvents().iterator(); i.hasNext();){ + UIModelEvent event = (UIModelEvent)i.next(); +/*{ + public void <%= event.getHandler() %>(<%= event.getArgument() %>); +}*/ + } + } +// accolade de fin d'interface +/*{ + } +}*/ + } +} // UIModelToUICallbackSwingGenerator + Index: topia/src/java/org/codelutin/topia/generators/ui/UIModelToUISwingGenerator.java diff -u /dev/null topia/src/java/org/codelutin/topia/generators/ui/UIModelToUISwingGenerator.java:1.1 --- /dev/null Wed Jun 9 11:00:20 2004 +++ topia/src/java/org/codelutin/topia/generators/ui/UIModelToUISwingGenerator.java Wed Jun 9 11:00:15 2004 @@ -0,0 +1,386 @@ +/* *##% +* Copyright (C) 2002, 2003 Code Lutin +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* UIModelToUISwingGenerator.java +* +* Created: Jun 1, 2004 +* +* @author Benjamin Poussin +* Copyright Code Lutin +* @version $Revision: 1.1 $ +* +* Mise a jour: $Date: 2004/06/09 11:00:15 $ +* par : $Author: mazelier $ +*/ + +package org.codelutin.topia.generators.ui; + +import org.codelutin.generator.models.ui.*; +import org.codelutin.generator.UIModelGenerator; +import org.codelutin.topia.Util; + +import java.io.Writer; +import java.io.IOException; +import java.io.File; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + + +public class UIModelToUISwingGenerator extends UIModelGenerator { //UIModelToUISwingGenerator + + /** + * Methode qui permet de generer une classe UI a partir de UIModel + * + */ + public String getFilenameForUIModel(UIModel model) { + String name = model.getRoot().getName(); + return model.getPackage().replace('.', File.separatorChar) + + Util.toUpperCaseFirstLetter(name) + "UI.java"; + } + + public void generateFromUIModel(Writer output, UIModel model) + throws IOException { + for(Iterator o = model.getObjects().iterator(); o.hasNext();){ + UIModelObject object = (UIModelObject)o.next(); + generateForUIModelObject(output, object); + } + } + + public void generateForRoot(Writer output, UIModelObject object) + throws IOException { + + // ------------- File Header + if (!object.getModel().getPackage().equals("")) { +/*{ + package <%=Util.getParentPackageName(object.getModel().getPackage())%>.ui; +}*/ + } + + // ------------- Imports + /*{ + import org.codelutin.topia.TopiaException; + import java.util.ArrayList; + + + public abstract class <%= Util.toUpperCaseFirstLetter(object.getName()) %>UI extends + <%= object.getType() %> implements <%= Util.toUpperCaseFirstLetter(object.getName()) %>UICallback { + + }*/ + + if (object.getType().equals("javax.swing.JDialog")){ + /*{ + public <%=Util.toUpperCaseFirstLetter(object.getName())%>UI(){ + this((Frame)null); + } + + public <%=Util.toUpperCaseFirstLetter(object.getName())%>UI(Dialog owner){ + super(owner, + i18n._("<%= object.getProperty("title").getStringValue() %>"), + <%= object.getProperty("modal").getBooleanValue() %>); + } + + public <%=Util.toUpperCaseFirstLetter(object.getName())%>UI(Frame owner){ + super(owner, + i18n._("<%= object.getProperty("title").getStringValue() %>"), + <%= object.getProperty("modal").getBooleanValue() %>); + } + }*/ + + }else if (object.getType().equals("javax.swing.JFrame")){ + /*{ + public <%=Util.toUpperCaseFirstLetter(object.getName())%>UI(){ + super(i18n._("<%= object.getProperty("title").getStringValue()%>")); + } + }*/ + + }else{ + /*{ + public <%=Util.toUpperCaseFirstLetter(object.getName())%>UI(){ + super(); + } + }*/ + } + + generateChildStatement(output, object); + generateConstraintStatement(output, object); + // accolade de fin de classe + /*{ + } + }*/ + + } + + /** + * Methode qui permet de generer une classe UI a partir de UIModelObject + * + */ + public void generateForUIModelObject(Writer output, UIModelObject object) + throws IOException { + + if(object.getParent() == null){ + generateForRoot(output, object); + + }else{ + + /*{ + private <%= object.getType() %> __<%= object.getName() %>__ = null; + public <%= object.getType() %> get<%= + Util.toUpperCaseFirstLetter(object.getName()) %>() { + + // test si deja instancier + if(__<%= object.getName() %>__ == null){ + + // creation de l'objet avec les arguments de construction + + }*/ + generateCreationStatement(output, object); + /*{ + // applications des proprietes + }*/ + generateSetStatement(output, object); + /*{ + + // recuperation des differentes donnees concernant l'objet + ArrayList childs = + get<%= Util.toUpperCaseFirstLetter(object.getName()) %>Childs(); + ArrayList constraints = + get<%= Util.toUpperCaseFirstLetter(object.getName()) %>Constraints(); + + // ajout des enfants avec leur contrainte + Iterator iConstraints = constraints.iterator(); + for(Iterator iChilds = childs.iterator(); iChilds.hasNext(); ){ + Component c = (Component)iChilds.next(); + result.add(c, iConstraints.next()); + + }*/ + if (object.getType().equals("javax.swing.JTabbedPane")){ + /*{ + result.setTitleAt(i, c.getName()); + + }*/ + } + /*{ + } + //ajout des events + }*/ + generateHandlerEventStatement(output, object); + /*{ + __<%= object.getName() %>__ = result; + } + return __<%= object.getName() %>__ ; + } + + }*/ + + generateChildStatement(output, object); + generateConstraintStatement(output, object); + } + } + + /** + * Methode pour generer les arguments de l'objet + */ + public void generateCreationStatement(Writer output, UIModelObject object) + throws IOException { + + ArrayList args = (ArrayList)object.getArguments(); + if (args.size() == 0 ){ + /*{ + <%= object.getType() %> result = new <%= object.getType() %>(); + }*/ + }else{ + /*{ + <%= object.getType() %> result = new <%= object.getType() %>( + }*/ + for(Iterator i=args.iterator(); i.hasNext();){ + + Object arg = i.next(); + + if (arg instanceof UIModelObject){ + + UIModelObject objectArg = (UIModelObject)arg; + generateForUIModelObject(output, objectArg); + /*{ + __<%= objectArg.getName() %>__ + }*/ + + }else if (arg instanceof String){ + String argString = (String)arg; + /*{ + <%= "argString" %> + }*/ + + }else if (arg instanceof Character){ + char argChar = ((Character)arg).charValue(); + /*{ + '<%= argChar %>' + }*/ + }else{ + /*{ + <%= arg.toString() %> + }*/ + } + if (i.hasNext()){ + /*{ + , + }*/ + } + } + /*{ + ); + }*/ + } + } + + /** + * Methode pour generer les proprietes de l'objet + */ + public void generateSetStatement(Writer output, UIModelObject object) + throws IOException { + + ArrayList properties = (ArrayList)object.getProperties(); + + for(Iterator i=properties.iterator(); i.hasNext();){ + + UIModelProperty property = (UIModelProperty) i.next(); + Object arg = property.getValue(); + String propertyName = property.getName(); + + try{ + + + + String index = (property.isIndexed()) ? new String(property.getIndex()+", "):""; + + if (arg instanceof UIModelObject){ + + UIModelObject objectArg = (UIModelObject)arg; + generateForUIModelObject(output, objectArg); + /*{ + __<%= object.getName() %>__.set<%= Util.toUpperCaseFirstLetter(propertyName) %>( + + <%=index%>get<%= Util.toUpperCaseFirstLetter(objectArg.getName()) %>()); + }*/ + + }else if (arg instanceof String){ + /*{ + __<%= object.getName() %>__.set<%= Util.toUpperCaseFirstLetter(propertyName) %>(<%=index%>"<%= property.getStringValue() %>"); + }*/ + + }else if (arg instanceof Character){ + /*{ + __<%= object.getName() %>__.set<%= Util.toUpperCaseFirstLetter(propertyName) %>(<%=index%>'<%= property.getCharValue() %>'); + }*/ + + }else{ + /*{ + __<%= object.getName() %>__.set<%= Util.toUpperCaseFirstLetter(propertyName) %>(<%=index%><%= property.getValue().toString() %>); + }*/ + } + }catch(Exception eee){ + System.out.println("Impossible d'acceder a l'index de la propriete " + propertyName); + System.out.println(eee); + } + } + } + + + /** + * Methode pour generer les events de l'objet + */ + public void generateHandlerEventStatement(Writer output, UIModelObject object) + throws IOException { + + ArrayList events = (ArrayList)object.getEvents(); + for(Iterator i=events.iterator(); i.hasNext();){ + + UIModelEvent event = (UIModelEvent) i.next(); + /*{ + Object l = EventHandler.create(<%= event.getSource() %>.class, + this, + "<%= event.getHandler() %>", + "<%= event.getArgument() %>", + "<%= event.getAction() %>"); + + __<%= object.getName() %>__.<%= event.getAddMethod() %>((<%= event.getSource() %>)l); + }*/ + } + } + + /** + * Methode pour generer les enfants de l'objet + */ + public void generateChildStatement(Writer output, UIModelObject object) + throws IOException { + + /*{ + public ArrayList get__<%= object.getName() %>Childs() { + ArrayList children = new ArrayList(); + }*/ + for(Iterator i=object.getChildren().iterator(); i.hasNext();){ + UIModelObject objectChild = (UIModelObject) i.next(); + + generateForUIModelObject(output, objectChild); + /*{ + children.add(__<%= objectChild.getName() %>__); + }*/ + } + /*{ + return children; + } + }*/ + + } + + /** + * Methode pour generer les enfants de l'objet + */ + public void generateConstraintStatement(Writer output, UIModelObject object) + throws IOException { + /*{ + public ArrayList get__<%= object.getName() %>Constraints() { + ArrayList constraints = new ArrayList(); + }*/ + for(Iterator i=object.getChildren().iterator(); i.hasNext();){ + UIModelObject objectChild = (UIModelObject) i.next(); + UIModelConstraint objectConstraint = objectChild.getConstraint(); + + if (objectConstraint instanceof UIModelObject) { + UIModelObject constraint = (UIModelObject)objectConstraint.getValue(); + generateForUIModelObject(output, constraint); + /*{ + constraints.add(__<%= constraint.getName() %>__); + }*/ + }else{ + /*{ + constraints.add(<%= objectConstraint.getStringValue() %>); + }*/ + } + } + /*{ + return constraints; + } + }*/ + + } + +} // UIModelToUISwingGenerator +