public void updateRow(int row) {
   WalrusInfoWeb walrus = this.walrusList.get(row);
   Grid g = (Grid) this.grid.getWidget(row, 0);
   HorizontalPanel p = (HorizontalPanel) g.getWidget(0, 1);
   walrus.setHost(((TextBox) p.getWidget(0)).getText());
   int widgetStartIndex = 1;
   ArrayList<String> properties = walrus.getProperties();
   for (int i = 0; i < (properties.size() / 4); ++i) {
     if (properties.get(4 * i).startsWith("KEYVALUE"))
       properties.set(4 * i + 2, ((TextBox) g.getWidget(widgetStartIndex + i, 1)).getText());
   }
 }
  private void insertTableRows(final Table type, final Integer r) {
    final int rows = r.intValue();

    if (Table.GRID.equals(type)) {
      final Grid grid = (Grid) table;

      for (int i = 0; i < rows; i++) {
        final Number num = new Integer(i);
        grid.resizeRows(i + 1);
        for (int j = i; j > 0; j--) {
          grid.setWidget(j, 0, grid.getWidget(j - 1, 0));
        }
        grid.setWidget(0, 0, makeLabel(num));
      }

    } else if (Table.FLEX_TABLE.equals(type)) {
      final FlexTable flexTable = (FlexTable) table;

      for (int i = 0; i < rows; i++) {
        final Number num = new Integer(i);
        flexTable.insertRow(0);
        flexTable.setWidget(0, 0, makeLabel(num));
      }

    } else if (Table.OBJECT_LIST_TABLE.equals(type)) {
      final ObjectListTable olt = (ObjectListTable) table;

      for (int i = 0; i < rows; i++) {
        final Number num = new Integer(i);
        olt.getObjects().add(0, num);
      }
    }
  }
  private void storeCellWidgets() {
    cellWidgets = new FocusWidget[boardGrid.getRowCount()][boardGrid.getCellCount(0)];

    for (int row = 0; row < boardGrid.getRowCount(); row++) {
      int cellCount = boardGrid.getCellCount(row);
      for (int col = 0; col < cellCount; col++) {

        cellWidgets[row][col] = (FocusWidget) boardGrid.getWidget(row, col);
      }
    }
  }
Exemple #4
0
  /**
   * A player can only select certain pits for their move. That's why some have to be enabled and
   * some have to be disabled before a player's turn.
   */
  @Override
  public void setPitEnabled(PlayerColor side, int col, boolean enabled) {
    AbsolutePanel pnl;
    if (col < 6) {
      if (side.isNorth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(0, State.getMirrorIndex(col, 5));
      } else if (side.isSouth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(1, col);
      } else throw new IllegalMoveException();

      final int colB = col;
      int row = side.isNorth() ? 0 : 1;

      if (enabled) {
        // the handerRegs keeps track of all click handlers of the pits
        // by removing it from this array the handler is removed from
        // the pit (absolutePanel) as well
        handlerRegs[row][col].removeHandler();
        handlerRegs[row][col] =
            pnl.addDomHandler(
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    presenter.makeMove(colB);
                  }
                },
                ClickEvent.getType());
      } else {
        handlerRegs[row][col].removeHandler();
        handlerRegs[row][col] =
            pnl.addDomHandler(
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    setWarnLabelText(messages.warnMessage());
                  }
                },
                ClickEvent.getType());
      }
    }
  }
Exemple #5
0
  /** The seedAmount will be placed on the right side at the correct index */
  @Override
  public void setSeeds(PlayerColor side, int col, int seedAmount) {
    if (col < 6) {
      AbsolutePanel pnl;
      if (side.isNorth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(0, State.getMirrorIndex(col, 5));
      } else if (side.isSouth()) {
        pnl = (AbsolutePanel) gameGrid.getWidget(1, col);
      } else throw new IllegalMoveException();

      addSeeds(pnl, seedAmount);
    } else if (col == 6) {
      AbsolutePanel pnl;
      if (side.isNorth()) {
        pnl = (AbsolutePanel) treasureGridN.getWidget(0, 0);
      } else if (side.isSouth()) {
        pnl = (AbsolutePanel) treasureGridS.getWidget(0, 0);
      } else throw new IllegalMoveException();
      addSeedsToTreasureChest(pnl, seedAmount);
    } else throw new IllegalMoveException();
  }
  /**
   * Set the current progress as a percentage
   *
   * @param percentage Set current percentage for the progress bar
   */
  public void setProgress(int percentage) {
    // Make sure we are error-tolerant
    if (percentage > 100) percentage = 100;
    if (percentage < 0) percentage = 0;

    // Set the internal variable
    progress = percentage;

    // Update the elements in the progress grid to
    // reflect the status
    int completed = elements * percentage / 100;
    for (int loop = 0; loop < elements; loop++) {
      Grid elm = (Grid) elementGrid.getWidget(0, loop);
      if (loop < completed) {
        elm.setStyleName("progressbar-fullbar");
        elm.addStyleName("progressbar-bar");
      } else {
        elm.setStyleName("progressbar-blankbar");
        elm.addStyleName("progressbar-bar");
      }
    }

    if (percentage > 0) {
      // Calculate the new time remaining
      long soFar = (System.currentTimeMillis() - startTime) / 1000;
      long remaining = soFar * (100 - percentage) / percentage;
      // Select the best UOM
      String remainText = secondsMessage;
      if (remaining > 120) {
        remaining = remaining / 60;
        remainText = minutesMessage;
        if (remaining > 120) {
          remaining = remaining / 60;
          remainText = hoursMessage;
        }
      }
      // Locate the position to insert out time remaining
      int pos = remainText.indexOf("{0}");
      if (pos >= 0) {
        String trail = "";
        if (pos + 3 < remainText.length()) trail = remainText.substring(pos + 3);
        remainText = remainText.substring(0, pos) + remaining + trail;
      }
      // Set the label
      remainLabel.setText(remainText);
    } else {
      // If progress is 0, reset the start time
      startTime = System.currentTimeMillis();
    }
  }
