Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2006-08-24 15:38:45 +0000
committeratikhomirov2006-08-24 15:38:45 +0000
commit7cbc0383a43ea508afc6565a0acea55321a25ef4 (patch)
tree7f5442f9a9385cf0b1cdc658dc000cb8b194d3b4 /plugins/org.eclipse.gmf.graphdef.codegen/src
parent2b73f868e5a0ec87f1bb4bd04a9f0b4f6966d157 (diff)
downloadorg.eclipse.gmf-tooling-7cbc0383a43ea508afc6565a0acea55321a25ef4.tar.gz
org.eclipse.gmf-tooling-7cbc0383a43ea508afc6565a0acea55321a25ef4.tar.xz
org.eclipse.gmf-tooling-7cbc0383a43ea508afc6565a0acea55321a25ef4.zip
[154687] mgolubev - Support scalable polygons
Diffstat (limited to 'plugins/org.eclipse.gmf.graphdef.codegen/src')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java34
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java160
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java140
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopGenerator.java148
4 files changed, 256 insertions, 226 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
index 8780a3126..739d697ad 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
@@ -66,6 +66,7 @@ import org.eclipse.gmf.graphdef.codegen.templates.RoundedRectAttrGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.ShapeAttrGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.TopConnectionGenerator;
import org.eclipse.gmf.graphdef.codegen.templates.TopFigureGenerator;
+import org.eclipse.gmf.graphdef.codegen.templates.TopGenerator;
import org.eclipse.gmf.internal.codegen.dispatch.EmitterFactory;
import org.eclipse.gmf.internal.codegen.dispatch.HierarchyKeyMap;
import org.eclipse.gmf.internal.codegen.dispatch.KeyChain;
@@ -80,6 +81,8 @@ import org.osgi.framework.Bundle;
*
*/
public class FigureGenerator implements TextEmitter {
+ private static final String ENTRY_POINT = "main";
+
private final GraphDefDispatcher myTopDispatcher;
private final GraphDefDispatcher myInnerDispatcher;
private final boolean myIsInnerClassCode;
@@ -99,18 +102,7 @@ public class FigureGenerator implements TextEmitter {
"org.eclipse.gmf.graphdef.codegen"
};
- KeyMap keyMap = new HierarchyKeyMap() {
- /*
- * Capture knowledge that we use classes and strings as keys
- */
- public KeyChain map(Object key) {
- if (key instanceof String) {
- return super.map(key);
- } else {
- return super.map(key.getClass());
- }
- }
- };
+ KeyMap keyMap = new ClassesOrStringsKeyMap();
String[] templatePath = new String[] {thisBundle.getEntry("/templates/").toString()};
EmitterFactory topFactory = new EmitterFactory(templatePath, fillTopLevel(), true, variables, true);
myTopDispatcher = new GraphDefDispatcher(topFactory, keyMap, figureNameSwitch, mapModeStrategy);
@@ -120,6 +112,7 @@ public class FigureGenerator implements TextEmitter {
private static TemplateRegistry fillTopLevel() {
StaticTemplateRegistry tr = new StaticTemplateRegistry(FigureGenerator.class.getClassLoader());
+ tr.put(ENTRY_POINT, "/top/Top.javajet", TopGenerator.class);
tr.put(PolylineConnection.class, "/top/PolylineConnection.javajet", TopConnectionGenerator.class);
tr.put(Figure.class, "/top/Figure.javajet", TopFigureGenerator.class);
return tr;
@@ -184,13 +177,26 @@ public class FigureGenerator implements TextEmitter {
String res = null;
myTopDispatcher.resetForNewClass(importManager);
myInnerDispatcher.resetForNewClass(importManager);
- Object args = new Object[] {fig, importManager, myTopDispatcher.getFQNSwitch(), myInnerDispatcher, Boolean.valueOf(myIsInnerClassCode)};
- res = myTopDispatcher.dispatch(fig, args);
+ Object args = new Object[] {fig, myInnerDispatcher, myTopDispatcher, Boolean.valueOf(myIsInnerClassCode)};
+ res = myTopDispatcher.dispatch(ENTRY_POINT, args);
if (res == null) {
throw new IllegalStateException();
}
return res;
}
+
+ private static class ClassesOrStringsKeyMap extends HierarchyKeyMap {
+ /*
+ * Capture knowledge that we use classes and strings as keys
+ */
+ public KeyChain map(Object key) {
+ if (key instanceof String) {
+ return super.map(key);
+ } else {
+ return super.map(key.getClass());
+ }
+ }
+ }
/*
public static class Feedback {
void registerChildAccessor(Figure parent, Figure child, String getterName, String setterName) {
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java
index d906304c8..39a7ceafd 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopConnectionGenerator.java
@@ -22,65 +22,42 @@ public class TopConnectionGenerator
protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
protected final String TEXT_1 = "";
- protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
- protected final String TEXT_3 = " extends ";
- protected final String TEXT_4 = " {" + NL;
- protected final String TEXT_5 = NL;
- protected final String TEXT_6 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
- protected final String TEXT_7 = " ";
- protected final String TEXT_8 = "() {" + NL + "\t\t";
- protected final String TEXT_9 = " result = new ";
- protected final String TEXT_10 = "();" + NL + "\t\t";
- protected final String TEXT_11 = NL + "\t\treturn result;" + NL + "\t}";
- protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
- protected final String TEXT_13 = "() {";
- protected final String TEXT_14 = NL;
- protected final String TEXT_15 = NL + "\t\tsetSourceDecoration(createSourceDecoration());";
- protected final String TEXT_16 = NL + "\t\tsetTargetDecoration(createTargetDecoration());";
- protected final String TEXT_17 = NL + "\t}" + NL;
- protected final String TEXT_18 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
- protected final String TEXT_19 = " createSourceDecoration() {";
- protected final String TEXT_20 = NL;
- protected final String TEXT_21 = NL + "\t\treturn df;" + NL + "\t}";
+ protected final String TEXT_2 = NL;
+ protected final String TEXT_3 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_4 = " ";
+ protected final String TEXT_5 = "() {" + NL + "\t\t";
+ protected final String TEXT_6 = " result = new ";
+ protected final String TEXT_7 = "();" + NL + "\t\t";
+ protected final String TEXT_8 = NL + "\t\treturn result;" + NL + "\t}";
+ protected final String TEXT_9 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
+ protected final String TEXT_10 = "() {";
+ protected final String TEXT_11 = NL;
+ protected final String TEXT_12 = NL + "\t\tsetSourceDecoration(createSourceDecoration());";
+ protected final String TEXT_13 = NL + "\t\tsetTargetDecoration(createTargetDecoration());";
+ protected final String TEXT_14 = NL + "\t}" + NL;
+ protected final String TEXT_15 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_16 = " createSourceDecoration() {";
+ protected final String TEXT_17 = NL;
+ protected final String TEXT_18 = NL + "\t\treturn df;" + NL + "\t}";
+ protected final String TEXT_19 = NL;
+ protected final String TEXT_20 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_21 = " createTargetDecoration() {";
protected final String TEXT_22 = NL;
- protected final String TEXT_23 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
- protected final String TEXT_24 = " createTargetDecoration() {";
- protected final String TEXT_25 = NL;
- protected final String TEXT_26 = NL + "\t\treturn df;" + NL + "\t}";
- protected final String TEXT_27 = NL;
- protected final String TEXT_28 = NL + "}" + NL + "\t";
- protected final String TEXT_29 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
- protected final String TEXT_30 = " ";
- protected final String TEXT_31 = " = ";
- protected final String TEXT_32 = ";";
- protected final String TEXT_33 = NL + "\t";
- protected final String TEXT_34 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
- protected final String TEXT_35 = " ";
- protected final String TEXT_36 = " = ";
- protected final String TEXT_37 = ";";
- protected final String TEXT_38 = NL + "}";
- protected final String TEXT_39 = NL;
+ protected final String TEXT_23 = NL + "\t\treturn df;" + NL + "\t}";
+ protected final String TEXT_24 = NL;
public String generate(Object argument)
{
final StringBuffer stringBuffer = new StringBuffer();
-Object[] args = (Object[]) argument;
-PolylineConnection figure = (PolylineConnection) args[0];
-final ImportAssistant importManager = (ImportAssistant) args[1];
-final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
-final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
-final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
+final GraphDefDispatcher.Args innerArgs = (GraphDefDispatcher.Args) ((Object[]) argument)[0];
+final PolylineConnection figure = (PolylineConnection)innerArgs.getFigure();
+final GraphDefDispatcher dispatcher = innerArgs.getDispatcher();
+final ImportAssistant importManager = dispatcher.getImportManager();
+final FigureQualifiedNameSwitch fqnSwitch = dispatcher.getFQNSwitch();
- importManager.emitPackageStatement(stringBuffer);
stringBuffer.append(TEXT_1);
- importManager.markImportLocation(stringBuffer);
stringBuffer.append(TEXT_2);
- stringBuffer.append(importManager.getCompilationUnitName());
- stringBuffer.append(TEXT_3);
- stringBuffer.append(fqnSwitch.get(figure, importManager));
- stringBuffer.append(TEXT_4);
- stringBuffer.append(TEXT_5);
//input: [oeg].common.codegen.ImportAssistant importManager
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
@@ -106,93 +83,54 @@ final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
- stringBuffer.append(TEXT_6);
+ stringBuffer.append(TEXT_3);
stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.Border"));
- stringBuffer.append(TEXT_7);
+ stringBuffer.append(TEXT_4);
stringBuffer.append(bfmNextMethodName);
- stringBuffer.append(TEXT_8);
+ stringBuffer.append(TEXT_5);
stringBuffer.append(bfmNextImplClass);
- stringBuffer.append(TEXT_9);
+ stringBuffer.append(TEXT_6);
stringBuffer.append(bfmNextImplClass);
- stringBuffer.append(TEXT_10);
+ stringBuffer.append(TEXT_7);
stringBuffer.append(dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} ));
- stringBuffer.append(TEXT_11);
+ stringBuffer.append(TEXT_8);
dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
}
} //end of namespace
- stringBuffer.append(TEXT_12);
+ stringBuffer.append(TEXT_9);
stringBuffer.append(figure.getName());
- stringBuffer.append(TEXT_13);
- stringBuffer.append(TEXT_14);
+ stringBuffer.append(TEXT_10);
+ stringBuffer.append(TEXT_11);
stringBuffer.append(dispatcher.dispatch("Shape", dispatcher.create(figure, "this")));
if (figure.getSourceDecoration() != null) {
- stringBuffer.append(TEXT_15);
+ stringBuffer.append(TEXT_12);
}
if (figure.getTargetDecoration() != null) {
- stringBuffer.append(TEXT_16);
+ stringBuffer.append(TEXT_13);
}
- stringBuffer.append(TEXT_17);
+ stringBuffer.append(TEXT_14);
if (figure.getSourceDecoration() != null) {
final String className = fqnSwitch.get(figure.getSourceDecoration(), importManager);
- stringBuffer.append(TEXT_18);
+ stringBuffer.append(TEXT_15);
stringBuffer.append(className);
- stringBuffer.append(TEXT_19);
- stringBuffer.append(TEXT_20);
+ stringBuffer.append(TEXT_16);
+ stringBuffer.append(TEXT_17);
stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getSourceDecoration(), "df")));
- stringBuffer.append(TEXT_21);
+ stringBuffer.append(TEXT_18);
} /*if sourceDecoration != null */
- stringBuffer.append(TEXT_22);
+ stringBuffer.append(TEXT_19);
if (figure.getTargetDecoration() != null) {
final String className = fqnSwitch.get(figure.getTargetDecoration(), importManager);
- stringBuffer.append(TEXT_23);
+ stringBuffer.append(TEXT_20);
stringBuffer.append(className);
- stringBuffer.append(TEXT_24);
- stringBuffer.append(TEXT_25);
+ stringBuffer.append(TEXT_21);
+ stringBuffer.append(TEXT_22);
stringBuffer.append(dispatcher.dispatch("instantiate", dispatcher.create(figure.getTargetDecoration(), "df")));
- stringBuffer.append(TEXT_26);
- }
- stringBuffer.append(TEXT_27);
-
-//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
-//input: boolean isInnerClass
-if (isInnerClass){ /*put fields out of inner class body*/
- stringBuffer.append(TEXT_28);
-
-//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
-for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
- StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next();
- stringBuffer.append(TEXT_29);
- stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_30);
- stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_31);
- stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_32);
-
-}
-
- } else {
- stringBuffer.append(TEXT_33);
-
-//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
-for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
- StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next();
- stringBuffer.append(TEXT_34);
- stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_35);
- stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_36);
- stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_37);
-
-}
-
- stringBuffer.append(TEXT_38);
+ stringBuffer.append(TEXT_23);
}
- importManager.emitSortedImports();
- stringBuffer.append(TEXT_39);
+ stringBuffer.append(TEXT_24);
return stringBuffer.toString();
}
}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java
index b68248cce..7bbc0d1ae 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopFigureGenerator.java
@@ -1,7 +1,6 @@
package org.eclipse.gmf.graphdef.codegen.templates;
import org.eclipse.gmf.gmfgraph.*;
-import org.eclipse.gmf.gmfgraph.util.*;
import org.eclipse.gmf.common.codegen.*;
import org.eclipse.gmf.graphdef.codegen.*;
import org.eclipse.emf.ecore.*;
@@ -22,62 +21,37 @@ public class TopFigureGenerator
protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
protected final String TEXT_1 = "";
- protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
- protected final String TEXT_3 = " extends ";
- protected final String TEXT_4 = " {" + NL;
- protected final String TEXT_5 = NL;
- protected final String TEXT_6 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
- protected final String TEXT_7 = " ";
- protected final String TEXT_8 = "() {" + NL + "\t\t";
- protected final String TEXT_9 = " result = new ";
- protected final String TEXT_10 = "();" + NL + "\t\t";
- protected final String TEXT_11 = NL + "\t\treturn result;" + NL + "\t}";
- protected final String TEXT_12 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
- protected final String TEXT_13 = "() {";
+ protected final String TEXT_2 = NL;
+ protected final String TEXT_3 = "\t\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate ";
+ protected final String TEXT_4 = " ";
+ protected final String TEXT_5 = "() {" + NL + "\t\t";
+ protected final String TEXT_6 = " result = new ";
+ protected final String TEXT_7 = "();" + NL + "\t\t";
+ protected final String TEXT_8 = NL + "\t\treturn result;" + NL + "\t}";
+ protected final String TEXT_9 = NL;
+ protected final String TEXT_10 = "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final org.eclipse.draw2d.geometry.PointList myTemplate = new org.eclipse.draw2d.geometry.PointList();" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate org.eclipse.draw2d.geometry.Rectangle myTemplateBounds;" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void addPoint(org.eclipse.draw2d.geometry.Point point){" + NL + "\t\tmyTemplate.addPoint(point);" + NL + "\t\tmyTemplateBounds = null;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void fillShape(org.eclipse.draw2d.Graphics graphics) {" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle bounds = getBounds();" + NL + "\t\tgraphics.pushState();" + NL + "\t\tgraphics.translate(bounds.x, bounds.y);" + NL + "\t\tgraphics.fillPolygon(scalePointList());" + NL + "\t\tgraphics.popState();" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void outlineShape(org.eclipse.draw2d.Graphics graphics) {" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle bounds = getBounds();" + NL + "\t\tgraphics.pushState();" + NL + "\t\tgraphics.translate(bounds.x, bounds.y);" + NL + "\t\tgraphics.drawPolygon(scalePointList());" + NL + "\t\tgraphics.popState();" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate org.eclipse.draw2d.geometry.Rectangle getTemplateBounds(){" + NL + "\t\tif (myTemplateBounds == null){" + NL + "\t\t\tmyTemplateBounds = new org.eclipse.draw2d.geometry.Rectangle();" + NL + "\t\t\tmyTemplateBounds = myTemplate.getBounds().union(0, 0);" + NL + "\t\t\t//just safety -- we are going to use this as divider " + NL + "\t\t\tif (myTemplateBounds.width < 1){" + NL + "\t\t\t\tmyTemplateBounds.width = 1;" + NL + "\t\t\t}" + NL + "\t\t\tif (myTemplateBounds.height < 1){" + NL + "\t\t\t\tmyTemplateBounds.height = 1;" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn myTemplateBounds;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate int[] scalePointList() {" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle pointsBounds = getTemplateBounds();" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle actualBounds = getBounds();" + NL + "" + NL + "\t\tfloat xScale = ((float) actualBounds.width) / pointsBounds.width;" + NL + "\t\tfloat yScale = ((float) actualBounds.height) / pointsBounds.height;" + NL + "" + NL + "\t\tif (xScale == 1 && yScale == 1) {" + NL + "\t\t\treturn myTemplate.toIntArray();" + NL + "\t\t}" + NL + "\t\tint[] scaled = (int[]) myTemplate.toIntArray().clone();" + NL + "\t\tfor (int i = 0; i < scaled.length; i += 2) {" + NL + "\t\t\tscaled[i] = (int) Math.floor(scaled[i] * xScale);" + NL + "\t\t\tscaled[i + 1] = (int) Math.floor(scaled[i + 1] * yScale);" + NL + "\t\t}" + NL + "\t\treturn scaled;" + NL + "\t}";
+ protected final String TEXT_11 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ";
+ protected final String TEXT_12 = "() {";
+ protected final String TEXT_13 = NL + "\t\t";
protected final String TEXT_14 = NL + "\t\t";
- protected final String TEXT_15 = NL + "\t\t";
- protected final String TEXT_16 = NL + "\t\tcreateContents();" + NL + "\t}" + NL;
+ protected final String TEXT_15 = NL + "\t\tcreateContents();" + NL + "\t}" + NL;
+ protected final String TEXT_16 = NL;
protected final String TEXT_17 = NL;
protected final String TEXT_18 = NL;
- protected final String TEXT_19 = NL;
- protected final String TEXT_20 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = ";
- protected final String TEXT_21 = ";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected boolean useLocalCoordinates() {" + NL + "\t\treturn myUseLocalCoordinates;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setUseLocalCoordinates(boolean useLocalCoordinates) {" + NL + "\t\tmyUseLocalCoordinates = useLocalCoordinates;" + NL + "\t}" + NL + "\t";
- protected final String TEXT_22 = NL;
- protected final String TEXT_23 = NL + "}" + NL + "\t";
- protected final String TEXT_24 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
- protected final String TEXT_25 = " ";
- protected final String TEXT_26 = " = ";
- protected final String TEXT_27 = ";";
- protected final String TEXT_28 = NL + "\t";
- protected final String TEXT_29 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
- protected final String TEXT_30 = " ";
- protected final String TEXT_31 = " = ";
- protected final String TEXT_32 = ";";
- protected final String TEXT_33 = NL + "}";
- protected final String TEXT_34 = NL;
+ protected final String TEXT_19 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean myUseLocalCoordinates = ";
+ protected final String TEXT_20 = ";" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected boolean useLocalCoordinates() {" + NL + "\t\treturn myUseLocalCoordinates;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void setUseLocalCoordinates(boolean useLocalCoordinates) {" + NL + "\t\tmyUseLocalCoordinates = useLocalCoordinates;" + NL + "\t}" + NL + "\t";
public String generate(Object argument)
{
final StringBuffer stringBuffer = new StringBuffer();
-Object[] args = (Object[]) argument;
-Figure figure = (Figure) args[0];
-final ImportAssistant importManager = (ImportAssistant) args[1];
-final FigureQualifiedNameSwitch fqnSwitch = (FigureQualifiedNameSwitch) args[2];
-final GraphDefDispatcher dispatcher = (GraphDefDispatcher) args[3];
+final GraphDefDispatcher.Args innerArgs = (GraphDefDispatcher.Args) ((Object[]) argument)[0];
+final Figure figure = innerArgs.getFigure();
+final GraphDefDispatcher dispatcher = innerArgs.getDispatcher();
+final ImportAssistant importManager = dispatcher.getImportManager();
-//[MG] FIXME: Why we need this? Is it in use somewhere?
-final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
-
- importManager.emitPackageStatement(stringBuffer);
stringBuffer.append(TEXT_1);
- importManager.markImportLocation(stringBuffer);
stringBuffer.append(TEXT_2);
- stringBuffer.append(importManager.getCompilationUnitName());
- stringBuffer.append(TEXT_3);
- stringBuffer.append(fqnSwitch.get(figure, importManager));
- stringBuffer.append(TEXT_4);
- stringBuffer.append(TEXT_5);
//input: [oeg].common.codegen.ImportAssistant importManager
//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
@@ -103,38 +77,42 @@ final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
String bfmNextMethodName = "createBorder_" + CodeGenUtil.capName(bfmLastFigureName) + "_" + (bfmNextIndex++);
- stringBuffer.append(TEXT_6);
+ stringBuffer.append(TEXT_3);
stringBuffer.append(importManager.getImportedName("org.eclipse.draw2d.Border"));
- stringBuffer.append(TEXT_7);
+ stringBuffer.append(TEXT_4);
stringBuffer.append(bfmNextMethodName);
- stringBuffer.append(TEXT_8);
+ stringBuffer.append(TEXT_5);
stringBuffer.append(bfmNextImplClass);
- stringBuffer.append(TEXT_9);
+ stringBuffer.append(TEXT_6);
stringBuffer.append(bfmNextImplClass);
- stringBuffer.append(TEXT_10);
+ stringBuffer.append(TEXT_7);
stringBuffer.append(dispatcher.dispatch("customAttributes", new Object[] {bfmNext, dispatcher, "result"} ));
- stringBuffer.append(TEXT_11);
+ stringBuffer.append(TEXT_8);
dispatcher.getAuxiliaryDataStorage().registerData(bfmNext, bfmNextMethodName);
}
} //end of namespace
- stringBuffer.append(TEXT_12);
+ if (figure instanceof ScalablePolygon) {
+ stringBuffer.append(TEXT_9);
+ stringBuffer.append(TEXT_10);
+ }
+ stringBuffer.append(TEXT_11);
stringBuffer.append(figure.getName());
- stringBuffer.append(TEXT_13);
+ stringBuffer.append(TEXT_12);
GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figure, "this", "myGenLayoutManager", null);
- stringBuffer.append(TEXT_14);
+ stringBuffer.append(TEXT_13);
stringBuffer.append(dispatcher.dispatch("createLayout", dispatcherArgs));
- stringBuffer.append(TEXT_15);
+ stringBuffer.append(TEXT_14);
stringBuffer.append(dispatcher.dispatch(figure, dispatcherArgs));
+ stringBuffer.append(TEXT_15);
stringBuffer.append(TEXT_16);
- stringBuffer.append(TEXT_17);
stringBuffer.append(dispatcher.dispatch("Children", dispatcherArgs));
- stringBuffer.append(TEXT_18);
+ stringBuffer.append(TEXT_17);
if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/
- stringBuffer.append(TEXT_19);
+ stringBuffer.append(TEXT_18);
// simple heuristic to detect need for local coordinates
boolean useLocalDefaultValue = false;
@@ -145,50 +123,10 @@ for (java.util.Iterator it = figure.getChildren().iterator(); it.hasNext(); ) {
}
}
- stringBuffer.append(TEXT_20);
+ stringBuffer.append(TEXT_19);
stringBuffer.append(useLocalDefaultValue);
- stringBuffer.append(TEXT_21);
- }
- stringBuffer.append(TEXT_22);
-
-//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
-//input: boolean isInnerClass
-if (isInnerClass){ /*put fields out of inner class body*/
- stringBuffer.append(TEXT_23);
-
-//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
-for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
- StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next();
- stringBuffer.append(TEXT_24);
- stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_25);
- stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_26);
- stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_27);
-
-}
-
- } else {
- stringBuffer.append(TEXT_28);
-
-//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
-for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
- StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next();
- stringBuffer.append(TEXT_29);
- stringBuffer.append(next.getType());
- stringBuffer.append(TEXT_30);
- stringBuffer.append(next.getName());
- stringBuffer.append(TEXT_31);
- stringBuffer.append(next.getValue());
- stringBuffer.append(TEXT_32);
-
-}
-
- stringBuffer.append(TEXT_33);
+ stringBuffer.append(TEXT_20);
}
- importManager.emitSortedImports();
- stringBuffer.append(TEXT_34);
return stringBuffer.toString();
}
}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopGenerator.java
new file mode 100644
index 000000000..58a900e6e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/templates/TopGenerator.java
@@ -0,0 +1,148 @@
+package org.eclipse.gmf.graphdef.codegen.templates;
+
+import org.eclipse.gmf.gmfgraph.*;
+import org.eclipse.gmf.gmfgraph.util.*;
+import org.eclipse.gmf.common.codegen.*;
+import org.eclipse.gmf.graphdef.codegen.*;
+import org.eclipse.emf.ecore.*;
+import java.util.Iterator;
+import org.eclipse.emf.ecore.util.EcoreUtil;;
+
+public class TopGenerator
+{
+ protected static String nl;
+ public static synchronized TopGenerator create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ TopGenerator result = new TopGenerator();
+ nl = null;
+ return result;
+ }
+
+ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+ protected final String TEXT_1 = "";
+ protected final String TEXT_2 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
+ protected final String TEXT_3 = " extends ";
+ protected final String TEXT_4 = " {" + NL;
+ protected final String TEXT_5 = NL;
+ protected final String TEXT_6 = NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ScalablePolygon extends org.eclipse.draw2d.Shape {";
+ protected final String TEXT_7 = NL;
+ protected final String TEXT_8 = "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate final org.eclipse.draw2d.geometry.PointList myTemplate = new org.eclipse.draw2d.geometry.PointList();" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate org.eclipse.draw2d.geometry.Rectangle myTemplateBounds;" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void addPoint(org.eclipse.draw2d.geometry.Point point){" + NL + "\t\tmyTemplate.addPoint(point);" + NL + "\t\tmyTemplateBounds = null;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void fillShape(org.eclipse.draw2d.Graphics graphics) {" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle bounds = getBounds();" + NL + "\t\tgraphics.pushState();" + NL + "\t\tgraphics.translate(bounds.x, bounds.y);" + NL + "\t\tgraphics.fillPolygon(scalePointList());" + NL + "\t\tgraphics.popState();" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void outlineShape(org.eclipse.draw2d.Graphics graphics) {" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle bounds = getBounds();" + NL + "\t\tgraphics.pushState();" + NL + "\t\tgraphics.translate(bounds.x, bounds.y);" + NL + "\t\tgraphics.drawPolygon(scalePointList());" + NL + "\t\tgraphics.popState();" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate org.eclipse.draw2d.geometry.Rectangle getTemplateBounds(){" + NL + "\t\tif (myTemplateBounds == null){" + NL + "\t\t\tmyTemplateBounds = new org.eclipse.draw2d.geometry.Rectangle();" + NL + "\t\t\tmyTemplateBounds = myTemplate.getBounds().union(0, 0);" + NL + "\t\t\t//just safety -- we are going to use this as divider " + NL + "\t\t\tif (myTemplateBounds.width < 1){" + NL + "\t\t\t\tmyTemplateBounds.width = 1;" + NL + "\t\t\t}" + NL + "\t\t\tif (myTemplateBounds.height < 1){" + NL + "\t\t\t\tmyTemplateBounds.height = 1;" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn myTemplateBounds;" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate int[] scalePointList() {" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle pointsBounds = getTemplateBounds();" + NL + "\t\torg.eclipse.draw2d.geometry.Rectangle actualBounds = getBounds();" + NL + "" + NL + "\t\tfloat xScale = ((float) actualBounds.width) / pointsBounds.width;" + NL + "\t\tfloat yScale = ((float) actualBounds.height) / pointsBounds.height;" + NL + "" + NL + "\t\tif (xScale == 1 && yScale == 1) {" + NL + "\t\t\treturn myTemplate.toIntArray();" + NL + "\t\t}" + NL + "\t\tint[] scaled = (int[]) myTemplate.toIntArray().clone();" + NL + "\t\tfor (int i = 0; i < scaled.length; i += 2) {" + NL + "\t\t\tscaled[i] = (int) Math.floor(scaled[i] * xScale);" + NL + "\t\t\tscaled[i + 1] = (int) Math.floor(scaled[i + 1] * yScale);" + NL + "\t\t}" + NL + "\t\treturn scaled;" + NL + "\t}" + NL + "}";
+ protected final String TEXT_9 = NL;
+ protected final String TEXT_10 = NL;
+ protected final String TEXT_11 = NL;
+ protected final String TEXT_12 = NL + "}" + NL + "\t";
+ protected final String TEXT_13 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
+ protected final String TEXT_14 = " ";
+ protected final String TEXT_15 = " = ";
+ protected final String TEXT_16 = ";";
+ protected final String TEXT_17 = NL + "\t";
+ protected final String TEXT_18 = NL + "\t" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final ";
+ protected final String TEXT_19 = " ";
+ protected final String TEXT_20 = " = ";
+ protected final String TEXT_21 = ";";
+ protected final String TEXT_22 = NL + "}";
+ protected final String TEXT_23 = NL;
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+
+Object[] args = (Object[]) argument;
+Figure figure = (Figure) args[0];
+final GraphDefDispatcher /*inner*/dispatcher = (GraphDefDispatcher) args[1];
+final GraphDefDispatcher topDispatcher = (GraphDefDispatcher) args[2];
+final boolean isStaticFieldsOutsideClassBody = ((Boolean) args[3]).booleanValue();
+
+class Asserter {
+ void makeAssert(boolean checkTrue){
+ assert checkTrue;
+ //temporarily use more forced way to ensure assertion
+ //TODO: replace with single assert
+ if (!checkTrue){
+ throw new IllegalStateException("Enable Assertions");
+ }
+ }
+}
+
+final Asserter myAsserter = new Asserter();
+myAsserter.makeAssert(topDispatcher.getImportManager() == /*inner*/dispatcher.getImportManager());
+myAsserter.makeAssert(topDispatcher.getFQNSwitch() == /*inner*/dispatcher.getFQNSwitch());
+
+final ImportAssistant importManager = topDispatcher.getImportManager();
+final FigureQualifiedNameSwitch fqnSwitch = topDispatcher.getFQNSwitch();
+
+ importManager.emitPackageStatement(stringBuffer);
+ stringBuffer.append(TEXT_1);
+ importManager.markImportLocation(stringBuffer);
+ stringBuffer.append(TEXT_2);
+ stringBuffer.append(importManager.getCompilationUnitName());
+ stringBuffer.append(TEXT_3);
+ stringBuffer.append(fqnSwitch.get(figure, importManager));
+ stringBuffer.append(TEXT_4);
+ stringBuffer.append(TEXT_5);
+
+//input: [oeg].gmfgraph.Figure figure
+{ //namespace, prefix spic (stands for Scalable Polygon as Inner Class) to avoid name clashes
+ boolean spicFound = false;
+ for (Iterator spicAllPolygons = EcoreUtil.getAllContents(figure, false); !spicFound && spicAllPolygons.hasNext();){
+ EObject spicNext = (EObject)spicAllPolygons.next();
+ spicFound = GMFGraphPackage.eINSTANCE.getScalablePolygon().isSuperTypeOf(spicNext.eClass());
+ }
+ if (spicFound) {
+
+ stringBuffer.append(TEXT_6);
+ stringBuffer.append(TEXT_7);
+ stringBuffer.append(TEXT_8);
+
+ }
+} // end of namespace
+
+ stringBuffer.append(TEXT_9);
+ /*NOTE: class structure is selected by topDispatcher, but children, attributes etc -- by inner dispatcher*/
+ stringBuffer.append(TEXT_10);
+ stringBuffer.append(topDispatcher.dispatch(figure, new Object[] {
+ /*inner*/dispatcher.create(figure, "this"),
+ topDispatcher.create(figure, "this")
+}));
+ stringBuffer.append(TEXT_11);
+
+if (isStaticFieldsOutsideClassBody){ /*put fields out of inner class body*/
+ stringBuffer.append(TEXT_12);
+
+//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
+for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
+ StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next();
+ stringBuffer.append(TEXT_13);
+ stringBuffer.append(next.getType());
+ stringBuffer.append(TEXT_14);
+ stringBuffer.append(next.getName());
+ stringBuffer.append(TEXT_15);
+ stringBuffer.append(next.getValue());
+ stringBuffer.append(TEXT_16);
+
+}
+
+ } else {
+ stringBuffer.append(TEXT_17);
+
+//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
+for (Iterator allFields = dispatcher.getStaticFieldsManager().allFields(); allFields.hasNext();) {
+ StaticFieldsManager.StaticField next = (StaticFieldsManager.StaticField)allFields.next();
+ stringBuffer.append(TEXT_18);
+ stringBuffer.append(next.getType());
+ stringBuffer.append(TEXT_19);
+ stringBuffer.append(next.getName());
+ stringBuffer.append(TEXT_20);
+ stringBuffer.append(next.getValue());
+ stringBuffer.append(TEXT_21);
+
+}
+
+ stringBuffer.append(TEXT_22);
+ }
+ importManager.emitSortedImports();
+ stringBuffer.append(TEXT_23);
+ return stringBuffer.toString();
+ }
+}

Back to the top