Package com.mxgraph.layout.hierarchical.model

Examples of com.mxgraph.layout.hierarchical.model.mxGraphAbstractHierarchyCell


            Iterator<mxGraphAbstractHierarchyCell> iter = rank
                .iterator();

            while (iter.hasNext())
            {
              mxGraphAbstractHierarchyCell cell = iter.next();
              cell.setX(j, cell.getGeneralPurposeVariable(j));
            }
          }

          bestXDelta = currentXDelta;
        }
        else
        {
          // Restore the best positions
          for (int j = 0; j < model.ranks.size(); j++)
          {
            mxGraphHierarchyRank rank = model.ranks
                .get(new Integer(j));
            Iterator<mxGraphAbstractHierarchyCell> iter = rank
                .iterator();

            while (iter.hasNext())
            {
              mxGraphAbstractHierarchyCell cell = iter.next();
              cell.setGeneralPurposeVariable(j,
                  (int) cell.getX(j));
            }
          }
        }
       
        minPath(model);
View Full Code Here


      for (int j = 0; j < rank[i].length; j++)
      {
        // Use the weight to store the rank and visited to store whether
        // or not the cell is in the list
        mxGraphAbstractHierarchyCell cell = rank[i][j];
        WeightedCellSorter cellWrapper = new WeightedCellSorter(cell, i);
        cellWrapper.rankIndex = j;
        cellWrapper.visited = true;
        nodeList.add(cellWrapper);
        map.put(cell, cellWrapper);
      }
    }

    // Set a limit of the maximum number of times we will access the queue
    // in case a loop appears
    int maxTries = nodeList.size() * 10;
    int count = 0;

    // Don't move cell within this value of their median
    int tolerance = 1;

    while (!nodeList.isEmpty() && count <= maxTries)
    {
      WeightedCellSorter cellWrapper = nodeList.getFirst();
      mxGraphAbstractHierarchyCell cell = cellWrapper.cell;

      int rankValue = cellWrapper.weightedValue;
      int rankIndex = cellWrapper.rankIndex;

      Object[] nextLayerConnectedCells = cell.getNextLayerConnectedCells(
          rankValue).toArray();
      Object[] previousLayerConnectedCells = cell
          .getPreviousLayerConnectedCells(rankValue).toArray();

      int numNextLayerConnected = nextLayerConnectedCells.length;
      int numPreviousLayerConnected = previousLayerConnectedCells.length;

      int medianNextLevel = medianXValue(nextLayerConnectedCells,
          rankValue + 1);
      int medianPreviousLevel = medianXValue(previousLayerConnectedCells,
          rankValue - 1);

      int numConnectedNeighbours = numNextLayerConnected
          + numPreviousLayerConnected;
      int currentPosition = cell.getGeneralPurposeVariable(rankValue);
      double cellMedian = currentPosition;

      if (numConnectedNeighbours > 0)
      {
        cellMedian = (medianNextLevel * numNextLayerConnected + medianPreviousLevel
            * numPreviousLayerConnected)
            / numConnectedNeighbours;
      }

      // Flag storing whether or not position has changed
      boolean positionChanged = false;

      if (cellMedian < currentPosition - tolerance)
      {
        if (rankIndex == 0)
        {
          cell.setGeneralPurposeVariable(rankValue, (int) cellMedian);
          positionChanged = true;
        }
        else
        {
          mxGraphAbstractHierarchyCell leftCell = rank[rankValue][rankIndex - 1];
          int leftLimit = leftCell
              .getGeneralPurposeVariable(rankValue);
          leftLimit = leftLimit + (int) leftCell.width / 2
              + (int) intraCellSpacing + (int) cell.width / 2;

          if (leftLimit < cellMedian)
          {
            cell.setGeneralPurposeVariable(rankValue,
                (int) cellMedian);
            positionChanged = true;
          }
          else if (leftLimit < cell
              .getGeneralPurposeVariable(rankValue) - tolerance)
          {
            cell.setGeneralPurposeVariable(rankValue, leftLimit);
            positionChanged = true;
          }
        }
      }
      else if (cellMedian > currentPosition + tolerance)
      {
        int rankSize = rank[rankValue].length;

        if (rankIndex == rankSize - 1)
        {
          cell.setGeneralPurposeVariable(rankValue, (int) cellMedian);
          positionChanged = true;
        }
        else
        {
          mxGraphAbstractHierarchyCell rightCell = rank[rankValue][rankIndex + 1];
          int rightLimit = rightCell
              .getGeneralPurposeVariable(rankValue);
          rightLimit = rightLimit - (int) rightCell.width / 2
              - (int) intraCellSpacing - (int) cell.width / 2;

          if (rightLimit > cellMedian)
          {
            cell.setGeneralPurposeVariable(rankValue,
                (int) cellMedian);
            positionChanged = true;
          }
          else if (rightLimit > cell
              .getGeneralPurposeVariable(rankValue) + tolerance)
          {
            cell.setGeneralPurposeVariable(rankValue, rightLimit);
            positionChanged = true;
          }
        }
      }

      if (positionChanged)
      {
        // Add connected nodes to map and list
        for (int i = 0; i < nextLayerConnectedCells.length; i++)
        {
          mxGraphAbstractHierarchyCell connectedCell = (mxGraphAbstractHierarchyCell) nextLayerConnectedCells[i];
          WeightedCellSorter connectedCellWrapper = map
              .get(connectedCell);

          if (connectedCellWrapper != null)
          {
            if (connectedCellWrapper.visited == false)
            {
              connectedCellWrapper.visited = true;
              nodeList.add(connectedCellWrapper);
            }
          }
        }

        // Add connected nodes to map and list
        for (int i = 0; i < previousLayerConnectedCells.length; i++)
        {
          mxGraphAbstractHierarchyCell connectedCell = (mxGraphAbstractHierarchyCell) previousLayerConnectedCells[i];
          WeightedCellSorter connectedCellWrapper = map
              .get(connectedCell);

          if (connectedCellWrapper != null)
          {
View Full Code Here

    Map<mxGraphAbstractHierarchyCell, WeightedCellSorter> cellMap = new Hashtable<mxGraphAbstractHierarchyCell, WeightedCellSorter>(
        rank.length);

    for (int i = 0; i < rank.length; i++)
    {
      mxGraphAbstractHierarchyCell currentCell = (mxGraphAbstractHierarchyCell) rank[i];
      weightedValues[i] = new WeightedCellSorter();
      weightedValues[i].cell = currentCell;
      weightedValues[i].rankIndex = i;
      cellMap.put(currentCell, weightedValues[i]);
      Collection<mxGraphAbstractHierarchyCell> nextLayerConnectedCells = null;

      if (nextRankValue < rankValue)
      {
        nextLayerConnectedCells = currentCell
            .getPreviousLayerConnectedCells(rankValue);
      }
      else
      {
        nextLayerConnectedCells = currentCell
            .getNextLayerConnectedCells(rankValue);
      }

      // Calculate the weighing based on this node type and those this
      // node is connected to on the next layer
      weightedValues[i].weightedValue = calculatedWeightedValue(
          currentCell, nextLayerConnectedCells);
    }

    Arrays.sort(weightedValues);
    // Set the new position of each node within the rank using
    // its temp variable

    for (int i = 0; i < weightedValues.length; i++)
    {
      int numConnectionsNextLevel = 0;
      mxGraphAbstractHierarchyCell cell = weightedValues[i].cell;
      Object[] nextLayerConnectedCells = null;
      int medianNextLevel = 0;

      if (nextRankValue < rankValue)
      {
        nextLayerConnectedCells = cell.getPreviousLayerConnectedCells(
            rankValue).toArray();
      }
      else
      {
        nextLayerConnectedCells = cell.getNextLayerConnectedCells(
            rankValue).toArray();
      }

      if (nextLayerConnectedCells != null)
      {
        numConnectionsNextLevel = nextLayerConnectedCells.length;

        if (numConnectionsNextLevel > 0)
        {
          medianNextLevel = medianXValue(nextLayerConnectedCells,
              nextRankValue);
        }
        else
        {
          // For case of no connections on the next level set the
          // median to be the current position and try to be
          // positioned there
          medianNextLevel = cell.getGeneralPurposeVariable(rankValue);
        }
      }

      double leftBuffer = 0.0;
      double leftLimit = -100000000.0;

      for (int j = weightedValues[i].rankIndex - 1; j >= 0;)
      {
        WeightedCellSorter weightedValue = cellMap.get(rank[j]);

        if (weightedValue != null)
        {
          mxGraphAbstractHierarchyCell leftCell = weightedValue.cell;

          if (weightedValue.visited)
          {
            // The left limit is the right hand limit of that
            // cell plus any allowance for unallocated cells
            // in-between
            leftLimit = leftCell
                .getGeneralPurposeVariable(rankValue)
                + leftCell.width
                / 2.0
                + intraCellSpacing
                + leftBuffer + cell.width / 2.0;
            j = -1;
          }
          else
          {
            leftBuffer += leftCell.width + intraCellSpacing;
            j--;
          }
        }
      }

      double rightBuffer = 0.0;
      double rightLimit = 100000000.0;

      for (int j = weightedValues[i].rankIndex + 1; j < weightedValues.length;)
      {
        WeightedCellSorter weightedValue = cellMap.get(rank[j]);

        if (weightedValue != null)
        {
          mxGraphAbstractHierarchyCell rightCell = weightedValue.cell;

          if (weightedValue.visited)
          {
            // The left limit is the right hand limit of that
            // cell plus any allowance for unallocated cells
            // in-between
            rightLimit = rightCell
                .getGeneralPurposeVariable(rankValue)
                - rightCell.width
                / 2.0
                - intraCellSpacing
                - rightBuffer - cell.width / 2.0;
View Full Code Here

    int totalWeight = 0;
    Iterator<mxGraphAbstractHierarchyCell> iter = collection.iterator();

    while (iter.hasNext())
    {
      mxGraphAbstractHierarchyCell cell = iter.next();

      if (currentCell.isVertex() && cell.isVertex())
      {
        totalWeight++;
      }
      else if (currentCell.isEdge() && cell.isEdge())
      {
        totalWeight += 8;
      }
      else
      {
View Full Code Here

      boolean boundsWarning = false;
      Iterator<mxGraphAbstractHierarchyCell> iter = rank.iterator();

      while (iter.hasNext())
      {
        mxGraphAbstractHierarchyCell cell = iter.next();

        if (cell.isVertex())
        {
          mxGraphHierarchyNode node = (mxGraphHierarchyNode) cell;
          mxRectangle bounds = layout.getVertexBounds(node.cell);

          if (bounds != null)
          {
            if (orientation == SwingConstants.NORTH
                || orientation == SwingConstants.SOUTH)
            {
              cell.width = bounds.getWidth();
              cell.height = bounds.getHeight();
            }
            else
            {
              cell.width = bounds.getHeight();
              cell.height = bounds.getWidth();
            }
          }
          else
          {
            boundsWarning = true;
          }

          maxCellHeight = Math.max(maxCellHeight, cell.height);
        }
        else if (cell.isEdge())
        {
          mxGraphHierarchyEdge edge = (mxGraphHierarchyEdge) cell;
          // The width is the number of additional parallel edges
          // time the parallel edge spacing
          int numEdges = 1;

          if (edge.edges != null)
          {
            numEdges = edge.edges.size();
          }
          else
          {
            logger.info("edge.edges is null");
          }

          cell.width = (numEdges - 1) * parallelEdgeSpacing;
        }

        // Set the initial x-value as being the best result so far
        localX += cell.width / 2.0;
        cell.setX(rankValue, localX);
        cell.setGeneralPurposeVariable(rankValue, (int) localX);
        localX += cell.width / 2.0;
        localX += intraCellSpacing;

        if (localX > widestRankValue)
        {
          widestRankValue = localX;
          widestRank = rankValue;
        }

        rankWidths[rankValue] = localX;
      }

      if (boundsWarning == true)
      {
        logger.info("At least one cell has no bounds");
      }

      rankY[rankValue] = y;
      double distanceToNextRank = maxCellHeight / 2.0
          + lastRankMaxCellHeight / 2.0 + interRankCellSpacing;
      lastRankMaxCellHeight = maxCellHeight;

      if (orientation == SwingConstants.NORTH
          || orientation == SwingConstants.WEST)
      {
        y += distanceToNextRank;
      }
      else
      {
        y -= distanceToNextRank;
      }

      iter = rank.iterator();

      while (iter.hasNext())
      {
        mxGraphAbstractHierarchyCell cell = iter.next();
        cell.setY(rankValue, y);
      }
    }
  }
View Full Code Here

      {
        // Left-most node, can move anywhere
        return true;
      }

      mxGraphAbstractHierarchyCell leftCell = rankArray[rankIndex - 1];
      int leftLimit = leftCell.getGeneralPurposeVariable(rank);
      leftLimit = leftLimit + (int) leftCell.width / 2
          + (int) intraCellSpacing + (int) cell.width / 2;

      if (leftLimit <= position)
      {
        return true;
      }
      else
      {
        return false;
      }
    }
    else if (position > currentX)
    {
      // Trying to move node to the right.
      if (rankIndex == rankArray.length - 1)
      {
        // Right-most node, can move anywhere
        return true;
      }

      mxGraphAbstractHierarchyCell rightCell = rankArray[rankIndex + 1];
      int rightLimit = rightCell.getGeneralPurposeVariable(rank);
      rightLimit = rightLimit - (int) rightCell.width / 2
          - (int) intraCellSpacing - (int) cell.width / 2;

      if (rightLimit >= position)
      {
View Full Code Here

      Iterator<mxGraphAbstractHierarchyCell> iter = rank
          .iterator();

      while (iter.hasNext())
      {
        mxGraphAbstractHierarchyCell cell = iter.next();
        System.out.print(cell.getX(j) + "  ");
      }
      System.out.println();
    }
   
    System.out.println("====================================");
View Full Code Here

            Iterator<mxGraphAbstractHierarchyCell> iter = rank
                .iterator();

            while (iter.hasNext())
            {
              mxGraphAbstractHierarchyCell cell = iter.next();
              cell.setX(j, cell.getGeneralPurposeVariable(j));
            }
          }

          bestXDelta = currentXDelta;
        }
        else
        {
          // Restore the best positions
          for (int j = 0; j < model.ranks.size(); j++)
          {
            mxGraphHierarchyRank rank = model.ranks
                .get(new Integer(j));
            Iterator<mxGraphAbstractHierarchyCell> iter = rank
                .iterator();

            while (iter.hasNext())
            {
              mxGraphAbstractHierarchyCell cell = iter.next();
              cell.setGeneralPurposeVariable(j,
                  (int) cell.getX(j));
            }
          }
        }

        minPath(model);
View Full Code Here

      for (int j = 0; j < rank[i].length; j++)
      {
        // Use the weight to store the rank and visited to store whether
        // or not the cell is in the list
        mxGraphAbstractHierarchyCell cell = rank[i][j];
        WeightedCellSorter cellWrapper = new WeightedCellSorter(cell, i);
        cellWrapper.rankIndex = j;
        cellWrapper.visited = true;
        nodeList.add(cellWrapper);
        map.put(cell, cellWrapper);
      }
    }

    // Set a limit of the maximum number of times we will access the queue
    // in case a loop appears
    int maxTries = nodeList.size() * 10;
    int count = 0;

    // Don't move cell within this value of their median
    int tolerance = 1;

    while (!nodeList.isEmpty() && count <= maxTries)
    {
      WeightedCellSorter cellWrapper = nodeList.getFirst();
      mxGraphAbstractHierarchyCell cell = cellWrapper.cell;

      int rankValue = cellWrapper.weightedValue;
      int rankIndex = cellWrapper.rankIndex;

      Object[] nextLayerConnectedCells = cell.getNextLayerConnectedCells(
          rankValue).toArray();
      Object[] previousLayerConnectedCells = cell
          .getPreviousLayerConnectedCells(rankValue).toArray();

      int numNextLayerConnected = nextLayerConnectedCells.length;
      int numPreviousLayerConnected = previousLayerConnectedCells.length;

      int medianNextLevel = medianXValue(nextLayerConnectedCells,
          rankValue + 1);
      int medianPreviousLevel = medianXValue(previousLayerConnectedCells,
          rankValue - 1);

      int numConnectedNeighbours = numNextLayerConnected
          + numPreviousLayerConnected;
      int currentPosition = cell.getGeneralPurposeVariable(rankValue);
      double cellMedian = currentPosition;

      if (numConnectedNeighbours > 0)
      {
        cellMedian = (medianNextLevel * numNextLayerConnected + medianPreviousLevel
            * numPreviousLayerConnected)
            / numConnectedNeighbours;
      }

      // Flag storing whether or not position has changed
      boolean positionChanged = false;

      if (cellMedian < currentPosition - tolerance)
      {
        if (rankIndex == 0)
        {
          cell.setGeneralPurposeVariable(rankValue, (int) cellMedian);
          positionChanged = true;
        }
        else
        {
          mxGraphAbstractHierarchyCell leftCell = rank[rankValue][rankIndex - 1];
          int leftLimit = leftCell
              .getGeneralPurposeVariable(rankValue);
          leftLimit = leftLimit + (int) leftCell.width / 2
              + (int) intraCellSpacing + (int) cell.width / 2;

          if (leftLimit < cellMedian)
          {
            cell.setGeneralPurposeVariable(rankValue,
                (int) cellMedian);
            positionChanged = true;
          }
          else if (leftLimit < cell
              .getGeneralPurposeVariable(rankValue) - tolerance)
          {
            cell.setGeneralPurposeVariable(rankValue, leftLimit);
            positionChanged = true;
          }
        }
      }
      else if (cellMedian > currentPosition + tolerance)
      {
        int rankSize = rank[rankValue].length;

        if (rankIndex == rankSize - 1)
        {
          cell.setGeneralPurposeVariable(rankValue, (int) cellMedian);
          positionChanged = true;
        }
        else
        {
          mxGraphAbstractHierarchyCell rightCell = rank[rankValue][rankIndex + 1];
          int rightLimit = rightCell
              .getGeneralPurposeVariable(rankValue);
          rightLimit = rightLimit - (int) rightCell.width / 2
              - (int) intraCellSpacing - (int) cell.width / 2;

          if (rightLimit > cellMedian)
          {
            cell.setGeneralPurposeVariable(rankValue,
                (int) cellMedian);
            positionChanged = true;
          }
          else if (rightLimit > cell
              .getGeneralPurposeVariable(rankValue) + tolerance)
          {
            cell.setGeneralPurposeVariable(rankValue, rightLimit);
            positionChanged = true;
          }
        }
      }

      if (positionChanged)
      {
        // Add connected nodes to map and list
        for (int i = 0; i < nextLayerConnectedCells.length; i++)
        {
          mxGraphAbstractHierarchyCell connectedCell = (mxGraphAbstractHierarchyCell) nextLayerConnectedCells[i];
          WeightedCellSorter connectedCellWrapper = map
              .get(connectedCell);

          if (connectedCellWrapper != null)
          {
            if (connectedCellWrapper.visited == false)
            {
              connectedCellWrapper.visited = true;
              nodeList.add(connectedCellWrapper);
            }
          }
        }

        // Add connected nodes to map and list
        for (int i = 0; i < previousLayerConnectedCells.length; i++)
        {
          mxGraphAbstractHierarchyCell connectedCell = (mxGraphAbstractHierarchyCell) previousLayerConnectedCells[i];
          WeightedCellSorter connectedCellWrapper = map
              .get(connectedCell);

          if (connectedCellWrapper != null)
          {
View Full Code Here

    Map<mxGraphAbstractHierarchyCell, WeightedCellSorter> cellMap = new Hashtable<mxGraphAbstractHierarchyCell, WeightedCellSorter>(
        rank.length);

    for (int i = 0; i < rank.length; i++)
    {
      mxGraphAbstractHierarchyCell currentCell = (mxGraphAbstractHierarchyCell) rank[i];
      weightedValues[i] = new WeightedCellSorter();
      weightedValues[i].cell = currentCell;
      weightedValues[i].rankIndex = i;
      cellMap.put(currentCell, weightedValues[i]);
      Collection<mxGraphAbstractHierarchyCell> nextLayerConnectedCells = null;

      if (nextRankValue < rankValue)
      {
        nextLayerConnectedCells = currentCell
            .getPreviousLayerConnectedCells(rankValue);
      }
      else
      {
        nextLayerConnectedCells = currentCell
            .getNextLayerConnectedCells(rankValue);
      }

      // Calculate the weighing based on this node type and those this
      // node is connected to on the next layer
      weightedValues[i].weightedValue = calculatedWeightedValue(
          currentCell, nextLayerConnectedCells);
    }

    Arrays.sort(weightedValues);
    // Set the new position of each node within the rank using
    // its temp variable

    for (int i = 0; i < weightedValues.length; i++)
    {
      int numConnectionsNextLevel = 0;
      mxGraphAbstractHierarchyCell cell = weightedValues[i].cell;
      Object[] nextLayerConnectedCells = null;
      int medianNextLevel = 0;

      if (nextRankValue < rankValue)
      {
        nextLayerConnectedCells = cell.getPreviousLayerConnectedCells(
            rankValue).toArray();
      }
      else
      {
        nextLayerConnectedCells = cell.getNextLayerConnectedCells(
            rankValue).toArray();
      }

      if (nextLayerConnectedCells != null)
      {
        numConnectionsNextLevel = nextLayerConnectedCells.length;

        if (numConnectionsNextLevel > 0)
        {
          medianNextLevel = medianXValue(nextLayerConnectedCells,
              nextRankValue);
        }
        else
        {
          // For case of no connections on the next level set the
          // median to be the current position and try to be
          // positioned there
          medianNextLevel = cell.getGeneralPurposeVariable(rankValue);
        }
      }

      double leftBuffer = 0.0;
      double leftLimit = -100000000.0;

      for (int j = weightedValues[i].rankIndex - 1; j >= 0;)
      {
        WeightedCellSorter weightedValue = cellMap.get(rank[j]);

        if (weightedValue != null)
        {
          mxGraphAbstractHierarchyCell leftCell = weightedValue.cell;

          if (weightedValue.visited)
          {
            // The left limit is the right hand limit of that
            // cell plus any allowance for unallocated cells
            // in-between
            leftLimit = leftCell
                .getGeneralPurposeVariable(rankValue)
                + leftCell.width
                / 2.0
                + intraCellSpacing
                + leftBuffer + cell.width / 2.0;
            j = -1;
          }
          else
          {
            leftBuffer += leftCell.width + intraCellSpacing;
            j--;
          }
        }
      }

      double rightBuffer = 0.0;
      double rightLimit = 100000000.0;

      for (int j = weightedValues[i].rankIndex + 1; j < weightedValues.length;)
      {
        WeightedCellSorter weightedValue = cellMap.get(rank[j]);

        if (weightedValue != null)
        {
          mxGraphAbstractHierarchyCell rightCell = weightedValue.cell;

          if (weightedValue.visited)
          {
            // The left limit is the right hand limit of that
            // cell plus any allowance for unallocated cells
            // in-between
            rightLimit = rightCell
                .getGeneralPurposeVariable(rankValue)
                - rightCell.width
                / 2.0
                - intraCellSpacing
                - rightBuffer - cell.width / 2.0;
View Full Code Here

TOP

Related Classes of com.mxgraph.layout.hierarchical.model.mxGraphAbstractHierarchyCell

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.