public UpgradesPanel(ORUIManager orUIManager) { super(BoxLayout.Y_AXIS); this.orUIManager = orUIManager; preferredSize = new Dimension((int) Math.round(100 * (2 + Scale.getFontScale()) / 3), 200); setSize(preferredSize); setVisible(true); upgradePanel = new JPanel(); upgradePanel.setOpaque(true); upgradePanel.setBackground(Color.DARK_GRAY); upgradePanel.setBorder(border); upgradePanel.setLayout(new GridLayout(defaultNbPanelElements, 1)); scrollPane = new JScrollPane(upgradePanel); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setSize(getPreferredSize()); doneButton.setActionCommand("Done"); doneButton.setMnemonic(KeyEvent.VK_D); doneButton.addActionListener(this); cancelButton.setActionCommand("Cancel"); cancelButton.setMnemonic(KeyEvent.VK_C); cancelButton.addActionListener(this); add(scrollPane); }
// populate version for corrections public void showCorrectionTokenUpgrades(MapCorrectionAction action) { // activate correctionTokenMode and deactivate standard tokenMode correctionTokenMode = true; tokenMode = false; // activate upgrade panel upgradePanel.removeAll(); GridLayout panelLayout = (GridLayout) upgradePanel.getLayout(); List<? extends TokenI> tokens = orUIManager.tokenLays; if (tokens == null || tokens.size() == 0) { // reset to the number of elements panelLayout.setRows(defaultNbPanelElements); // set to position 0 scrollPane.getVerticalScrollBar().setValue(0); } else { Color fgColour = null; Color bgColour = null; String text = null; String description = null; TokenIcon icon; CorrectionTokenLabel tokenLabel; correctionTokenLabels = new ArrayList<CorrectionTokenLabel>(); for (TokenI token : tokens) { if (token instanceof BaseToken) { PublicCompanyI comp = ((BaseToken) token).getCompany(); fgColour = comp.getFgColour(); bgColour = comp.getBgColour(); description = text = comp.getName(); } icon = new TokenIcon(25, fgColour, bgColour, text); tokenLabel = new CorrectionTokenLabel(icon, token); tokenLabel.setName(description); tokenLabel.setText(description); tokenLabel.setBackground(defaultLabelBgColour); tokenLabel.setOpaque(true); tokenLabel.setVisible(true); tokenLabel.setBorder(border); tokenLabel.addMouseListener(this); tokenLabel.addPossibleAction(action); correctionTokenLabels.add(tokenLabel); upgradePanel.add(tokenLabel); } } upgradePanel.add(doneButton); upgradePanel.add(cancelButton); // repaint(); revalidate(); }
// populate version for corrections public void showCorrectionTileUpgrades() { // deactivate correctionTokenMode and tokenmode correctionTokenMode = false; tokenMode = false; // activate upgrade panel upgradePanel.removeAll(); GridLayout panelLayout = (GridLayout) upgradePanel.getLayout(); List<TileI> tiles = orUIManager.tileUpgrades; if (tiles == null || tiles.size() == 0) { // reset to the number of elements panelLayout.setRows(defaultNbPanelElements); // set to position 0 scrollPane.getVerticalScrollBar().setValue(0); } else { // set to the max of available or the default number of elements panelLayout.setRows(Math.max(tiles.size() + 2, defaultNbPanelElements)); for (TileI tile : tiles) { BufferedImage hexImage = getHexImage(tile.getId()); ImageIcon hexIcon = new ImageIcon(hexImage); // Cheap n' Easy rescaling. hexIcon.setImage( hexIcon .getImage() .getScaledInstance( (int) (hexIcon.getIconWidth() * GUIHex.NORMAL_SCALE * 0.8), (int) (hexIcon.getIconHeight() * GUIHex.NORMAL_SCALE * 0.8), Image.SCALE_SMOOTH)); HexLabel hexLabel = new HexLabel(hexIcon, tile.getId()); hexLabel.setName(tile.getName()); hexLabel.setTextFromTile(tile); hexLabel.setOpaque(true); hexLabel.setVisible(true); hexLabel.setBorder(border); hexLabel.addMouseListener(this); upgradePanel.add(hexLabel); } } upgradePanel.add(doneButton); upgradePanel.add(cancelButton); // repaint(); revalidate(); }