Exemple #7
0
 /** Simulates a click event on the Grid cell with the given indexes. */
 public static void click(Grid grid, int row, int column) {
   Widget target = grid.getWidget(row, column);
   Event clickEvent = EventBuilder.create(Event.ONCLICK).setTarget(target.getElement()).build();
   assertCanApplyEvent(target, clickEvent);
   dispatchEventInternal(grid, clickEvent);
 }
Exemple #8
0
  /** To animate a seed from one pit to another */
  @Override
  public void animateFromPitToPit(
      PlayerColor startSide,
      int startCol,
      PlayerColor endSide,
      int endCol,
      double delay,
      boolean finalAnimation) {
    int startRow = startSide.isNorth() ? 0 : 1;
    int actualStartCol = (startRow == 0) ? 5 - startCol : startCol;
    int endRow = endSide.isNorth() ? 0 : 1;
    int actualEndCol = (endRow == 0) ? 5 - endCol : endCol;

    AbsolutePanel startPanel = (AbsolutePanel) gameGrid.getWidget(startRow, actualStartCol);
    final Image seed;
    seed = (Image) startPanel.getWidget(startPanel.getWidgetCount() - 2);
    int startXStartPanel = startPanel.getWidgetLeft(seed);
    int startYStartPanel = startPanel.getWidgetTop(seed);
    int startX =
        2
            + actualStartCol * 2
            + TREASURE_CHEST_WIDTH
            + PIT_WIDTH * actualStartCol
            + PADDING * (actualStartCol * 2 + 3)
            + startXStartPanel;
    int startY = 2 + PADDING + startRow * (PIT_HEIGHT + 2 * PADDING + 2) + startYStartPanel;

    AbsolutePanel endPanel;
    int[] endPointEndPanel;
    int endXEndPanel;
    int endYEndPanel;
    int endX;
    int endY;
    if (endCol < 6) {
      endPanel = (AbsolutePanel) gameGrid.getWidget(endRow, actualEndCol);
      endPointEndPanel = getTargetPoint(endPanel.getWidgetCount() - 1);
      endXEndPanel = endPointEndPanel[0];
      endYEndPanel = endPointEndPanel[1];
      endX =
          2
              + actualEndCol * 2
              + TREASURE_CHEST_WIDTH
              + PIT_WIDTH * actualEndCol
              + PADDING * (actualEndCol * 2 + 3)
              + endXEndPanel;
      endY = 2 + PADDING + endRow * (PIT_HEIGHT + 2 * PADDING + 2) + endYEndPanel;
    } else {
      Grid hGrid = endRow == 0 ? treasureGridN : treasureGridS;
      endPanel = (AbsolutePanel) hGrid.getWidget(0, 0);
      endPointEndPanel = getTargetPointTreasureChest(endPanel.getWidgetCount() - 1);
      endXEndPanel = endPointEndPanel[0];
      endYEndPanel = endPointEndPanel[1];
      endX =
          2
              + PADDING
              + (TREASURE_CHEST_WIDTH + PIT_WIDTH * 6 + PADDING * 14 + 6 * 2) * endRow
              + endXEndPanel;
      endY = 2 + PADDING + endYEndPanel;
    }

    animation =
        new SeedMovingAnimation(
            seed,
            gameImages.redSeed(),
            startPanel,
            endPanel,
            startXStartPanel,
            startYStartPanel,
            endXEndPanel,
            endYEndPanel,
            startX,
            startY,
            endX,
            endY,
            finalAnimation,
            this,
            dotSound);
    animation.run(1000, Duration.currentTimeMillis() + delay);
  }