Search in sources :

Example 36 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class TrainSwitchListEditFrame method buildSwitchList.

/**
     * Print = all false;
     *
     * @param isPreview true if print preview
     * @param isChanged true if only print changes was requested
     * @param isCsv true if building a CSV switch list files
     * @param isUpdate true if only updating switch lists (no printing or
     *            preview)
     */
@SuppressFBWarnings(// NOI18N
value = { "UC_USELESS_CONDITION", "RpC_REPEATED_CONDITIONAL_TEST" }, // NOI18N
justification = "isChanged value is dependent on which user button is activated")
private void buildSwitchList(boolean isPreview, boolean isChanged, boolean isCsv, boolean isUpdate) {
    TrainSwitchLists trainSwitchLists = new TrainSwitchLists();
    // this for loop prevents ConcurrentModificationException when printing and status changes
    for (JCheckBox checkbox : new ArrayList<JCheckBox>(locationCheckBoxes)) {
        String locationName = checkbox.getName();
        Location location = locationManager.getLocationByName(locationName);
        if (location.isSwitchListEnabled()) {
            if (!isCsv) {
                // update switch list
                trainSwitchLists.buildSwitchList(location);
                // print or only print changes
                if (!isUpdate && (!isChanged || (isChanged && (location.getStatus().equals(Location.MODIFIED) || location.getStatus().equals(Location.UPDATED))))) {
                    trainSwitchLists.printSwitchList(location, isPreview);
                }
            } else if (Setup.isGenerateCsvSwitchListEnabled() && (!isChanged || (isChanged && location.getStatus().equals(Location.MODIFIED)))) {
                TrainCsvSwitchLists trainCsvSwitchLists = new TrainCsvSwitchLists();
                trainCsvSwitchLists.buildSwitchList(location);
            }
        }
    }
    // set trains switch lists printed
    TrainManager.instance().setTrainsSwitchListStatus(Train.PRINTED);
}
Also used : JCheckBox(javax.swing.JCheckBox) ArrayList(java.util.ArrayList) Location(jmri.jmrit.operations.locations.Location) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 37 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class ManageLocationsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (f == null || !f.isVisible()) {
        // Handle the Listener
        listenerLoc = VSDecoderManager.instance().getVSDecoderPreferences().getListenerPosition();
        // Handle Reporters
        ReporterManager rmgr = jmri.InstanceManager.getDefault(jmri.ReporterManager.class);
        String[] reporterNameArray = rmgr.getSystemNameArray();
        Object[][] reporterTable = new Object[reporterNameArray.length][6];
        reporterMap = new HashMap<String, PhysicalLocation>();
        int i = 0;
        for (String s : reporterNameArray) {
            Reporter r = rmgr.getByDisplayName(s);
            if (r instanceof PhysicalLocationReporter) {
                reporterMap.put(s, ((PhysicalLocationReporter) r).getPhysicalLocation());
                PhysicalLocation p = ((PhysicalLocationReporter) r).getPhysicalLocation();
                reporterTable[i][0] = s;
                reporterTable[i][1] = true;
                reporterTable[i][2] = p.getX();
                reporterTable[i][3] = p.getY();
                reporterTable[i][4] = p.getZ();
                reporterTable[i][5] = p.isTunnel();
            } else {
                reporterTable[i][0] = s;
                reporterTable[i][1] = false;
                reporterTable[i][2] = Float.valueOf(0.0f);
                reporterTable[i][3] = Float.valueOf(0.0f);
                reporterTable[i][4] = Float.valueOf(0.0f);
                reporterTable[i][5] = false;
            }
            i++;
        }
        // Handle Blocks
        BlockManager bmgr = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
        String[] blockNameArray = bmgr.getSystemNameArray();
        Object[][] blockTable = new Object[blockNameArray.length][6];
        blockMap = new HashMap<String, PhysicalLocation>();
        i = 0;
        for (String s : blockNameArray) {
            Block b = bmgr.getByDisplayName(s);
            // NOTE: Unlike Reporters, all Blocks are (now) PhysicalLocationReporters, so no need to do a check here.
            // We'll keep the explicit cast for now, but it's not actually necessary.
            blockMap.put(s, ((PhysicalLocationReporter) b).getPhysicalLocation());
            PhysicalLocation p = ((PhysicalLocationReporter) b).getPhysicalLocation();
            blockTable[i][0] = s;
            blockTable[i][1] = true;
            blockTable[i][2] = p.getX();
            blockTable[i][3] = p.getY();
            blockTable[i][4] = p.getZ();
            blockTable[i][5] = p.isTunnel();
            i++;
        }
        // Handle Ops Locations
        LocationManager lmgr = LocationManager.instance();
        List<Location> locations = lmgr.getLocationsByIdList();
        opsMap = new HashMap<String, PhysicalLocation>();
        log.debug("TableSize : " + locations.size());
        Object[][] opsTable = new Object[locations.size()][6];
        i = 0;
        for (Location l : locations) {
            if (log.isDebugEnabled()) {
                log.debug("i = " + i + "MLA " + l.getId() + " Name: " + l.getName() + " table " + java.util.Arrays.toString(opsTable[i]));
            }
            PhysicalLocation p = l.getPhysicalLocation();
            Boolean use = false;
            if (p == PhysicalLocation.Origin) {
                use = false;
            } else {
                use = true;
            }
            opsTable[i][0] = l.getName();
            opsTable[i][1] = use;
            opsTable[i][2] = p.getX();
            opsTable[i][3] = p.getY();
            opsTable[i][4] = p.getZ();
            opsTable[i][5] = p.isTunnel();
            opsMap.put(l.getName(), l.getPhysicalLocation());
            i++;
        }
        f = new ManageLocationsFrame(listenerLoc, reporterTable, opsTable, blockTable);
    }
    f.setExtendedState(Frame.NORMAL);
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ReporterManager(jmri.ReporterManager) PhysicalLocationReporter(jmri.PhysicalLocationReporter) Reporter(jmri.Reporter) BlockManager(jmri.BlockManager) Block(jmri.Block) PhysicalLocationReporter(jmri.PhysicalLocationReporter) PhysicalLocation(jmri.util.PhysicalLocation) PhysicalLocation(jmri.util.PhysicalLocation) Location(jmri.jmrit.operations.locations.Location)

