📄 configurator.java
字号:
DefaultMutableTreeNode unitControllerNode = new DefaultMutableTreeNode(new ImmutableAnchor("HVAC Controller", "hvac-controller.html")); DefaultMutableTreeNode unitControllerClassNode = new DefaultMutableTreeNode(new ClassAnchor("N/A", "hvac-controller-class.html", "configurator.ac.controller.class")); DefaultMutableTreeNode unitDriverNode = new DefaultMutableTreeNode(new ImmutableAnchor("HVAC Driver", "hvac-driver.html")); DefaultMutableTreeNode unitDriverClassNode = new DefaultMutableTreeNode(new ClassAnchor("N/A", "hvac-driver-class.html", "configurator.ac.driver.class")); unitDriverNode.add(unitDriverClassNode); unitControllerNode.add(unitControllerClassNode); unitControllerNode.add(unitDriverNode); unitNode.add(unitControllerNode); } private void createZoneController(String unitName, DefaultMutableTreeNode unitNode) { DefaultMutableTreeNode zoneControllerNode = new DefaultMutableTreeNode(new ImmutableAnchor("Zone Controller", "zone-controller.html")); DefaultMutableTreeNode zoneControllerClassNode = new DefaultMutableTreeNode(new ClassAnchor(targetCf.getString("dz.unit." + unitName + ".zone_controller.class", "N/A"),"zone-controller-class.html", "configurator.zone.controller.class")); DefaultMutableTreeNode zoneControllerDumpNode = new DefaultMutableTreeNode(new StringAnchor("Dump threshold: ",targetCf.getString("dz.unit." + unitName + ".zone_controller.dump_threshold", "0.4"), "dump-threshold.html")); zoneControllerNode.add(zoneControllerClassNode); zoneControllerNode.add(zoneControllerDumpNode); unitNode.add(zoneControllerNode); } private void createNewZoneController(String unitName, DefaultMutableTreeNode unitNode) { DefaultMutableTreeNode zoneControllerNode = new DefaultMutableTreeNode(new ImmutableAnchor("Zone Controller", "zone-controller.html")); DefaultMutableTreeNode zoneControllerClassNode = new DefaultMutableTreeNode(new ClassAnchor("N/A","zone-controller-class.html", "configurator.zone.controller.class")); DefaultMutableTreeNode zoneControllerDumpNode = new DefaultMutableTreeNode(new StringAnchor("Dump threshold: ","0.4", "dump-threshold.html")); zoneControllerNode.add(zoneControllerClassNode); zoneControllerNode.add(zoneControllerDumpNode); unitNode.add(zoneControllerNode); } /** * Create the zone node and attach it to the unit node. * * @param unitName The unit name. * * @param zoneName The zone name. * * @param unitNode The unit node to attach it to. */ private void createZone(String unitName, String zoneName, DefaultMutableTreeNode unitNode) { DefaultMutableTreeNode zoneNode = new DefaultMutableTreeNode(new ZoneAnchor(zoneName)); DefaultMutableTreeNode thermostatNode = new DefaultMutableTreeNode(new ImmutableAnchor("Thermostat", "thermostat.html")); DefaultMutableTreeNode thermostatControllerClassNode = new DefaultMutableTreeNode(new ClassAnchor(targetCf.getString("dz.unit." + unitName + ".zone." + zoneName + ".thermostat.controller.class", "N/A"), "thermostat-controller-class.html", "configurator.thermostat.controller.class")); DefaultMutableTreeNode damperNode = new DefaultMutableTreeNode(new ImmutableAnchor("Damper", "damper.html")); DefaultMutableTreeNode damperClassNode = new DefaultMutableTreeNode(new ClassAnchor(targetCf.getString("dz.unit." + unitName + ".zone." + zoneName + ".damper.class", "N/A"), "damper-class.html", "configurator.damper.class")); DefaultMutableTreeNode dumpCoolingNode = new DefaultMutableTreeNode(new DumpPriorityAnchor("Dump Priority/Cooling", Integer.toString(targetCf.getInteger("dz.unit." + unitName + ".zone." + zoneName + ".thermostat.dump_priority.cool", 0)), "dump-priority.html")); DefaultMutableTreeNode dumpHeatingNode = new DefaultMutableTreeNode(new DumpPriorityAnchor("Dump Priority/Heating", Integer.toString(targetCf.getInteger("dz.unit." + unitName + ".zone." + zoneName + ".thermostat.dump_priority.heat", 0)), "dump-priority.html")); DefaultMutableTreeNode tempSensorNode = new DefaultMutableTreeNode(new ImmutableAnchor("Temperature Sensor", "temp-sensor.html")); DefaultMutableTreeNode tempSensorClassNode = new DefaultMutableTreeNode(new ClassAnchor(targetCf.getString("dz.unit." + unitName + ".zone." + zoneName + ".thermostat.temp_sensor.class", "N/A"), "temp-sensor-class.html", "configurator.thermostat.sensor.class")); DefaultMutableTreeNode tempSensorAddressNode = new DefaultMutableTreeNode(new StringAnchor("Address", targetCf.getString("dz.unit." + unitName + ".zone." + zoneName + ".thermostat.temp_sensor.address", "N/A"), "temp-sensor-address.html")); thermostatNode.add(thermostatControllerClassNode); thermostatNode.add(dumpCoolingNode); thermostatNode.add(dumpHeatingNode); tempSensorNode.add(tempSensorClassNode); tempSensorNode.add(tempSensorAddressNode); thermostatNode.add(tempSensorNode); damperNode.add(damperClassNode); zoneNode.add(thermostatNode); zoneNode.add(damperNode); unitNode.add(zoneNode); } /** * Create a new zone subtree from scratch. * * It will contain the thermostat subtree, the damper subtree and the * dump priority nodes. The name will default to "New Zone". * * @param unitName Name of the unit to add the zone subtree to. */ private void createNewZone(String unitName) { // Find the unit node TreePath rootPath = cfTree.getPathForRow(0); DefaultMutableTreeNode root = (DefaultMutableTreeNode)rootPath.getLastPathComponent(); for ( int idx = 0; idx < root.getChildCount(); idx++ ) { DefaultMutableTreeNode unitNode = (DefaultMutableTreeNode)root.getChildAt(idx); Object userObject = unitNode.getUserObject(); UnitAnchor unit = (UnitAnchor)userObject; if ( unit.getName().equals(unitName) ) { // We've found the unit node to create the zone at DefaultMutableTreeNode zoneNode = new DefaultMutableTreeNode(new ZoneAnchor("New Zone")); DefaultMutableTreeNode thermostatNode = new DefaultMutableTreeNode(new ImmutableAnchor("Thermostat", "thermostat.html")); DefaultMutableTreeNode thermostatControllerClassNode = new DefaultMutableTreeNode(new ClassAnchor("N/A", "thermostat-controller-class.html", "configurator.thermostat.controller.class")); DefaultMutableTreeNode damperNode = new DefaultMutableTreeNode(new ImmutableAnchor("Damper", "damper.html")); DefaultMutableTreeNode damperClassNode = new DefaultMutableTreeNode(new ClassAnchor("N/A", "damper-class.html", "configurator.damper.class")); DefaultMutableTreeNode dumpCoolingNode = new DefaultMutableTreeNode(new DumpPriorityAnchor("Dump Priority/Cooling", "0", "dump-priority.html")); DefaultMutableTreeNode dumpHeatingNode = new DefaultMutableTreeNode(new DumpPriorityAnchor("Dump Priority/Heating", "0", "dump-priority.html")); DefaultMutableTreeNode tempSensorNode = new DefaultMutableTreeNode(new ImmutableAnchor("Temperature Sensor", "temp-sensor.html")); DefaultMutableTreeNode tempSensorClassNode = new DefaultMutableTreeNode(new ClassAnchor("N/A", "temp-sensor-class.html", "configurator.thermostat.sensor.class")); DefaultMutableTreeNode tempSensorAddressNode = new DefaultMutableTreeNode(new StringAnchor("Address", "N/A", "temp-sensor-address.html")); thermostatNode.add(thermostatControllerClassNode); thermostatNode.add(dumpCoolingNode); thermostatNode.add(dumpHeatingNode); tempSensorNode.add(tempSensorClassNode); tempSensorNode.add(tempSensorAddressNode); thermostatNode.add(tempSensorNode); damperNode.add(damperClassNode); zoneNode.add(thermostatNode); zoneNode.add(damperNode); ((DefaultTreeModel)cfTree.getModel()).insertNodeInto(zoneNode, unitNode, unitNode.getChildCount()); cfTree.scrollPathToVisible(new TreePath(zoneNode.getPath())); return; } } } public void valueChanged(TreeSelectionEvent e) { try { DefaultMutableTreeNode cursor = (DefaultMutableTreeNode)cfTree.getLastSelectedPathComponent(); if ( cursor == null ) { return; } Object userObject = cursor.getUserObject(); //complain(LOG_DEBUG, CH_CF, "Selected: " + userObject.getClass().getName() + ": " + userObject); if ( userObject instanceof NodeAnchor ) { NodeAnchor na = ((NodeAnchor)userObject); rightSplit.setTopComponent(na.getPanel()); try { helpPane.setPage(new URL(na.getHelpURL())); } catch ( FileNotFoundException fnfex ) { complain(LOG_WARNING, CH_CF, "Missing page: " + na.getHelpURL()); helpPane.setPage(new URL(getConfiguration().getString("configurator.docroot") + "/missing.html")); } } else { rightSplit.setTopComponent(nodeDisplay); helpPane.setPage(new URL(getConfiguration().getString("configurator.docroot") + "/missing.html")); } } catch ( Throwable t ) { complain(LOG_WARNING, CH_CF, "Tree selection failure:", t); } } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if ( source == file_save ) { save(targetCfURL); } else if ( source == file_exit ) { // VT: FIXME: Ask if they want to save it mainFrame.setVisible(false); mainFrame.dispose(); stop(); } else if ( source == help_about ) { complain(LOG_NOTICE, CH_CF, "Go to http://diy-zoning.sourceforge.net/ and read the configurator manual"); } } /** * Save the configuration. * * Quick and dirty hack, but what the hell - it works. Proper way, of * course, is <code>Configuration.saveXML()</code>, which is not * implemented yet ;) * * <p> * * VT: FIXME: Even without the configuration, this better be spread * around the <code>NodeAnchor</code> subclasses and used as a template * method with an <code>indent</code> parameter. */ private void save(String target) { try { URL targetURL = new URL(target); if ( !targetURL.getProtocol().equals("file") ) { complain(LOG_ERR, CH_CF, "Can't save anything other than 'file:' URL: " + target); } PrintWriter pw = new PrintWriter(new FileWriter(targetURL.getFile())); pw.println("<dz>"); TreePath rootPath = cfTree.getPathForRow(0); DefaultMutableTreeNode root = (DefaultMutableTreeNode)rootPath.getLastPathComponent(); HouseAnchor ha = (HouseAnchor)root.getUserObject(); pw.println(" <name>"); pw.println(" " + ha.getName()); pw.println(" </name>"); for ( int unit_idx = 0; unit_idx < root.getChildCount(); unit_idx++ ) { DefaultMutableTreeNode unitNode = (DefaultMutableTreeNode)root.getChildAt(unit_idx); UnitAnchor ua = (UnitAnchor)unitNode.getUserObject(); pw.println(" <unit name=\"" + ua.getName() + "\">"); // HVAC Controller DefaultMutableTreeNode hvacClassNode = (DefaultMutableTreeNode)unitNode.getChildAt(0).getChildAt(0); ClassAnchor hca = (ClassAnchor)hvacClassNode.getUserObject(); pw.println(" <class>"); pw.println(" " + hca.getName()); pw.println(" </class>"); // HVAC Driver DefaultMutableTreeNode hvacDriverClassNode = (DefaultMutableTreeNode)unitNode.getChildAt(0).getChildAt(1).getChildAt(0); ClassAnchor hdca = (ClassAnchor)hvacDriverClassNode.getUserObject(); pw.println(" <driver>"); pw.println(" <class>"); pw.println(" " + hdca.getName()); pw.println(" </class>"); // VT: FIXME: Here goes the actual configuration for the driver pw.println(" </driver>"); // Zone controller pw.println(" <zone_controller>"); DefaultMutableTreeNode zoneClassNode = (DefaultMutableTreeNode)unitNode.getChildAt(1).getChildAt(0); ClassAnchor zca = (ClassAnchor)zoneClassNode.getUserObject(); pw.println(" <class>"); pw.println(" " + zca.getName()); pw.println(" </class>"); // Dump threshold DefaultMutableTreeNode dumpThresholdNode = (DefaultMutableTreeNode)unitNode.getChildAt(1).getChildAt(1); StringAnchor dt = (StringAnchor)dumpThresholdNode.getUserObject(); pw.println(" <dump_threshold>"); pw.println(" " + dt.getName()); pw.println(" </dump_threshold>"); pw.println(" </zone_controller>"); // All the zones for ( int zone_idx = 2; zone_idx < unitNode.getChildCount(); zone_idx++ ) { DefaultMutableTreeNode zoneNode = (DefaultMutableTreeNode)unitNode.getChildAt(zone_idx); ZoneAnchor za = (ZoneAnchor)zoneNode.getUserObject(); pw.println(" <zone name=\"" + za.getName() + "\">"); // Thermostat pw.println(" <thermostat>"); DefaultMutableTreeNode tsClassNode = (DefaultMutableTreeNode)zoneNode.getChildAt(0).getChildAt(0); ClassAnchor tsca = (ClassAnchor)tsClassNode.getUserObject(); pw.println(" <controller>"); pw.println(" <class>"); pw.println(" " + tsca.getName()); pw.println(" </class>"); pw.println(" </controller>"); // Dump priority DefaultMutableTreeNode dumpCoolNode = (DefaultMutableTreeNode)zoneNode.getChildAt(0).getChildAt(1); DumpPriorityAnchor dcool = (DumpPriorityAnchor)dumpCoolNode.getUserObject(); pw.println(" <dump_priority>"); pw.println(" <cool>"); pw.println(" " + dcool.getName()); pw.println(" </cool>"); DefaultMutableTreeNode dumpHeatNode = (DefaultMutableTreeNode)zoneNode.getChildAt(0).getChildAt(2); DumpPriorityAnchor dheat = (DumpPriorityAnchor)dumpHeatNode.getUserObject(); pw.println(" <heat>"); pw.println(" " + dheat.getName()); pw.println(" </heat>"); pw.println(" </dump_priority>"); // Sensor pw.println(" <temp_sensor>"); DefaultMutableTreeNode sensorClassNode = (DefaultMutableTreeNode)zoneNode.getChildAt(0).getChildAt(3).getChildAt(0); ClassAnchor sca = (ClassAnchor)sensorClassNode.getUserObject(); pw.println(" <class>"); pw.println(" " + sca.getName()); pw.println(" </class>"); DefaultMutableTreeNode sensorAddressNode = (DefaultMutableTreeNode)zoneNode.getChildAt(0).getChildAt(3).getChildAt(1); StringAnchor saca = (StringAnchor)sensorAddressNode.getUserObject(); pw.println(" <address>"); pw.println(" " + saca.getName()); pw.println(" </address>"); // VT: FIXME: The rest of the sensor configuration goes here pw.println(" </temp_sensor>"); pw.println(" </thermostat>"); // Damper DefaultMutableTreeNode damperClassNode = (DefaultMutableTreeNode)zoneNode.getChildAt(1).getChildAt(0); ClassAnchor dca = (ClassAnchor)damperClassNode.getUserObject(); pw.println(" <damper>"); pw.println(" <class>"); pw.println(" " + dca.getName()); pw.println(" </class>"); // VT: FIXME: The damper configuration goes here pw.println(" </damper>"); pw.println(" </zone>"); } pw.println(" </unit>"); } pw.println("</dz>"); pw.flush(); pw.close(); } catch ( Throwable t ) { complain(LOG_ERR, CH_CF, "Can't save " + target + ", cause:", t); } complain(LOG_NOTICE, CH_CF, "Saved " + target); } /** * Describes the tree node context, logical and graphical. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -