use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project tdq-studio-se by Talend.
the class JungGraphGenerator method generate.
public Composite generate(Composite parent, boolean isWithHelp) {
Composite frameComp = createAWTSWTComposite(parent);
frame = SWT_AWT.new_Frame(frameComp);
// $NON-NLS-1$
frame.setTitle(DefaultMessagesImpl.getString("JungGraphGenerator.NominalAnalysis"));
pr = new LineRender(graphbuilder);
sr = new LineRender(graphbuilder);
PersistentLayout layout = new PersistentLayoutImpl(new ISOMLayout(graph));
VisualizationModel vm = new DefaultVisualizationModel(layout);
vv = new VisualizationViewer(vm, pr);
sv = new SatelliteVisualizationViewer(vv, vm, sr, new Dimension(200, 200));
configureVViewer(vv);
// create contollers
JPanel controllers = createToolControllers(vv);
// MOD yyi 2009-09-09 feature 8834
if (this.isPreview)
controllers.setVisible(false);
JPanel panel = new GraphZoomScrollPane(vv);
if (isWithHelp) {
helpDialog = createSatelliteDialog(vv, sv);
controllers.add(createShowSatelliteCheck(helpDialog));
}
frame.add(panel);
frame.add(controllers, BorderLayout.SOUTH);
frame.validate();
addListeners();
return frameComp;
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project tdq-studio-se by Talend.
the class MyFirstMain method run.
public void run(final GraphBuilder graphbuilder) {
Graph graph = graphbuilder.createMultiGraph(allData);
PluggableRenderer pr = new PluggableRenderer();
vv = new VisualizationViewer(new FRLayout(graph), pr);
// vv = new VisualizationViewer(new CircleLayout(graph), pr);
// vv = new VisualizationViewer(new SpringLayout(graph), pr);
// vv = new VisualizationViewer(new KKLayout(graph), pr);
vv.setBackground(Color.white);
vv.setPickSupport(new ShapePickSupport());
pr.setEdgeShapeFunction(new EdgeShape.Line());
vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
int x;
int y;
Font font;
FontMetrics metrics;
int swidth;
int sheight;
String str = "My first Demo";
public void paint(Graphics g) {
Dimension d = vv.getSize();
if (font == null) {
font = new Font(g.getFont().getName(), Font.BOLD, 30);
metrics = g.getFontMetrics(font);
swidth = metrics.stringWidth(str);
sheight = metrics.getMaxAscent() + metrics.getMaxDescent();
x = (d.width - swidth) / 2;
y = (int) (d.height - sheight * 1.5);
}
g.setFont(font);
Color oldColor = g.getColor();
g.setColor(Color.DARK_GRAY);
g.drawString(str, x, y);
g.setColor(oldColor);
}
public boolean useTransform() {
return false;
}
});
pr.setVertexPaintFunction(new VertexPaintFunction() {
public Paint getFillPaint(Vertex v) {
final Object userDatum = v.getUserDatum(GraphBuilder.COLUMN_IDX_KEY);
if (userDatum != null) {
Integer colIndex = (Integer) userDatum;
return AWTColorUtils.getColor(colIndex);
}
return null;
}
public Paint getDrawPaint(Vertex v) {
return Color.BLACK;
}
});
pr.setVertexStringer(new VertexStringer() {
public String getLabel(ArchetypeVertex v) {
final Object userDatum = v.getUserDatum(GraphBuilder.V_LABEL_KEY);
if (userDatum != null) {
return (String) userDatum;
}
return null;
}
});
pr.setEdgeStrokeFunction(new EdgeStrokeFunction() {
public Stroke getStroke(Edge e) {
Integer weight = graphbuilder.getEdgeWeight().getNumber(e).intValue();
// return new BasicStroke(10 * weight / graphbuilder.getTotalWeight());
return new BasicStroke(10.0f / weight);
}
});
pr.setEdgePaintFunction(new EdgePaintFunction() {
public Paint getFillPaint(Edge e) {
return null;
}
public Paint getDrawPaint(Edge e) {
return getInternalPaint(e);
}
private Paint getInternalPaint(Edge e) {
final Object userDatum = e.getUserDatum(GraphBuilder.E_ROWNUM_KEY);
if (userDatum != null) {
Integer color = (Integer) userDatum;
return AWTColorUtils.getColor(color);
}
return Color.GRAY;
}
});
pr.setEdgeStringer(new EdgeStringer() {
public String getLabel(ArchetypeEdge arg0) {
return String.valueOf(graphbuilder.getEdgeWeight().getNumber(arg0));
// final Object userDatum = arg0.getUserDatum(GraphBuilder.E_LABEL_KEY);
// if (userDatum != null) {
// return (String) userDatum;
// }
// return null;
}
});
// vv.addGraphMouseListener(new TestGraphMouseListener());
// add my listener for ToolTips
vv.setToolTipFunction(new DefaultToolTipFunction());
// create a frome to hold the graph
final JFrame frame = new JFrame();
Container content = frame.getContentPane();
final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
content.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final GraphMouse graphMouse = new DefaultModalGraphMouse();
vv.setGraphMouse(graphMouse);
JMenuBar menu = new JMenuBar();
menu.add(((DefaultModalGraphMouse) graphMouse).getModeMenu());
panel.setCorner(menu);
final ScalingControl scaler = new CrossoverScalingControl();
JButton plus = new JButton("+");
plus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scaler.scale(vv, 1.1f, vv.getCenter());
}
});
JButton minus = new JButton("-");
minus.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scaler.scale(vv, 1 / 1.1f, vv.getCenter());
}
});
JButton reset = new JButton("reset");
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
vv.getLayoutTransformer().setToIdentity();
vv.getViewTransformer().setToIdentity();
}
});
JPanel controls = new JPanel();
controls.add(plus);
controls.add(minus);
controls.add(reset);
content.add(controls, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project tdq-studio-se by Talend.
the class MyFullDemoMain method startFunction.
public JPanel startFunction() {
final GraphBuilder graphBuilder = new GraphBuilder();
// getGraph();
Graph g = graphBuilder.createMultiGraph(MyFirstMain.createListObjects());
// init variables
edge_weight = graphBuilder.getEdgeWeight();
vertexWeights = graphBuilder.getVertexWeight();
final GraphRenderer graphRenderer = new GraphRenderer();
// pr = graphRenderer.createPluggableRenderer();
pr = new PluggableRenderer();
Layout layout = new FRLayout(g);
vv = new VisualizationViewer(layout, pr);
// add Shape based pick support
vv.setPickSupport(new ShapePickSupport());
PickedState picked_state = vv.getPickedState();
affineTransformer = vv.getLayoutTransformer();
// create decorators
vcf = new SeedColor(picked_state);
ewcs = new EdgeWeightStrokeFunction(edge_weight);
vsh = new VertexStrokeHighlight(picked_state);
ff = new FontHandler();
vs_none = new ConstantVertexStringer(null);
es_none = new ConstantEdgeStringer(null);
vssa = new VertexShapeSizeAspect(vertexWeights);
show_edge = new DirectionDisplayPredicate(true, true);
show_arrow = new DirectionDisplayPredicate(true, false);
show_vertex = new VertexDisplayPredicate(false);
// uses a gradient edge if unpicked, otherwise uses picked selection
edgePaint = new GradientPickedEdgePaintFunction(new PickableEdgePaintFunction(picked_state, Color.black, Color.cyan), vv, vv, picked_state);
pr.setVertexPaintFunction(vcf);
pr.setVertexStrokeFunction(vsh);
pr.setVertexStringer(vs_none);
pr.setVertexFontFunction(ff);
pr.setVertexShapeFunction(vssa);
pr.setVertexIncludePredicate(show_vertex);
pr.setEdgePaintFunction(edgePaint);
pr.setEdgeStringer(es_none);
pr.setEdgeFontFunction(ff);
pr.setEdgeStrokeFunction(ewcs);
pr.setEdgeIncludePredicate(show_edge);
pr.setEdgeShapeFunction(new EdgeShape.Line());
pr.setEdgeArrowPredicate(show_arrow);
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
vv.setBackground(Color.white);
GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(vv);
jp.add(scrollPane);
gm = new DefaultModalGraphMouse();
vv.setGraphMouse(gm);
gm.add(new PopupGraphMousePlugin());
addBottomControls(jp);
vssa.setScaling(true);
vv.setToolTipFunction(new VoltageTips());
vv.setToolTipText("<html><center>Use the mouse wheel to zoom<p>Click and Drag the mouse to pan<p>Shift-click and Drag to Rotate</center></html>");
return jp;
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.
the class Transform method doView.
// public JComponent lowerComp() throws FQLException {
// JComponent c = src.thesig.pretty();
// c.setMaximumSize(new Dimension(400,100));
// return c;
// }
/*
* public JComponent lowerComp(String s, String d) { int size =
* src.thesig.nodes.size();
*
* // JPanel pan = new JPanel(new GridLayout(1, size + 1)); // for (Node n :
* src.thesig.nodes) { // JLabel l = new JLabel(n.string); //
* l.setOpaque(true); // l.setHorizontalAlignment(SwingConstants.CENTER); //
* l.setBackground(sColor); // pan.add(l); // }
*
* //JPanel xxx = new JPanel(); // xxx.add(new JLabel(" ")); //JPanel yu =
* new MyLabel2(); // yu.setSize(20, 12); //xxx.add(new MyLabel2()); //
* xxx.add(new JLabel(s + " (source)")); // xxx.add(new JLabel(" ")); //
* JPanel uy = new MyLabel(); // uy.setSize(20,20); // xxx.add(uy); //
* xxx.add(new JLabel(d + " (target)")); // pan.add(xxx); // pan.set
* JScrollPane p = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER,
* JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
*
* pan.setBorder(BorderFactory.createTitledBorder(
* BorderFactory.createEmptyBorder(2, 2, 2, 2), "Legend"));
* p.setViewportView(pan); return p; }
*/
@SuppressWarnings("unchecked")
private static JPanel doView(Color scolor, Color tcolor, @SuppressWarnings("unused") String src_n, @SuppressWarnings("unused") String dst_n, Graph<Quad<Node, Object, String, Boolean>, Pair<Path, Integer>> first, Map<Quad<Node, Object, String, Boolean>, Map<Attribute<Node>, Object>> second) {
// HashMap<Pair<Node, Object>,String> map = new HashMap<>();
JPanel cards = new JPanel(new CardLayout());
try {
Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.trans_graph);
Constructor<?> x = c.getConstructor(Graph.class);
Layout<Quad<Node, Object, String, Boolean>, Pair<Path, Integer>> layout = (Layout<Quad<Node, Object, String, Boolean>, Pair<Path, Integer>>) x.newInstance(first);
layout.setSize(new Dimension(600, 350));
VisualizationViewer<Quad<Node, Object, String, Boolean>, Pair<Path, Integer>> vv = new VisualizationViewer<>(layout);
Function<Quad<Node, Object, String, Boolean>, Paint> vertexPaint = (Quad<Node, Object, String, Boolean> i) -> i.fourth ? scolor : tcolor;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
// Set up a new stroke Transformer for the edges
float[] dash = { 1.0f };
Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
// Function<String, Stroke> edgeStrokeTransformer = new
// Function<String, Stroke>() {
// public Stroke transform(String s) {
// return edgeStroke;
// }
// };
vv.getRenderContext().setVertexLabelRenderer(new MyVertexT(cards));
Stroke bs = new BasicStroke();
Function<Pair<Path, Integer>, Stroke> edgeStrokeTransformer = (Pair<Path, Integer> s) -> (s.first == null) ? edgeStroke : bs;
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
// vv.getRenderContext().setVertexLabelTransformer(
// new ToStringLabeller());
vv.getRenderContext().setEdgeLabelTransformer((Pair<Path, Integer> t) -> (t.first == null) ? "" : t.first.toString());
// new ToStringLabeller());
// vv.getRenderer().getVertexRenderer().
// vv.getRenderContext().setLabelOffset(20);
// vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
vv.getRenderContext().setVertexLabelTransformer((Quad<Node, Object, String, Boolean> t) -> t.third + "." + t.first + "." + t.second);
// vv.getRenderer().setVertexRenderer(new MyRenderer());
JPanel ret = new JPanel(new BorderLayout());
JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
for (Quad<Node, Object, String, Boolean> n : first.getVertices()) {
Map<Attribute<Node>, Object> s = second.get(n);
Object[] columnNames = new Object[s.keySet().size()];
Object[][] rowData = new Object[1][s.keySet().size()];
int i = 0;
// Map<Attribute<Node>, Object> v = ma;
for (Attribute<Node> a : s.keySet()) {
columnNames[i] = a.name;
rowData[0][i] = s.get(a);
i++;
}
// }
JPanel p = new JPanel(new GridLayout(1, 1));
@SuppressWarnings("serial") JTable table = new JTable(rowData, columnNames) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = getPreferredSize();
return new Dimension(d.width, d.height);
}
};
JScrollPane jsp = new JScrollPane(table);
p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Attributes for " + n.second));
p.add(jsp);
cards.add(p, n.second.toString());
}
cards.add(new JPanel(), "blank");
CardLayout cl = (CardLayout) (cards.getLayout());
cl.show(cards, "blank");
pane.add(new GraphZoomScrollPane(vv));
pane.setResizeWeight(1.0d);
pane.add(cards);
cards.setPreferredSize(new Dimension(400, 100));
ret.add(pane, BorderLayout.CENTER);
// JComponent iii = lowerComp(src_n, dst_n);
// iii.setPreferredSize(new Dimension(1, 60));
// ret.add(iii, BorderLayout.NORTH);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException();
}
}
use of edu.uci.ics.jung.visualization.GraphZoomScrollPane in project fql by CategoricalData.
the class FqlppDisplay method doFNView.
@SuppressWarnings("unchecked")
private <X, Y> JComponent doFNView(Functor fn, JPanel p, Color clr, Graph<X, Y> sgv) {
Layout<X, Y> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<X, Y> vv = new VisualizationViewer<>(layout);
Function<X, Paint> vertexPaint = z -> clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function fff = arg0 -> Util.nice(arg0.toString());
vv.getRenderContext().setVertexLabelTransformer(fff);
vv.getRenderContext().setEdgeLabelTransformer(fff);
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
X str = ((X) e.getItem());
Object y = fn.applyO(str);
p.removeAll();
if (y instanceof Category) {
Category ttt = (Category) y;
JPanel sss = showCat(ttt, getColor(ttt));
p.add(sss);
} else if (y instanceof Set) {
Set ttt = (Set) y;
JPanel sss = showSet(ttt, getColor(ttt));
p.add(sss);
} else if (y instanceof Functor) {
Functor ttt = (Functor) y;
JPanel sss = showFtr(ttt, getColor(ttt), null);
p.add(sss);
} else {
String sss = Util.nice(y.toString());
p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
}
p.revalidate();
});
vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedVertexState().clear();
X str = ((X) e.getItem());
Object y = fn.applyA(str);
p.removeAll();
if (y instanceof Functor) {
Functor ttt = (Functor) y;
JPanel sss = showFtr(ttt, getColor(ttt.source), null);
p.add(sss);
} else if (y instanceof Fn) {
Fn ttt = (Fn) y;
JPanel sss = showFn(ttt, getColor(ttt.source), getColor(ttt.target));
p.add(sss);
} else if (y instanceof Transform) {
Transform ttt = (Transform) y;
JPanel sss = showTrans(ttt, getColor(ttt.source));
p.add(sss);
} else {
String sss = Util.nice(y.toString());
p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
}
p.revalidate();
});
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
Aggregations