Forums

Full Version: prefuby
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Using prefuse within JRuby - posted by simonvc in the prefuse sourceforge forum

http://sourceforge.net/forum/forum.php?t..._id=343013


Code:
puts "Ruby Powered"
require 'java'
java.lang.System.out.println "Java Loaded"

graph=Java::prefuse.data.io.GraphMLReader.new.readGraph("socialnet.xml")
vis=Java::prefuse.Visualization.new
vis.add("graph", graph)
vis.setInteractive("graph.edges", nil, false)
r=Java::prefuse.render.LabelRenderer.new("name")
r.setRoundedCorner(8,8)

dfr=Java::prefuse.render.DefaultRendererFactory(r).new
vis.setRendererFactory(dfr)

#Color stuff
red=Java::prefuse.util.ColorLib.rgb(255,180,180)
blue=Java::prefuse.util.ColorLib.rgb(190,190,255)

palette=[red, blue].to_java :int

NOMINAL=Java::prefuse.Constants::NOMINAL
FILLCOLOR=Java::prefuse.visual.VisualItem::FILLCOLOR
TEXTCOLOR=Java::prefuse.visual.VisualItem::TEXTCOLOR
STROKECOLOR=Java::prefuse.visual.VisualItem::STROKECOLOR

fill=Java::prefuse.action.assignment.DataColorAction.new("graph.nodes", "gender", NOMINAL, FILLCOLOR, palette)
text=Java::prefuse.action.assignment.ColorAction.new("graph.nodes", TEXTCOLOR, Java::prefuse.util.ColorLib.gray(0))
edges=Java::prefuse.action.assignment.ColorAction.new("graph.edges", STROKECOLOR, Java::prefuse.util.ColorLib.gray(200))

color=Java::prefuse.action.ActionList.new
color.add(fill)
color.add(text)
color.add(edges)


# Layout Stuff

Infinity=Java::prefuse.activity.Activity::INFINITY
layout=Java::prefuse.action.ActionList.new(Infinity)

layout.add Java::prefuse.action.layout.graph.ForceDirectedLayout.new("graph")
layout.add Java::prefuse.action.RepaintAction.new

vis.putAction("color", color)
vis.putAction("layout", layout)



d=Java::prefuse.Display.new(vis)
d.setSize(720, 500)
d.addControlListener Java::prefuse.controls.DragControl.new
d.addControlListener Java::prefuse.controls.PanControl.new
d.addControlListener Java::prefuse.controls.ZoomControl.new


frame=javax.swing.JFrame.new("prefuse example")
frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE)
frame.getContentPane().add(d)
frame.pack
frame.setVisible(true)

vis.run("color")
vis.run("layout")

well done
Reference URL's