use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.
the class View method initialiseModel.
/**
* When we initialize the sketch, we flush out all the data concerning the
* sketch itself. Even the modelAdapter is reinitialized.
*
* This methods serves as a "new sketch" function.
*/
@Override
public void initialiseModel() {
clearSelection();
model = new ViewGraphModel(this);
final GraphLayoutCache glc = new GraphLayoutCache(model, new ModelViewFactory<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>());
setModel(model);
setGraphLayoutCache(glc);
_nodes = new LinkedHashMap<>();
_edges = new LinkedHashMap<>();
if (_Frame.getInfoTreeUI() != null) {
// Wipe
_Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame));
// Tree
_Frame.getInfoTreeUI().refreshTree();
}
_docInfo.reset();
model.discardUndo();
}
use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.
the class ModelConstraint method addVisualsToModel.
/**
* Adds the visual aids to the sketch
*/
private void addVisualsToModel() {
// Push loading state
_theModel.getStateManager().pushState(new LoadingState<>(_theModel));
_theModel.getGraphModel().beginInsignificantUpdate();
_visuals.clear();
// Get Nodes involved in constraint
LinkedHashSet<N> entitiesInvolved = new LinkedHashSet<>();
for (E edge : _edges) {
entitiesInvolved.add(edge.getSourceEntity());
entitiesInvolved.add(edge.getTargetEntity());
}
int avgX = 0, avgY = 0;
if ("limitconstraint".equals(getType())) {
// slightly differently
for (N node : entitiesInvolved) {
avgX += node.getX();
avgY += node.getY();
}
LimitConstraint<F, GM, M, N, E> thisConstraintAsLC = ((LimitConstraint<F, GM, M, N, E>) this);
N constraintRoot = thisConstraintAsLC.getLimitNode();
final float BIG_EDGE_WIDTH = (float) 3.0;
final float LITTLE_EDGE_WIDTH = (float) 2.0;
final int TRANSPARENCY = 230;
// a hopefully
Color col = EasikTools.getUnusedColor(TRANSPARENCY);
// unique
// color,
// 230 is
// transparency
_visuals.add(new TriangleEdge<>(this, constraintRoot, col, BIG_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
_visuals.add(new TriangleEdge<>(this, thisConstraintAsLC.getCone().getA(), col, LITTLE_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
_visuals.add(new TriangleEdge<>(this, thisConstraintAsLC.getCone().getB(), col, LITTLE_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
_visuals.add(new TriangleEdge<>(this, thisConstraintAsLC.getCone().getC(), col, LITTLE_EDGE_WIDTH, GraphConstants.ARROW_NONE, GraphConstants.ARROW_NONE));
} else {
// edges going to each entity involved
for (N node : entitiesInvolved) {
GuideEdge<F, GM, M, N, E> myEdge = new GuideEdge<>(this, node);
_visuals.add(myEdge);
avgX += node.getX();
avgY += node.getY();
}
}
// If only one entity is involved add some vertical space
if (entitiesInvolved.size() == 1) {
avgY += 20;
}
int posX = getX();
int posY = getY();
// If visual does not already have a position then position it
if ((posX == 0) && (posY == 0)) {
posX = avgX / entitiesInvolved.size();
posY = avgY / entitiesInvolved.size();
}
// Set the on-screen position of our entity to the attributes of the
// entity
AttributeMap attribs = getAttributes();
GraphConstants.setAutoSize(attribs, true);
GraphConstants.setBounds(attribs, new Rectangle2D.Double(posX, posY, 0, 0));
GraphConstants.setSelectable(attribs, false);
// Actually add them to the sketch display:
GraphLayoutCache glc = _theModel.getGraphLayoutCache();
if (!_nodeVisualized) {
glc.insert(this);
_nodeVisualized = true;
}
glc.insert(_visuals.toArray(new GuideEdge[0]));
_edgesVisualized = true;
_theModel.getGraphModel().endInsignificantUpdate();
_theModel.refresh();
// Pop state
_theModel.getStateManager().popState();
}
use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.
the class ModelConstraint method removeVisualsFromModel.
/**
* Removes the visuals from the sketch (when hiding)
*/
private void removeVisualsFromModel() {
// Push loading state
_theModel.getStateManager().pushState(new LoadingState<>(_theModel));
_theModel.getGraphModel().beginInsignificantUpdate();
GraphLayoutCache glc = _theModel.getGraphLayoutCache();
glc.remove(_visuals.toArray(new GuideEdge[0]));
_visuals.clear();
_edgesVisualized = false;
GraphConstants.setSelectable(getAttributes(), false);
_theModel.refresh();
_theModel.getGraphModel().cancelInsignificantUpdate();
// Pop state
_theModel.getStateManager().popState();
}
use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.
the class ModelConstraint method setVisible.
/**
* Sets if the constraint should be visible or not
*
* @param inIsVisible
* If the constraint should be visible or not.
*/
public void setVisible(boolean inIsVisible) {
if (inIsVisible != _isVisible) {
_isVisible = inIsVisible;
_theModel.setDirty();
}
@SuppressWarnings({ "unused", "unchecked" }) GuideEdge<F, GM, M, N, E>[] visuals = _visuals.toArray(new GuideEdge[0]);
@SuppressWarnings("unused") GraphLayoutCache glc = _theModel.getGraphLayoutCache();
if (_isVisible && !_edgesVisualized) {
addVisualsToModel();
} else if (!_isVisible && _edgesVisualized) {
removeVisualsFromModel();
}
_theModel.clearSelection();
}
use of org.jgraph.graph.GraphLayoutCache in project fql by CategoricalData.
the class Sketch method initialiseModel.
/**
* When we initialise the sketch, we flush out all the data concerning the
* sketch itself.
*
* This methods serves as a "new sketch" function.
*/
@Override
public void initialiseModel() {
clearSelection();
model = new SketchGraphModel(this);
final GraphLayoutCache glc = new GraphLayoutCache(model, new ModelViewFactory<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>());
setModel(model);
setGraphLayoutCache(glc);
_nodes = new LinkedHashMap<>();
_edges = new LinkedHashMap<>();
if (_Frame.getInfoTreeUI() != null) {
// Wipe
_Frame.setInfoTreeUI(new ModelInfoTreeUI<>(_Frame));
// Tree
_Frame.getInfoTreeUI().refreshTree();
}
_docInfo.reset();
_views = new HashMap<>();
_connParams = new HashMap<>();
model.discardUndo();
}
Aggregations