@SuppressWarnings("unchecked")
  private String roleToXML(Role role) {
    String xml = "\t<ROLE ID='" + role.getKey() + "'>\n";
    xml += "\t\t<TITLE>" + role.getName() + "</TITLE>\n";
    xml += "\t\t<COORDINATES>\n";
    Point2D coord = layout.transform(role);
    xml += "\t\t\t<X>" + coord.getX() + "</X>\n";
    xml += "\t\t\t<Y>" + coord.getY() + "</Y>\n";
    xml += "\t\t</COORDINATES>\n";

    if (graphMouse != null) {
      VertexAnnotation<Role, String> annotation =
          graphMouse.getAnnotatingPlugin().getAnnotation(role);
      System.out.println("Annotation: " + annotation);
      if (annotation != null)
        xml += "\t\t<ANNOTATION>" + annotation.getAnnotation() + "</ANNOTATION>\n";
    }

    Collection<Role> predecessors = getPredecessors(role);
    if (predecessors.size() > 0) {
      xml += "\t\t<SUPERIORS>\n";
      for (Role predecessor : predecessors) {
        xml +=
            "\t\t\t<SUPERIOR ID='"
                + predecessor.getKey()
                + "'>"
                + predecessor.getName()
                + "</SUPERIOR>\n";
      }
      xml += "\t\t</SUPERIORS>\n";
    }
    xml += "\t</ROLE>\n";
    return xml;
  }
Example #2
0
    /**
     * Changes the size of the underlying Layout.
     *
     * @param size The new size for the layout.
     */
    private void setSize(Dimension size) {
      ObservableCachingLayout<V, E> observableLayout = (ObservableCachingLayout) getGraphLayout();
      Layout<V, E> tmpLayout = observableLayout;
      while (!AbstractLayout.class.isAssignableFrom(tmpLayout.getClass()))
        tmpLayout = ((LayoutDecorator<V, E>) tmpLayout).getDelegate();
      AbstractLayout<V, E> layout = (AbstractLayout<V, E>) tmpLayout;

      // the first time the graph is resized, re-initialize the layout to make sure it gets
      // the right size.  Any other time, just scale it. The first resize should be when the
      // graph is made visible and laid out.
      // this is kind of a hack; there may be a better way to handle this.
      // I tried listening for componentShown, but it didn't work properly.
      if (layoutInitialized < 1) {
        layout.getSize().setSize(size);
        layout.initialize();
        layoutInitialized++;
        return;
      }

      // change the size of the layout without triggering the automatic resizing.
      double wScale = size.getWidth() / layout.getSize().getWidth();
      double hScale = size.getHeight() / layout.getSize().getHeight();
      double scale = Math.min(wScale, hScale);
      layout.getSize().setSize(size);
      Collection<V> vertices = new Vector(getVertices());
      synchronized (graph) {
        for (V v : vertices) {
          double x =
              layout.getX(v)
                  * scale; // Math.min( size.getWidth( ) - 10, Math.max( 10, layout.getX( v ) *
                           // scale ));
          double y =
              layout.getY(v)
                  * scale; // Math.min( size.getHeight( ) - 10, Math.max( 10, layout.getY( v ) *
                           // scale ));
          layout.setLocation(v, new Point2D.Double(x, y));
        }
      }
      // alert the ObservableLayout that things have changed.
      observableLayout.fireStateChanged();
    }