You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by mg...@apache.org on 2021/12/19 20:07:46 UTC

[cayenne-modeler] branch master updated: Refactoring and added comments.

This is an automated email from the ASF dual-hosted git repository.

mgentry pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne-modeler.git


The following commit(s) were added to refs/heads/master by this push:
     new 782c8b0  Refactoring and added comments.
782c8b0 is described below

commit 782c8b0808b0c1d3234cef144c1cc47bbf5b791c
Author: Michael Gentry <bl...@gmail.com>
AuthorDate: Sun Dec 19 15:07:08 2021 -0500

    Refactoring and added comments.
---
 .../cayenne/modeler/layout/SplashLayout.java       | 74 +++++++++++++++++-----
 src/main/resources/layouts/SplashLayout.fxml       | 24 ++++---
 2 files changed, 73 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/apache/cayenne/modeler/layout/SplashLayout.java b/src/main/java/org/apache/cayenne/modeler/layout/SplashLayout.java
index c089c7b..c9ea60c 100644
--- a/src/main/java/org/apache/cayenne/modeler/layout/SplashLayout.java
+++ b/src/main/java/org/apache/cayenne/modeler/layout/SplashLayout.java
@@ -40,16 +40,39 @@ import javafx.stage.FileChooser;
 import javafx.stage.Stage;
 import javafx.stage.StageStyle;
 
+/**
+ * The "splash" page for the application. Shown on modeler launch and gives the
+ * choice of opening recent/existing projects or creating a new project.
+ */
 public class SplashLayout extends AbstractWindowLayout
 {
     private static final Logger LOGGER = LoggerFactory.getLogger(SplashLayout.class);
 
+    /**
+     * Outlet to the recent projects ListView.
+     */
     @FXML
-    private ListView<String> projectListView;
+    private ListView<String> recentProjectsListView;
 
+    /**
+     * Outlet to the New Project Button.
+     */
     @FXML
-    private Button newProjectButton, openProjectButton;
+    private Button newProjectButton;
 
+    /**
+     * Outlet to the OpenProject Button.
+     */
+    @FXML
+    private Button openProjectButton;
+
+
+    /**
+     * Create a new splash layout.
+     *
+     * @param initialStage
+     * @throws IOException
+     */
     public SplashLayout(final Stage initialStage) throws IOException
     {
         super(initialStage, "/layouts/SplashLayout.fxml");
@@ -58,19 +81,28 @@ public class SplashLayout extends AbstractWindowLayout
         setResizable(false);
     }
 
+    /**
+     * Initialize the layout with a list of recent projects.
+     */
     public void initialize()
     {
+        // Load the recent projects.
         final ObservableList<String> projects =
             FXCollections.observableArrayList(ModelerPreferences.getLastProjFiles());
 
-        projectListView.setItems(projects);
-        projectListView.getSelectionModel().select(0);
+        // Set the recent projects and pre-select the first entry.
+        recentProjectsListView.setItems(projects);
+        recentProjectsListView.getSelectionModel().select(0);
 
+        // Set the graphics for the new/open button.
         newProjectButton.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.PLUS_SQUARE, "16px"));
         openProjectButton.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.FOLDER_OPEN, "16px"));
     }
 
-    public void onOpenClicked()
+    /**
+     * Callback handler for when the Open Project button is clicked.
+     */
+    public void onOpenProjectClicked()
     {
         try
         {
@@ -104,29 +136,41 @@ public class SplashLayout extends AbstractWindowLayout
         }
     }
 
-    public void onNewClicked()
+    /**
+     * Callback handler for when the New Project button is clicked.
+     */
+    public void onNewProjectClicked()
     {
-        LOGGER.debug("new clicked");
+        LOGGER.debug("new project clicked -- but not implemented");
     }
 
