Package org.eclipse.zest.layouts.exampleStructures

Examples of org.eclipse.zest.layouts.exampleStructures.SimpleNode


      public void mouseMove(MouseEvent e) {

        if (selectedEntity == null) {
          // Nothing selected, lets use a mouse hover
          SimpleNode oldEntity = hoverEntity;
          hoverEntity = null;

          for (Iterator iter = entities.iterator(); iter.hasNext() && selectedEntity == null;) {
            SimpleNode entity = (SimpleNode) iter.next();
            double x = entity.getX();
            double y = entity.getY();
            double w = entity.getWidth();
            double h = entity.getHeight();
            Rectangle rect = new Rectangle((int) x, (int) y, (int) w, (int) h);
            if (rect.contains(e.x, e.y)) {
              hoverEntity = entity;
              hoverEntity.ignoreInLayout(true);
              hoverEntity.setSelected();
              break;
            }
          }
          if (oldEntity != null && oldEntity != hoverEntity) {
            oldEntity.ignoreInLayout(false);
            oldEntity.setUnSelected();
          }
        }

      }

    });
    mainComposite.addMouseListener(new MouseListener() {

      public void mouseDoubleClick(MouseEvent e) {
      }

      public void mouseDown(MouseEvent e) {
        selectedEntity = null;
        hoverEntity = null;
        for (Iterator iter = entities.iterator(); iter.hasNext() && selectedEntity == null;) {
          SimpleNode entity = (SimpleNode) iter.next();
          double x = entity.getX();
          double y = entity.getY();
          double w = entity.getWidth();
          double h = entity.getHeight();
          Rectangle rect = new Rectangle((int) x, (int) y, (int) w, (int) h);
          if (rect.contains(e.x, e.y)) {
            selectedEntity = entity;
          }
        }
        if (selectedEntity != null) {
          mouseDownPoint = new Point(e.x, e.y);
          selectedEntityPositionAtMouseDown = new Point((int) selectedEntity.getX(), (int) selectedEntity.getY());
          selectedEntity.ignoreInLayout(true);
          selectedEntity.setSelected();
        } else {
          mouseDownPoint = null;
          selectedEntityPositionAtMouseDown = null;
        }
      }

      public void mouseUp(MouseEvent e) {
        if (selectedEntity != null) {
          selectedEntity.ignoreInLayout(false);
          selectedEntity.setUnSelected();
          List relatedNodes = selectedEntity.getRelatedEntities();
          for (Iterator iter = relatedNodes.iterator(); iter.hasNext();) {
            SimpleNode element = (SimpleNode) iter.next();
            element.setUnSelected();
          }
          SimpleRelationship[] rels = selectedEntity.getRelationships();
          for (int i = 0; i < rels.length; i++) {
            rels[i].resetLineWidth();
          }
View Full Code Here


  private void createTreeGraph(int maxLevels, int maxChildren, boolean random) {
    entities = new ArrayList();
    relationships = new ArrayList();

    // ccallendar - testing out having 2 roots
    SimpleNode root = createSimpleNode(getNextID());
    entities.add(root);
    SimpleNode root2 = createSimpleNode(getNextID());
    entities.add(root2);
    // end

    SimpleNode currentParent = createSimpleNode(getNextID());
    entities.add(currentParent);

    // ccallendar - adding relationships from the parent to the 2 roots
    SimpleRelationship rel = new SimpleRelationship(root, currentParent, false);
    root.addRelationship(rel);
    currentParent.addRelationship(rel);
    relationships.add(rel);
    rel = new SimpleRelationship(root2, currentParent, false);
    root2.addRelationship(rel);
    currentParent.addRelationship(rel);
    relationships.add(rel);
    // end

    int levels = random ? (int) (Math.random() * maxLevels + 1) : maxLevels;
    createTreeGraphRecursive(currentParent, maxChildren, levels, 1, random);
View Full Code Here

      return;
    }

    int numChildren = random ? (int) (Math.random() * maxChildren + 1) : maxChildren;
    for (int child = 0; child < numChildren; child++) {
      SimpleNode childNode = createSimpleNode(getNextID());
      entities.add(childNode);
      SimpleRelationship rel = new SimpleRelationship(currentParentNode, childNode, false);
      childNode.addRelationship(rel);
      currentParentNode.addRelationship(rel);
      relationships.add(rel);
      SimpleRelationship.setDefaultSize(2);
      createTreeGraphRecursive(childNode, maxChildren, maxLevel, level + 1, random);
    }
View Full Code Here

  }

  /** Places nodes randomly on the screen **/
  private void placeRandomly() {
    for (Iterator iter = entities.iterator(); iter.hasNext();) {
      SimpleNode simpleNode = (SimpleNode) iter.next();
      double x = Math.random() * INITIAL_PANEL_WIDTH - INITIAL_NODE_WIDTH;
      double y = Math.random() * INITIAL_PANEL_HEIGHT - INITIAL_NODE_HEIGHT;
      simpleNode.setLocationInLayout(x, y);
    }
  }
View Full Code Here

   * Creates a SimpleNode
   * @param name
   * @return SimpleNode
   */
  private SimpleNode createSimpleNode(String name) {
    SimpleNode simpleNode = new SimpleNode(name);
    int w = name.length() * 8; // an initial approximation of the width
    simpleNode.setSizeInLayout(Math.max(w, INITIAL_NODE_WIDTH), INITIAL_NODE_HEIGHT);
    return simpleNode;
  }
View Full Code Here

      GC gcBuffer = new GC(imageBuffer);

      // paint the relationships
      for (Iterator iter = relationships.iterator(); iter.hasNext();) {
        SimpleRelationship rel = (SimpleRelationship) iter.next();
        SimpleNode src = (SimpleNode) rel.getSourceInLayout();
        SimpleNode dest = (SimpleNode) rel.getDestinationInLayout();

        // highlight the adjacent nodes if one of the nodes is selected
        if (src.equals(selectedEntity)) {
          dest.setAdjacent();
          rel.setSelected();
        } else if (dest.equals(selectedEntity)) {
          src.setAdjacent();
          rel.setSelected();
        } else {
          rel.setUnSelected();
        }

        // Add bend points if required
        if ((rel).getBendPoints() != null && (rel).getBendPoints().length > 0) {
          src = drawBendPoints(rel, gcBuffer); // change source to last bendpoint
        }

        double srcX = src.getX() + src.getWidth() / 2.0;
        double srcY = src.getY() + src.getHeight() / 2.0;
        double destX = dest.getX() + dest.getWidth() / 2.0;
        double destY = dest.getY() + dest.getHeight() / 2.0;
        drawEdge(srcX, srcY, destX, destY, rel, gcBuffer);

      }

      // paint the nodes
      for (Iterator iter = entities.iterator(); iter.hasNext();) {
        SimpleNode entity = (SimpleNode) iter.next();

        String name = entity.toString();
        Point textSize = gcBuffer.stringExtent(name);
        int entityX = (int) entity.getX();
        int entityY = (int) entity.getY();
        //TODO: What about resize from the layout algorithm
        int entityWidth = Math.max((int) entity.getWidth(), textSize.x + 8);
        int entityHeight = Math.max((int) entity.getHeight(), textSize.y + 2);

        gcBuffer.setBackground((Color) entity.getColor());
        gcBuffer.fillRoundRectangle(entityX, entityY, entityWidth, entityHeight, 8, 8);

        // position the text in the middle of the node
        int x = (int) (entityX + (entityWidth / 2.0)) - (textSize.x / 2);
        gcBuffer.setForeground(BLACK);
        gcBuffer.drawString(name, x, entityY);
        gcBuffer.setForeground((Color) entity.getBorderColor());
        gcBuffer.setLineWidth(entity.getBorderWidth());
        gcBuffer.drawRoundRectangle(entityX, entityY, entityWidth, entityHeight, 8, 8);
      }

      e.gc.drawImage(imageBuffer, 0, 0);
      imageBuffer.dispose();
View Full Code Here

     */
    private SimpleNode drawBendPoints(SimpleRelationship rel, GC gcBuffer) {
      final String DUMMY_TITLE = "dummy";
      LayoutBendPoint[] bendPoints = (rel).getBendPoints();
      LayoutBendPoint bp;
      SimpleNode startEntity = (SimpleNode) rel.getSourceInLayout();
      SimpleNode destEntity = null;

      double srcX = startEntity.getX() + startEntity.getWidth() / 2.0;
      double srcY = startEntity.getY() + startEntity.getHeight() / 2.0;
      for (int i = 1; i < bendPoints.length - 1; i++) {
        bp = bendPoints[i];
        destEntity = new SimpleNode(DUMMY_TITLE, bp.getX(), bp.getY(), 0.01, 0.01);
        drawEdge(srcX, srcY, bp.getX(), bp.getY(), rel, gcBuffer);
        startEntity = destEntity;
        srcX = startEntity.getX();
        srcY = startEntity.getY();
      }
View Full Code Here

    mainPanel.addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        selectedEntity = null;
        for (Iterator iter = entities.iterator(); iter.hasNext() && selectedEntity == null;) {
          SimpleNode entity = (SimpleNode) iter.next();
          double x = entity.getX();
          double y = entity.getY();
          double w = entity.getWidth();
          double h = entity.getHeight();
          Rectangle2D.Double rect = new Rectangle2D.Double(x, y, w, h);
          if (rect.contains(e.getX(), e.getY())) {
            selectedEntity = entity;
          }
        }
View Full Code Here

  }

  /** Places nodes randomly on the screen **/
  private void placeRandomly() {
    for (Iterator iter = entities.iterator(); iter.hasNext();) {
      SimpleNode simpleNode = (SimpleNode) iter.next();
      double x = Math.random() * INITIAL_PANEL_WIDTH - INITIAL_NODE_WIDTH;
      double y = Math.random() * INITIAL_PANEL_HEIGHT - INITIAL_NODE_HEIGHT;
      simpleNode.setLocationInLayout(x, y);
      simpleNode.setSizeInLayout(INITIAL_NODE_WIDTH, INITIAL_NODE_HEIGHT);
    }
  }
View Full Code Here

   * Creates a SimpleNode
   * @param name
   * @return
   */
  private SimpleNode createSimpleNode(String name) {
    SimpleNode simpleNode = new SimpleNode(name);
    return simpleNode;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.zest.layouts.exampleStructures.SimpleNode

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.