use of edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse in project fql by CategoricalData.
the class SqlViewer method makeUI.
private void makeUI() {
if (graph.getVertexCount() == 0) {
top = new JPanel();
return;
}
Layout<Chc<SqlType, SqlTable>, Chc<SqlColumn, SqlForeignKey>> layout = new FRLayout<>(graph);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Chc<SqlType, SqlTable>, Chc<SqlColumn, SqlForeignKey>> vv = new VisualizationViewer<>(layout);
Function<Chc<SqlType, SqlTable>, Paint> vertexPaint = x -> x.left ? UIManager.getColor("Panel.background") : color;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<Chc<SqlType, SqlTable>, String> vt = x -> x.left ? x.l.name : x.r.name;
Function<Chc<SqlColumn, SqlForeignKey>, String> et = x -> x.left ? x.l.name : "";
vv.getRenderContext().setVertexLabelTransformer(vt);
vv.getRenderContext().setEdgeLabelTransformer(et);
top = new GraphZoomScrollPane(vv);
if (inst == null) {
return;
}
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
@SuppressWarnings("unchecked") Chc<SqlType, SqlTable> x1 = (Chc<SqlType, SqlTable>) e.getItem();
if (x1.left) {
return;
}
cards.show(bottom, x1.r.name);
});
}
use of edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse in project tdq-studio-se by Talend.
the class JungGraphGenerator method createModeSwitcher.
/**
* DOC bZhou Comment method "createModeSwitcher".
*
* @param graphMouse
* @return
*/
private JCheckBox createModeSwitcher(final GraphMouse graphMouse) {
// $NON-NLS-1$
final JCheckBox checkBox = new JCheckBox(DefaultMessagesImpl.getString("JungGraphGenerator.Pick"));
checkBox.addActionListener(new ActionListener() {
/*
* (non-Javadoc)
*
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
DefaultModalGraphMouse modalGraphMouse = (DefaultModalGraphMouse) graphMouse;
if (checkBox.isSelected()) {
modalGraphMouse.setMode(Mode.PICKING);
} else {
modalGraphMouse.setMode(Mode.TRANSFORMING);
}
}
});
return checkBox;
}
use of edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse 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.DefaultModalGraphMouse 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.DefaultModalGraphMouse 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;
}
Aggregations