private void setVertexColor(Object vertex, Color color) {

    DefaultGraphCell cell = m_jgAdapter.getVertexCell(vertex);
    AttributeMap attr = cell.getAttributes();

    GraphConstants.setBackground(attr, color);

    AttributeMap cellAttr = new AttributeMap();

    cellAttr.put(cell, attr);

    m_jgAdapter.edit(cellAttr, null, null, null);
  }
  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);
  }
示例#3
0
    /**
     * Filters a list of vertices out of an array of JGraph GraphCell objects. Other objects are
     * thrown away.
     *
     * @param cells Array of cells to be filtered.
     * @return a list of vertices.
     */
    private List<Object> filterVertices(Object[] cells) {
      List<Object> jVertices = new ArrayList<Object>();

      for (int i = 0; i < cells.length; i++) {
        Object cell = cells[i];

        if (cell instanceof org.jgraph.graph.Edge) {
          // ignore -- we don't care about edges.
        } else if (cell instanceof Port) {
          // ignore -- we don't care about ports.
        } else if (cell instanceof DefaultGraphCell) {
          DefaultGraphCell graphCell = (DefaultGraphCell) cell;

          // If a DefaultGraphCell has a Port as a child, it is a
          // vertex.
          // Note: do not change the order of following conditions;
          // the code uses the short-circuit evaluation of ||.
          if (graphCell.isLeaf() || (graphCell.getFirstChild() instanceof Port)) {
            jVertices.add(cell);
          }
        } else if (cell instanceof GraphCell) {
          // If it is not a DefaultGraphCell, it doesn't have
          // children.
          jVertices.add(cell);
        }
      }

      return jVertices;
    }
示例#4
0
  /**
   * Adds the specified JGraphT vertex to be reflected by this graph model. To be called only for
   * edges that already exist in the JGraphT graph.
   *
   * @param jtVertex a JGraphT vertex to be reflected by this graph model.
   */
  void handleJGraphTAddedVertex(V jtVertex) {
    DefaultGraphCell vertexCell = cellFactory.createVertexCell(jtVertex);
    vertexCell.add(new DefaultPort());

    vertexToCell.put(jtVertex, vertexCell);
    cellToVertex.put(vertexCell, jtVertex);

    internalInsertCell(vertexCell, createVertexAttributeMap(vertexCell), null);
  }
示例#5
0
  /**
   * Returns the JGraph port cell that corresponds to the specified JGraphT vertex. If no
   * corresponding port found, returns <code>null</code>.
   *
   * @param jGraphTVertex a JGraphT vertex of the JGraphT graph.
   * @return the JGraph port cell that corresponds to the specified JGraphT vertex, or <code>null
   *     </code> if no corresponding cell found.
   */
  public DefaultPort getVertexPort(Object jGraphTVertex) {
    DefaultGraphCell vertexCell = getVertexCell(jGraphTVertex);

    if (vertexCell == null) {
      return null;
    } else {
      return (DefaultPort) vertexCell.getChildAt(0);
    }
  }
示例#6
0
  /**
   * Removes the specified JGraphT vertex from being reflected by this graph model. To be called
   * only for vertices that have already been removed from the JGraphT graph.
   *
   * @param jtVertex a JGraphT vertex to be removed from being reflected by this graph model.
   */
  void handleJGraphTRemoveVertex(Object jtVertex) {
    DefaultGraphCell vertexCell = (DefaultGraphCell) vertexToCell.remove(jtVertex);
    cellToVertex.remove(vertexCell);

    List<Object> ports = new ArrayList<Object>();

    for (Object child : vertexCell.getChildren()) {
      if (this.isPort(child)) {
        ports.add(child);
      }
    }
    this.remove(ports.toArray());

    internalRemoveCell(vertexCell);
  }
  protected Vector<AbstractAction> createChangeViewActions(
      final DefaultGraphCell cell, final ModelJGraph graph) {
    Vector<AbstractAction> possibleViews = new Vector<AbstractAction>();
    final ingenias.editor.entities.Entity ent =
        ((ingenias.editor.entities.Entity) cell.getUserObject());

    if (ent.getClass().getName().equals("ingenias.editor.entities.TestingPackage")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.TestingPackage")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DeploymentPackage")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DeploymentPackage")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.SimulationPackage")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.SimulationPackage")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.INGENIASComponent")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.INGENIASComponent")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.Application")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.Application")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.EnvironmentApplication")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.EnvironmentApplication")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.InternalApplication")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.InternalApplication")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.UMLComment")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.UMLComment")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DeploymentUnitByType")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DeploymentUnitByType")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass()
        .getName()
        .equals("ingenias.editor.entities.DeploymentUnitByTypeEnumInitMS")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass()
        .getName()
        .equals("ingenias.editor.entities.DeploymentUnitByTypeEnumInitMS")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DeploymentUnitByTypeMSEntity")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.UML;
      possibleViews.add(
          new AbstractAction("UML") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.UML);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.UML);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DeploymentUnitByTypeMSEntity")) {
      final ViewPreferences.ViewType current1 = ViewPreferences.ViewType.INGENIAS;
      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ent.getPrefs().setView(ViewPreferences.ViewType.INGENIAS);
              // ingenias.editor.cell.TextUseCaseRenderer.setCurrent(ViewPreferences.ViewType.INGENIAS);
              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.UMLAnnotatedElement")) {

      possibleViews.add(
          new AbstractAction("NOICON") {
            public void actionPerformed(ActionEvent e) {
              ingenias.editor.cell.RenderComponentManager.setRelationshipView(
                  ViewPreferences.ViewType.NOICON, ent, cell, graph);

              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.UMLAnnotatedElement")) {

      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ingenias.editor.cell.RenderComponentManager.setRelationshipView(
                  ViewPreferences.ViewType.INGENIAS, ent, cell, graph);

              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.UMLAnnotatedElement")) {

      possibleViews.add(
          new AbstractAction("LABEL") {
            public void actionPerformed(ActionEvent e) {
              ingenias.editor.cell.RenderComponentManager.setRelationshipView(
                  ViewPreferences.ViewType.LABEL, ent, cell, graph);

              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DefinesDeployment")) {

      possibleViews.add(
          new AbstractAction("NOICON") {
            public void actionPerformed(ActionEvent e) {
              ingenias.editor.cell.RenderComponentManager.setRelationshipView(
                  ViewPreferences.ViewType.NOICON, ent, cell, graph);

              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DefinesDeployment")) {

      possibleViews.add(
          new AbstractAction("INGENIAS") {
            public void actionPerformed(ActionEvent e) {
              ingenias.editor.cell.RenderComponentManager.setRelationshipView(
                  ViewPreferences.ViewType.INGENIAS, ent, cell, graph);

              graph.repaint();
            }
          });
    }

    if (ent.getClass().getName().equals("ingenias.editor.entities.DefinesDeployment")) {

      possibleViews.add(
          new AbstractAction("LABEL") {
            public void actionPerformed(ActionEvent e) {
              ingenias.editor.cell.RenderComponentManager.setRelationshipView(
                  ViewPreferences.ViewType.LABEL, ent, cell, graph);

              graph.repaint();
            }
          });
    }

    return possibleViews;
  }