Exemplo n.º 1
0
  /**
   * Creates an information panel that shows the given texts and images, and an "OK" button.
   *
   * @param freeColClient The <code>FreeColClient</code> for the game.
   * @param texts The texts to be displayed in the panel.
   * @param fcos The source <code>FreeColObject</code> for the text.
   * @param images The images to be displayed in the panel.
   */
  public InformationPanel(
      FreeColClient freeColClient, String[] texts, FreeColObject[] fcos, ImageIcon[] images) {
    super(freeColClient, new MigLayout("wrap 1, insets 200 10 10 10", "[510]", "[242]20[20]"));

    final SwingGUI gui = getGUI();
    JPanel textPanel = new MigPanel();
    textPanel.setOpaque(false);
    textPanel.setLayout(new MigLayout("wrap 2", "", "top"));
    for (int i = 0; i < texts.length; i++) {
      if (images != null && images[i] != null) {
        textPanel.add(new JLabel(images[i]));
        textPanel.add(
            Utility.getDefaultTextArea(
                texts[i], new Dimension(475 - images[i].getIconWidth(), 185)));
      } else {
        textPanel.add(Utility.getDefaultTextArea(texts[i], new Dimension(475, 185)), "skip");
      }
      StringTemplate disp = displayLabel(fcos[i]);
      if (disp == null) continue;
      JButton button =
          Utility.localizedButton(
              StringTemplate.template("informationPanel.display")
                  .addStringTemplate("%object%", disp));
      final FreeColObject fco = fcos[i];
      button.addActionListener(
          (ActionEvent ae) -> {
            gui.displayObject(fco);
          });
      textPanel.add(button, "skip");
    }

    JScrollPane scrollPane =
        new JScrollPane(
            textPanel,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // correct way to make scroll pane opaque
    scrollPane.getViewport().setOpaque(false);
    scrollPane.setBorder(null);
    setBorder(null);

    add(scrollPane);
    add(okButton, "tag ok");
  }