From: Dan B. <dan...@us...> - 2011-04-23 16:58:11
|
Update of /cvsroot/jmri/jmri/jmrit/operations/rollingstock In directory vz-cvs-3.sog:/tmp/cvs-serv5781/src/jmri/jmrit/operations/rollingstock Modified Files: RollingStockSetFrame.java RollingStock.java Log Message: Minor code clean up Index: RollingStock.java =================================================================== RCS file: /cvsroot/jmri/jmri/jmrit/operations/rollingstock/RollingStock.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** RollingStock.java 20 Apr 2011 23:42:55 -0000 1.56 --- RollingStock.java 23 Apr 2011 16:58:09 -0000 1.57 *************** *** 321,325 **** * @param force when true place rolling stock ignore track length, type, & road * @return "okay" if successful, "type" if the rolling stock's type isn't ! * acceptable, or "length" if the rolling stock length didn't fit. */ public String setLocation(Location location, Track track, boolean force) { --- 321,326 ---- * @param force when true place rolling stock ignore track length, type, & road * @return "okay" if successful, "type" if the rolling stock's type isn't ! * acceptable, "road" if rolling stock road isn't acceptable, ! * or "length" if the rolling stock length didn't fit. */ public String setLocation(Location location, Track track, boolean force) { *************** *** 485,489 **** * @param destination * @param track ! * @return status */ public String testDestination(Location destination, Track track) { --- 486,490 ---- * @param destination * @param track ! * @return status OKAY, TYPE, ROAD, LENGTH, ERROR_TRACK */ public String testDestination(Location destination, Track track) { Index: RollingStockSetFrame.java =================================================================== RCS file: /cvsroot/jmri/jmri/jmrit/operations/rollingstock/RollingStockSetFrame.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** RollingStockSetFrame.java 17 Apr 2011 18:03:41 -0000 1.14 --- RollingStockSetFrame.java 23 Apr 2011 16:58:09 -0000 1.15 *************** *** 335,389 **** // save the statuses ! rs.setLocationUnknown(locationUnknownCheckBox.isSelected()); ! rs.setOutOfService(outOfServiceCheckBox.isSelected()); ! ! if (!ignoreLocationCheckBox.isSelected()){ ! if (locationBox.getSelectedItem() == null || locationBox.getSelectedItem().equals("")) { ! rs.setLocation(null, null); ! } else { ! if (trackLocationBox.getSelectedItem() == null ! || trackLocationBox.getSelectedItem().equals("")) { ! JOptionPane.showMessageDialog(this, ! getRb().getString("rsFullySelect"), getRb().getString("rsCanNotLoc"), ! JOptionPane.ERROR_MESSAGE); ! return false; ! } ! // update location only if it has changed ! if (rs.getLocation() == null || !rs.getLocation().equals(locationBox.getSelectedItem()) ! || rs.getTrack() == null || !rs.getTrack().equals(trackLocationBox.getSelectedItem())){ ! String status = rs.setLocation((Location) locationBox.getSelectedItem(), ! (Track)trackLocationBox.getSelectedItem()); ! if (!status.equals(RollingStock.OKAY)){ ! log.debug ("Can't set rs's location because of "+ status); ! JOptionPane.showMessageDialog(this, ! getRb().getString("rsCanNotLocMsg")+ status, ! getRb().getString("rsCanNotLoc"), ! JOptionPane.ERROR_MESSAGE); ! return false; ! } ! } ! } ! } ! if (!ignoreDestinationCheckBox.isSelected()){ ! if (destinationBox.getSelectedItem() == null || destinationBox.getSelectedItem().equals("")) { ! rs.setDestination(null, null); ! } else { ! Track destTrack = null; ! if (trackDestinationBox.getSelectedItem() != null ! && !trackDestinationBox.getSelectedItem().equals("")){ ! destTrack = (Track)trackDestinationBox.getSelectedItem(); ! } ! Location destination = (Location) destinationBox.getSelectedItem(); ! String status = rs.setDestination(destination, destTrack); ! if (!status.equals(RollingStock.OKAY)){ ! log.debug ("Can't set rs's destination because of "+ status); ! JOptionPane.showMessageDialog(this, ! getRb().getString("rsCanNotDestMsg")+ status, ! getRb().getString("rsCanNotDest"), ! JOptionPane.ERROR_MESSAGE); ! return false; ! } ! } } if (!ignoreTrainCheckBox.isSelected()){ if (trainBox.getSelectedItem() == null || trainBox.getSelectedItem().equals("")) --- 335,348 ---- // save the statuses ! if (!ignoreStatusCheckBox.isSelected()){ ! rs.setLocationUnknown(locationUnknownCheckBox.isSelected()); ! rs.setOutOfService(outOfServiceCheckBox.isSelected()); } + // update location and destination + if (!changeLocation(rs)) + return false; + if (!changeDestination(rs)) + return false; + if (!ignoreTrainCheckBox.isSelected()){ if (trainBox.getSelectedItem() == null || trainBox.getSelectedItem().equals("")) *************** *** 485,488 **** --- 444,502 ---- } + private boolean changeLocation(RollingStock rs){ + if (!ignoreLocationCheckBox.isSelected()){ + if (locationBox.getSelectedItem() == null || locationBox.getSelectedItem().equals("")) { + rs.setLocation(null, null); + } else { + if (trackLocationBox.getSelectedItem() == null + || trackLocationBox.getSelectedItem().equals("")) { + JOptionPane.showMessageDialog(this, + getRb().getString("rsFullySelect"), getRb().getString("rsCanNotLoc"), + JOptionPane.ERROR_MESSAGE); + return false; + } + // update location only if it has changed + if (rs.getLocation() == null || !rs.getLocation().equals(locationBox.getSelectedItem()) + || rs.getTrack() == null || !rs.getTrack().equals(trackLocationBox.getSelectedItem())){ + String status = rs.setLocation((Location) locationBox.getSelectedItem(), + (Track)trackLocationBox.getSelectedItem()); + if (!status.equals(RollingStock.OKAY)){ + log.debug ("Can't set rs's location because of "+ status); + JOptionPane.showMessageDialog(this, + getRb().getString("rsCanNotLocMsg")+ status, + getRb().getString("rsCanNotLoc"), + JOptionPane.ERROR_MESSAGE); + return false; + } + } + } + } + return true; + } + + private boolean changeDestination(RollingStock rs){ + if (!ignoreDestinationCheckBox.isSelected()){ + if (destinationBox.getSelectedItem() == null || destinationBox.getSelectedItem().equals("")) { + rs.setDestination(null, null); + } else { + Track destTrack = null; + if (trackDestinationBox.getSelectedItem() != null + && !trackDestinationBox.getSelectedItem().equals("")){ + destTrack = (Track)trackDestinationBox.getSelectedItem(); + } + String status = rs.setDestination((Location) destinationBox.getSelectedItem(), destTrack); + if (!status.equals(RollingStock.OKAY)){ + log.debug ("Can't set rs's destination because of "+ status); + JOptionPane.showMessageDialog(this, + getRb().getString("rsCanNotDestMsg")+ status, + getRb().getString("rsCanNotDest"), + JOptionPane.ERROR_MESSAGE); + return false; + } + } + } + return true; + } + protected void updateComboBoxes(){ if (_disableComboBoxUpdate) *************** *** 510,547 **** if (rs == _rs) continue; ! if (!ignoreLocationCheckBox.isSelected()){ ! if (locationBox.getSelectedItem() == null || locationBox.getSelectedItem().equals("")) { ! rs.setLocation(null, null); ! } else { ! String status = rs.setLocation((Location) locationBox.getSelectedItem(), ! (Track)trackLocationBox.getSelectedItem()); ! if (!status.equals(RollingStock.OKAY)){ ! log.debug ("Can't set the location for all of the rolling stock in the group because of "+ status); ! JOptionPane.showMessageDialog(this, ! getRb().getString("rsCanNotLocMsg")+ status, ! getRb().getString("rsCanNotLoc"), ! JOptionPane.ERROR_MESSAGE); ! return false; ! } ! } ! } ! if (!ignoreDestinationCheckBox.isSelected()){ ! if (destinationBox.getSelectedItem() == null || destinationBox.getSelectedItem().equals("")) { ! rs.setDestination(null, null); ! } else { ! Track track = null; ! if (trackDestinationBox.getSelectedItem() != null && !trackDestinationBox.getSelectedItem().equals("")) ! track = (Track)trackDestinationBox.getSelectedItem(); ! String status = rs.setDestination((Location)destinationBox.getSelectedItem(), track); ! if (!status.equals(RollingStock.OKAY)){ ! log.debug ("Can't set the destination for all of the rolling stock in the group because of "+ status); ! JOptionPane.showMessageDialog(this, ! getRb().getString("rsCanNotDestMsg")+ status, ! getRb().getString("rsCanNotDest"), ! JOptionPane.ERROR_MESSAGE); ! return false; ! } ! } } if (!ignoreTrainCheckBox.isSelected()){ if (trainBox.getSelectedItem() == null || trainBox.getSelectedItem().equals("")){ --- 524,538 ---- if (rs == _rs) continue; ! // Location status and out of service ! if (!ignoreStatusCheckBox.isSelected()){ ! rs.setLocationUnknown(locationUnknownCheckBox.isSelected()); ! rs.setOutOfService(outOfServiceCheckBox.isSelected()); } + // update location and destination + if (!changeLocation(rs)) + return false; + if (!changeDestination(rs)) + return false; + if (!ignoreTrainCheckBox.isSelected()){ if (trainBox.getSelectedItem() == null || trainBox.getSelectedItem().equals("")){ *************** *** 551,559 **** } } ! // Location status and out of service ! if (!ignoreStatusCheckBox.isSelected()){ ! rs.setLocationUnknown(locationUnknownCheckBox.isSelected()); ! rs.setOutOfService(outOfServiceCheckBox.isSelected()); ! } // remove rolling stock from being picked up and delivered rs.setRouteLocation(null); --- 542,546 ---- } } ! // remove rolling stock from being picked up and delivered rs.setRouteLocation(null); |