这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统

源代码在线查看: mapzonespage.java

软件大小: 1258 K
上传用户: shkk21
关键词: JAVA 编写 程序 温度控制系统
下载地址: 免注册下载 普通下载 VIP

相关代码

				package net.sf.dz.setup.core;								import java.awt.event.ActionEvent;				import java.util.Iterator;				import java.util.LinkedList;				import java.util.List;				import java.util.Map;				import java.util.SortedSet;				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 net.sf.dz.util.wizard.DoubleListPanel;				import net.sf.dz.util.wizard.Wizard;				import net.sf.dz.util.wizard.WizardPage;								class MapZonesPage extends WizardPage {								    private JList zoneList;				    private JList unitList;				    				    private JButton assignButton;				    private JButton detachButton;				    				    private DoubleListPanel dlp;				    				    public MapZonesPage(Logger logger, Wizard owner) {				    				        super(logger, owner, "Map Servos to Temperature Zones");								        List buttonNames = new LinkedList();				        				        buttonNames.add("Assign >>");				        buttonNames.add("				        				        dlp = new DoubleListPanel(getContentPane(), this,				                                  "Temperature Zones",				                                  "Units",				                                  buttonNames);				        				        assignButton = dlp.getButton(0);				        detachButton = dlp.getButton(1);				        				        zoneList = dlp.leftList;				        unitList = dlp.rightList;				        				        zoneList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);				        unitList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);				        				        assignButton.setEnabled(false);				        detachButton.setEnabled(false);				    }								    public void activate() {								        SortedSet zoneSet = getSortedContextValues("zone.");				        SortedSet unitSet = getSortedContextValues("unit.");				        				        // Take care to preserve existing selection, if any				        				        Object selected = null;				        				        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);				        }				        				        if ( unitList.getSelectedIndex() != -1 ) {				        				            selected = unitList.getSelectedValue();				        }				        				        unitList.setListData(new Vector(unitSet));				        				        if ( selected != null ) {				        				            unitList.setSelectedValue(selected, true);								        } else if ( !unitSet.isEmpty() ) {				        				            unitList.setSelectedIndex(0);				        }				        				    }				    				    public String validate() {				    				        UnitDescriptor ud = null;				        ZoneDescriptor zd = null;				        				        // Check which buttons have to be enabled must happen before the				        // validation check, otherwise the buttons will just stay				        // disabled								        if (zoneList.getSelectedIndex() != -1) {				        				            zd =  (ZoneDescriptor)zoneList.getSelectedValue();				        }				        				        if (unitList.getSelectedIndex() != -1) {				        				            ud = (UnitDescriptor)unitList.getSelectedValue();				        }				        				        assignButton.setEnabled(ud != null && zd != null				                             && !ud.zoneSet.contains(zd) && zd.unit == null);				        detachButton.setEnabled(zd != null && zd.unit != null);				        				        // Validation succeeds when there are no unassigned zones, and				        // no units that don't have any zones assigned to them.				        				        Map context = getOwner().getContext();				        				        for ( Iterator i = context.keySet().iterator(); i.hasNext(); ) {				        				            String key = i.next().toString();				            				            if ( key.startsWith("zone.") ) {				            				                zd = (ZoneDescriptor)context.get(key);				                				                if ( zd.unit == null ) {				                				                    return "Some zones (at least'" + zd.name + "') aren't assigned - assign, or delete zone";				                }				            }				        }				        				        for ( Iterator i = context.keySet().iterator(); i.hasNext(); ) {				        				            String key = i.next().toString();				            				            if ( key.startsWith("unit.") ) {				            				                ud = (UnitDescriptor)context.get(key);				                				                if ( ud.zoneSet.isEmpty() ) {				                				                    return "Some units (at least '" + ud.name + "') don't have zones assigned - assign, or delete unit";				                }				            }				        }				        								        return "";				    }				    				    public boolean isEnabled() {				    				        return true;				    }				    				    public String getHelpURL() {				    				        return "FIXME";				    }				    				    public void actionPerformed2(ActionEvent e) {				        				        Object source = e.getSource();				        UnitDescriptor ud = (UnitDescriptor)unitList.getSelectedValue();				        ZoneDescriptor zd = (ZoneDescriptor)zoneList.getSelectedValue();				        				        if ( assignButton == source ) {				        				            ud.zoneSet.add(zd);				            zd.unit = ud;				        				        } else if ( detachButton == source ) {				        				            zd.unit.zoneSet.remove(zd);				            zd.unit = null;				        }				        				        zoneList.validate();				        unitList.validate();				        				        zoneList.repaint();				        unitList.repaint();				    }				    				    public void valueChanged2(ListSelectionEvent e) {				    				    }				}							

相关资源