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

📄 schedulepanel.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    }                }            }        }    }        private void setCurrent(ScheduleEvent currentEvent) throws Throwable {            this.currentEvent = currentEvent;        weekPanel.setCurrentDay(currentEvent.dayOffset);        weekPanel.setSelectedDay(currentEvent.dayOffset);    }        /**     * Process the event list selection status change.     *     * If there is a selection, {@link #controlPanel control panel} is     * enabled, otherwise it is disabled.     */    public void valueChanged(ListSelectionEvent e) {            if ( e.getValueIsAdjusting() ) {                    // This prevents double triggering                    return;        }            JList source = (JList)e.getSource();        int index = source.getSelectedIndex();                if ( index == -1 ) {                    // There are no selected items at all                        controlPanel.setEnabled(false);            return;        }                ScheduleEvent se = (ScheduleEvent)source.getSelectedValue();                controlPanel.enable(se);    }        private Vector set2vector(SortedSet source) {            return new Vector(source);    }        public void setEnabled(boolean enabled) {            this.enabled = enabled;                weekPanel.setEnabled(enabled);        dayPanel.setEnabled(enabled);                // Not so fast - this one is enabled only if there's a non-null        // selection in dayPanel                controlPanel.setEnabled(enabled && dayPanel.list.getSelectedIndex() != -1);    }        /**     * Weekday list panel.     *     * Displays the list of days of week and allows to select a day to     * display on the {@link #dayPanel day panel}.     *     * <p>     *     * Current day is displayed in blue text. Selected day is displayed with     * raised border around the day name.     */    protected class WeekPanel extends JPanel implements MouseListener {            private GridBagLayout layout;        private GridBagConstraints cs;        private JLabel dayList[] = new JLabel[7];                int selected = 0;        int current = -1;        boolean enabled = true;                public WeekPanel() {                    System.err.println("FIXME: subclass JLabel to fixed width");                    setBorder(BorderFactory.createLoweredBevelBorder());                    layout = new GridBagLayout();            cs = new GridBagConstraints();                        setLayout(layout);                        cs.fill = GridBagConstraints.HORIZONTAL;            cs.gridx = 0;            cs.gridy = 0;            cs.gridwidth = 1;            cs.weightx = 1;            cs.weighty = 0;                        for ( int day = 0; day < 7; day++ ) {                            JLabel b = new JLabel(dayName[day], JLabel.CENTER);                                // VT: FIXME: Suppose, the button foreground color is black.                // This is not always right, but let's just remember to fix                // it later - it'll work for majority of the cases.                                b.addMouseListener(this);                //b.setFont(smallFont);                b.setToolTipText("Click to view " + longDayName[day] + " schedule");                                dayList[day] = b;                layout.setConstraints(b, cs);                add(b);                cs.gridx++;            }                        dayList[selected].setBorder(BorderFactory.createRaisedBevelBorder());                        if ( current != -1 ) {                            dayList[current].setForeground(Color.blue);            }        }                /**         * Set the day to select.         *         * @param day Day to select, 0 being Sunday.         */        public synchronized void setSelectedDay(int day) {                    if ( day < 0 || day > 6 ) {                            throw new IllegalArgumentException("Illegal day: " + day);            }                        if ( day == selected ) {                            //return;            }                        dayList[selected].setBorder(BorderFactory.createEmptyBorder());                        dayList[day].setBorder(BorderFactory.createRaisedBevelBorder());                        selected = day;                        // Retrieve the day panel selection, if any                        Object eventObject = dayPanel.list.getSelectedValue();            String eventName = null;            if ( eventObject != null ) {                            eventName = ((ScheduleEvent)eventObject).name;            }                        // Set the new list data                        dayPanel.list.setListData(set2vector(eventSet[day]));                        // Restore the selection, if it was there. Obviously, it will be            // restored only if there's an event with the same name.                        if ( eventName != null ) {                            SortedSet events = eventSet[day];                            for ( Iterator i = events.iterator(); i.hasNext(); ) {                                    ScheduleEvent e = (ScheduleEvent)i.next();                                        if ( eventName.equals(e.name) ) {                                            dayPanel.list.setSelectedValue(e, true);                        break;                    }                }            }        }                /**         * Get the selected day.         *         * @return Index of the selected day, 0 being Sunday.         */        public synchronized int getSelectedDay() {                    return selected;        }                /**         * Set the day to display as current.         *         * @param day Day to highlight, 0 being Sunday.         */        public synchronized void setCurrentDay(int day) {                    if ( day < 0 || day > 6 ) {                            throw new IllegalArgumentException("Illegal day: " + day);            }                        if ( day == current ) {                            //return;            }                        if ( current != -1 ) {                            dayList[current].setForeground(Color.black);            }                        dayList[day].setForeground(Color.blue);                        current = day;        }                public void mouseClicked(MouseEvent e) {                }        public void mouseEntered(MouseEvent e) {                }        public void mouseExited(MouseEvent e) {                }        public void mousePressed(MouseEvent e) {                    if ( !enabled ) {                            return;            }                    Object source = e.getSource();                        for ( int day = 0; day < 7; day++ ) {                            if ( dayList[day] == source ) {                                    setSelectedDay(day);                    return;                }            }        }        public void mouseReleased(MouseEvent e) {                }                public void setEnabled(boolean enabled) {                    this.enabled = enabled;                        for ( int offset = 0; offset < dayList.length; offset++ ) {                            dayList[offset].setEnabled(enabled);            }        }    }    /**     * Panel displaying the event list for the day.     *     * <p>     *     * Current event is displayed in blue text. Selected event is displayed     * with a default list selection color background.     */    protected class DayPanel extends JPanel {            private GridBagLayout layout;        private GridBagConstraints cs;                JList list;                public DayPanel() {                    setBorder(BorderFactory.createLoweredBevelBorder());                    layout = new GridBagLayout();            cs = new GridBagConstraints();                        setLayout(layout);                        cs.fill = GridBagConstraints.BOTH;            cs.gridx = 0;            cs.gridy = 0;            cs.gridwidth = 1;            cs.weightx = 1;            cs.weighty = 1;                        JScrollPane sp = new JScrollPane();                        list = new JList(set2vector(eventSet[0]));            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);            list.setCellRenderer(new ScheduleItemRenderer());            list.setToolTipText("Select period to edit");                        // Make the size consistent with the week panel size                        JLabel l = new JLabel("XX");            Dimension d = l.getPreferredSize();                        sp.setMinimumSize(new Dimension(d.width * 12, d.height * 4));            sp.setPreferredSize(new Dimension(d.width * 12, d.height * 4));            sp.getViewport().setView(list);                        layout.setConstraints(sp, cs);            add(sp);        }        public ScheduleEvent getSelectedEvent() {                    return (ScheduleEvent)list.getSelectedValue();        }                public void setEnabled(boolean enabled) {                    list.setEnabled(enabled);        }    }        /**     * Controls for the schedule panel.     *     * Allow to modify the selected day/event's start time, setpoint,     * whether it is disabled and/or voting, and dump priority.     */    protected class ControlPanel extends JPanel implements ActionListener, ItemListener {            private GridBagLayout layout;        private GridBagConstraints cs;                private final String[] dumpValues = { "Off", "High", "Medium", "Low" };                private JButton timeUp = new JButton(">>");        private JButton timeDown = new JButton("<<");        private JButton tempUp = new JButton("+");        private JButton tempDown = new JButton("-");        private JCheckBox offBox = new JCheckBox("Off");        private JCheckBox votingBox = new JCheckBox("Voting");        private JComboBox dumpSelector = new JComboBox(dumpValues);                private SchedulePanel owner;        public ControlPanel(SchedulePanel owner) {                    this.owner = owner;                    timeUp.addActionListener(this);            timeDown.addActionListener(this);            tempUp.addActionListener(this);            tempDown.addActionListener(this);            offBox.addItemListener(this);            votingBox.addItemListener(this);            dumpSelector.addActionListener(this);                    timeUp.setFont(smallFont);            timeDown.setFont(smallFont);            tempUp.setFont(smallFont);            tempDown.setFont(smallFont);            offBox.setFont(smallFont);            votingBox.setFont(smallFont);            dumpSelector.setFont(smallFont);            timeUp.setToolTipText("10 min forward");            timeDown.setToolTipText("10 min back");            tempUp.setToolTipText("Warmer");            tempDown.setToolTipText("Cooler");            offBox.setToolTipText("Is zone disabled?");            votingBox.setToolTipText("Is zone voting?");            dumpSelector.setToolTipText("Dump priority");                    setBorder(BorderFactory.createLoweredBevelBorder());                    layout = new GridBagLayout();            cs = new GridBagConstraints();                        setLayout(layout);                        cs.fill = GridBagConstraints.BOTH;            cs.gridx = 0;            cs.gridy = 0;            cs.gridwidth = 1;            cs.weightx = 0;            cs.weighty = 1;                        layout.setConstraints(timeUp, cs);            add(timeUp);

⌨️ 快捷键说明

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