[jboss-cvs] JBossAS SVN: r91120 - in projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher: graph and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 10 17:34:44 EDT 2009
Author: alesj
Date: 2009-07-10 17:34:44 -0400 (Fri, 10 Jul 2009)
New Revision: 91120
Added:
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/GraphComponentFactory.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/AbstractGraphCreator.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/BeanGraphCreator.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/GraphSettings.java
projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java
Log:
Keep graph component creation in one place.
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-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -21,11 +21,15 @@
*/
package org.jboss.mctools.grapher;
+import java.awt.*;
+
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,4 +54,10 @@
/** The edge routing */
public static final Edge.Routing ROUTING = ParallelSplineRouter.getInstance();
+
+ /** The vertex color */
+ public static final Color COLOR = Color.WHITE;
+
+ /** The graph component factory */
+ public static final GraphComponentFactory COMPONENT_FACTORY = DefaultGraphComponentFactory.getInstance();
}
\ No newline at end of file
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java 2009-07-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -21,7 +21,6 @@
*/
package org.jboss.mctools.grapher.graph;
-import java.awt.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -39,12 +38,9 @@
import org.jgraph.JGraph;
import org.jgraph.graph.AttributeMap;
import org.jgraph.graph.ConnectionSet;
-import org.jgraph.graph.DefaultEdge;
-import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultGraphModel;
import org.jgraph.graph.Edge;
import org.jgraph.graph.GraphCell;
-import org.jgraph.graph.GraphConstants;
import org.jgraph.graph.GraphModel;
/**
@@ -56,6 +52,9 @@
{
protected Logger log = Logger.getLogger(getClass());
+ /** The graph component factory */
+ private GraphComponentFactory factory = GrapherConstants.COMPONENT_FACTORY;
+
public JGraph createGraph(KernelController controller)
{
Map attributes = new HashMap();
@@ -85,9 +84,17 @@
return new JGraph(model);
}
+ /**
+ * Create cells.
+ *
+ * @param controller the controller
+ * @param attributes the attributes
+ * @param cs the connection set
+ * @return graph cells
+ */
protected Object[] createCells(KernelController controller, Map attributes, ConnectionSet cs)
{
- Map<Object, DefaultGraphCell> cells = new HashMap<Object, DefaultGraphCell>();
+ Map<Object, GraphCell> cells = new HashMap<Object, GraphCell>();
Set<Object> objects = new HashSet<Object>();
createCells(controller, cells, objects, attributes, cs);
@@ -109,7 +116,7 @@
* @param attributes the graph attributes
* @param cs the connection set
*/
- protected abstract void createCells(KernelController controller, Map<Object, DefaultGraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs);
+ protected abstract void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs);
/**
* Create the cell.
@@ -117,19 +124,9 @@
* @param label the cell's label
* @return new cell instance
*/
- protected DefaultGraphCell createCell(Object label)
+ protected GraphCell createCell(Object label)
{
- DefaultGraphCell cell = new ColorableGraphCell(label, Color.BLUE);
-/*
- GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(20,20,30,15));
- GraphConstants.setGradientColor(cell.getAttributes(), Color.orange);
- GraphConstants.setOpaque(cell.getAttributes(), true);
-*/
-
- cell.addPort();
-
- // TODO - add html link
- return cell;
+ return factory.createVertex(label);
}
/**
@@ -153,9 +150,10 @@
* @param cs the connection set
* @param context the context to render
*/
- protected void handleContext(KernelController controller, Map<Object, DefaultGraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, ControllerContext context)
+ @SuppressWarnings({"UnusedDeclaration"})
+ protected void handleContext(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs, ControllerContext context)
{
- DefaultGraphCell owner = getCell(cells, objects, context);
+ GraphCell owner = getCell(cells, objects, context);
DependencyInfo info = context.getDependencyInfo();
Set<DependencyItem> items = info.getIDependOn(null);
@@ -164,7 +162,7 @@
for(DependencyItem item : items)
{
Object iDependOn = item.getIDependOn();
- DefaultGraphCell dependency = cells.get(iDependOn);
+ GraphCell dependency = cells.get(iDependOn);
ControllerContext dependant = null;
if (dependency == null)
{
@@ -182,14 +180,7 @@
}
ControllerState state = item.getWhenRequired();
- Edge edge = new DefaultEdge(state != null ? state.getStateString() : "UNKNOWN");
- cs.connect(edge, owner.getChildAt(0), dependency.getChildAt(0));
-
- int arrow = GraphConstants.ARROW_CLASSIC;
- GraphConstants.setLineEnd(edge.getAttributes(), arrow);
- GraphConstants.setEndFill(edge.getAttributes(), true);
- GraphConstants.setRouting(edge.getAttributes(), GrapherConstants.ROUTING);
-
+ Edge edge = factory.createEdge(state != null ? state.getStateString() : "UNKNOWN", owner, dependency, cs);
objects.add(edge);
if (dependant != null && doRecurse(dependant))
@@ -206,10 +197,10 @@
* @param context the context
* @return context's cell
*/
- protected DefaultGraphCell getCell(Map<Object, DefaultGraphCell> cells, Set<Object> objects, ControllerContext context)
+ protected GraphCell getCell(Map<Object, GraphCell> cells, Set<Object> objects, ControllerContext context)
{
Object name = context.getName();
- DefaultGraphCell cell = cells.get(name);
+ GraphCell cell = cells.get(name);
if (cell == null)
{
cell = createCell(name);
@@ -240,13 +231,14 @@
* @param cell the cell to enhance
* @param context the context to get info from
*/
- protected void enhanceCell(DefaultGraphCell cell, ControllerContext context)
+ protected void enhanceCell(GraphCell cell, ControllerContext context)
{
- // TODO - enhance cell rendering with context's info
+ factory.enhanceVertex(cell, context);
}
private class ModifiedGraphModel extends DefaultGraphModel
{
+ @SuppressWarnings({"unchecked", "deprecation"})
protected Map handleAttributes(Map attributes)
{
if (attributes != null)
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java 2009-07-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AllGraphCreator.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -28,8 +28,8 @@
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.ControllerStateModel;
import org.jboss.kernel.spi.dependency.KernelController;
-import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.ConnectionSet;
+import org.jgraph.graph.GraphCell;
/**
* Render all MC components.
@@ -38,7 +38,7 @@
*/
public class AllGraphCreator extends AbstractGraphCreator
{
- protected void createCells(KernelController controller, Map<Object, DefaultGraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
+ protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
{
ControllerStateModel model = controller.getStates();
for (ControllerState state : model)
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/BeanGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/BeanGraphCreator.java 2009-07-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/BeanGraphCreator.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -26,8 +26,8 @@
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.dependency.KernelController;
-import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.ConnectionSet;
+import org.jgraph.graph.GraphCell;
/**
* Render single bean.
@@ -46,7 +46,7 @@
this.bean = bean;
}
- protected void createCells(KernelController controller, Map<Object, DefaultGraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
+ protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
{
ControllerContext context = controller.getContext(bean, null);
if (context == null)
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-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/Colorable.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -33,5 +33,12 @@
*
* @return the color
*/
- Color color();
+ Color getColor();
+
+ /**
+ * Set the color.
+ *
+ * @param color the color
+ */
+ void setColor(Color color);
}
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-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/ColorableGraphCell.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -45,7 +45,7 @@
this.color = color;
}
- public Color color()
+ public Color getColor()
{
return color;
}
Added: 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 (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/DefaultGraphComponentFactory.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -0,0 +1,108 @@
+/*
+ * 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 java.awt.*;
+
+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;
+import org.jgraph.graph.GraphConstants;
+
+/**
+ * Create graph components.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultGraphComponentFactory implements GraphComponentFactory
+{
+ private static final GraphComponentFactory instance = new DefaultGraphComponentFactory();
+
+ private DefaultGraphComponentFactory()
+ {
+ }
+
+ public static GraphComponentFactory getInstance()
+ {
+ return instance;
+ }
+
+ /**
+ * Create vertex.
+ *
+ * @param label the vertex label
+ * @param color the vertex color
+ * @return new vertex
+ */
+ protected GraphCell createVertex(Object label, Color color)
+ {
+ DefaultGraphCell cell = new ColorableGraphCell(label, color);
+ cell.addPort();
+ return cell;
+ }
+
+ public GraphCell createVertex(Object label)
+ {
+ return createVertex(label, GrapherConstants.COLOR);
+ }
+
+ public GraphCell createVertex(ControllerContext context)
+ {
+ Color color = mapContextToColor(context);
+ return createVertex(context.getName(), color);
+ }
+
+ /**
+ * Map context to color.
+ *
+ * @param context the context
+ * @return mapped color
+ */
+ protected Color mapContextToColor(ControllerContext context)
+ {
+ return Color.BLUE; // TODO
+ }
+
+ public void enhanceVertex(GraphCell vertex, ControllerContext context)
+ {
+ Colorable colorable = Colorable.class.cast(vertex);
+ if (colorable.getColor() == GrapherConstants.COLOR)
+ colorable.setColor(mapContextToColor(context));
+ }
+
+ 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));
+
+ int arrow = GraphConstants.ARROW_CLASSIC;
+ GraphConstants.setLineEnd(edge.getAttributes(), arrow);
+ GraphConstants.setEndFill(edge.getAttributes(), true);
+ GraphConstants.setRouting(edge.getAttributes(), GrapherConstants.ROUTING);
+
+ return edge;
+ }
+}
\ No newline at end of file
Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphComponentFactory.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphComponentFactory.java (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphComponentFactory.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -0,0 +1,70 @@
+/*
+ * 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.dependency.spi.ControllerContext;
+import org.jgraph.graph.ConnectionSet;
+import org.jgraph.graph.Edge;
+import org.jgraph.graph.GraphCell;
+
+/**
+ * Create graph components.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface GraphComponentFactory
+{
+ /**
+ * Create vertex.
+ *
+ * @param label the vertex label
+ * @return new graph vertex
+ */
+ GraphCell createVertex(Object label);
+
+ /**
+ * Create vertex.
+ *
+ * @param context the context
+ * @return new graph vertex
+ */
+ GraphCell createVertex(ControllerContext context);
+
+ /**
+ * Enhance existing vertex.
+ *
+ * @param vertex the vertex to enhance
+ * @param context the controller context
+ */
+ void enhanceVertex(GraphCell vertex, ControllerContext context);
+
+ /**
+ * Create edge.
+ *
+ * @param label the edge label
+ * @param target the edge target
+ * @param source the edge source
+ * @param cs the connection set
+ * @return new edge
+ */
+ Edge createEdge(Object label, GraphCell target, GraphCell source, ConnectionSet cs);
+}
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-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/GraphSettings.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -56,7 +56,7 @@
if (obj instanceof Colorable)
{
Colorable cell = (Colorable)obj;
- attributes.put(cell, createBounds(col * 70, row * 70, cell.color()));
+ attributes.put(cell, createBounds(col * 70, row * 70, cell.getColor()));
}
if (col >= nodesperrow)
{
Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java 2009-07-10 21:05:17 UTC (rev 91119)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/TreeGraphCreator.java 2009-07-10 21:34:44 UTC (rev 91120)
@@ -21,14 +21,14 @@
*/
package org.jboss.mctools.grapher.graph;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.HashSet;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.dependency.KernelController;
-import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.ConnectionSet;
+import org.jgraph.graph.GraphCell;
/**
* Render single bean.
@@ -49,7 +49,7 @@
visited = new HashSet<Object>();
}
- protected void createCells(KernelController controller, Map<Object, DefaultGraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
+ protected void createCells(KernelController controller, Map<Object, GraphCell> cells, Set<Object> objects, Map attributes, ConnectionSet cs)
{
ControllerContext context = controller.getContext(root, null);
if (context == null)
More information about the jboss-cvs-commits
mailing list