Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import org.graphstream.algorithm.layout.openord.OpenOrdLayout;
- import org.graphstream.graph.Edge;
- import org.graphstream.graph.Graph;
- import org.graphstream.graph.Node;
- import org.graphstream.graph.implementations.MultiGraph;
- import org.graphstream.stream.PipeBase;
- import org.graphstream.stream.file.FileSource;
- import org.graphstream.stream.file.FileSourceFactory;
- import org.graphstream.ui.layout.springbox.implementations.SpringBox;
- import org.graphstream.ui.swingViewer.Viewer;
- public class LabelVisibility {
- public static class VisibleLink extends PipeBase {
- public void edgeAdded(String sourceId, long timeId, String edgeId,
- String source, String target, boolean directed) {
- sendNodeAdded(this.sourceId, edgeId);
- sendNodeAttributeAdded(this.sourceId, edgeId, "ui.class", "link");
- sendEdgeAdded(this.sourceId, edgeId + "_A", source, edgeId,
- directed);
- sendEdgeAdded(this.sourceId, edgeId + "_B", edgeId, target,
- directed);
- }
- public void edgeRemoved(String sourceId, long timeId, String edgeId) {
- sendNodeRemoved(this.sourceId, edgeId);
- }
- public void edgeAttributeAdded(String sourceId, long timeId,
- String edgeId, String attributeId, Object value) {
- sendNodeAttributeAdded(this.sourceId, edgeId, attributeId, value);
- if (attributeId.equals("ui.class")) {
- sendEdgeAttributeAdded(this.sourceId, edgeId + "_A",
- attributeId, value);
- sendEdgeAttributeAdded(this.sourceId, edgeId + "_B",
- attributeId, value);
- }
- }
- public void edgeAttributeChanged(String sourceId, long timeId,
- String edgeId, String attributeId, Object oldValue, Object value) {
- sendNodeAttributeChanged(this.sourceId, edgeId, attributeId,
- oldValue, value);
- if (attributeId.equals("ui.class")) {
- sendEdgeAttributeChanged(this.sourceId, edgeId + "_A",
- attributeId, oldValue, value);
- sendEdgeAttributeChanged(this.sourceId, edgeId + "_B",
- attributeId, oldValue, value);
- }
- }
- public void edgeAttributeRemoved(String sourceId, long timeId,
- String edgeId, String attributeId) {
- sendNodeAttributeRemoved(this.sourceId, edgeId, attributeId);
- }
- }
- public static void main(String[] args) {
- System.setProperty("org.graphstream.ui.renderer",
- "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
- Graph graph = new MultiGraph("__test__");
- Graph displayGraph = new MultiGraph("__test_display__");
- FileSource fs = null;
- VisibleLink vl = new VisibleLink();
- graph.addSink(vl);
- vl.addSink(displayGraph);
- try {
- fs = FileSourceFactory.sourceFor(___source___);
- fs.addSink(graph);
- fs.readAll(___source___);
- } catch (IOException e) {
- System.err.println(e.getMessage());
- } finally {
- fs.removeSink(graph);
- }
- for (Node node : graph)
- node.addAttribute("ui.label", node.getId());
- for (Edge edge : graph.getEachEdge()) {
- edge.addAttribute("ui.label", edge.getAttribute("arcvalue"));
- if (edge.getNumber("arcvalue") > 100)
- edge.addAttribute("ui.class", "biglink");
- }
- graph.addAttribute("ui.quality");
- graph.addAttribute("ui.antialias");
- graph.addAttribute("layout.gravity", 0.02);
- graph.addAttribute(
- "ui.stylesheet",
- "node {text-background-mode:plain;text-background-color:yellow;text-size:14px;text-padding:2px;} "
- + "node.link {text-background-mode:plain;text-background-color:orange;text-size:11px;} "
- + "node.biglink {text-background-color:red;text-size:11px;} "
- + "edge {fill-color:gray;}"
- + "edge.biglink {size:4px; fill-color:black;}");
- Viewer v = displayGraph.display(false);
- SpringBox l = new SpringBox();
- v.enableAutoLayout(l);
- l.shake();
- }
- }
Add Comment
Please, Sign In to add comment