parent
edfd4faa0a
commit
09f8b96d7c
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import javafx.scene.text.Text?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
|
||||
<SplitPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="View.ImageSensorController"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
<items>
|
||||
<Text fx:id="temp"/>
|
||||
<ImageView fx:id="img" fitHeight="200" fitWidth="350"/>
|
||||
</items>
|
||||
|
||||
</SplitPane>
|
After Width: | Height: | Size: 668 KiB |
After Width: | Height: | Size: 1.6 MiB |
After Width: | Height: | Size: 2.0 MiB |
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
|
||||
<?import javafx.scene.text.Text?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
|
||||
<SplitPane dividerPositions="0.3"
|
||||
xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
prefWidth="550" prefHeight="350">
|
||||
<items>
|
||||
<Text fx:id="temperature"/>
|
||||
<ImageView fx:id="image" fitHeight="350" fitWidth="500"/>
|
||||
</items>
|
||||
</SplitPane>
|
@ -0,0 +1,43 @@
|
||||
package Launcher;
|
||||
|
||||
import Model.ImageSensor;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import Model.Sensor;
|
||||
import View.ImageSensorController;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Launch extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
ImageSensor imgSens = new ImageSensor(1,"ImageSensor");
|
||||
|
||||
Thread t = new Thread(()->{
|
||||
while (true){
|
||||
try{
|
||||
Thread.sleep(1000);
|
||||
Platform.runLater(()-> {
|
||||
try{
|
||||
imgSens.getTemperature();
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
}catch (InterruptedException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
Application.launch(args);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package Model;
|
||||
|
||||
public interface IGenStrategy {
|
||||
abstract int generate();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package Model;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class ImageSensor extends SimpleSensor{
|
||||
|
||||
private final ObjectProperty<Image> image = new SimpleObjectProperty<>();
|
||||
public ObjectProperty<Image> getImage(){return image;}
|
||||
public void setImage(Image image){this.image.set(image);}
|
||||
public ImageSensor(float t, String n) {
|
||||
super(t, n, new RandomGenerator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genTemp(){
|
||||
setTemperature(15);
|
||||
if(getTemperature()<0){
|
||||
setImage(new Image("/Img/snow-1674382959288-6329.jpg"));
|
||||
}else if(getTemperature()>0 && getTemperature()<20){
|
||||
setImage(new Image("/Img/Warm-Green-Landscape-Mountains-Wallpaper-1920x1200-1387564693.jpg"));
|
||||
}else {
|
||||
setImage(new Image("/Img/videoblocks-panoramic-view-sand-dunes-and-hills-in-hot-desert-wilderness-desert-landscape_h0eyeniim_thumbnail-1080_01.png"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package Model;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomGenerator implements IGenStrategy{
|
||||
@Override
|
||||
public int generate() {
|
||||
Random rand = new Random();
|
||||
return rand.nextInt(50);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package Model;
|
||||
|
||||
import javafx.beans.property.FloatProperty;
|
||||
import javafx.beans.property.SimpleFloatProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class Sensor {
|
||||
private final FloatProperty temperature = new SimpleFloatProperty();
|
||||
public float getTemperature() {return temperature.get();}
|
||||
public FloatProperty temperatureProperty() {return temperature;}
|
||||
public void setTemperature(float temperature) {this.temperature.set(temperature);}
|
||||
private final StringProperty name = new SimpleStringProperty();
|
||||
public String getName() {return name.get();}
|
||||
public StringProperty nameProperty() {return name;}
|
||||
public void setName(String name) {this.name.set(name);}
|
||||
private final StringProperty id = new SimpleStringProperty(UUID.randomUUID().toString());
|
||||
public String getId() {return id.get();}
|
||||
public StringProperty idProperty() {return id;}
|
||||
public void setId(String id) {this.id.set(id);}
|
||||
|
||||
public Sensor(float t,String n){
|
||||
this.temperature.set(t);
|
||||
this.name.set(n);
|
||||
}
|
||||
|
||||
public abstract void genTemp();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package Model;
|
||||
|
||||
public class SimpleSensor extends Sensor{
|
||||
private IGenStrategy gen;
|
||||
|
||||
public SimpleSensor(float t, String n,IGenStrategy genStrat) {
|
||||
super(t, n);
|
||||
this.gen = genStrat;
|
||||
}
|
||||
|
||||
private void setStrategy(IGenStrategy g){
|
||||
gen = g;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genTemp() {
|
||||
setTemperature(gen.generate());
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package View;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FXMLWindow extends Stage {
|
||||
public FXMLWindow(String title,String url)throws IOException{
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource(url));
|
||||
fxmlLoader.setController(this);
|
||||
Parent group = fxmlLoader.load();
|
||||
this.setScene(new Scene(group));
|
||||
this.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package View;
|
||||
|
||||
import Model.ImageSensor;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.converter.NumberStringConverter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImageSensorController extends FXMLWindow{
|
||||
|
||||
@FXML
|
||||
private Text temp;
|
||||
|
||||
@FXML
|
||||
private ImageView img;
|
||||
|
||||
public ImageSensorController(ImageSensor sens,String title, String url) throws IOException {
|
||||
super(title, url);
|
||||
temp.textProperty().bindBidirectional(sens.temperatureProperty(),new NumberStringConverter());
|
||||
img.imageProperty().bindBidirectional(sens.getImage());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue