public LabourUnitPanel(UnitType unitType, int count) { this.unitType = unitType; setOpaque(false); setLayout(new MigLayout("wrap 2", "[60, right][left]")); add( new JLabel(new ImageIcon(getImageLibrary().getSmallUnitImage(unitType, (count == 0)))), "spany 2"); add(new JLabel(Messages.getName(unitType))); add(new JLabel(Integer.toString(count))); }
/** * Get a label for one of the wanted goods. * * @param index The index into the wanted goods. * @param player The requesting <code>Player</code>. * @return A suitable <code>StringTemplate</code>. */ public StringTemplate getWantedGoodsLabel(int index, Player player) { StringTemplate ret; if (hasVisited(player) && 0 <= index && index < wantedGoods.length) { if (wantedGoods[index] == null) { ret = StringTemplate.key("model.indianSettlement.wantedGoodsNone"); } else { ret = StringTemplate.label("").add(Messages.nameKey(wantedGoods[index])); String sale = player.getLastSaleString(this, wantedGoods[index]); if (sale != null) ret.addName(" " + sale); } } else { ret = StringTemplate.key("model.indianSettlement.wantedGoodsUnknown"); } return ret; }
/** {@inheritDoc} */ @Override public Component getListCellRendererComponent( JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) { FreeColGameObject fcgo = getGame().getFreeColGameObject(value); if (fcgo instanceof Location) { setText(Messages.message(((Location) fcgo).getLocationLabel())); } else { setText(value); } setForeground((isSelected) ? list.getSelectionForeground() : list.getForeground()); setBackground((isSelected) ? list.getSelectionBackground() : list.getBackground()); return this; }
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()); }
/** {@inheritDoc} */ @Override public String getColumnName(int column) { return Messages.message(columnNames[column]); }