use of edu.uci.ics.jung.visualization.VisualizationViewer in project fql by CategoricalData.
the class Mpl method doTermView2.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <O, A> JComponent doTermView2(Graph<MplStrict2.Node<O, A>, Integer> sgv) {
if (sgv.getVertexCount() == 0) {
return new JPanel();
}
Layout layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer vv = new VisualizationViewer<>(layout);
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
// vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
// vv.getRenderContext().setVertexLabelTransformer(ttt);
vv.getRenderContext().setEdgeLabelTransformer(xx -> "");
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
use of edu.uci.ics.jung.visualization.VisualizationViewer in project fql by CategoricalData.
the class TransformEditor method doView.
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComponent doView(Color clr, /* final Color color */
Graph<String, String> sgv) {
try {
Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.inst_graph);
Constructor<?> x = c.getConstructor(Graph.class);
Layout<String, String> layout = (Layout<String, String>) x.newInstance(sgv);
layout.setSize(new Dimension(500, 340));
VisualizationViewer<String, String> vv = new VisualizationViewer<>(layout);
Function<String, Paint> vertexPaint = (String i) -> thesig.isAttribute(i) ? UIManager.getColor("Panel.background") : clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
// gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setVertexLabelTransformer((String str) -> {
if (thesig.isAttribute(str)) {
str = thesig.getTypeLabel(str);
}
return str;
});
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
String str = ((String) e.getItem());
if (thesig.isNode(str)) {
cards.show(vwr, str);
card = str;
}
});
vv.getRenderContext().setLabelOffset(20);
vv.getRenderContext().setEdgeLabelTransformer((String s) -> {
if (thesig.isAttribute(s)) {
return "";
}
return s;
});
float[] dash = { 1.0f };
Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
Stroke bs = new BasicStroke();
Function<String, Stroke> edgeStrokeTransformer = (String s) -> {
if (thesig.isAttribute(s)) {
return edgeStroke;
}
return bs;
};
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
zzz.setPreferredSize(new Dimension(600, 400));
vwr.setPreferredSize(new Dimension(600, 200));
// JPanel newthing = new JPanel(new GridLayout(2,1));
JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
newthing.setResizeWeight(.5d);
newthing.setDividerLocation(.5d);
// setDividerLocation(.9d);
newthing.add(zzz);
JPanel yyy = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton ar = new JButton("Add Row");
JButton dr = new JButton("Delete Rows");
ar.setPreferredSize(dr.getPreferredSize());
yyy.add(ar);
yyy.add(dr);
JPanel xxx = new JPanel(new BorderLayout());
xxx.add(vwr, BorderLayout.CENTER);
xxx.add(yyy, BorderLayout.SOUTH);
newthing.add(xxx);
newthing.resetToPreferredSizes();
dr.addActionListener((ActionEvent e) -> {
JTable t = tj.get(card);
int[] i = t.getSelectedRows();
int j = 0;
DefaultTableModel dtm = (DefaultTableModel) t.getModel();
for (int x1 : i) {
dtm.removeRow(x1 - (j++));
}
tjx.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), name + "." + card + " (" + dtm.getRowCount() + " rows)"));
});
ar.addActionListener((ActionEvent e) -> {
JTable t = tj.get(card);
DefaultTableModel dtm = (DefaultTableModel) t.getModel();
dtm.addRow((Vector) null);
tjx.get(card).setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), name + "." + card + " (" + dtm.getRowCount() + " rows)"));
});
return newthing;
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException();
}
}
use of edu.uci.ics.jung.visualization.VisualizationViewer in project fql by CategoricalData.
the class Mapping method doView.
@SuppressWarnings("unchecked")
private JPanel doView(Color scolor, Color tcolor, @SuppressWarnings("unused") FqlEnvironment env, Graph<String, String> sgv) {
// Layout<V, E>, BasicVisualizationServer<V,E>
try {
Class<?> c = Class.forName(FqlOptions.layout_prefix + DefunctGlobalOptions.debug.fql.mapping_graph);
Constructor<?> x = c.getConstructor(Graph.class);
Layout<String, String> layout = (Layout<String, String>) x.newInstance(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<String, String> vv = new VisualizationViewer<>(layout);
// vv.setPreferredSize(new Dimension(600, 400));
// Setup up a new vertex to paint transformer...
Function<String, Paint> vertexPaint = (String t) -> {
int i = t.indexOf(".");
String j = t.substring(i + 1);
String p = t.substring(0, i);
if (source.isAttribute(j) || target.isAttribute(j)) {
return UIManager.getColor("Panel.background");
}
if (p.equals("@source")) {
return scolor;
}
return 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 = { 10.0f };
Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
Stroke bs = new BasicStroke();
Function<String, Stroke> edgeStrokeTransformer = (String s) -> {
if (s.contains(" ")) {
return edgeStroke;
}
return bs;
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
vv.getRenderContext().setVertexLabelTransformer((String t) -> {
int i = t.indexOf(".");
String j = t.substring(i + 1);
// String p = t.substring(0, i);
return j;
});
JPanel p = new JPanel(new GridLayout(1, 1));
p.setBorder(BorderFactory.createEtchedBorder());
p.add(new GraphZoomScrollPane(vv));
return p;
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException();
}
}
use of edu.uci.ics.jung.visualization.VisualizationViewer in project fql by CategoricalData.
the class XCtx method makeGraph.
private JComponent makeGraph(boolean isInstance) {
if (allTerms().size() > 128) {
return new JTextArea("Too large to display");
}
Graph<C, C> sgv = buildFromSig();
Layout<C, C> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<C, C> vv = new VisualizationViewer<>(layout);
vv.getRenderContext().setLabelOffset(20);
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
// was TRANSFORMING
gm.setMode(Mode.PICKING);
vv.setGraphMouse(gm);
vv.getRenderContext().setVertexFillPaintTransformer((C x) -> global.terms().contains(x) ? Color.RED : Color.GREEN);
com.google.common.base.Function<C, String> ttt = (C arg0) -> {
String ret = arg0.toString();
return (ret.length() > 40) ? ret.substring(0, 39) + "..." : ret;
};
vv.getRenderContext().setVertexLabelTransformer(ttt);
// vv.getRenderer().setVertexRenderer(new MyRenderer());
vv.getRenderContext().setEdgeLabelTransformer(ttt);
vv.getPickedVertexState().addItemListener(e -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
// Object str = e.getItem();
if (cl == null) {
}
// cl.show(clx, xgrid.get(str));
});
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
if (isInstance && DefunctGlobalOptions.debug.fpql.x_tables && xcat != null) {
JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
// setDividerLocation(.9d);
jsp.setResizeWeight(.8d);
jsp.setDividerSize(2);
jsp.add(ret);
jsp.add(clx);
return jsp;
} else {
return ret;
}
}
use of edu.uci.ics.jung.visualization.VisualizationViewer in project fql by CategoricalData.
the class AqlViewer method viewSchema.
private <Ty, En, Sym, Fk, Att> JComponent viewSchema(Schema<Ty, En, Sym, Fk, Att> schema) {
Graph<Chc<Ty, En>, Chc<Fk, Att>> sgv = new DirectedSparseMultigraph<>();
int i = 0;
boolean triggered = false;
for (En en : schema.ens) {
sgv.addVertex(Chc.inRight(en));
i++;
if (i >= maxrows) {
triggered = true;
break;
}
}
// if (i <= maxrows) {
i = 0;
for (Ty ty : schema.typeSide.tys) {
sgv.addVertex(Chc.inLeft(ty));
i++;
if (i >= maxrows * maxrows) {
triggered = true;
break;
}
}
for (Att att : schema.atts.keySet()) {
sgv.addEdge(Chc.inRight(att), Chc.inRight(schema.atts.get(att).first), Chc.inLeft(schema.atts.get(att).second));
i++;
if (i >= maxrows * maxrows) {
triggered = true;
break;
}
}
for (Fk fk : schema.fks.keySet()) {
sgv.addEdge(Chc.inLeft(fk), Chc.inRight(schema.fks.get(fk).first), Chc.inRight(schema.fks.get(fk).second));
i++;
if (i >= maxrows * maxrows) {
triggered = true;
break;
}
}
if (sgv.getVertexCount() == 0) {
return new JPanel();
}
// Layout<Chc<Ty, En>, Chc<Fk, Att>> layout = new KKLayout<>(sgv);
Layout<Chc<Ty, En>, Chc<Fk, Att>> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Chc<Ty, En>, Chc<Fk, Att>> vv = new VisualizationViewer<>(layout);
Function<Chc<Ty, En>, Paint> vertexPaint = x -> x.left ? Color.gray : Color.black;
DefaultModalGraphMouse<Chc<Ty, En>, Chc<Fk, Att>> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<Chc<Fk, Att>, String> et = Chc::toStringMash;
Function<Chc<Ty, En>, String> vt = Chc::toStringMash;
vv.getRenderContext().setEdgeLabelTransformer(et);
vv.getRenderContext().setVertexLabelTransformer(vt);
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
vv.getRenderContext().setLabelOffset(16);
// vv.getRenderContext().set
vv.setBackground(Color.white);
if (triggered) {
ret.setBorder(BorderFactory.createTitledBorder("Partial"));
}
return ret;
}
Aggregations