diff --git a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/Main.java b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/FaselApplication.java similarity index 77% rename from fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/Main.java rename to fasel-jfx/src/main/java/de/vanitasvitae/fasel/FaselApplication.java index 459c4c3..bb9042e 100644 --- a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/Main.java +++ b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/FaselApplication.java @@ -1,12 +1,13 @@ -package de.vanitasvitae.fasel.sample; +package de.vanitasvitae.fasel; +import de.vanitasvitae.fasel.ui.container.LoginController; 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 { +public class FaselApplication extends Application { private Stage primaryStage; @@ -14,7 +15,7 @@ public class Main extends Application { public void start(Stage primaryStage) throws Exception{ this.primaryStage = primaryStage; FXMLLoader loader = new FXMLLoader(); - loader.setLocation(getClass().getResource("/fxml/layout/login.fxml")); + loader.setLocation(getClass().getResource("/fxml/container/login_container.fxml")); Parent root = loader.load(); LoginController controller = loader.getController(); controller.setApplication(this); diff --git a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/Controller.java b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/Controller.java deleted file mode 100644 index 592e5bd..0000000 --- a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/Controller.java +++ /dev/null @@ -1,4 +0,0 @@ -package de.vanitasvitae.fasel.sample; - -public class Controller { -} diff --git a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/JavaFXTrayIconSample.java b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/JavaFXTrayIconSample.java deleted file mode 100644 index 80b105f..0000000 --- a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/JavaFXTrayIconSample.java +++ /dev/null @@ -1,180 +0,0 @@ -package de.vanitasvitae.fasel.sample; -import javafx.application.*; -import javafx.geometry.Pos; -import javafx.scene.*; -import javafx.scene.control.Label; -import javafx.scene.layout.*; -import javafx.scene.paint.Color; -import javafx.stage.*; - -import javax.imageio.ImageIO; -import java.io.IOException; -import java.net.URL; -import java.text.*; -import java.util.*; - -// Java 8 code -public class JavaFXTrayIconSample extends Application { - - // one icon location is shared between the application tray icon and task bar icon. - // you could also use multiple icons to allow for clean display of tray icons on hi-dpi devices. - private static final String iconImageLoc = - "http://icons.iconarchive.com/icons/scafer31000/bubble-circle-3/16/GameCenter-icon.png"; - - // application stage is stored so that it can be shown and hidden based on system tray icon operations. - private Stage stage; - - // a timer allowing the tray icon to provide a periodic notification event. - private Timer notificationTimer = new Timer(); - - // format used to display the current time in a tray icon notification. - private DateFormat timeFormat = SimpleDateFormat.getTimeInstance(); - - // sets up the javafx application. - // a tray icon is setup for the icon, but the main stage remains invisible until the user - // interacts with the tray icon. - @Override public void start(final Stage stage) { - // stores a reference to the stage. - this.stage = stage; - - // instructs the javafx system not to exit implicitly when the last application window is shut. - Platform.setImplicitExit(false); - - // sets up the tray icon (using awt code run on the swing thread). - javax.swing.SwingUtilities.invokeLater(this::addAppToTray); - - // out stage will be translucent, so give it a transparent style. - stage.initStyle(StageStyle.TRANSPARENT); - - // create the layout for the javafx stage. - StackPane layout = new StackPane(createContent()); - layout.setStyle( - "-fx-background-color: rgba(255, 255, 255, 0.5);" - ); - layout.setPrefSize(300, 200); - - // this dummy app just hides itself when the app screen is clicked. - // a real app might have some interactive UI and a separate icon which hides the app window. - layout.setOnMouseClicked(event -> stage.hide()); - - // a scene with a transparent fill is necessary to implement the translucent app window. - Scene scene = new Scene(layout); - scene.setFill(Color.TRANSPARENT); - - stage.setScene(scene); - } - - /** - * For this dummy app, the (JavaFX scenegraph) content, just says "hello, world". - * A real app, might load an FXML or something like that. - * - * @return the main window application content. - */ - private Node createContent() { - Label hello = new Label("hello, world"); - hello.setStyle("-fx-font-size: 40px; -fx-text-fill: forestgreen;"); - Label instructions = new Label("(click to hide)"); - instructions.setStyle("-fx-font-size: 12px; -fx-text-fill: orange;"); - - VBox content = new VBox(10, hello, instructions); - content.setAlignment(Pos.CENTER); - - return content; - } - - /** - * Sets up a system tray icon for the application. - */ - private void addAppToTray() { - try { - // ensure awt toolkit is initialized. - java.awt.Toolkit.getDefaultToolkit(); - - // app requires system tray support, just exit if there is no support. - if (!java.awt.SystemTray.isSupported()) { - System.out.println("No system tray support, application exiting."); - Platform.exit(); - } - - // set up a system tray icon. - java.awt.SystemTray tray = java.awt.SystemTray.getSystemTray(); - URL imageLoc = new URL( - iconImageLoc - ); - java.awt.Image image = ImageIO.read(imageLoc); - java.awt.TrayIcon trayIcon = new java.awt.TrayIcon(image); - - // if the user double-clicks on the tray icon, show the main app stage. - trayIcon.addActionListener(event -> Platform.runLater(this::showStage)); - - // if the user selects the default menu item (which includes the app name), - // show the main app stage. - java.awt.MenuItem openItem = new java.awt.MenuItem("hello, world"); - openItem.addActionListener(event -> Platform.runLater(this::showStage)); - - // the convention for tray icons seems to be to set the default icon for opening - // the application stage in a bold font. - java.awt.Font defaultFont = java.awt.Font.decode(null); - java.awt.Font boldFont = defaultFont.deriveFont(java.awt.Font.BOLD); - openItem.setFont(boldFont); - - // to really exit the application, the user must go to the system tray icon - // and select the exit option, this will shutdown JavaFX and remove the - // tray icon (removing the tray icon will also shut down AWT). - java.awt.MenuItem exitItem = new java.awt.MenuItem("Exit"); - exitItem.addActionListener(event -> { - notificationTimer.cancel(); - Platform.exit(); - tray.remove(trayIcon); - }); - - // setup the popup menu for the application. - final java.awt.PopupMenu popup = new java.awt.PopupMenu(); - popup.add(openItem); - popup.addSeparator(); - popup.add(exitItem); - trayIcon.setPopupMenu(popup); - - // create a timer which periodically displays a notification message. - notificationTimer.schedule( - new TimerTask() { - @Override - public void run() { - javax.swing.SwingUtilities.invokeLater(() -> - trayIcon.displayMessage( - "hello", - "The time is now " + timeFormat.format(new Date()), - java.awt.TrayIcon.MessageType.INFO - ) - ); - } - }, - 5_000, - 60_000 - ); - - // add the application tray icon to the system tray. - tray.add(trayIcon); - } catch (java.awt.AWTException | IOException e) { - System.out.println("Unable to init system tray"); - e.printStackTrace(); - } - } - - /** - * Shows the application stage and ensures that it is brought ot the front of all stages. - */ - private void showStage() { - if (stage != null) { - stage.show(); - stage.toFront(); - } - } - - public static void main(String[] args) throws IOException, java.awt.AWTException { - // Just launches the JavaFX application. - // Due to way the application is coded, the application will remain running - // until the user selects the Exit menu option from the tray icon. - launch(args); - } -} \ No newline at end of file diff --git a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/LoginController.java b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/LoginController.java deleted file mode 100644 index c26579d..0000000 --- a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/LoginController.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.vanitasvitae.fasel.sample; - -import javafx.fxml.FXML; - -public class LoginController extends Controller { - - @FXML - private LoginFragmentController loginFragmentController; - - @FXML - private void initialize() { - - } - - public void setApplication(Main main) { - loginFragmentController.setApplication(main); - } -} diff --git a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/ui/container/LoginController.java b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/ui/container/LoginController.java new file mode 100644 index 0000000..5c0f2a1 --- /dev/null +++ b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/ui/container/LoginController.java @@ -0,0 +1,20 @@ +package de.vanitasvitae.fasel.ui.container; + +import de.vanitasvitae.fasel.FaselApplication; +import de.vanitasvitae.fasel.ui.fragment.LoginFragmentController; +import javafx.fxml.FXML; + +public class LoginController { + + @FXML + private LoginFragmentController loginFragmentController; + + @FXML + private void initialize() { + + } + + public void setApplication(FaselApplication main) { + loginFragmentController.setApplication(main); + } +} diff --git a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/LoginFragmentController.java b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/ui/fragment/LoginFragmentController.java similarity index 83% rename from fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/LoginFragmentController.java rename to fasel-jfx/src/main/java/de/vanitasvitae/fasel/ui/fragment/LoginFragmentController.java index 9722d4d..79a202a 100644 --- a/fasel-jfx/src/main/java/de/vanitasvitae/fasel/sample/LoginFragmentController.java +++ b/fasel-jfx/src/main/java/de/vanitasvitae/fasel/ui/fragment/LoginFragmentController.java @@ -1,10 +1,11 @@ -package de.vanitasvitae.fasel.sample; +package de.vanitasvitae.fasel.ui.fragment; import java.io.IOException; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXPasswordField; import com.jfoenix.controls.JFXTextField; +import de.vanitasvitae.fasel.FaselApplication; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; @@ -23,7 +24,7 @@ public class LoginFragmentController { @FXML private JFXButton button_login; - private Main main; + private FaselApplication main; @FXML private void initialize() { @@ -44,7 +45,7 @@ public class LoginFragmentController { private void switchToMainScene() throws IOException { FXMLLoader loader = new FXMLLoader(); - loader.setLocation(getClass().getResource("/fxml/sample.fxml")); + loader.setLocation(getClass().getResource("/fxml/container/main_container.fxml")); Parent root = loader.load(); Scene scene = new Scene(root, 1200, 741); @@ -53,7 +54,7 @@ public class LoginFragmentController { // primaryStage.show(); } - public void setApplication(Main main) { + public void setApplication(FaselApplication main) { this.main = main; } } diff --git a/fasel-jfx/src/main/resources/fxml/layout/login.fxml b/fasel-jfx/src/main/resources/fxml/container/login_container.fxml similarity index 54% rename from fasel-jfx/src/main/resources/fxml/layout/login.fxml rename to fasel-jfx/src/main/resources/fxml/container/login_container.fxml index 0e3c0d0..7a343dc 100644 --- a/fasel-jfx/src/main/resources/fxml/layout/login.fxml +++ b/fasel-jfx/src/main/resources/fxml/container/login_container.fxml @@ -3,7 +3,12 @@ - + + diff --git a/fasel-jfx/src/main/resources/fxml/sample.fxml b/fasel-jfx/src/main/resources/fxml/container/main_container.fxml similarity index 78% rename from fasel-jfx/src/main/resources/fxml/sample.fxml rename to fasel-jfx/src/main/resources/fxml/container/main_container.fxml index 09eef88..c8594ac 100644 --- a/fasel-jfx/src/main/resources/fxml/sample.fxml +++ b/fasel-jfx/src/main/resources/fxml/container/main_container.fxml @@ -5,13 +5,18 @@ - + - +
@@ -28,7 +33,7 @@
- +
diff --git a/fasel-jfx/src/main/resources/fxml/layout/chat_input_toolbar.fxml b/fasel-jfx/src/main/resources/fxml/elements/chat_input_toolbar.fxml similarity index 88% rename from fasel-jfx/src/main/resources/fxml/layout/chat_input_toolbar.fxml rename to fasel-jfx/src/main/resources/fxml/elements/chat_input_toolbar.fxml index 19932c2..80da4f0 100644 --- a/fasel-jfx/src/main/resources/fxml/layout/chat_input_toolbar.fxml +++ b/fasel-jfx/src/main/resources/fxml/elements/chat_input_toolbar.fxml @@ -5,8 +5,6 @@ diff --git a/fasel-jfx/src/main/resources/fxml/main_headerbar.fxml b/fasel-jfx/src/main/resources/fxml/elements/main_headerbar.fxml similarity index 90% rename from fasel-jfx/src/main/resources/fxml/main_headerbar.fxml rename to fasel-jfx/src/main/resources/fxml/elements/main_headerbar.fxml index 2aff274..ce94887 100644 --- a/fasel-jfx/src/main/resources/fxml/main_headerbar.fxml +++ b/fasel-jfx/src/main/resources/fxml/elements/main_headerbar.fxml @@ -6,7 +6,7 @@ - + diff --git a/fasel-jfx/src/main/resources/fxml/fragment/login.fxml b/fasel-jfx/src/main/resources/fxml/fragment/login.fxml index de56e1c..3bbf73b 100644 --- a/fasel-jfx/src/main/resources/fxml/fragment/login.fxml +++ b/fasel-jfx/src/main/resources/fxml/fragment/login.fxml @@ -6,7 +6,7 @@ -