private ArrayList<Integer> findRanges() {
   int rowsPerRange = (int) Math.ceil((grid.size()) / (double) threads);
   ArrayList<Integer> ranges = new ArrayList<Integer>();
   int startRow = 0, endRow = rowsPerRange;
   for (int i = 0; i < threads; i++) {
     ranges.add(startRow);
     ranges.add(endRow);
     startRow = endRow;
     ;
     endRow += rowsPerRange;
   }
   ranges.set(ranges.size() - 1, Math.min(grid.size(), ranges.get(ranges.size() - 1)));
   System.out.println(ranges);
   return ranges;
 }
示例#2
0
  /** Pastes Items from the Clipboard on the Board */
  public void paste() {

    ComponentSelection clipboardContent = (ComponentSelection) tbe.getClipboard().getContents(this);

    if ((clipboardContent != null)
        && (clipboardContent.isDataFlavorSupported(ComponentSelection.itemFlavor))) {

      Object[] tempItems = null;
      try {
        tempItems =
            board.cloneItems(clipboardContent.getTransferData(ComponentSelection.itemFlavor));
      } catch (UnsupportedFlavorException e1) {

        e1.printStackTrace();
      }
      ItemComponent[] items = new ItemComponent[tempItems.length];
      for (int i = 0; i < tempItems.length; i++) {
        items[i] = (ItemComponent) tempItems[i];
      }
      PasteCommand del = new PasteCommand(items);
      ArrayList<Command> actCommands = new ArrayList<Command>();
      actCommands.add(del);
      tbe.addCommands(actCommands);
      board.addItem(items);
    }
  }
示例#3
0
  /** Deletes the selected Item of the Board and creates a DeleteCommand */
  public void delete() {

    ItemComponent[] items = board.getSelectedItems();
    DeleteCommand del = new DeleteCommand(items);
    ArrayList<Command> actCommands = new ArrayList<Command>();
    actCommands.add(del);
    tbe.addCommands(actCommands);
    board.removeItem(items);
  }
示例#4
0
  /** Cuts selected Iems of the Board and put it into the ClipBoard */
  public void cut() {

    ItemComponent[] items = board.getSelectedItems();
    CutCommand cut = new CutCommand(items);
    ArrayList<Command> actCommands = new ArrayList<Command>();
    actCommands.add(cut);
    tbe.addCommands(actCommands);
    ComponentSelection contents = new ComponentSelection(this.getBoard().cloneItems(items));
    tbe.getClipboard().setContents(contents, cut);
    board.removeItem(items);
  }
示例#5
0
 /**
  * Add/Remove a Point to/from an Arrow
  *
  * @param b boolean, true = add, false = remove
  */
 public void addRemovePoint(boolean b) {
   if (board.getSelectionCount() == 1 && board.getSelectionCell() instanceof ArrowItem) {
     MoveCommand mc = new MoveCommand(board.getSelectedItems());
     ArrowItem a = (ArrowItem) board.getSelectionCell();
     if (b) {
       a.addPoint();
     } else {
       a.removePoint();
     }
     WorkingView.this.refresh();
     board.setSelectionCell(a);
     setTool(cursorTool, cursorButton);
     board.addItem(a);
     mc.setMoveEnd(board.getSelectedItems());
     ArrayList<Command> actCommands = new ArrayList<Command>();
     actCommands.add(mc);
     tbe.addCommands(actCommands);
   }
 }
  public void parseInput(String file, int threads, int limit)
      throws FileNotFoundException, InterruptedException {
    // long startParseTime = System.currentTimeMillis();
    m_jgAdapter = new JGraphModelAdapter<Position, DefaultEdge>(graph);
    jgraph = new JGraph(m_jgAdapter);
    this.threads = threads;

    Scanner input = new Scanner(new File(file));
    try {
      for (int r = 0; input.hasNextLine() && r < limit; r++) {
        Scanner line = new Scanner(input.nextLine());
        try {

          ArrayList<Position> row = new ArrayList<Position>();
          grid.add(row);

          System.out.println("Row " + r);

          for (int c = 0; line.hasNextInt() && c < limit; c++) {
            Position position = new Position(r, c, line.nextInt());
            row.add(position);
            graph.addVertex(position);
            positionVertexAt(position, position.column * 5, position.row * 5);
          }
        } finally {
          line.close();
        }
      }
    } finally {
      input.close();
    }

    graphGrid(grid);

    // ArrayList<ArrayList<Position>> grid2 = transpose(grid);
    // outputGrid(grid2);

  }