Package org.jgraph.graph

Examples of org.jgraph.graph.DefaultGraphCell


                          if (moveCell == null)
                            return;
                          Point dropPoint = new Point(dsde.getX()
                              - jgraph.getLocationOnScreen().x, dsde.getY()
                              - jgraph.getLocationOnScreen().y);
                          DefaultGraphCell endCell = (DefaultGraphCell) GraphView.this.jgraph
                              .getSelectionCell();
                          if (endCell != null) {
                            ModelGraph endGraph = GuiUtils.find(
                                state.getGraphs(),
                                ((ModelNode) endCell.getUserObject()).getId());
                            if (!endGraph.getModel().isParentType()
                                || GuiUtils.isSubGraph(moveGraph, endGraph))
                              return;
                            if (moveGraph.getParent() == null)
                              state.removeGraph(moveGraph);
                            else
                              GuiUtils.removeNode(state.getGraphs(),
                                  moveGraph.getModel());
                            GraphView.this.removeShift(state, moveGraph);
                            GuiUtils.addChild(state.getGraphs(), endGraph
                                .getModel().getId(), moveGraph);
                            GraphView.this.notifyListeners();
                          } else {
                            if (moveGraph.getParent() != null) {
                              GuiUtils.removeNode(state.getGraphs(),
                                  moveGraph.getModel());
                              state.addGraph(moveGraph);
                            }
                            Point shiftPoint = new Point(
                                (int) ((dropPoint.x - (dge.getDragOrigin().x - (bounds
                                    .getX() * scale))) / scale),
                                (int) ((dropPoint.y - (dge.getDragOrigin().y - (bounds
                                    .getY() * scale))) / scale));
                            GraphView.this.setShift(state, moveGraph,
                                shiftPoint);
                            GraphView.this.notifyListeners();
                          }
                        }

                        public void dragEnter(DragSourceDragEvent dsde) {
                          mouseOverCell = (DefaultGraphCell) GraphView.this.jgraph
                              .getFirstCellForLocation(
                                  dsde.getX() - jgraph.getLocationOnScreen().x,
                                  dsde.getY() - jgraph.getLocationOnScreen().y);
                          mouseOverGraph = GuiUtils.find(state.getGraphs(),
                              ((ModelNode) mouseOverCell.getUserObject())
                                  .getId());
                        }

                        public void dragExit(DragSourceEvent dse) {
                          System.out.println("DRAG EXIT!!!!");
                        }

                        public void dragOver(DragSourceDragEvent dsde) {
                          if (state.getMode().equals(Mode.EDIT)) {
                            if (mouseOverCell != null) {
                              Rectangle2D currentBounds = (Rectangle2D) mouseOverCell
                                  .getAttributes().get(GraphConstants.BOUNDS);
                              Point currentPoint = new Point(dsde.getX()
                                  - jgraph.getLocationOnScreen().x, dsde.getY()
                                  - jgraph.getLocationOnScreen().y);
                              if (currentBounds.contains(currentPoint)) {
                                for (ModelGraph child : mouseOverGraph
                                    .getChildren()) {
                                  DefaultGraphCell mouseOverCellLoc = GraphView.this.m_jgAdapter
                                      .getVertexCell(child.getModel());
                                  currentBounds = (Rectangle2D) mouseOverCellLoc
                                      .getAttributes().get(
                                          GraphConstants.BOUNDS);
                                  if (currentBounds.contains(currentPoint)) {
                                    mouseOverCell = mouseOverCellLoc;
                                    mouseOverGraph = child;
                                    break;
                                  }
                                }
                              } else {
                                if (mouseOverGraph.getParent() != null
                                    && (!mouseOverGraph.isCondition() || (mouseOverGraph
                                        .isCondition() && mouseOverGraph
                                        .getParent().isCondition()))) {
                                  mouseOverCell = GraphView.this.m_jgAdapter
                                      .getVertexCell((mouseOverGraph = mouseOverGraph
                                          .getParent()).getModel());
                                  currentBounds = (Rectangle2D) mouseOverCell
                                      .getAttributes().get(
                                          GraphConstants.BOUNDS);
                                } else {
                                  mouseOverCell = null;
                                  mouseOverGraph = null;
                                }
                              }
                            } else {
                              mouseOverCell = (DefaultGraphCell) GraphView.this.jgraph
                                  .getFirstCellForLocation(
                                      dsde.getX()
                                          - jgraph.getLocationOnScreen().x,
                                      dsde.getY()
                                          - jgraph.getLocationOnScreen().y);
                              if (mouseOverCell != null)
                                mouseOverGraph = GuiUtils.find(state
                                    .getGraphs(), ((ModelNode) mouseOverCell
                                    .getUserObject()).getId());
                              else
                                mouseOverGraph = null;
                            }
                            if (mouseOverGraph != null) {
                              if (GuiUtils.isDummyNode(mouseOverGraph
                                  .getModel())) {
                                mouseOverGraph = mouseOverGraph.getParent();
                              } else {
                                while (mouseOverGraph != null
                                    && mouseOverGraph.getModel().isRef())
                                  mouseOverGraph = mouseOverGraph.getParent();
                              }
                              if (mouseOverGraph != null)
                                mouseOverCell = GraphView.this.m_jgAdapter
                                    .getVertexCell(mouseOverGraph.getModel());
                              else
                                mouseOverCell = null;
                            }
                            GraphView.this.jgraph
                                .setSelectionCells(new Object[] { mouseOverCell });
                          }
                        }

                        public void dropActionChanged(DragSourceDragEvent dsde) {
                          System.out.println("DRAG CHANGE!!!!");
                        }

                      });
                }
              }
            }
          }

        });

    List<Line> lines = GuiUtils.findLines(state.getGraphs());
    for (Line line : lines) {
      if (!this.directedGraph.containsVertex(line.getFromModel()))
        this.directedGraph.addVertex(line.getFromModel());

      if (line.getToModel() != null) {
        if (!this.directedGraph.containsVertex(line.getToModel()))
          this.directedGraph.addVertex(line.getToModel());
        IdentifiableEdge edge = new IdentifiableEdge(line.getFromModel(), line.getToModel());
        directedGraph.addEdge(edge, line.getFromModel(), line.getToModel());
        this.edgeMap.put(edge.id, new Pair(line.getFromModel() != null ? line
            .getFromModel().getId() : null, line.getToModel().getId()));
      }
    }

    JGraphFacade facade = new JGraphFacade(jgraph);
    facade.setIgnoresUnconnectedCells(false);
    JGraphHierarchicalLayout layout = new JGraphHierarchicalLayout();
    layout.setOrientation(SwingConstants.WEST);
    layout.setIntraCellSpacing(70.0);
    layout.setLayoutFromSinks(false);
    layout.run(facade);
    Map nested = facade.createNestedMap(true, true);
    if (nested != null) {
      this.hideDummyNodes(nested);
      this.addGroups(state.getGraphs(), nested, state);
      this.ensureNoOverlap(nested, state);
      nested = this.shiftMap(nested, state);
      jgraph.getGraphLayoutCache().edit(nested);
    }

    String edgeDisplayMode = state.getFirstPropertyValue(EDGE_DISPLAY_MODE);
    if (edgeDisplayMode == null)
      state.setProperty(EDGE_DISPLAY_MODE, edgeDisplayMode = WORKFLOW_MODE);
    if (edgeDisplayMode.equals(WORKFLOW_MODE)) {
      this.edgeMap = new HashMap<String, Pair>();
      removeAllEdges(this.directedGraph);
      lines = GuiUtils.findSequentialLines(state.getGraphs());
      for (Line line : lines) {
        IdentifiableEdge edge = new IdentifiableEdge(line.getFromModel(), line.getToModel());
        directedGraph.addEdge(edge, line.getFromModel(), line.getToModel());
        this.edgeMap.put(edge.id, new Pair(line.getFromModel() != null ? line
            .getFromModel().getId() : null, line.getToModel().getId()));
      }
    }

    if (state.getSelected() != null) {
      ModelGraph graph = GuiUtils.find(state.getGraphs(), state.getSelected()
          .getModel().getId());
      if (graph != null) {
        DefaultGraphCell cell = this.m_jgAdapter
            .getVertexCell(graph.getModel());
        if (cell != null)
          this.jgraph.setSelectionCells(new Object[] { cell });
        else
          this.jgraph.setSelectionCells(new Object[] {});
View Full Code Here


        for (Point2D.Double point : points)
          newPoints
              .add(new Point2D.Double(point.x + shift.x, point.y + shift.y));
        ((Map<Object, Object>) entry.getValue()).put("points", newPoints);
      } else if (entry.getKey() instanceof DefaultGraphCell) {
        DefaultGraphCell cell = (DefaultGraphCell) entry.getKey();
        Rectangle2D bounds = (Rectangle2D) ((Map<Object, Object>) entry
            .getValue()).get("bounds");
        Point shift = this.getShift(state, cell, nested);
        AttributeMap.SerializableRectangle2D newBounds = new AttributeMap.SerializableRectangle2D(
            bounds.getX() + shift.x, bounds.getY() + shift.y,
View Full Code Here

      changed = false;
      for (int i = 0; i < state.getGraphs().size(); i++) {
        ModelGraph currentGraph = state.getGraphs().get(i);
        if (this.ensureNoInternalOverlap(currentGraph, nested))
          changed = true;
        DefaultGraphCell currentCell = this.m_jgAdapter
            .getVertexCell(currentGraph.getModel());
        Rectangle2D currentBounds = (Rectangle2D) ((Map) nested
            .get(currentCell)).get(GraphConstants.BOUNDS);
        Point currentShift = this.getShift(state, currentCell, nested);
        Rectangle currentShiftBounds = new Rectangle(
            (int) (currentBounds.getX() + currentShift.getX()),
            (int) (currentBounds.getY() + currentShift.getY()),
            (int) currentBounds.getWidth(), (int) currentBounds.getHeight());
        for (int j = 0; j < state.getGraphs().size(); j++) {
          if (i == j)
            continue;
          ModelGraph graph = state.getGraphs().get(j);
          DefaultGraphCell cell = this.m_jgAdapter.getVertexCell(graph
              .getModel());
          Rectangle2D bounds = (Rectangle2D) ((Map) nested.get(cell))
              .get(GraphConstants.BOUNDS);
          Point shift = this.getShift(state, cell, nested);
          Rectangle shiftBounds = new Rectangle(
View Full Code Here

      List<ModelGraph> sortedChildren = new Vector<ModelGraph>(
          graph.getChildren());
      Collections.sort(sortedChildren, new Comparator<ModelGraph>() {

        public int compare(ModelGraph o1, ModelGraph o2) {
          DefaultGraphCell child1Cell = GraphView.this.m_jgAdapter
              .getVertexCell(o1.getModel());
          DefaultGraphCell child2Cell = GraphView.this.m_jgAdapter
              .getVertexCell(o2.getModel());
          Rectangle2D child1Bounds = (Rectangle2D) ((Map) nested
              .get(child1Cell)).get(GraphConstants.BOUNDS);
          Rectangle2D child2Bounds = (Rectangle2D) ((Map) nested
              .get(child2Cell)).get(GraphConstants.BOUNDS);
          if (graph.getModel().getExecutionType().equals("parallel"))
            return Double.compare(child1Bounds.getMaxY(),
                child2Bounds.getMaxY());
          else
            return Double.compare(child1Bounds.getX(), child2Bounds.getX());
        }

      });
      changed = ensureNoInternalOverlap(sortedChildren.get(0), nested);
      Rectangle2D graphRectangle = (Rectangle2D) ((Map) nested
          .get(this.m_jgAdapter.getVertexCell(sortedChildren.get(0).getModel())))
          .get(GraphConstants.BOUNDS);
      for (int i = 1; i < sortedChildren.size(); i++) {
        ModelGraph child2 = sortedChildren.get(i);
        if (ensureNoInternalOverlap(child2, nested))
          changed = true;
        DefaultGraphCell child2Cell = this.m_jgAdapter.getVertexCell(child2
            .getModel());
        for (int j = i - 1; j >= 0; j--) {
          ModelGraph child1 = sortedChildren.get(j);
          DefaultGraphCell child1Cell = this.m_jgAdapter.getVertexCell(child1
              .getModel());
          Rectangle2D child1Bounds = (Rectangle2D) ((Map) nested
              .get(child1Cell)).get(GraphConstants.BOUNDS);
          Rectangle2D child2Bounds = (Rectangle2D) ((Map) nested
              .get(child2Cell)).get(GraphConstants.BOUNDS);
View Full Code Here

  }

  private void shift(List<ModelGraph> graphs, Map nested, double x, double y) {
    for (int i = 0; i < graphs.size(); i++) {
      ModelGraph graph = graphs.get(i);
      DefaultGraphCell cell = this.m_jgAdapter.getVertexCell(graph.getModel());
      Rectangle2D bounds = (Rectangle2D) ((Map) nested.get(cell))
          .get(GraphConstants.BOUNDS);
      ((Map) nested.get(cell)).put(
          GraphConstants.BOUNDS,
          new AttributeMap.SerializableRectangle2D(bounds.getX() + x, bounds
View Full Code Here

  private DefaultGraphCell addGroups(ModelGraph modelGraph, Map nested,
      ViewState state) {
    if (modelGraph.getModel().isParentType()) {
      double top_x = Double.MAX_VALUE, top_y = Double.MAX_VALUE, bottom_x = 0.0, bottom_y = 0.0;
      this.directedGraph.addVertex(modelGraph.getModel());
      DefaultGraphCell modelCell = this.m_jgAdapter.getVertexCell(modelGraph
          .getModel());
      Vector<DefaultGraphCell> group = new Vector<DefaultGraphCell>();
      group.add(modelCell);

      HashMap<Object, Object> map = new HashMap<Object, Object>();
      for (int i = 0; i < modelGraph.getChildren().size(); i++) {
        ModelGraph child = modelGraph.getChildren().get(i);
        DefaultGraphCell curCell = addGroups(child, nested, state);
        group.add(curCell);
        Rectangle2D bounds = (Rectangle2D) ((Map<Object, Object>) nested
            .get(curCell)).get("bounds");
        if (bounds.getX() < top_x)
          top_x = bounds.getX();
        if (bounds.getY() < top_y)
          top_y = bounds.getY();
        if (bounds.getMaxX() > bottom_x)
          bottom_x = bounds.getMaxX();
        if (bounds.getMaxY() > bottom_y)
          bottom_y = bounds.getMaxY();
      }

      map.put(GraphConstants.BOUNDS, new AttributeMap.SerializableRectangle2D(
          top_x - 5, top_y - 20, bottom_x - top_x + 10, bottom_y - top_y + 25));
      map.put(GraphConstants.FOREGROUND, Color.black);
      if (modelGraph.getModel().isRef())
        map.put(GraphConstants.BACKGROUND, Color.lightGray);
      else
        map.put(GraphConstants.BACKGROUND, Color.white);
      if (modelGraph.isExcused())
        map.put(GraphConstants.GRADIENTCOLOR, Color.gray);
      map.put(GraphConstants.HORIZONTAL_ALIGNMENT, SwingConstants.LEFT);
      map.put(GraphConstants.VERTICAL_ALIGNMENT, SwingConstants.TOP);
      map.put(GraphConstants.BORDER, new LineBorder(modelGraph.getModel()
          .getColor(), 1));
      jgraph.getGraphLayoutCache().toBack(new Object[] { modelCell });
      nested.put(modelCell, map);
      return modelCell;
    }
    DefaultGraphCell cell = this.m_jgAdapter.getVertexCell(modelGraph
        .getModel());
    ((Map<Object, Object>) nested.get(cell)).put(GraphConstants.FOREGROUND,
        Color.black);
    if (modelGraph.isExcused())
      ((Map<Object, Object>) nested.get(cell)).put(
View Full Code Here

  public DefaultGraphCell getVertexCell(ModelNode node) {
    if (cellMap.get(node.getId()) != null) {
      return cellMap.get(node.getId());
    }

    DefaultGraphCell cell = new DefaultGraphCell(node);
    cell.add(new DefaultPort());
    return cell;
  }
View Full Code Here

    }

  }

  private void addJGraphVertex(ModelNode node) {
    DefaultGraphCell cell = new DefaultGraphCell(node);
    cell.add(new DefaultPort());
    insert(new Object[] { cell }, getVertexAttributes(cell), null, null, null);
    cellMap.put(node.getId(), cell);
  }
View Full Code Here

  }

  private void addJGraphEdge(IdentifiableEdge e) {
    ConnectionSet set = new ConnectionSet();
    DefaultEdge theEdge = new DefaultEdge(e);
    DefaultGraphCell from = null;
    DefaultGraphCell to = null;
    String fromVertexId = e.getFrom().getId();
    String toVertexId = e.getTo().getId();
    if (!cellMap.containsKey(fromVertexId)) {
      addJGraphVertex(e.getFrom());
    }
    from = cellMap.get(fromVertexId);

    if (!cellMap.containsKey(toVertexId)) {
      addJGraphVertex(e.getTo());
    }

    to = cellMap.get(toVertexId);

    set.connect(theEdge, (DefaultPort) from.getChildAt(0),
        (DefaultPort) to.getChildAt(0));
    insert(new Object[] { theEdge }, getEdgeAttributes(theEdge), set, null,
        null);
  }
View Full Code Here

    if (cellObject instanceof DefaultEdge)
      return false;
    else if (cellObject instanceof DefaultPort)
      return false;
    else if (cellObject instanceof DefaultGraphCell) {
      DefaultGraphCell defaultGraphCell = (DefaultGraphCell) cellObject;
      AttributeMap attributes = defaultGraphCell.getAttributes();
      String type = (String) attributes.get(CELL_TYPE_KEY);
      if (type != null && type.equals(CELL_TYPE_ACTION))
        return true;
      else
        return false;
View Full Code Here

TOP

Related Classes of org.jgraph.graph.DefaultGraphCell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.