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

📄 preferencespanel.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
字号:
package net.sf.dz.view.tcp.client;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.util.Iterator;import java.util.StringTokenizer;import javax.swing.BorderFactory;import javax.swing.ButtonGroup;import javax.swing.JCheckBox;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.border.TitledBorder;import org.freehold.jukebox.logger.LogAware;import org.freehold.jukebox.logger.LogChannel;public class PreferencesPanel extends LogAware implements ActionListener, ItemListener {    public static final LogChannel CH_PP = new LogChannel("Preferenes");    private ClientDaemon daemon;    private JPanel panel;        private JRadioButton modeCoolRadio;    private JRadioButton modeOffRadio;    private JRadioButton modeHeatRadio;    private JRadioButton tempCelsiusRadio;    private JRadioButton tempFahrenheitRadio;        private JCheckBox displayHvacGraph;    private JCheckBox displayZoneGraph;    private JCheckBox displayPConGraph;    private JCheckBox displayDamperGraph;    private JCheckBox displayScheduler;        public PreferencesPanel(ClientDaemon daemon) {            this.daemon = daemon;                setLogger(daemon.getLogger());                this.panel = new JPanel();                // The following controls must be present here:                //	HVAC mode selector: cool, off, heat - radio button        //	Temperature display: F/C - radio button        //	Display HVAC controller graph: checkbox        //	Display zone controller graph: checkbox        //	Display controller signal graph: checkbox        //	Display damper signal graph: checkbox        //	Display scheduler on main tab: checkbox                ButtonGroup modeGroup = new ButtonGroup();        ButtonGroup tempGroup = new ButtonGroup();                modeCoolRadio = new JRadioButton("Cooling", true);        modeOffRadio = new JRadioButton("Off");        modeHeatRadio = new JRadioButton("Heating");                modeGroup.add(modeCoolRadio);        modeGroup.add(modeOffRadio);        modeGroup.add(modeHeatRadio);                modeCoolRadio.addActionListener(this);        modeOffRadio.addActionListener(this);        modeHeatRadio.addActionListener(this);        tempCelsiusRadio = new JRadioButton("\u00b0C (Celsius)", true);        tempFahrenheitRadio = new JRadioButton("\u00b0F (Fahrenheit)");                tempGroup.add(tempCelsiusRadio);        tempGroup.add(tempFahrenheitRadio);                tempCelsiusRadio.addActionListener(this);        tempFahrenheitRadio.addActionListener(this);                displayHvacGraph = new JCheckBox("Unit Status graph");        displayZoneGraph = new JCheckBox("Zone Signal graph");        displayPConGraph = new JCheckBox("Controller Signal graph");        displayDamperGraph = new JCheckBox("Damper Signal graph");        displayScheduler = new JCheckBox("Scheduler on main tab");                displayHvacGraph.addItemListener(this);        displayZoneGraph.addItemListener(this);        displayPConGraph.addItemListener(this);        displayDamperGraph.addItemListener(this);        displayScheduler.addItemListener(this);                JPanel modePanel = new JPanel();                modePanel.setBorder(BorderFactory.createTitledBorder("HVAC Mode"));        modePanel.setLayout(new GridLayout(3, 1));                modePanel.add(modeCoolRadio);        modePanel.add(modeOffRadio);        modePanel.add(modeHeatRadio);                panel.add(modePanel);                JPanel tempPanel = new JPanel();        tempPanel.setBorder(BorderFactory.createTitledBorder("Temperature Units"));        tempPanel.setLayout(new GridLayout(2, 1));                tempPanel.add(tempCelsiusRadio);        tempPanel.add(tempFahrenheitRadio);                panel.add(tempPanel);                JPanel unitOptionsPanel = new JPanel();        unitOptionsPanel.setBorder(BorderFactory.createTitledBorder("Unit Panel"));        unitOptionsPanel.setLayout(new GridLayout(2, 1));                unitOptionsPanel.add(displayHvacGraph);        unitOptionsPanel.add(displayZoneGraph);        unitOptionsPanel.add(displayPConGraph);        unitOptionsPanel.add(displayDamperGraph);        unitOptionsPanel.add(displayScheduler);                panel.add(unitOptionsPanel);        JPanel zoneOptionsPanel = new JPanel();        zoneOptionsPanel.setBorder(BorderFactory.createTitledBorder("Zone Panel"));        zoneOptionsPanel.setLayout(new GridLayout(3, 1));                zoneOptionsPanel.add(displayPConGraph);        zoneOptionsPanel.add(displayDamperGraph);        zoneOptionsPanel.add(displayScheduler);                panel.add(zoneOptionsPanel);                // Set the defaults                // HVAC mode is not subject to defaults, it is set based on CORE        // data                // Default measurement units are centigree, this is where the        // selector is by default already                // Both HVAC status and zone signal graphs are visible                displayHvacGraph.setSelected(true);        displayZoneGraph.setSelected(true);                // Both zone controller signal and damper state graphs are visible                displayPConGraph.setSelected(true);        displayDamperGraph.setSelected(true);                // Schedule is on the main panel by default                displayScheduler.setSelected(true);                // VT: FIXME: And this is not yet implemented                displayScheduler.setEnabled(false);    }        public JPanel getPanel() {            return panel;    }        public void itemStateChanged(ItemEvent e) {            JCheckBox source = (JCheckBox)e.getSource();        boolean enabled = source.isSelected();                // VT: FIXME: Implement this later, so far let's just show that we        // know someone's pressing the buttons                if ( source == displayHvacGraph ) {                    daemon.setHvacGraph(enabled);                    } else if ( source == displayZoneGraph ) {                    daemon.setZoneGraph(enabled);                    } else if ( source == displayPConGraph ) {                    daemon.setPConGraph(enabled);                    } else if ( source == displayDamperGraph ) {                    daemon.setDamperGraph(enabled);                    } else if ( source == displayScheduler ) {                    complain(LOG_NOTICE, CH_PP, "Scheduler: " + enabled);                    } else {                    complain(LOG_WARNING, CH_PP, "Don't know how to handle checkbox: " + source);        }    }    public void actionPerformed(ActionEvent e) {            Object source = e.getSource();                if ( source == modeCoolRadio ) {                    setMode(-1);                    } else if ( source == modeOffRadio ) {                    setMode(0);                    } else if ( source == modeHeatRadio ) {                    setMode(1);        } else if ( source == tempCelsiusRadio ) {                } else if ( source == tempFahrenheitRadio ) {                } else {                    complain(LOG_WARNING, CH_PP, "Don't know how to handle radio button: " + source);        }    }        /**     * Set the HVAC mode.     *     * Currently, all the units must have the same mode - this may or may     * not be a smart idea. See the mailing list archive for discussion.     *     * @param mode HVAC mode - 0 is off, 1 is heating, -1 is cooling.     */    private void setMode(int mode) {            // Figure out all the units that we have                for ( Iterator i = daemon.getUnitNames().iterator(); i.hasNext(); ) {                    daemon.send("unit:" + i.next() + ":ac:mode:" + mode);        }    }        public void parse(StringTokenizer st) {            String target = st.nextToken();                if ( "mode".equals(target) ) {                    int mode = Integer.parseInt(st.nextToken());                        switch ( mode ) {                            case -1:                                    modeCoolRadio.setSelected(true);                    break;                case 0:                                    modeOffRadio.setSelected(true);                    break;                case 1:                                    modeHeatRadio.setSelected(true);                    break;            }                    } else {                    complain(LOG_WARNING, CH_PP, "Unknown target: '" + target + "'");        }        }}

⌨️ 快捷键说明

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