コード例 #1
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);
   }
 }
コード例 #2
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);
       }
     }
   }
 }
コード例 #3
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;
 }