zonepanel.java

来自「这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统」· Java 代码 · 共 563 行 · 第 1/2 页

JAVA
563
字号
package net.sf.dz.view.tcp.client;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.StringTokenizer;import java.util.TreeMap;import javax.swing.BorderFactory;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JSpinner;import javax.swing.SpinnerNumberModel;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import org.freehold.jukebox.logger.LogAware;import org.freehold.jukebox.logger.LogChannel;import net.sf.dz.util.Round;import net.sf.dz.util.chart.Chart;import net.sf.dz.view.component.ScheduleListener;import net.sf.dz.view.component.SchedulePanel;/** * Zone panel. * * Contains zone display elements and controls. Display elements include: * * <ul> * *     <li> Current temperature display; * *     <li> Controller status chart; * *     <li> Damper status chart; * *     <li> Schedule view. * * </ul> * * Controls include: * * <ul> * *     <li> "Hold" checkbox, allows to put this zone on hold (disallow *          setpoint changes caused by scheduler); * *     <li> "Disable" checkbox, allows to shut off this zone; * *     <li> "Voting" checkbox, allows to select whether this zone is allowed *          to initiate HVAC start; * *     <li> Dump priority drop down, allows to select dump priority. * * </ul> * * @author Copyright &copy; <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2001-2004 * @version $Id: ZonePanel.java,v 1.28 2004/07/16 22:27:59 vtt Exp $ */public class ZonePanel extends LogAware implements ChangeListener, ItemListener, ScheduleListener {    /**     * Log channel to use.     */    public final LogChannel CH_ZP;        /**     * Font to use.     */    public static final Font normalFont = new Font("Lucida Bright", Font.ROMAN_BASELINE, 16);        /**     * Reference to the unit panel this zone panel belongs to.     */    private UnitPanel unitPanel;        /**     * Name of this zone.     */    private String zoneName;        /**     * The zone panel GUI container.     */    private JPanel panel;        /**     * The {@link #panel zone panel} layout.     */    private GridBagLayout layout = new GridBagLayout();        /**     * The {@link #panel zone panel} layout constraints.     */    private GridBagConstraints cs = new GridBagConstraints();        /**     * Allows to control the ON mode.     */    private JCheckBox disableBox;        /**     * Allows to control the HOLD mode.     */    private JCheckBox holdBox;        /**     * Allows to control the voting mode.     */    private JCheckBox votingBox;        /**     * Allows to select dump priority.     */    private JComboBox dumpSelector;        /**     * Displays the current temperature.     */    private JLabel currentLabel;        /**     * Displays and adjusts the setpoint.     */    private JSpinner setpointSpinner;        /**     * Displays the controller status.     */    private Chart controllerChart;        /**     * Displays the damper status.     */    private Chart damperChart;        /**     * The schedule panel.     */    private SchedulePanel schedulePanel;        /**     * Command prefix.     *     * The command prefix is the string "zone:" with appended name of this     * zone.     */    private final String prefix;        /**     * Controller legend.     */    private List controllerLegend;        public ZonePanel(UnitPanel unitPanel, String zoneName) {            CH_ZP = new LogChannel("Zone/" + zoneName);                this.unitPanel = unitPanel;        this.zoneName = zoneName;                prefix = "zone:" + zoneName + ":";                panel = new JPanel();        panel.setBorder(BorderFactory.createTitledBorder(zoneName));        panel.setLayout(layout);    }        public JPanel getPanel() {            return panel;    }        protected void configure() throws Throwable {            cs.gridx = 0;        cs.gridy = 0;        cs.fill = GridBagConstraints.HORIZONTAL;        cs.weightx = 1;        cs.weighty = 0;                holdBox = new JCheckBox("Hold");        //holdBox.setFont(normalFont);        holdBox.setToolTipText("Check this box to make current settings stay regardless of the schedule");        holdBox.addItemListener(this);                layout.setConstraints(holdBox, cs);        panel.add(holdBox);                cs.gridy++;        disableBox = new JCheckBox("Disable");        disableBox.setToolTipText("Check this box to shut off this zone");        //disableBox.setFont(normalFont);        disableBox.addItemListener(this);                layout.setConstraints(disableBox, cs);        panel.add(disableBox);        cs.gridy++;        votingBox = new JCheckBox("Voting");        votingBox.setToolTipText("Uncheck this box to prevent this zone from switching on the HVAC");        //votingBox.setFont(normalFont);        votingBox.addItemListener(this);                layout.setConstraints(votingBox, cs);        panel.add(votingBox);                cs.gridy++;        final String[] dumpValues = { "Off", "High", "Medium", "Low" };        dumpSelector = new JComboBox(dumpValues);        dumpSelector.setToolTipText("Select dump priority for this zone");        //dumpSelector.setFont(normalFont);        //dumpSelector.addItemListener(this);                // VT: FIXME: This has to be implemented first        dumpSelector.setEnabled(false);                layout.setConstraints(dumpSelector, cs);        panel.add(dumpSelector);                cs.gridx++;        cs.gridy = 0;        cs.gridheight = 4;        currentLabel = new JLabel("99.9999\u00b0", JLabel.RIGHT);        currentLabel.setFont(new Font("Lucida Bright", Font.BOLD, 48));        currentLabel.setBorder(BorderFactory.createTitledBorder("Current Temperature"));        currentLabel.setToolTipText("Current temperature");                // Fix the problem: the preferred size may be different by the time        // this panel gets displayed, so let's set it now, while the size is        // good.                currentLabel.setPreferredSize(currentLabel.getPreferredSize());                layout.setConstraints(currentLabel, cs);        panel.add(currentLabel);                cs.gridx++;        setpointSpinner = new JSpinner(new SpinnerNumberModel(24.0, 15.0, 32.0, 0.25));                // VT: FIXME: WHAT??? Font doesn't change???                setpointSpinner.setFont(new Font("Lucida Bright", Font.BOLD, 48));        setpointSpinner.setBorder(BorderFactory.createTitledBorder("Setpoint"));        setpointSpinner.setToolTipText("Change the desired temperature");        setpointSpinner.addChangeListener(this);                // Fix the problem: default size is too narrow                Dimension d1 = currentLabel.getPreferredSize();        Dimension d2 = setpointSpinner.getPreferredSize();        setpointSpinner.setPreferredSize(new Dimension(d2.width * 2, d1.height));                layout.setConstraints(setpointSpinner, cs);        panel.add(setpointSpinner);                controllerChart = new Chart();        controllerChart.setBackground(Color.black);        controllerChart.setGridColor(Color.darkGray);                controllerLegend = new LinkedList();                controllerLegend.add("Error");        controllerLegend.add("Signal");        controllerLegend.add("P");        controllerLegend.add("I");

⌨️ 快捷键说明

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