Refactoring and added comments. master
authorMichael Gentry <blacknext@gmail.com>
Sun, 19 Dec 2021 20:07:08 +0000 (15:07 -0500)
committerMichael Gentry <blacknext@gmail.com>
Sun, 19 Dec 2021 20:07:08 +0000 (15:07 -0500)
src/main/java/org/apache/cayenne/modeler/layout/SplashLayout.java
src/main/resources/layouts/SplashLayout.fxml

index c089c7bd5da8e84c31a06f38bd047d155a94bd17..c9ea60c884c7d69193fc2a635e948b97964c1efe 100644 (file)
@@ -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)
index 7b1ab1268f909a8d51f53e7ee2e5012a5e4a7f55..e75186617bbac477d2d4589996e1e7bc986b3880 100644 (file)
         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>
             </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>