View Javadoc
1   /*******************************************************************************
2    * jhunters: Pool League
3    * Copyright 2015 Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   ********************************************************************************/
17  package net.sourceforge.jhunters.pool.ui;
18  
19  import javafx.collections.ObservableList;
20  import javafx.event.ActionEvent;
21  import javafx.event.EventHandler;
22  import javafx.geometry.Insets;
23  import javafx.geometry.Pos;
24  import javafx.scene.Node;
25  import javafx.scene.Scene;
26  import javafx.scene.control.Button;
27  import javafx.scene.control.Label;
28  import javafx.scene.layout.VBox;
29  import javafx.stage.Modality;
30  import javafx.stage.Stage;
31  import javafx.stage.StageStyle;
32  
33  /**
34   * About Box.
35   */
36  public class AboutBox extends Stage {
37      /**
38       * Title.
39       */
40      private static final String PROGRAM_TITLE = ProgramResource.TITLE.getValue();
41  
42      /**
43       * Version prompt.
44       */
45      private static final String PROMPT_VERSION = GuiResource.ABOUT_PROMPT_VERSION.getValue();
46  
47      /**
48       * Version.
49       */
50      private static final String PROGRAM_VERSION = ProgramResource.VERSION.getValue();
51  
52      /**
53       * Revision prompt.
54       */
55      private static final String PROMPT_REVISION = GuiResource.ABOUT_PROMPT_REVISION.getValue();
56  
57      /**
58       * Revision.
59       */
60      private static final String PROGRAM_REVISION = ProgramResource.REVISION.getValue();
61  
62      /**
63       * BuiltOn prompt.
64       */
65      private static final String PROMPT_BUILDDATE = GuiResource.ABOUT_PROMPT_BUILDDATE.getValue();
66  
67      /**
68       * Build Date.
69       */
70      private static final String PROGRAM_BUILDDATE = ProgramResource.BUILDDATE.getValue();
71  
72      /**
73       * Copyright.
74       */
75      private static final String PROGRAM_COPYRIGHT = ProgramResource.COPYRIGHT.getValue();
76  
77      /**
78       * OK text.
79       */
80      private static final String TEXT_OK = GuiResource.ABOUT_BUTTON_OK.getValue();
81  
82      /**
83       * InSet size.
84       */
85      private static final int INSET_SIZE = 5;
86  
87      /**
88       * OK Button.
89       */
90      private final Button theOKButton;
91  
92      /**
93       * Constructor.
94       * @param pStage the owning stage
95       */
96      protected AboutBox(final Stage pStage) {
97          /* Undecorated */
98          super(StageStyle.UNDECORATED);
99          initOwner(pStage);
100         initModality(Modality.WINDOW_MODAL);
101 
102         /* Create the components */
103         Label myProduct = new Label(PROGRAM_TITLE);
104         Label myVersion = new Label(PROMPT_VERSION + " "
105                 + PROGRAM_VERSION);
106         Label myRevision = new Label(PROMPT_REVISION + " "
107                 + PROGRAM_REVISION);
108         Label myBuild = new Label(PROMPT_BUILDDATE + " "
109                 + PROGRAM_BUILDDATE);
110         Label myCopyright = new Label(PROGRAM_COPYRIGHT);
111 
112         /* Build the OK button */
113         theOKButton = new Button(TEXT_OK);
114         theOKButton.setMaxWidth(Double.MAX_VALUE);
115         theOKButton.setOnAction(new EventHandler<ActionEvent>() {
116             @Override
117             public void handle(final ActionEvent e) {
118                 close();
119             }
120         });
121 
122         /* Layout the panel */
123         VBox myPanel = new VBox();
124         myPanel.setAlignment(Pos.CENTER);
125         myPanel.setPadding(new Insets(INSET_SIZE, INSET_SIZE, INSET_SIZE, INSET_SIZE));
126         ObservableList<Node> myChildren = myPanel.getChildren();
127         myChildren.addAll(myProduct, myCopyright, new Label());
128         myChildren.addAll(myVersion, myRevision, myBuild, new Label());
129         myChildren.add(theOKButton);
130 
131         /* Define style of VBox */
132         myPanel.getStyleClass().add("-jht-about");
133 
134         /* Create the scene and attach it */
135         Scene myScene = new Scene(myPanel);
136         String myStylesheet = getClass().getResource("AboutBox.css").toExternalForm();
137         myScene.getStylesheets().add(myStylesheet);
138         setScene(myScene);
139     }
140 }