Search in sources :

Example 11 with Block

use of jmri.Block 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 12 with Block

use of jmri.Block in project JMRI by JMRI.

the class SectionManagerXml method store.

/**
     * Implementation for storing the contents of a SectionManager
     *
     * @param o Object to store, of type SectionManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element sections = new Element("sections");
    setStoreElementClass(sections);
    SectionManager tm = (SectionManager) o;
    if (tm != null) {
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        // don't return an element if there are not Sections to include
        if (!iter.hasNext()) {
            return null;
        }
        // store the Section
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during store");
            } else {
                log.debug("Section system name is " + sname);
                Section x = tm.getBySystemName(sname);
                if (x.getSectionType() != Section.DYNAMICADHOC) {
                    Element elem = new Element("section");
                    elem.addContent(new Element("systemName").addContent(sname));
                    // store common part
                    storeCommon(x, elem);
                    String txt = "userdefined";
                    if (x.getSectionType() == Section.SIGNALMASTLOGIC) {
                        txt = "signalmastlogic";
                    }
                    elem.setAttribute("creationtype", txt);
                    txt = x.getForwardStoppingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("fstopsensorname", txt);
                    }
                    txt = x.getReverseStoppingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("rstopsensorname", txt);
                    }
                    txt = x.getForwardBlockingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("fsensorname", txt);
                    }
                    txt = x.getReverseBlockingSensorName();
                    if ((txt != null) && (!txt.equals(""))) {
                        elem.setAttribute("rsensorname", txt);
                    }
                    if (x.getSectionType() == Section.USERDEFINED) {
                        // save child block entries
                        int index = 0;
                        Block b = x.getBlockBySequenceNumber(index);
                        Element bElem = null;
                        while (b != null) {
                            bElem = new Element("blockentry");
                            bElem.setAttribute("sName", b.getSystemName());
                            bElem.setAttribute("order", Integer.toString(index));
                            elem.addContent(bElem);
                            index++;
                            b = x.getBlockBySequenceNumber(index);
                        }
                        // save child entry points
                        List<EntryPoint> epList = x.getEntryPointList();
                        Element epElem = null;
                        EntryPoint ep = null;
                        for (int i = 0; i < epList.size(); i++) {
                            ep = epList.get(i);
                            if (ep != null) {
                                epElem = new Element("entrypoint");
                                // add some protection against a reading problem
                                if (ep.getFromBlock() == null) {
                                    log.error("Unexpected null getFromBlock while storing ep " + i + " in Section " + sname + ", skipped");
                                    break;
                                }
                                epElem.setAttribute("fromblock", ep.getFromBlock().getSystemName());
                                if (ep.getBlock() == null) {
                                    log.error("Unexpected null getBlock while storing ep " + i + " in Section " + sname + ", skipped");
                                    break;
                                }
                                epElem.setAttribute("toblock", ep.getBlock().getSystemName());
                                epElem.setAttribute("direction", Integer.toString(ep.getDirection()));
                                epElem.setAttribute("fixed", "" + (ep.isFixed() ? "yes" : "no"));
                                epElem.setAttribute("fromblockdirection", "" + ep.getFromBlockDirection());
                                elem.addContent(epElem);
                            }
                        }
                    }
                    sections.addContent(elem);
                }
            }
        }
    }
    return (sections);
}
Also used : SectionManager(jmri.SectionManager) Element(org.jdom2.Element) Block(jmri.Block) EntryPoint(jmri.EntryPoint) Section(jmri.Section) EntryPoint(jmri.EntryPoint)

Example 13 with Block

use of jmri.Block in project JMRI by JMRI.

the class Maintenance method findOrphansPressed.

/**
     * Find orphaned elements in the various Manager Objects.
     *
     * @param parent Frame to check
     */