-    public void onOpenProjectSelected(final MouseEvent event)
+    /**
+     * Callback handler for when a recent project is double-clicked.
+     */
+    public void onOpenRecentProject(final MouseEvent event)
     {
-        if (event.getClickCount() == 2)
-            if (projectListView.getItems().size() > 0)
-                openSelectedModel();
+        if (event.getClickCount() == 2 && recentProjectsListView.getItems().size() > 0)
+            openSelectedProject();
     }
 
+    /**
+     * Callback handler for when return/enter is pressed (to open the recent
+     * project).
+     */
     public void onKeyTyped(final KeyEvent event)
     {
-        if (event.getCharacter().equals("\r"))
-            openSelectedModel();
+        if (event.getCharacter().equals("\r") && recentProjectsListView.getItems().size() > 0)
+            openSelectedProject();
     }
 
-    private void openSelectedModel()
+    /**
+     * Opens the selected recent project.
+     */
+    private void openSelectedProject()
     {
         try
         {
-            CayenneModeler.openProject(projectListView.getSelectionModel().getSelectedItem());
+            CayenneModeler.openProject(recentProjectsListView.getSelectionModel().getSelectedItem());
             hide();
         }
         catch (final Exception exception)
diff --git a/src/main/resources/layouts/SplashLayout.fxml b/src/main/resources/layouts/SplashLayout.fxml
index 7b1ab12..e751866 100644
--- a/src/main/resources/layouts/SplashLayout.fxml
+++ b/src/main/resources/layouts/SplashLayout.fxml
@@ -19,14 +19,18 @@
         under the License.
 -->
 
-<?import javafx.geometry.*?>
-<?import javafx.scene.control.*?>
-<?import javafx.scene.text.*?>
-<?import javafx.scene.image.*?>
-<?import java.lang.*?>
-<?import javafx.scene.layout.*?>
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.Button?>
+<?import javafx.scene.control.Label?>
+<?import javafx.scene.control.ListView?>
+<?import javafx.scene.image.Image?>
+<?import javafx.scene.image.ImageView?>
+<?import javafx.scene.layout.AnchorPane?>
+<?import javafx.scene.layout.HBox?>
+<?import javafx.scene.layout.VBox?>
+<?import javafx.scene.text.Font?>
 
-<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
+<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
    <children>
       <ImageView fitHeight="400.0" fitWidth="600.0" layoutX="119.0" layoutY="117.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
          <image>
@@ -40,7 +44,7 @@
                   <Font name="System Bold" size="24.0" />
                </font>
             </Label>
-            <ListView fx:id="projectListView" onKeyTyped="#onKeyTyped" onMouseClicked="#onOpenProjectSelected" prefHeight="200.0" prefWidth="200.0">
+            <ListView fx:id="recentProjectsListView" onKeyTyped="#onKeyTyped" onMouseClicked="#onOpenRecentProject" prefHeight="200.0" prefWidth="200.0">
                <placeholder>
                   <Label text="No previously opened projects found; please open or create a new one." />
                </placeholder>
@@ -50,12 +54,12 @@
             </ListView>
             <HBox alignment="CENTER">
                <children>
-                  <Button fx:id="openProjectButton" graphicTextGap="6.0" mnemonicParsing="false" onAction="#onOpenClicked" prefWidth="200.0" text="Open Different Project">
+                  <Button fx:id="openProjectButton" graphicTextGap="6.0" mnemonicParsing="false" onAction="#onOpenProjectClicked" prefWidth="200.0" text="Open Different Project">
                      <HBox.margin>
                         <Insets right="4.0" />
                      </HBox.margin>
                   </Button>
-                  <Button fx:id="newProjectButton" graphicTextGap="6.0" mnemonicParsing="false" onAction="#onNewClicked" prefWidth="200.0" text="Create New Project">
+                  <Button fx:id="newProjectButton" graphicTextGap="6.0" mnemonicParsing="false" onAction="#onNewProjectClicked" prefWidth="200.0" text="Create New Project">
                      <HBox.margin>
                         <Insets left="4.0" />
                      </HBox.margin>