Search in sources :

Example 6 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class DetectionPanel method checkDetection.

/*
     * ******************************************
     */
private void checkDetection() {
    String name = _occDetectorName.getText();
    if (name != null && name.trim().length() > 0) {
        OBlock block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock(name);
        if (block != null) {
            if (block.equals(_block)) {
                return;
            }
            makePathList(block);
        } else {
            Sensor sensor = InstanceManager.sensorManagerInstance().getSensor(name);
            if (sensor == null) {
                JOptionPane.showMessageDialog(_parent._paletteFrame, Bundle.getMessage("InvalidOccDetector", name), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
                _occDetectorName.setText(null);
            }
            _blockPathPanel.setVisible(false);
            _block = null;
        }
    } else {
        _blockPathPanel.setVisible(false);
        _block = null;
    }
}
Also used : OBlock(jmri.jmrit.logix.OBlock) Sensor(jmri.Sensor)

Example 7 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class IndicatorTurnoutIcon method setOccBlockHandle.

@Override
public void setOccBlockHandle(NamedBeanHandle<OBlock> blockHandle) {
    if (namedOccBlock != null) {
        getOccBlock().removePropertyChangeListener(this);
    }
    namedOccBlock = blockHandle;
    if (namedOccBlock != null) {
        OBlock block = getOccBlock();
        block.addPropertyChangeListener(this, namedOccBlock.getName(), "Indicator Turnout Icon");
        setStatus(block, block.getState());
        if (_iconMaps != null) {
            displayState(turnoutState());
        }
        setTooltip(new ToolTip(block.getDescription(), 0, 0));
    }
}
Also used : OBlock(jmri.jmrit.logix.OBlock)

Example 8 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class IndicatorTurnoutIconXml method store.

/**
     * Default implementation for storing the contents of a IndicatorTurnoutIcon
     *
     * @param o Object to store, of type IndicatorTurnoutIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    IndicatorTurnoutIcon p = (IndicatorTurnoutIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("indicatorturnouticon");
    storeCommonAttributes(p, element);
    NamedBeanHandle<Turnout> t = p.getNamedTurnout();
    if (t != null) {
        element.addContent(storeNamedBean("turnout", t));
    }
    NamedBeanHandle<OBlock> b = p.getNamedOccBlock();
    if (b != null) {
        element.addContent(storeNamedBean("occupancyblock", b));
    }
    NamedBeanHandle<Sensor> s = p.getNamedOccSensor();
    if (b == null && s != null) {
        // only write sensor if no OBlock
        element.addContent(storeNamedBean("occupancysensor", s));
    }
    Element elem = new Element("showTrainName");
    String show = "no";
    if (p.showTrain()) {
        show = "yes";
    }
    elem.addContent(show);
    element.addContent(elem);
    HashMap<String, HashMap<Integer, NamedIcon>> iconMaps = p.getIconMaps();
    Iterator<Entry<String, HashMap<Integer, NamedIcon>>> it = iconMaps.entrySet().iterator();
    Element el = new Element("iconmaps");
    String family = p.getFamily();
    if (family != null) {
        el.setAttribute("family", family);
    }
    while (it.hasNext()) {
        Entry<String, HashMap<Integer, NamedIcon>> ent = it.next();
        elem = new Element(ent.getKey());
        Iterator<Entry<Integer, NamedIcon>> iter = ent.getValue().entrySet().iterator();
        while (iter.hasNext()) {
            Entry<Integer, NamedIcon> entry = iter.next();
            elem.addContent(storeIcon(p.getStateName(entry.getKey()), entry.getValue()));
        }
        el.addContent(elem);
    }
    element.addContent(el);
    elem = new Element("paths");
    ArrayList<String> paths = p.getPaths();
    if (paths != null) {
        for (int i = 0; i < paths.size(); i++) {
            Element e = new Element("path");
            e.addContent(paths.get(i));
            elem.addContent(e);
        }
        element.addContent(elem);
    }
    element.setAttribute("class", "jmri.jmrit.display.configurexml.IndicatorTurnoutIconXml");
    return element;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) Element(org.jdom2.Element) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Entry(java.util.Map.Entry) Turnout(jmri.Turnout) OBlock(jmri.jmrit.logix.OBlock) Sensor(jmri.Sensor)

Example 9 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class EditPortalFrame method findAdjacentBlock.

/*
     * If icon is on the home block, find another intersecting block
     */
private OBlock findAdjacentBlock(PortalIcon icon) {
    ArrayList<OBlock> neighbors = new ArrayList<OBlock>();
    OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    String[] sysNames = manager.getSystemNameArray();
    for (int j = 0; j < sysNames.length; j++) {
        OBlock block = manager.getBySystemName(sysNames[j]);
        if (block.equals(_homeBlock)) {
            continue;
        }
        if (iconIntersectsBlock(icon, block) == null) {
            neighbors.add(block);
        }
    }
    OBlock block = null;
    if (neighbors.size() == 1) {
        block = neighbors.get(0);
    } else if (neighbors.size() > 1) {
        // show list
        String[] selects = new String[neighbors.size()];
        Iterator<OBlock> iter = neighbors.iterator();
        int i = 0;
        while (iter.hasNext()) {
            selects[i++] = iter.next().getDisplayName();
        }
        Object select = JOptionPane.showInputDialog(this, Bundle.getMessage("multipleBlockSelections", _homeBlock.getDisplayName()), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE, null, selects, null);
        if (select != null) {
            iter = neighbors.iterator();
            while (iter.hasNext()) {
                block = iter.next();
                if (((String) select).equals(block.getDisplayName())) {
                    return block;
                }
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("findAdjacentBlock: neighbors.size()= " + neighbors.size() + " return " + (block == null ? "null" : block.getDisplayName()));
    }
    return block;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) OBlockManager(jmri.jmrit.logix.OBlockManager) OBlock(jmri.jmrit.logix.OBlock) Point(java.awt.Point)

Example 10 with OBlock

use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.

the class PortalIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    if (!(o instanceof ControlPanelEditor)) {
        log.error("Can't load portalIcon.  Panel editor must use ControlPanelEditor.");
        return;
    }
    ControlPanelEditor ed = (ControlPanelEditor) o;
    String fromBlk;
    try {
        fromBlk = element.getAttribute("fromBlockName").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for portalIcon; must use fromBlockName.");
        //            ed.loadFailed();
        return;
    }
    String portalName;
    try {
        portalName = element.getAttribute("portalName").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for portalIcon; must use portalName.");
        //            ed.loadFailed();
        return;
    }
    OBlock block = jmri.InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock(fromBlk);
    Portal portal = block.getPortalByName(portalName);
    PortalIcon l = new PortalIcon(ed, portal);
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, ControlPanelEditor.MARKERS, element);
    Attribute a = element.getAttribute("scale");
    double scale = 1.0;
    if (a != null) {
        try {
            scale = a.getDoubleValue();
        } catch (org.jdom2.DataConversionException dce) {
            log.error(l.getNameString() + " can't convert scale " + dce);
        }
    }
    l.setScale(scale);
    a = element.getAttribute("rotate");
    int deg = 0;
    if (a != null) {
        try {
            deg = a.getIntValue();
        } catch (org.jdom2.DataConversionException dce) {
            log.error(l.getNameString() + " can't convert rotate " + dce);
        }
    }
    l.rotate(deg);
    boolean value = true;
    if ((a = element.getAttribute("arrowSwitch")) != null && a.getValue().equals("no")) {
        value = false;
    }
    l.setArrowOrientatuon(value);
    value = false;
    if ((a = element.getAttribute("arrowHide")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    l.setHideArrows(value);
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Attribute(org.jdom2.Attribute) PortalIcon(jmri.jmrit.display.controlPanelEditor.PortalIcon) Portal(jmri.jmrit.logix.Portal) OBlock(jmri.jmrit.logix.OBlock)

Aggregations

OBlock (jmri.jmrit.logix.OBlock)40 Portal (jmri.jmrit.logix.Portal)13 OBlockManager (jmri.jmrit.logix.OBlockManager)10 Element (org.jdom2.Element)10 ArrayList (java.util.ArrayList)6 Positionable (jmri.jmrit.display.Positionable)6 NamedBean (jmri.NamedBean)5 Sensor (jmri.Sensor)5 Point (java.awt.Point)4 OPath (jmri.jmrit.logix.OPath)4 PropertyVetoException (java.beans.PropertyVetoException)3 Entry (java.util.Map.Entry)3 JMenu (javax.swing.JMenu)3 Reporter (jmri.Reporter)3 Attribute (org.jdom2.Attribute)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 JInternalFrame (javax.swing.JInternalFrame)2