public CargoPanel() { super(); setOpaque(false); setBorder(Utility.localizedBorder("cargoOnCarrier")); addMouseListener(TradeRouteInputPanel.this.dropListener); }
/** * 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()); }
public GoodsPanel() { super(new GridLayout(0, 4, MARGIN, MARGIN)); for (GoodsType goodsType : getSpecification().getGoodsTypeList()) { if (goodsType.isStorable()) { CargoLabel label = new CargoLabel(goodsType); add(label); } } setOpaque(false); setBorder(Utility.localizedBorder("goods")); addMouseListener(TradeRouteInputPanel.this.dropListener); }
/** {@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; }
private JPanel displayStatsMessage(String title, Map<String, String> stats) { JPanel panel = new JPanel(); panel.setBorder(Utility.localizedBorder(title)); Box b = new Box(BoxLayout.Y_AXIS); panel.add(b); Map<String, String> memory = new HashMap<>(); Map<String, String> ai = new HashMap<>(); for (String k : memoryKeys) { memory.put(Messages.message("memoryManager." + k), stats.remove(k)); } for (String k : new ArrayList<>(stats.keySet())) { if (k.startsWith("AI")) { // FIXME: AIMain.aiStatisticsPrefix ai.put(k, stats.remove(k)); } } b.add(createStatsTable("Memory", memory)); b.add(createStatsTable("Game", stats)); if (ai.isEmpty()) { b.add(new JLabel()); } else { b.add(createStatsTable("AI", ai)); } 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()); }