zonepanel.java
来自「这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统」· Java 代码 · 共 563 行 · 第 1/2 页
JAVA
563 行
controllerLegend.add("D"); Map controllerColorMap = new HashMap(); controllerColorMap.put("Error", Color.red); controllerColorMap.put("Signal", Color.yellow); controllerColorMap.put("P", Color.green); controllerColorMap.put("I", Color.blue); controllerColorMap.put("D", Color.cyan); controllerChart.setLegend(controllerLegend); controllerChart.setChartColors(controllerColorMap); controllerChart.setBorder(BorderFactory.createTitledBorder("Controller")); cs.gridx++; layout.setConstraints(controllerChart, cs); panel.add(controllerChart); cs.gridx++; damperChart = new Chart(); damperChart.setBackground(Color.black); damperChart.setGridColor(Color.darkGray); List damperLegend = new LinkedList(); damperLegend.add("Requested"); damperLegend.add("Actual"); Map damperColorMap = new HashMap(); damperColorMap.put("Requested", Color.red); damperColorMap.put("Actual", Color.green); damperChart.setLegend(damperLegend); damperChart.setChartColors(damperColorMap); damperChart.setBorder(BorderFactory.createTitledBorder("Damper")); layout.setConstraints(damperChart, cs); panel.add(damperChart); cs.gridx++; schedulePanel = new SchedulePanel(this); layout.setConstraints(schedulePanel, cs); panel.add(schedulePanel); // Fix the charts' height Dimension d3 = schedulePanel.getPreferredSize(); Dimension d4 = new Dimension(currentLabel.getPreferredSize().width, d3.height); controllerChart.setPreferredSize(d4); damperChart.setPreferredSize(d4); // VT: FIXME: Check the preferences and make invisible the elements // that are not enabled } public void parse(StringTokenizer st) throws Throwable { String target = st.nextToken(); String op = st.nextToken(); // Just in case boolean onHold = holdBox.isSelected(); boolean disabled = disableBox.isSelected(); boolean voting = votingBox.isSelected(); if ( "temperature".equals(target) ) { try { // VT: NOTE: You may want to use Round.round3() for // debugging currentLabel.setText("" + Round.round1(Double.parseDouble(op)) + "\u00b0"); // VT: FIXME: This may not be right if the color scheme is not default currentLabel.setForeground(Color.black); // VT: FIXME: set the proper colors } catch ( NumberFormatException nfex ) { // This must be a problem with the sensor if ( op.startsWith("E") ) { // Mark the sensor panel as non-functional currentLabel.setText("FAULT"); // VT: FIXME: This may not be right if the color scheme is not default currentLabel.setForeground(Color.red); } } return; } else if ( "hold".equals(target) ) { boolean state = "true".equals(op); if ( state != onHold ) { holdBox.setSelected(state); } } else if ( "on".equals(target) ) { boolean state = !("true".equals(op)); if ( state != disabled ) { disableBox.setSelected(state); } // VT: NOTE: At startup, state may coincide with the signal, and // color will not be set properly. So I'll just set the color // right in any case. renderEnabled(!state); } else if ( "voting".equals(target) ) { boolean state = ("true".equals(op)); if ( state != disabled ) { votingBox.setSelected(state); } } else if ( "controller".equals(target) ) { if ( "status".equals(op) ) { String setpointToken = st.nextToken(); String statusToken = st.nextToken(); double setpoint = Double.parseDouble(setpointToken); handleSetpointNotification(setpoint); // The controller status is a sequence of slash delimited // numbers StringTokenizer cst = new StringTokenizer(statusToken, "/"); for ( int idx = 0; cst.hasMoreTokens(); idx++ ) { String value = cst.nextToken(); controllerChart.record((String)controllerLegend.get(idx), System.currentTimeMillis(), Double.parseDouble(value)); } } } else if ( "damper".equals(target) ) { if ( "status".equals(op) ) { String status = st.nextToken(); // The damper status is a sequence of slash delimited // numbers StringTokenizer cst = new StringTokenizer(status, "/"); long now = System.currentTimeMillis(); damperChart.record("Requested", now, Double.parseDouble(cst.nextToken())); damperChart.record("Actual", now, Double.parseDouble(cst.nextToken())); } else { throw new IllegalArgumentException("Unsupported damper message '" + op + "'"); } } else if ( "schedule".equals(target) ) { schedulePanel.parse(op, st); } else { throw new IllegalArgumentException("Unsupported target: '" + target + "'"); } } private boolean inSetpointNotification = false; private void handleSetpointNotification(double setpoint) { inSetpointNotification = true; setpointSpinner.setValue(new Double(setpoint)); inSetpointNotification = false; } public void itemStateChanged(ItemEvent e) { JCheckBox source = (JCheckBox)e.getSource(); boolean state = source.isSelected(); if ( source == disableBox ) { unitPanel.send(prefix + "on:" + !state); renderEnabled(!state); } else if ( source == holdBox ) { unitPanel.send(prefix + "hold:" + state); } else if ( source == votingBox ) { unitPanel.send(prefix + "voting:" + state); } } /** * React to the spinner event. * * @param e The spinner event. We don't listen to anything else. */ public void stateChanged(ChangeEvent e) { Object source = e.getSource(); if ( source == setpointSpinner ) { if ( inSetpointNotification ) { // Ignore it, dear, it came from the wire... return; } double setpoint = ((Double)((JSpinner)source).getValue()).doubleValue(); unitPanel.send(prefix + "controller:setpoint:" + setpoint); } } /** * Decide whether to render controls normal or grayed out. * * The only control that is not affected is 'hold' - in case one will * want to choose whether to keep the zone disabled just for the current * period or indefinitely. * * @param enabled If true, the controls look normal, otherwise grayed * out. */ private void renderEnabled(boolean enabled) { votingBox.setEnabled(enabled); setpointSpinner.setEnabled(enabled); // VT: FIXME: This may not be right if the color scheme is not default disableBox.setForeground(enabled ? Color.black : Color.red); } public void scheduleEventChanged(SchedulePanel source, String renderCommand) { unitPanel.send(prefix + "schedule:event:" + renderCommand); } public void setPConGraph(boolean enabled) { controllerChart.setVisible(enabled); } public void setDamperGraph(boolean enabled) { damperChart.setVisible(enabled); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?