Package org.jgraph.graph

Examples of org.jgraph.graph.DefaultGraphCell


  public void group(Object[] cells) {
    // Order Cells by Model Layering
    cells = graph.order(cells);
    // If Any Cells in View
    if (cells != null && cells.length > 0) {
      DefaultGraphCell group = createGroupCell();
      // Insert into model
      graph.getGraphLayoutCache().insertGroup(group, cells);
    }
  }
View Full Code Here


    }
  }

  // Hook for subclassers
  protected DefaultGraphCell createGroupCell() {
    return new DefaultGraphCell();
  }
View Full Code Here

        .deriveFont(10));
    //
    // The Swing MVC Pattern
    //
    // Model Column
    DefaultGraphCell gm = new DefaultGraphCell("GraphModel");
    attributes.put(gm,
        createBounds(new AttributeMap(), 20, 100, Color.blue));
    gm.add(new DefaultPort("GraphModel/Center"));
    DefaultGraphCell dgm = new DefaultGraphCell("DefaultGraphModel");
    attributes.put(dgm, createBounds(new AttributeMap(), 20, 180,
        Color.blue));
    dgm.add(new DefaultPort("DefaultGraphModel/Center"));
    DefaultEdge dgmImplementsGm = new DefaultEdge("implements");
    cs.connect(dgmImplementsGm, gm.getChildAt(0), dgm.getChildAt(0));
    attributes.put(dgmImplementsGm, implementStyle);
    DefaultGraphCell modelGroup = new DefaultGraphCell("ModelGroup");
    modelGroup.add(gm);
    modelGroup.add(dgm);
    modelGroup.add(dgmImplementsGm);
    // JComponent Column
    DefaultGraphCell jc = new DefaultGraphCell("JComponent");
    attributes.put(jc, createBounds(new AttributeMap(), 150, 20,
        Color.green));
    jc.add(new DefaultPort("JComponent/Center"));
    DefaultGraphCell jg = new DefaultGraphCell("JGraph");
    attributes.put(jg, createBounds(new AttributeMap(), 150, 100,
        Color.green));
    jg.add(new DefaultPort("JGraph/Center"));
    DefaultEdge jgExtendsJc = new DefaultEdge("extends");
    cs.connect(jgExtendsJc, jc.getChildAt(0), jg.getChildAt(0));
    attributes.put(jgExtendsJc, extendStyle);
    // UI Column
    DefaultGraphCell cu = new DefaultGraphCell("ComponentUI");
    attributes
        .put(cu, createBounds(new AttributeMap(), 280, 20, Color.red));
    cu.add(new DefaultPort("ComponentUI/Center"));
    DefaultGraphCell gu = new DefaultGraphCell("GraphUI");
    attributes.put(gu,
        createBounds(new AttributeMap(), 280, 100, Color.red));
    gu.add(new DefaultPort("GraphUI/Center"));
    DefaultGraphCell dgu = new DefaultGraphCell("BasicGraphUI");
    attributes.put(dgu, createBounds(new AttributeMap(), 280, 180,
        Color.red));
    dgu.add(new DefaultPort("BasicGraphUI/Center"));
    DefaultEdge guExtendsCu = new DefaultEdge("extends");
    cs.connect(guExtendsCu, cu.getChildAt(0), gu.getChildAt(0));
    attributes.put(guExtendsCu, extendStyle);
    DefaultEdge dguImplementsDu = new DefaultEdge("implements");
    cs.connect(dguImplementsDu, gu.getChildAt(0), dgu.getChildAt(0));
    attributes.put(dguImplementsDu, implementStyle);
    DefaultGraphCell uiGroup = new DefaultGraphCell("UIGroup");
    uiGroup.add(cu);
    uiGroup.add(gu);
    uiGroup.add(dgu);
    uiGroup.add(dguImplementsDu);
    uiGroup.add(guExtendsCu);
    // Aggregations
    DefaultEdge jgAggregatesGm = new DefaultEdge("model");
    cs.connect(jgAggregatesGm, jg.getChildAt(0), gm.getChildAt(0));
    attributes.put(jgAggregatesGm, aggregateStyle);
    DefaultEdge jcAggregatesCu = new DefaultEdge("ui");
