b969277877
closed #45
359 lines
11 KiB
Java
359 lines
11 KiB
Java
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.StackPane;
|
|
import model.SOMEvent;
|
|
import model.SOMImage;
|
|
import model.SOMLayout;
|
|
import workers.FilesWorker;
|
|
import workers.ScaleWorker;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* Created by Simon on 13.06.2016.
|
|
*/
|
|
public class PictureCtl {
|
|
@FXML
|
|
public StackPane pane;
|
|
|
|
@FXML
|
|
public GridPane grid;
|
|
|
|
@FXML
|
|
public Button singleBtn;
|
|
@FXML
|
|
public Button seriesBtn;
|
|
@FXML
|
|
public Button galleryBtn;
|
|
@FXML
|
|
public Button printBtn;
|
|
|
|
@FXML
|
|
public ImageView image;
|
|
|
|
// Get the Event Images
|
|
List<SOMImage> somImageList = SOMEvent.getInstance().getImages();
|
|
int numberOfImages = somImageList.size();
|
|
|
|
|
|
public void initialize() {
|
|
|
|
// Basic Layout setup
|
|
setPane();
|
|
setGrid();
|
|
|
|
// Buttons setup
|
|
setGalleryBtn();
|
|
setSeriesBtn();
|
|
setSingleBtn();
|
|
setPrintBtn();
|
|
|
|
// Image Setup
|
|
setImage();
|
|
}
|
|
|
|
private void setPane() {
|
|
pane.setPrefSize(SOMLayout.screenWidth, SOMLayout.screenHeight);
|
|
pane.setBackground(SOMLayout.BLACK_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<MouseEvent>() {
|
|
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<MouseEvent>() {
|
|
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<MouseEvent> seriesCapturePressedEventHandler = new EventHandler<MouseEvent>() {
|
|
public void handle(MouseEvent event) {
|
|
// Feedback (Button gets lesstransparent)
|
|
seriesBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4));
|
|
}
|
|
};
|
|
//Set Action after series Button is released
|
|
EventHandler<MouseEvent> seriesCaptureReleasedEventHandler = new EventHandler<MouseEvent>() {
|
|
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<TouchEvent> seriesCapturePressedTouchEventHandler = new EventHandler<TouchEvent>() {
|
|
public void handle(TouchEvent event) {
|
|
// Feedback (Button gets lesstransparent)
|
|
seriesBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4));
|
|
}
|
|
};
|
|
//Set Action after series Button is released
|
|
EventHandler<TouchEvent> seriesCaptureReleasedTouchEventHandler = new EventHandler<TouchEvent>() {
|
|
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<MouseEvent>() {
|
|
public void handle(MouseEvent event) {
|
|
// Feedback
|
|
galleryBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4));
|
|
}
|
|
});
|
|
|
|
// Set Mouse Release Action
|
|
galleryBtn.setOnMouseReleased(new EventHandler<MouseEvent>() {
|
|
public void handle(MouseEvent event) {
|
|
|
|
// Feedback
|
|
galleryBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4));
|
|
|
|
// Action
|
|
action();
|
|
}
|
|
|
|
// Action Performed
|
|
private void action() {
|
|
SOMGUI.changetogallery();
|
|
}
|
|
});
|
|
}
|
|
|
|
private void setPrintBtn() {
|
|
// get the button height & width
|
|
int height = (SOMLayout.screenHeight / 4);
|
|
|
|
// set the Button height & width
|
|
printBtn.setPrefSize(height, height);
|
|
|
|
// Make it a circle
|
|
printBtn.setBackground(SOMLayout.getTransparentBG10rounded(height / 2));
|
|
|
|
//Set Text Color
|
|
printBtn.setTextFill(SOMLayout.WHITE);
|
|
printBtn.setText(null);
|
|
|
|
// Set Image
|
|
ImageView imageView = new ImageView(SOMLayout.PRINT_IMAGE);
|
|
|
|
printBtn.setGraphic(imageView);
|
|
|
|
// Set Mouse Press Action
|
|
printBtn.setOnMousePressed(new EventHandler<MouseEvent>() {
|
|
public void handle(MouseEvent event) {
|
|
// Feedback
|
|
printBtn.setBackground(SOMLayout.getTransparentBG20rounded(SOMLayout.screenHeight / 4));
|
|
}
|
|
});
|
|
|
|
// Check if active
|
|
if (numberOfImages == 0) {
|
|
printBtn.setDisable(true);
|
|
} else {
|
|
printBtn.setDisable(false);
|
|
}
|
|
|
|
// Set Mouse Release Action
|
|
printBtn.setOnMouseReleased(new EventHandler<MouseEvent>() {
|
|
public void handle(MouseEvent event) {
|
|
|
|
// Feedback
|
|
printBtn.setBackground(SOMLayout.getTransparentBG10rounded(SOMLayout.screenHeight / 4));
|
|
|
|
// Action
|
|
action();
|
|
}
|
|
|
|
// Action Performed
|
|
private void action() {
|
|
FilesWorker.print();
|
|
}
|
|
});
|
|
}
|
|
|
|
private void setImage() {
|
|
// // Set the image aspect ratio to be preserved
|
|
// image.setPreserveRatio(true);
|
|
//
|
|
// // Set the image to the image View
|
|
// Image splash = SOMLayout.LOGO_IMAGE;
|
|
// image.setImage(splash);
|
|
//
|
|
// // make it fit the height of the Screen
|
|
// image.setFitWidth(SOMLayout.screenHeight/2);
|
|
|
|
// Set the image aspect ratio to be preserved
|
|
image.setPreserveRatio(true);
|
|
|
|
// Set the image to the image View
|
|
image.setImage(SOMLayout.LOGO_IMAGE);
|
|
|
|
// make it fit the height of the Screen
|
|
// image.setFitWidth(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);
|
|
|
|
// Get the Event Images
|
|
List<SOMImage> 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 -- commented out to test it
|
|
// 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()));
|
|
|
|
// If the current image is not already set, set the last image
|
|
if (SOMEvent.getInstance().getCurrentimage() == null) {
|
|
SOMEvent event = SOMEvent.getInstance();
|
|
event.createAndSetLastImage();
|
|
event.createAndSetImage(event.getLastImage());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|