Example 38 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class LocationsByCarLoadFrame method removePropertyChangeLocations.

private void removePropertyChangeLocations() {
    for (Location location : locationManager.getList()) {
        location.removePropertyChangeListener(this);
        List<Track> tracks = location.getTrackList();
        for (Track track : tracks) {
            track.removePropertyChangeListener(this);
        }
    }
}
Also used : Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Example 39 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class LocationCopyFrame method buttonActionPerformed.

@Override
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "GUI ease of use")
protected void buttonActionPerformed(java.awt.event.ActionEvent ae) {
    if (ae.getSource() == copyButton) {
        log.debug("copy location button activated");
        if (!checkName()) {
            return;
        }
        if (locationBox.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("SelectLocationToCopy"), MessageFormat.format(Bundle.getMessage("CanNotLocation"), new Object[] { Bundle.getMessage("ButtonCopy") }), JOptionPane.ERROR_MESSAGE);
            return;
        }
        Location location = (Location) locationBox.getSelectedItem();
        // check to see if there are cars scheduled for pickup or set out
        if (moveRollingStockCheckBox.isSelected()) {
            for (Track track : location.getTrackList()) {
                if (track.getPickupRS() > 0) {
                    JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("FoundRollingStockPickUp"), new Object[] { track.getPickupRS() }), MessageFormat.format(Bundle.getMessage("TrainsServicingTrack"), new Object[] { track.getName() }), JOptionPane.WARNING_MESSAGE);
                    // can't move rolling stock, some are scheduled for a pick up
                    return;
                }
                if (track.getDropRS() > 0) {
                    JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("FoundRollingStockDrop"), new Object[] { track.getDropRS() }), MessageFormat.format(Bundle.getMessage("TrainsServicingTrack"), new Object[] { track.getName() }), JOptionPane.WARNING_MESSAGE);
                    // can't move rolling stock, some are scheduled for drops
                    return;
                }
            }
        }
        // now copy all of the tracks
        Location newLocation = locationManager.newLocation(loctionNameTextField.getText());
        location.copyLocation(newLocation);
        // does the user want the cars to also move to the new tracks?
        if (moveRollingStockCheckBox.isSelected()) {
            for (Track track : location.getTrackList()) {
                moveRollingStock(track, newLocation.getTrackByName(track.getName(), null));
                if (deleteTrackCheckBox.isSelected()) {
                    location.deleteTrack(track);
                }
            }
        }
    }
    if (ae.getSource() == saveButton) {
        log.debug("save track button activated");
        // save checkbox states
        moveRollingStock = moveRollingStockCheckBox.isSelected();
        deleteTrack = deleteTrackCheckBox.isSelected();
        // save location file
        OperationsXml.save();
    }
}
Also used : Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 40 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class PrintLocationsAction method printCommentsSelected.

