Example #1
0
  /**
   * Creates the statistics panel.
   *
   * @param freeColClient The <code>FreeColClient</code> for the game.
   */
  public StatisticsPanel(FreeColClient freeColClient) {
    super(freeColClient, new BorderLayout());

    // Retrieve the client and server data
    Map<String, String> serverStatistics = igc().getServerStatistics();
    Map<String, String> clientStatistics = igc().getClientStatistics();

    // Title
    JPanel header = new JPanel();
    this.add(header, BorderLayout.NORTH);
    header.add(Utility.localizedLabel("statistics"), JPanel.CENTER_ALIGNMENT);

    // Actual stats panel
    JPanel statsPanel = new JPanel(new GridLayout(1, 2));
    JScrollPane scrollPane =
        new JScrollPane(
            statsPanel,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // correct way to make scroll pane opaque
    scrollPane.getViewport().setOpaque(false);
    scrollPane.setBorder(null);

    this.add(scrollPane, BorderLayout.CENTER);
    statsPanel.add(displayStatsMessage("client", clientStatistics));
    statsPanel.add(displayStatsMessage("server", serverStatistics));

    add(okButton, BorderLayout.SOUTH);

    setSize(getPreferredSize());
  }
 /** {@inheritDoc} */
 @Override
 public Component getListCellRendererComponent(
     JList<? extends TradeRouteStop> list,
     TradeRouteStop value,
     int index,
     boolean isSelected,
     boolean hasFocus) {
   JPanel panel = (isSelected) ? SELECTED_COMPONENT : NORMAL_COMPONENT;
   panel.removeAll();
   panel.setForeground(list.getForeground());
   panel.setFont(list.getFont());
   Location location = value.getLocation();
   ImageLibrary lib = getImageLibrary();
   JLabel icon, name;
   if (location instanceof Europe) {
     Europe europe = (Europe) location;
     Image image = lib.getSmallerMiscIconImage(europe.getOwner().getNation());
     icon = new JLabel(new ImageIcon(image));
     name = Utility.localizedLabel(europe);
   } else if (location instanceof Colony) {
     Colony colony = (Colony) location;
     icon =
         new JLabel(
             new ImageIcon(
                 ImageLibrary.getSettlementImage(colony, lib.getScaleFactor() * 0.5f)));
     name = new JLabel(colony.getName());
   } else {
     throw new IllegalStateException("Bogus location: " + location);
   }
   panel.add(icon, "spany");
   panel.add(name, "span, wrap");
   for (GoodsType cargo : value.getCargo()) {
     panel.add(new JLabel(new ImageIcon(lib.getSmallerIconImage(cargo))));
   }
   return panel;
 }
  /**
   * Create a panel to define trade route cargos.
   *
   * @param freeColClient The <code>FreeColClient</code> for the game.
   * @param newRoute The <code>TradeRoute</code> to operate on.
   */
  public TradeRouteInputPanel(FreeColClient freeColClient, TradeRoute newRoute) {
    super(freeColClient, new MigLayout("wrap 4, fill", "[]20[fill]rel"));

    final Game game = freeColClient.getGame();
    final Player player = getMyPlayer();
    final TradeRoute tradeRoute = newRoute.copy(game, TradeRoute.class);

    this.newRoute = newRoute;
    this.cargoHandler = new CargoHandler();
    this.dragListener = new DragListener(freeColClient, this);
    this.dropListener = new DropListener();

    this.stopListModel = new DefaultListModel<>();
    for (TradeRouteStop stop : tradeRoute.getStops()) {
      this.stopListModel.addElement(stop);
    }

    this.stopList = new JList<>(this.stopListModel);
    this.stopList.setCellRenderer(new StopRenderer());
    this.stopList.setFixedCellHeight(48);
    this.stopList.setDragEnabled(true);
    this.stopList.setTransferHandler(new StopListHandler());
    this.stopList.addKeyListener(
        new KeyListener() {

          @Override
          public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_DELETE) {
              deleteCurrentlySelectedStops();
            }
          }

          @Override
          public void keyPressed(KeyEvent e) {} // Ignore

          @Override
          public void keyReleased(KeyEvent e) {} // Ignore
        });
    this.stopList.addListSelectionListener(this);
    JScrollPane tradeRouteView = new JScrollPane(stopList);

    JLabel nameLabel = Utility.localizedLabel("tradeRouteInputPanel.nameLabel");
    this.tradeRouteName = new JTextField(tradeRoute.getName());

    JLabel destinationLabel = Utility.localizedLabel("tradeRouteInputPanel.destinationLabel");
    this.destinationSelector = new JComboBox<>();
    this.destinationSelector.setRenderer(new DestinationCellRenderer());
    StringTemplate template = StringTemplate.template("tradeRouteInputPanel.allColonies");
    this.destinationSelector.addItem(Messages.message(template));
    if (player.getEurope() != null) {
      this.destinationSelector.addItem(player.getEurope().getId());
    }
    for (Colony colony : freeColClient.getMySortedColonies()) {
      this.destinationSelector.addItem(colony.getId());
    }

    this.messagesBox = new JCheckBox(Messages.message("tradeRouteInputPanel.silence"));
    this.messagesBox.setSelected(tradeRoute.isSilent());
    this.messagesBox.addActionListener(
        (ActionEvent ae) -> {
          tradeRoute.setSilent(messagesBox.isSelected());
        });

    this.addStopButton = Utility.localizedButton("tradeRouteInputPanel.addStop");
    this.addStopButton.addActionListener(
        (ActionEvent ae) -> {
          addSelectedStops();
        });

    this.removeStopButton = Utility.localizedButton("tradeRouteInputPanel.removeStop");
    this.removeStopButton.addActionListener(
        (ActionEvent ae) -> {
          deleteCurrentlySelectedStops();
        });

    this.goodsPanel = new GoodsPanel();
    this.goodsPanel.setTransferHandler(this.cargoHandler);
    this.goodsPanel.setEnabled(false);
    this.cargoPanel = new CargoPanel();
    this.cargoPanel.setTransferHandler(this.cargoHandler);

    JButton cancelButton = Utility.localizedButton("cancel");
    cancelButton.setActionCommand(CANCEL);
    cancelButton.addActionListener(this);
    setCancelComponent(cancelButton);

    add(Utility.localizedHeader("tradeRouteInputPanel.editRoute", false), "span, align center");
    add(tradeRouteView, "span 1 5, grow");
    add(nameLabel);
    add(this.tradeRouteName, "span");
    add(destinationLabel);
    add(this.destinationSelector, "span");
    add(this.messagesBox);
    add(this.addStopButton);
    add(this.removeStopButton, "span");
    add(this.goodsPanel, "span");
    add(this.cargoPanel, "span, height 80:, growy");
    add(okButton, "newline 20, span, split 2, tag ok");
    add(cancelButton, "tag cancel");

    // update cargo panel if stop is selected
    if (this.stopListModel.getSize() > 0) {
      this.stopList.setSelectedIndex(0);
      TradeRouteStop selectedStop = this.stopListModel.firstElement();
      this.cargoPanel.initialize(selectedStop);
    }

    // update buttons according to selection
    updateButtons();

    getGUI().restoreSavedSize(this, getPreferredSize());
  }
