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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 22 15:18:27 EDT 2009


Author: alesj
Date: 2009-07-22 15:18:27 -0400 (Wed, 22 Jul 2009)
New Revision: 91572

Added:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/render/HtmlRenderer.java
Modified:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultRendererMapper.java
Log:
Html renderer.

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultRendererMapper.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultRendererMapper.java	2009-07-22 19:14:30 UTC (rev 91571)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/map/DefaultRendererMapper.java	2009-07-22 19:18:27 UTC (rev 91572)
@@ -24,12 +24,13 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.jboss.mctools.grapher.GrapherConstants;
 import org.jboss.mctools.grapher.render.GIFRenderer;
+import org.jboss.mctools.grapher.render.HtmlRenderer;
 import org.jboss.mctools.grapher.render.JPGRenderer;
 import org.jboss.mctools.grapher.render.PNGRenderer;
 import org.jboss.mctools.grapher.render.Renderer;
 import org.jboss.mctools.grapher.render.SVGRenderer;
-import org.jboss.mctools.grapher.GrapherConstants;
 
 /**
  * Default graph creator mapper.
@@ -47,6 +48,7 @@
    public DefaultRendererMapper()
    {
       renderers = new HashMap<String, Renderer>();
+      renderers.put("html", new HtmlRenderer());
       renderers.put("svg", new SVGRenderer());
       renderers.put("jpg", new JPGRenderer());
       renderers.put("png", new PNGRenderer());

Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/render/HtmlRenderer.java (from rev 90939, projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/render/SVGRenderer.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/render/HtmlRenderer.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/render/HtmlRenderer.java	2009-07-22 19:18:27 UTC (rev 91572)
@@ -0,0 +1,80 @@
+/*
+ * 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.render;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.mctools.grapher.graph.GVertex;
+import org.jgraph.JGraph;
+
+/**
+ * Render html.
+ * // TODO test
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class HtmlRenderer implements Renderer
+{
+   private static final Comparator<Object> COMPARATOR = new CellComparator();
+
+   public void render(JGraph graph, OutputStream out, int inset) throws IOException
+   {
+      Object[] roots = graph.getRoots();
+      if (roots != null)
+      {
+         Set<Object> links = new TreeSet<Object>(COMPARATOR);
+         links.addAll(Arrays.asList(roots));
+
+         write(out, "<html>");
+         write(out, "<ul>");
+         for (Object cell : links)
+         {
+            if (cell instanceof GVertex)
+            {
+               write(out, "<li><a href=\"?bean=" + cell + "\">" + cell + "</a></li>\n");
+            }
+         }
+         write(out, "</ul>");
+         write(out, "</html>");
+         out.flush();
+      }
+   }
+
+   // simplify write
+   private void write(OutputStream out, String text) throws IOException
+   {
+      out.write(text.getBytes());
+   }
+
+   private static class CellComparator implements Comparator<Object>
+   {
+      public int compare(Object o1, Object o2)
+      {
+         return o1.toString().compareTo(o2.toString());
+      }
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list