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

📄 dacwizard.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package net.sf.dz.setup.dac;import java.awt.GridBagConstraints;import java.awt.GridBagLayout; import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ItemEvent;import java.io.IOException;import java.io.File;import java.io.FileWriter;import java.io.PrintWriter;import java.util.Enumeration;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.TreeMap;import javax.comm.CommPortIdentifier;import javax.comm.PortInUseException;import javax.comm.SerialPort;import javax.comm.UnsupportedCommOperationException;import javax.swing.BorderFactory;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.WindowConstants;import com.dalsemi.onewire.OneWireAccessProvider;import com.dalsemi.onewire.adapter.DSPortAdapter;import org.freehold.jukebox.logger.LogChannel;import org.freehold.jukebox.logger.Logger;import org.freehold.jukebox.service.PassiveService;import net.sf.dz.setup.ConfigureConnectorsPage;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;/** * DAC configuration wizard. * * Allows to select the hardware type (1-Wire is the only one supported at * this point), 1-Wire access type (OWAPI vs. OWFS), RRD logger (RRDTool vs. * JRobin), and UDP broadcaster ports. * * @author Copyright &copy; <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2004 * @version $Id: DacWizard.java,v 1.3 2004/07/22 18:49:30 vtt Exp $ */public class DacWizard extends PassiveService {    public static final LogChannel CH_DW = new LogChannel("Wizard/DAC");        private File dzDeploymentBin;    private File dzDeploymentConfig;    private File dzDeploymentData;        private JFrame mainFrame;    private Wizard wizard;    protected void startup() throws Throwable {            mainFrame = new JFrame("DIY Zoning Data Acquisition Module configurator");        mainFrame.setSize(800, 600);        mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);                // 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"));        dzDeploymentData = new File(System.getProperty("dz.data.dir"));                WizardProcessor wp = new DacWizardProcessor();                wizard = new Wizard(wp);                String pnpServerMessage = "Next page allows you to configure the PnP server.\n\n"                                + "It is not recommended to change default port and transport settings.\n"                                + "Do so only if default settings conflict with your existing network\n"                                + "configuration.\n\n"                                + "A symptom of it is a \"port is already bound\" message.";                WizardPage content[] = { new SelectConfigurationFilePage(getLogger(), wizard, dzDeploymentConfig, "dac.conf.xml", null, "cf.dac"),                                 new SelectHardwarePage(getLogger(), wizard),                                 new SelectOneWireDriverPage(getLogger(), wizard),                                 new SelectSerialPage(getLogger(), wizard),                                 new ConfigureLoggerPage(getLogger(), wizard),                                 new MessageWizardPage(getLogger(), wizard, "PnP Server Configuration", pnpServerMessage),                                 new ConfigureConnectorsPage(getLogger(), wizard, true),                                 new ConfirmPage(getLogger(), wizard)        };                wizard.process(content);        mainFrame.getContentPane().add(wizard);                mainFrame.setVisible(true);    }        protected void shutdown(Throwable cause) throws Throwable {        }        protected class SelectHardwarePage extends NarrowWizardPage {            private JCheckBox onewireBox;        private JCheckBox phidgetBox;            public SelectHardwarePage(Logger logger, Wizard owner) {                    super(logger, owner, "Select Peripheral Hardware (sensors and switches)");                        GridBagLayout layout = new GridBagLayout();            GridBagConstraints cs = new GridBagConstraints();                        getNarrowPane().setLayout(layout);                        onewireBox = new JCheckBox("1-Wire");            phidgetBox = new JCheckBox("Phidgets");                        JPanel filler1 = new JPanel();            JPanel filler2 = new JPanel();                        cs.fill = GridBagConstraints.BOTH;            cs.gridx = 0;            cs.gridy = 0;            cs.weightx = 1;            cs.weighty = 1;            layout.setConstraints(filler1, cs);            getNarrowPane().add(filler1);                        cs.gridy++;            cs.fill = GridBagConstraints.HORIZONTAL;            cs.weighty = 0;                        layout.setConstraints(onewireBox, cs);            getNarrowPane().add(onewireBox);                        cs.gridy++;                        layout.setConstraints(phidgetBox, cs);            getNarrowPane().add(phidgetBox);                        cs.gridy++;            cs.fill = GridBagConstraints.BOTH;            cs.weighty = 1;                        layout.setConstraints(filler2, cs);            getNarrowPane().add(filler2);                        // VT: FIXME: Sorry...                        onewireBox.setSelected(true);            phidgetBox.setEnabled(false);                        onewireBox.addItemListener(this);            phidgetBox.addItemListener(this);        }                public String getHelpURL() {                    return "FIXME";        }                public String validate() {                    try {                            return (onewireBox.isSelected() || phidgetBox.isSelected()) ? "" : "At least one type must be selected";                            } finally {                            getOwner().getContext().put("hardware.1-Wire", new Boolean(onewireBox.isSelected()));                getOwner().getContext().put("hardware.Phidgets", new Boolean(phidgetBox.isSelected()));            }        }        public boolean isEnabled() {                    return true;        }    }    protected class SelectOneWireDriverPage extends NarrowWizardPage {            private JRadioButton owapiRadio;        private JRadioButton owfsRadio;        private ButtonGroup driverGroup;            private JRadioButton serialRadio;        private JRadioButton usbRadio;        private ButtonGroup adapterGroup;                private JPanel owapiAdapterPanel;        private JPanel owfsMountPointPanel;        private JButton owfsMountPointButton;        private JFileChooser owfsMountPointChooser;                private JPanel serialSelectionPanel;        private JButton probeSerialButton;        private JPanel portListPanel;            public SelectOneWireDriverPage(Logger logger, Wizard owner) {                    super(logger, owner, "Select 1-Wire Driver");                        GridBagLayout layout = new GridBagLayout();            GridBagConstraints cs = new GridBagConstraints();                        getNarrowPane().setLayout(layout);                        owapiRadio = new JRadioButton("Java 1-Wire API");            serialRadio = new JRadioButton("Serial (RxTx)");            usbRadio = new JRadioButton("USB");            owfsRadio = new JRadioButton("OWFS");                        driverGroup = new ButtonGroup();            adapterGroup = new ButtonGroup();                        driverGroup.add(owapiRadio);            driverGroup.add(owfsRadio);                        adapterGroup.add(serialRadio);            adapterGroup.add(usbRadio);                        JPanel fillerTop = new JPanel();            JPanel fillerBottom = new JPanel();                        owapiAdapterPanel = new JPanel();            owfsMountPointPanel = new JPanel();                        owapiAdapterPanel.setLayout(new GridLayout(2, 1));            owapiAdapterPanel.add(serialRadio);            owapiAdapterPanel.add(usbRadio);            owapiAdapterPanel.setBorder(BorderFactory.createTitledBorder("1-Wire Adapter"));                        owfsMountPointButton = new JButton("/mnt/owfs");            owfsMountPointButton.addActionListener(this);                        owfsMountPointPanel.setBorder(BorderFactory.createTitledBorder("Mount Point"));            owfsMountPointPanel.setLayout(new GridLayout(1, 1));            owfsMountPointPanel.add(owfsMountPointButton);                        owfsMountPointChooser = new JFileChooser();            owfsMountPointChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);            owfsMountPointChooser.setCurrentDirectory(new File("/mnt"));                        cs.fill = GridBagConstraints.BOTH;            cs.gridx = 0;            cs.gridy = 0;            cs.weightx = 1;            cs.weighty = 1;            layout.setConstraints(fillerTop, cs);            getNarrowPane().add(fillerTop);                        cs.gridy++;            cs.fill = GridBagConstraints.HORIZONTAL;            cs.weighty = 0;                        layout.setConstraints(owapiRadio, cs);            getNarrowPane().add(owapiRadio);                        cs.gridx++;                        layout.setConstraints(owapiAdapterPanel, cs);            getNarrowPane().add(owapiAdapterPanel);                        cs.gridx--;            cs.gridy++;                        layout.setConstraints(owfsRadio, cs);            getNarrowPane().add(owfsRadio);                        cs.gridx++;                        layout.setConstraints(owfsMountPointPanel, cs);            getNarrowPane().add(owfsMountPointPanel);                        cs.gridx--;            cs.gridy++;            cs.fill = GridBagConstraints.BOTH;            cs.weighty = 1;                        layout.setConstraints(fillerBottom, cs);            getNarrowPane().add(fillerBottom);                        // VT: FIXME: Sorry... OWFS is not yet fully supported, neither            // is USB 1-Wire adapter.            owfsRadio.setEnabled(false);            usbRadio.setEnabled(false);                        owapiRadio.setSelected(true);            serialRadio.setSelected(true);            owfsMountPointButton.setEnabled(false);                        owapiRadio.addActionListener(this);            owfsRadio.addActionListener(this);            serialRadio.addActionListener(this);            usbRadio.addActionListener(this);        }                public String getHelpURL() {                    return "FIXME";        }                public String validate() {                    try {                        // We can go next if one of the following is true:                //                // - OWAPI is selected, serial adapter is selected;                // - OWFS is selected, mount point is a valid directory.                            if (owapiRadio.isSelected() && serialRadio.isSelected()) {                                    return "";                }                                if ( owfsRadio.isSelected() ) {                                    File mountPoint = new File(owfsMountPointButton.getText());                                        if ( mountPoint.exists() && mountPoint.isDirectory() && mountPoint.canWrite() ) {                                            return "";                    } else {                                            return mountPoint.toString() + ": doesn't exist, is not a directory or not writable";                    }                }                                throw new IllegalStateException("We shouldn't be here");            } finally {                            getOwner().getContext().put("1-Wire.owapi", new Boolean(owapiRadio.isSelected()));                getOwner().getContext().put("1-Wire.owfs", new Boolean(owfsRadio.isSelected()));                getOwner().getContext().put("1-Wire.owapi.serial", new Boolean(serialRadio.isSelected()));                getOwner().getContext().put("1-Wire.owapi.USB", new Boolean(usbRadio.isSelected()));                getOwner().getContext().put("1-Wire.owfs.mountpoint", owfsMountPointButton.getText());            }        }                protected void actionPerformed2(ActionEvent e) {                    if ( owfsMountPointButton.equals(e.getSource()) ) {                            int rc = owfsMountPointChooser.showDialog(getNarrowPane(), "Use as mount point");                                if ( rc == JFileChooser.APPROVE_OPTION ) {                                    owfsMountPointButton.setText(owfsMountPointChooser.getSelectedFile().toString());                }            }            getOwner().getContext().put("1-Wire driver.owapi", new Boolean(owapiRadio.isSelected()));            getOwner().getContext().put("1-Wire driver.owfs", new Boolean(owfsRadio.isSelected()));            getOwner().getContext().put("1-Wire adapter.serial", new Boolean(serialRadio.isSelected()));            getOwner().getContext().put("1-Wire adapter.usb", new Boolean(usbRadio.isSelected()));                        getOwner().getContext().put("1-Wire driver.owfs.mountpoint", owfsMountPointButton.getText());                        serialRadio.setEnabled(owapiRadio.isSelected());                        // VT: FIXME            //usbRadio.setEnabled(owapiRadio.isSelected());            

⌨️ 快捷键说明

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