/** * 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; }
@Override public Object getValueAt(int row, int col) { if (row > sysNameList.size()) { return ""; } OBlock b = null; if (row < sysNameList.size()) { String name = sysNameList.get(row); b = _manager.getBySystemName(name); } switch (col) { case SYSNAMECOL: if (b != null) { return b.getSystemName(); } return tempRow[col]; case USERNAMECOL: if (b != null) { return b.getUserName(); } return tempRow[col]; case COMMENTCOL: if (b != null) { return b.getComment(); } return tempRow[col]; case STATECOL: if (b != null) { int state = b.getState(); int num = Integer.numberOfLeadingZeros(state) - 24; if (num >= 0) { return ZEROS.substring(0, num) + Integer.toBinaryString(state); } } return ZEROS; case SENSORCOL: if (b != null) { Sensor s = b.getSensor(); if (s == null) { return ""; } return s.getDisplayName(); } return tempRow[col]; case LENGTHCOL: if (b != null) { if (b.isMetric()) { return (twoDigit.format(b.getLengthCm())); } return (twoDigit.format(b.getLengthIn())); } if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) { return (twoDigit.format(_tempLen / 10)); } return (twoDigit.format(_tempLen / 25.4f)); case UNITSCOL: if (b != null) { if (log.isDebugEnabled()) { log.debug( "getValueAt: row= " + row + ", col= " + col + ", " + b.getDisplayName() + " isMetric= " + b.isMetric()); } return b.isMetric(); } if (log.isDebugEnabled()) { log.debug( "getValueAt: row= " + row + ", col= " + col + ", is cm= " + tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))); } return Boolean.valueOf(tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))); case CURVECOL: if (b != null) { String c = ""; if (b.getCurvature() == Block.NONE) { c = noneText; } else if (b.getCurvature() == Block.GRADUAL) { c = gradualText; } else if (b.getCurvature() == Block.TIGHT) { c = tightText; } else if (b.getCurvature() == Block.SEVERE) { c = severeText; } return c; } return tempRow[col]; case ERR_SENSORCOL: if (b != null) { Sensor s = b.getErrorSensor(); if (s == null) { return ""; } return s.getDisplayName(); } return tempRow[col]; case REPORTERCOL: if (b != null) { Reporter r = b.getReporter(); if (r == null) { return ""; } return r.getDisplayName(); } return tempRow[col]; case REPORT_CURRENTCOL: if (b != null) { if (b.getReporter() != null) { return b.isReportingCurrent(); } return ""; } return Boolean.valueOf(tempRow[REPORT_CURRENTCOL].equals(Bundle.getMessage("Current"))); case PERMISSIONCOL: if (b != null) { return b.getPermissiveWorking(); } return Boolean.valueOf(tempRow[PERMISSIONCOL].equals(Bundle.getMessage("Permissive"))); case SPEEDCOL: if (b != null) { return b.getBlockSpeed(); } return tempRow[col]; case EDIT_COL: if (b != null) { return Bundle.getMessage("ButtonEditPath"); } return ""; case DELETE_COL: if (b != null) { return Bundle.getMessage("ButtonDelete"); } return Bundle.getMessage("ButtonClear"); } return super.getValueAt(row, col); }