⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 corewizard.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package net.sf.dz.setup.core;import java.awt.GridBagConstraints;import java.awt.GridBagLayout; import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Set;import java.util.SortedSet;import java.util.StringTokenizer;import java.util.TreeMap;import java.util.TreeSet;import java.util.Vector;import javax.swing.BorderFactory;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JScrollPane;import javax.swing.JTextPane;import javax.swing.ListSelectionModel;import javax.swing.WindowConstants;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import org.freehold.jukebox.logger.LogChannel;import org.freehold.jukebox.logger.Logger;import org.freehold.jukebox.service.PassiveService;import org.freehold.servomaster.device.model.Servo;import org.freehold.servomaster.device.model.ServoController;import net.sf.dz.setup.ConfigureConnectorsPage;import net.sf.dz.util.wizard.ConfigurationReader;import net.sf.dz.util.wizard.DoublePanel;import net.sf.dz.util.wizard.DoubleListPanel;import net.sf.dz.util.wizard.Wizard;import net.sf.dz.util.wizard.WizardPage;import net.sf.dz.util.wizard.WizardProcessor;import net.sf.dz.util.wizard.NarrowWizardPage;import net.sf.dz.util.wizard.MessageWizardPage;import net.sf.dz.util.wizard.SelectConfigurationFilePage;import net.sf.dz.pnp.MulticastClient;import net.sf.dz.pnp.MulticastEvent;import net.sf.dz.pnp.MulticastEventListener;import net.sf.dz.pnp.custom.SimpleBroadcastClient;/** * CORE configuration wizard. * * Allows to configure the CORE module, provided the DAC is already * configured, up and running (however, it is possible to have a 'dry run' * without DAC even installed). * * @author Copyright &copy; <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2004 * @version $Id: CoreWizard.java,v 1.13 2004/07/28 07:22:52 vtt Exp $ */public class CoreWizard extends PassiveService {    public static final LogChannel CH_CW = new LogChannel("Wizard/CORE");        /**     * Directory where the DZ binaries are located.     *     * Obtained from environment variable.     */    private File dzDeploymentBin;        /**     * Directory where the DZ binaries are located.     *     * Obtained from environment variable.     */    private File dzDeploymentConfig;    /**     * Directory where the DZ schedule files are located.     *     * <strong>FIXME:</strong> This one is a shortcut to avoid extra wizard     * page. Derived from {@link #dzDeploymentConfig dzDeploymentConfig}.     */    private File dzDeploymentSchedule;    /**     * Directory where the DZ collected data is to be located.     *     * Obtained from environment variable.     */    private File dzDeploymentData;    private JFrame mainFrame;    private Wizard wizard;    private MulticastClient sensorClient = new SimpleBroadcastClient(5001);    private MulticastClient switchClient = new SimpleBroadcastClient(5003);        protected void startup() throws Throwable {            mainFrame = new JFrame("DIY Zoning Core Module configurator");        mainFrame.setSize(800, 600);        mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);                sensorClient.setLogger(getLogger());        switchClient.setLogger(getLogger());                // VT: FIXME: Check if it really started                try {                    sensorClient.start().waitFor();            switchClient.start().waitFor();                    } catch ( InterruptedException iex ) {                    complain(LOG_ERR, CH_CW, "Interrupted:", iex);        }                // A little cheating. The script that runs this class contains all        // the necessary things as environment variables, configured at        // ./configure time.                dzDeploymentBin = new File(System.getProperty("dz.bin.dir"));        dzDeploymentConfig = new File(System.getProperty("dz.conf.dir"));        dzDeploymentSchedule = new File(dzDeploymentConfig, "schedule");        dzDeploymentData = new File(System.getProperty("dz.data.dir"));                WizardProcessor wp = new CoreWizardProcessor();                wizard = new Wizard(wp);                wizard.getContext().put("schedule.dir", dzDeploymentSchedule.toString());                String pnpClientMessage = "Next page allows you to configure the PnP client.\n\n"                                + "Port and transport settings should match those set in DAC\n"                                + "(if you didn't change the defaults, you're fine).";        String pnpMessage = "Configurator will now try to discover the devices provided by DAC modules.\n"                          + "It is assumed that at this point the DAC modules are up and running.\n\n"                          + "You may have to wait a few seconds until capabilities discovery broadcast arrives.";                                  PnpTemperatureSensorPage pnptsPage = new PnpTemperatureSensorPage(getLogger(), wizard);        AddHvacUnitPage ahuPage = new AddHvacUnitPage(getLogger(), wizard);        ConfigurationReader cfReader = new CoreConfigurationReader(getLogger());                WizardPage content[] = { new SelectConfigurationFilePage(getLogger(), wizard, dzDeploymentConfig, "dz.conf.xml", cfReader, "cf.core"),                                 new MessageWizardPage(getLogger(), wizard, "PnP Client Configuration", pnpClientMessage),                                 new ConfigureConnectorsPage(getLogger(), wizard, false),                                 new MessageWizardPage(getLogger(), wizard, "PnP Device Discovery", pnpMessage),                                 pnptsPage,                                 new SchedulePage(getLogger(), wizard),                                 new SelectServoControllerPage(getLogger(), wizard),                                 new MapServosPage(getLogger(), wizard),                                 ahuPage,                                 new MapZonesPage(getLogger(), wizard),                                 new ConfirmPage(getLogger(), wizard)        };                sensorClient.addListener(pnptsPage);                // VT: FIXME                switchClient.addListener(ahuPage);        wizard.process(content);        mainFrame.getContentPane().add(wizard);                mainFrame.setVisible(true);    }        protected void shutdown(Throwable cause) throws Throwable {            sensorClient.stop();        switchClient.stop();    }    protected class CoreWizardProcessor implements WizardProcessor {            public void init(Map context) {                    complain(LOG_CRIT, CH_CW, "FIXME: init");        }                /**         * Put together an XML document and write it into a specified file.         *         * @param context Data created by the wizard.         */        public void finish(Map context) {            File outputFile = new File(context.get("config.file").toString());                        if ( outputFile.isDirectory() ) {                            outputFile = new File(outputFile, "dz.conf.xml");            }                        complain(LOG_NOTICE, CH_CW, "Output file: " + outputFile);                        StringBuffer sb = new StringBuffer();            File dzCoreWizard = new File(dzDeploymentBin, "dz_core_wizard");                        sb.append("<dz xmlns=\"http://diy-zoning.sourceforge.net/namespaces/core\">\n\n");            sb.append("    <!--\n\n");            sb.append("        This file was generated by ");            sb.append(dzCoreWizard.toString());            sb.append(".\n        Do not edit - unless you read the docs, that is\n\n");            sb.append("      -->\n\n");                        // VT: FIXME: House name should be configurable                        sb.append("    <name>My House</name>\n");                        for ( Iterator i = getSortedContextValues(context, "unit.").iterator(); i.hasNext(); ) {                            UnitDescriptor ud = (UnitDescriptor)i.next();                                renderUnit(ud, context, sb);            }                        renderSchedule(context, sb);                        renderView(context, sb);                        sb.append("</dz>\n");                        String configuration = sb.toString();            complain(LOG_NOTICE, CH_CW, "Configuration:\n" + configuration);                        // Now that we have it, save it                        try {                            PrintWriter pw = new PrintWriter(new FileWriter(outputFile));                                pw.println(configuration);                pw.flush();                pw.close();                            } catch ( IOException ioex ) {                            complain(LOG_ERR, CH_CW, "Unable to save " + outputFile + ":", ioex);            }        }                private void renderUnit(UnitDescriptor ud, Map context, StringBuffer sb) {                    String modeAddress = (String)ud.propertyMap.get("switch.mode.address");            String stageAddress = (String)ud.propertyMap.get("switch.stage.address");            String fanAddress = (String)ud.propertyMap.get("switch.fan.address");                    sb.append("    <unit name=\"").append(ud.name).append("\">\n");            sb.append("        <class>net.sf.dz.device.actuator.impl.AC_Controller</class>\n");            sb.append("        <driver>\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -