use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class FqlppDisplay method makeCatViewer.
private static <X, Y> JComponent makeCatViewer(Category<X, Y> cat, Color clr) {
Graph<X, Y> g = buildFromCat(cat);
if (g.getVertexCount() == 0) {
return new JPanel();
} else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(xxx);
return ret;
} else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(xxx);
return ret;
}
return doCatView(clr, g);
}
use of catdata.ide.CodeTextPanel 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;
}
use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class AqlTester method doSelfTests.
public static void doSelfTests() {
int c = JOptionPane.showConfirmDialog(null, message, "Run Self-Test?", JOptionPane.YES_NO_OPTION);
if (c != JOptionPane.YES_OPTION) {
return;
}
Ctx<String, String> exs = new Ctx<>();
for (Example e : Examples.getExamples(Language.AQL)) {
exs.put(e.getName(), e.getText());
}
Ctx<String, Throwable> result = runMany(exs);
if (result.isEmpty()) {
JOptionPane.showMessageDialog(null, "OK: Tested Passed");
return;
}
JTabbedPane t = new JTabbedPane();
for (String k : result.keySet()) {
t.addTab(k, new CodeTextPanel("Error", result.get(k).getMessage()));
}
JOptionPane.showMessageDialog(null, t);
}
use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class OplQuery method display.
@Override
public JComponent display() {
JTabbedPane ret = new JTabbedPane();
ret.addTab("Text", new CodeTextPanel(BorderFactory.createEtchedBorder(), "", toString()));
return ret;
}
use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class XMapping method makeTables.
@SuppressWarnings("unchecked")
private Component makeTables() {
try {
List<JComponent> grid = new LinkedList<>();
for (C id : src.schema.ids) {
Map<List<C>, List<D>> map = new HashMap<>();
for (Triple<C, C, List<C>> arr : src.cat().hom((C) "_1", id)) {
// arrows())
// {
List<C> toApply = new LinkedList<>(arr.third);
toApply.add(0, arr.first);
List<D> applied = apply(toApply);
for (Triple<D, D, List<D>> cand : dst.cat().hom((D) "_1", (D) id)) {
if (dst.getKB().equiv(cand.third, applied)) {
map.put(arr.third, cand.third);
}
}
}
Object[][] rowData = new Object[map.size()][2];
Object[] colNames = new Object[] { "src", "dst" };
int i = 0;
for (Entry<List<C>, List<D>> k : map.entrySet()) {
rowData[i][0] = Util.sep(k.getKey(), ".");
rowData[i][1] = Util.sep(k.getValue(), ".");
i++;
}
JPanel tbl = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), id + " (" + map.size() + " rows)", rowData, colNames);
grid.add(tbl);
}
return GuiUtil.makeGrid(grid);
} catch (Exception e) {
return new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "ERROR:\n\n" + e.getMessage());
}
}
Aggregations