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.javafx.button;
18  
19  import io.github.tonywasher.joceanus.oceanus.event.OceanusEventRegistrar;
20  import io.github.tonywasher.joceanus.tethys.api.base.TethysUIEvent;
21  import io.github.tonywasher.joceanus.tethys.core.button.TethysUICoreDateButtonManager;
22  import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
23  import io.github.tonywasher.joceanus.tethys.javafx.base.TethysUIFXNode;
24  
25  /**
26   * JavaFX DateButton Manager.
27   */
28  public final class TethysUIFXDateButtonManager
29          extends TethysUICoreDateButtonManager {
30      /**
31       * The dialog.
32       */
33      private TethysUIFXDateDialog theDialog;
34  
35      /**
36       * Constructor.
37       *
38       * @param pFactory the GuiFactory
39       */
40      TethysUIFXDateButtonManager(final TethysUICoreFactory<?> pFactory) {
41          /* Initialise the super-class */
42          super(pFactory);
43      }
44  
45      @Override
46      public TethysUIFXNode getNode() {
47          return (TethysUIFXNode) super.getNode();
48      }
49  
50      @Override
51      public void setVisible(final boolean pVisible) {
52          getNode().setManaged(pVisible);
53          getNode().setVisible(pVisible);
54      }
55  
56      /**
57       * Obtain the dialog.
58       *
59       * @return the dialog
60       */
61      public TethysUIFXDateDialog getDialog() {
62          ensureDialog();
63          return theDialog;
64      }
65  
66      /**
67       * Make sure that the dialog is created.
68       */
69      private void ensureDialog() {
70          /* If the dialog does not exist */
71          if (theDialog == null) {
72              /* Create it */
73              theDialog = new TethysUIFXDateDialog(getConfig());
74  
75              /* Add listeners */
76              final OceanusEventRegistrar<TethysUIEvent> myRegistrar = theDialog.getEventRegistrar();
77              myRegistrar.addEventListener(TethysUIEvent.PREPAREDIALOG, e -> handleDialogRequest());
78              myRegistrar.addEventListener(TethysUIEvent.NEWVALUE, e -> handleNewValue());
79              myRegistrar.addEventListener(TethysUIEvent.WINDOWCLOSED, e -> handleNewValue());
80          }
81      }
82  
83      @Override
84      protected void showDialog() {
85          /* Make sure that the dialog exists */
86          ensureDialog();
87  
88          /* Show the dialog under the node */
89          theDialog.showDialogUnderNode(getNode().getNode());
90      }
91  
92      @Override
93      public void setPreferredWidth(final Integer pWidth) {
94          getNode().setPreferredWidth(pWidth);
95      }
96  
97      @Override
98      public void setPreferredHeight(final Integer pHeight) {
99          getNode().setPreferredHeight(pHeight);
100     }
101 
102     @Override
103     public void setBorderPadding(final Integer pPadding) {
104         super.setBorderPadding(pPadding);
105         getNode().createWrapperPane(getBorderTitle(), getBorderPadding());
106     }
107 
108     @Override
109     public void setBorderTitle(final String pTitle) {
110         super.setBorderTitle(pTitle);
111         getNode().createWrapperPane(getBorderTitle(), getBorderPadding());
112     }
113 }