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

📄 mapservospage.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
字号:
package net.sf.dz.setup.core;import java.awt.event.ActionEvent;import java.io.IOException;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.SortedSet;import java.util.TreeMap;import java.util.TreeSet;import java.util.Vector;import javax.swing.JButton;import javax.swing.JList;import javax.swing.ListSelectionModel;import javax.swing.event.ListSelectionEvent;import org.freehold.jukebox.logger.Logger;import org.freehold.servomaster.device.model.Servo;import org.freehold.servomaster.device.model.ServoController;import net.sf.dz.util.wizard.DoubleListPanel;import net.sf.dz.util.wizard.Wizard;import net.sf.dz.util.wizard.WizardPage;class MapServosPage extends WizardPage {    private JList servoList;    private JList zoneList;        private JButton assignButton;    private JButton detachButton;    private JButton testButton;        private DoubleListPanel dlp;        public MapServosPage(Logger logger, Wizard owner) {            super(logger, owner, "Map Servos to Temperature Zones");        List buttonNames = new LinkedList();                buttonNames.add("Assign >>");        buttonNames.add("<< Detach");        buttonNames.add("<separator>");        buttonNames.add("< Test");                dlp = new DoubleListPanel(getContentPane(), this,                                  "Servos",                                  "Temperature Zones",                                  buttonNames);                assignButton = dlp.getButton(0);        detachButton = dlp.getButton(1);        testButton = dlp.getButton(2);                servoList = dlp.leftList;        zoneList = dlp.rightList;                servoList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        zoneList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);                assignButton.setEnabled(false);        detachButton.setEnabled(false);    }    public void activate() {        SortedSet servoSet = getSortedContextValues("servo.");        SortedSet zoneSet = getSortedContextValues("zone.");                // Take care to preserve existing selection, if any                Object selected = null;                if ( servoList.getSelectedIndex() != -1 ) {                    selected = servoList.getSelectedValue();        }                servoList.setListData(new Vector(servoSet));                if ( selected != null ) {                    servoList.setSelectedValue(selected, true);        } else if ( !servoSet.isEmpty() ) {                    servoList.setSelectedIndex(0);        }                if ( zoneList.getSelectedIndex() != -1 ) {                    selected = zoneList.getSelectedValue();        }                zoneList.setListData(new Vector(zoneSet));                if ( selected != null ) {                    zoneList.setSelectedValue(selected, true);        } else if ( !zoneSet.isEmpty() ) {                    zoneList.setSelectedIndex(0);        }            }        public String validate() {            if ( !isVisible() ) {                    return "";        }            ServoDescriptor sd = null;        ZoneDescriptor zd = null;        if (servoList.getSelectedIndex() != -1) {                    sd =  (ServoDescriptor)servoList.getSelectedValue();        }                if (zoneList.getSelectedIndex() != -1) {                    zd = (ZoneDescriptor)zoneList.getSelectedValue();        }                assignButton.setEnabled(sd != null && zd != null                             && sd.zone == null && zd.servo == null);        detachButton.setEnabled(zd != null && zd.servo != null);        testButton.setEnabled(sd != null);        return "";    }        public boolean isEnabled() {            return true;    }        public String getHelpURL() {            return "FIXME";    }        public void actionPerformed2(ActionEvent e) {                Object source = e.getSource();        ServoDescriptor sd = (ServoDescriptor)servoList.getSelectedValue();        ZoneDescriptor zd = (ZoneDescriptor)zoneList.getSelectedValue();                if ( assignButton == source ) {                    sd.zone = zd;            zd.servo = sd;                } else if ( detachButton == source ) {                    zd.servo.zone = null;            zd.servo = null;        } else if ( testButton == source ) {                    try {                            sd.servo.setPosition(0);                Thread.sleep(800);                sd.servo.setPosition(1);                Thread.sleep(800);                sd.servo.setPosition(0.5);                            } catch ( Throwable t ) {                            complain(LOG_ERR, CH_WP, "Failed to test servo:", t);            }        }                servoList.validate();        zoneList.validate();                servoList.repaint();        zoneList.repaint();        }        public void valueChanged2(ListSelectionEvent e) {        }}

⌨️ 快捷键说明

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