次に、SCADA UIプログラムの例を、JavaFX SDK対応に書き換えてみます。今回は、数値指示計の部分を書き換えました。
逐次解釈型では、Textオブジェクトで「%m.nf」形式の書式付き出力を行うと、頭の空白文字が無視されという不備な点がありましたが、それは修正されています。
NetBeansで、JavaFX企画を作成し、SCADA UI構成単位のJavaFXファイルと依頼機を模擬する制御構成単位のJavaファイルを作成し、警報音源ファイルを置いて、企画を構築して実行すると、図のような数値指示計の画面が表示されます。
次に、SCADA UI構成単位のJavaFXファイルを示します。
/*
* ScadaClientUI.fx
* An example of a User Interface (UI) module of the client-side Presentation
* component for a SCADA application.
*
* Created and modified:
* V 1.0.0 2008/08/01
*/
package client;
import javafx.animation.*;
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.geometry.*;
import javafx.scene.paint.*;
import javafx.scene.text.*;
import java.lang.System;
import client.ScadaClientControl;
/**
* @author terra
*/
var scc: ScadaClientControl = new ScadaClientControl();
/*
* A control compenent for SCADA Data in the UI module.
*/
class ScadaDataControl {
attribute numericData: Number;
attribute schedular: Timeline = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame {
time: 200ms
action: function(): Void {
numericData = scc.receiveData();
}
}
}
function getDisplayColor(value: Number): Color {
var c: Color = Color.GREEN;
if (value > 90.0) {
c = Color.RED;
} else if (value > 75.0) {
c = Color.color(1.0, 0.6, 0.0);
}
return c;
}
}
var sdc = ScadaDataControl {};
sdc.schedular.start();
Frame {
title: "SCADA UI Example"
width: 800, height: 632
visible: true
closeAction: function(): Void {System.exit(0);}
stage: Stage {
width: 800, height: 600
fill: Color.color(0.9, 0.9, 0.9)
content: [
Group {
translateX: 50, translateY: 50
content: [
Rectangle {
width: 55, height: 18
arcWidth: 4, arcHeight: 4
stroke: Color.BLUE, fill: Color.WHITE
},
Text {
x: 4, y: 5
textOrigin: TextOrigin.TOP
fill: bind sdc.getDisplayColor(sdc.numericData)
font: Font {name: "Monospaced", size: 14, style: FontStyle.PLAIN}
content: bind "{%7.2f sdc.numericData}"
},
Text {
x: 60, y: 6
textOrigin: TextOrigin.TOP
font: Font {name: "Monospaced", size: 14, style: FontStyle.PLAIN}
content: "m3/s"
}
]
}
]
}
}
また、模擬依頼機制御構成単位のJavaファイルを示します。
/*
* ScadaClientControl.java
* An example of the client-side Control component for a SCADA application.
*
* Created and modified:
* V 1.0.0 2008/07/31
*/
package client;
import java.applet.Applet;
import java.applet.AudioClip;
import javax.swing.JOptionPane;
/**
* @author terra
*/
public class ScadaClientControl {
private AudioClip ac = Applet.newAudioClip(
ScadaClientControl.class.getResource("ALERT.WAV"));
private int i = -1;
/**
* Create and return pseudo SCADA data as if received from a server.
*/
public double receiveData() {
i += 1;
if (i >= 360) {
i = 0;
}
return (double) Math.sin(i * Math.PI / 180) * 100;
}
/**
* Start sounding the alarm.
*/
public void startAlarm() {
ac.loop();
}
/**
* Stop sounding the alarm.
*/
public void stopAlarm() {
ac.stop();
}
/**
* Main method for testing this class.
*
* @param args the command line arguments
*/
public static void main(String[] args) {
ScadaClientControl scc = new ScadaClientControl();
for (int i = 0; i < 5; i++) {
System.out.println(scc.receiveData());
}
scc.startAlarm();
JOptionPane.showMessageDialog(null, "Alarm is sounding!", "Alarm test",
JOptionPane.WARNING_MESSAGE);
scc.stopAlarm();
}
}
0 件のコメント:
コメントを投稿