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

📄 configurator.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                resetButton.setEnabled(false);            } else if ( source == resetButton ) {                            textField.setText(name);            }        }    }        /**     * Prevents the name redundancy across the instances with the same meta.     */    protected class UniqueStringAnchor extends StringAnchor {            /**         * Create the instance.         *         * @param meta Meta name.         *         * @param name Node name.         *         * @param helpURL Relative help URL.         */        public UniqueStringAnchor(String meta, String name, String helpURL) {                    super(meta, name, helpURL);                        Set instances = (Set)contentMap.get(getMeta());                        if ( instances == null ) {                            instances = new HashSet();                contentMap.put(getMeta(), instances);            }                        instances.add(this);        }                protected void validate(Document d) {                    // Let's take a shortcut and validate the text instead                        if ( name.equals(currentText.trim()) ) {                            commitButton.setEnabled(false);                resetButton.setEnabled(false);                return;            } else {                            resetButton.setEnabled(true);            }                        synchronized ( contentMap ) {                            Set instances = (Set)contentMap.get(getMeta());                                for ( Iterator i = instances.iterator(); i.hasNext(); ) {                                    UniqueStringAnchor usa = (UniqueStringAnchor)i.next();                                        if ( usa == this ) {                                            continue;                    }                                        if ( currentText.trim().equals(usa.currentText) ) {                                            try {                                                        Document errorDoc = error.getDocument();                            String message = "Duplicate " + getMeta() + " name: '" + currentText + "' - duplicates not allowed\n";                            errorDoc.insertString(errorDoc.getLength(), message, null);                                                        commitButton.setEnabled(false);                            return;                                            } catch ( Throwable t ) {                                                    // There's not much to do about it, if it's                            // broken, it's broken                                                        t.printStackTrace();                        }                    }                }                commitButton.setEnabled(true);                                        // VT: FIXME: clear the error area            }        }    }        /**     * An anchor class that supports the one-of-many choice selection.     */    abstract protected class ChoiceAnchor extends NodeAnchor {            protected JComboBox choiceBox;                /**         * Create the instance.         *         * @param meta Meta name.         *         * @param name Node name.         *         * @param helpURL Relative help URL.         */        public ChoiceAnchor(String meta, String name, String helpURL) {                    super(meta, name, helpURL);                        choiceBox = new JComboBox(getContent());            choiceBox.addActionListener(this);                        content.add(choiceBox);        }                /**         * Provide the content array to populate the combo box with.         */        abstract protected Object[] getContent();                public void actionPerformed(ActionEvent e) {                    // VT: NOTE: This doesn't implement the reset - "worse is            // better". Reset is an overcomplication here.                    Object source = e.getSource();            String selected = choiceBox.getSelectedItem().toString();                        if ( source == choiceBox ) {                            if ( selected.equals(name) ) {                                    commitButton.setEnabled(false);                } else {                                    commitButton.setEnabled(true);                }            } else if ( source == commitButton ) {                            renameNode(selected);                commitButton.setEnabled(false);            }        }    }         /**     * An anchor class that supports selecting the Java class name.     *     * This one is a little bit more complicated that the superclasses - the     * class names populating the drop down have to be looked up and     * introspected for conformance to a given interface.     *     * <p>     *     * VT: FIXME: The hell with the introspection for the moment. According     * to "worse is better", the class names suitable for the context will     * be looked up in the configuration instead, and the introspection will     * be implemented later, if it turns out to be desirable.     */    protected class ClassAnchor extends ChoiceAnchor {            /**         * The interface class name.         *         * VT: FIXME: Today, this is a configuration path to the list of the class names.         */        protected String interfaceClass;                /**         * Create the instance.         *         * @param name Node name.         *         * @param helpURL Relative help URL.         *         * @param interfaceClass The class name of the interface that         * defines the classes populating the drop down.         *         * VT: FIXME: For now, <code>interfaceClass</code> will contain the         * configuration root for the list of the suitable class names.         */        public ClassAnchor(String name, String helpURL, String interfaceClass) {                    super("Class", name, helpURL);                        this.interfaceClass = interfaceClass;                        List classNameList = getConfiguration().getList(interfaceClass);                        for ( Iterator i = classNameList.iterator(); i.hasNext(); ) {                            choiceBox.addItem(i.next());            }                    }                protected Object[] getContent() {                    // VT: NOTE: It is not possible to load the list at this time -            // the interface name is not known yet                        return new Object[0];        }    }        protected class DumpPriorityAnchor extends ChoiceAnchor {            public DumpPriorityAnchor(String meta, String name, String helpURL) {                    super(meta, name, helpURL);        }                protected Object[] getContent() {                        Object list[] = {                            "0",                "1",                "2",                "3",                "4",                "5"            };                        return list;        }    }        protected class HouseAnchor extends StringAnchor {            private JButton addUnitButton;                public HouseAnchor(String name) {                    super("House", name, "house.html");                        addUnitButton = new JButton("Add Unit");            addUnitButton.addActionListener(this);                        layout.setConstraints(addUnitButton, cs);            display.add(addUnitButton);        }                public int getExtraButtonCount() {                    // "add unit"                        return 1;        }                public void actionPerformed(ActionEvent e) {                    Object source = e.getSource();                        if ( source == addUnitButton ) {                            createNewUnit();            } else {                            super.actionPerformed(e);            }        }    }    protected class UnitAnchor extends UniqueStringAnchor {            protected JButton removeButton;        protected JButton addZoneButton;                public UnitAnchor(String name) {                    super("Unit", name, "unit.html");            removeButton = new JButton("Remove Unit");            removeButton.addActionListener(this);                        layout.setConstraints(removeButton, cs);            display.add(removeButton);                        cs.gridx++;                        addZoneButton = new JButton("Add Zone");            addZoneButton.addActionListener(this);                        layout.setConstraints(addZoneButton, cs);            display.add(addZoneButton);                    }        public int getExtraButtonCount() {                    // "remove unit"            // "add zone"                        return 2;        }                public void actionPerformed(ActionEvent e) {                    Object source = e.getSource();                        if ( source == removeButton ) {                            //            } else if ( source == addZoneButton ) {                            createNewZone(name);                        } else {                            super.actionPerformed(e);            }        }    }    protected class ZoneAnchor extends UniqueStringAnchor {            protected JButton removeButton;            public ZoneAnchor(String name) {                    super("Zone", name, "zone.html");            removeButton = new JButton("Remove Zone");            removeButton.addActionListener(this);                        layout.setConstraints(removeButton, cs);            display.add(removeButton);        }        public int getExtraButtonCount() {                    // "remove this"                        return 1;        }                public void actionPerformed(ActionEvent e) {                    Object source = e.getSource();                        if ( source == removeButton ) {                            //            } else {                            super.actionPerformed(e);            }        }    }        protected class ImmutableAnchor extends NodeAnchor {            public ImmutableAnchor(String meta, String helpURL) {                    super(meta, null, helpURL);        }                protected boolean isConfigurable() {                    return false;        }    }        }

⌨️ 快捷键说明

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