コード例 #1
0
 /** Add any stops selected in the destination selector. */
 private void addSelectedStops() {
   int startIndex = -1;
   int endIndex = -1;
   int sel = this.destinationSelector.getSelectedIndex();
   if (sel == 0) { // All colonies + Europe
     startIndex = 1;
     endIndex = this.destinationSelector.getItemCount();
   } else { // just one place
     startIndex = sel;
     endIndex = startIndex + 1;
   }
   List<GoodsType> cargo = new ArrayList<>();
   for (Component comp : cargoPanel.getComponents()) {
     CargoLabel label = (CargoLabel) comp;
     cargo.add(label.getType());
   }
   int maxIndex = this.stopList.getMaxSelectionIndex();
   for (int i = startIndex; i < endIndex; i++) {
     String id = this.destinationSelector.getItemAt(i);
     FreeColGameObject fcgo = getGame().getFreeColGameObject(id);
     if (fcgo instanceof Location) {
       TradeRouteStop stop = new TradeRouteStop(getGame(), (Location) fcgo);
       stop.setCargo(cargo);
       if (maxIndex < 0) {
         this.stopListModel.addElement(stop);
       } else {
         maxIndex++;
         this.stopListModel.add(maxIndex, stop);
       }
     }
   }
 }
コード例 #2
0
 /** {@inheritDoc} */
 @Override
 protected void exportDone(JComponent source, Transferable data, int action) {
   try {
     CargoLabel label = (CargoLabel) data.getTransferData(DefaultTransferHandler.flavor);
     if (source.getParent() instanceof CargoPanel) {
       TradeRouteInputPanel.this.cargoPanel.remove(label);
       int[] indices = TradeRouteInputPanel.this.stopList.getSelectedIndices();
       for (int stopIndex : indices) {
         TradeRouteStop stop = TradeRouteInputPanel.this.stopListModel.get(stopIndex);
         List<GoodsType> cargo = new ArrayList<>(stop.getCargo());
         for (int index = 0; index < cargo.size(); index++) {
           if (cargo.get(index) == label.getType()) {
             cargo.remove(index);
             break;
           }
         }
         stop.setCargo(cargo);
       }
       TradeRouteInputPanel.this.stopList.revalidate();
       TradeRouteInputPanel.this.stopList.repaint();
       TradeRouteInputPanel.this.cargoPanel.revalidate();
       TradeRouteInputPanel.this.cargoPanel.repaint();
     }
   } catch (IOException | UnsupportedFlavorException ex) {
     logger.log(Level.WARNING, "CargoHandler export", ex);
   }
 }
コード例 #3
0
 public void initialize(TradeRouteStop newStop) {
   removeAll();
   if (newStop != null) {
     // stop = newStop;
     for (GoodsType goodsType : newStop.getCargo()) {
       add(new CargoLabel(goodsType));
     }
   }
   revalidate();
   repaint();
 }
コード例 #4
0
 /** {@inheritDoc} */
 @Override
 public boolean importData(JComponent target, Transferable data) {
   if (!canImport(target, data.getTransferDataFlavors())) return false;
   try {
     CargoLabel label = (CargoLabel) data.getTransferData(DefaultTransferHandler.flavor);
     if (target instanceof CargoPanel) {
       CargoLabel newLabel = new CargoLabel(label.getType());
       TradeRouteInputPanel.this.cargoPanel.add(newLabel);
       TradeRouteInputPanel.this.cargoPanel.revalidate();
       int[] indices = TradeRouteInputPanel.this.stopList.getSelectedIndices();
       for (int index : indices) {
         TradeRouteStop stop = TradeRouteInputPanel.this.stopListModel.get(index);
         stop.addCargo(label.getType());
       }
       TradeRouteInputPanel.this.stopList.revalidate();
       TradeRouteInputPanel.this.stopList.repaint();
     }
     return true;
   } catch (IOException | UnsupportedFlavorException ex) {
     logger.log(Level.WARNING, "CargoHandler import", ex);
   }
   return false;
 }
コード例 #5
0
 /** {@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;
 }