[jboss-cvs] JBossAS SVN: r91386 - in projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher: layout and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 17 16:11:27 EDT 2009


Author: alesj
Date: 2009-07-17 16:11:27 -0400 (Fri, 17 Jul 2009)
New Revision: 91386

Added:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/DefaultGraphLayout.java
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayoutMapping.java
Modified:
   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/GrapherServlet.java
Log:
Layout choice.

Modified: 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/GrapherConstants.java	2009-07-17 19:34:16 UTC (rev 91385)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java	2009-07-17 20:11:27 UTC (rev 91386)
@@ -23,13 +23,13 @@
 
 import java.awt.*;
 
+import org.jboss.mctools.grapher.graph.DefaultGraphComponentFactory;
+import org.jboss.mctools.grapher.graph.GraphComponentFactory;
+import org.jboss.mctools.grapher.layout.DefaultGraphLayout;
 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;
 import org.jboss.mctools.grapher.routing.ParallelSplineRouter;
-import org.jboss.mctools.grapher.graph.GraphComponentFactory;
-import org.jboss.mctools.grapher.graph.DefaultGraphComponentFactory;
 import org.jgraph.graph.Edge;
 
 /**
@@ -50,7 +50,7 @@
    public static final GraphCreatorMapper MAPPER = new DefaultGraphCreatorMapper();
 
    /** The default layout */
-   public static final GraphLayout LAYOUT = new ReflectionGraphLayout("com.jgraph.layout.tree.JGraphRadialTreeLayout");
+   public static final GraphLayout LAYOUT = new DefaultGraphLayout();
 
    /** The edge routing */
    public static final Edge.Routing ROUTING = ParallelSplineRouter.getInstance(); 

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-17 19:34:16 UTC (rev 91385)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherServlet.java	2009-07-17 20:11:27 UTC (rev 91386)
@@ -37,6 +37,7 @@
 import org.jboss.mc.servlet.vdf.api.KernelControllerVDFConnector;
 import org.jboss.mctools.grapher.graph.GraphCreator;
 import org.jboss.mctools.grapher.layout.GraphLayout;
+import org.jboss.mctools.grapher.layout.GraphLayoutMapping;
 import org.jboss.mctools.grapher.map.GraphCreatorMapper;
 import org.jboss.mctools.grapher.map.ExcludeTypes;
 import org.jboss.mctools.grapher.render.GIFRenderer;
@@ -156,16 +157,17 @@
       JGraph graph = creator.createGraph(controller, ExcludeTypes.createExcludedTypes(request));
 
       // apply layout
-      layout.applyLayout(graph);
+      GraphLayout currentLayout = mapGraphLayout(request);
+      currentLayout.applyLayout(graph);
 
-      Renderer current = getRenderer(request.getParameter("renderer"));
+      Renderer currentRenderer = getRenderer(request.getParameter("renderer"));
       if (log.isTraceEnabled())
-         log.trace("Using renderer: " + current);
+         log.trace("Using renderer: " + currentRenderer);
 
       OutputStream writer = response.getOutputStream();
       try
       {
-         current.render(graph, writer, 10);
+         currentRenderer.render(graph, writer, 10);
       }
       finally
       {
@@ -176,7 +178,7 @@
    /**
     * Map graph creator from request.
     *
-    * @param request the curent http request
+    * @param request the current http request
     * @return graph creator instance
     */
    protected GraphCreator mapGraphCreator(HttpServletRequest request)
@@ -184,6 +186,21 @@
       return mapper.mapFromRequest(request);
    }
 
+   /**
+    * Map graph layout.
+    *
+    * @param request the current http request
+    * @return
+    */
+   protected GraphLayout mapGraphLayout(HttpServletRequest request)
+   {
+      String layoutKey = request.getParameter("layout");
+      if (layoutKey == null)
+         return layout;
+
+      return GraphLayoutMapping.getLayout(layoutKey); 
+   }
+
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {

Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/DefaultGraphLayout.java (from rev 91385, 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/DefaultGraphLayout.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/DefaultGraphLayout.java	2009-07-17 20:11:27 UTC (rev 91386)
@@ -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;
+
+/**
+ * Default graph layout.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultGraphLayout implements GraphLayout
+{
+   public void applyLayout(JGraph graph)
+   {
+      // TODO - write our own impl
+      GraphLayout layout = new ReflectionGraphLayout("com.jgraph.layout.graph.JGraphSimpleLayout");
+      layout.applyLayout(graph);
+   }
+}
\ No newline at end of file

Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayoutMapping.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayoutMapping.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/layout/GraphLayoutMapping.java	2009-07-17 20:11:27 UTC (rev 91386)
@@ -0,0 +1,73 @@
+/*
+ * 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.util.Map;
+import java.util.HashMap;
+
+import org.jboss.mctools.grapher.GrapherConstants;
+
+/**
+ * Map simple name to full layout class name.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public final class GraphLayoutMapping
+{
+   private static final Map<String, String> map = new HashMap<String, String>();
+
+   static
+   {
+      map.put("simple", "com.jgraph.layout.graph.JGraphSimpleLayout");
+      map.put("tree", "com.jgraph.layout.tree.JGraphTreeLayout");
+      map.put("spring", "com.jgraph.layout.graph.JGraphSpringLayout");
+      map.put("hierarchical", "com.jgraph.layout.hierarchical.JGrapHierarchicalhLayout");
+      map.put("compound", "com.jgraph.layout.graph.JGraphCompoundTreeLayout");
+      map.put("compact", "com.jgraph.layout.graph.JGraphCompactTreeLayout");
+      map.put("moen", "com.jgraph.layout.graph.JGraphMoenLayout");
+      map.put("radial", "com.jgraph.layout.graph.JGraphRadialTreeLayout");
+      map.put("annealing", "com.jgraph.layout.graph.JGraphAnnealingLayout");
+      map.put("fr", "com.jgraph.layout.graph.JGraphFRLayout");
+      map.put("organic", "com.jgraph.layout.organic.JGraphOrganicLayout");
+      map.put("self", "com.jgraph.layout.organic.JGraphSelfOrganizingOrganicLayout");
+      map.put("isom", "com.jgraph.layout.graph.JGraphISOMLayout");
+      map.put("org", "com.jgraph.layout.tree.OrganizationalLayout");
+   }
+
+   /**
+    * Get layout.
+    *
+    * @param key the layout key
+    * @return the layout
+    */
+   public static GraphLayout getLayout(String key)
+   {
+      if (key == null)
+         return GrapherConstants.LAYOUT;
+
+      String className = map.get(key);
+      if (className == null)
+         return GrapherConstants.LAYOUT;
+
+      return new ReflectionGraphLayout(className);
+   }
+}




More information about the jboss-cvs-commits mailing list