[jboss-cvs] JBossAS SVN: r91017 - in projects/mc-tools/grapher/trunk/src: main/java/org/jboss/mctools/grapher/layout and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 9 15:38:57 EDT 2009
Author: alesj
Date: 2009-07-09 15:38:57 -0400 (Thu, 09 Jul 2009)
New Revision: 91017
Added:
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayout.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/ReflectionGraphLayout.java
Modified:
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java
projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/AbstractRendererTest.java
projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/ManualGraphWrite2FileTestCase.java
Log:
Add layout + its reflection trick.
Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java (from rev 90961, projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java 2009-07-09 19:38:57 UTC (rev 91017)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mctools.grapher;
+
+import org.jboss.mctools.grapher.layout.GraphLayout;
+import org.jboss.mctools.grapher.layout.ReflectionGraphLayout;
+import org.jboss.mctools.grapher.map.DefaultGraphCreatorMapper;
+import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+
+/**
+ * Grapher constants.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public final class GrapherConstants
+{
+ private GrapherConstants()
+ {
+ }
+
+ /** The default format */
+ public static final String FORMAT = "gif";
+
+ /** The default mapper */
+ public static final GraphCreatorMapper MAPPER = new DefaultGraphCreatorMapper();
+
+ /** The default layout */
+ public static final GraphLayout LAYOUT = new ReflectionGraphLayout("com.jgraph.layout.organic.JGraphOrganicLayout");
+}
\ No newline at end of file
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java 2009-07-09 19:37:00 UTC (rev 91016)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java 2009-07-09 19:38:57 UTC (rev 91017)
@@ -36,7 +36,7 @@
import org.jboss.logging.Logger;
import org.jboss.mc.servlet.vdf.api.KernelControllerVDFConnector;
import org.jboss.mctools.grapher.graph.GraphCreator;
-import org.jboss.mctools.grapher.map.DefaultGraphCreatorMapper;
+import org.jboss.mctools.grapher.layout.GraphLayout;
import org.jboss.mctools.grapher.map.GraphCreatorMapper;
import org.jboss.mctools.grapher.render.GIFRenderer;
import org.jboss.mctools.grapher.render.JPGRenderer;
@@ -63,8 +63,8 @@
private KernelController controller;
private GraphCreatorMapper mapper;
+ private GraphLayout layout;
- private static final String DEFAULT_FORMAT = "gif";
/**
* The default renderer
*/
@@ -81,7 +81,8 @@
controller = connector.getUtility();
- mapper = createInstance(config.getInitParameter("mapper"), new DefaultGraphCreatorMapper(), GraphCreatorMapper.class);
+ mapper = createInstance(config.getInitParameter("mapper"), GrapherConstants.MAPPER, GraphCreatorMapper.class);
+ layout = createInstance(config.getInitParameter("layout"), GrapherConstants.LAYOUT, GraphLayout.class);
renderers = new HashMap<String, Renderer>();
renderers.put("svg", new SVGRenderer());
@@ -96,7 +97,7 @@
// or is this a new impl
if (renderer == null)
- renderer = createInstance(defaultRenderer, renderers.get(DEFAULT_FORMAT), Renderer.class);
+ renderer = createInstance(defaultRenderer, renderers.get(GrapherConstants.FORMAT), Renderer.class);
}
/**
@@ -133,6 +134,10 @@
log.info("Invoking creator: " + creator);
JGraph graph = creator.createGraph(controller);
+
+ // apply layout
+ layout.applyLayout(graph);
+
Renderer current = getRenderer(request.getParameter("renderer"));
//if (log.isTraceEnabled())
log.info("Using renderer: " + current);
Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayout.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayout.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayout.java 2009-07-09 19:38:57 UTC (rev 91017)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mctools.grapher.layout;
+
+import org.jgraph.JGraph;
+
+/**
+ * Graph layout interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface GraphLayout
+{
+ /**
+ * Apply the layout to the graph.
+ *
+ * @param graph the graph to apply layout to
+ */
+ void applyLayout(JGraph graph);
+}
Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/ReflectionGraphLayout.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/ReflectionGraphLayout.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/ReflectionGraphLayout.java 2009-07-09 19:38:57 UTC (rev 91017)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mctools.grapher.layout;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jgraph.JGraph;
+
+/**
+ * Reflection based graph layout due to license limitations.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ReflectionGraphLayout implements GraphLayout
+{
+ private Logger log = Logger.getLogger(getClass());
+ private String jgraphLayoutClass;
+
+ public ReflectionGraphLayout(String jgraphLayoutClass)
+ {
+ this.jgraphLayoutClass = jgraphLayoutClass;
+ }
+
+ public void applyLayout(JGraph graph)
+ {
+ if (jgraphLayoutClass == null)
+ return;
+
+ try
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Object layout = loader.loadClass(jgraphLayoutClass).newInstance();
+ Class<?> facadeClass = loader.loadClass("com.jgraph.layout.JGraphFacade");
+ Constructor facadeCtor = facadeClass.getConstructor(JGraph.class);
+ Object facade = facadeCtor.newInstance(graph);
+ Method runLayout = layout.getClass().getMethod("run", facadeClass);
+ runLayout.invoke(layout, facade);
+ Method createNestedMap = facadeClass.getMethod("createNestedMap", Boolean.TYPE, Boolean.TYPE);
+ Map nested = (Map)createNestedMap.invoke(facade, true, true);
+ graph.getGraphLayoutCache().edit(nested);
+ }
+ catch (Exception e)
+ {
+ log.debug("Missing layout classes [" + jgraphLayoutClass + "]: " + e);
+ }
+ }
+}
\ No newline at end of file
Modified: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/AbstractRendererTest.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/AbstractRendererTest.java 2009-07-09 19:37:00 UTC (rev 91016)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/AbstractRendererTest.java 2009-07-09 19:38:57 UTC (rev 91017)
@@ -25,6 +25,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.jboss.mctools.grapher.GrapherConstants;
+import org.jboss.mctools.grapher.layout.GraphLayout;
import org.jboss.mctools.grapher.render.GIFRenderer;
import org.jboss.mctools.grapher.render.JPGRenderer;
import org.jboss.mctools.grapher.render.PNGRenderer;
@@ -57,6 +59,11 @@
suffixes.put(PNGRenderer.class, ".png");
}
+ protected GraphLayout createLayout()
+ {
+ return GrapherConstants.LAYOUT;
+ }
+
protected abstract T createOutputStream(String suffix) throws Throwable;
protected abstract void testOutputStream(T out, String suffix);
@@ -71,6 +78,11 @@
protected void testRenderer(Renderer renderer) throws Throwable
{
JGraph graph = createGraph();
+
+ // apply layout
+ GraphLayout layout = createLayout();
+ layout.applyLayout(graph);
+
String suffix = suffixes.get(renderer.getClass());
T out = createOutputStream(suffix);
try
Modified: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/ManualGraphWrite2FileTestCase.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/ManualGraphWrite2FileTestCase.java 2009-07-09 19:37:00 UTC (rev 91016)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/ManualGraphWrite2FileTestCase.java 2009-07-09 19:38:57 UTC (rev 91017)
@@ -45,7 +45,7 @@
public ManualGraphWrite2FileTestCase(String name)
{
super(name);
- //setDeleteFile(false);
+ setDeleteFile(false);
}
public static Test suite()
More information about the jboss-cvs-commits
mailing list