XJ Prolog UI Library
The "XJ" name originated in "XSB Prolog + Java Swing". XJ originated at XSB, Inc., back in 2000...2004; during Studio development over 2013 and 2014 XJ was further improved and extended. XJ is currently bundled with Prolog Studio.
Desktop users consume, transform and/or produce information in documents. XJ is a declarative developer’s tool to ease the construction of Java + XSB Prolog applications that are assumed to follow, at least partially, the following scenario:
- A Java GUI is intended to access a back-end Prolog engine implementing some data-related functionality
- Prolog data is loaded from somewhere
- Prolog data is shown and editable in the GUI, through Swing-derived objects; GUI changes propagate transparently (unless errors occur) to Prolog predicates in memory, as GUI objects are closed/unfocused
- Application operations may be invoked on GUI objects, producing side-effects
- Prolog data is saved to somewhere
XJ2 addresses the problem of Prolog data display, editing and operation invocation on displayed data, including automatic basic error handling, undo and drag & drop support. It generates GUI fragments at runtime based on information contained in an "XJModel" for the application, a small set of declarative Prolog rules. Depending on the level of customization desired and developer preferences, the whole GUI may be specified either entirely in the XJModel, or it may be partially constructed in Java and complemented with XJ2-generated visual hierarchies for Prolog data visualization and interaction.
CRUD UI for Prolog predicates
XJ as a "Create/Read/Update/Delete" table user interface allowing edition os a Prolog relation (through user predicates, which can simply assert/retract on memory or even access remote data or knowledge bases).
Visualizing graph networks
Prolog Studio has its user interface based on XJ, a Java Swing library for Prolog, which also includes JUNG's graph framework, http://jung.sourceforge.net/.
How to create a graph visualization
The easiest way to use graphs is to invoke the "View Results as Graph" menu from the Query window, see above.
A graph for an arbitrary Prolog relation can be visualized with:
...where AtLeastTwoArgsPred should be something like myrelation(?X,?Y,...). Only the first two args are relevant, as they define the binary relation displayed.
...adds a list of initial nodes (the graph must then be expanded from them by the user).
The GUI argument can be used by XJ-savvy developers to message the graph Java object.
This alternative predicate for Prolog relations gives more control:
?- xjGenericGraph( ['Avenida'], segment(_NodeID1,_NodeID2,_ID,_Type,_Term,_Tip), station(_ID,_Type,_Term,_Tip), [layout=frlayout2, labelsInNodes, cubicCurve, maxItems=20000], [ accessible=[icon='http://www.berklee.edu/sites/default/files/images/BPC/wheelchair-icon.jpg'], normal=[icon='/com/declarativa/fidji/flora.gif'] ], [blueLine=[color=blue,dotted], greenLine=[color=green, dashed], yellowLine=[color=yellow] ], _GraphUI).
Other more flexible variations are possibly by using XJ GUITerm specifications, not documented here.
In the graph window there will be a Operations menu. In this, try "Selection Mode" and "Scroll Mode" to make the mouse select (and relocate) nodes and to drag the whole graph, respectively. Try also the layout algorithms under the Layouts submenu.
Right-clicking a node or a edge reveals a popup menu with commands applying to the clicked item (node or edge).
Bugs and Missing Features
- IMPORTANT CAVEAT: when using the Studio listener, if you call a Prolog goal which creates lazy Java UI objects (e.g. non eager trees and lists, that paint themselves by lazily fetching data from Prolog) do NOT include (non anonymous) variables in your goal: if you do, the Prolog top level will pause after showing your variable bindings, thus forbidding (pending, e.g. AWT thread) Java deterministicGoals to evaluate. The system will deadlock and you will have to kill it. Killing just the Prolog subprocess may allow you to save some work, but possibly not.
- Sorting lists that contain N non persistent columns will result in a different column to be sorted, apparently N columns to the right of the clicked one
- Missing doubleclick to toggle graph nodes, namely to collapse previously expanded nodes (see unexpandVertex comments)