2008年8月3日日曜日

SCADA UIプログラム例のJavaFX SDK対応書き換え:残り

SCADA UIプログラム例の残りの部分を、JavaFX SDK対応に書き換えました。
新たな書き換えの要因として、次のものがあります。
・差分が1と異なる列の指定のしかたが、たとえば、[0,20..100]から[0..100 step 20]のように変わった。
・ConfirmDialogがないので、 javafx.application.Dialogに変えた。

SCADA UI構成単位のJavaFXファイルを置き換えて、企画を再構築して実行すると、図のような画面が表示されます。
次に、
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 newNumericDatum: Number;
attribute numericData: Number[] = for (i in [0..180]) 0.0;
attribute alarting: Boolean;
attribute schedular: Timeline = Timeline{
repeatCount: Timeline.INDEFINITE
keyFrames: KeyFrame {
time: 200ms
action: function(): Void {
newNumericDatum = scc.receiveData();
delete numericData[0];
insert newNumericDatum into numericData;
if (newNumericDatum > 90.0 and not alarting) {
alarting = true;
scc.startAlarm();
Dialog {
title: "Alarm"
width: 300, height: 60
visible: true
closeAction: function() {
scc.stopAlarm();
alarting = false;
}
stage: Stage {
content: Text {
x: 10, y: 10
textOrigin: TextOrigin.TOP
fill: Color.RED
font: Font {size: 14}
content: "Flow rate exceeded the second upper limit!"
}
}
}
}
}
}
}
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.newNumericDatum)
font: Font {
name: "Monospaced", size: 14, style: FontStyle.PLAIN
}
content: bind "{%7.2f sdc.newNumericDatum}"
},
Text {
x: 60, y: 6
textOrigin: TextOrigin.TOP
font: Font {
name: "Monospaced", size: 14, style: FontStyle.PLAIN
}
content: "m3/s"
}
]
},
Group {
translateX: 200, translateY: 50
content: [
Rectangle {
width: 60, height: 120
stroke: Color.BLUE, fill: Color.WHITE
},
Rectangle {
x: 10, y: 10
width: 10, height: 100
fill: LinearGradient {
startX: 0.0, startY: 0.0
endX: 0.0, endY: 1.0
stops: [
Stop {offset: 0.05, color: Color.RED},
Stop {offset: 0.0875, color: Color.color(1.0, 0.6, 0.0)},
Stop {offset: 0.125, color: Color.LIMEGREEN},
]
}
},
Rectangle {
x: 10, y: 10
width: 10, height: bind 50 - sdc.newNumericDatum / 2
fill: Color.BLACK
},
Line {
startX: 23, startY: 10
endX: 23, endY: 110
stroke: Color.BLACK
},
Group {
translateX: 23, translateY: 10
content: for (i in [-100..100 step 50]) Line {
translateY: i / 2 + 50
startX: 0, startY: 0
endX: 3, endY: 0
stroke: Color.BLACK
}
},
Group {
translateX: 32, translateY: 10
content: for (i in [-100..100 step 50]) Text {
translateY: 53 - i / 2
content: "{i}"
font: Font {
name: "Monospaced", size: 10, style: FontStyle.PLAIN
}
horizontalAlignment: HorizontalAlignment.LEADING
verticalAlignment: VerticalAlignment.TOP
}
}
]
},
Group {
translateX: 50, translateY: 200
content: [
Rectangle {
width: 230, height: 120
stroke: Color.BLUE, fill: Color.WHITE
},
Rectangle {
x: 10, y: 22
width: 181, height: 88
fill: Color.BLACK
},
Rectangle {
x: 10, y: 15
width: 181, height: 7
fill: Color.GRAY
},
Rectangle {
x: 10, y: 10
width: 181, height: 5
fill: Color.DARKGRAY
},
Line {
startX: 194, startY: 10
endX: 194, endY: 110
stroke: Color.BLACK
},
Group {
translateX: 194, translateY: 10
content: for (i in [-100..100 step 50]) Line {
translateY: i / 2 + 50
startX: 0, startY: 0
endX: 3, endY: 0
stroke: Color.BLACK
}
},
Group {
translateX: 203, translateY: 11
content: for (i in [-100..100 step 50]) Text {
translateY: 53 - i / 2
content: "{i}"
font: Font {
name: "Monospaced", size: 10, style: FontStyle.PLAIN
}
horizontalAlignment: HorizontalAlignment.LEADING
verticalAlignment: VerticalAlignment.TOP
}
},
Group {
translateX: 10, translateY: 10
content: for (i in [0..179]) Line {
translateX: i
startX: 0, startY: bind 50 - sdc.numericData[i] / 2
endX: 1, endY: bind 50 - sdc.numericData[i + 1] / 2
strokeWidth: 2
stroke: bind sdc.getDisplayColor(sdc.numericData[i + 1])
}
}
]
}
]
}
}

0 件のコメント: