use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class PrintLocationsByCarTypesAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// obtain a HardcopyWriter
try {
writer = new HardcopyWriter(mFrame, Bundle.getMessage("TitleLocationsByType"), Control.reportFontSize, .5, .5, .5, .5, isPreview);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
}
// Loop through the car types showing which locations and tracks will
// service that car type
String[] carTypes = CarTypes.instance().getNames();
List<Location> locations = locManager.getLocationsByNameList();
try {
// title line
String s = Bundle.getMessage("Type") + TAB + Bundle.getMessage("Location") + TAB + Bundle.getMessage("Track") + NEW_LINE;
writer.write(s);
// car types
for (String type : carTypes) {
s = type + NEW_LINE;
writer.write(s);
// locations
for (Location location : locations) {
if (location.acceptsTypeName(type)) {
s = TAB + location.getName() + NEW_LINE;
writer.write(s);
// tracks
List<Track> tracks = location.getTrackByNameList(null);
for (Track track : tracks) {
if (track.acceptsTypeName(type)) {
s = TAB + TAB + TAB + track.getName() + NEW_LINE;
writer.write(s);
}
}
}
}
}
// and force completion of the printing
writer.close();
} catch (IOException we) {
log.error("Error printing PrintLocationAction: " + we);
}
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class PrintLocationsAction method getDestinations.
private String getDestinations(Track track) {
if (track.getDestinationOption().equals(Track.ALL_DESTINATIONS)) {
return "";
}
String op = Bundle.getMessage("AcceptOnly") + " " + track.getDestinationListSize() + " " + Bundle.getMessage("Destinations") + ":";
if (track.getDestinationOption().equals(Track.EXCLUDE_DESTINATIONS)) {
op = Bundle.getMessage("Exclude") + " " + (LocationManager.instance().getNumberOfLocations() - track.getDestinationListSize()) + " " + Bundle.getMessage("Destinations") + ":";
}
StringBuffer buf = new StringBuffer(TAB + TAB + op + NEW_LINE + TAB + TAB);
String[] destIds = track.getDestinationIds();
int charCount = 0;
for (String id : destIds) {
Location location = manager.getLocationById(id);
if (location == null) {
continue;
}
charCount += location.getName().length() + 2;
if (charCount > charactersPerLine - 2 * TAB_LENGTH) {
buf.append(NEW_LINE + TAB + TAB);
charCount = location.getName().length() + 2;
}
buf.append(location.getName() + ", ");
}
if (buf.length() > 2) {
// remove trailing separators
buf.setLength(buf.length() - 2);
}
buf.append(NEW_LINE);
return buf.toString();
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class PrintLocationsAction method printLocationsSelected.
// Loop through the Roster, printing as needed
private void printLocationsSelected() throws IOException {
List<Location> locations = manager.getLocationsByNameList();
int totalLength = 0;
int usedLength = 0;
int numberRS = 0;
int numberCars = 0;
int numberEngines = 0;
// header
String s = Bundle.getMessage("Location") + TAB + TAB + TAB + Bundle.getMessage("Length") + " " + Bundle.getMessage("Used") + TAB + Bundle.getMessage("RS") + TAB + Bundle.getMessage("Cars") + TAB + Bundle.getMessage("Engines") + TAB + Bundle.getMessage("Pickups") + " " + Bundle.getMessage("Drop") + NEW_LINE;
writer.write(s);
for (Location location : locations) {
if (_location != null && location != _location) {
continue;
}
// location name, track length, used, number of RS, scheduled pick ups and drops
s = padOutString(location.getName(), Control.max_len_string_location_name) + TAB + " " + Integer.toString(location.getLength()) + TAB + Integer.toString(location.getUsedLength()) + TAB + Integer.toString(location.getNumberRS()) + TAB + Integer.toString(location.getNumberCars()) + TAB + Integer.toString(location.getNumberEngines()) + TAB + Integer.toString(location.getPickupRS()) + TAB + Integer.toString(location.getDropRS()) + NEW_LINE;
writer.write(s);
totalLength += location.getLength();
usedLength += location.getUsedLength();
numberRS += location.getNumberRS();
List<Track> yards = location.getTrackByNameList(Track.YARD);
if (yards.size() > 0) {
// header
writer.write(SPACE + Bundle.getMessage("YardName") + NEW_LINE);
for (Track yard : yards) {
writer.write(getTrackString(yard));
numberCars += yard.getNumberCars();
numberEngines += yard.getNumberEngines();
}
}
List<Track> spurs = location.getTrackByNameList(Track.SPUR);
if (spurs.size() > 0) {
// header
writer.write(SPACE + Bundle.getMessage("SpurName") + NEW_LINE);
for (Track spur : spurs) {
writer.write(getTrackString(spur));
numberCars += spur.getNumberCars();
numberEngines += spur.getNumberEngines();
}
}
List<Track> interchanges = location.getTrackByNameList(Track.INTERCHANGE);
if (interchanges.size() > 0) {
// header
writer.write(SPACE + Bundle.getMessage("InterchangeName") + NEW_LINE);
for (Track interchange : interchanges) {
writer.write(getTrackString(interchange));
numberCars += interchange.getNumberCars();
numberEngines += interchange.getNumberEngines();
}
}
List<Track> stagingTracks = location.getTrackByNameList(Track.STAGING);
if (stagingTracks.size() > 0) {
// header
writer.write(SPACE + Bundle.getMessage("StagingName") + NEW_LINE);
for (Track staging : stagingTracks) {
writer.write(getTrackString(staging));
numberCars += staging.getNumberCars();
numberEngines += staging.getNumberEngines();
}
}
writer.write(NEW_LINE);
}
// summary
s = MessageFormat.format(Bundle.getMessage("TotalLengthMsg"), new Object[] { Integer.toString(totalLength), Integer.toString(usedLength), totalLength > 0 ? Integer.toString(usedLength * 100 / totalLength) : 0 }) + NEW_LINE;
writer.write(s);
s = MessageFormat.format(Bundle.getMessage("TotalRollingMsg"), new Object[] { Integer.toString(numberRS), Integer.toString(numberCars), Integer.toString(numberEngines) }) + NEW_LINE;
writer.write(s);
// are there trains en route, then some cars and engines not counted!
if (numberRS != numberCars + numberEngines) {
s = MessageFormat.format(Bundle.getMessage("NoteRSMsg"), new Object[] { Integer.toString(numberRS - (numberCars + numberEngines)) }) + NEW_LINE;
writer.write(s);
}
if (printSchedules.isSelected() || printComments.isSelected() || printDetails.isSelected() || printAnalysis.isSelected()) {
writer.write(FORM_FEED);
}
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrackCopyFrame method updateTrackComboBox.
protected void updateTrackComboBox() {
log.debug("update track combobox");
if (locationBox.getSelectedItem() == null) {
trackBox.removeAllItems();
} else {
log.debug("Copy Track Frame sees location: {}", locationBox.getSelectedItem());
Location l = (Location) locationBox.getSelectedItem();
l.updateComboBox(trackBox);
}
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class SetPhysicalLocationFrame method buttonActionPerformed.
@Override
public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
// check to see if a location has been selected
if (locationBox.getSelectedItem() == null) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("SelectLocationToEdit"), Bundle.getMessage("NoLocationSelected"), JOptionPane.ERROR_MESSAGE);
return;
}
Location l = (Location) locationBox.getSelectedItem();
if (l == null) {
return;
}
if (ae.getSource() == saveButton) {
int value = JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("UpdatePhysicalLocation"), new Object[] { l.getName() }), Bundle.getMessage("UpdateDefaults"), JOptionPane.YES_NO_OPTION);
if (value == JOptionPane.YES_OPTION) {
saveSpinnerValues(l);
}
OperationsXml.save();
if (Setup.isCloseWindowOnSaveEnabled()) {
dispose();
}
}
}
Aggregations