View Javadoc
1   /*
2    * Tethys: GUI Utilities
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * 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, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.tethys.core.dialog;
18  
19  import io.github.tonywasher.joceanus.tethys.api.base.TethysUINode;
20  import io.github.tonywasher.joceanus.tethys.api.base.TethysUIProgram;
21  import io.github.tonywasher.joceanus.tethys.api.button.TethysUIButton;
22  import io.github.tonywasher.joceanus.tethys.api.control.TethysUIControlFactory;
23  import io.github.tonywasher.joceanus.tethys.api.control.TethysUILabel;
24  import io.github.tonywasher.joceanus.tethys.api.dialog.TethysUIAboutBox;
25  import io.github.tonywasher.joceanus.tethys.api.pane.TethysUIBoxPaneManager;
26  import io.github.tonywasher.joceanus.tethys.core.base.TethysUICoreComponent;
27  import io.github.tonywasher.joceanus.tethys.core.base.TethysUIResource;
28  import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
29  
30  /**
31   * About Box.
32   */
33  public abstract class TethysUICoreAboutBox
34          extends TethysUICoreComponent
35          implements TethysUIAboutBox {
36      /**
37       * Version Prompt.
38       */
39      private static final String PROMPT_VERSION = TethysUIResource.ABOUT_VERSION.getValue();
40  
41      /**
42       * Revision Prompt.
43       */
44      private static final String PROMPT_REVISION = TethysUIResource.ABOUT_REVISION.getValue();
45  
46      /**
47       * BuiltOn Prompt.
48       */
49      private static final String PROMPT_BUILDDATE = TethysUIResource.ABOUT_BUILTON.getValue();
50  
51      /**
52       * OK Text.
53       */
54      private static final String TEXT_OK = TethysUIResource.BUTTON_OK.getValue();
55  
56      /**
57       * InSet size.
58       */
59      private static final int INSET_SIZE = 5;
60  
61      /**
62       * The panel.
63       */
64      private final TethysUIBoxPaneManager thePanel;
65  
66      /**
67       * Constructor.
68       *
69       * @param pFactory the GUI factory
70       */
71      protected TethysUICoreAboutBox(final TethysUICoreFactory<?> pFactory) {
72          /* Access application details */
73          final TethysUIProgram myApp = pFactory.getProgramDefinitions();
74  
75          /* Create the components */
76          final TethysUIControlFactory myFactory = pFactory.controlFactory();
77          final TethysUILabel myProduct = myFactory.newLabel(myApp.getName());
78          final TethysUILabel myVersion = myFactory.newLabel(PROMPT_VERSION + " "
79                  + myApp.getVersion());
80          final TethysUILabel myRevision = myFactory.newLabel(PROMPT_REVISION + " "
81                  + myApp.getRevision());
82          final TethysUILabel myBuild = myFactory.newLabel(PROMPT_BUILDDATE + " "
83                  + myApp.getBuiltOn());
84          final TethysUILabel myCopyright = myFactory.newLabel(myApp.getCopyright());
85  
86          /* Build the OK button */
87          final TethysUIButton myOKButton = pFactory.buttonFactory().newButton();
88          myOKButton.setText(TEXT_OK);
89          myOKButton.getEventRegistrar().addEventListener(e -> closeDialog());
90  
91          /* Layout the panel */
92          thePanel = pFactory.paneFactory().newVBoxPane();
93          thePanel.setBorderPadding(INSET_SIZE);
94          thePanel.addNode(myProduct);
95          thePanel.addNode(myCopyright);
96          thePanel.addStrut();
97          thePanel.addNode(myVersion);
98          thePanel.addNode(myRevision);
99          thePanel.addNode(myBuild);
100         thePanel.addStrut();
101         thePanel.addNode(myOKButton);
102     }
103 
104     /**
105      * Close the Dialog.
106      */
107     protected abstract void closeDialog();
108 
109     @Override
110     public TethysUINode getNode() {
111         return thePanel.getNode();
112     }
113 
114     @Override
115     public void setEnabled(final boolean pEnabled) {
116         thePanel.setEnabled(pEnabled);
117     }
118 
119     @Override
120     public void setVisible(final boolean pVisible) {
121         thePanel.setVisible(pVisible);
122     }
123 
124     @Override
125     public Integer getId() {
126         return thePanel.getId();
127     }
128 }