Exemplo n.º 1
0
  /**
   * Adds an item to the page for printing. If the document was not successfully opened, or if the
   * item has an invalid barcode, no action will be taken and a negative Result will be returned.
   *
   * @param item
   */
  public Result addItem(Item item) {
    if (!_open) {
      return new Result(false, "Cannot add a product to an unopened file.");
    }
    if (!item.getBarcode().isValid()) {
      return new Result(false, "Cannot print an invalid barcode.");
    }

    // Generate the barcode image:
    BarcodeEAN codeEAN = new BarcodeEAN();
    codeEAN.setCodeType(com.itextpdf.text.pdf.Barcode.UPCA);
    codeEAN.setCode(item.getBarcode().toString());
    Image bcimage = codeEAN.createImageWithBarcode(_rawContent, null, null);

    // Add some text to a chunk, and the image to a chunk.
    Font font = new Font(Font.FontFamily.HELVETICA, 8);
    Chunk c1 =
        new Chunk(
            item.getProductDescription()
                + "\n"
                + item.getShortEntryDateString()
                + " -> "
                + item.getShortExpirationDateString()
                + "\n\n");
    c1.setFont(font);
    Phrase p = new Phrase(c1);
    Chunk c2 = new Chunk(bcimage, 0, 0);
    p.add(c2);

    PdfPCell cell = new PdfPCell(p);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(10);
    cell.setBorder(0);
    _table.addCell(cell);

    _itemsAdded++;

    return new Result(true, "Barcode added successfully.");
  }
Exemplo n.º 2
0
  @Override
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      // SaveState.writeFile(player,"Player test.txt");
      switchState(States.Pause);
    }

    if (e.getKeyCode() == KeyEvent.VK_I) {
      switchState(States.Inventory);
      // SaveState.writeFile(player,"Player test.txt");
    }

    if (e.getKeyCode() == KeyEvent.VK_G) {
      switchState(States.Gear);
    }

    if (e.getKeyCode() == KeyEvent.VK_M) {
      switchState(States.Map);
    }

    if (e.getKeyCode() == KeyEvent.VK_Q) {
      int x = player.getLocation().getX(),
          y = player.getLocation().getY(),
          size = controller.getTiles(x, y).getItems().size();
      for (int i = 0; i < size; i++) {
        Item item =
            controller
                .getTiles(player.getLocation().getX(), player.getLocation().getY())
                .getItems()
                .get(i);
        switch (item.getType()) {
          case PICKUPABLE:
          case USEABLE:
          case WEAPON:
          case ARMOR:
            controller.getPlayer().PickUpItem();
            break;
          default:
            item.onInteract(controller.getPlayer());
            break;
        }
      }
    }

    if ((e.getKeyCode() == KeyEvent.VK_NUMPAD8 || e.getKeyCode() == KeyEvent.VK_UP)) {
      controller.getPlayer().move(0);
    }
    if ((e.getKeyCode() == KeyEvent.VK_NUMPAD6 || e.getKeyCode() == KeyEvent.VK_RIGHT)) {
      controller.getPlayer().move(1);
    }
    if ((e.getKeyCode() == KeyEvent.VK_NUMPAD2 || e.getKeyCode() == KeyEvent.VK_DOWN)) {
      controller.getPlayer().move(2);
    }
    if ((e.getKeyCode() == KeyEvent.VK_NUMPAD4 || e.getKeyCode() == KeyEvent.VK_LEFT)) {
      controller.getPlayer().move(3);
    }

    if (e.getKeyCode() == KeyEvent.VK_NUMPAD9) {
      controller.getPlayer().move(4);
    }
    if (e.getKeyCode() == KeyEvent.VK_NUMPAD3) {
      controller.getPlayer().move(5);
    }
    if (e.getKeyCode() == KeyEvent.VK_NUMPAD1) {
      controller.getPlayer().move(6);
    }
    if (e.getKeyCode() == KeyEvent.VK_NUMPAD7) {
      controller.getPlayer().move(7);
    }

    if (e.getKeyCode() == KeyEvent.VK_K) {
      player
          .getStats()
          .applyEffect(new Effect(new StatStructure(StatsEnum.LIFE, -1), 0, "Take Damage"));
    }
    if (e.getKeyCode() == KeyEvent.VK_L) {
      player
          .getStats()
          .applyEffect(new Effect(new StatStructure(StatsEnum.EXPERIENCE, 1), 0, "At 1 EXP "));
    }
  }