[jboss-cvs] JBossAS SVN: r91342 - in projects/mc-tools/grapher/trunk/src: main/java/org/jboss/mctools/grapher/graph and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 16 08:40:48 EDT 2009
Author: alesj
Date: 2009-07-16 08:40:48 -0400 (Thu, 16 Jul 2009)
New Revision: 91342
Added:
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GEdge.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GVertex.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GrapherEdge.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/graph/Colorable.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/ColorableGraphCell.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphSettings.java
projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java
Log:
Add JBoss graph.
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-16 12:30:05 UTC (rev 91341)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -50,7 +50,7 @@
public static final GraphCreatorMapper MAPPER = new DefaultGraphCreatorMapper();
/** The default layout */
- public static final GraphLayout LAYOUT = new ReflectionGraphLayout("com.jgraph.layout.graph.JGraphFRLayout");
+ public static final GraphLayout LAYOUT = new ReflectionGraphLayout("com.jgraph.layout.tree.JGraphTreeLayout");
/** The edge routing */
public static final Edge.Routing ROUTING = ParallelSplineRouter.getInstance();
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/Colorable.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/Colorable.java 2009-07-16 12:30:05 UTC (rev 91341)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/Colorable.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -24,6 +24,8 @@
import java.awt.*;
/**
+ * Object has color attribute.
+ *
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
public interface Colorable
@@ -41,4 +43,11 @@
* @param color the color
*/
void setColor(Color color);
+
+ /**
+ * Get the cell label.
+ *
+ * @return
+ */
+ String getLabel();
}
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/ColorableGraphCell.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/ColorableGraphCell.java 2009-07-16 12:30:05 UTC (rev 91341)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/ColorableGraphCell.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -23,6 +23,7 @@
import java.awt.*;
+import org.jboss.util.graph.Vertex;
import org.jgraph.graph.DefaultGraphCell;
/**
@@ -30,19 +31,16 @@
*
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class ColorableGraphCell extends DefaultGraphCell implements Colorable
+public class ColorableGraphCell extends DefaultGraphCell implements Colorable, GVertex
{
private Color color;
+ private Vertex<String> vertex;
- public ColorableGraphCell(Color color)
- {
- this.color = color;
- }
-
public ColorableGraphCell(Object userObject, Color color)
{
super(userObject);
this.color = color;
+ vertex = new Vertex<String>(getLabel());
}
public Color getColor()
@@ -54,4 +52,15 @@
{
this.color = color;
}
+
+ public String getLabel()
+ {
+ Object label = getUserObject();
+ return label != null ? label.toString() : "";
+ }
+
+ public Vertex<String> getVertex()
+ {
+ return vertex;
+ }
}
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java 2009-07-16 12:30:05 UTC (rev 91341)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -26,7 +26,6 @@
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.mctools.grapher.GrapherConstants;
import org.jgraph.graph.ConnectionSet;
-import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.Edge;
import org.jgraph.graph.GraphCell;
@@ -95,8 +94,11 @@
public Edge createEdge(Object label, GraphCell target, GraphCell source, ConnectionSet cs)
{
- Edge edge = new DefaultEdge(label);
- cs.connect(edge, ((DefaultGraphCell)target).getChildAt(0), ((DefaultGraphCell)source).getChildAt(0));
+ GrapherEdge edge = new GrapherEdge(label);
+ ColorableGraphCell from = (ColorableGraphCell)target;
+ ColorableGraphCell to = (ColorableGraphCell)source;
+ cs.connect(edge, from.getChildAt(0), to.getChildAt(0));
+ edge.setEdge(from.getVertex(), to.getVertex());
int arrow = GraphConstants.ARROW_CLASSIC;
GraphConstants.setLineEnd(edge.getAttributes(), arrow);
Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GEdge.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GEdge.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GEdge.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -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.graph;
+
+import org.jboss.util.graph.Edge;
+
+/**
+ * JBoss graph edge.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface GEdge
+{
+ /**
+ * Get JBoss Edge impl.
+ *
+ * @return the vertex
+ */
+ Edge<String> getEdge();
+}
\ No newline at end of file
Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GVertex.java (from rev 91120, projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/Colorable.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GVertex.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GVertex.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -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.graph;
+
+import org.jboss.util.graph.Vertex;
+
+/**
+ * JBoss graph vertex.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface GVertex
+{
+ /**
+ * Get JBoss Vertext impl.
+ *
+ * @return the vertex
+ */
+ Vertex<String> getVertex();
+}
\ No newline at end of file
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphSettings.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphSettings.java 2009-07-16 12:30:05 UTC (rev 91341)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphSettings.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -41,6 +41,7 @@
* @param cells the cells
* @param attributes the attributes
*/
+ @SuppressWarnings("unchecked")
public static void layout(Object[] cells, Map attributes)
{
int count = cells.length;
@@ -56,7 +57,7 @@
if (obj instanceof Colorable)
{
Colorable cell = (Colorable)obj;
- attributes.put(cell, createBounds(col * 70, row * 70, cell.getColor()));
+ attributes.put(cell, createBounds(cell.getLabel(), col * 70, row * 70, cell.getColor()));
}
if (col >= nodesperrow)
{
@@ -69,15 +70,18 @@
/**
* Create bounds.
*
+ * @param label the label
* @param x the x
* @param y the y
* @param c the color
* @return bounds map
*/
- private static Map createBounds(int x, int y, Color c)
+ private static Map createBounds(String label, int x, int y, Color c)
{
Map map = new HashMap();
- GraphConstants.setBounds(map, new Rectangle(x, y, 30, 30));
+ int length = label.length();
+ int width = Math.min(200, 12 * length);
+ GraphConstants.setBounds(map, new Rectangle(x, y, width, 30));
GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder());
GraphConstants.setBackground(map, c.brighter());
GraphConstants.setForeground(map, Color.white);
Copied: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GrapherEdge.java (from rev 91120, projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/ColorableGraphCell.java)
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GrapherEdge.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GrapherEdge.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -0,0 +1,51 @@
+/*
+ * 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.graph;
+
+import org.jboss.util.graph.Edge;
+import org.jboss.util.graph.Vertex;
+import org.jgraph.graph.DefaultEdge;
+
+/**
+ * Colorable graph cell.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class GrapherEdge extends DefaultEdge implements GEdge
+{
+ private Edge<String> edge;
+
+ public GrapherEdge(Object o)
+ {
+ super(o);
+ }
+
+ public Edge getEdge()
+ {
+ return edge;
+ }
+
+ void setEdge(Vertex<String> from, Vertex<String> to)
+ {
+ edge = new Edge<String>(from, to);
+ }
+}
\ No newline at end of file
Modified: projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java 2009-07-16 12:30:05 UTC (rev 91341)
+++ projects/mc-tools/grapher/trunk/src/test/java/org/jboss/test/mctools/grapher/render/test/Write2FileTestCase.java 2009-07-16 12:40:48 UTC (rev 91342)
@@ -23,12 +23,10 @@
import java.io.File;
import java.io.FileOutputStream;
-import java.security.ProtectionDomain;
-import java.security.CodeSource;
import java.net.URL;
+import java.security.CodeSource;
+import java.security.ProtectionDomain;
-import javax.swing.*;
-
import junit.framework.Test;
import org.jboss.mctools.grapher.graph.GraphCreator;
import org.jboss.mctools.grapher.map.GraphCreatorMapper;
More information about the jboss-cvs-commits
mailing list