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/templates
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/templates')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet31
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet23
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Top.javajet53
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc10
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/customBorderFactoryMethods.jetinc (renamed from plugins/org.eclipse.gmf.graphdef.codegen/templates/customBorderFactoryMethods.jetinc)0
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonAsInnerClass.jetinc20
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonBehavior.jetinc77
7 files changed, 166 insertions, 48 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet
index ffb3a645f..5feebb82a 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Figure.javajet
@@ -1,25 +1,16 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopFigureGenerator"
- imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.emf.ecore.* java.util.Iterator org.eclipse.emf.ecore.util.EcoreUtil org.eclipse.emf.codegen.util.CodeGenUtil; "%>
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.emf.ecore.* java.util.Iterator org.eclipse.emf.ecore.util.EcoreUtil org.eclipse.emf.codegen.util.CodeGenUtil; "%>
<%
-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];
-
-//[MG] FIXME: Why we need this? Is it in use somewhere?
-final boolean isInnerClass = ((Boolean) args[4]).booleanValue();
+final GraphDefDispatcher.Args innerArgs = (GraphDefDispatcher.Args) ((Object[]) argument)[0];
+final Figure figure = innerArgs.getFigure();
+final GraphDefDispatcher dispatcher = innerArgs.getDispatcher();
+final ImportAssistant importManager = dispatcher.getImportManager();
%>
-<%importManager.emitPackageStatement(stringBuffer);%>
-
-<%importManager.markImportLocation(stringBuffer);%>
-
-/**
- * @generated
- */
-public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
-<%@ include file="../customBorderFactoryMethods.jetinc"%>
+<%@ include file="customBorderFactoryMethods.jetinc"%>
+<%if (figure instanceof ScalablePolygon) {%>
+<%@ include file="scalablePolygonBehavior.jetinc"%>
+<%}%>
/**
* @generated
@@ -37,6 +28,4 @@ GraphDefDispatcher.LayoutArgs dispatcherArgs = dispatcher.createLayoutArgs(figur
<%if (false == figure instanceof Polyline) {/*no much sense to define useLocalCoordinates for polyline and its descendants*/%>
<%@ include file="localCoordinates.jetinc"%>
-<%}%>
-<%@ include file="classFooter.jetinc"%>
-<%importManager.emitSortedImports();%>
+<%}%> \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet
index 4be7ba54c..b72f2c976 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/PolylineConnection.javajet
@@ -1,23 +1,14 @@
<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopConnectionGenerator"
imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.emf.ecore.* java.util.Iterator org.eclipse.emf.ecore.util.EcoreUtil org.eclipse.emf.codegen.util.CodeGenUtil;"%>
<%
-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);%>
-<%importManager.markImportLocation(stringBuffer);%>
-
-/**
- * @generated
- */
-public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
-
-<%@ include file="../customBorderFactoryMethods.jetinc"%>
+<%@ include file="customBorderFactoryMethods.jetinc"%>
/**
* @generated
@@ -53,5 +44,3 @@ if (figure.getTargetDecoration() != null) {%>
return df;
}
<%}%>
-<%@ include file="classFooter.jetinc"%>
-<%importManager.emitSortedImports();%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Top.javajet b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Top.javajet
new file mode 100644
index 000000000..be427c250
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/Top.javajet
@@ -0,0 +1,53 @@
+<%@ jet package="org.eclipse.gmf.graphdef.codegen.templates" class="TopGenerator"
+ imports="org.eclipse.gmf.gmfgraph.* org.eclipse.gmf.gmfgraph.util.* org.eclipse.gmf.common.codegen.* org.eclipse.gmf.graphdef.codegen.* org.eclipse.emf.ecore.* java.util.Iterator org.eclipse.emf.ecore.util.EcoreUtil; "%>
+<%
+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);%>
+
+<%importManager.markImportLocation(stringBuffer);%>
+
+/**
+ * @generated
+ */
+public class <%=importManager.getCompilationUnitName()%> extends <%=fqnSwitch.get(figure, importManager)%> {
+
+<%@ include file="scalablePolygonAsInnerClass.jetinc"%>
+
+<% /*NOTE: class structure is selected by topDispatcher, but children, attributes etc -- by inner dispatcher*/ %>
+<%=topDispatcher.dispatch(figure, new Object[] {
+ /*inner*/dispatcher.create(figure, "this"),
+ topDispatcher.create(figure, "this")
+})%>
+
+<%
+if (isStaticFieldsOutsideClassBody){ /*put fields out of inner class body*/ %>
+}
+ <%@ include file="staticFields.jetinc"%>
+<% } else { %>
+ <%@ include file="staticFields.jetinc"%>
+}
+<%}%>
+<%importManager.emitSortedImports();%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc
deleted file mode 100644
index 2143d1a51..000000000
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/classFooter.jetinc
+++ /dev/null
@@ -1,10 +0,0 @@
-<%
-//input: [oeg].graphdef.codegen GraphDefDispatcher dispatcher
-//input: boolean isInnerClass
-if (isInnerClass){ /*put fields out of inner class body*/ %>
-}
- <%@ include file="staticFields.jetinc"%>
-<% } else { %>
- <%@ include file="staticFields.jetinc"%>
-}
-<%}%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/customBorderFactoryMethods.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/customBorderFactoryMethods.jetinc
index 78d4422f3..78d4422f3 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates/customBorderFactoryMethods.jetinc
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/customBorderFactoryMethods.jetinc
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonAsInnerClass.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonAsInnerClass.jetinc
new file mode 100644
index 000000000..77213ee45
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonAsInnerClass.jetinc
@@ -0,0 +1,20 @@
+<%
+//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) {
+%>
+/**
+ * @generated
+ */
+public class ScalablePolygon extends org.eclipse.draw2d.Shape {
+<%@ include file="scalablePolygonBehavior.jetinc"%>
+}
+<%
+ }
+} // end of namespace
+%>
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonBehavior.jetinc b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonBehavior.jetinc
new file mode 100644
index 000000000..46188cb11
--- /dev/null
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates/top/scalablePolygonBehavior.jetinc
@@ -0,0 +1,77 @@
+ /**
+ * @generated
+ */
+ private final org.eclipse.draw2d.geometry.PointList myTemplate = new org.eclipse.draw2d.geometry.PointList();
+ /**
+ * @generated
+ */
+ private org.eclipse.draw2d.geometry.Rectangle myTemplateBounds;
+
+ /**
+ * @generated
+ */
+ public void addPoint(org.eclipse.draw2d.geometry.Point point){
+ myTemplate.addPoint(point);
+ myTemplateBounds = null;
+ }
+
+ /**
+ * @generated
+ */
+ protected void fillShape(org.eclipse.draw2d.Graphics graphics) {
+ org.eclipse.draw2d.geometry.Rectangle bounds = getBounds();
+ graphics.pushState();
+ graphics.translate(bounds.x, bounds.y);
+ graphics.fillPolygon(scalePointList());
+ graphics.popState();
+ }
+
+ /**
+ * @generated
+ */
+ protected void outlineShape(org.eclipse.draw2d.Graphics graphics) {
+ org.eclipse.draw2d.geometry.Rectangle bounds = getBounds();
+ graphics.pushState();
+ graphics.translate(bounds.x, bounds.y);
+ graphics.drawPolygon(scalePointList());
+ graphics.popState();
+ }
+
+ /**
+ * @generated
+ */
+ private org.eclipse.draw2d.geometry.Rectangle getTemplateBounds(){
+ if (myTemplateBounds == null){
+ myTemplateBounds = new org.eclipse.draw2d.geometry.Rectangle();
+ myTemplateBounds = myTemplate.getBounds().union(0, 0);
+ //just safety -- we are going to use this as divider
+ if (myTemplateBounds.width < 1){
+ myTemplateBounds.width = 1;
+ }
+ if (myTemplateBounds.height < 1){
+ myTemplateBounds.height = 1;
+ }
+ }
+ return myTemplateBounds;
+ }
+
+ /**
+ * @generated
+ */
+ private int[] scalePointList() {
+ org.eclipse.draw2d.geometry.Rectangle pointsBounds = getTemplateBounds();
+ org.eclipse.draw2d.geometry.Rectangle actualBounds = getBounds();
+
+ float xScale = ((float) actualBounds.width) / pointsBounds.width;
+ float yScale = ((float) actualBounds.height) / pointsBounds.height;
+
+ if (xScale == 1 && yScale == 1) {
+ return myTemplate.toIntArray();
+ }
+ int[] scaled = (int[]) myTemplate.toIntArray().clone();
+ for (int i = 0; i < scaled.length; i += 2) {
+ scaled[i] = (int) Math.floor(scaled[i] * xScale);
+ scaled[i + 1] = (int) Math.floor(scaled[i + 1] * yScale);
+ }
+ return scaled;
+ }

Back to the top