private void printCommentsSelected() throws IOException {
    String s = Bundle.getMessage("PrintComments") + NEW_LINE + NEW_LINE;
    writer.write(s);
    List<Location> locations = manager.getLocationsByNameList();
    for (Location location : locations) {
        if (_location != null && location != _location) {
            continue;
        }
        s = location.getName() + NEW_LINE;
        writer.write(s);
        s = SPACE + location.getComment() + NEW_LINE;
        writer.write(s);
        for (Track track : location.getTrackByNameList(null)) {
            if (!track.getComment().equals(Track.NONE) || !track.getCommentBoth().equals(Track.NONE) || !track.getCommentPickup().equals(Track.NONE) || !track.getCommentSetout().equals(Track.NONE)) {
                s = SPACE + track.getName() + NEW_LINE;
                writer.write(s);
                if (!track.getComment().equals(Track.NONE)) {
                    s = SPACE + SPACE + track.getComment() + NEW_LINE;
                    writer.write(s);
                }
                if (!track.getCommentBoth().equals(Track.NONE)) {
                    s = SPACE + SPACE + Bundle.getMessage("CommentBoth") + ":" + NEW_LINE;
                    writer.write(s);
                    s = SPACE + SPACE + track.getCommentBoth() + NEW_LINE;
                    writer.write(s);
                }
                if (!track.getCommentPickup().equals(Track.NONE)) {
                    s = SPACE + SPACE + Bundle.getMessage("CommentPickup") + ":" + NEW_LINE;
                    writer.write(s);
                    s = SPACE + SPACE + track.getCommentPickup() + NEW_LINE;
                    writer.write(s);
                }
                if (!track.getCommentSetout().equals(Track.NONE)) {
                    s = SPACE + SPACE + Bundle.getMessage("CommentSetout") + ":" + NEW_LINE;
                    writer.write(s);
                    s = SPACE + SPACE + track.getCommentSetout() + NEW_LINE;
                    writer.write(s);
                }
            }
        }
    }
    if (printDetails.isSelected() || printAnalysis.isSelected()) {
        writer.write(FORM_FEED);
    }
}
Also used : Track(jmri.jmrit.operations.locations.Track) Location(jmri.jmrit.operations.locations.Location)

Aggregations

Location (jmri.jmrit.operations.locations.Location)186 Track (jmri.jmrit.operations.locations.Track)108 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)82 Route (jmri.jmrit.operations.routes.Route)51 LocationManager (jmri.jmrit.operations.locations.LocationManager)43 Car (jmri.jmrit.operations.rollingstock.cars.Car)41 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)29 RouteManager (jmri.jmrit.operations.routes.RouteManager)21 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)19 Test (org.junit.Test)18 JCheckBox (javax.swing.JCheckBox)13 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)13 Train (jmri.jmrit.operations.trains.Train)13 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)10 File (java.io.File)9 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)9 TrainManager (jmri.jmrit.operations.trains.TrainManager)8