commit c459938a9a1534c43a5ac7a98ec0df32e8217bd7 Author: simongehrig Date: Mon Dec 12 10:21:13 2016 +0100 SOM moved to OpenProject Git diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..7d4fd01 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +selfomat-single-user \ No newline at end of file diff --git a/.idea/artifacts/selfomat_single_user_jar.xml b/.idea/artifacts/selfomat_single_user_jar.xml new file mode 100644 index 0000000..50a38f5 --- /dev/null +++ b/.idea/artifacts/selfomat_single_user_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/classes/artifacts/selfomat_single_user_jar + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..a9e1831 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_twelvemonkeys_common_common_image_3_2_1.xml b/.idea/libraries/Maven__com_twelvemonkeys_common_common_image_3_2_1.xml new file mode 100644 index 0000000..af4836f --- /dev/null +++ b/.idea/libraries/Maven__com_twelvemonkeys_common_common_image_3_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_twelvemonkeys_common_common_io_3_2_1.xml b/.idea/libraries/Maven__com_twelvemonkeys_common_common_io_3_2_1.xml new file mode 100644 index 0000000..3db1f7a --- /dev/null +++ b/.idea/libraries/Maven__com_twelvemonkeys_common_common_io_3_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_twelvemonkeys_common_common_lang_3_2_1.xml b/.idea/libraries/Maven__com_twelvemonkeys_common_common_lang_3_2_1.xml new file mode 100644 index 0000000..3b54557 --- /dev/null +++ b/.idea/libraries/Maven__com_twelvemonkeys_common_common_lang_3_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_core_3_2_1.xml b/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_core_3_2_1.xml new file mode 100644 index 0000000..aa57c77 --- /dev/null +++ b/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_core_3_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_jpeg_3_2_1.xml b/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_jpeg_3_2_1.xml new file mode 100644 index 0000000..4e8f4fa --- /dev/null +++ b/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_jpeg_3_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_metadata_3_2_1.xml b/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_metadata_3_2_1.xml new file mode 100644 index 0000000..0603e44 --- /dev/null +++ b/.idea/libraries/Maven__com_twelvemonkeys_imageio_imageio_metadata_3_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_io_commons_io_2_4.xml b/.idea/libraries/Maven__commons_io_commons_io_2_4.xml new file mode 100644 index 0000000..bc2aad0 --- /dev/null +++ b/.idea/libraries/Maven__commons_io_commons_io_2_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/commons_io_commons_io_2_4.xml b/.idea/libraries/commons_io_commons_io_2_4.xml new file mode 100644 index 0000000..9ca89f9 --- /dev/null +++ b/.idea/libraries/commons_io_commons_io_2_4.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3e8613d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5c32992 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Testbilder/1.jpg b/Testbilder/1.jpg new file mode 100644 index 0000000..337bc01 Binary files /dev/null and b/Testbilder/1.jpg differ diff --git a/Testbilder/10.jpg b/Testbilder/10.jpg new file mode 100644 index 0000000..8a4b89a Binary files /dev/null and b/Testbilder/10.jpg differ diff --git a/Testbilder/11.jpg b/Testbilder/11.jpg new file mode 100644 index 0000000..1f75fe4 Binary files /dev/null and b/Testbilder/11.jpg differ diff --git a/Testbilder/12.jpg b/Testbilder/12.jpg new file mode 100644 index 0000000..95c775f Binary files /dev/null and b/Testbilder/12.jpg differ diff --git a/Testbilder/13.jpg b/Testbilder/13.jpg new file mode 100644 index 0000000..9b8ef2f Binary files /dev/null and b/Testbilder/13.jpg differ diff --git a/Testbilder/14.jpg b/Testbilder/14.jpg new file mode 100644 index 0000000..d03183f Binary files /dev/null and b/Testbilder/14.jpg differ diff --git a/Testbilder/15.jpg b/Testbilder/15.jpg new file mode 100644 index 0000000..dcee696 Binary files /dev/null and b/Testbilder/15.jpg differ diff --git a/Testbilder/16.jpg b/Testbilder/16.jpg new file mode 100644 index 0000000..78b0f04 Binary files /dev/null and b/Testbilder/16.jpg differ diff --git a/Testbilder/17.jpg b/Testbilder/17.jpg new file mode 100644 index 0000000..9acacb4 Binary files /dev/null and b/Testbilder/17.jpg differ diff --git a/Testbilder/18.jpg b/Testbilder/18.jpg new file mode 100644 index 0000000..fe1b61d Binary files /dev/null and b/Testbilder/18.jpg differ diff --git a/Testbilder/19.jpg b/Testbilder/19.jpg new file mode 100644 index 0000000..0473747 Binary files /dev/null and b/Testbilder/19.jpg differ diff --git a/Testbilder/2.jpg b/Testbilder/2.jpg new file mode 100644 index 0000000..a175774 Binary files /dev/null and b/Testbilder/2.jpg differ diff --git a/Testbilder/20.jpg b/Testbilder/20.jpg new file mode 100644 index 0000000..a597b21 Binary files /dev/null and b/Testbilder/20.jpg differ diff --git a/Testbilder/21.jpg b/Testbilder/21.jpg new file mode 100644 index 0000000..4ea68bc Binary files /dev/null and b/Testbilder/21.jpg differ diff --git a/Testbilder/22.jpg b/Testbilder/22.jpg new file mode 100644 index 0000000..5137fd4 Binary files /dev/null and b/Testbilder/22.jpg differ diff --git a/Testbilder/23.jpg b/Testbilder/23.jpg new file mode 100644 index 0000000..1fceb33 Binary files /dev/null and b/Testbilder/23.jpg differ diff --git a/Testbilder/24.jpg b/Testbilder/24.jpg new file mode 100644 index 0000000..81221b0 Binary files /dev/null and b/Testbilder/24.jpg differ diff --git a/Testbilder/25.jpg b/Testbilder/25.jpg new file mode 100644 index 0000000..00afc77 Binary files /dev/null and b/Testbilder/25.jpg differ diff --git a/Testbilder/26.jpg b/Testbilder/26.jpg new file mode 100644 index 0000000..7d2ca74 Binary files /dev/null and b/Testbilder/26.jpg differ diff --git a/Testbilder/27.jpg b/Testbilder/27.jpg new file mode 100644 index 0000000..98671d0 Binary files /dev/null and b/Testbilder/27.jpg differ diff --git a/Testbilder/28.jpg b/Testbilder/28.jpg new file mode 100644 index 0000000..fe105a9 Binary files /dev/null and b/Testbilder/28.jpg differ diff --git a/Testbilder/29.jpg b/Testbilder/29.jpg new file mode 100644 index 0000000..d2c7a89 Binary files /dev/null and b/Testbilder/29.jpg differ diff --git a/Testbilder/3.jpg b/Testbilder/3.jpg new file mode 100644 index 0000000..876d354 Binary files /dev/null and b/Testbilder/3.jpg differ diff --git a/Testbilder/30.jpg b/Testbilder/30.jpg new file mode 100644 index 0000000..c555338 Binary files /dev/null and b/Testbilder/30.jpg differ diff --git a/Testbilder/31.jpg b/Testbilder/31.jpg new file mode 100644 index 0000000..5b22aef Binary files /dev/null and b/Testbilder/31.jpg differ diff --git a/Testbilder/32.jpg b/Testbilder/32.jpg new file mode 100644 index 0000000..a548261 Binary files /dev/null and b/Testbilder/32.jpg differ diff --git a/Testbilder/33.jpg b/Testbilder/33.jpg new file mode 100644 index 0000000..bd6d901 Binary files /dev/null and b/Testbilder/33.jpg differ diff --git a/Testbilder/34.jpg b/Testbilder/34.jpg new file mode 100644 index 0000000..76b034d Binary files /dev/null and b/Testbilder/34.jpg differ diff --git a/Testbilder/35.jpg b/Testbilder/35.jpg new file mode 100644 index 0000000..488ea4a Binary files /dev/null and b/Testbilder/35.jpg differ diff --git a/Testbilder/36.jpg b/Testbilder/36.jpg new file mode 100644 index 0000000..708bd90 Binary files /dev/null and b/Testbilder/36.jpg differ diff --git a/Testbilder/37.jpg b/Testbilder/37.jpg new file mode 100644 index 0000000..997cfd8 Binary files /dev/null and b/Testbilder/37.jpg differ diff --git a/Testbilder/38.jpg b/Testbilder/38.jpg new file mode 100644 index 0000000..917bff0 Binary files /dev/null and b/Testbilder/38.jpg differ diff --git a/Testbilder/39.jpg b/Testbilder/39.jpg new file mode 100644 index 0000000..cca91ea Binary files /dev/null and b/Testbilder/39.jpg differ diff --git a/Testbilder/4.jpg b/Testbilder/4.jpg new file mode 100644 index 0000000..066f3c1 Binary files /dev/null and b/Testbilder/4.jpg differ diff --git a/Testbilder/40.jpg b/Testbilder/40.jpg new file mode 100644 index 0000000..7b40340 Binary files /dev/null and b/Testbilder/40.jpg differ diff --git a/Testbilder/41.jpg b/Testbilder/41.jpg new file mode 100644 index 0000000..802d11d Binary files /dev/null and b/Testbilder/41.jpg differ diff --git a/Testbilder/42.jpg b/Testbilder/42.jpg new file mode 100644 index 0000000..f3fcab4 Binary files /dev/null and b/Testbilder/42.jpg differ diff --git a/Testbilder/43.jpg b/Testbilder/43.jpg new file mode 100644 index 0000000..87ce7ae Binary files /dev/null and b/Testbilder/43.jpg differ diff --git a/Testbilder/44.jpg b/Testbilder/44.jpg new file mode 100644 index 0000000..2800155 Binary files /dev/null and b/Testbilder/44.jpg differ diff --git a/Testbilder/45.jpg b/Testbilder/45.jpg new file mode 100644 index 0000000..852ab0c Binary files /dev/null and b/Testbilder/45.jpg differ diff --git a/Testbilder/46.jpg b/Testbilder/46.jpg new file mode 100644 index 0000000..d1f7114 Binary files /dev/null and b/Testbilder/46.jpg differ diff --git a/Testbilder/47.jpg b/Testbilder/47.jpg new file mode 100644 index 0000000..2b4b881 Binary files /dev/null and b/Testbilder/47.jpg differ diff --git a/Testbilder/48.jpg b/Testbilder/48.jpg new file mode 100644 index 0000000..fa31adc Binary files /dev/null and b/Testbilder/48.jpg differ diff --git a/Testbilder/49.jpg b/Testbilder/49.jpg new file mode 100644 index 0000000..dae4395 Binary files /dev/null and b/Testbilder/49.jpg differ diff --git a/Testbilder/5.jpg b/Testbilder/5.jpg new file mode 100644 index 0000000..77e197f Binary files /dev/null and b/Testbilder/5.jpg differ diff --git a/Testbilder/50.jpg b/Testbilder/50.jpg new file mode 100644 index 0000000..23b8cbe Binary files /dev/null and b/Testbilder/50.jpg differ diff --git a/Testbilder/51.jpg b/Testbilder/51.jpg new file mode 100644 index 0000000..d9ef7e5 Binary files /dev/null and b/Testbilder/51.jpg differ diff --git a/Testbilder/52.jpg b/Testbilder/52.jpg new file mode 100644 index 0000000..809761b Binary files /dev/null and b/Testbilder/52.jpg differ diff --git a/Testbilder/53.jpg b/Testbilder/53.jpg new file mode 100644 index 0000000..7af250a Binary files /dev/null and b/Testbilder/53.jpg differ diff --git a/Testbilder/54.jpg b/Testbilder/54.jpg new file mode 100644 index 0000000..c0d24fb Binary files /dev/null and b/Testbilder/54.jpg differ diff --git a/Testbilder/55.jpg b/Testbilder/55.jpg new file mode 100644 index 0000000..4346b55 Binary files /dev/null and b/Testbilder/55.jpg differ diff --git a/Testbilder/56.jpg b/Testbilder/56.jpg new file mode 100644 index 0000000..8c189c1 Binary files /dev/null and b/Testbilder/56.jpg differ diff --git a/Testbilder/57.jpg b/Testbilder/57.jpg new file mode 100644 index 0000000..dbc24f1 Binary files /dev/null and b/Testbilder/57.jpg differ diff --git a/Testbilder/58.jpg b/Testbilder/58.jpg new file mode 100644 index 0000000..7aba50d Binary files /dev/null and b/Testbilder/58.jpg differ diff --git a/Testbilder/59.jpg b/Testbilder/59.jpg new file mode 100644 index 0000000..a0018c2 Binary files /dev/null and b/Testbilder/59.jpg differ diff --git a/Testbilder/6.jpg b/Testbilder/6.jpg new file mode 100644 index 0000000..f98658f Binary files /dev/null and b/Testbilder/6.jpg differ diff --git a/Testbilder/60.jpg b/Testbilder/60.jpg new file mode 100644 index 0000000..cf5f0b7 Binary files /dev/null and b/Testbilder/60.jpg differ diff --git a/Testbilder/61.jpg b/Testbilder/61.jpg new file mode 100644 index 0000000..5dc1e7d Binary files /dev/null and b/Testbilder/61.jpg differ diff --git a/Testbilder/62.jpg b/Testbilder/62.jpg new file mode 100644 index 0000000..72fc992 Binary files /dev/null and b/Testbilder/62.jpg differ diff --git a/Testbilder/63.jpg b/Testbilder/63.jpg new file mode 100644 index 0000000..611ce14 Binary files /dev/null and b/Testbilder/63.jpg differ diff --git a/Testbilder/64.jpg b/Testbilder/64.jpg new file mode 100644 index 0000000..7b55b0f Binary files /dev/null and b/Testbilder/64.jpg differ diff --git a/Testbilder/65.jpg b/Testbilder/65.jpg new file mode 100644 index 0000000..c373cc6 Binary files /dev/null and b/Testbilder/65.jpg differ diff --git a/Testbilder/66.jpg b/Testbilder/66.jpg new file mode 100644 index 0000000..c46f8f4 Binary files /dev/null and b/Testbilder/66.jpg differ diff --git a/Testbilder/67.jpg b/Testbilder/67.jpg new file mode 100644 index 0000000..3dfbc84 Binary files /dev/null and b/Testbilder/67.jpg differ diff --git a/Testbilder/7.jpg b/Testbilder/7.jpg new file mode 100644 index 0000000..d3d4e5f Binary files /dev/null and b/Testbilder/7.jpg differ diff --git a/Testbilder/8.jpg b/Testbilder/8.jpg new file mode 100644 index 0000000..885fca3 Binary files /dev/null and b/Testbilder/8.jpg differ diff --git a/Testbilder/9.jpg b/Testbilder/9.jpg new file mode 100644 index 0000000..29e2129 Binary files /dev/null and b/Testbilder/9.jpg differ diff --git a/classes/artifacts/selfomat_single_user_jar/selfomat-single-user.jar b/classes/artifacts/selfomat_single_user_jar/selfomat-single-user.jar new file mode 100644 index 0000000..6eec927 Binary files /dev/null and b/classes/artifacts/selfomat_single_user_jar/selfomat-single-user.jar differ diff --git a/lib/commons-io-2.4.jar b/lib/commons-io-2.4.jar new file mode 100644 index 0000000..90035a4 Binary files /dev/null and b/lib/commons-io-2.4.jar differ diff --git a/lib/jai-imageio-core-1.3.1.jar b/lib/jai-imageio-core-1.3.1.jar new file mode 100644 index 0000000..27c0a3b Binary files /dev/null and b/lib/jai-imageio-core-1.3.1.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4c5a68d --- /dev/null +++ b/pom.xml @@ -0,0 +1,78 @@ + + 4.0.0 + de.selfomat + selfomat-single-user + 0.4.0.5-SNAPSHOT + + + scm:svn:svn://simongehrig:L4ut5pr3ch3r!@svn.picture.tools/selfomat/trunk/selfomat-java-single-user + scm:svn:svn://simongehrig:L4ut5pr3ch3r!@svn.picture.tools/selfomat/trunk + + HEAD + + + + + repo + My maven2 repository + dav:http://software:release@cloud.selfom.at/remote.php/webdav/00-SELFOMAT-Releases + + + + + + commons-io + commons-io + 2.4 + + + + com.twelvemonkeys.imageio + imageio-jpeg + 3.2.1 + + + + + + selfomat single user + Photobooth Software + + + + + maven-jar-plugin + + + + Start + + + + + + maven-assembly-plugin + + + + Start + + + + jar-with-dependencies + + + + + + + src/main/resources + + + src/main/resources + + + + + diff --git a/release.properties b/release.properties new file mode 100644 index 0000000..9ef080a --- /dev/null +++ b/release.properties @@ -0,0 +1,7 @@ +#release configuration +#Fri Jun 17 14:04:37 CEST 2016 +preparationGoals=clean verify +scm.commentPrefix=[maven-release-plugin] +remoteTagging=true +completedPhase=check-poms +scm.url=scm\:svn\:svn\://simongehrig\:L4ut5pr3ch3r\!@svn.picture.tools/selfomat/trunk/selfomat-java-single-user/ diff --git a/selfomat-java.iml b/selfomat-java.iml new file mode 100644 index 0000000..e69de29 diff --git a/selfomat-service.iml b/selfomat-service.iml new file mode 100644 index 0000000..e69de29 diff --git a/selfomat-single-user.iml b/selfomat-single-user.iml new file mode 100644 index 0000000..464d71a --- /dev/null +++ b/selfomat-single-user.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/GUI/CaptureCtl.java b/src/main/java/GUI/CaptureCtl.java new file mode 100644 index 0000000..76bae89 --- /dev/null +++ b/src/main/java/GUI/CaptureCtl.java @@ -0,0 +1,238 @@ +package GUI; + +import javafx.application.Platform; +import javafx.fxml.FXML; +import javafx.geometry.Pos; +import javafx.scene.control.Label; +import javafx.scene.control.ProgressIndicator; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.StackPane; +import javafx.scene.text.Font; +import model.SOMConfig; +import model.SOMImage; +import model.SOMLayout; +import workers.FilesWorker; +import workers.ScaleWorker; + +import java.util.Timer; +import java.util.TimerTask; + +/** + * Created by Simon on 13.06.2016. + */ +public class CaptureCtl { + + @FXML + public StackPane capturePane; + @FXML + public Label countdownText; + @FXML + public ImageView image; + @FXML + public ProgressIndicator pictureLoadIndicator; + + // series switch + public boolean series = false; + // Timer for coutdown + Timer timer; + // series picture counter + private int seriesCounter; + // countdown counter + private int counter = 0; + + // Initialisation + public void initialize() { + setPane(); + setImage(); + setCountdownText(); + setPictureLoadIndicator(); + } + + private void setPictureLoadIndicator() { + pictureLoadIndicator.setVisible(false); + + pictureLoadIndicator.setPrefHeight(SOMLayout.screenHeight / 4); + pictureLoadIndicator.setPrefWidth(SOMLayout.screenHeight / 4); + + pictureLoadIndicator.setMaxSize(SOMLayout.screenHeight / 2, SOMLayout.screenHeight / 2); + + pictureLoadIndicator.setStyle("-fx-progress-color: white;"); + } + + private void setCountdownText() { + + capturePane.setAlignment(Pos.CENTER); + countdownText.setAlignment(Pos.CENTER); + + countdownText.setPrefSize(SOMLayout.screenHeight / 2, SOMLayout.screenHeight / 2); + countdownText.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + + countdownText.setText(null); + countdownText.setFont(new Font("Century Gothic Bold", SOMLayout.screenHeight / 4)); + countdownText.setTextFill(SOMLayout.WHITE); + } + + public void setPane() { + capturePane.setBackground(SOMLayout.BLACK_BG); + } + + public void setImage() { + // Set the image aspect ratio to be preserved + image.setPreserveRatio(true); + + // Set the image to the image View + image.setImage(SOMLayout.SPLASH_IMAGE); + + // make it fit the height of the Screen + image.setFitHeight(SOMLayout.screenHeight); + + // Calculate the offset to center it horizontally if the image is wider than the screen (or narrower) + double aspect = image.getImage().getWidth() / image.getImage().getHeight(); + double scaledWidth = aspect * SOMLayout.screenHeight; + double offset = (scaledWidth - SOMLayout.screenWidth) / 2; + + image.setX(-offset); + } + + public void setSeries(Boolean series) { + this.series = series; + } + + /* LOGIC + * ----------------------------------------------------------------- + * ----------------------------------------------------------------- + * */ + protected void shoot(boolean series) { + // Check for series mode + System.out.println("shoot"); + + // Change to the capture screen + SOMGUI.changetocapture(); + + if (series) + // if series mode is on, set the counter to amount of pictures to make + seriesCounter = SOMConfig.SERIES_COUNTER; + else + // else set it to one + seriesCounter = 1; + + + //start the first countdown + countdown2(); + } + + protected void countdown2() { + // set the Countdown Value + counter = SOMConfig.COUNTDOWN_COUNTER; + + // open a Timer + timer = new Timer(); + // give it a Task + TimerTask task = new TimerTask() { + @Override + public void run() { + + if (seriesCounter == 0) + counter = 0; + + System.out.println("countdown " + counter); + // It feels better if there is still + // a second after the counter is at + // 0, so it will count to -1 + + // show smile instead of a zero + if (counter == 0) { + + Platform.runLater(new Runnable() { + public void run() { + // Remove Text + countdownText.setText(null); + // Set Countdown Smile Image + countdownText.setGraphic(new ImageView(SOMLayout.SMILE_IMAGE)); + } + }); + + } + // shoot the camera + else if (counter <= -1) { + + // Run on Javafx Thread + Platform.runLater(new Runnable() { + public void run() { + // Remove Graphic + countdownText.setGraphic(null); + // Remove Text + countdownText.setText(null); + } + }); + + // cancel the timer + timer.cancel(); + // show the Load indicator + pictureLoadIndicator.setVisible(true); + // hide the Countdown Text + countdownText.setVisible(false); + // actually take the picture + takePicture(); + // Count down one Picture + seriesCounter--; + + // check if pictures are left + if (seriesCounter > 0) { + // restart if pictures left + countdown2(); + + + } else { + // Change the UI + Platform.runLater(new Runnable() { + public void run() { + // change to Picture scene + SOMGUI.changetopicture(); + // set the Gallery page to the first + SOMGUI.galleryCtl.setPage(); + // update the Gallery + SOMGUI.galleryCtl.getGalleryImages(); + } + }); + } + } + // Show the Time left + else { + + Platform.runLater(new Runnable() { + public void run() { + // Set Countdown Text + countdownText.setText(String.valueOf(counter + 1)); + // Set the Counter Visible + countdownText.setVisible(true); + } + }); + + } + counter--; + } + }; + + // start the timer + timer.schedule(task, 0, 1000); + } + + private void takePicture() { + // Capture the image + SOMImage newImage = FilesWorker.waitForImageAndCapture(); + + //Scale the image to preview + ScaleWorker.scale(newImage, ScaleWorker.PREVIEW); + // set te image to UI + image.setImage(new Image(newImage.getPrv().toURI().toString())); + SOMGUI.pictureCtl.image.setImage(new Image(newImage.getPrv().toURI().toString())); + + // trigger the thumb calculation + ScaleWorker.scale(newImage, ScaleWorker.THUMBNAIL); + + } + +// +} diff --git a/src/main/java/GUI/GalleryCtl.java b/src/main/java/GUI/GalleryCtl.java new file mode 100644 index 0000000..3ba8586 --- /dev/null +++ b/src/main/java/GUI/GalleryCtl.java @@ -0,0 +1,415 @@ +package GUI; + +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.geometry.HPos; +import javafx.geometry.VPos; +import javafx.scene.control.Button; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import model.SOMConfig; +import model.SOMEvent; +import model.SOMImage; +import model.SOMLayout; +import workers.ScaleWorker; + +import java.util.List; + +/** + * Created by Simon on 13.06.2016. + */ +public class GalleryCtl { + @FXML + private Pane pane; + @FXML + private GridPane grid; + @FXML + private Button forthButton; + @FXML + private Button backButton; + @FXML + private Button pictureButton; + @FXML + private ImageView galleryImageView1; + @FXML + private ImageView galleryImageView2; + @FXML + private ImageView galleryImageView3; + @FXML + private ImageView galleryImageView4; + @FXML + private ImageView galleryImageView5; + @FXML + private ImageView galleryImageView6; + @FXML + private ImageView galleryImageView7; + @FXML + private ImageView galleryImageView8; + @FXML + private ImageView galleryImageView9; + @FXML + private Button galleryButton1; + @FXML + private Button galleryButton2; + @FXML + private Button galleryButton3; + @FXML + private Button galleryButton4; + @FXML + private Button galleryButton5; + @FXML + private Button galleryButton6; + @FXML + private Button galleryButton7; + @FXML + private Button galleryButton8; + @FXML + private Button galleryButton9; + + private ImageView[] imageViews; + private Button[] imageButtons; + private int page = 0; + private SOMImage[] somPageImagesArray = new SOMImage[9]; + + public void initialize() { + setPane(); + setGrid(); + setBackButton(); + setForthButton(); + setPictureButton(); + + imageViews = new ImageView[]{ + galleryImageView1, + galleryImageView2, + galleryImageView3, + galleryImageView4, + galleryImageView5, + galleryImageView6, + galleryImageView7, + galleryImageView8, + galleryImageView9 + }; + imageButtons = new Button[]{ + galleryButton1, + galleryButton2, + galleryButton3, + galleryButton4, + galleryButton5, + galleryButton6, + galleryButton7, + galleryButton8, + galleryButton9 + }; + + setImageViews(); + getGalleryImages(); + setImageButtons(); + } + + private void setImageButtons() { + int i = 0; + for (Button imageButton : imageButtons) { + imageButton.setText(null); + imageButton.setBackground(SOMLayout.BLACK_BG); + + final int finalI = i; + imageButton.setOnMouseReleased(new EventHandler() { + + public void handle(MouseEvent event) { + if (!somPageImagesArray[finalI].isPrvthere()) { + ScaleWorker.scale(somPageImagesArray[finalI], ScaleWorker.PREVIEW); + } + SOMGUI.pictureCtl.image.setImage(new Image(somPageImagesArray[finalI].getPrv().toURI().toString())); + SOMGUI.captureCtl.image.setImage(new Image(somPageImagesArray[finalI].getPrv().toURI().toString())); + SOMGUI.changetopicture(); + } + }); + + i++; + } + } + + private void setImageViews() { + for (ImageView imageView : imageViews) { + // Set the image aspect ratio to be preserved + imageView.setPreserveRatio(true); + + // Set the image to the image View + imageView.setImage(SOMLayout.SPLASH_IMAGE); + + // make it fit the height of the Screen + imageView.setFitHeight(SOMLayout.screenHeight / 3); + imageView.setFitWidth(SOMLayout.screenWidth / 4); + + // position the images in Center + GridPane.setValignment(imageView, VPos.CENTER); + GridPane.setHalignment(imageView, HPos.CENTER); + } + } + + public void setPane() { + pane.setPrefSize(SOMLayout.screenWidth, SOMLayout.screenHeight); + pane.setMinSize(SOMLayout.screenWidth, SOMLayout.screenHeight); + pane.setBackground(SOMLayout.BLACK_BG); + } + + public void setGrid() { + grid.setPrefHeight(SOMLayout.screenHeight); + grid.setPrefWidth(SOMLayout.screenWidth); + grid.setMinSize(SOMLayout.screenWidth, SOMLayout.screenHeight); + + + } + + public void setForthButton() { + // get the button height & width + int height = (SOMLayout.screenHeight / 4); + // set alignment + GridPane.setHalignment(forthButton, HPos.CENTER); + GridPane.setValignment(forthButton, VPos.CENTER); + // set the Button height & width + forthButton.setPrefSize(height, height); + + // Make it a circle + forthButton.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); + + //Set Text Color + forthButton.setTextFill(SOMLayout.WHITE); + forthButton.setText(null); + + // Set Image + ImageView imageView = new ImageView(SOMLayout.FORTH_IMAGE); + + forthButton.setGraphic(imageView); + + // Set Mouse Press Action + forthButton.setOnMousePressed(new EventHandler() { + public void handle(MouseEvent event) { + // Feedback + forthButton.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }); + + // Set Mouse Release Action + forthButton.setOnMouseReleased(new EventHandler() { + public void handle(MouseEvent event) { + + // Feedback + forthButton.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Action + action(); + } + + // Action Performed + private void action() { + page++; + getGalleryImages(); + } + }); + } + + public void setBackButton() { + // get the button height & width + int height = (SOMLayout.screenHeight / 4); + // set alignment + GridPane.setHalignment(backButton, HPos.CENTER); + GridPane.setValignment(backButton, VPos.CENTER); + // set the Button height & width + backButton.setPrefSize(height, height); + + // Make it a circle + backButton.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); + + //Set Text Color + backButton.setTextFill(SOMLayout.WHITE); + backButton.setText(null); + + // Set Image + ImageView imageView = new ImageView(SOMLayout.BACK_IMAGE); + + backButton.setGraphic(imageView); + + // Set Mouse Press Action + backButton.setOnMousePressed(new EventHandler() { + public void handle(MouseEvent event) { + // Feedback + backButton.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }); + + // Set Mouse Release Action + backButton.setOnMouseReleased(new EventHandler() { + public void handle(MouseEvent event) { + + // Feedback + backButton.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Action + action(); + } + + // Action Performed + private void action() { + page--; + getGalleryImages(); + } + }); + } + + public void setPictureButton() { + // get the button height & width + int height = (SOMLayout.screenHeight / 4); + // set alignment + GridPane.setHalignment(pictureButton, HPos.CENTER); + GridPane.setValignment(pictureButton, VPos.CENTER); + // set the Button height & width + pictureButton.setPrefSize(height, height); + + // Make it a circle + pictureButton.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); + + //Set Text Color + pictureButton.setTextFill(SOMLayout.WHITE); + pictureButton.setText(null); + + // Set Image + ImageView imageView = new ImageView(SOMLayout.PICTURE_IMAGE); + + pictureButton.setGraphic(imageView); + + // Set Mouse Press Action + pictureButton.setOnMousePressed(new EventHandler() { + public void handle(MouseEvent event) { + // Feedback + pictureButton.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }); + + // Set Mouse Release Action + pictureButton.setOnMouseReleased(new EventHandler() { + public void handle(MouseEvent event) { + + // Feedback + pictureButton.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Action + action(); + } + + // Action Performed + private void action() { + SOMGUI.changetopicture(); + } + }); + } + + public void setGalleryImageView1(ImageView galleryImageView1) { + this.galleryImageView1 = galleryImageView1; + } + + /* + * LOGIC + * ----------------------------------------------------------------------- + * ----------------------------------------------------------------------- + * */ + + void getGalleryImages() { + //Behandelt + System.out.println("Galerie baut auf"); + + // get the Images as Array + List imagelist = SOMEvent.getInstance().getImages(); + SOMImage[] imagearray = imagelist.toArray( + new SOMImage[imagelist.size()] + ); + // Open new Array for reversing + SOMImage[] reverseImageArray = new SOMImage[imagelist.size()]; + // Reverse the Array + for (int h = 0; h < imagearray.length; h++) { + reverseImageArray[reverseImageArray.length - h - 1] = imagearray[h]; + } + + // get the number of images + double numberOfPictures = reverseImageArray.length; + // calculate the number of pages (round up) + int numberOfPages = (int) Math.ceil(numberOfPictures / SOMConfig.IMAGES_PER_PAGE); + + //report to console + System.out.println( + "WE HAVE " + + numberOfPages + + " PAGES AND " + + reverseImageArray.length + + " IMAGES" + ); + + // Loop through the Array + System.out.println("Start looping through current pages images"); + + // Loop through the ImageViews of the current page + for (int i = 0; i < SOMConfig.IMAGES_PER_PAGE; i++) { + + // SYSOUT for manual checking + System.out.println("Page: " + page); + System.out.println("Image of Page: " + (i + 1)); + System.out.println("Image of whole; " + (i + (page * SOMConfig.IMAGES_PER_PAGE) + 1)); + + // If there is an Image to set at the Position + // (on the last page it probably stops somewhere in between) + if (i + (page * SOMConfig.IMAGES_PER_PAGE) < reverseImageArray.length) { + + // get the current image for the position + SOMImage currentSOMImage = reverseImageArray[i + (page * SOMConfig.IMAGES_PER_PAGE)]; + // Calculate the scaled Image + currentSOMImage = ScaleWorker.scale(currentSOMImage, ScaleWorker.THUMBNAIL); + + // REPORT THE Images Path to Console + System.out.println(currentSOMImage.getTmb().toURI().toString()); + // set the image to corresponding ImageView + imageViews[i].setImage(new Image(currentSOMImage.getTmb().toURI().toString())); + + // save the SOMImage to an Array in the + // same order for Button Actions etc. + somPageImagesArray[i] = currentSOMImage; + } + // if there are no more images to set + else { + // Set the image to null + imageViews[i].setImage(null); + + // save the SOMImage to an Array in the + // same order for Button Actions etc. + somPageImagesArray[i] = null; + } + } + + // EN/DISABLE BUTTONS AT THE ENDS + if (page >= numberOfPages - 1) { + + forthButton.setDisable(true); + } else { + forthButton.setDisable(false); + } + + if (page <= 0) { + backButton.setDisable(true); + } else { + backButton.setDisable(false); + } + setImageButtons(); + } + + // Set the Gallery Page Number + public void setPage(int pageNumber) { + this.page = pageNumber; + } + + // Default to 0 + public void setPage() { + setPage(0); + } +} diff --git a/src/main/java/GUI/PictureCtl.java b/src/main/java/GUI/PictureCtl.java new file mode 100644 index 0000000..ae49f65 --- /dev/null +++ b/src/main/java/GUI/PictureCtl.java @@ -0,0 +1,272 @@ +package GUI; + +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.geometry.HPos; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.input.MouseEvent; +import javafx.scene.input.TouchEvent; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import model.SOMEvent; +import model.SOMImage; +import model.SOMLayout; +import workers.ScaleWorker; + +import java.util.List; + +/** + * Created by Simon on 13.06.2016. + */ +public class PictureCtl { + @FXML + public Pane pane; + + @FXML + public GridPane grid; + + @FXML + public Button singleBtn; + @FXML + public Button seriesBtn; + @FXML + public Button galleryBtn; + + @FXML + public ImageView image; + + public void initialize() { + + // Basic Layout setup + setPane(); + setGrid(); + + // Buttons setup + setGalleryBtn(); + setSeriesBtn(); + setSingleBtn(); + + // Image Setup + setImage(); + } + + private void setPane() { + pane.setPrefSize(SOMLayout.screenWidth, SOMLayout.screenHeight); + pane.setBackground(SOMLayout.WHITE_BG); + } + + private void setGrid() { + grid.setPrefSize(SOMLayout.screenWidth, SOMLayout.screenHeight); + + grid.setAlignment(Pos.CENTER); + + GridPane.setHalignment(galleryBtn, HPos.CENTER); + GridPane.setHalignment(singleBtn, HPos.CENTER); + GridPane.setHalignment(seriesBtn, HPos.CENTER); + } + + private void setSingleBtn() { + // get the button height & width + int height = (SOMLayout.screenHeight / 4); + + // set the Button height & width + singleBtn.setPrefSize(height, height); + + // Make it a circle + singleBtn.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); + + //Set Text Color + singleBtn.setTextFill(SOMLayout.WHITE); + singleBtn.setText(null); + + // Set Image + ImageView imageView = new ImageView(SOMLayout.SINGLE_PHOTO_IMAGE); + singleBtn.setGraphic(imageView); + + // INTERACTION + // Set the Action to run after Button is Pressed + EventHandler singleCapturePressedEventHandler = new EventHandler() { + public void handle(MouseEvent event) { + singleBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }; + + // Set the Action to run after Button is Released + EventHandler singleCaptureReleasedEventHandler = new EventHandler() { + public void handle(MouseEvent event) { + + // Feedback (button gets less transparent) + singleBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Action + action(); + } + + // Action Performed + private void action() { + // Capture one image (false means no series mode) + SOMGUI.captureCtl.shoot(false); + } + }; + + // Set Mouse Press Action + singleBtn.setOnMousePressed(singleCapturePressedEventHandler); + + // Set Mouse Release Action + singleBtn.setOnMouseReleased(singleCaptureReleasedEventHandler); + + // Set Touch Press Action + singleBtn.setOnTouchPressed(singleCapturePressedEventHandler); + + // Set Touch Release Action + singleBtn.setOnTouchReleased(singleCaptureReleasedEventHandler); + } + + private void setSeriesBtn() { + // get the button height & width + int height = (SOMLayout.screenHeight / 4); + + // set the Button height & width + seriesBtn.setPrefSize(height, height); + + // Make it a circle + seriesBtn.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); + + //Set Text Color + seriesBtn.setTextFill(SOMLayout.WHITE); + seriesBtn.setText(null); + + // Set Image + ImageView imageView = new ImageView(SOMLayout.SERIES_PHOTO_IMAGE); + + seriesBtn.setGraphic(imageView); + + //INTERACTION + //Set Action after Series Button is pressed + EventHandler seriesCapturePressedEventHandler = new EventHandler() { + public void handle(MouseEvent event) { + // Feedback (Button gets lesstransparent) + seriesBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }; + //Set Action after series Button is released + EventHandler seriesCaptureReleasedEventHandler = new EventHandler() { + public void handle(MouseEvent event) { + + // Feedback (Button gets less transparent) + seriesBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Shoot series (true means series Mode) + SOMGUI.captureCtl.shoot(true); + } + + }; //Set Action after Series Button is pressed + EventHandler seriesCapturePressedTouchEventHandler = new EventHandler() { + public void handle(TouchEvent event) { + // Feedback (Button gets lesstransparent) + seriesBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }; + //Set Action after series Button is released + EventHandler seriesCaptureReleasedTouchEventHandler = new EventHandler() { + public void handle(TouchEvent event) { + + // Feedback (Button gets less transparent) + seriesBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Shoot series (true means series Mode) + SOMGUI.captureCtl.shoot(true); + } + + }; + // Set Mouse Press Action + seriesBtn.setOnMousePressed(seriesCapturePressedEventHandler); + + // Set Mouse Release Action + seriesBtn.setOnMouseReleased(seriesCaptureReleasedEventHandler); + // Set Mouse Press Action + seriesBtn.setOnTouchPressed(seriesCapturePressedTouchEventHandler); + + // Set Mouse Release Action + seriesBtn.setOnTouchReleased(seriesCaptureReleasedTouchEventHandler); + } + + private void setGalleryBtn() { + // get the button height & width + int height = (SOMLayout.screenHeight / 4); + + // set the Button height & width + galleryBtn.setPrefSize(height, height); + + // Make it a circle + galleryBtn.setBackground(SOMLayout.getTransparentBG10rounded(height / 2)); + + //Set Text Color + galleryBtn.setTextFill(SOMLayout.WHITE); + galleryBtn.setText(null); + + // Set Image + ImageView imageView = new ImageView(SOMLayout.GALLERY_IMAGE); + + galleryBtn.setGraphic(imageView); + + // Set Mouse Press Action + galleryBtn.setOnMousePressed(new EventHandler() { + public void handle(MouseEvent event) { + // Feedback + galleryBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4)); + } + }); + + // Set Mouse Release Action + galleryBtn.setOnMouseReleased(new EventHandler() { + public void handle(MouseEvent event) { + + // Feedback + galleryBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4)); + + // Action + action(); + } + + // Action Performed + private void action() { + SOMGUI.changetogallery(); + } + }); + } + + private void setImage() { + // Set the image aspect ratio to be preserved + image.setPreserveRatio(true); + + // Set the image to the image View + Image splash = SOMLayout.SPLASH_IMAGE; + image.setImage(splash); + + // make it fit the height of the Screen + image.setFitHeight(SOMLayout.screenHeight); + + // Get the Event Images + List somImageList = SOMEvent.getInstance().getImages(); + int numberOfImages = somImageList.size(); + + if (numberOfImages != 0) { + // Set the last Image of the session + SOMImage somImage = somImageList.get(numberOfImages - 1); + + // update the Image State + // TODO Probably not necessary + somImage.updateImageState(); + + // Scale the Image if needed + ScaleWorker.scale(somImage, ScaleWorker.PREVIEW); + + // set the Image to UI + image.setImage(new Image(somImage.getPrv().toURI().toString())); + } + } +} diff --git a/src/main/java/GUI/SOMGUI.java b/src/main/java/GUI/SOMGUI.java new file mode 100644 index 0000000..3d3be91 --- /dev/null +++ b/src/main/java/GUI/SOMGUI.java @@ -0,0 +1,126 @@ +package GUI; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.stage.StageStyle; +import model.SOMLayout; +import workers.FilesWorker; + +/** + * Created by Simon on 13.06.2016. + */ +public class SOMGUI extends Application { + + + // picture + // gallery + // upload + // capture + // warn + + // CONTROLLER + public static PictureCtl pictureCtl; + public static GalleryCtl galleryCtl; + public static UploadCtl uploadCtl; + public static CaptureCtl captureCtl; + public static WarnCtl warnCtl; + // STAGE + private static Stage thestage; + // PANES + private static Parent picture; + private static Parent gallery; + private static Parent upload; + private static Parent capture; + private static Parent warn; + //SCENES + private static Scene pictureScene; + private static Scene galleryScene; + private static Scene uploadScene; + private static Scene captureScene; + private static Scene warnScene; + // INSTANCE + private static SOMGUI somgui; + + protected SOMGUI() throws Exception { + // set up the scenes + FXMLLoader pictureLoader = new FXMLLoader(getClass().getResource("/fxml/picture.fxml")); + picture = pictureLoader.load(); + pictureCtl = pictureLoader.getController(); + + FXMLLoader galleryLoader = new FXMLLoader(getClass().getResource("/fxml/gallery.fxml")); + gallery = galleryLoader.load(); + galleryCtl = galleryLoader.getController(); + + FXMLLoader uploadLoader = new FXMLLoader(getClass().getResource("/fxml/upload.fxml")); + upload = uploadLoader.load(); + uploadCtl = uploadLoader.getController(); + + FXMLLoader captureLoader = new FXMLLoader(getClass().getResource("/fxml/capture.fxml")); + capture = captureLoader.load(); + captureCtl = captureLoader.getController(); + + FXMLLoader warnLoader = new FXMLLoader(getClass().getResource("/fxml/warn.fxml")); + warn = warnLoader.load(); + warnCtl = warnLoader.getController(); + + // Initialize the Scenes + pictureScene = new Scene(picture, SOMLayout.screenWidth, SOMLayout.screenHeight); + galleryScene = new Scene(gallery, SOMLayout.screenWidth, SOMLayout.screenHeight); + uploadScene = new Scene(upload, SOMLayout.screenWidth, SOMLayout.screenHeight); + captureScene = new Scene(capture, SOMLayout.screenWidth, SOMLayout.screenHeight); + warnScene = new Scene(warn, SOMLayout.screenWidth, SOMLayout.screenHeight); + } + + public static SOMGUI getInstance() throws Exception { + if (somgui == null) { + somgui = new SOMGUI(); + } + return somgui; + } + + public static void changetopicture() { + thestage.setScene(pictureScene); + } + + public static void changetogallery() { + thestage.setScene(galleryScene); + } + + public static void changetoupload() { + thestage.setScene(uploadScene); + } + + public static void changetocapture() { + thestage.setScene(captureScene); + } + + public static void changetowarn() { + thestage.setScene(warnScene); + } + + @Override + public void start(Stage primaryStage) throws Exception { + // make the Stage Accessible + thestage = primaryStage; + + // remove all borders + thestage.initStyle(StageStyle.UNDECORATED); + // set stage to fullscreen + thestage.setFullScreen(true); + // set the upper left X & Y position of the stage + thestage.setX(0); + thestage.setY(0); + + // set stage visible + thestage.show(); + + // Set the Upload scene + changetoupload(); + // Start Upload Process + FilesWorker.upload(); + // Set the Picture scene + } +} \ No newline at end of file diff --git a/src/main/java/GUI/UploadCtl.java b/src/main/java/GUI/UploadCtl.java new file mode 100644 index 0000000..20555f6 --- /dev/null +++ b/src/main/java/GUI/UploadCtl.java @@ -0,0 +1,154 @@ +package GUI; + +import javafx.fxml.FXML; +import javafx.geometry.HPos; +import javafx.scene.control.Label; +import javafx.scene.control.ProgressBar; +import javafx.scene.image.ImageView; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import javafx.scene.paint.Color; +import model.SOMLayout; + +/** + * Controller for upload.fxml UI + * Created by Simon on 10.05.2016. + */ +public class UploadCtl { + + + @FXML + public ProgressBar folderProgressBar; + @FXML + public ProgressBar pictureProgressBar; + @FXML + public ProgressBar cleanProgressBar; + @FXML + public ImageView folderImageView; + @FXML + public ImageView pictureImageView; + @FXML + public ImageView cleanImageView; + @FXML + public Label headLabel; + @FXML + public Label folderLabel; + @FXML + public Label picLabel; + @FXML + public Label cleanLabel; + @FXML + private Pane pane; + @FXML + private GridPane grid; + + public UploadCtl() { + + } + + /** + * Set Up the UI + * each part of the UI is accessed via the Setter + */ + public void initialize() { +// Set up the Upload UI parts + +// basic structure + setPane(); + setGrid(); + +// headline + setHeadLbl(); + +// folder row + setFolderIV(); + setFolderLbl(); + setFolderProg(); + +// picture row + setPicIV(); + setPicLbl(); + setPicProg(); + +// cleanup row + setCleanIV(); + setCleanLbl(); + setCleanProg(); + } + + private void setPane() { + pane.setPrefSize(SOMLayout.screenWidth, SOMLayout.screenHeight); + pane.setBackground(SOMLayout.BLACK_BG); + } + + private void setGrid() { + grid.setPrefSize(SOMLayout.screenWidth, SOMLayout.screenHeight); + GridPane.setHalignment(folderImageView, HPos.CENTER); + GridPane.setHalignment(folderLabel, HPos.CENTER); + GridPane.setHalignment(folderProgressBar, HPos.CENTER); + + GridPane.setHalignment(pictureImageView, HPos.CENTER); + GridPane.setHalignment(picLabel, HPos.CENTER); + GridPane.setHalignment(pictureProgressBar, HPos.CENTER); + + GridPane.setHalignment(cleanImageView, HPos.CENTER); + GridPane.setHalignment(cleanLabel, HPos.CENTER); + GridPane.setHalignment(cleanProgressBar, HPos.CENTER); + + GridPane.setHalignment(headLabel, HPos.CENTER); + } + + private void setFolderProg() { + folderProgressBar.setPrefSize(SOMLayout.screenWidth, 3); + } + + private void setPicProg() { + pictureProgressBar.setPrefSize(SOMLayout.screenWidth, 3); + } + + private void setCleanProg() { + cleanProgressBar.setPrefSize(SOMLayout.screenWidth, 3); + } + + private void setFolderIV() { + folderImageView.setImage(SOMLayout.GALLERY_IMAGE); + } + + private void setPicIV() { + folderImageView.setImage(SOMLayout.GALLERY_IMAGE); + } + + private void setCleanIV() { + folderImageView.setImage(SOMLayout.GALLERY_IMAGE); + } + + private void setHeadLbl() { + headLabel.setTextFill(Color.web("#ffffff")); + } + + private void setFolderLbl() { + folderLabel.setTextFill(Color.web("#ffffff")); + } + + private void setPicLbl() { + picLabel.setTextFill(Color.web("#ffffff")); + } + + private void setCleanLbl() { + cleanLabel.setTextFill(Color.web("#ffffff")); + } + + // set the progress +// public void setFolderProgress(double value) { +// folderProgressBar.setProgress(value); +// System.out.println("Folder Progress set to: "+ value); +// } + + public void setPicProgress(double value) { + pictureProgressBar.setProgress(value); + } + + public void setCleanProgress(double value) { + pictureProgressBar.setProgress(value); + } +} diff --git a/src/main/java/GUI/WarnCtl.java b/src/main/java/GUI/WarnCtl.java new file mode 100644 index 0000000..03cc00d --- /dev/null +++ b/src/main/java/GUI/WarnCtl.java @@ -0,0 +1,9 @@ +package GUI; + +/** + * Created by Simon on 13.06.2016. + */ +public class WarnCtl { + public void initialize() { + } +} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7f36481 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Start + diff --git a/src/main/java/Start.java b/src/main/java/Start.java new file mode 100644 index 0000000..51fd226 --- /dev/null +++ b/src/main/java/Start.java @@ -0,0 +1,30 @@ +/** + * Created by Simon on 10.05.2016. + */ + +import GUI.SOMGUI; +import model.SOMConfig; +import model.SOMEvent; + +public class Start extends SOMGUI { + public Start() throws Exception { + } + + public static void main(String[] args) throws Exception { + // Log the start + System.out.println("Gestartet!"); + + // Start the UI + launch(args); + + // Set up the backend + // get configuration + SOMConfig config = SOMConfig.getInstance(); + config.readConfig(); + + // get event instance + SOMEvent event = SOMEvent.getInstance(); + event.getEventImages(); + + } +} diff --git a/src/main/java/model/SOMConfig.java b/src/main/java/model/SOMConfig.java new file mode 100644 index 0000000..79f3164 --- /dev/null +++ b/src/main/java/model/SOMConfig.java @@ -0,0 +1,120 @@ +package model; + +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.util.Calendar; + +@XmlRootElement(name = "Config") +public class SOMConfig { + + + // important Paths + @XmlElement(name = "PICTURES_PATH") + public static final File PICTURES_PATH = new File("images"); + // The Box's ID + // Todo Throw out!! or by MAC Adress + @XmlElement(name = "BOX_ID") + public static final String BOX_ID = "selfomat-42"; + // Number of pictures in series mode + @XmlElement(name = "SERIES_COUNTER") + public static final int SERIES_COUNTER = 4; + // Seconds before image is taken + @XmlElement(name = "COUNTDOWN_COUNTER") + public static final int COUNTDOWN_COUNTER = 3; + // Images per Page in the Gallery + public static final int IMAGES_PER_PAGE = 9; + // Make the Scaling Algorithm switchable + public static final int SCALING_GRAPHICS_2D = 0; + public static final int SCALING_IMAGE_ICON = 1; + public static final int SCALING_JAVAFX = 2; + public static final int SCALING_ALGORITHM = SCALING_GRAPHICS_2D; + // Path to configfile + //TODO Resource?? + private static final File configfile = new File(SOMLayout.class.getResource("/config/config.xml").getFile()); + // Instance + 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); + } + + // Instance + public static SOMConfig getInstance() { + // Singleton Pattern + if (config == null) { + config = new SOMConfig(); + } + return config; + } + + // Write Config + private void writeConfig() { + try { + + // TODO catch possible fail + 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() { + // 1) create a java calendar instance + Calendar calendar = Calendar.getInstance(); + + // 2) get a java.util.Date from the calendar instance. + // this date will represent the current instant, or "now". + java.util.Date now = calendar.getTime(); + + // 3) a java current time (now) instance + java.sql.Timestamp c = new java.sql.Timestamp(now.getTime()); + return c.getTime(); + } + +} \ No newline at end of file diff --git a/src/main/java/model/SOMEvent.java b/src/main/java/model/SOMEvent.java new file mode 100644 index 0000000..7b2622b --- /dev/null +++ b/src/main/java/model/SOMEvent.java @@ -0,0 +1,175 @@ +package model; + +import workers.FilesWorker; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** + * @author simon + */ +public class SOMEvent { + /** + * The instance for the Singleton + */ + private static SOMEvent event = null; + /** + * The Event Date + */ + private final Date date = new Date(); + /** + * All images form the Event + */ + private final List images = new ArrayList(); + /** + * The currently selected image + */ + private SOMImage currentimage; + /** + * Makes the getEventImages function unusable after first use + */ + private boolean imagesread = false; + + /** + * Event Constructor + */ + private SOMEvent() { + } + + /** + * Returns an Instance of the Event (Singleton) + * + * @return + */ + public static SOMEvent getInstance() { + // Singleton to prevent Instantiation + if (event == null) { + event = new SOMEvent(); + // event.currentimage = SOMImage.getFallbackImage(); + } + + return event; + } + + /** + * Returns the List of Images already shot at the event if SOM is turned off + * in between. Gets unfunctional after one time use caused by imagesread + * boolean. + */ + public void getEventImages() { + // Behandelt + if (!imagesread) { + + File[] files = FilesWorker.getSourcePath().listFiles(); + + assert files != null; + Arrays.sort(files); + + for (File file : files) { + SOMImage img = new SOMImage(file.getName()); + img.updateImageState(); + this.addImage(img); + } + + imagesread = true; + } +// return; + } + + /** + * Adds the Given Image to the Events' Image List + * + * @param now + * @return + */ + public void addImage(SOMImage now) { + images.add(now); + } + + /** + * Returns the Events' Date + * + * @return the date + */ + public Date getDate() { + return date; + } + + /** + * Returns a List of all of the Events' images + * + * @return the images + */ + public List getImages() { + // If there are no Event Images Collected + if (images.size() == 0) + // get all the events' images + getEventImages(); + //...and return them + return images; + } + + /** + * returns the last image shot + * + * @return + */ + public SOMImage getLastImage() { + SOMImage[] imagesarr = this.images.toArray(new SOMImage[this.images + .size()]); + + return imagesarr[imagesarr.length - 1]; + } + + /** + * Returns the Icon of the last shot image and sets the "current image" to + * this one + * + * @return + */ + public void createAndSetLastImage() { + this.currentimage = getLastImage(); + // this.currenticon = +// makeIcon(this.currentimage); + // return currenticon; + } + + /** + * Sets the given Image as the Current Image, creates a Preview and sets it + * to UI + * + * @param + */ + public void createAndSetImage(SOMImage image) { + this.currentimage = image; + // this.currenticon = +// makeIcon(this.currentimage); + // return currenticon; + } + + + /** + * Sets the given ImageIcon as the current Icon + *

