private void positionVertexAt(Object vertex, int x, int y) {

    DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex);
    AttributeMap attr = cell.getAttributes();
    Rectangle2D b = GraphConstants.getBounds(attr);

    Rectangle2D newBounds = new Rectangle2D.Double(x, y, 5, 5);
    GraphConstants.setBounds(attr, newBounds);

    AttributeMap cellAttr = new AttributeMap();

    cellAttr.put(cell, attr);

    m_jgAdapter.edit(cellAttr, null, null, null);
  }
  /**
   * Sets new value to horizontal and vertical positions
   *
   * @param x
   * @param y
   */
  public void setPosition(Point point) {

    Map attrs = new Hashtable();
    GraphConstants.setBounds(
        attrs,
        new Rectangle2D.Double(point.getX(), point.getY(), getDefaultWidth(), getDefaultHeight()));

    graph.getGraphLayoutCache().editCell(this, attrs);

    graph.repaint();
  }
  /**
   * Creates and returns a map of attributes to be used as defaults for vertex attributes.
   *
   * @return a map of attributes to be used as defaults for vertex attributes.
   */
  public static AttributeMap createDefaultVertexAttributes() {
    AttributeMap map = new AttributeMap();
    Color c = Color.decode("#FF9900");

    GraphConstants.setBounds(map, new Rectangle2D.Double(50, 50, 90, 30));
    GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder());
    GraphConstants.setBackground(map, c);
    GraphConstants.setForeground(map, Color.white);
    GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12));
    GraphConstants.setOpaque(map, true);

    return map;
  }
  @SuppressWarnings("unchecked")
  private void positionVertexAt(Object vertex, int x, int y) {
    DefaultGraphCell cell = m_jgAdapter_.getVertexCell(vertex);
    AttributeMap attr = cell.getAttributes();
    Rectangle2D bounds = GraphConstants.getBounds(attr);

    Rectangle2D newBounds = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());

    GraphConstants.setBounds(attr, newBounds);

    // TODO: Clean up generics once JGraph goes generic
    AttributeMap cellAttr = new AttributeMap();
    cellAttr.put(cell, attr);
    m_jgAdapter_.edit(cellAttr, null, null, null);
  }
Exemple #5
0
  /**
   * 往流程图编辑器中增加一个元素
   *
   * @param ele
   */
  public DefaultGraphCell insertFlowElement(FlowElementObject ele) {
    if (this.graph == null) return null;

    if (ele.getId() == 0) {

      int id = (new IDService()).getProcessID();
      ele.setId(id);
    }
    DefaultGraphCell cell = new DefaultGraphCell();

    cell.setUserObject(ele);

    if (ele.getImageResource() != null) {
      GraphConstants.setIcon(cell.getAttributes(), UIUtil.loadImageIcon(ele.getImageResource()));
    }

    // 自动设置大小
    // GraphConstants.setAutoSize(cell.getAttributes(), true);
    GraphConstants.setOpaque(cell.getAttributes(), true);
    // GraphConstants.setBackground(cell.getAttributes(), Color.YELLOW);
    GraphConstants.setLineColor(cell.getAttributes(), Color.RED);
    GraphConstants.setLineWidth(cell.getAttributes(), 1.5f);
    GraphConstants.setLineStyle(cell.getAttributes(), GraphConstants.STYLE_SPLINE);
    // GraphConstants.setSizeable(cell.getAttributes(),false);

    GraphConstants.setBorder(
        cell.getAttributes(), BorderFactory.createLineBorder(Color.BLACK)); // 外框颜色

    // GraphConstants.setBounds(cell.getAttributes(), new
    // Rectangle2D.Double(
    // 10, 10, 80, 40));
    GraphConstants.setBounds(
        cell.getAttributes(),
        new Rectangle2D.Double(
            ele.getLeft().doubleValue(),
            ele.getTop().doubleValue(),
            ele.getWidth().doubleValue(),
            ele.getHeight().doubleValue()));

    GraphConstants.setEditable(cell.getAttributes(), false);
    cell.addPort();

    this.graph.getGraphLayoutCache().insert(cell); // 向图形编辑器写入处理后的图片.

    return cell;
  }
  @Override
  public AttributeMap getDefaultVertexAttributes() {
    AttributeMap map = new AttributeMap();

    // we set the bounds only to force the layout manager to use minimum size shapes
    // this way the auto sizing mechanism will immediately generate the optimum sized shapes
    // TODO I am not sure how exactly setBounds(...) works with setAutoSize(...)
    GraphConstants.setBounds(map, new Rectangle2D.Double(0, 0, 100, 100));
    GraphConstants.setAutoSize(map, true);
    GraphConstants.setBackground(map, Color.LIGHT_GRAY);
    GraphConstants.setForeground(map, Color.BLACK);
    GraphConstants.setOpaque(map, true);
    //		GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12));
    GraphConstants.setBorderColor(map, Color.black);

    // we want to have the nodes represented as circles
    // but, the auto size property overrides this and
    // ellipses are created
    CellConstants.setVertexShape(map, MultiLineVertexRenderer.SHAPE_CIRCLE);

    return map;
  }