diff --git a/pom.xml b/pom.xml index c46e753..ca1dadc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.selfomat selfomat-single-user - 0.4.1.1-SNAPSHOT + 0.4.1.2-SNAPSHOT scm:git:http://192.168.100.78/git/selfomat-software.git diff --git a/src/main/java/GUI/PictureCtl.java b/src/main/java/GUI/PictureCtl.java index 08e5b01..e023a04 100644 --- a/src/main/java/GUI/PictureCtl.java +++ b/src/main/java/GUI/PictureCtl.java @@ -11,6 +11,7 @@ import javafx.scene.input.MouseEvent; import javafx.scene.input.TouchEvent; import javafx.scene.layout.GridPane; import javafx.scene.layout.StackPane; +import model.SOMConfig; import model.SOMEvent; import model.SOMImage; import model.SOMLayout; @@ -249,55 +250,60 @@ public class PictureCtl { } private void setPrintBtn() { - // get the button height & width - int height = (SOMLayout.screenHeight / 4); - // set the Button height & width - printBtn.setPrefSize(height, height); + if (SOMConfig.PRINTER == true) { + // get the button height & width + int height = (SOMLayout.screenHeight / 4); - // Make it a circle - printBtn.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); + // set the Button height & width + printBtn.setPrefSize(height, height); - //Set Text Color - printBtn.setTextFill(SOMLayout.WHITE); - printBtn.setText(null); + // Make it a circle + printBtn.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); - // Set Image - ImageView imageView = new ImageView(SOMLayout.PRINT_IMAGE); + //Set Text Color + printBtn.setTextFill(SOMLayout.WHITE); + printBtn.setText(null); - printBtn.setGraphic(imageView); + // Set Image + ImageView imageView = new ImageView(SOMLayout.PRINT_IMAGE); - // Set Mouse Press Action - printBtn.setOnMousePressed(new EventHandler() { - public void handle(MouseEvent event) { - // Feedback - printBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + printBtn.setGraphic(imageView); + + // Set Mouse Press Action + printBtn.setOnMousePressed(new EventHandler() { + public void handle(MouseEvent event) { + // Feedback + printBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }); + + // Check if active + if (numberOfImages == 0) { + printBtn.setDisable(true); + } else { + printBtn.setDisable(false); } - }); - // Check if active - if (numberOfImages == 0) { - printBtn.setDisable(true); - } else { - printBtn.setDisable(false); + // Set Mouse Release Action + printBtn.setOnMouseReleased(new EventHandler() { + public void handle(MouseEvent event) { + + // Feedback + printBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Action + action(); + } + + // Action Performed + private void action() { + FilesWorker.print(); + } + }); + }else { + printBtn.setVisible(false); } - - // Set Mouse Release Action - printBtn.setOnMouseReleased(new EventHandler() { - public void handle(MouseEvent event) { - - // Feedback - printBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); - - // Action - action(); - } - - // Action Performed - private void action() { - FilesWorker.print(); - } - }); } private void setImage() { diff --git a/src/main/java/Start.java b/src/main/java/Start.java index 8c5b72c..853faca 100644 --- a/src/main/java/Start.java +++ b/src/main/java/Start.java @@ -12,15 +12,16 @@ public class Start extends SOMGUI { public static void main(String[] args) throws Exception { // Log the start - System.out.println("Gestartet!"); - - // Start the UI - launch(args); + System.out.println("-------------------"); + System.out.println("WELCOME TO SELFOMAT"); + System.out.println("-------------------"); // Set up the backend // get configuration - SOMConfig config = SOMConfig.getInstance(); - config.readConfig(); + SOMConfig.getInstance(); + + // Start the UI + launch(args); // get event instance SOMEvent event = SOMEvent.getInstance(); diff --git a/src/main/java/model/SOMConfig.java b/src/main/java/model/SOMConfig.java index 092ea04..794819a 100644 --- a/src/main/java/model/SOMConfig.java +++ b/src/main/java/model/SOMConfig.java @@ -2,61 +2,76 @@ package model; import workers.MachineWorker; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import java.io.File; -import java.nio.file.Files; +import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; -@XmlRootElement(name = "Config") public class SOMConfig { - // important Paths - @XmlElement(name = "PICTURES_PATH") - public static final File PICTURES_PATH = new File("images"); - @XmlElement(name = "UPLOAD_PATH") - public static final String UPLOAD_PATH = getEventPicDir(); + public static File PICTURES_PATH = new File("images"); + public static String UPLOAD_PATH = getEventPicDir(); + // The Box's ID - @XmlElement(name = "BOX_ID") - public static final String BOX_ID = MachineWorker.getHostName(); + public static String BOX_ID = MachineWorker.getHostName(); + // Number of pictures in series mode - @XmlElement(name = "SERIES_COUNTER") - public static final int SERIES_COUNTER = 4; + public static int SERIES_COUNTER; // Seconds before image is taken - @XmlElement(name = "COUNTDOWN_COUNTER") - public static final int COUNTDOWN_COUNTER = 4; + public static int COUNTDOWN_COUNTER; + + // Session has Printer support + public static boolean PRINTER; + // Images per Page in the Gallery public static final int IMAGES_PER_PAGE = 9; - // Limot of Parallel Uploads - public static final int PARALLEL_UPLOADS = 10; - // Cloud Credentials - public static final String CLOUD_CREDENTIALS = "upload:geheim"; + + // Cloud + public static String CLOUD_CREDENTIALS = "upload:geheim"; + public static String CLOUD_ADDRESS = "https://cloud.selfomat.de/remote.php/webdav/"; + // Limit of Parallel Uploads + public static int PARALLEL_UPLOADS; + // Make the Scaling Algorithm switchable public static final int SCALING_GRAPHICS_2D = 0; public static final int SCALING_JAVAFX = 1; + public static int SCALING_ALGORITHM = SCALING_GRAPHICS_2D; - public static final int SCALING_ALGORITHM = SCALING_GRAPHICS_2D; - public static final String CLOUD_ADDRESS = "https://cloud.selfomat.de/remote.php/webdav/"; // Path to configfile - private static final File configfile = new File(("config/config.xml")); + static final File configfile = new File(("config/config.xml")); + // Instance +// @XmlElement(name = "config") private static SOMConfig config = null; // Constructor private SOMConfig() { - // TODO fix readConfig - // readConfig(); - // get the default Displays' dimensions - System.out.println("Screen Dimensions: " + SOMLayout.screenWidth + "x" + SOMLayout.screenHeight); + + System.out.println("Creating Configuration. Sreen Size: " + SOMLayout.screenWidth + "x" + SOMLayout.screenHeight); + + // important Paths + PICTURES_PATH = new File("images"); + UPLOAD_PATH = getEventPicDir(); + + // The Box's ID + BOX_ID = MachineWorker.getHostName(); + + // Number of pictures in series mode + SERIES_COUNTER = 4; + // Seconds before image is taken + COUNTDOWN_COUNTER = 4; + + // Cloud + CLOUD_CREDENTIALS = "upload:geheim"; + CLOUD_ADDRESS = "https://cloud.selfomat.de/remote.php/webdav/"; + // Limit of Parallel Uploads + PARALLEL_UPLOADS = 3; + + // Make the Scaling Algorithm switchable + SCALING_ALGORITHM = SCALING_GRAPHICS_2D; } // Instance @@ -64,6 +79,8 @@ public class SOMConfig { // Singleton Pattern if (config == null) { config = new SOMConfig(); + SOMConfigFileHandler handler = new SOMConfigFileHandler(); + handler.readConfig(); } return config; } @@ -87,47 +104,7 @@ public class SOMConfig { return eventPicDir; } - // Write Config - private void writeConfig() { - try { - configfile.getParentFile().mkdirs(); - JAXBContext jaxbContext = JAXBContext.newInstance(SOMConfig.class); - Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); - - // output pretty printed - jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - - jaxbMarshaller.marshal(this, configfile); - jaxbMarshaller.marshal(this, System.out); - - } catch (JAXBException e) { - e.printStackTrace(); - } - - } - - // Read Config - public void readConfig() { - try { - - if (Files.exists(configfile.toPath())) { - - JAXBContext jaxbContext = JAXBContext - .newInstance(SOMConfig.class); - - Unmarshaller jaxbUnmarshaller = jaxbContext - .createUnmarshaller(); - config = (SOMConfig) jaxbUnmarshaller.unmarshal(configfile); - - System.out.println(); - } else { - this.writeConfig(); - } - } catch (JAXBException e) { - e.printStackTrace(); - } - } // return the current Timestamp public long getCurrentTimestamp() { diff --git a/src/main/java/model/SOMConfigFileHandler.java b/src/main/java/model/SOMConfigFileHandler.java new file mode 100644 index 0000000..47c6977 --- /dev/null +++ b/src/main/java/model/SOMConfigFileHandler.java @@ -0,0 +1,104 @@ +package model; + +import workers.MachineWorker; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.io.File; +import java.nio.file.Files; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +@XmlRootElement(name = "Config") +public class SOMConfigFileHandler { + + @XmlElement + private int SERIES_COUNTER; + @XmlElement + private int COUNTDOWN_COUNTER; + @XmlElement + private boolean PRINTER; +// @XmlElement +// private String CLOUD_CREDENTIALS; +// @XmlElement +// private String CLOUD_ADDRESS; + @XmlElement + private int PARALLEL_UPLOADS; + @XmlElement + private int SCALING_ALGORITHM; + @XmlElement + private final File configfile; + + // Constructor + SOMConfigFileHandler() { + // get the default Displays' dimensions + System.out.println("Configuration Handler."); + SERIES_COUNTER = SOMConfig.SERIES_COUNTER; + COUNTDOWN_COUNTER = SOMConfig.COUNTDOWN_COUNTER; +// CLOUD_CREDENTIALS = SOMConfig.CLOUD_CREDENTIALS; +// CLOUD_ADDRESS = SOMConfig.CLOUD_ADDRESS; + PARALLEL_UPLOADS = SOMConfig.PARALLEL_UPLOADS; + SCALING_ALGORITHM = SOMConfig.SCALING_ALGORITHM; + configfile = SOMConfig.configfile; + PRINTER = SOMConfig.PRINTER; + } + + // Write Config + private void writeConfig() { + try { + // make all directories to specified path if tot existent before writing config + configfile.getParentFile().mkdirs(); + + // Create Marshaller + JAXBContext jaxbContext = JAXBContext.newInstance(SOMConfigFileHandler.class); + Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); + + // output pretty printed + jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + // Do the marshalling + jaxbMarshaller.marshal(this, configfile); + jaxbMarshaller.marshal(this, System.out); + + } catch (JAXBException e) { + e.printStackTrace(); + } + + } + + // Read Config + void readConfig() { + SOMConfigFileHandler retCFH = new SOMConfigFileHandler(); + try { + + if (Files.exists(configfile.toPath())) { + + JAXBContext jc = JAXBContext.newInstance(SOMConfigFileHandler.class); + + Unmarshaller unmarshaller = jc.createUnmarshaller(); + + System.out.println(configfile.toString()); + + retCFH = (SOMConfigFileHandler) unmarshaller.unmarshal(configfile); + + } else { + writeConfig(); + } + } catch (JAXBException e) { + e.printStackTrace(); + } + SOMConfig.SERIES_COUNTER = retCFH.SERIES_COUNTER; + SOMConfig.COUNTDOWN_COUNTER = retCFH.COUNTDOWN_COUNTER; +// SOMConfig.CLOUD_CREDENTIALS = retCFH.CLOUD_CREDENTIALS; +// SOMConfig.CLOUD_ADDRESS = retCFH.CLOUD_ADDRESS; + SOMConfig.PARALLEL_UPLOADS = retCFH.PARALLEL_UPLOADS; + SOMConfig.SCALING_ALGORITHM = retCFH.SCALING_ALGORITHM; + SOMConfig.PRINTER = retCFH.PRINTER; + } + +} \ No newline at end of file diff --git a/src/main/java/workers/CaptureWorker.java b/src/main/java/workers/CaptureWorker.java index da7ad4d..e47b22d 100644 --- a/src/main/java/workers/CaptureWorker.java +++ b/src/main/java/workers/CaptureWorker.java @@ -3,10 +3,8 @@ */ package workers; -import com.sun.java.util.jar.pack.Package; import model.SOMImage; -import java.io.File; import java.io.IOException; import java.nio.file.Files; diff --git a/src/main/java/workers/FilesWorker.java b/src/main/java/workers/FilesWorker.java index d094708..df9705c 100644 --- a/src/main/java/workers/FilesWorker.java +++ b/src/main/java/workers/FilesWorker.java @@ -123,7 +123,7 @@ public class FilesWorker { builder.redirectErrorStream(true); - // launch capture! + // launch print! Process process = builder.start(); } catch (IOException e) { @@ -229,14 +229,15 @@ public class FilesWorker { List limitpics = new ArrayList(); for (File pic : pics ) { - // Counter for queues files + // Counter for all queued files over the whole upload process queuedfiles++; System.out.println("Queueing File " + pic.toString()); limitpics.add(pic); - if (limitpics.size() >= SOMConfig.PARALLEL_UPLOADS - // Upload even if limit is not reached + if ( // Check if the parallel Upload Limit is reached + limitpics.size() >= SOMConfig.PARALLEL_UPLOADS + // Upload even if limit is not reached if the pics are the last ones || (pics.size() - queuedfiles) < SOMConfig.PARALLEL_UPLOADS) { System.out.println("Launch File upload"); @@ -244,9 +245,7 @@ public class FilesWorker { System.out.println("Clear File Queue"); limitpics.clear(); - } else if (queuedfiles == pics.size() && pics.size() != 0) { - // reboot - new ProcessBuilder("reboot").start(); + } else { } } @@ -259,6 +258,11 @@ public class FilesWorker { // Archive the Backup archiveBackup(); + + + // reboot + new File("reboot").mkdirs(); +// new ProcessBuilder("sudo reboot").start(); } // Update the State fot previews and thumbs @@ -366,6 +370,8 @@ public class FilesWorker { System.out.println("process ended failing " + file); Thread.sleep(1000); + + return false; } }