public static void findOrphansPressed(Frame parent) {
    Vector<String> display = new Vector<String>();
    Vector<String> names = new Vector<String>();
    Iterator<String> iter = InstanceManager.sensorManagerInstance().getSystemNameList().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (!search(name, null) && !name.equals("ISCLOCKRUNNING")) {
            display.add(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) getTypeAndNames(name)));
            names.add(name);
        }
    }
    iter = InstanceManager.turnoutManagerInstance().getSystemNameList().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (!search(name, null)) {
            display.add(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) getTypeAndNames(name)));
            names.add(name);
        }
    }
    iter = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSystemNameList().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (!search(name, null)) {
            display.add(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) getTypeAndNames(name)));
            names.add(name);
        }
    }
    iter = InstanceManager.lightManagerInstance().getSystemNameList().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (!search(name, null)) {
            display.add(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) getTypeAndNames(name)));
            names.add(name);
        }
    }
    iter = InstanceManager.getDefault(jmri.ConditionalManager.class).getSystemNameList().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (!search(name, null)) {
            display.add(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) getTypeAndNames(name)));
            names.add(name);
        }
    }
    iter = InstanceManager.getDefault(jmri.SectionManager.class).getSystemNameList().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (!search(name, null)) {
            display.add(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) getTypeAndNames(name)));
            names.add(name);
        }
    }
    iter = InstanceManager.getDefault(jmri.BlockManager.class).getSystemNameList().iterator();
    while (iter.hasNext()) {
        String name = iter.next();
        if (!search(name, null)) {
            display.add(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) getTypeAndNames(name)));
            names.add(name);
        }
    }
    DefaultListModel<String> listModel = new DefaultListModel<String>();
    for (int i = 0; i < display.size(); i++) {
        listModel.addElement(display.get(i));
    }
    JList<String> list = new JList<String>(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    JButton button = new JButton(Bundle.getMessage("ButtonDelete"));
    button.setToolTipText(rbm.getString("OrphanDeleteHint"));
    class SearchListener implements ActionListener {

        JList<String> list;

        Vector<String> n;

        SearchListener(JList<String> list, Vector<String> name) {
            this.list = list;
            this.n = name;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            int index = list.getMaxSelectionIndex();
            if (index < 0) {
                javax.swing.JOptionPane.showMessageDialog(null, rbm.getString("OrphanDeleteHint"), rbm.getString("DeleteTitle"), javax.swing.JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            int min = list.getMinSelectionIndex();
            DefaultListModel<String> model = (DefaultListModel<String>) list.getModel();
            while (index >= min) {
                String[] names = getTypeAndNames(n.get(index));
                if (names[0].equals("Sensor")) {
                    // NOI18N
                    Sensor s = InstanceManager.sensorManagerInstance().getBySystemName(names[2]);
                    if (s == null) {
                        s = InstanceManager.sensorManagerInstance().getBySystemName(names[1]);
                    }
                    InstanceManager.sensorManagerInstance().deregister(s);
                } else if (names[0].equals("Turnout")) {
                    // NOI18N
                    Turnout t = InstanceManager.turnoutManagerInstance().getBySystemName(names[2]);
                    if (t == null) {
                        t = InstanceManager.turnoutManagerInstance().getBySystemName(names[1]);
                    }
                    InstanceManager.turnoutManagerInstance().deregister(t);
                } else if (names[0].equals("SignalHead")) {
                    // NOI18N
                    SignalHead sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(names[2]);
                    if (sh == null) {
                        sh = InstanceManager.getDefault(jmri.SignalHeadManager.class).getBySystemName(names[1]);
                    }
                    InstanceManager.getDefault(jmri.SignalHeadManager.class).deregister(sh);
                } else if (names[0].equals("Light")) {
                    // NOI18N
                    Light l = InstanceManager.lightManagerInstance().getBySystemName(names[2]);
                    if (l == null) {
                        l = InstanceManager.lightManagerInstance().getBySystemName(names[1]);
                    }
                    InstanceManager.lightManagerInstance().deregister(l);
                } else if (names[0].equals("Conditional")) {
                    // NOI18N
                    Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(names[2]);
                    if (c == null) {
                        c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(names[1]);
                    }
                    InstanceManager.getDefault(jmri.ConditionalManager.class).deregister(c);
                } else if (names[0].equals("Section")) {
                    // NOI18N
                    jmri.Section sec = InstanceManager.getDefault(jmri.SectionManager.class).getBySystemName(names[2]);
                    if (sec == null) {
                        sec = InstanceManager.getDefault(jmri.SectionManager.class).getBySystemName(names[1]);
                    }
                    InstanceManager.getDefault(jmri.SectionManager.class).deregister(sec);
                } else if (names[0].equals("Block")) {
                    // NOI18N
                    jmri.Block b = InstanceManager.getDefault(jmri.BlockManager.class).getBySystemName(names[2]);
                    if (b == null) {
                        b = InstanceManager.getDefault(jmri.BlockManager.class).getBySystemName(names[1]);
                    }
                    InstanceManager.getDefault(jmri.BlockManager.class).deregister(b);
                }
                model.remove(index);
                n.remove(index);
                index--;
            }
            index++;
            if (index >= model.getSize()) {
                index = model.getSize() - 1;
            }
            if (index >= 0) {
                list.setSelectedIndex(index);
            }
        }
    }
    JScrollPane scrollPane = new JScrollPane(list);
    button.addActionListener(new SearchListener(list, names));
    button.setMaximumSize(button.getPreferredSize());
    makeDialog(scrollPane, button, parent, rbm.getString("OrphanTitle"));
}
Also used : ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) DefaultListModel(javax.swing.DefaultListModel) SignalHead(jmri.SignalHead) Conditional(jmri.Conditional) Light(jmri.Light) Vector(java.util.Vector) JScrollPane(javax.swing.JScrollPane) Block(jmri.Block) ActionListener(java.awt.event.ActionListener) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Turnout(jmri.Turnout) JList(javax.swing.JList) Sensor(jmri.Sensor)

Example 14 with Block

use of jmri.Block in project JMRI by JMRI.

the class TransitTableAction method connected.

@SuppressWarnings("unused")
private boolean connected(Section s1, Section s2) {
    if ((s1 != null) && (s2 != null)) {
        List<EntryPoint> s1Entries = s1.getEntryPointList();
        List<EntryPoint> s2Entries = s2.getEntryPointList();
        for (int i = 0; i < s1Entries.size(); i++) {
            Block b = s1Entries.get(i).getFromBlock();
            for (int j = 0; j < s2Entries.size(); j++) {
                if (b == s2Entries.get(j).getBlock()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EntryPoint(jmri.EntryPoint) Block(jmri.Block) EntryPoint(jmri.EntryPoint)

Example 15 with Block

use of jmri.Block in project JMRI by JMRI.

the class TransitTableAction method forwardConnected.

private boolean forwardConnected(Section s1, Section s2, int restrictedDirection) {
    if ((s1 != null) && (s2 != null)) {
        List<EntryPoint> s1ForwardEntries = s1.getForwardEntryPointList();
        List<EntryPoint> s2Entries = new ArrayList<>();
        if (restrictedDirection == Section.FORWARD) {
            s2Entries = s2.getReverseEntryPointList();
        } else if (restrictedDirection == Section.REVERSE) {
            s2Entries = s2.getForwardEntryPointList();
        } else {
            s2Entries = s2.getEntryPointList();
        }
        for (int i = 0; i < s1ForwardEntries.size(); i++) {
            Block b1 = s1ForwardEntries.get(i).getFromBlock();
            for (int j = 0; j < s2Entries.size(); j++) {
                Block b2 = s2Entries.get(j).getFromBlock();
                if ((b1 == s2Entries.get(j).getBlock()) && (b2 == s1ForwardEntries.get(i).getBlock())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) EntryPoint(jmri.EntryPoint) Block(jmri.Block) EntryPoint(jmri.EntryPoint)

Aggregations

Block (jmri.Block)84 ArrayList (java.util.ArrayList)19 EntryPoint (jmri.EntryPoint)16 Sensor (jmri.Sensor)10 Element (org.jdom2.Element)9 BlockManager (jmri.BlockManager)8 SignalMast (jmri.SignalMast)8 Turnout (jmri.Turnout)8 Test (org.junit.Test)7 Path (jmri.Path)6 Reporter (jmri.Reporter)6 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 Section (jmri.Section)5 Hashtable (java.util.Hashtable)4 NamedBean (jmri.NamedBean)4 SignalHead (jmri.SignalHead)4 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3