Browse Source

fixed webcam bug and updated MonitorDesktopTask cause they share some code

main
mainSpi 3 years ago
parent
commit
ab29339aba
  1. 12
      src/main/java/greek/horse/server/ui/controllers/WebcamController.java
  2. 24
      src/main/java/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.java
  3. 26
      src/main/java/greek/horse/server/ui/controllers/tasks/WebcamTask.java
  4. BIN
      target/classes/greek/horse/server/ui/controllers/WebcamController.class
  5. BIN
      target/classes/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.class
  6. BIN
      target/classes/greek/horse/server/ui/controllers/tasks/WebcamTask$1.class
  7. BIN
      target/classes/greek/horse/server/ui/controllers/tasks/WebcamTask.class

12
src/main/java/greek/horse/server/ui/controllers/WebcamController.java

@ -20,12 +20,12 @@ public class WebcamController {
public void configureChoiceBox() { public void configureChoiceBox() {
choiceBox.getSelectionModel().selectFirst(); choiceBox.getSelectionModel().selectFirst();
choiceBox.getSelectionModel().selectedIndexProperty()
.addListener((observableValue, oldIndex, newIndex) -> {
if (oldIndex.intValue() != newIndex.intValue()) {
task.refreshSettings(newIndex.intValue());
}
});
// choiceBox.getSelectionModel().selectedIndexProperty()
// .addListener((observableValue, oldIndex, newIndex) -> {
// if (oldIndex.intValue() != newIndex.intValue()) {
// task.refreshSettings(newIndex.intValue());
// }
// });
} }
public void setImage(BufferedImage screenCapture) { public void setImage(BufferedImage screenCapture) {

24
src/main/java/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.java

@ -79,8 +79,6 @@ public class MonitorDesktopTask implements Runnable {
} }
}); });
loadMonitors();
while (!start.get()) { while (!start.get()) {
try { try {
Thread.sleep(100); Thread.sleep(100);
@ -89,6 +87,8 @@ public class MonitorDesktopTask implements Runnable {
} }
} }
loadMonitors();
startListening(); startListening();
while (this.running.get() && this.plebe.getRunning().get()) { while (this.running.get() && this.plebe.getRunning().get()) {
@ -129,13 +129,7 @@ public class MonitorDesktopTask implements Runnable {
} }
}); });
}
private void startListening() {
double w = stage.getWidth() - 50;
double h = stage.getHeight() - 70;
while(controller.choiceBox.getItems().isEmpty()){
while (controller.choiceBox.getSelectionModel().getSelectedItem() == null){
try { try {
Thread.sleep(20); Thread.sleep(20);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -143,6 +137,12 @@ public class MonitorDesktopTask implements Runnable {
} }
} }
}
private void startListening() {
double w = stage.getWidth() - 50;
double h = stage.getHeight() - 70;
request = plebe.startDesktop(new MonitorDesktopWrapper(w, h, controller.isCompressed(), 0)); request = plebe.startDesktop(new MonitorDesktopWrapper(w, h, controller.isCompressed(), 0));
ObservableList<Object> observableList = request.getObservableReceivedObjs(); ObservableList<Object> observableList = request.getObservableReceivedObjs();
@ -191,9 +191,13 @@ public class MonitorDesktopTask implements Runnable {
} }
public void refreshSettings() { public void refreshSettings() {
int index = controller.choiceBox.getSelectionModel().getSelectedIndex();
if (index<0){
return;
}
double w = stage.getWidth() - 50; double w = stage.getWidth() - 50;
double h = stage.getHeight() - 70; double h = stage.getHeight() - 70;
this.plebe.refreshDesktop(new MonitorDesktopWrapper(w, h, controller.isCompressed(), controller.choiceBox.getSelectionModel().getSelectedIndex()));
this.plebe.refreshDesktop(new MonitorDesktopWrapper(w, h, controller.isCompressed(), index));
} }
public AtomicBoolean getRunning() { public AtomicBoolean getRunning() {

26
src/main/java/greek/horse/server/ui/controllers/tasks/WebcamTask.java

@ -80,8 +80,6 @@ public class WebcamTask implements Runnable {
} }
}); });
loadWebcams();
while (!start.get()) { while (!start.get()) {
try { try {
Thread.sleep(100); Thread.sleep(100);
@ -90,6 +88,8 @@ public class WebcamTask implements Runnable {
} }
} }
loadWebcams();
startListening(); startListening();
while (this.running.get() && this.plebe.getRunning().get()) { while (this.running.get() && this.plebe.getRunning().get()) {
@ -116,14 +116,6 @@ public class WebcamTask implements Runnable {
double w = stage.getWidth() - 50; double w = stage.getWidth() - 50;
double h = stage.getHeight() - 70; double h = stage.getHeight() - 70;
while(controller.choiceBox.getItems().isEmpty()){
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
request = plebe.startWebcam(new WebcamInfoWrapper(w, h, controller.choiceBox.getSelectionModel().getSelectedItem())); request = plebe.startWebcam(new WebcamInfoWrapper(w, h, controller.choiceBox.getSelectionModel().getSelectedItem()));
ObservableList<Object> observableList = request.getObservableReceivedObjs(); ObservableList<Object> observableList = request.getObservableReceivedObjs();
@ -171,11 +163,20 @@ public class WebcamTask implements Runnable {
} catch (Exception e) { } catch (Exception e) {
log.error("Failed to get webcams", e); log.error("Failed to get webcams", e);
this.running.set(false); this.running.set(false);
} finally {
}
finally {
controller.configureChoiceBox(); controller.configureChoiceBox();
} }
}); });
while (controller.choiceBox.getSelectionModel().getSelectedItem() == null){
try {
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} }
public void refreshSettings() { public void refreshSettings() {
@ -183,6 +184,9 @@ public class WebcamTask implements Runnable {
} }
public void refreshSettings(int index) { public void refreshSettings(int index) {
if (index<0){
return;
}
double w = stage.getWidth() - 50; double w = stage.getWidth() - 50;
double h = stage.getHeight() - 70; double h = stage.getHeight() - 70;
this.plebe.refreshWebcam(new WebcamInfoWrapper(w, h, controller.choiceBox.getItems().get(index))); this.plebe.refreshWebcam(new WebcamInfoWrapper(w, h, controller.choiceBox.getItems().get(index)));

BIN
target/classes/greek/horse/server/ui/controllers/WebcamController.class

BIN
target/classes/greek/horse/server/ui/controllers/tasks/MonitorDesktopTask.class

BIN
target/classes/greek/horse/server/ui/controllers/tasks/WebcamTask$1.class

BIN
target/classes/greek/horse/server/ui/controllers/tasks/WebcamTask.class

Loading…
Cancel
Save