/** * Store the contents of a OBlockManager. * * @param o Object to store, of type BlockManager * @return Element containing the complete info */ public Element store(Object o) { Element blocks = new Element("oblocks"); blocks.setAttribute("class", "jmri.jmrit.logix.configurexml.OBlockManagerXml"); OBlockManager manager = (OBlockManager) o; Iterator<String> iter = manager.getSystemNameList().iterator(); while (iter.hasNext()) { String sname = iter.next(); OBlock block = manager.getBySystemName(sname); String uname = block.getUserName(); if (log.isDebugEnabled()) { log.debug("OBlock: sysName= " + sname + ", userName= "******"oblock"); elem.setAttribute("systemName", sname); if (uname != null && uname.length() > 0) { elem.setAttribute("userName", uname); // doing this for compatibility during 2.9.* series elem.addContent(new Element("userName").addContent(uname)); } String comment = block.getComment(); if (comment != null) { Element c = new Element("comment"); c.addContent(comment); elem.addContent(c); } elem.setAttribute("length", "" + block.getLengthMm()); elem.setAttribute("units", block.isMetric() ? "true" : "false"); elem.setAttribute("curve", "" + block.getCurvature()); if (block.getNamedSensor() != null) { Element se = new Element("sensor"); se.setAttribute("systemName", block.getNamedSensor().getName()); elem.addContent(se); } if (block.getNamedErrorSensor() != null) { Element se = new Element("errorSensor"); se.setAttribute("systemName", block.getNamedErrorSensor().getName()); elem.addContent(se); } if (block.getReporter() != null) { Element se = new Element("reporter"); se.setAttribute("systemName", block.getReporter().getSystemName()); se.setAttribute("reportCurrent", block.isReportingCurrent() ? "true" : "false"); elem.addContent(se); } elem.setAttribute("permissive", block.getPermissiveWorking() ? "true" : "false"); elem.setAttribute("speedNotch", block.getBlockSpeed()); List<Path> paths = block.getPaths(); for (int j = 0; j < paths.size(); j++) { elem.addContent(storePath((OPath) paths.get(j))); } List<Portal> portals = block.getPortals(); for (int i = 0; i < portals.size(); i++) { elem.addContent(storePortal(portals.get(i))); } // and put this element out blocks.addContent(elem); } return blocks; }
private boolean findErrors() { boolean error = false; if (checkForSavePath()) { return true; } java.util.List<Path> list = _block.getPaths(); if (list.size() == 0) { JOptionPane.showMessageDialog( this, Bundle.getMessage("noPaths", _block.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE); } for (int i = 0; i < list.size(); i++) { OPath path = (OPath) list.get(i); ArrayList<Positionable> pathGp = makePathGroup(path); if (pathGp.size() == 0) { error = true; break; } OPath p = makeOPath(path.getName(), pathGp, false); if (p == null) { error = true; break; } } if (error) { int result = JOptionPane.showConfirmDialog( this, Bundle.getMessage("hasPathErrors"), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { error = false; } } return error; }
/** * 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(); }