use of edu.uci.ics.jung.visualization.control.ScalingControl in project tdq-studio-se by Talend.
the class JungGraphGenerator method createToolControllers.
/**
* DOC bZhou Comment method "createToolControllers".
*
* @param vv
* @return
*/
private JPanel createToolControllers(final VisualizationViewer vv) {
final GraphMouse graphMouse = new DefaultModalGraphMouse();
vv.setGraphMouse(graphMouse);
JPanel pSlider = createSlider();
JCheckBox inverse = createInverseCheck(vv);
ScalingControl scaler = new CrossoverScalingControl();
JButton plus = createPlusScaler(vv, scaler);
JButton minus = createMinusScaler(vv, scaler);
JButton reset = createResetBTN(vv);
// set mode seleciton box
JCheckBox checkBox = createModeSwitcher(graphMouse);
final PersistentLayout pl = (PersistentLayout) vv.getGraphLayout();
JButton persist = createPersistBTN(pl, PERSIST_LAYOUT_FILE_NAME);
JButton restore = createRestoreBTN(vv, pl, PERSIST_LAYOUT_FILE_NAME);
JPanel jp2 = new JPanel();
jp2.setLayout(new java.awt.GridLayout(2, 1));
jp2.add(inverse);
jp2.add(checkBox);
JPanel jp3 = new JPanel();
jp3.setLayout(new java.awt.GridLayout(2, 1));
jp3.add(persist);
jp3.add(restore);
JPanel controls = new JPanel();
controls.add(pSlider);
controls.add(plus);
controls.add(minus);
controls.add(reset);
controls.add(jp2);
controls.add(jp3);
return controls;
}
use of edu.uci.ics.jung.visualization.control.ScalingControl 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.control.ScalingControl in project tdq-studio-se by Talend.
the class MyFullDemoMain method addBottomControls.
// /**
// * Generates a mixed-mode random graph, runs VoltageRanker on it, and returns the resultant graph.
// */
// public Graph getGraph() {
// Graph g = TestGraphs.generateMixedRandomGraph(edge_weight, 20, false);
// vs = new NumberVertexValueStringer(voltages);
// es = new NumberEdgeValueStringer(edge_weight);
//
// // collect the seeds used to define the random graph
// Collection seeds = PredicateUtils.getVertices(g, new
// ContainsUserDataKeyVertexPredicate(BarabasiAlbertGenerator.SEED));
// if (seeds.size() < 2)
// System.out.println("need at least 2 seeds (one source, one sink)");
//
// // use these seeds as source and sink vertices, run VoltageRanker
// boolean source = true;
// Set sources = new HashSet();
// Set sinks = new HashSet();
// for (Iterator iter = seeds.iterator(); iter.hasNext();) {
// if (source)
// sources.add(iter.next());
// else
// sinks.add(iter.next());
// source = !source;
// }
// VoltageRanker vr = new VoltageRanker(edge_weight, voltages, 100, 0.01);
// vr.calculateVoltages(g, sources, sinks);
//
// Set verts = g.getVertices();
//
// // assign a transparency value of 0.9 to all vertices
// for (Iterator iter = verts.iterator(); iter.hasNext();) {
// Vertex v = (Vertex) iter.next();
// transparency.setNumber(v, new MutableDouble(0.9));
// }
//
// // add a couple of self-loops (sanity check on rendering)
// Vertex v = (Vertex) verts.iterator().next();
// Edge e = new DirectedSparseEdge(v, v);
// edge_weight.setNumber(e, new Double(Math.random()));
// g.addEdge(e);
// e = new UndirectedSparseEdge(v, v);
// edge_weight.setNumber(e, new Double(Math.random()));
// g.addEdge(e);
// return g;
// }
/**
* @param jp panel to which controls will be added
*/
protected void addBottomControls(final JPanel jp) {
final JPanel control_panel = new JPanel();
jp.add(control_panel, BorderLayout.SOUTH);
control_panel.setLayout(new BorderLayout());
final Box vertex_panel = Box.createVerticalBox();
vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices"));
final Box edge_panel = Box.createVerticalBox();
edge_panel.setBorder(BorderFactory.createTitledBorder("Edges"));
final Box both_panel = Box.createVerticalBox();
control_panel.add(vertex_panel, BorderLayout.WEST);
control_panel.add(edge_panel, BorderLayout.EAST);
control_panel.add(both_panel, BorderLayout.CENTER);
// set up vertex controls
v_color = new JCheckBox("vertex seed coloring");
v_color.addActionListener(this);
v_stroke = new JCheckBox("<html>vertex selection<p>stroke highlighting</html>");
v_stroke.addActionListener(this);
v_labels = new JCheckBox("show vertex ranks (voltages)");
v_labels.addActionListener(this);
v_shape = new JCheckBox("vertex degree shapes");
v_shape.addActionListener(this);
v_size = new JCheckBox("vertex voltage size");
v_size.addActionListener(this);
v_size.setSelected(true);
v_aspect = new JCheckBox("vertex degree ratio stretch");
v_aspect.addActionListener(this);
v_small = new JCheckBox("filter vertices of degree < " + VertexDisplayPredicate.DEFAULT_DEGREE);
v_small.addActionListener(this);
vertex_panel.add(v_color);
vertex_panel.add(v_stroke);
vertex_panel.add(v_labels);
vertex_panel.add(v_shape);
vertex_panel.add(v_size);
vertex_panel.add(v_aspect);
vertex_panel.add(v_small);
// set up edge controls
JPanel gradient_panel = new JPanel(new GridLayout(1, 0));
gradient_panel.setBorder(BorderFactory.createTitledBorder("Edge paint"));
no_gradient = new JRadioButton("Solid color");
no_gradient.addActionListener(this);
no_gradient.setSelected(true);
// gradient_absolute = new JRadioButton("Absolute gradient");
// gradient_absolute.addActionListener(this);
gradient_relative = new JRadioButton("Gradient");
gradient_relative.addActionListener(this);
ButtonGroup bg_grad = new ButtonGroup();
bg_grad.add(no_gradient);
bg_grad.add(gradient_relative);
// bg_grad.add(gradient_absolute);
gradient_panel.add(no_gradient);
// gradientGrid.add(gradient_absolute);
gradient_panel.add(gradient_relative);
JPanel shape_panel = new JPanel(new GridLayout(3, 2));
shape_panel.setBorder(BorderFactory.createTitledBorder("Edge shape"));
e_line = new JRadioButton("line");
e_line.addActionListener(this);
e_line.setSelected(true);
// e_bent = new JRadioButton("bent line");
// e_bent.addActionListener(this);
e_wedge = new JRadioButton("wedge");
e_wedge.addActionListener(this);
e_quad = new JRadioButton("quad curve");
e_quad.addActionListener(this);
e_cubic = new JRadioButton("cubic curve");
e_cubic.addActionListener(this);
ButtonGroup bg_shape = new ButtonGroup();
bg_shape.add(e_line);
// bg.add(e_bent);
bg_shape.add(e_wedge);
bg_shape.add(e_quad);
bg_shape.add(e_cubic);
shape_panel.add(e_line);
// shape_panel.add(e_bent);
shape_panel.add(e_wedge);
shape_panel.add(e_quad);
shape_panel.add(e_cubic);
fill_edges = new JCheckBox("fill edge shapes");
fill_edges.setSelected(false);
fill_edges.addActionListener(this);
shape_panel.add(fill_edges);
shape_panel.setOpaque(true);
e_color = new JCheckBox("edge weight highlighting");
e_color.addActionListener(this);
e_labels = new JCheckBox("show edge weights");
e_labels.addActionListener(this);
e_uarrow_pred = new JCheckBox("undirected");
e_uarrow_pred.addActionListener(this);
e_darrow_pred = new JCheckBox("directed");
e_darrow_pred.addActionListener(this);
e_darrow_pred.setSelected(true);
JPanel arrow_panel = new JPanel(new GridLayout(1, 0));
arrow_panel.setBorder(BorderFactory.createTitledBorder("Show arrows"));
arrow_panel.add(e_uarrow_pred);
arrow_panel.add(e_darrow_pred);
e_show_d = new JCheckBox("directed");
e_show_d.addActionListener(this);
e_show_d.setSelected(true);
e_show_u = new JCheckBox("undirected");
e_show_u.addActionListener(this);
e_show_u.setSelected(true);
JPanel show_edge_panel = new JPanel(new GridLayout(1, 0));
show_edge_panel.setBorder(BorderFactory.createTitledBorder("Show edges"));
show_edge_panel.add(e_show_u);
show_edge_panel.add(e_show_d);
shape_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
edge_panel.add(shape_panel);
gradient_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
edge_panel.add(gradient_panel);
show_edge_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
edge_panel.add(show_edge_panel);
arrow_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
edge_panel.add(arrow_panel);
e_color.setAlignmentX(Component.LEFT_ALIGNMENT);
edge_panel.add(e_color);
e_labels.setAlignmentX(Component.LEFT_ALIGNMENT);
edge_panel.add(e_labels);
// set up zoom controls
zoom_at_mouse = new JCheckBox("<html><center>zoom at mouse<p>(wheel only)</center></html>");
zoom_at_mouse.addActionListener(this);
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());
}
});
Box zoomPanel = Box.createVerticalBox();
zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom"));
plus.setAlignmentX(Component.CENTER_ALIGNMENT);
zoomPanel.add(plus);
minus.setAlignmentX(Component.CENTER_ALIGNMENT);
zoomPanel.add(minus);
zoom_at_mouse.setAlignmentX(Component.CENTER_ALIGNMENT);
zoomPanel.add(zoom_at_mouse);
// add font and zoom controls to center panel
font = new JCheckBox("bold text");
font.addActionListener(this);
font.setAlignmentX(Component.CENTER_ALIGNMENT);
both_panel.add(zoomPanel);
both_panel.add(font);
JComboBox modeBox = gm.getModeComboBox();
modeBox.setAlignmentX(Component.CENTER_ALIGNMENT);
JPanel modePanel = new JPanel(new BorderLayout()) {
public Dimension getMaximumSize() {
return getPreferredSize();
}
};
modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
modePanel.add(modeBox);
both_panel.add(modePanel);
}
use of edu.uci.ics.jung.visualization.control.ScalingControl in project titan.EclipsePlug-ins by eclipse.
the class CustomSatelliteViewer method changeSize.
/**
* This method sets a new size for the view, it does also the needed
* zooming.
*
* @param size
* : The size to set
*/
public void changeSize(final Dimension size) {
setPreferredSize(size);
final ScalingControl scaler = new CrossoverScalingControl();
scaler.scale(this, (float) (1.0f / actZoom), new Point2D.Double());
scaleToLayout(new CrossoverScalingControl());
setSize(size);
}
use of edu.uci.ics.jung.visualization.control.ScalingControl in project tdq-studio-se by Talend.
the class JungGraphGenerator method createSatelliteDialog.
/**
* DOC bZhou Comment method "createSatelliteView".
*
* @param vv
* @param sv
* @return
*/
private JFrame createSatelliteDialog(final VisualizationViewer vv, VisualizationViewer sv) {
final JFrame dialog = new JFrame();
// $NON-NLS-1$
dialog.setTitle(DefaultMessagesImpl.getString("JungGraphGenerator.Satellite"));
ScalingControl scaler = new CrossoverScalingControl();
JButton plus = createPlusScaler(vv, scaler);
JButton minus = createMinusScaler(vv, scaler);
JButton reset = createResetBTN(vv);
JButton help = createHelpBTN();
JPanel controls = new JPanel(new java.awt.GridLayout(2, 2));
controls.add(plus);
controls.add(minus);
controls.add(reset);
controls.add(help);
dialog.add(sv);
dialog.add(controls, BorderLayout.SOUTH);
return dialog;
}
Aggregations