Skip to content
Permalink
Browse files
Refactoring and added comments.
  • Loading branch information
mrg committed Dec 19, 2021
1 parent 89a84f4 commit 782c8b0808b0c1d3234cef144c1cc47bbf5b791c
Showing 2 changed files with 73 additions and 25 deletions.
@@ -40,16 +40,39 @@
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 SplashLayout(final Stage initialStage) throws IOException
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 void onOpenClicked()
}
}

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)
@@ -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>

0 comments on commit 782c8b0

Please sign in to comment.