commit a1b14c64ba2e0c6f05d24fcdefe58fa0e47b483f Author: Sebastian Seedorf Date: Sun Dec 6 19:05:19 2020 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d532a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,109 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/intellij +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# End of https://www.toptal.com/developers/gitignore/api/intellij + diff --git a/.idea/artifacts/KinoViewer_jar.xml b/.idea/artifacts/KinoViewer_jar.xml new file mode 100644 index 0000000..71edb28 --- /dev/null +++ b/.idea/artifacts/KinoViewer_jar.xml @@ -0,0 +1,10 @@ + + + $PROJECT_DIR$/out/artifacts/KinoViewer_jar + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..1c24f9a --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2eccbf8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c11f16e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/KinoViewer.iml b/KinoViewer.iml new file mode 100644 index 0000000..615e3ef --- /dev/null +++ b/KinoViewer.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/amd64/libglass.so b/amd64/libglass.so new file mode 100644 index 0000000..e57fd7b Binary files /dev/null and b/amd64/libglass.so differ diff --git a/amd64/libprism_es2.so b/amd64/libprism_es2.so new file mode 100644 index 0000000..dacc883 Binary files /dev/null and b/amd64/libprism_es2.so differ diff --git a/lib/jfxrt.jar b/lib/jfxrt.jar new file mode 100644 index 0000000..51a6f23 Binary files /dev/null and b/lib/jfxrt.jar differ diff --git a/lib/mysql-connector-java-5.1.42-bin.jar b/lib/mysql-connector-java-5.1.42-bin.jar new file mode 100644 index 0000000..4c6df38 Binary files /dev/null and b/lib/mysql-connector-java-5.1.42-bin.jar differ diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..440fa71 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: sample.Main + diff --git a/src/sample/Chair.java b/src/sample/Chair.java new file mode 100644 index 0000000..9caedc2 --- /dev/null +++ b/src/sample/Chair.java @@ -0,0 +1,35 @@ +package sample; + +/** + * Created by sebastian on 09.05.17. + */ +public class Chair { + private final int row; + private final int pos; + private final boolean isUsed; + private final double price; + + public Chair(int row, int pos, boolean isUsed, double price) { + + this.row = row; + this.pos = pos; + this.isUsed = isUsed; + this.price = price; + } + + public int getRow() { + return row; + } + + public int getPos() { + return pos; + } + + public boolean isUsed() { + return isUsed; + } + + public double getPrice() { + return price; + } +} diff --git a/src/sample/ChairIterator.java b/src/sample/ChairIterator.java new file mode 100644 index 0000000..c0dbc25 --- /dev/null +++ b/src/sample/ChairIterator.java @@ -0,0 +1,45 @@ +package sample; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Iterator; + +/** + * Created by sebastian on 09.05.17. + */ +public class ChairIterator implements Iterator { + + private ResultSet resultSet; + private boolean hasNext = false; + + public ChairIterator(ResultSet resultSet) throws SQLException { + this.resultSet = resultSet; + hasNext = resultSet.next(); + } + + @Override + public boolean hasNext() { + return hasNext; + } + + @Override + public Chair next() { + if (!hasNext) { + return null; + } else { + try { + Chair chair = new Chair( + resultSet.getInt("Row"), + resultSet.getInt("Pos"), + resultSet.getBoolean("isUsed"), + resultSet.getDouble("Price") + ); + hasNext = resultSet.next(); + return chair; + } catch (SQLException e) { + e.printStackTrace(); + return null; + } + } + } +} diff --git a/src/sample/ChoiceValue.java b/src/sample/ChoiceValue.java new file mode 100644 index 0000000..adb8e8f --- /dev/null +++ b/src/sample/ChoiceValue.java @@ -0,0 +1,23 @@ +package sample; + +/** + * Created by sebastian on 08.05.17. + */ +public class ChoiceValue { + + private final int key; + private final String value; + + ChoiceValue(int key, String value) { + this.key = key; + this.value = value; + } + + int getKey() { + return key; + } + + public String toString() { + return value; + } +} diff --git a/src/sample/Controller.java b/src/sample/Controller.java new file mode 100644 index 0000000..ee08114 --- /dev/null +++ b/src/sample/Controller.java @@ -0,0 +1,75 @@ +package sample; + +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXML; +import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.control.ChoiceBox; +import javafx.scene.paint.Color; +import javafx.scene.text.TextAlignment; + +import java.sql.SQLException; +import java.util.ArrayList; + +public class Controller { + private static final String CLASS_NAME = Controller.class.getName(); + private DataHandler dataHandler = null; + + @FXML + public ChoiceBox fxChoiceBox; + public Canvas fxCanvas; + + @FXML + public void initialize() { + try { + dataHandler = new DataHandler("sebse.de", 3306, "db_vorlesung", "db_vorlesung", "db_vorlesung"); + ArrayList choices = dataHandler.getPresentations(); + fxChoiceBox.getItems().addAll(choices); + } catch (SQLException e) { + Log.severe(CLASS_NAME, "SQL-Fehler!"); + e.printStackTrace(); + } + + + GraphicsContext context = fxCanvas.getGraphicsContext2D(); + + fxChoiceBox.getSelectionModel().selectedIndexProperty().addListener((ObservableValue observableValue, Number number, Number t1) -> { + + if (dataHandler != null) { + try { + HallDimens dimens = dataHandler.getHallDimentions(fxChoiceBox.getItems().get(t1.intValue()).getKey()); + Log.finer(CLASS_NAME, dimens != null); + if (dimens != null) { + Log.finer(CLASS_NAME, dimens.toString()); + + double width = fxCanvas.getWidth()/(dimens.getWidth()+2); + double height = fxCanvas.getHeight()/(dimens.getHeight()+4); + + context.setFill(Color.LAVENDER); + context.fillRect(0, 0, fxCanvas.getWidth(), fxCanvas.getHeight()); + + context.setStroke(Color.BLACK); + context.setFill(Color.BLACK); + for (ChairIterator iter = dataHandler.getChairIterator(fxChoiceBox.getItems().get(t1.intValue()).getKey()); iter.hasNext(); ) { + Chair chair = iter.next(); + if (chair.isUsed()) + context.fillRect(width*chair.getPos(), height*chair.getRow(), width, height); + else + context.strokeRect(width*chair.getPos(), height*chair.getRow(), width, height); + } + + context.fillRect(width, height*(dimens.getHeight()+2), width*dimens.getWidth(), height); + context.setStroke(Color.RED); + context.setTextAlign(TextAlignment.CENTER); + context.strokeText("Leinwand", fxCanvas.getWidth()/2, height*(dimens.getHeight()+3)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + }); + + context.setFill(Color.LAVENDER); + context.fillRect(0, 0, fxCanvas.widthProperty().doubleValue(), fxCanvas.heightProperty().doubleValue()); + } +} diff --git a/src/sample/DataHandler.java b/src/sample/DataHandler.java new file mode 100644 index 0000000..fade1d7 --- /dev/null +++ b/src/sample/DataHandler.java @@ -0,0 +1,102 @@ +package sample; + +import java.sql.*; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * Created by sebastian on 08.05.17. + */ +public class DataHandler { + private static final String CLASS_NAME = DataHandler.class.getName(); + + private final String host; + private final int port; + private final String user; + private final String pwd; + private String database; + private final Connection connect; + + public DataHandler(String host, int port, String user, String pwd, String database) throws SQLException { + this.host = host; + this.port = port; + this.user = user; + this.pwd = pwd; + this.database = database; + + // This will load the MySQL driver, each DB has its own driver + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + Log.severe(CLASS_NAME, "MySQL driver not found!"); + e.printStackTrace(); + } + // Setup the connection with the DB + connect = DriverManager + .getConnection("jdbc:mysql://"+host+":"+port+"/"+database+"?" + + "user="+user+"&password="+pwd+""); + + } + + public ArrayList getPresentations() throws SQLException { + ArrayList choices = new ArrayList<>(); + + Statement stmt = connect.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT ID, Saalname, Beginn, Filmname FROM v_Vorstellung"); + + while (rs.next()) { + choices.add(new ChoiceValue(rs.getInt("ID"), rs.getString("Saalname")+" - "+rs.getString("Beginn")+" - "+rs.getString("Filmname"))); + } + return choices; + } + + + public HallDimens getHallDimentions(int presID) throws SQLException { + PreparedStatement stmt = connect.prepareStatement( + "SELECT MIN(Sitzplatz.Reihe) `MinReihe`, MIN(Sitzplatz.Platz) `MinPlatz`, " + + "MAX(Sitzplatz.Reihe) `MaxReihe`, MAX(Sitzplatz.Platz) `MaxPlatz` " + + "FROM Saal " + + "JOIN Sitzplatz ON Saal.ID = Sitzplatz.fk_Saal_ID " + + "JOIN Vorstellung ON Saal.ID = Vorstellung.fk_Saal_ID " + + "WHERE Vorstellung.ID=? " + + "GROUP BY Saal.ID" + ); + stmt.setInt(1, presID); + Log.finer(CLASS_NAME, stmt.toString()); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) + return new HallDimens( + rs.getInt("MinPlatz"), + rs.getInt("MinReihe"), + rs.getInt("MaxPlatz"), + rs.getInt("MaxReihe") + ); + else + return null; + } + + + public ChairIterator getChairIterator(int presID) throws SQLException { + PreparedStatement stmt = connect.prepareStatement( + "SELECT *, COUNT(*)=2 `isUsed` FROM ((" + + "SELECT Sitzplatz.Reihe `Row`, Sitzplatz.Platz `Pos`, Sitzplatz.Preis `Price` " + + "FROM Vorstellung " + + "JOIN Saal ON Vorstellung.fk_Saal_ID = Saal.ID " + + "JOIN Sitzplatz ON Saal.ID = Sitzplatz.fk_Saal_ID " + + "WHERE Vorstellung.ID=?" + + ") UNION ALL (" + + "SELECT Sitzplatz.Reihe `Row`, Sitzplatz.Platz `Pos`, Sitzplatz.Preis `Price` " + + "FROM Vorstellung " + + "JOIN Reservierung ON Vorstellung.ID = Reservierung.fk_Vorstellung_ID " + + "JOIN nm_Reservierung_Sitzplatz ON Reservierung.ID = nm_Reservierung_Sitzplatz.fk_Reservierung_ID " + + "JOIN Sitzplatz ON nm_Reservierung_Sitzplatz.fk_Sitzplatz_ID = Sitzplatz.ID " + + "WHERE Vorstellung.ID=?" + + ")) t GROUP BY `Row`, `Pos`, `Price`" + ); + stmt.setInt(1, presID); + stmt.setInt(2, presID); + ResultSet rs = stmt.executeQuery(); + return new ChairIterator(rs); + } + +} diff --git a/src/sample/HallDimens.java b/src/sample/HallDimens.java new file mode 100644 index 0000000..fb67054 --- /dev/null +++ b/src/sample/HallDimens.java @@ -0,0 +1,46 @@ +package sample; + +/** + * Created by sebastian on 08.05.17. + */ +public class HallDimens { + private final int minWidth; + private final int minHeight; + private final int maxWidth; + private final int maxHeight; + + public HallDimens(int minWidth, int minHeight, int maxWidth, int maxHeight) { + this.minWidth = minWidth; + this.minHeight = minHeight; + this.maxWidth = maxWidth; + this.maxHeight = maxHeight; + } + + public int getMinWidth() { + return minWidth; + } + + public int getMinHeight() { + return minHeight; + } + + public int getMaxWidth() { + return maxWidth; + } + + public int getMaxHeight() { + return maxHeight; + } + + public int getWidth() { + return maxWidth-minWidth+1; + } + + public int getHeight() { + return maxHeight-minHeight+1; + } + + public String toString() { + return "mw: "+getMinWidth()+"mh: "+getMinHeight()+"w: "+getWidth()+"h: "+getHeight(); + } +} diff --git a/src/sample/Log.java b/src/sample/Log.java new file mode 100644 index 0000000..2394f84 --- /dev/null +++ b/src/sample/Log.java @@ -0,0 +1,61 @@ +package sample; + +import java.util.HashMap; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Created by sebastian on 08.05.17. + */ +@SuppressWarnings("WeakerAccess") +public class Log { + private static final Level LOG_LEVEL = Level.FINEST; + + + private static HashMap logger = new HashMap<>(); + private static ConsoleHandler consoleHandler; + + public static Logger getLogger(String key) { + if (!logger.containsKey(key)) { + Logger newLogger = Logger.getLogger(key); + newLogger.setLevel(LOG_LEVEL); + newLogger.addHandler(getConsoleHandler()); + logger.put(key, newLogger); + } + + return logger.get(key); + } + + private static ConsoleHandler getConsoleHandler() { + if (consoleHandler == null) { + consoleHandler = new ConsoleHandler(); + consoleHandler.setLevel(Level.FINEST); + } + return consoleHandler; + } + + public static void finer(String key, String log) { + getLogger(key).log(Level.FINER, log); + } + + public static void finer(String key, int log) { + getLogger(key).log(Level.FINER, String.valueOf(log)); + } + + public static void finer(String key, boolean log) { + getLogger(key).log(Level.FINER, String.valueOf(log)); + } + + public static void severe(String key, String log) { + getLogger(key).log(Level.SEVERE, log); + } + + public static void severe(String key, int log) { + getLogger(key).log(Level.SEVERE, String.valueOf(log)); + } + + public static void severe(String key, boolean log) { + getLogger(key).log(Level.SEVERE, String.valueOf(log)); + } +} diff --git a/src/sample/Main.java b/src/sample/Main.java new file mode 100644 index 0000000..fcc9dfe --- /dev/null +++ b/src/sample/Main.java @@ -0,0 +1,27 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Main extends Application { + + @Override + public void start(Stage primaryStage) throws Exception{ + Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); + primaryStage.setTitle("KinoViewer"); + primaryStage.setScene(new Scene(root, 800, 600)); + primaryStage.setMinWidth(800); + primaryStage.setMaxWidth(800); + primaryStage.setMinHeight(600); + primaryStage.setMaxHeight(600); + primaryStage.show(); + } + + + public static void main(String[] args) { + launch(args); + } +} \ No newline at end of file diff --git a/src/sample/sample.fxml b/src/sample/sample.fxml new file mode 100644 index 0000000..aed8013 --- /dev/null +++ b/src/sample/sample.fxml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + +