|
@@ -57,7 +57,7 @@ public class ConnectPhysical implements Algorithm{
|
|
|
|
|
|
private JLabel rotorLabel;
|
|
|
private JLabel houseLabel;
|
|
|
-
|
|
|
+ private boolean onlyOnChange = false;
|
|
|
//
|
|
|
Future<?> future;
|
|
|
private boolean lessInformation = false;
|
|
@@ -93,7 +93,10 @@ public class ConnectPhysical implements Algorithm{
|
|
|
String room2Keyword = "room2";
|
|
|
|
|
|
|
|
|
-
|
|
|
+ //OnChange
|
|
|
+ int oldValueRotor = -1;
|
|
|
+ int oldValueRoom1 = -1;
|
|
|
+ int oldValueRoom2 = -1;
|
|
|
|
|
|
|
|
|
|
|
@@ -157,6 +160,21 @@ public class ConnectPhysical implements Algorithm{
|
|
|
});
|
|
|
parameterPanel.add(lessInformationCheckBox);
|
|
|
|
|
|
+ JLabel onlyOnChangeLabel = new JLabel("OnlyOnChange:");
|
|
|
+ onlyOnChangeLabel.setBounds(200, 240, 200, 20);
|
|
|
+ parameterPanel.add(onlyOnChangeLabel);
|
|
|
+
|
|
|
+
|
|
|
+ JCheckBox onlyOnChangeCheckBox = new JCheckBox();
|
|
|
+ onlyOnChangeCheckBox.setSelected(false);
|
|
|
+ onlyOnChangeCheckBox.setBounds(400, 240, 25, 20);
|
|
|
+ onlyOnChangeCheckBox.addActionListener(actionEvent -> {
|
|
|
+ onlyOnChange = onlyOnChangeCheckBox.isSelected();
|
|
|
+ });
|
|
|
+ parameterPanel.add(onlyOnChangeCheckBox);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
JLabel delayLabel = new JLabel("Delay:");
|
|
|
delayLabel.setBounds(200, 210, 50, 20);
|
|
@@ -167,7 +185,7 @@ public class ConnectPhysical implements Algorithm{
|
|
|
parameterPanel.add(delayUnitLabel);
|
|
|
|
|
|
warningLabel = new JLabel(stringToHtml(stringWithColor("You need to Stop and Run again to affect delay change.", "red")));
|
|
|
- warningLabel.setBounds(200, 240, 400, 20);
|
|
|
+ warningLabel.setBounds(200, 280, 400, 20);
|
|
|
warningLabel.setVisible(false);
|
|
|
parameterPanel.add(warningLabel);
|
|
|
|
|
@@ -296,6 +314,7 @@ public class ConnectPhysical implements Algorithm{
|
|
|
console.println("Starting sending Requests on localhost:2019");
|
|
|
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
|
|
final Runnable beeper = new Runnable() {
|
|
|
+
|
|
|
//RepeatedMethod
|
|
|
public void run() {
|
|
|
if(lessInformation)console.print(".");
|
|
@@ -316,11 +335,28 @@ public class ConnectPhysical implements Algorithm{
|
|
|
return;
|
|
|
}
|
|
|
if(wrapper.hObject.getNumberOfElements() > 0) {
|
|
|
+ //OnlyForRotor
|
|
|
+
|
|
|
int value = Math.round(((float)wrapper.hObject.getNumberOfActiveElements()/(float) wrapper.hObject.getNumberOfElements())*(float) 100);
|
|
|
- sendRequest(wrapper.postAddress, value);
|
|
|
+ if(onlyOnChange) {
|
|
|
+ if(oldValueRotor != value) {
|
|
|
+ sendRequest(wrapper.postAddress, value);
|
|
|
+ oldValueRotor = value;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ sendRequest(wrapper.postAddress, value);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}else {
|
|
|
- sendRequest(wrapper.postAddress, 0);
|
|
|
+ if(onlyOnChange) {
|
|
|
+ if(oldValueRotor != 0) {
|
|
|
+ sendRequest(wrapper.postAddress, 0);
|
|
|
+ oldValueRotor = 0;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ sendRequest(wrapper.postAddress, 0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -351,7 +387,9 @@ public class ConnectPhysical implements Algorithm{
|
|
|
|
|
|
// just want to do an HTTP GET here
|
|
|
connection.setRequestMethod("GET");
|
|
|
- connection.getResponseMessage();
|
|
|
+
|
|
|
+ connection.getResponseCode();
|
|
|
+
|
|
|
// give it 15 seconds to respond
|
|
|
connection.setReadTimeout(1000);
|
|
|
connection.connect();
|
|
@@ -379,18 +417,46 @@ public class ConnectPhysical implements Algorithm{
|
|
|
List<HolonElement> elementsOfRoom2 = house.hObject.getElements().stream().filter(ele -> ele.getEleName().contains(room2Keyword)).collect(Collectors.toList());
|
|
|
|
|
|
if(elementsOfRoom1.isEmpty()){
|
|
|
- sendRequest(room1Address, 0);
|
|
|
+ if(onlyOnChange) {
|
|
|
+ if(oldValueRoom1 != 0) {
|
|
|
+ sendRequest(room1Address, 0);
|
|
|
+ oldValueRoom1 = 0;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ sendRequest(room1Address, 0);
|
|
|
+ }
|
|
|
}
|
|
|
else{
|
|
|
int value = Math.round(((float)elementsOfRoom1.stream().filter(ele -> ele.isActive()).count()/(float) elementsOfRoom1.size())*(float) 100);
|
|
|
- sendRequest(room1Address, value);
|
|
|
+ if(onlyOnChange) {
|
|
|
+ if(oldValueRoom1 != value) {
|
|
|
+ sendRequest(room1Address, value);
|
|
|
+ oldValueRoom1 = value;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ sendRequest(room1Address, value);
|
|
|
+ }
|
|
|
}
|
|
|
if(elementsOfRoom2.isEmpty()){
|
|
|
- sendRequest(room2Address, 0);
|
|
|
+ if(onlyOnChange) {
|
|
|
+ if(oldValueRoom2 != 0) {
|
|
|
+ sendRequest(room2Address, 0);
|
|
|
+ oldValueRoom2 = 0;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ sendRequest(room2Address, 0);
|
|
|
+ }
|
|
|
}
|
|
|
else{
|
|
|
int value = Math.round(((float)elementsOfRoom2.stream().filter(ele -> ele.isActive()).count()/(float) elementsOfRoom2.size())*(float) 100);
|
|
|
- sendRequest(room2Address, value);
|
|
|
+ if(onlyOnChange) {
|
|
|
+ if(oldValueRoom2 != value) {
|
|
|
+ sendRequest(room2Address, value);
|
|
|
+ oldValueRoom2 = value;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ sendRequest(room2Address, value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|