Package org.jgraph.graph

Examples of org.jgraph.graph.GraphModel


public class HelloWorld {

  public static void main(String[] args) {

    // Construct Model and Graph
    GraphModel model = new DefaultGraphModel();
    JGraph graph = new JGraph(model);

    // Control-drag should clone selection
    graph.setCloneable(true);
View Full Code Here


   *
   * @param newModel
   *            the <code>GraphModel</code> that is to provide the data
   */
  public void setModel(GraphModel newModel) {
    GraphModel oldModel = graphModel;
    graphModel = newModel;
    firePropertyChange(GRAPH_MODEL_PROPERTY, oldModel, graphModel);
    // FIX: Use Listener
    if (graphLayoutCache != null
        && graphLayoutCache.getModel() != graphModel)
View Full Code Here

  /**
   *
   */
  private void emptyGraph() {
    //GraphModel model = jGraphMain.getModel();
    GraphModel model = new DefaultGraphModel();
    jGraphMain.setModel(model);       
   
  }
View Full Code Here

  /**
   * @param wc
   */
  public void setModel(IWs[] wsArry) {   
    //GraphModel model = jGraphMain.getModel();
    GraphModel model = new DefaultGraphModel();
    jGraphMain.setModel(model);
   
   
   
    // Insert all three cells in one call, so we need an
View Full Code Here

    boolean intersecato = false;
    boolean sharedTheSameSourceTarget = false;
    if ((sourceOfEdge2 != null && sourceOfEdge1 != null) && (sourceOfEdge2.equals(sourceOfEdge1) || targetOfEdge1.equals(targetOfEdge2))) {
      sharedTheSameSourceTarget = true;

      GraphModel graphmodel = mediator.getGraph().getModel();
      Object[] listEdgesIn = null;
      Object[] listEdgesOut = null;
      if (targetOfEdge1.equals(targetOfEdge2)) {
        sourcesame = true;
View Full Code Here

    JmtCell sourceOfEdge = (JmtCell) ((DefaultPort) this.getSource()).getParent();
    Rectangle boundsSource = GraphConstants.getBounds(sourceOfEdge.getAttributes()).getBounds();
    JmtCell targetOfEdge = (JmtCell) ((DefaultPort) this.getTarget()).getParent();
    Rectangle boundsTarget = GraphConstants.getBounds(targetOfEdge.getAttributes()).getBounds();
    Object[] listEdges = null;
    GraphModel graphmodel = mediator.getGraph().getModel();
    //    System.out.println("Padre: "+targetOfEdge);
    Object[] fathers = (DefaultGraphModel.getIncomingEdges(graphmodel, targetOfEdge));
    int max = (int) boundsSource.getMaxX();
    for (Object father : fathers) {
      //      System.out.println("Dentro il for");
View Full Code Here

          }

        }
        Object[] listEdgesIn = null;
        Object[] listEdgesOut = null;
        GraphModel graphmodel = mediator.getGraph().getModel();
        listEdgesIn = DefaultGraphModel.getEdges(graphmodel, cells2[i], true);
        listEdgesOut = DefaultGraphModel.getEdges(graphmodel, cells2[i], false);

        for (int j = 0; j < listEdgesIn.length; j++) {
          if (!listEdges2.contains(listEdgesIn[j])) {
View Full Code Here

      Vector<Object> celle = new Vector<Object>();
      for (int x = 0; x < celletmp.length; x++) {
        if (!(celletmp[x] == vertex) && !((vertex.getChildren()).contains(celletmp[x])) && !(celletmp[x] == edge)) {
          Object[] listEdgesIn = null;
          Object[] listEdgesOut = null;
          GraphModel graphmodel = mediator.getGraph().getModel();
          listEdgesIn = DefaultGraphModel.getEdges(graphmodel, vertex, true);
          listEdgesOut = DefaultGraphModel.getEdges(graphmodel, vertex, false);
          boolean edgeIn = false;
          boolean edgeOut = false;
          for (Object element : listEdgesIn) {
            if (celletmp[x] instanceof JmtEdge && element.equals(celletmp[x])) {
              edgeIn = true;
            }
          }
          for (Object element : listEdgesOut) {
            if (celletmp[x] instanceof JmtEdge && element.equals(celletmp[x])) {
              edgeIn = true;
            }
          }
          if ((listEdgesIn.length == 0 && listEdgesOut.length == 0) || (!edgeIn && !edgeOut)) {
            if (celletmp[x] instanceof JmtEdge) {
              JmtEdgeView viewtmp = (JmtEdgeView) (mediator.getGraph().getGraphLayoutCache()).getMapping(((celletmp[x])), false);
              if (((JmtEdge) celletmp[x]).intersects(viewtmp, newRett)) {
                celle.add(celletmp[x]);
              }
            } else {
              celle.add(celletmp[x]);
            }
          }
        }
      }
      Object[] celletmp3 = (mediator.getGraph()).getDescendants(mediator.getGraph().getRoots(newRettDown));
      Vector<Object> celle2 = new Vector<Object>();
      for (int x = 0; x < celletmp3.length; x++) {
        if (!(celletmp3[x] == vertex) && !((vertex.getChildren()).contains(celletmp3[x])) && !(celletmp3[x] == edge)) {
          if (celletmp3[x] instanceof JmtEdge) {
            JmtEdgeView viewtmp = (JmtEdgeView) (mediator.getGraph().getGraphLayoutCache()).getMapping(((celletmp3[x])), false);
            if (((handledEdges.size() == 0) || (handledEdges.size() > 0 && !handledEdges.contains(celletmp3[x])))
                && ((JmtEdge) celletmp3[x]).intersects(viewtmp, newRettDown)) {
              celle2.add(celletmp3[x]);
            }
          } else {
            celle2.add(celletmp3[x]);
          }
        }

      }
      if (celle.size() > 0 && celle2.size() == 0) {
        if (((int) newRettDown.getMinX() < 20) || ((int) newRettDown.getMinY() < 0)) {
          return new Point((int) cellBound.getMinX(), (int) cellBound.getMinY());
        }
        return new Point((int) newRettDown.getMinX(), (int) newRettDown.getMinY());
      } else if (celle.size() == 0) {
        if (((int) newRettUp.getMinX() < 20) || ((int) newRettUp.getMinY() < 0)) {
          return new Point((int) cellBound.getMinX(), (int) cellBound.getMinY());
        }
        return new Point((int) newRettUp.getMinX(), (int) newRettUp.getMinY());
      } else if (celle.size() > 0 && celle2.size() > 0) {

        return new Point((int) cellBound.getMinX(), (int) cellBound.getMinY());

      }
      pointBack = new Point((int) vertexMinX, pointYToMove);

    } //END IF to move the vertex UP

    //BEGIN IF to move the vertex RIGHT
    else if (!down && !up && !left && right) {

      int pointXToMove = (int) (tmp.getX() + 12);
      Rectangle newRett = new Rectangle(pointXToMove, (int) vertexMinY, (int) vertexWidth, (int) vertexHeight);
      Object[] celletmp = (mediator.getGraph()).getDescendants(mediator.getGraph().getRoots(newRett));
      Vector<Object> celle = new Vector<Object>();

      for (int x = 0; x < celletmp.length; x++) {//BEGIN FOR

        if (!(celletmp[x] == vertex) && !((vertex.getChildren()).contains(celletmp[x])) && !(celletmp[x] == edge)) {

          Object[] listEdgesIn = null;
          Object[] listEdgesOut = null;
          GraphModel graphmodel = mediator.getGraph().getModel();
          listEdgesIn = DefaultGraphModel.getEdges(graphmodel, vertex, true);
          listEdgesOut = DefaultGraphModel.getEdges(graphmodel, vertex, false);
          boolean edgeIn = false;
          boolean edgeOut = false;

          for (Object element : listEdgesIn) {
            if (celletmp[x] instanceof JmtEdge && element.equals(celletmp[x])) {
              edgeIn = true;
            }
          }
          for (Object element : listEdgesOut) {
            if (celletmp[x] instanceof JmtEdge && element.equals(celletmp[x])) {
              edgeIn = true;
            }
          }

          if ((listEdgesIn.length == 0 && listEdgesOut.length == 0) || (!edgeIn && !edgeOut)) {
            if (!(celletmp[x] == vertex) && !((vertex.getChildren()).contains(celletmp[x])) && !(celletmp[x] == edge)) {
              if (celletmp[x] instanceof JmtEdge) {
                JmtEdgeView viewtmp = (JmtEdgeView) (mediator.getGraph().getGraphLayoutCache()).getMapping(((celletmp[x])), false);
                if (((handledEdges.size() == 0) || (handledEdges.size() > 0 && !handledEdges.contains(celletmp[x])))
                    && ((JmtEdge) celletmp[x]).intersects(viewtmp, newRett)) {
                  celle.add(celletmp[x]);
                }
              } else {
                celle.add(celletmp[x]);
              }

            }

          }
        }
      }//END FOR

      Object[] celletmp3 = (mediator.getGraph()).getDescendants(mediator.getGraph().getRoots(newRettLeft));
      Vector<Object> celle3 = new Vector<Object>();
      for (int x = 0; x < celletmp3.length; x++) {

        if (!(celletmp3[x] == vertex) && !((vertex.getChildren()).contains(celletmp3[x])) && !(celletmp3[x] == edge)) {
          if (celletmp3[x] instanceof JmtEdge) {
            JmtEdgeView viewtmp = (JmtEdgeView) (mediator.getGraph().getGraphLayoutCache()).getMapping(((celletmp3[x])), false);
            if (((handledEdges.size() == 0) || (handledEdges.size() > 0 && !handledEdges.contains(celletmp3[x])))
                && ((JmtEdge) celletmp3[x]).intersects(viewtmp, newRettLeft)) {
              celle3.add(celletmp3[x]);
            }
          } else {
            celle3.add(celletmp3[x]);
          }
        }
      }

      if (celle.size() > 0 && celle3.size() == 0) {
        if (((int) cellBound.getMinX() < 20) || ((int) cellBound.getMinY() < 0)) {
          return new Point((int) cellBound.getMinX(), (int) cellBound.getMinY());
        }
        return new Point((int) newRettLeft.getMinX(), (int) newRettLeft.getMinY());
      } else if (celle.size() == 0) {
        if (((int) cellBound.getMinX() < 20) || ((int) cellBound.getMinY() < 0)) {
          return new Point((int) cellBound.getMinX(), (int) cellBound.getMinY());
        }
        return new Point((int) newRett.getMinX(), (int) newRett.getMinY());
      } else if (celle.size() > 0 && celle3.size() > 0) {

        return new Point((int) cellBound.getMinX(), (int) cellBound.getMinY());
      }
      pointBack = new Point(pointXToMove, (int) vertexMinY);
    }//END IF to move the vertex RIGHT

    //BEGIN IF to move the vertex LEFT
    else if (!down && !up && left && !right) {

      int pointXToMove = (int) (vertexMaxX - tmp.getX());
      int point2XToMove = (int) (vertexMinX - pointXToMove) - 12;
      if (point2XToMove < 0) {
        point2XToMove = (int) (tmp.getX() + 12);
      }
      Rectangle newRett = new Rectangle(point2XToMove, (int) vertexMinY, (int) vertexWidth, (int) vertexHeight);
      Object[] celletmp = (mediator.getGraph()).getDescendants(mediator.getGraph().getRoots(newRett));
      Vector<Object> celle = new Vector<Object>();
      for (int x = 0; x < celletmp.length; x++) {

        if (!(celletmp[x] == vertex) && !((vertex.getChildren()).contains(celletmp[x])) && !(celletmp[x] == edge)) {
          Object[] listEdgesIn = null;
          Object[] listEdgesOut = null;
          GraphModel graphmodel = mediator.getGraph().getModel();
          listEdgesIn = DefaultGraphModel.getEdges(graphmodel, vertex, true);
          listEdgesOut = DefaultGraphModel.getEdges(graphmodel, vertex, false);
          boolean edgeIn = false;
          boolean edgeOut = false;
          for (Object element : listEdgesIn) {
View Full Code Here

   * Bertoli Marco 03-06-2005
   */
  public void deleteSelected() {
    Object cells[] = graph.getSelectionCells();
    GraphModel graphmodel = graph.getModel();

    // If a cell is a blocking region avoid removing its edges and
    // select its element at the end of the removal process
    Set edges = new HashSet();
    Set<Object> select = new HashSet<Object>();

    // Set with all regions that can be deleted as its child were removed
    Set<Object> regions = new HashSet<Object>();
    // Set with all JmtCells that we are removing
    Set<Object> jmtCells = new HashSet<Object>();

    // Giuseppe De Cicco & Fabio Granara
    // for(int k=0; k<cells.length; k++){
    // if(cells[k] instanceof JmtEdge){
    // ((JmtCell)(graphmodel.getParent(graphmodel.getSource((JmtEdge)cells[k])))).SubOut();
    // ((JmtCell)(graphmodel.getParent(graphmodel.getTarget((JmtEdge)cells[k])))).SubIn();
    // }
    //
    // }
    for (int i = 0; i < cells.length; i++) {
      if (!(cells[i] instanceof BlockingRegion)) {
        // Adds edge for removal
        edges.addAll(DefaultGraphModel.getEdges(graphmodel, new Object[] { cells[i] }));
        // Giuseppe De Cicco & Fabio Granara
        // quando vado a eliminare un nodo, a cui è collegato un arco,
        // vado ad incrementare o diminuire il contatore per il
        // pulsanteAGGIUSTATUTTO
        // Iterator iter = edges.iterator();
        // while (iter.hasNext()) {
        // Object next = iter.next();
        // if (next instanceof JmtEdge){
        // ((JmtCell)(graphmodel.getParent(graphmodel.getSource((JmtEdge)next)))).SubOut();
        // ((JmtCell)(graphmodel.getParent(graphmodel.getTarget((JmtEdge)next)))).SubIn();
        // }
        //
        // }
        // Stores parents information and cell
        if (cells[i] instanceof JmtCell) {
          if (((JmtCell) cells[i]).getParent() instanceof BlockingRegion) {
            regions.add(((JmtCell) cells[i]).getParent());
          }
          jmtCells.add(cells[i]);
        }
      } else {
        // Adds node for selection
        Object[] nodes = graph.getDescendants(new Object[] { cells[i] });
        for (Object node : nodes) {
          if (node instanceof JmtCell || node instanceof JmtEdge) {
            select.add(node);
          }
        }
        // Removes blocking region from data structure
        model.deleteBlockingRegion(((BlockingRegion) cells[i]).getKey());
      }
    }

    if (!edges.isEmpty()) {
      graphmodel.remove(edges.toArray());
    }
    // removes cells from graph
    graphmodel.remove(cells);

    // Checks if all children of a blocking region have been removed
    Iterator<Object> it = regions.iterator();
    while (it.hasNext()) {
      jmtCells.add(null);
      BlockingRegion region = (BlockingRegion) it.next();
      List child = region.getChildren();
      boolean empty = true;
      for (int i = 0; i < child.size(); i++) {
        if (child.get(i) instanceof JmtCell && !jmtCells.contains(child.get(i))) {
          empty = false;
          break;
        }
      }
      if (empty) {
        model.deleteBlockingRegion(region.getKey());
        graphmodel.remove(new Object[] { region });
      }
    }

    // Removes cells from data structure
    for (Object cell : cells) {
View Full Code Here

  // Giuseppe De Cicco & Fabio Granara
  private int searchNext(JmtCell prev) {
    Rectangle boundspadre = GraphConstants.getBounds((prev).getAttributes()).getBounds();
    Object[] listEdges = null;
    GraphModel graphmodel = graph.getModel();
    List<Object> next = new ArrayList<Object>();

    if (flag1 == false && prev.seen == false) {

      // Rectangle bounds =
      // GraphConstants.getBounds(((JmtCell)prev).getAttributes()).getBounds();
      if (!flag2) {
        boundspadre.setLocation(x, y + ((e + 1) * (42 + heightMax)) - (int) (boundspadre.getHeight() / 2) + 30);
      } else {
        boundspadre.setLocation(x - (int) (boundspadre.getWidth() / 2), y + ((e + 1) * (42 + heightMax))
            - (int) (boundspadre.getHeight() / 2) + 30);
      }

      GraphConstants.setBounds(prev.getAttributes(), boundspadre);
      x = (int) boundspadre.getCenterX() + widthMax + 50;
      prev.seen = true;
      flag2 = true;
    }

    // inserisco tutti gli archi uscenti e entranti di min.get(j) in
    // listEdges
    listEdges = DefaultGraphModel.getOutgoingEdges(graphmodel, prev);
    Vector<Object> listEdgestmp = new Vector<Object>();
    for (Object listEdge : listEdges) {
      JmtCell qq = (JmtCell) (graphmodel.getParent(graphmodel.getTarget(listEdge)));
      if (!(qq).seen) {
        listEdgestmp.add(listEdge);
      }
    }
    listEdges = listEdgestmp.toArray();

    int numTarget = listEdges.length;
    if (numTarget == 0) {
      return 1;
    }

    for (int k = 0; k < numTarget; k++) {
      next.add((graphmodel.getParent(graphmodel.getTarget(listEdges[k]))));
    }

    int j = 1;
    if (inRepositionSons == false && ((JmtCell) next.get(0)).seen == false) {
      j = searchNext((JmtCell) next.get(0));
View Full Code Here

TOP

Related Classes of org.jgraph.graph.GraphModel

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.