[graphl-cvs] graphl/src/org/mediavirus/graphl/view GraphFacetRegistry.java LabelGenerator.java Simpl
Status: Pre-Alpha
Brought to you by:
flo1
From: Flo L. <fl...@us...> - 2004-08-20 12:39:07
|
Update of /cvsroot/graphl/graphl/src/org/mediavirus/graphl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25631/src/org/mediavirus/graphl/view Modified Files: LabelGenerator.java SimpleFacetRegistry.java AbstractFacet.java Facet.java Added Files: GraphFacetRegistry.java Log Message: added basic infrastructure to configure Facets from an RDF graph. work in progress... Index: SimpleFacetRegistry.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/view/SimpleFacetRegistry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SimpleFacetRegistry.java 2 Aug 2004 12:36:31 -0000 1.1 --- SimpleFacetRegistry.java 20 Aug 2004 12:38:52 -0000 1.2 *************** *** 5,9 **** package org.mediavirus.graphl.view; - import java.util.Collections; import java.util.Hashtable; import java.util.Iterator; --- 5,8 ---- Index: Facet.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/view/Facet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Facet.java 2 Aug 2004 12:36:31 -0000 1.1 --- Facet.java 20 Aug 2004 12:38:52 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- import org.mediavirus.graphl.graph.GraphElement; + import org.mediavirus.graphl.graph.Node; *************** *** 19,36 **** public interface Facet extends Cloneable { ! public boolean hasVisualController(); public JComponent getVisualController(); public String getName(); public boolean isSameClass(Object o); public Object clone(); public Set getAssignedElements(); public void assignElement(GraphElement element); public void unassignElement(GraphElement element); } \ No newline at end of file --- 20,86 ---- public interface Facet extends Cloneable { ! /** ! * Indicated whether this Facet has a GUI component for end-user control of its properties. ! * @return true if a GUI component exists. In this case, getVisualController() returns the ! * Component. false is no such component has been defined. ! */ ! public boolean hasVisualController(); + /** + * Returns a JComponent to be used for end-user control of this facet's proprties, or null if + * no such component exists. + * @returna A JComponent to be used for end-user control of this facet's proprties, or null if + * no such component exists. + */ public JComponent getVisualController(); + /** + * Returns the human-readable name of this facet. This can be used to display a label for this facet. + * @return The human-readable name for this facet. + */ public String getName(); + /** + * Compares this instance to another facet, testing if the classes are identical. + * @param o The Object that this facet should be compared to. + * @return true if this facet's class matches the class of the Object. false otherwise. + */ public boolean isSameClass(Object o); + /** + * Creates an identical copy of this facet instance. + * @return A clone of this facet. + */ public Object clone(); + /** + * Retrieves the GraphElements (Nodes or Edges) this facet is currently assigned to. + * @return A Set of GraphElements that are assigned to this facet. + */ public Set getAssignedElements(); + /** + * Adds a GraphElement to the Set of assigned elements. This should only be used for caching, + * otherwise facets should be assigned through the FacetRegistry. + * @param element The GraphElement (Node or Edge) to add to the assigned elements cache. + */ public void assignElement(GraphElement element); + /** + * Removes a GraphElement from the Set of assigned elements. This should only be used for caching, + * otherwise facets should be assigned through the FacetRegistry. + * @param element The GraphElement (Node or Edge) to remove from the assigned elements cache. + */ public void unassignElement(GraphElement element); + + /** + * Set a Node that carries configuration information for this facet. Depending on the implementation, + * the facet will use the node and its properties to set up its own properties. This + * is used by the GraphFacetRegistry to dynamically instantiate Facets from a configuration + * graph. + * @param node The Node that carries the configuration information for this facet (Usually + * of type "http://www.mediavirus.org/graphl#Facet". + */ + public void setConfigurationNode(Node node); + } \ No newline at end of file --- NEW FILE: GraphFacetRegistry.java --- /* * Created on 07.08.2004 by flo */ package org.mediavirus.graphl.view; import java.util.Collection; import java.util.Iterator; import org.mediavirus.graphl.graph.Graph; import org.mediavirus.graphl.graph.GraphListener; import org.mediavirus.graphl.graph.Node; import org.mediavirus.graphl.layout.EdgeLayouter; import org.mediavirus.graphl.layout.NodeLayouter; import org.mediavirus.graphl.painter.EdgePainter; import org.mediavirus.graphl.painter.NodePainter; /** * @author flo * created: 07.08.2004 22:10:50 */ public class GraphFacetRegistry extends SimpleFacetRegistry implements GraphListener { Graph registryGraph = null; public GraphFacetRegistry(Graph graph) { setRegistryGraph(graph); } public void setRegistryGraph(Graph graph) { this.registryGraph = graph; registryGraph.addGraphListener(this); graphContentsChanged(registryGraph); } public void graphLayoutUpdated(Graph graph) { //empty } public void graphUpdated(Graph graph) { //empty } public void graphContentsChanged(Graph graph) { Iterator nodes = graph.getNodes().iterator(); while (nodes.hasNext()) { Node node = (Node) nodes.next(); if (node.getType().equals("http://www.mediavirus.org/graphl#NodePainter")) { NodePainter nodePainter = (NodePainter)getFacetInstance(node); } else if (node.getType().equals("http://www.mediavirus.org/graphl#NodeLayouter")) { NodeLayouter nodeLayouter = (NodeLayouter)getFacetInstance(node); } else if (node.getType().equals("http://www.mediavirus.org/graphl#EdgePainter")) { EdgePainter edgePainter = (EdgePainter)getFacetInstance(node); } else if (node.getType().equals("http://www.mediavirus.org/graphl#EdgeLayouter")) { EdgeLayouter edgeLayouter = (EdgeLayouter)getFacetInstance(node); } } } private Facet getFacetInstance(Node facetNode) { String type = facetNode.getProperty("http://www.mediavirus.org/graphl#javaClass"); try { if (type != null) { Class facetClass = Class.forName(type); if (facetClass != null) { Object o = facetClass.newInstance(); if (o instanceof Facet) { Facet facet = (Facet)o; facet.setConfigurationNode(facetNode); return facet; } } else { System.err.println("Class not found: " + type); } } } catch (Exception e) { System.err.println("Problem instantiating facet: " + e.getMessage()); } return null; } public void elementsAdded(Graph graph, Collection nodes, Collection edges) { // TODO Auto-generated method stub } public void elementsRemoved(Graph graph, Collection nodes, Collection edges) { // TODO Auto-generated method stub } } Index: LabelGenerator.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/view/LabelGenerator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** LabelGenerator.java 12 Jul 2004 11:48:51 -0000 1.3 --- LabelGenerator.java 20 Aug 2004 12:38:52 -0000 1.4 *************** *** 269,271 **** --- 269,314 ---- } } + + /** + * @param to + */ + public void setConfigurationNode(Node node) { + Node listNode = null; + + listNode = node.getFirstNeighbour("http://www.mediavirus.org/graphl#labelFacets", true); + if (listNode != null) { + facets.clear(); + } + + while (listNode != null && !listNode.getValue().equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil")) { + Node labelFacetNode = listNode.getFirstNeighbour("http://www.w3.org/1999/02/22-rdf-syntax-ns#first", true); + if (labelFacetNode != null) { + String data = labelFacetNode.getProperty("http://www.mediavirus.org/graphl#labelFacetValue"); + int type = STRING; + String str = labelFacetNode.getProperty("http://www.mediavirus.org/graphl#labelFacetType"); + if (str != null) { + if (str.equalsIgnoreCase("value")) { + type = VALUE; + } + else if (str.equalsIgnoreCase("type")) { + type = TYPE; + } + else if (str.equalsIgnoreCase("property")) { + type = PROPERTY; + } + else if (str.equalsIgnoreCase("neighbour")) { + type = NEIGHBOUR; + } + } + boolean guessName = false; + str = labelFacetNode.getProperty("http://www.mediavirus.org/graphl#guessName"); + if (str != null && str.equalsIgnoreCase("true")) guessName = true; + LabelFacet labelFacet = new LabelFacet(type,data,guessName); + facets.add(labelFacet); + } + + listNode = listNode.getFirstNeighbour("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest", true); + } + + } } Index: AbstractFacet.java =================================================================== RCS file: /cvsroot/graphl/graphl/src/org/mediavirus/graphl/view/AbstractFacet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractFacet.java 2 Aug 2004 12:36:31 -0000 1.2 --- AbstractFacet.java 20 Aug 2004 12:38:52 -0000 1.3 *************** *** 5,13 **** package org.mediavirus.graphl.view; - import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.mediavirus.graphl.graph.GraphElement; /** --- 5,13 ---- package org.mediavirus.graphl.view; import java.util.HashSet; import java.util.Set; import org.mediavirus.graphl.graph.GraphElement; + import org.mediavirus.graphl.graph.Node; /** *************** *** 47,50 **** return getName(); } ! } --- 47,59 ---- return getName(); } ! ! /* ! * Overrides @see org.mediavirus.graphl.view.Facet#setConfigurationNode(org.mediavirus.graphl.graph.Node) ! */ ! public void setConfigurationNode(Node node) { ! // do nothing per default. ! ! // TODO (2) either implement a generic property mechanism here, or implement his method in all subclasses ! // (it should then be removed here). ! } } |