+ * // * @param ImageIcon + * small + */ + public void setCurrentIcon() { + /* + The ImageIcon of the currently shown Image + */ + } + + /** + * Returns the Current Image for the Print Panel to pass to the System + * Printing Queue + * + * @return + */ + public SOMImage getCurrentimage() { + return currentimage; + } +} \ No newline at end of file diff --git a/src/main/java/model/SOMImage.java b/src/main/java/model/SOMImage.java new file mode 100644 index 0000000..3b114ae --- /dev/null +++ b/src/main/java/model/SOMImage.java @@ -0,0 +1,175 @@ +package model; + +import workers.FilesWorker; + +import javax.swing.*; +import java.io.File; +import java.nio.file.Files; + +public class SOMImage { + + private static String name; // the filename + private final SOMConfig config = SOMConfig.getInstance(); + private final File tmb; // thumbnail + private final File prv; // preview + private final File src; // source + private final File fnl; // final + private final File tmp; // temp + + private boolean tmbthere; // thumbnail status + private boolean prvthere; // preview status + private boolean srcthere; // source status + private boolean fnlthere; // final status + + SOMImage(String name) { + + File src = new File(FilesWorker.getSourcePath().toString() + "/" + name); + + File prv = new File(FilesWorker.getPreviewPath().toString() + "/" + + name); + + File tmb = new File(FilesWorker.getThumbPath().toString() + "/" + name); + + File fnl = new File(FilesWorker.getFinalPath().toString() + "/" + name); + + File tmp = new File(FilesWorker.getTempPath().toString() + "/" + name); + + this.tmb = tmb; + this.prv = prv; + this.src = src; + this.fnl = fnl; + this.tmp = tmp; + + this.updateImageState(); + } + + public SOMImage() { + super(); + + int numberOfEventPictures = SOMEvent.getInstance().getImages().size(); + String fill = "00000"; + int nmb = (numberOfEventPictures + 1); + String number = String.valueOf(nmb); + String filledNumber = fill.substring(number.length()) + number; + name = filledNumber + ".jpg"; + + File src = new File(FilesWorker.getSourcePath().toString() + "/" + name); + File prv = new File(FilesWorker.getPreviewPath().toString() + "/" + name); + File tmb = new File(FilesWorker.getThumbPath().toString() + "/" + name); + File fnl = new File(FilesWorker.getFinalPath().toString() + "/" + name); + File tmp = new File(FilesWorker.getTempPath().toString() + "/" + name); + + this.tmb = tmb; + this.prv = prv; + this.src = src; + this.fnl = fnl; + this.tmp = tmp; + + this.updateImageState(); + } + + public void updateImageState() { + // tmb + tmbthere = Files.exists(tmb.toPath()); + // prv + prvthere = Files.exists(prv.toPath()); + // src + srcthere = Files.exists(src.toPath()); + // fnl + fnlthere = Files.exists(fnl.toPath()); + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the tmb + */ + public File getTmb() { + return this.tmb; + } + + /** + * @return the prv + */ + public File getPrv() { + return prv; + } + + /** + * @return the src + */ + public File getSrc() { + return src; + } + + /** + * @return the fnl + */ + public File getFnl() { + return fnl; + } + + /** + * @return the tmp + */ + public File getTmp() { + return tmp; + } + + /** + * @return the tmbthere + */ + public boolean isTmbthere() { + return tmbthere; + } + + /** + * @return the prvthere + */ + public boolean isPrvthere() { + return prvthere; + } + + /** + * @return the srcthere + */ + public boolean isSrcthere() { + return srcthere; + } + + /** + * @return the fnlthere + */ + public boolean isFnlthere() { + return fnlthere; + } + + /** + * @param type 0 = thumb, 1 = preview, 2 = full Size + * @return + */ + public ImageIcon toImageIcon(int type) { + File imagepath; + switch (type) { + case 0: + imagepath = getTmb(); + break; + case 1: + imagepath = getPrv(); + break; + case 2: + imagepath = getSrc(); + break; + default: + imagepath = null; + break; + } + + return new ImageIcon(imagepath.getPath()); + } +} diff --git a/src/main/java/model/SOMLanguage.java b/src/main/java/model/SOMLanguage.java new file mode 100644 index 0000000..16b4702 --- /dev/null +++ b/src/main/java/model/SOMLanguage.java @@ -0,0 +1,16 @@ +package model; + +public class SOMLanguage { + // for Testing + public static final String pre = ""; + // for Use +// public static String pre = "/resources"; + /** + * Languagestring of the Button that switches back one Panel + */ + // public static final String UIBtnBack = "Zurück"; + /** + * Tells People to SMILE! + */ + public static final String UIBtnSmile = "SMILE"; +} diff --git a/src/main/java/model/SOMLayout.java b/src/main/java/model/SOMLayout.java new file mode 100644 index 0000000..f8f5c9a --- /dev/null +++ b/src/main/java/model/SOMLayout.java @@ -0,0 +1,77 @@ +package model; + +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; +import javafx.stage.Screen; + +import java.awt.*; + +public class SOMLayout { + // Fonts + public static final Font H_0 = new Font(Font.SANS_SERIF, 1, 150); + public static final Font H_1 = new Font(Font.SANS_SERIF, 1, 100); + public static final Font H_2 = new Font(Font.SANS_SERIF, 1, 75); + public static final Font P = new Font(Font.SANS_SERIF, 1, 50); + // Icons & Images + //UI + public static final javafx.scene.image.Image GALLERY_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_Gallery.png").toString()); + public static final javafx.scene.image.Image SINGLE_PHOTO_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_CaptureSingle.png").toString()); + public static final javafx.scene.image.Image SERIES_PHOTO_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_CaptureSeries.png").toString()); + public static final javafx.scene.image.Image PRINT_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_Print.png").toString()); + public static final javafx.scene.image.Image PICTURE_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_Picture.png").toString()); + public static final javafx.scene.image.Image SMILE_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_Smiley.png").toString()); //TODO LINK right image + public static final javafx.scene.image.Image BACK_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_Back.png").toString()); //TODO LINK right image + public static final javafx.scene.image.Image FORTH_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMIcons_Forth.png").toString()); //TODO LINK right image + //CI + public static final javafx.scene.image.Image LOGO_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMLogo.png").toString()); + public static final javafx.scene.image.Image SPLASH_IMAGE = new javafx.scene.image.Image(ClassLoader.class.getResource("/img/SOMSplash.jpg").toString()); + public static final javafx.scene.paint.Color WHITE = new javafx.scene.paint.Color(1, 1, 1, 1); + public static final Background WHITE_BG = new Background(new BackgroundFill(WHITE, null, null)); + // Screen +// private static final GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + private static final javafx.geometry.Rectangle2D gd = Screen.getPrimary().getBounds(); + public static final int screenWidth = (int) gd.getWidth(); + public static final int screenHeight = (int) gd.getHeight(); + // Layout + private static final int row = screenHeight / 3; + private static final int column = screenWidth / 4; + // Colors + private static final javafx.scene.paint.Color BLACK = new javafx.scene.paint.Color(0, 0, 0, 1); + //Backgrounds + public static final Background BLACK_BG = new Background(new BackgroundFill(BLACK, null, null)); + private static final javafx.scene.paint.Color TRANSPARENT_10 = new javafx.scene.paint.Color(0.05, 0.05, 0.05, 0.6); + public static final Background TRANSPARENT_10_BG = new Background(new BackgroundFill(TRANSPARENT_10, null, null)); + private static final javafx.scene.paint.Color TRANSPARENT_20 = new javafx.scene.paint.Color(0.05, 0.05, 0.05, 0.8); + public static final Background TRANSPARENT_20_BG = new Background(new BackgroundFill(TRANSPARENT_20, null, null)); + private static final Background TRANSPARENT_10_BG_ROUNDED = new Background(new BackgroundFill(TRANSPARENT_10, new CornerRadii(12), null)); + private static final Background TRANSPARENT_20_BG_ROUNDED = new Background(new BackgroundFill(TRANSPARENT_20, new CornerRadii(12), null)); + + public static int getRow(int span) { + return row * span; + } + + public static int getColumn(int span) { + return column * span; + } + + public static Background getTransparentBG10rounded(int radius) { + return new Background( + new BackgroundFill( + TRANSPARENT_10_BG_ROUNDED.getFills().get(0).getFill(), + new CornerRadii(radius), + TRANSPARENT_10_BG_ROUNDED.getFills().get(0).getInsets() + ) + ); + } + + public static Background getTransparentBG20rounded(int radius) { + return new Background( + new BackgroundFill( + TRANSPARENT_20_BG_ROUNDED.getFills().get(0).getFill(), + new CornerRadii(radius), + TRANSPARENT_20_BG_ROUNDED.getFills().get(0).getInsets() + ) + ); + } +} \ No newline at end of file diff --git a/src/main/java/workers/CaptureWorker.java b/src/main/java/workers/CaptureWorker.java new file mode 100644 index 0000000..88d983b --- /dev/null +++ b/src/main/java/workers/CaptureWorker.java @@ -0,0 +1,51 @@ +/** + * + */ +package workers; + +import model.SOMImage; + +import java.io.IOException; +import java.nio.file.Files; + +import static java.nio.file.StandardCopyOption.ATOMIC_MOVE; + +/** + * @author Simon Gehrig + */ +class CaptureWorker { + + /** + * Captures an image and returns it + * + * @return the SOMImage captured or null in case of failure + */ + public static SOMImage now() { + SOMImage image = new SOMImage(); + try { + // get a process taking the image + ProcessBuilder builder = new ProcessBuilder( + "gphoto2", + "--capture-image-and-download", + "--filename=" + image.getTmp().toString()); + builder.redirectErrorStream(true); + + // launch capture! + Process process = builder.start(); + + // wait for the process to end + if (process.waitFor() == 0) { + + // MOVE & RENAME THE IMAGE + Files.move(image.getTmp().toPath(), image.getSrc().toPath(), ATOMIC_MOVE); + } else { + System.out.println("Capture Process failed"); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return image; + } +} diff --git a/src/main/java/workers/FilesWorker.java b/src/main/java/workers/FilesWorker.java new file mode 100644 index 0000000..529db55 --- /dev/null +++ b/src/main/java/workers/FilesWorker.java @@ -0,0 +1,510 @@ +package workers; + +import GUI.SOMGUI; +import javafx.concurrent.Task; +import javafx.fxml.FXMLLoader; +import model.SOMConfig; +import model.SOMEvent; +import model.SOMImage; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.DirectoryFileFilter; +import org.apache.commons.io.filefilter.TrueFileFilter; + +import javax.activation.MimetypesFileTypeMap; +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.file.*; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static java.nio.file.StandardWatchEventKinds.*; + +public class FilesWorker { + + private static final SOMEvent event = SOMEvent.getInstance(); + + public FilesWorker() { + + } + + /** + * Returns true if a File is an image and returns false if not. + * + * @param path + * @return + */ + public static boolean isImage(Path path) { + File f = path.toFile(); + String mimeType = new MimetypesFileTypeMap().getContentType(f); + String type = mimeType.split("/")[0]; + return type.equals("image"); + } + + /** + * Returns the Path to the Source (direct from Camera) images directory, or + * if a File of one of the other Folders is given the Source File' Path + * + * @return + */ + public static File getSourcePath() { + File src = new File(getEventPicDir().toString() + "/src"); + + // TODO catch possible fail + src.mkdirs(); + return src; + } + + /** + * Returns the Path to the Preview Images (Full Screen) images directory, or + * if a File of one of the other Folders is given the Preview File' Path + * + * @return + */ + public static File getPreviewPath() { + File prv = new File(getEventPicDir().toString() + "/prv"); + + // TODO catch possible fail + prv.mkdirs(); + return prv; + } + + /** + * Returns the Path to the Thumbnail (Gallery) images directory, or if a + * File of one of the other Folders is given the Thumbnail File' Path + * + * @return + */ + public static File getThumbPath() { + File tmb = new File(getEventPicDir().toString() + "/tmb"); + + // TODO catch possible fail + tmb.mkdirs(); + return tmb; + } + + /** + * Returns the Path to the Final images directory, or if a File of one of + * the other Folders is given the Final Files' Path + * + * @return + */ + public static File getFinalPath() { + File fnl = new File(getEventPicDir().toString() + "/fnl"); + + // TODO catch possible fail + fnl.mkdirs(); + return fnl; + } + + /** + * Returns the Path to the Temporary (pre-source) images directory, or if a + * File of one of the other Folders is given the Thumbnail File' Path + * + * @return + */ + public static File getTempPath() { + File tmp = new File(getEventPicDir().toString() + "/tmp"); + + // TODO catch possible fail + tmp.mkdirs(); + return tmp; + } + + /** + * Gets the Directory for the Event and Creates the Folders + * + * @return + */ + private static File getEventPicDir() { + DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); + + String timeString = df.format(event.getDate()); + + String boxID = SOMConfig.BOX_ID; + + File picturesPath = SOMConfig.PICTURES_PATH; + + File eventPicDir = new File(picturesPath.toString() + "/" + timeString + + "/" + boxID); + + // TODO catch possible fail + eventPicDir.mkdirs(); + + return eventPicDir; + } + + private static boolean internet() { + + Socket sock = new Socket(); + InetSocketAddress socketAddress = new InetSocketAddress("google.com", 80); + + try { + sock.connect(socketAddress, 3000); + System.out.println("Internet available"); + return true; + } catch (IOException e) { + System.out.println("Internet NOT available"); + return false; + } finally { + try { + sock.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public static void upload() { + try { + + // Get all Files in the image Folder + List images = allFilesForUpload(); + // Lists for either dirs or pictures + List dirs = new ArrayList(); + List pics = new ArrayList(); + + //relative ones +// int directoriesUploaded = 0; +// int picturesUploaded = 0; + + // Check for internet connection + if (internet()) { + + // Count Files and Dirs + for (int i = 0; i < images.size(); i++) { + + // get the current file + File file = images.get(i); + + System.out.println(file); + + // get dirs + if (file.isDirectory() + && !file.toString().contains("prv") + && !file.toString().contains("tmb") + && !file.toString().contains("tmp") + && !file.toString().contains("fnl")) { + dirs.add(file); + + } + // get pics + else if (file.isFile() + && file.toPath().toString().contains("src")) { + pics.add(file); + } + } + +// REPORT TO CONSOLE + System.out.println(dirs.size() + " Directories"); + System.out.println(pics.size() + " Pics"); + // GET THE UI + + + FXMLLoader fxmlLoader = new FXMLLoader(); + try { + fxmlLoader.setLocation( + FilesWorker.class.getClassLoader().getResource("fxml/upload.fxml") + ); + + fxmlLoader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + + int i = 0; + List limitdirs = new ArrayList(); + // TODO Limit Uploads + for (File dir : dirs + ) { + + i++; + + System.out.println("Queueing Dir " + dir.toString()); + limitdirs.add(dir); + if (limitdirs.size() >= 3 || limitdirs.size() == i) { + + System.out.println("Launch Dir upload"); + uploadDir(limitdirs); + + System.out.println("Clear Queue"); + limitdirs.clear(); + } + } +// uploadDir(dirs); + List limitpics = new ArrayList(); + for (File pic : pics + ) { + i++; + System.out.println("Queueing Dir " + pic.toString()); + limitpics.add(pic); + if (limitpics.size() >= 3 || limitdirs.size() == i) { + + System.out.println("Launch Pic upload"); + uploadFile(limitpics); + + System.out.println("Clear Queue"); + limitpics.clear(); + } + } +// uploadFile(pics); + + SOMGUI.changetopicture(); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void uploadFile(final List files) throws Exception { + final Thread[] threads = new Thread[files.size()]; + + for (int i = 0; i < threads.length; i++) { + + System.out.println("launch Upload Process: " + i); + + final File file = files.get(i); + + final int pictureCounter = i + 1; + Task task = new Task() { + + @Override + protected Boolean call() throws Exception { + // build the upload process + // TODO remove -k option (this option skips certificate verification) + ProcessBuilder builder = new ProcessBuilder( + "curl", + "-T", + file.toString(), + "-u", + "upload:geheim", + "https://cloud.selfom.at/remote.php/webdav/" + file.toString().replace("/src", ""), + "-k"); + + // make the process traceable + builder.redirectErrorStream(true); + + + Process process = builder.start(); + // launch upload process + + // wait for the process to end + if (process.waitFor() == 0) { + // process ended successful + System.out.println("file uploaded: " + file); + + // TODO get the length of all threads + // TODO bind to UI + updateProgress(pictureCounter, threads.length); + + return true; + + } else { + // process ended failing + // TODO Catch failed uploads + System.out.println("process ended failing " + file); + Thread.sleep(1000); + return false; + } + } + }; + + SOMGUI.uploadCtl.pictureProgressBar.progressProperty().bind(task.progressProperty()); + + threads[i] = new Thread(task); + threads[i].setDaemon(true); + threads[i].start(); + } + int i = 0; + while (i < threads.length) { + threads[i].join(); + i++; + } +//TODO Catch fails + } + + private static void uploadDir(final List dirs) throws Exception { + + final Thread[] threads = new Thread[dirs.size()]; + for (int i = 0; i < threads.length; i++) { + + System.out.println("launch mkdir Process: " + i); + + final File dir = dirs.get(i); + final int directoryCounter = i + 1; + Task task = new Task() { + + @Override + protected Boolean call() throws Exception { + // build the Upload process with curl + // TODO remove -k option (this option skips certificate verification) + ProcessBuilder builder = new ProcessBuilder("curl", + "-u", + "upload:geheim", + "-X", + "MKCOL", + "https://cloud.selfom.at/remote.php/webdav/" + dir.toString().replace("/src", ""), + "-k"); + + // make the process traceable + builder.redirectErrorStream(true); + + // launch upload process + Process process = builder.start(); + + // wait for the process to end + if (process.waitFor() == 0) { + // Process ended successful + System.out.println("directory made: " + dir); + + //Set upload Progress + // TODO get the length of all threads + // TODO bind to UI + updateProgress(directoryCounter, threads.length); + return true; + + } else { + // Process ended failing + System.out.println("process ended failing " + dir); + return false; + } + } + }; + + SOMGUI.uploadCtl.folderProgressBar.progressProperty().bind(task.progressProperty()); + + // Start the Task + threads[i] = new Thread(task); + threads[i].setDaemon(true); + threads[i].start(); + } // End of loop + + // Join the tasks + int i = 0; + while (i < threads.length) { + threads[i].join(); + i++; + } + + //TODO Catch upload fails + } + + private static List allFilesForUpload() { + + File dir = SOMConfig.PICTURES_PATH; + + Collection filesAndDirs = FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, DirectoryFileFilter.DIRECTORY); + + return new ArrayList(filesAndDirs); + } + + // TODO static?? + public static SOMImage waitForImageAndCapture() { + //Behandelt + try { + + // Set the Source Path to be watched + Path dir = getSourcePath().toPath(); + + // REGISTER WATCH SERVICE + WatchService watcher = FileSystems.getDefault().newWatchService(); + dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); + + System.out.println("Watch Service registered for dir: " + + dir.getFileName()); + + // TRIGGER THE CAPTURE + System.out.println("START CAPTURE THREAD"); + SOMImage newImage = CaptureWorker.now(); + + while (true) { + + WatchKey key; + + try { + key = watcher.take(); + } catch (InterruptedException ex) { + return newImage; + } + + for (WatchEvent event : key.pollEvents()) { + WatchEvent.Kind kind = event.kind(); + + @SuppressWarnings("unchecked") + WatchEvent ev = (WatchEvent) event; + Path fileName = ev.context(); + + System.out.println(kind.name() + ": " + fileName); + // check for a file being created + if ( + // Make sure there is an Image created + kind == ENTRY_CREATE + // Check that filename is the same as expected image + && fileName.toString().equals( + newImage.getSrc().getName())) { + + //Set the Progress Indicator to 0.5 + SOMGUI.captureCtl.pictureLoadIndicator.setProgress(0.5); + + // START THE "PICTURE HAS ARRIVED" ACTION + System.out.println("The image is there!!!"); + + // ADD THE IMAGE TO THE EVENT + FilesWorker.event.addImage(newImage); + + // Set last Image + System.out.println("Set the taken Picture to UI"); + FilesWorker.event.createAndSetImage(FilesWorker.event.getLastImage()); + + // Hide the Progress Indicator + SOMGUI.captureCtl.pictureLoadIndicator.setVisible(false); + // Set back the Progress Indicator + SOMGUI.captureCtl.pictureLoadIndicator.setProgress(-1); + + //Close Watcher + watcher.close(); + } else if ( + // Make sure there is an Image created + kind == ENTRY_CREATE + // Check that filename is the same as expected image + && !fileName.toString().equals( + newImage.getSrc().getName())) { + // TODO Catch wrong pictures, only for testing + // Hide the Progress Indicator + SOMGUI.captureCtl.pictureLoadIndicator.setVisible(false); + // Set back the Progress Indicator + SOMGUI.captureCtl.pictureLoadIndicator.setProgress(-1); + + //Close Watcher + watcher.close(); + } + + } + + + boolean valid = key.reset(); + if (!valid) { + break; + } + } + + // return the new image + newImage.updateImageState(); + return newImage; + + } catch (IOException ex) { + System.err.println(ex); + return null; + } + + } +} diff --git a/src/main/java/workers/PrintWorker.java b/src/main/java/workers/PrintWorker.java new file mode 100644 index 0000000..d4aa9e2 --- /dev/null +++ b/src/main/java/workers/PrintWorker.java @@ -0,0 +1,236 @@ +package workers; + +//import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +// import org.cups4j.PrintJob; + +/** + * + */ +public class PrintWorker implements Runnable { + private static Thread queueWorker = null; + private static PrintWorker instance; + // TODO Add Printer Model Code + private final List waitQueue = new ArrayList(); + private final List workQueue = new ArrayList(); + private final File printcountfile = new File("src/main/resources/config/printcount"); + private File imagetransfer = null; + private int copiestransfer = 0; + private int printcount = getPrintcount(); + + /** + * + */ + private PrintWorker(int copies, File image) { + + this.imagetransfer = image; + this.copiestransfer = copies; + + if (queueWorker == null) { + queueWorker = new Thread(this); + queueWorker.setName("SOMPrintQueue"); + queueWorker.start(); + } + } + + /** + * @param copies + * @param image + */ + public static void print(int copies, File image) { + + if (instance == null) { + instance = new PrintWorker(copies, image); + } else { + instance.addPrint(copies, image); + } + } + + /** + * + */ + public static void resumePrint() { + synchronized (queueWorker) { + System.out.println("resume print thread"); + queueWorker.notify(); + } + } + + public Thread getQueueWorker() { + return queueWorker; + } + + private void addPrint(int copies, File image) { + + // add to Print Queue + for (int i = 0; i < copies; i++) { + waitQueue.add(image); + } + } + + /** + * + */ + private void workQueue() { + if (printcountfile.exists()) { + printcount = getPrintcount(); + } + // Refresh working queue (if there is anything to refresh) + if (waitQueue.size() != 0) { + for (File image : + waitQueue) { + // switch files over from wait to work + workQueue.add(image); +// waitQueue.remove(image); + } + // TODO Recursion may do this + waitQueue.removeAll(waitQueue); + } + + // work all the workQueue Files + if (workQueue.size() != 0) { + for (File image : + workQueue) { + + // Halt the Process if anything is empty + if (printcount % 36 == 0) { + // Check Paper (18 per Package) +// MainFrame mf = MainFrame.getInstance(); +// JPanel cp = (JPanel) mf.getContentPane(); +// CardLayout cl = (CardLayout) cp.getLayout(); +// +// WarnPanel.getInstance().setTextText("Bitte Papier und Farbe wechseln"); + +// cl.show(cp, "warn"); + + try { + synchronized (queueWorker) { + System.out.println("pause print thread"); + queueWorker.wait(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + // Todo set printcount to 0 + + } else if (printcount % 18 == 0) { +// // Check Ink (36 per Package) +// MainFrame mf = MainFrame.getInstance(); +// JPanel cp = (JPanel) mf.getContentPane(); +// CardLayout cl = (CardLayout) cp.getLayout(); +// +// WarnPanel.getInstance().setTextText("Bitte Papier wechseln"); +// cl.show(cp, "warn"); + + try { + synchronized (queueWorker) { + System.out.println("pause print thread"); + queueWorker.wait(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + sendToPrinter(image); + System.out.println("Drucke " + printcount); + + // Timeout in Milliseconds + try { + System.out.println("Going to Sleep"); + Thread.sleep(65000); + System.out.println("Waking Up"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + //remove the just printed File from Queue +// workQueue.remove(image); + addPrintcount(); + } + + workQueue.removeAll(workQueue); + + workQueue(); + + } + + // Recurse + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + workQueue(); + } + + + /** + * @param image + */ + private void sendToPrinter(File image) { + // Bild in Druckwarteschlange einfügen + String command = "lp " + image.toString(); + System.out.println(command); + + try { + Process child = Runtime.getRuntime().exec(command); + System.out.println(child.getErrorStream().toString()); + addPrintcount(); + } catch (IOException e) { + System.out.println("Print Failed"); + e.printStackTrace(); + } + } + + /** + * + */ + private void addPrintcount() { + // Count up the prints + printcount++; + // Write printcount to File (for recovery) +// try { +// FileUtils.writeStringToFile(printcountfile, Integer.toString(printcount)); +// } catch (IOException e) { +// e.printStackTrace(); +// } + } + + /** + * @return + */ + private int getPrintcount() { + if (printcount == 0) { + if (printcountfile.exists()) { + System.out.println("printcount is 0, Prontcountfile exists"); +// try { +// // read printcount File +// printcount = Integer.parseInt(FileUtils.readFileToString(printcountfile)); +// } catch (IOException e) { +// e.printStackTrace(); +// } + } else { + printcount = 0; + } + } + return printcount; + } + + /** + * + */ + public void run() { + // TODO run implementation + + addPrint(copiestransfer, imagetransfer); + + // work down print Queue + workQueue(); + + } +} diff --git a/src/main/java/workers/ScaleWorker.java b/src/main/java/workers/ScaleWorker.java new file mode 100644 index 0000000..5d167d1 --- /dev/null +++ b/src/main/java/workers/ScaleWorker.java @@ -0,0 +1,514 @@ +package workers; + +import javafx.concurrent.Task; +import javafx.embed.swing.SwingFXUtils; +import model.SOMConfig; +import model.SOMImage; +import model.SOMLayout; + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.awt.image.CropImageFilter; +import java.awt.image.FilteredImageSource; +import java.io.File; +import java.io.IOException; + +public class ScaleWorker extends Thread { + + public static final int SOURCE = 0; + public static final int PREVIEW = 1; + public static final int THUMBNAIL = 2; + + SOMConfig config = SOMConfig.getInstance(); + + public static SOMImage scale(SOMImage somImage1, final int type) { + + final SOMImage somImage = somImage1; + Task task = new Task() { + @Override + protected SOMImage call() throws Exception { + // Do the scale work + return prepareandStart(somImage, type); + } + }; + + // open Thread + Thread thread = new Thread(task); + // start Thread + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + //return the somImage1 + return somImage1; + } + + // Overload of scale() that lets you enter Arrays of Pictures + public static SOMImage[] scale(SOMImage[] somImages, int type) { + // loop through Array of SOMImages + for (SOMImage image : somImages) { + //update the image + image = scale(image, type); + } + // return the imagearray + return somImages; + } + + private static SOMImage prepareandStart(SOMImage somImage, int type) { + + + // the image before scaling +// Image sourceImage; + // the image after scaling +// Image resultImage; + + // type of image to be used to scale down + int source = SOURCE; + + // check for scaled versions of the image + somImage.updateImageState(); + + // preview + if (type == PREVIEW) { + // check if the requested image already exists + if (somImage.isPrvthere()) + // exit the scaler + return somImage; + + // The requested image does not exist, + } + + // thumbnail + if (type == THUMBNAIL) { + // check if the requested image already exists + if (somImage.isTmbthere()) { + return somImage; + } + // The requested image does not exist, + // check for Preview to scale faster + if (somImage.isPrvthere()) { + source = PREVIEW; + } + + } + + // In any other case we need to scale the + // full sized image, which is default + + somImage = generateScaledImage(somImage, type, source); + + return somImage; + } + + private static SOMImage generateScaledImage(SOMImage somImage, int target, int source) { + // the source image size + double sourceWidth = 0; + double sourceHeight = 0; + + // the scaled sources width and height + // before cropping + int scaledSourceHeight; + int scaledSourceWidth; + + // the later image size + int targetWidth = 0; + int targetHeight = 0; + + // Aspect ratio before cropping + double sourceAspect; + // The ImageViews' cropped aspect ratio + double targetAspect; + + // Source File + File sourceFile = somImage.getSrc(); + // Target File + File targetFile = null; + + // ImageIcons + ImageIcon sourceImageIcon; + ImageIcon targetImageIcon; + + // JAVAFX Images + javafx.scene.image.Image targetImage; + + // Buffered Images + BufferedImage scaledSourceBufferedImage; + BufferedImage croppedBufferedImage; + + // Graphics for Buffered Images + Graphics2D scaledSourceGraphics; + Graphics croppedGraphics; + + // get the target IMAGE SIZES + // and the target FILE + switch (target) { + + // for the preview + case PREVIEW: + targetWidth = SOMLayout.screenWidth; + targetHeight = SOMLayout.screenHeight; + + targetFile = somImage.getPrv(); + + // for the Thumbnail + break; + case THUMBNAIL: + targetWidth = SOMLayout.getColumn(1); + targetHeight = SOMLayout.getRow(1); + + targetFile = somImage.getTmb(); + break; + } + + // get the SOURCE FILE + switch (source) { + case SOURCE: + sourceFile = somImage.getSrc(); + break; + case PREVIEW: + sourceFile = somImage.getPrv(); + break; + } + + switch (SOMConfig.SCALING_ALGORITHM) { + + // GRAPHICS 2D ---------------------------------------------------------- + case SOMConfig.SCALING_GRAPHICS_2D: { + // Generate an ImageIcon from the Source File + sourceImageIcon = new ImageIcon(sourceFile.getPath()); + + // the sources original width and height + sourceWidth = sourceImageIcon.getIconWidth(); + sourceHeight = sourceImageIcon.getIconHeight(); + + // Calculate the aspect ratio before cropping + sourceAspect = (sourceWidth) / (sourceHeight); + + // Calculate the ImageViews' cropped aspect ratio + targetAspect = ((double) targetWidth) / ((double) targetHeight); + + // if picture is higher than frame + if (sourceAspect < targetAspect) { + scaledSourceHeight = (int) Math.ceil(targetWidth / sourceAspect); + scaledSourceWidth = targetWidth; + } + + // if Picture is narrower (or equal) + else { + scaledSourceWidth = (int) Math.ceil(targetHeight * sourceAspect); + scaledSourceHeight = targetHeight; + } + + // Probably way faster than ImageIcon + System.out.println("Scale with Graphics2D:"); + + // Print the File Path + System.out.println(sourceFile.toString()); + + // Print the Sizes + System.out.println("Size now: " + sourceWidth + "px X " + sourceHeight + "px"); + System.out.println("Size between: " + scaledSourceWidth + "px X " + scaledSourceHeight + "px"); + System.out.println("Size after: " + targetWidth + "px X " + targetHeight + "px"); + + // SCALE ----------------------------------------------------------- + // THE ------------------------------------------------------------- + // SOURCE ---------------------------------------------------------- + + // Get the ImageIcon + Image sourceImageIconImage = sourceImageIcon.getImage(); + System.out.println("Got the ImageIcon"); + + // Open a buffered Image in the specified size + // (with no data at this point --> black image) + scaledSourceBufferedImage = new BufferedImage( + scaledSourceWidth, + scaledSourceHeight, + BufferedImage.TYPE_INT_RGB + ); + System.out.println("Got the BufferedImage"); + + // Get the Graphics2D + scaledSourceGraphics = scaledSourceBufferedImage.createGraphics(); + System.out.println("Got the Graphics2D"); + + // Set the Rendering hints + scaledSourceGraphics.setRenderingHint( + RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR + ); + System.out.println("Rendering Hints Set"); + + // Actually Scale the Image + scaledSourceGraphics.drawImage(sourceImageIconImage, 0, 0, scaledSourceWidth, scaledSourceHeight, null); + System.out.println("IMAGE SCALED"); + + scaledSourceGraphics.dispose(); + // System Resources Released + // TODO Can we use this for perormance?? + + System.out.println("Got the target Image Icon"); + + + // Calculate the Offsets + int wOffset; + int hOffset; + + // CROP ------------------------------------------------------------ + // THE ------------------------------------------------------------- + // IMAGE ----------------------------------------------------------- + + if (sourceAspect > targetAspect) { + hOffset = 0; + wOffset = (scaledSourceWidth - targetWidth) / 2; + } else { + hOffset = (scaledSourceHeight - targetHeight) / 2; + wOffset = 0; + } + + System.out.println("Got the Offset for cropping"); + + System.out.println("Get the Crop Image Filter"); + + CropImageFilter cropimgf = new CropImageFilter( + // Crop by moving the image half the way + // it is wider to the left + wOffset, + // Crop by moving the image half the way + // it is higher to the top + hOffset, + + targetWidth, + targetHeight + ); + + System.out.println("Ready"); + + System.out.println("Get the Filtered image Source"); + + FilteredImageSource producer = new FilteredImageSource( + scaledSourceBufferedImage.getSource(), + cropimgf + ); + + System.out.println("Ready"); + + System.out.println("Get the target Image"); + Image image = Toolkit.getDefaultToolkit().createImage( + producer + ); + System.out.println("Ready"); + + System.out.println("Get the target image Icon"); + targetImageIcon = new ImageIcon( // TODO Veeeery slow on raspberry + image + ); + System.out.println("Ready"); + // TODO Check if there is something in the Image Icon on RPi + System.out.println("IMAGE CROPPED"); + + // save the smaller image + croppedBufferedImage = new BufferedImage( + targetWidth, + targetHeight, + BufferedImage.TYPE_INT_RGB + ); + + System.out.println("Got the BufferedImage after CROPPING"); + croppedGraphics = croppedBufferedImage.getGraphics(); + System.out.println("Got the Graphics"); + + croppedGraphics.drawImage(targetImageIcon.getImage(), 0, 0, null); + + System.out.println("Graphics drawn"); + + // WRITE --------------------------------------------------------------- + // THE ----------------------------------------------------------------- + // IMAGE --------------------------------------------------------------- + + System.out.println("Writing Thumb"); + + System.out.println("Trying to write image to " + targetFile.toString()); + System.out.println(croppedBufferedImage.toString()); + // TODO Breaking up at this point on the RPi --> Look at older ScaleWorker + + writeJPEG(targetFile, croppedBufferedImage); + + System.out.println("Image Writer returned: " +// + iw + ); + + + // UPDATE --------------------------------------------------------------- + // IMAGE ---------------------------------------------------------------- + // STATE ---------------------------------------------------------------- + + somImage.updateImageState(); + + System.out.println("Image State Updated"); + +// Clean up + croppedGraphics.dispose(); + scaledSourceGraphics.dispose(); + + image.flush(); + sourceImageIconImage.flush(); + + System.gc(); + + break; + } + case SOMConfig.SCALING_IMAGE_ICON: { +// // IMAGE ICON ---------------------------------------------------------- +// // Generate an ImageIcon from the Source File +// sourceImage = new javafx.scene.image.Image(sourceFile.toString()); +// // the sources original width and height +// sourceWidth = sourceImage.getWidth(); +// sourceHeight = sourceImage.getHeight(); +// +// // Calculate the aspect ratio before cropping +// sourceAspect = (sourceWidth) / (sourceHeight); +// // Calculate the ImageViews' cropped aspect ratio +// targetAspect = ((double) targetWidth) / ((double) targetHeight); +// +// // if picture is higher than frame +// if (sourceAspect < targetAspect) { +// scaledSourceHeight = (int) Math.ceil(targetWidth / sourceAspect); +// scaledSourceWidth = targetWidth; +// } +// +// // if Picture is narrower (or equal) +// else { +// scaledSourceWidth = (int) Math.ceil(targetHeight * sourceAspect); +// scaledSourceHeight = targetHeight; +// } +// +// //Way too slow for the RPi +// System.out.println("Scale with ImageIcon"); +// +// // Scale to right size, +// // no cropping +// targetImageIcon = new ImageIcon( +// sourceImageIcon.getImage().getScaledInstance( +// scaledSourceWidth, scaledSourceHeight, +// Image.SCALE_FAST +// )); +// +// +// // Calculate the Offsets +// int wOffset; +// int hOffset; +// +// // ---------- +// // Crop Image +// if (sourceAspect > targetAspect) { +// hOffset = 0; +// wOffset = (scaledSourceWidth - targetWidth) / 2; +// } else { +// hOffset = (scaledSourceHeight - targetHeight) / 2; +// wOffset = 0; +// } +// +// System.out.println("Got the Offset for cropping"); +// +// System.out.println("Get the Crop Image Filter"); +// CropImageFilter cropimgf = new CropImageFilter( +// // Crop by moving the image half the way +// // it is wider to the left +// wOffset, +// // Crop by moving the image half the way +// // it is higher to the top +// hOffset, +// +// targetWidth, +// targetHeight +// ); +// System.out.println("Ready"); +// +// System.out.println("Get the Filtered image Source"); +// FilteredImageSource producer = new FilteredImageSource( +// sourceImageIcon.getImage().getSource(), +// cropimgf +// ); +// System.out.println("Ready"); +// +// System.out.println("Get the target Image"); +// Image image = Toolkit.getDefaultToolkit().createImage( +// producer +// ); +// System.out.println("Ready"); +// +// System.out.println("Get the target image Icon"); +// targetImageIcon = new ImageIcon( // TODO Veeeery slow on raspberry +// image +// ); +// System.out.println("Ready"); +// // TODO Check if there is something in the Image Icon on RPi +// System.out.println("IMAGE CROPPED"); +// +// // save the smaller image +// BufferedImage bufferedImage = new BufferedImage( +// targetWidth, +// targetHeight, +// BufferedImage.TYPE_INT_RGB +// ); +// +// System.out.println("Got the BufferedImage after CROPPING"); +// croppedGraphics = bufferedImage.getGraphics(); +// System.out.println("Got the Graphics"); +// +// croppedGraphics.drawImage(targetImageIcon.getImage(), 0, 0, null); +// +// System.out.println("Graphics drawn"); +// +// System.out.println("Writing Thumb"); +// +// System.out.println("Trying to write image to " + targetFile.toString()); +// System.out.println(bufferedImage.toString()); +// // TODO Breaking up at this point on the RPi --> Look at older ScaleWorker +// +// writeJPEG(targetFile, bufferedImage); +// +// System.out.println("Image Writer returned: " +//// + iw +// ); +// somImage.updateImageState(); +// +// System.out.println("Image State Updated"); +// +// somImage.updateImageState(); + break; + } + // JAVAFX ---------------------------------------------------------- + case SOMConfig.SCALING_JAVAFX: { + // Scale with javafx + // FIXME breaks up + targetImage = new javafx.scene.image.Image(sourceFile.toString(), targetWidth, targetHeight, true, false, true); + + BufferedImage bi = SwingFXUtils.fromFXImage(targetImage, null); + writeJPEG(targetFile, bi); + + somImage.updateImageState(); + + System.out.println("Image State Updated"); + + somImage.updateImageState(); + break; + } + } + + + return somImage; + } + + private static void writeJPEG(File targetFile, BufferedImage bi) { + try { + boolean iw = ImageIO.write(bi, "JPEG", targetFile); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7f36481 --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Start + diff --git a/src/main/resources/config/config.xml b/src/main/resources/config/config.xml new file mode 100644 index 0000000..70f7405 --- /dev/null +++ b/src/main/resources/config/config.xml @@ -0,0 +1,6 @@ + + + selfomat-42 + \usr\bin\selfomat + images + diff --git a/src/main/resources/fxml/capture.fxml b/src/main/resources/fxml/capture.fxml new file mode 100644 index 0000000..d473b06 --- /dev/null +++ b/src/main/resources/fxml/capture.fxml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/src/main/resources/fxml/gallery.fxml b/src/main/resources/fxml/gallery.fxml new file mode 100644 index 0000000..47ec4ea --- /dev/null +++ b/src/main/resources/fxml/gallery.fxml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/picture.fxml b/src/main/resources/fxml/picture.fxml new file mode 100644 index 0000000..c3fd3d1 --- /dev/null +++ b/src/main/resources/fxml/picture.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + +