public void displayTrain(int trainNumber) {
    this.trainNumber = trainNumber;

    trainViewJPanel1.display(trainNumber);
    String s;
    String destination = "";
    int priority = TrainModel.PRIORITY_NORMAL;
    int state = TrainModel.STATE_STOPPED;
    if (trainNumber >= 0) {
      TrainModel train =
          (TrainModel) w.get(KEY.TRAINS, trainNumber, modelRoot.getPlayerPrincipal());

      trainCargoBundleKey = train.getCargoBundle();
      CargoBundle cb = (CargoBundle) w.get(train.getCargoBundle());
      s = "Train #" + trainNumber + ": ";
      ScheduleIterator si = train.getScheduleIterator();
      TrainOrdersModel tom = si.getCurrentOrder(w);
      if (tom != null) {
        ObjectKey2 ok = tom.getStation();
        StationModel station = (StationModel) w.get(ok);
        destination = station.getStationName();
      }
      priority = train.getPriority();
      state = train.getState();
      setStatusLabel(train);
    } else {
      s = "No trains to display";
      setStatusLabel(null);
    }
    setStatusButton(priority, state);
    nameJLabel.setText(s);
    destinationJLabel.setText(destination);
  }
Exemplo n.º 2
0
  /**
   * _more_
   *
   * @param symbols _more_
   * @param listener _more_
   * @param smm _more_
   * @return _more_
   */
  public static List makeStationModelMenuItems(
      List symbols, final ObjectListener listener, StationModelManager smm) {
    List items = new ArrayList();
    List subMenus = new ArrayList();
    Hashtable categories = new Hashtable();
    for (int i = 0; i < symbols.size(); i++) {
      StationModel sm = (StationModel) symbols.get(i);
      boolean isUsers = smm.isUsers(sm);
      String name = sm.getName();
      if (name.equals("")) continue;
      List toks = StringUtil.split(name, ">", true, true);
      if (toks.size() > 0) {
        name = (String) toks.get(toks.size() - 1);
      }
      JMenuItem item = new JMenuItem(GuiUtils.getLocalName(name, isUsers));
      item.addActionListener(
          new ObjectListener(sm) {
            public void actionPerformed(ActionEvent ae) {
              listener.setObject(this.theObject);
              listener.actionPerformed(ae);
            }
          });

      toks.remove(toks.size() - 1);
      if (toks.size() == 0) {
        items.add(item);
        continue;
      }
      JMenu categoryMenu = null;
      String catSoFar = "";
      String menuCategory = "";
      for (int catIdx = 0; catIdx < toks.size(); catIdx++) {
        String subCat = (String) toks.get(catIdx);
        catSoFar = catSoFar + "/" + subCat;
        JMenu m = (JMenu) categories.get(catSoFar);
        if (m == null) {
          m = new JMenu(subCat);
          menuCategory = catSoFar;
          categories.put(catSoFar, m);
          if (categoryMenu != null) {
            categoryMenu.add(m, 0);
          } else {
            subMenus.add(m);
          }
        }
        categoryMenu = m;
      }
      if (categoryMenu == null) {
        categoryMenu = new JMenu("");
        categories.put(toks.toString(), categoryMenu);
        subMenus.add(categoryMenu);
        menuCategory = toks.toString();
      }
      categoryMenu.add(item);
    }
    items.addAll(subMenus);
    return items;
  }
Exemplo n.º 3
0
 /** Save the current station model under a new name */
 private void doSaveAs() {
   StationModel nl = getStationModel();
   String newName = smm.doSaveAs(nl, this);
   if (newName == null) {
     return;
   }
   nl = new StationModel(newName, new ArrayList(nl.getList()));
   setStationModel(nl, false);
   smm.addUsers(nl);
 }
Exemplo n.º 4
0
 /** Rename the current station model */
 protected void doRename() {
   if (!okToChange()) {
     return;
   }
   String newName = smm.doNew(this, "Rename", stationModel.getName(), "Use '>' to add categories");
   if (newName == null) {
     return;
   }
   doSave(false);
   StationModel sm = getStationModel();
   sm.setName(newName);
   setStationModel(sm, false);
   doSave(true);
 }
Exemplo n.º 5
0
 /**
  * Set the current station model
  *
  * @param newModel The station model
  * @param closeDialogs If true then close any dialog windows
  */
 public void setStationModel(StationModel newModel, boolean closeDialogs) {
   if (closeDialogs) {
     closeDialogs();
   }
   if (!smm.isUsers(newModel)) {
     List newGlyphs = cloneGlyphs(newModel.getList());
     newModel = new StationModel(newModel.getName(), newGlyphs);
     // new ArrayList(newModel.getList()));
   }
   stationModel = newModel;
   setGlyphs(cloneGlyphs(newModel.getList()));
   setName(stationModel.getDisplayName());
   setHaveChanged(false);
   frame.setTitle(
       GuiUtils.getApplicationTitle() + "Layout Model Editor -- " + stationModel.getName());
 }
Exemplo n.º 6
0
 /**
  * set the plot model
  *
  * @param sm the plot model
  */
 public void setPlotModel(StationModel sm) {
   this.plotModel = sm;
   if (sm != null) {
     label.setText(sm.getDisplayName());
   } else {
     label.setText("None");
   }
   label.repaint();
 }
Exemplo n.º 7
0
 /** Remove the current station model */
 protected void doRemove() {
   if (!GuiUtils.showYesNoDialog(
       null,
       "Are you sure you want to remove the station model: " + stationModel.getName() + "?",
       "Confirm")) {
     return;
   }
   smm.removeUsers(stationModel);
   initFromDefault();
 }
Exemplo n.º 8
0
  /**
   * @return the ObjectKey2 in the STATIONS table of the station owned by player p within the city
   *     radius, or -1 if there is no station
   */
  public ObjectKey2 hasStation(FreerailsPrincipal p) {
    int xmin = cityModel.getCityX() - cityModel.getCityRadius();
    int xmax = cityModel.getCityX() + cityModel.getCityRadius();
    int ymin = cityModel.getCityY() - cityModel.getCityRadius();
    int ymax = cityModel.getCityY() + cityModel.getCityRadius();

    xmin = xmin < 0 ? 0 : xmin;
    ymin = ymin < 0 ? 0 : ymin;
    xmax = xmax >= world.getMapWidth() ? world.getMapWidth() - 1 : xmax;
    ymax = ymax >= world.getMapHeight() ? world.getMapHeight() - 1 : ymax;

    Iterator i = world.getIterator(KEY.STATIONS, p);
    while (i.hasNext()) {
      StationModel sm = (StationModel) i.next();
      int x = sm.getStationX();
      int y = sm.getStationY();
      if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) {
        return new ObjectKey2(KEY.STATIONS, p, sm.getUUID());
      }
    }
    return null;
  }
Exemplo n.º 9
0
 /**
  * If there has been a change to the station model then ask the user if they want to save them
  *
  * @return Should the cancel proceed
  */
 boolean okToChange() {
   if (getHaveChanged()) {
     int result =
         GuiUtils.showYesNoCancelDialog(
             null,
             "Save changes to station model: " + stationModel.getName(),
             "Save station model changes");
     if (result == JOptionPane.CANCEL_OPTION) {
       return false;
     }
     if (result == JOptionPane.YES_OPTION) {
       doSave();
     }
   }
   return true;
 }
Exemplo n.º 10
0
 /**
  * Return the station model name
  *
  * @return The station model name
  */
 public String toString() {
   return stationModel.toString();
 }
Exemplo n.º 11
0
 /**
  * Get the current station model
  *
  * @return The current station model
  */
 public StationModel getStationModel() {
   stationModel.setList(getGlyphs());
   return stationModel;
 }