Portal loadPortal(Element elem) { String sysName = null; String userName = elem.getAttribute("portalName").getValue(); if (elem.getAttribute("systemName") == null) { if (log.isDebugEnabled()) { log.debug("Portal systemName is null"); } } else { sysName = elem.getAttribute("systemName").getValue(); } String fromBlockName = null; String toBlockName = null; // Portals must have user names. Portal portal = _portalMgr.getByUserName(userName); if (portal != null) { fromBlockName = portal.getFromBlock().getSystemName(); toBlockName = portal.getToBlock().getSystemName(); } else { portal = _portalMgr.providePortal(userName); } if (portal == null) { log.error( "unable to create Portal (" + sysName + ", " + userName + ") " + elem + " " + elem.getAttributes()); return null; } if (log.isDebugEnabled()) { log.debug("create Portal: (" + sysName + ", " + userName + ")"); } OBlock fromBlock = null; Element eFromBlk = elem.getChild("fromBlock"); if (eFromBlk != null && eFromBlk.getAttribute("blockName") != null) { String name = eFromBlk.getAttribute("blockName").getValue(); if (fromBlockName != null && !fromBlockName.equals(name)) { log.error( "Portal has user name \"" + userName + "\" conflicting with " + portal.toString()); } else { fromBlock = getBlock(name); if (fromBlock != null) { portal.setFromBlock(fromBlock, false); fromBlock.addPortal(portal); List<Element> ePathsFromBlock = eFromBlk.getChildren("path"); for (int i = 0; i < ePathsFromBlock.size(); i++) { Element e = ePathsFromBlock.get(i); String pathName = e.getAttribute("pathName").getValue(); String blockName = e.getAttribute("blockName").getValue(); if (log.isDebugEnabled()) { log.debug( "Load portal= " + userName + " fromBlock= " + fromBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName); } /*(if (fromBlock.getSystemName().equals(blockName))*/ { // path is in the fromBlock OPath path = getPath(fromBlock, pathName); portal.addPath(path); } } } } } else { log.error("Portal \"" + userName + "\" has no fromBlock!"); } OBlock toBlock = null; Element eToBlk = elem.getChild("toBlock"); if (eToBlk != null && eToBlk.getAttribute("blockName") != null) { String name = eToBlk.getAttribute("blockName").getValue(); if (toBlockName != null && !toBlockName.equals(name)) { log.error( "Portal has user name \"" + userName + "\" conflicting with " + portal.toString()); } else { toBlock = getBlock(name); if (toBlock != null) { portal.setToBlock(toBlock, false); toBlock.addPortal(portal); List<Element> ePathsToBlock = eToBlk.getChildren("path"); for (int i = 0; i < ePathsToBlock.size(); i++) { Element e = ePathsToBlock.get(i); String pathName = e.getAttribute("pathName").getValue(); String blockName = e.getAttribute("blockName").getValue(); if (log.isDebugEnabled()) { log.debug( "Load portal= " + userName + " toBlock= " + toBlock.getSystemName() + " pathName= " + pathName + " blockName= " + blockName); } /*if (toBlock.getSystemName().equals(blockName))*/ { // path is in the toBlock OPath path = getPath(toBlock, pathName); portal.addPath(path); } } } } } else { log.error("Portal \"" + userName + "\" has no toBlock!"); } Element eSignal = elem.getChild("fromSignal"); if (eSignal != null) { String name = eSignal.getAttribute("signalName").getValue(); float length = 0.0f; try { Attribute attr = eSignal.getAttribute("signalDelay"); if (attr != null) { length = attr.getFloatValue(); } } catch (org.jdom2.DataConversionException e) { log.error( "Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")"); } portal.setProtectSignal(Portal.getSignal(name), length, toBlock); } eSignal = elem.getChild("toSignal"); if (eSignal != null) { String name = eSignal.getAttribute("signalName").getValue(); float length = 0.0f; try { Attribute attr = eSignal.getAttribute("signalDelay"); if (attr != null) { length = attr.getFloatValue(); } } catch (org.jdom2.DataConversionException e) { log.error( "Could not parse signalDelay for signal (" + name + ") in portal (" + userName + ")"); } portal.setProtectSignal(Portal.getSignal(name), length, fromBlock); } if (log.isDebugEnabled()) { log.debug("End Load portal " + userName); } return portal; }
OPath loadPath(Element elem, OBlock block) { String pName = elem.getAttribute("pathName").getValue(); OPath path = getPath(block, pName); try { Attribute attr = elem.getAttribute("fromDirection"); if (attr != null) { path.setFromBlockDirection(attr.getIntValue()); } attr = elem.getAttribute("toDirection"); if (attr != null) { path.setToBlockDirection(attr.getIntValue()); } attr = elem.getAttribute("length"); if (attr != null) { path.setLength(attr.getFloatValue()); } } catch (org.jdom2.DataConversionException e) { log.error( "Could not parse attribute of path (" + pName + ") block (" + block.getSystemName() + ")"); } Attribute attr = elem.getAttribute("fromPortal"); if (attr != null) { Portal portal = getPortal(attr.getValue()); if (portal != null) { path.setFromPortal(portal); portal.addPath(path); } } attr = elem.getAttribute("toPortal"); if (attr != null) { Portal portal = getPortal(attr.getValue()); if (portal != null) { path.setToPortal(portal); portal.addPath(path); } } List<Element> settings = elem.getChildren("setting"); if (log.isDebugEnabled()) { log.debug("Path (" + pName + ") has " + settings.size() + " settings."); } java.util.HashSet<String> turnouts = new java.util.HashSet<String>(); int dups = 0; for (int i = 0; i < settings.size(); i++) { Element setElem = settings.get(i); int setting = 0; try { setting = setElem.getAttribute("set").getIntValue(); } catch (org.jdom2.DataConversionException e) { log.error( "Could not parse 'set' attribute for path (" + pName + ") block (" + block.getSystemName() + ")"); } String sysName = setElem.getAttribute("turnout").getValue(); if (!turnouts.contains(sysName)) { Turnout to = InstanceManager.turnoutManagerInstance().provideTurnout(sysName); turnouts.add(sysName); BeanSetting bs = new BeanSetting(to, sysName, setting); path.addSetting(bs); } else { dups++; } } if (dups > 0) { log.warn(dups + " duplicate settings not loaded for path \"" + pName + "\""); } return path; }
/** * Create or update the selected path named in the text field Checks that icons have been selected * for the path */ private void addPath() { String name = _pathName.getText(); if (name == null || name.trim().length() == 0) { JOptionPane.showMessageDialog( this, Bundle.getMessage("TooltipPathName"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE); return; } OPath otherPath = _block.getPathByName(name); boolean sameName = false; if (otherPath != null) { _pathList.setSelectedValue(otherPath, true); sameName = true; if (!_pathChange) { // check portals OK Portal p = otherPath.getFromPortal(); if (p != null && !p.isValidPath(otherPath)) { p.addPath(otherPath); } p = otherPath.getToPortal(); if (p != null && !p.isValidPath(otherPath)) { p.addPath(otherPath); } setPathLength(otherPath); return; } } OPath path = makeOPath(name, _pathGroup, true); if (path == null) { return; // proper OPath cannot be made } if (otherPath == null) { // is this path already defined? Iterator<Path> iter = _block.getPaths().iterator(); while (iter.hasNext()) { OPath p = (OPath) iter.next(); if (pathsEqual(path, p)) { otherPath = p; break; } } } // match icons to current selections changePathNameInIcons(name, path); if (otherPath != null) { // same path if (!sameName) { int result = JOptionPane.showConfirmDialog( this, Bundle.getMessage("samePath", otherPath.getName(), name), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { changePathName(); } } _pathList.setSelectedValue(otherPath, true); } Portal toPortal = path.getToPortal(); Portal fromPortal = path.getFromPortal(); if (fromPortal != null && fromPortal.equals(toPortal)) { int result = JOptionPane.showConfirmDialog( this, Bundle.getMessage("balloonTrack", name, fromPortal.getDescription()), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.NO_OPTION) { fromPortal = null; } } _pathChange = false; // If the name is the same as a Path already in the block, don't add. // Just update OPath changes if (sameName) { OPath oldPath = _block.getPathByName(name); oldPath.setToPortal(toPortal); oldPath.setFromPortal(fromPortal); setPathLength(oldPath); oldPath.clearSettings(); Iterator<BeanSetting> it = path.getSettings().iterator(); while (it.hasNext()) { oldPath.addSetting(it.next()); } toPortal.addPath(oldPath); if (fromPortal != null) { fromPortal.addPath(oldPath); } } else { _block.addPath(path); // OBlock adds path to portals and checks for duplicate path names setPathLength(path); } _pathList.setSelectedValue(path, true); _pathListModel.dataChange(); }