Search in sources :

Example 6 with DefaultGraphCell

use of org.jgraph.graph.DefaultGraphCell in project cayenne by apache.

the class BaseGraphBuilder method updateRelationshipLabels.

/**
 * Updates relationship labels for specified relationship edge.
 */
protected void updateRelationshipLabels(DefaultEdge edge, Relationship rel, Relationship reverse) {
    DefaultGraphCell sourceCell = entityCells.get(rel.getSourceEntity().getName());
    DefaultGraphCell targetCell = entityCells.get(rel.getTargetEntity().getName());
    edge.setSource(sourceCell != null ? sourceCell.getChildAt(0) : null);
    edge.setTarget(targetCell != null ? targetCell.getChildAt(0) : null);
    Object[] labels = { rel.getName() + " " + getRelationshipLabel(rel), reverse == null ? "" : reverse.getName() + " " + getRelationshipLabel(reverse) };
    GraphConstants.setExtraLabels(edge.getAttributes(), labels);
    Point2D[] labelPositions = { new Point2D.Double(GraphConstants.PERMILLE * (0.1 + 0.2 * Math.random()), 10), new Point2D.Double(GraphConstants.PERMILLE * (0.9 - 0.2 * Math.random()), -10) };
    GraphConstants.setExtraLabelPositions(edge.getAttributes(), labelPositions);
}
Also used : DefaultGraphCell(org.jgraph.graph.DefaultGraphCell) Point2D(java.awt.geom.Point2D)

Example 7 with DefaultGraphCell

use of org.jgraph.graph.DefaultGraphCell in project cayenne by apache.

the class BaseGraphBuilder method removeEntityCell.

protected void removeEntityCell(Entity e) {
    final DefaultGraphCell cell = entityCells.get(e.getName());
    if (cell != null) {
        runWithUndoDisabled(() -> graph.getGraphLayoutCache().remove(new Object[] { cell }, true, true));
        entityCells.remove(e.getName());
    }
}
Also used : DefaultGraphCell(org.jgraph.graph.DefaultGraphCell)

Example 8 with DefaultGraphCell

use of org.jgraph.graph.DefaultGraphCell in project cayenne by apache.

the class BaseGraphBuilder method createEntityCell.

protected DefaultGraphCell createEntityCell(Entity entity) {
    DefaultGraphCell cell = new DefaultGraphCell(getCellMetadata(entity));
    GraphConstants.setResize(cell.getAttributes(), true);
    GraphConstants.setBorder(cell.getAttributes(), new LineBorder(Color.BLACK));
    GraphConstants.setEditable(cell.getAttributes(), false);
    entityCells.put(entity.getName(), cell);
    cell.addPort();
    return cell;
}
Also used : DefaultGraphCell(org.jgraph.graph.DefaultGraphCell) LineBorder(javax.swing.border.LineBorder)

Example 9 with DefaultGraphCell

use of org.jgraph.graph.DefaultGraphCell in project cayenne by apache.

the class ObjGraphBuilder method createInheritanceEdge.

DefaultEdge createInheritanceEdge(ObjEntity entity) {
    if (!inheritanceEdges.containsKey(entity)) {
        ObjEntity superEntity = entity.getSuperEntity();
        if (superEntity != null) {
            DefaultGraphCell sourceCell = entityCells.get(entity.getName());
            DefaultGraphCell targetCell = entityCells.get(superEntity.getName());
            DefaultEdge edge = new DefaultEdge();
            edge.setSource(sourceCell.getChildAt(0));
            edge.setTarget(targetCell.getChildAt(0));
            GraphConstants.setDashPattern(edge.getAttributes(), new float[] { 5, 5 });
            GraphConstants.setLineEnd(edge.getAttributes(), GraphConstants.ARROW_TECHNICAL);
            GraphConstants.setSelectable(edge.getAttributes(), false);
            inheritanceEdges.put(entity, edge);
            return edge;
        }
    }
    return null;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DefaultGraphCell(org.jgraph.graph.DefaultGraphCell) DefaultEdge(org.jgraph.graph.DefaultEdge)

Aggregations

DefaultGraphCell (org.jgraph.graph.DefaultGraphCell)9 Rectangle2D (java.awt.geom.Rectangle2D)2 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LineBorder (javax.swing.border.LineBorder)1 DataMap (org.apache.cayenne.map.DataMap)1 Entity (org.apache.cayenne.map.Entity)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 JGraph (org.jgraph.JGraph)1 AttributeMap (org.jgraph.graph.AttributeMap)1 DefaultCellViewFactory (org.jgraph.graph.DefaultCellViewFactory)1 DefaultEdge (org.jgraph.graph.DefaultEdge)1 DefaultGraphModel (org.jgraph.graph.DefaultGraphModel)1 GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)1 GraphModel (org.jgraph.graph.GraphModel)1