Example #4
0
  /**
   * The constructor that will add the items to this panel.
   *
   * @param freeColClient The <code>FreeColClient</code> for the game.
   */
  public AboutPanel(FreeColClient freeColClient) {
    super(freeColClient, new MigLayout("wrap"));

    // Header with image
    Image tempImage = ResourceManager.getImage("image.flavor.Title");
    JLabel apLogoLabel = new JLabel(new ImageIcon(tempImage));
    apLogoLabel.setBorder(
        new CompoundBorder(new EmptyBorder(2, 2, 2, 2), new BevelBorder(BevelBorder.LOWERED)));
    add(apLogoLabel, "center");

    // Create available Font choices
    Font fontBold =
        FontLibrary.createFont(
            FontLibrary.FontType.NORMAL,
            FontLibrary.FontSize.TINY,
            Font.BOLD,
            getImageLibrary().getScalingFactor());
    Font fontNormal =
        FontLibrary.createFont(
            FontLibrary.FontType.NORMAL,
            FontLibrary.FontSize.TINY,
            getImageLibrary().getScalingFactor());

    // Version
    JLabel apVersion = Utility.localizedLabel("aboutPanel.version");
    apVersion.setFont(fontBold);
    JLabel apRevision = new JLabel(FreeCol.getRevision());
    apRevision.setFont(fontNormal);
    add(apVersion, "newline 20");
    add(apRevision, "newline");

    // Official Site Link
    JLabel apOfficialSite = new JLabel();
    apOfficialSite = Utility.localizedLabel("aboutPanel.officialSite");
    apOfficialSite.setFont(fontBold);
    add(apOfficialSite, "newline 10");
    JButton apSiteURL = Utility.getLinkButton(SITE_URL, null, SITE_URL);
    apSiteURL.addActionListener(this);
    apSiteURL.setFont(fontNormal);
    add(apSiteURL, "newline");

    // SourceForge Project Site Link
    JLabel apSFProject = new JLabel();
    apSFProject = Utility.localizedLabel("aboutPanel.sfProject");
    apSFProject.setFont(fontBold);
    add(apSFProject, "newline 10");
    JButton apProjectURL = Utility.getLinkButton(PROJECT_URL, null, PROJECT_URL);
    apProjectURL.addActionListener(this);
    apProjectURL.setFont(fontNormal);
    add(apProjectURL, "newline");

    // License Disclaimer
    JTextArea apLegal = Utility.localizedTextArea("aboutPanel.legalDisclaimer");
    apLegal.setFont(fontNormal);
    add(apLegal, "newline 20, width 300px");

    // Copyright
    JLabel apCopyright = Utility.localizedLabel("aboutPanel.copyright");
    apCopyright.setFont(fontNormal);
    add(apCopyright, "newline 10");

    add(okButton, "newline 20, tag ok");
  }