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

📄 schedulepanel.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        cs.gridx++;            layout.setConstraints(tempUp, cs);            add(tempUp);                        cs.gridx = 0;            cs.gridy++;            layout.setConstraints(timeDown, cs);            add(timeDown);                        cs.gridx++;            layout.setConstraints(tempDown, cs);            add(tempDown);                        cs.gridx = 0;            cs.gridy++;            cs.gridwidth = 1;            cs.weightx = 1;            cs.weighty = 0;            cs.fill = GridBagConstraints.HORIZONTAL;            layout.setConstraints(votingBox, cs);            add(votingBox);            cs.gridx++;            layout.setConstraints(offBox, cs);            add(offBox);                                  cs.gridx = 0;            cs.gridy++;            cs.gridwidth = 2;            layout.setConstraints(dumpSelector, cs);            add(dumpSelector);                        setEnabled(false);        }                public void enable(ScheduleEvent se) {                    push();                        try {                            setEnabled(true);                                offBox.setSelected(!se.enabled);                votingBox.setSelected(se.voting);                dumpSelector.setSelectedIndex(se.dumpPriority);                            } finally {                            pop();            }        }                /**         * Set the enabled/disabled state of the controls.         *         * This is required in case of empty list selection.  Default state         * is disabled.         */        public void setEnabled(boolean enabled) {                    push();                    timeUp.setEnabled(enabled);            timeDown.setEnabled(enabled);            tempUp.setEnabled(enabled);            tempDown.setEnabled(enabled);            offBox.setEnabled(enabled);            votingBox.setEnabled(enabled);            dumpSelector.setEnabled(enabled);                        if ( enabled && currentEvent != null ) {                            offBox.setSelected(!currentEvent.enabled);                votingBox.setSelected(currentEvent.voting);                dumpSelector.setSelectedIndex(currentEvent.dumpPriority);            } else {                            offBox.setSelected(false);                votingBox.setSelected(false);                dumpSelector.setSelectedIndex(0);            }                        pop();        }        /**         * Handless >>, <<, +, - buttons and dump priority combo.         */        public void actionPerformed(ActionEvent e) {                    // Clone the current event, change it and send away the modified            // copy                        ScheduleEvent origin = dayPanel == null ? null : dayPanel.getSelectedEvent();                        if (origin == null ) {                            // This may happen due to ass-backwards initialization                // procedure and interdependencies of ControlPanel and                // DayPanel                                return;            }                        ScheduleEvent clone = new ScheduleEvent(origin);            Object source = e.getSource();                        if ( source == timeUp ) {                            clone.setTime((clone.getTimeAsInt().intValue() + 10) % (60 * 24));                        } else if ( source == timeDown ) {                            clone.setTime((clone.getTimeAsInt().intValue() - 10 + (60 * 24)) % (60 * 24));            } else if ( source == tempUp ) {                            clone.setpoint += 0.5;                            } else if ( source == tempDown ) {                            clone.setpoint -= 0.5;                        } else if ( source == dumpSelector ) {                            clone.dumpPriority = ((JComboBox)source).getSelectedIndex();            }                    sendEventChangeNotification(clone);        }                /**         * Handles "off" and "voting" checkboxes.         */        public void itemStateChanged(ItemEvent e) {                    // Clone the current event, change it and send away the modified            // copy                        ScheduleEvent origin = dayPanel.getSelectedEvent();                        if (origin == null ) {                            // How come?                                return;            }                        ScheduleEvent clone = new ScheduleEvent(origin);                        JCheckBox source = (JCheckBox)e.getSource();            boolean selected = source.isSelected();                        if ( source == offBox ) {                            clone.enabled = !selected;                                tempUp.setEnabled(!selected);                tempDown.setEnabled(!selected);                votingBox.setEnabled(!selected);                dumpSelector.setEnabled(!selected);                        } else if ( source == votingBox ) {                            clone.voting = selected;            }                    sendEventChangeNotification(clone);        }                public void sendEventChangeNotification(ScheduleEvent target) {                    if ( nestingLevel != 0 ) {                            return;            }                    if ( target != null ) {                            listener.scheduleEventChanged(owner, target.toString());            }        }    }        /**     * A renderer for the schedule event.     */    protected class ScheduleItemRenderer extends JPanel implements ListCellRenderer {            private JLabel period;        private JLabel time;        private JLabel temp;                ScheduleItemRenderer() {                    setLayout(new GridLayout());                        period = new JLabel("", JLabel.LEFT);            time = new JLabel("", JLabel.RIGHT);            temp = new JLabel("", JLabel.CENTER);                        add(period);            add(time);            add(temp);                }            public Component getListCellRendererComponent(JList list, Object entry, int index, boolean isSelected, boolean cellHasFocus) {                    ScheduleEvent se = (ScheduleEvent)entry;                        period.setText(se.name);            time.setText(se.time);            temp.setText(se.enabled ? (se.setpoint + "\u00b0C") : "OFF");            period.setFont(list.getFont());            time.setFont(list.getFont());            temp.setFont(list.getFont());                        // Set the colors                        Color displayBg;            Color displayFg;                        if ( isSelected ) {                            displayBg = list.getSelectionBackground();                displayFg = list.getSelectionForeground();                            } else {                            displayBg = list.getBackground();                displayFg = list.getForeground();            }                        // See if we're rendering the current event                        if (    weekPanel.current == weekPanel.selected                 && currentEvent != null                 && se.name.equals(currentEvent.name) ) {                                 displayFg = Color.blue;            }                        setForeground(displayFg);            setBackground(displayBg);            setEnabled(list.isEnabled());                        period.setForeground(displayFg);            period.setBackground(displayBg);            period.setEnabled(list.isEnabled());            time.setForeground(displayFg);            time.setBackground(displayBg);            time.setEnabled(list.isEnabled());                        temp.setForeground(displayFg);            temp.setBackground(displayBg);            temp.setEnabled(list.isEnabled());                        return this;        }        }        /**     * Schedule event description.     */    protected class ScheduleEvent implements Comparable {            /**         * Minimum allowed temperature, C\u00B0.         */        public final double TEMP_MIN = 15;                /**         * Maximum allowed temperature, C\u00B0.         */        public final double TEMP_MAX = 32;                /**         * Day of week, 0 being Sunday.         */        int dayOffset;        /**         * Event name.         */        String name;                /**         * Start time.         */        String time;                /**         * Temperature to hold.         */        double setpoint;        /**         * True if the zone is not shut off.         */        boolean enabled;                /**         * True if the zone is voting.         */        boolean voting;                /**         * Dump priority of the zone in the current period.         */        int dumpPriority;                public ScheduleEvent() {                }                public ScheduleEvent(ScheduleEvent template) {                    this.dayOffset = template.dayOffset;            this.name = template.name;            this.time = template.time;            this.setpoint = template.setpoint;            this.enabled = template.enabled;            this.voting = template.voting;            this.dumpPriority = template.dumpPriority;        }                public int compareTo(Object other) {                    if ( other == null ) {                            throw new IllegalArgumentException("Other can't be null");            }                        if ( !(other instanceof ScheduleEvent) ) {                            throw new IllegalArgumentException("Expected " + getClass().getName() + ", got " + other.getClass().getName());            }                        ScheduleEvent otherEvent = (ScheduleEvent)other;                        int match = getTimeAsInt().compareTo(otherEvent.getTimeAsInt());                        if ( match != 0 ) {                            return match;            }                        return name.compareTo(otherEvent.name);        }                public Integer getTimeAsInt() {                    StringTokenizer st = new StringTokenizer(time, ":");            String hour = st.nextToken();            String minute = st.nextToken();                        return new Integer((Integer.parseInt(hour) * 60) + Integer.parseInt(minute));        }                public void setTime(int value) {                    int minute = value % 60;            int hour = (value - minute) / 60;                    time = "" + hour + ":" + minute;        }                public String toString() {                    String message =         dayName[dayOffset]                             + ":" + name                             + ":" + time                             + ":" + setpoint                             + ":" + (enabled ? "on" : "-")                             + ":" + (voting ? "voting" : "-")                             + ":" + dumpPriority;                                         return message;        }    }}

⌨️ 快捷键说明

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