View Full Code Here

  public static DefaultGraphCell createVertex(String name, double x,
      double y, double w, double h, Color bg, boolean raised,int type) {

      // Create vertex with the given name
    DefaultGraphCell cell =null;
    if(type==0)
      cell = new WsGraphCell(name);   
    else
      cell = new WcGraphCell(name);

      // Set bounds
      GraphConstants.setBounds(cell.getAttributes(),
          new Rectangle2D.Double(x, y, w, h));

      //horizontalTextPosition
      GraphConstants.setHorizontalAlignment(cell.getAttributes(), SwingConstants.RIGHT);//Color.orange
      GraphConstants.setVerticalAlignment(cell.getAttributes(), SwingConstants.BOTTOM);//Color.orange
     
      // Set fill color
      if (bg != null) {
        GraphConstants.setGradientColor(
          cell.getAttributes(), bg);//Color.orange
        GraphConstants.setOpaque(
          cell.getAttributes(), true);
      }

      // Set raised border
      if (raised)
        GraphConstants.setBorder(
          cell.getAttributes(),
          BorderFactory.createRaisedBevelBorder());
      else
        // Set black border
        GraphConstants.setBorderColor(
          cell.getAttributes(), Color.black);

      // Add a Port
      DefaultPort port = new DefaultPort();
      cell.add(port);
      port.setParent(cell);

      return cell;
    }
View Full Code Here

   * @param node
   */
  public void updateNode(IWs node) {
    DefaultGraphModel model = (DefaultGraphModel)jGraphMain.getModel();
    List theRoots = model.getRoots();
    DefaultGraphCell selectedElement=null;
    findNode(node.getName());
   
    System.out.println();
  }
View Full Code Here

   */
  public DefaultGraphCell findNode(String nodeName) {
    System.out.println("FindNode "+nodeName);
    DefaultGraphModel model = (DefaultGraphModel)jGraphMain.getModel();
    List theRoots = model.getRoots();
    DefaultGraphCell selectedElement;
    for (Iterator iter = theRoots.iterator(); iter.hasNext();) {
      DefaultGraphCell element = (DefaultGraphCell) iter.next();
        if(element.toString()!=null)
          if(element.toString().equals(nodeName)){
          // Update this node
            return element;
          }           
    }
    return null;
View Full Code Here

    }
    return null;
  }

  public void setCurrentWc(String name){
    DefaultGraphCell wcCell=findNode("Wc");
    DefaultGraphCell wsCell=findNode(name);
   
    if(wcCell==null||wsCell==null
      return;
   
    DefaultPort zeroChild = (DefaultPort)wcCell.getChildAt(0);
    Set edges = zeroChild.getEdges();
    DefaultEdge edge1=(DefaultEdge)edges.iterator().next();

    DefaultGraphModel model = (DefaultGraphModel)jGraphMain.getModel();
    model.remove(new Object[]{edge1});
   
    // Create Edge
      DefaultEdge edge = new DefaultEdge();
    int arrow = GraphConstants.ARROW_CLASSIC;
    GraphConstants.setLineEnd(edge.getAttributes(), arrow);
    GraphConstants.setEndFill(edge.getAttributes(), true);
    setLineAttribs(edge);

      // Create ConnectionSet for Insertion
      ConnectionSet cs = new ConnectionSet(edge, wcCell.getChildAt(0), wsCell.getChildAt(0));

      // Add Edge and Connections to the Model
      Object[] insert = new Object[]{edge};
      model.insert(insert, null,cs, null, null);
View Full Code Here

  }

  public void setColor(final String name, final Color color){
   
    //jGraphMain.set
    DefaultGraphCell wsCell=findNode(name);
    jGraphMain.startEditingAtCell(wsCell);
    if(wsCell!=null){
      AttributeMap attribs = wsCell.getAttributes();
      attribs.put("gradientColor",color);
      wsCell.changeAttributes(attribs);
      System.err.println("SetColor "+name+" "+color);
    }
    jGraphMain.stopEditing();
    jGraphMain.clearSelection();
    //setCurrentWc(name);
View Full Code Here

    jg.setBackground(c);
  }

  private void positionVertexAt(Object vertex, int x, int y,
      JGraphModelAdapter<String, String> m_jgAdapter) {
    DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex);
    Map attr = cell.getAttributes();
    Rectangle2D b = GraphConstants.getBounds(attr);

    GraphConstants.setBounds(attr, new Rectangle(x, y, (int) b.getWidth(),
        (int) b.getHeight()));
View Full Code Here

   * @param vertex Vertex to be positioned
   * @param x x coordinate
   * @param y y coordinate
   */
  protected void positionVertexAt(Object vertex, int x, int y) {
    DefaultGraphCell cell = jgAdapter.getVertexCell(vertex);
    AttributeMap attr = cell.getAttributes();
    Rectangle2D bounds = GraphConstants.getBounds(attr);

    positionVertexAt(vertex, x, y, bounds.getWidth(), bounds.getHeight());
  }
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.