use of easik.model.edge.GuideEdge in project fql by CategoricalData.
the class ViewGraphModel method getAttributes.
/**
* Overridden method to get cell attributes; we make sure the appropriate
* attributes are applied to the Easik objects before returning them.
*
* @see DefaultGraphModel.getAttributes(Object)
*
* @param o
*
* @return
*/
@Override
@SuppressWarnings("unchecked")
public AttributeMap getAttributes(Object o) {
_mode = (_view.getSketch().getFrame().getMode() == Mode.EDIT) ? "edit_" : "manip_";
if (o instanceof GraphCell) {
GraphCell cell = (GraphCell) o;
AttributeMap attribs = cell.getAttributes();
AttributeMap easikAttribs = null;
if (cell instanceof View_Edge) {
easikAttribs = (cell instanceof InjectiveViewEdge) ? injectiveEdgeAttributes() : (cell instanceof PartialViewEdge) ? partialEdgeAttributes() : normalEdgeAttributes();
} else if (cell instanceof TriangleEdge) {
easikAttribs = triangleEdgeAttributes((TriangleEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell);
} else if (cell instanceof GuideEdge) {
easikAttribs = ((GuideEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge>) cell).isHighlighted() ? virtualHighlightedEdgeAttributes() : virtualEdgeAttributes();
} else if (cell instanceof ModelConstraint) {
easikAttribs = virtualVertexAttributes();
} else if (cell instanceof QueryNode) {
easikAttribs = vertexAttributes();
}
if (easikAttribs != null) {
if (_view.isCellSelected(cell)) {
Color selColor;
float lineWidth;
if (_view.getStateManager().peekState() instanceof GetPathState) {
selColor = getColor("path_selection");
lineWidth = getWidth("path_selection", 2);
} else {
selColor = getColor("selection");
lineWidth = getWidth("selection", 3);
}
int borderWidth = getIntWidth(_mode + ((cell instanceof ModelConstraint) ? "constraint" : "entity") + "_border", 1);
GraphConstants.setBorder(easikAttribs, BorderFactory.createLineBorder(selColor, borderWidth));
GraphConstants.setForeground(easikAttribs, selColor);
GraphConstants.setLineColor(easikAttribs, selColor);
GraphConstants.setLineWidth(easikAttribs, lineWidth);
}
if (attribs == null) {
cell.setAttributes(easikAttribs);
attribs = easikAttribs;
} else {
attribs.applyMap(easikAttribs);
}
return attribs;
}
}
return super.getAttributes(o);
}
use of easik.model.edge.GuideEdge 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 easik.model.edge.GuideEdge 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 easik.model.edge.GuideEdge 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 easik.model.edge.GuideEdge in project fql by CategoricalData.
the class Model method removeConstraint.
/**
* Removes a constraint and guide arrows
*
* @param toRemove
* The constraint about to be removed
*/
public void removeConstraint(final ModelConstraint<F, GM, M, N, E> toRemove) {
model.beginUpdate();
getGraphLayoutCache().remove(toRemove.getGuideEdges().toArray(new GuideEdge[toRemove.getGuideEdges().size()]));
getGraphLayoutCache().remove(new Object[] { toRemove });
final int position = toRemove.getID();
_constraints.remove(toRemove.getID());
for (N n : toRemove.getEntities()) {
n.removeConstraint(toRemove);
}
model.postEdit(new AbstractUndoableEdit() {
/**
*/
private static final long serialVersionUID = 6431577416127308496L;
@Override
public void undo() {
super.undo();
_constraints.put(position, toRemove);
for (N n : toRemove.getEntities()) {
n.addConstraint(toRemove);
}
}
@Override
public void redo() {
super.redo();
_constraints.remove(position);
for (N n : toRemove.getEntities()) {
n.removeConstraint(toRemove);
}
}
});
// Remove Entity from tree
_Frame.getInfoTreeUI().removeConstraint(toRemove);
model.endUpdate();
}
Aggregations