Search in sources :

Example 6 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class OptionsFile method readDispatcherOptions.

/*
     *  Reads Dispatcher Options from a file in the user's preferences directory
     *  If the file containing Dispatcher Options does not exist this routine returns quietly.
     */
public void readDispatcherOptions(DispatcherFrame f) throws org.jdom2.JDOMException, java.io.IOException {
    // check if file exists
    if (checkFile(defaultFileName)) {
        // file is present, 
        log.debug("Reading Dispatcher options from file {}", defaultFileName);
        root = rootFromName(defaultFileName);
        dispatcher = f;
        if (root != null) {
            // there is a file
            Element options = root.getChild("options");
            if (options != null) {
                // there are options defined, read and set Dispatcher options
                if (options.getAttribute("lename") != null) {
                    // there is a layout editor name selected
                    String leName = options.getAttribute("lename").getValue();
                    // get list of Layout Editor panels
                    ArrayList<LayoutEditor> layoutEditorList = jmri.jmrit.display.PanelMenu.instance().getLayoutEditorPanelList();
                    if (layoutEditorList.size() == 0) {
                        log.warn("Dispatcher options specify a Layout Editor panel that is not present.");
                    } else {
                        boolean found = false;
                        for (int i = 0; i < layoutEditorList.size(); i++) {
                            if (leName.equals(layoutEditorList.get(i).getTitle())) {
                                found = true;
                                dispatcher.setLayoutEditor(layoutEditorList.get(i));
                            }
                        }
                        if (!found) {
                            log.warn("Layout Editor panel - " + leName + " - not found.");
                        }
                    }
                }
                if (options.getAttribute("usesignaltype") != null) {
                    dispatcher.setSignalType(0x00);
                    if (options.getAttribute("usesignaltype").getValue().equals("signalmast")) {
                        dispatcher.setSignalType(0x01);
                    }
                }
                if (options.getAttribute("useconnectivity") != null) {
                    dispatcher.setUseConnectivity(true);
                    if (options.getAttribute("useconnectivity").getValue().equals("no")) {
                        dispatcher.setUseConnectivity(false);
                    }
                }
                if (options.getAttribute("trainsfromroster") != null) {
                    dispatcher.setTrainsFromRoster(true);
                    if (options.getAttribute("trainsfromroster").getValue().equals("no")) {
                        dispatcher.setTrainsFromRoster(false);
                    }
                }
                if (options.getAttribute("trainsfromtrains") != null) {
                    dispatcher.setTrainsFromTrains(true);
                    if (options.getAttribute("trainsfromtrains").getValue().equals("no")) {
                        dispatcher.setTrainsFromTrains(false);
                    }
                }
                if (options.getAttribute("trainsfromuser") != null) {
                    dispatcher.setTrainsFromUser(true);
                    if (options.getAttribute("trainsfromuser").getValue().equals("no")) {
                        dispatcher.setTrainsFromUser(false);
                    }
                }
                if (options.getAttribute("autoallocate") != null) {
                    dispatcher.setAutoAllocate(false);
                    if (options.getAttribute("autoallocate").getValue().equals("yes")) {
                        dispatcher.setAutoAllocate(true);
                    }
                }
                if (options.getAttribute("autoturnouts") != null) {
                    dispatcher.setAutoTurnouts(true);
                    if (options.getAttribute("autoturnouts").getValue().equals("no")) {
                        dispatcher.setAutoTurnouts(false);
                    }
                }
                if (options.getAttribute("trustknownturnouts") != null) {
                    dispatcher.setTrustKnownTurnouts(false);
                    if (options.getAttribute("trustknownturnouts").getValue().equals("yes")) {
                        dispatcher.setTrustKnownTurnouts(true);
                    }
                }
                if (options.getAttribute("minthrottleinterval") != null) {
                    String s = (options.getAttribute("minthrottleinterval")).getValue();
                    dispatcher.setMinThrottleInterval(Integer.parseInt(s));
                }
                if (options.getAttribute("fullramptime") != null) {
                    String s = (options.getAttribute("fullramptime")).getValue();
                    dispatcher.setFullRampTime(Integer.parseInt(s));
                }
                if (options.getAttribute("hasoccupancydetection") != null) {
                    dispatcher.setHasOccupancyDetection(true);
                    if (options.getAttribute("hasoccupancydetection").getValue().equals("no")) {
                        dispatcher.setHasOccupancyDetection(false);
                    }
                }
                if (options.getAttribute("shortactivetrainnames") != null) {
                    dispatcher.setShortActiveTrainNames(true);
                    if (options.getAttribute("shortactivetrainnames").getValue().equals("no")) {
                        dispatcher.setShortActiveTrainNames(false);
                    }
                }
                if (options.getAttribute("shortnameinblock") != null) {
                    dispatcher.setShortNameInBlock(true);
                    if (options.getAttribute("shortnameinblock").getValue().equals("no")) {
                        dispatcher.setShortNameInBlock(false);
                    }
                }
                if (options.getAttribute("extracolorforallocated") != null) {
                    dispatcher.setExtraColorForAllocated(true);
                    if (options.getAttribute("extracolorforallocated").getValue().equals("no")) {
                        dispatcher.setExtraColorForAllocated(false);
                    }
                }
                if (options.getAttribute("nameinallocatedblock") != null) {
                    dispatcher.setNameInAllocatedBlock(true);
                    if (options.getAttribute("nameinallocatedblock").getValue().equals("no")) {
                        dispatcher.setNameInAllocatedBlock(false);
                    }
                }
                if (options.getAttribute("supportvsdecoder") != null) {
                    dispatcher.setSupportVSDecoder(true);
                    if (options.getAttribute("supportvsdecoder").getValue().equals("no")) {
                        dispatcher.setSupportVSDecoder(false);
                    }
                }
                if (options.getAttribute("layoutscale") != null) {
                    String s = (options.getAttribute("layoutscale")).getValue();
                    for (int i = 1; i <= Scale.NUM_SCALES; i++) {
                        if (Scale.getShortScaleID(i).equals(s)) {
                            dispatcher.setScale(i);
                        }
                    }
                }
                if (options.getAttribute("usescalemeters") != null) {
                    dispatcher.setUseScaleMeters(true);
                    if (options.getAttribute("usescalemeters").getValue().equals("no")) {
                        dispatcher.setUseScaleMeters(false);
                    }
                }
                if (options.getAttribute("userosterentryinblock") != null) {
                    dispatcher.setRosterEntryInBlock(false);
                    if (options.getAttribute("userosterentryinblock").getValue().equals("yes")) {
                        dispatcher.setRosterEntryInBlock(true);
                    }
                }
            }
        }
    } else {
        log.debug("No Dispatcher options file found at {}, using defaults", defaultFileName);
    }
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Element(org.jdom2.Element)

Example 7 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class OptionsMenu method initializeLayoutEditorCombo.

private boolean initializeLayoutEditorCombo() {
    // get list of Layout Editor panels
    layoutEditorList = jmri.jmrit.display.PanelMenu.instance().getLayoutEditorPanelList();
    if (layoutEditorList.size() == 0) {
        return false;
    }
    layoutEditorBox.removeAllItems();
    for (int i = 0; i < layoutEditorList.size(); i++) {
        layoutEditorBox.addItem(layoutEditorList.get(i).getTitle());
    }
    if (layoutEditorList.size() > 1) {
        LayoutEditor le = dispatcher.getLayoutEditor();
        for (int j = 0; j < layoutEditorList.size(); j++) {
            if (le == layoutEditorList.get(j)) {
                layoutEditorBox.setSelectedIndex(j);
            }
        }
    } else {
        layoutEditorBox.setSelectedIndex(0);
    }
    return true;
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor)

Example 8 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class BlockContentsIconXml method load.

/**
     * Load, starting with the BlockContentsIcon element, then all the
     * value-icon pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    Editor ed = null;
    BlockContentsIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new BlockContentsIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("blockcontents");
    if (attr == null) {
        log.error("incorrect information for a block contents; must use block name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
    if (m != null) {
        l.setBlock(name);
    } else {
        log.error("Block named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    }
    Attribute a = element.getAttribute("selectable");
    if (a != null && a.getValue().equals("yes")) {
        l.setSelectable(true);
    } else {
        l.setSelectable(false);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("blockstate");
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String iconName = item.getAttribute("icon").getValue();
        NamedIcon icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed("Memory " + name, iconName);
            if (icon == null) {
                log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
            }
        }
        if (icon != null) {
            String keyValue = item.getAttribute("value").getValue();
            l.addKeyAndIcon(icon, keyValue);
        }
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setOriginalLocation(x, y);
    l.displayState();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) BlockContentsIcon(jmri.jmrit.display.BlockContentsIcon) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) Block(jmri.Block) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Editor(jmri.jmrit.display.Editor)

Example 9 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class LayoutEditorXml method load.

/**
     * Create a LayoutEditor object, then register and fill it, then pop it in a
     * JFrame
     *
     * @param shared Top level Element to unpack.
     */
@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    Attribute a;
    // find coordinates
    int x = 0;
    int y = 0;
    // From this version onwards separate sizes for window and panel are used
    int windowHeight = 400;
    int windowWidth = 300;
    int panelHeight = 340;
    int panelWidth = 280;
    int sidetrackwidth = 3;
    int mainlinetrackwidth = 3;
    try {
        x = shared.getAttribute("x").getIntValue();
        y = shared.getAttribute("y").getIntValue();
        // For compatibility with previous versions, try and see if height and width tags are contained in the file
        if ((a = shared.getAttribute("height")) != null) {
            windowHeight = a.getIntValue();
            panelHeight = windowHeight - 60;
        }
        if ((a = shared.getAttribute("width")) != null) {
            windowWidth = a.getIntValue();
            panelWidth = windowWidth - 18;
        }
        // For files created by the new version, retrieve window and panel sizes
        if ((a = shared.getAttribute("windowheight")) != null) {
            windowHeight = a.getIntValue();
        }
        if ((a = shared.getAttribute("windowwidth")) != null) {
            windowWidth = a.getIntValue();
        }
        if ((a = shared.getAttribute("panelheight")) != null) {
            panelHeight = a.getIntValue();
        }
        if ((a = shared.getAttribute("panelwidth")) != null) {
            panelWidth = a.getIntValue();
        }
        mainlinetrackwidth = shared.getAttribute("mainlinetrackwidth").getIntValue();
        sidetrackwidth = shared.getAttribute("sidetrackwidth").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert LayoutEditor's attribute");
        result = false;
    }
    double xScale = 1.0;
    double yScale = 1.0;
    a = shared.getAttribute("xscale");
    if (a != null) {
        try {
            xScale = (Float.parseFloat(a.getValue()));
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    a = shared.getAttribute("yscale");
    if (a != null) {
        try {
            yScale = (Float.parseFloat(a.getValue()));
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    // find the name and default track color
    String name = "";
    if (shared.getAttribute("name") != null) {
        name = shared.getAttribute("name").getValue();
    }
    if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
        JFrame frame = new JFrame("DialogDemo");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        log.warn("File contains a panel with the same name (" + name + ") as an existing panel");
        int n = JOptionPane.showConfirmDialog(frame, java.text.MessageFormat.format(rb.getString("DuplicatePanel"), new Object[] { name }), rb.getString("DuplicatePanelTitle"), JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.NO_OPTION) {
            return false;
        }
    }
    String defaultColor = "black";
    String defaultTextColor = "black";
    if (shared.getAttribute("defaulttrackcolor") != null) {
        defaultColor = shared.getAttribute("defaulttrackcolor").getValue();
    }
    if (shared.getAttribute("defaulttextcolor") != null) {
        defaultTextColor = shared.getAttribute("defaulttextcolor").getValue();
    }
    //default to using use default track color for circle color
    String turnoutCircleColor = "track";
    if (shared.getAttribute("turnoutcirclecolor") != null) {
        turnoutCircleColor = shared.getAttribute("turnoutcirclecolor").getValue();
    }
    int turnoutCircleSize = 2;
    if (shared.getAttribute("turnoutcirclesize") != null) {
        try {
            turnoutCircleSize = shared.getAttribute("turnoutcirclesize").getIntValue();
        } catch (DataConversionException e1) {
            //leave at default if cannot convert
            log.warn("unable to convert turnoutcirclesize");
        }
    }
    boolean turnoutDrawUnselectedLeg = true;
    if ((a = shared.getAttribute("turnoutdrawunselectedleg")) != null && a.getValue().equals("no")) {
        turnoutDrawUnselectedLeg = false;
    }
    // create the objects
    LayoutEditor panel = new LayoutEditor(name);
    panel.setLayoutName(name);
    panel.setMainlineTrackWidth(mainlinetrackwidth);
    panel.setSideTrackWidth(sidetrackwidth);
    panel.setDefaultTrackColor(defaultColor);
    panel.setDefaultTextColor(defaultTextColor);
    panel.setTurnoutCircleColor(turnoutCircleColor);
    panel.setTurnoutCircleSize(turnoutCircleSize);
    panel.setTurnoutDrawUnselectedLeg(turnoutDrawUnselectedLeg);
    panel.setXScale(xScale);
    panel.setYScale(yScale);
    // turnout size parameters
    double sz = 20.0;
    a = shared.getAttribute("turnoutbx");
    if (a != null) {
        try {
            sz = (Float.parseFloat(a.getValue()));
            panel.setTurnoutBX(sz);
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    a = shared.getAttribute("turnoutcx");
    if (a != null) {
        try {
            sz = (Float.parseFloat(a.getValue()));
            panel.setTurnoutCX(sz);
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    a = shared.getAttribute("turnoutwid");
    if (a != null) {
        try {
            sz = (Float.parseFloat(a.getValue()));
            panel.setTurnoutWid(sz);
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    a = shared.getAttribute("xoverlong");
    if (a != null) {
        try {
            sz = (Float.parseFloat(a.getValue()));
            panel.setXOverLong(sz);
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    a = shared.getAttribute("xoverhwid");
    if (a != null) {
        try {
            sz = (Float.parseFloat(a.getValue()));
            panel.setXOverHWid(sz);
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    a = shared.getAttribute("xovershort");
    if (a != null) {
        try {
            sz = (Float.parseFloat(a.getValue()));
            panel.setXOverShort(sz);
        } catch (Exception e) {
            log.error("failed to convert to float - " + a.getValue());
            result = false;
        }
    }
    // grid size parameter
    // this value is never used but it's the default
    int iz = 10;
    a = shared.getAttribute("gridSize");
    if (a != null) {
        try {
            iz = (Integer.parseInt(a.getValue()));
            panel.setGridSize(iz);
        } catch (Exception e) {
            log.error("failed to convert to int - " + a.getValue());
            result = false;
        }
    }
    // second grid size parameter
    // this value is never used but it's the default
    iz = 10;
    a = shared.getAttribute("gridSize2nd");
    if (a != null) {
        try {
            iz = (Integer.parseInt(a.getValue()));
            panel.setGridSize2nd(iz);
        } catch (Exception e) {
            log.error("failed to convert to int - " + a.getValue());
            result = false;
        }
    }
    // set contents state
    String slValue = "both";
    if ((a = shared.getAttribute("sliders")) != null && a.getValue().equals("no")) {
        slValue = "none";
    }
    if ((a = shared.getAttribute("scrollable")) != null) {
        slValue = a.getValue();
    }
    boolean edValue = true;
    if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
        edValue = false;
    }
    boolean value = true;
    if ((a = shared.getAttribute("positionable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllPositionable(value);
    value = true;
    if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllControlling(value);
    value = true;
    if ((a = shared.getAttribute("animating")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setTurnoutAnimation(value);
    boolean hbValue = true;
    if ((a = shared.getAttribute("showhelpbar")) != null && a.getValue().equals("no")) {
        hbValue = false;
    }
    boolean dgValue = false;
    if ((a = shared.getAttribute("drawgrid")) != null && a.getValue().equals("yes")) {
        dgValue = true;
    }
    boolean sgaValue = false;
    if ((a = shared.getAttribute("snaponadd")) != null && a.getValue().equals("yes")) {
        sgaValue = true;
    }
    boolean sgmValue = false;
    if ((a = shared.getAttribute("snaponmove")) != null && a.getValue().equals("yes")) {
        sgmValue = true;
    }
    boolean aaValue = false;
    if ((a = shared.getAttribute("antialiasing")) != null && a.getValue().equals("yes")) {
        aaValue = true;
    }
    value = false;
    if ((a = shared.getAttribute("turnoutcircles")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    panel.setTurnoutCircles(value);
    value = false;
    if ((a = shared.getAttribute("tooltipsnotedit")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    panel.setTooltipsNotEdit(value);
    value = false;
    if ((a = shared.getAttribute("autoblkgenerate")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    panel.setAutoBlockAssignment(value);
    value = true;
    if ((a = shared.getAttribute("tooltipsinedit")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setTooltipsInEdit(value);
    // set default track color
    if ((a = shared.getAttribute("defaulttrackcolor")) != null) {
        panel.setDefaultTrackColor(a.getValue());
    }
    // set default track color
    if ((a = shared.getAttribute("defaultoccupiedtrackcolor")) != null) {
        panel.setDefaultOccupiedTrackColor(a.getValue());
    }
    // set default track color
    if ((a = shared.getAttribute("defaultalternativetrackcolor")) != null) {
        panel.setDefaultAlternativeTrackColor(a.getValue());
    }
    try {
        int red = shared.getAttribute("redBackground").getIntValue();
        int blue = shared.getAttribute("blueBackground").getIntValue();
        int green = shared.getAttribute("greenBackground").getIntValue();
        panel.setDefaultBackgroundColor(ColorUtil.colorToString(new Color(red, green, blue)));
        panel.setBackgroundColor(new Color(red, green, blue));
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse color attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    if (shared.getAttribute("useDirectTurnoutControl") != null) {
        if (shared.getAttribute("useDirectTurnoutControl").getValue().equals("yes")) {
            panel.setDirectTurnoutControl(true);
        }
    }
    // note: moving zoom attribute into per-window user preference
    //if (shared.getAttribute("zoom") != null) {
    //    panel.setZoom(Double.valueOf(shared.getAttribute("zoom").getValue()));
    //}
    // Set editor's option flags, load content after
    // this so that individual item flags are set as saved
    panel.initView();
    // load the contents
    List<Element> items = shared.getChildren();
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String adapterName = item.getAttribute("class").getValue();
        if (log.isDebugEnabled()) {
            String id = "<null>";
            try {
                id = item.getAttribute("ident").getValue();
                log.debug("Load " + id + " for [" + panel.getName() + "] via " + adapterName);
            } catch (Exception e) {
                log.debug("Load layout object for [" + panel.getName() + "] via " + adapterName);
            }
        }
        try {
            XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
            // and do it
            adapter.load(item, panel);
            if (!panel.loadOK()) {
                result = false;
            }
        } catch (Exception e) {
            log.error("Exception while loading " + item.getName() + ":" + e);
            result = false;
            e.printStackTrace();
        }
    }
    // dispose of url correction data
    panel.disposeLoadData();
    // final initialization of objects
    panel.setConnections();
    // display the results
    // set first since other attribute use this setting
    panel.setAllEditable(edValue);
    panel.setShowHelpBar(hbValue);
    panel.setDrawGrid(dgValue);
    panel.setSnapOnAdd(sgaValue);
    panel.setSnapOnMove(sgmValue);
    panel.setAntialiasingOn(aaValue);
    panel.setScroll(slValue);
    panel.pack();
    panel.setLayoutDimensions(windowWidth, windowHeight, x, y, panelWidth, panelHeight);
    // always show the panel
    panel.setVisible(true);
    panel.resetDirty();
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(panel);
    }
    //open Dispatcher frame if any Transits are defined, and open Dispatcher flag set on
    if (jmri.InstanceManager.getDefault(jmri.TransitManager.class).getSystemNameList().size() > 0) {
        if (shared.getAttribute("openDispatcher") != null) {
            if (shared.getAttribute("openDispatcher").getValue().equals("yes")) {
                panel.setOpenDispatcherOnLoad(true);
                jmri.jmrit.dispatcher.DispatcherFrame df = jmri.jmrit.dispatcher.DispatcherFrame.instance();
                df.loadAtStartup();
            } else {
                panel.setOpenDispatcherOnLoad(false);
            }
        }
    }
    return result;
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) Color(java.awt.Color) Element(org.jdom2.Element) DataConversionException(org.jdom2.DataConversionException) ConfigureManager(jmri.ConfigureManager) JFrame(javax.swing.JFrame) DataConversionException(org.jdom2.DataConversionException) DataConversionException(org.jdom2.DataConversionException) AbstractXmlAdapter(jmri.configurexml.AbstractXmlAdapter) XmlAdapter(jmri.configurexml.XmlAdapter)

Example 10 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class LayoutTurnoutXml method load.

/**
     * Load, starting with the levelxing element, then all the other data
     *
     * @param element Top level Element to unpack.
     * @param o       LayoutEditor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LayoutEditor p = (LayoutEditor) o;
    // get center point
    String name = element.getAttribute("ident").getValue();
    double x = 0.0;
    double y = 0.0;
    int tType = LayoutTurnout.RH_TURNOUT;
    try {
        x = element.getAttribute("xcen").getFloatValue();
        y = element.getAttribute("ycen").getFloatValue();
        tType = element.getAttribute("type").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutturnout attribute");
    }
    int version = 1;
    try {
        version = element.getAttribute("ver").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutturnout b coords attribute");
    } catch (java.lang.NullPointerException e) {
    //can be ignored as panel file may not support method
    }
    // create the new LayoutTurnout
    LayoutTurnout l = new LayoutTurnout(name, tType, new Point2D.Double(x, y), 0.0, 1.0, 1.0, p, version);
    // get remaining attributes
    Attribute a = element.getAttribute("blockname");
    if (a != null) {
        l.tBlockName = a.getValue();
    }
    a = element.getAttribute("blockbname");
    if (a != null) {
        l.tBlockBName = a.getValue();
    }
    a = element.getAttribute("blockcname");
    if (a != null) {
        l.tBlockCName = a.getValue();
    }
    a = element.getAttribute("blockdname");
    if (a != null) {
        l.tBlockDName = a.getValue();
    }
    a = element.getAttribute("turnoutname");
    if (a != null) {
        l.tTurnoutName = a.getValue();
    }
    a = element.getAttribute("secondturnoutname");
    if (a != null) {
        l.tSecondTurnoutName = a.getValue();
    }
    a = element.getAttribute("connectaname");
    if (a != null) {
        l.connectAName = a.getValue();
    }
    a = element.getAttribute("connectbname");
    if (a != null) {
        l.connectBName = a.getValue();
    }
    a = element.getAttribute("connectcname");
    if (a != null) {
        l.connectCName = a.getValue();
    }
    a = element.getAttribute("connectdname");
    if (a != null) {
        l.connectDName = a.getValue();
    }
    a = element.getAttribute("signala1name");
    if (a != null) {
        l.setSignalA1Name(a.getValue());
    }
    a = element.getAttribute("signala2name");
    if (a != null) {
        l.setSignalA2Name(a.getValue());
    }
    a = element.getAttribute("signala3name");
    if (a != null) {
        l.setSignalA3Name(a.getValue());
    }
    a = element.getAttribute("signalb1name");
    if (a != null) {
        l.setSignalB1Name(a.getValue());
    }
    a = element.getAttribute("signalb2name");
    if (a != null) {
        l.setSignalB2Name(a.getValue());
    }
    a = element.getAttribute("signalc1name");
    if (a != null) {
        l.setSignalC1Name(a.getValue());
    }
    a = element.getAttribute("signalc2name");
    if (a != null) {
        l.setSignalC2Name(a.getValue());
    }
    a = element.getAttribute("signald1name");
    if (a != null) {
        l.setSignalD1Name(a.getValue());
    }
    a = element.getAttribute("signald2name");
    if (a != null) {
        l.setSignalD2Name(a.getValue());
    }
    a = element.getAttribute("linkedturnoutname");
    if (a != null) {
        l.linkedTurnoutName = a.getValue();
        try {
            l.linkType = element.getAttribute("linktype").getIntValue();
        } catch (org.jdom2.DataConversionException e) {
            log.error("failed to convert linked layout turnout type");
        }
    }
    a = element.getAttribute("continuing");
    if (a != null) {
        int continuing = Turnout.CLOSED;
        try {
            continuing = element.getAttribute("continuing").getIntValue();
        } catch (org.jdom2.DataConversionException e) {
            log.error("failed to convert continuingsense attribute");
        }
        l.setContinuingSense(continuing);
    }
    boolean value = false;
    if ((a = element.getAttribute("disabled")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    l.setDisabled(value);
    value = false;
    if ((a = element.getAttribute("disableWhenOccupied")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    l.setDisableWhenOccupied(value);
    boolean hide = false;
    if (element.getAttribute("hidden") != null) {
        if (element.getAttribute("hidden").getValue().equals("yes")) {
            hide = true;
        }
    }
    l.setHidden(hide);
    if (version == 2) {
        try {
            x = element.getAttribute("xa").getFloatValue();
            y = element.getAttribute("ya").getFloatValue();
            l.setCoordsA(new Point2D.Double(x, y));
        } catch (org.jdom2.DataConversionException e) {
            log.error("failed to convert layoutturnout b coords attribute");
        } catch (java.lang.NullPointerException e) {
        //can be ignored as panel file may not support method
        }
    }
    try {
        x = element.getAttribute("xb").getFloatValue();
        y = element.getAttribute("yb").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutturnout b coords attribute");
    }
    l.setCoordsB(new Point2D.Double(x, y));
    try {
        x = element.getAttribute("xc").getFloatValue();
        y = element.getAttribute("yc").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutturnout c coords attribute");
    }
    l.setCoordsC(new Point2D.Double(x, y));
    if (version == 2) {
        try {
            x = element.getAttribute("xd").getFloatValue();
            y = element.getAttribute("yd").getFloatValue();
            l.setCoordsD(new Point2D.Double(x, y));
        } catch (org.jdom2.DataConversionException e) {
            log.error("failed to convert layoutturnout c coords attribute");
        } catch (java.lang.NullPointerException e) {
        //can be ignored as panel file may not support method
        }
    }
    if (element.getChild("signalAMast") != null) {
        String mast = element.getChild("signalAMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalAMast(mast);
        }
    }
    if (element.getChild("signalBMast") != null) {
        String mast = element.getChild("signalBMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalBMast(mast);
        }
    }
    if (element.getChild("signalCMast") != null) {
        String mast = element.getChild("signalCMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalCMast(mast);
        }
    }
    if (element.getChild("signalDMast") != null) {
        String mast = element.getChild("signalDMast").getText();
        if (mast != null && !mast.equals("")) {
            l.setSignalDMast(mast);
        }
    }
    if (element.getChild("sensorA") != null) {
        String sensor = element.getChild("sensorA").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorA(sensor);
        }
    }
    if (element.getChild("sensorB") != null) {
        String sensor = element.getChild("sensorB").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorB(sensor);
        }
    }
    if (element.getChild("sensorC") != null) {
        String sensor = element.getChild("sensorC").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorC(sensor);
        }
    }
    if (element.getChild("sensorD") != null) {
        String sensor = element.getChild("sensorD").getText();
        if (sensor != null && !sensor.equals("")) {
            l.setSensorD(sensor);
        }
    }
    p.turnoutList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) LayoutTurnout(jmri.jmrit.display.layoutEditor.LayoutTurnout) Point2D(java.awt.geom.Point2D)

Aggregations

LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)28 Element (org.jdom2.Element)12 Attribute (org.jdom2.Attribute)9 Point2D (java.awt.geom.Point2D)6 ArrayList (java.util.ArrayList)5 PointDetails (jmri.jmrit.signalling.entryexit.PointDetails)5 Source (jmri.jmrit.signalling.entryexit.Source)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Editor (jmri.jmrit.display.Editor)3 ControlPanelEditor (jmri.jmrit.display.controlPanelEditor.ControlPanelEditor)3 JmriJFrame (jmri.util.JmriJFrame)3 ConfigureManager (jmri.ConfigureManager)2 Sensor (jmri.Sensor)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Positionable (jmri.jmrit.display.Positionable)2 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)2 SwitchboardEditor (jmri.jmrit.display.switchboardEditor.SwitchboardEditor)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1