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 javafx.geometry.Side;
21  import io.github.tonywasher.joceanus.tethys.api.base.TethysUIEvent;
22  import io.github.tonywasher.joceanus.tethys.core.button.TethysUICoreListButtonManager;
23  import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
24  import io.github.tonywasher.joceanus.tethys.javafx.base.TethysUIFXNode;
25  import io.github.tonywasher.joceanus.tethys.javafx.menu.TethysUIFXScrollMenu;
26  
27  /**
28   * PopUp menu that displays a list of checkMenu items.
29   *
30   * @param <T> the item type
31   */
32  public final class TethysUIFXListButtonManager<T extends Comparable<? super T>>
33          extends TethysUICoreListButtonManager<T> {
34      /**
35       * Constructor.
36       *
37       * @param pFactory the GUI factory
38       */
39      TethysUIFXListButtonManager(final TethysUICoreFactory<?> pFactory) {
40          /* Initialise the underlying class */
41          super(pFactory);
42      }
43  
44      @Override
45      public TethysUIFXNode getNode() {
46          return (TethysUIFXNode) super.getNode();
47      }
48  
49      @Override
50      public void setVisible(final boolean pVisible) {
51          getNode().setManaged(pVisible);
52          getNode().setVisible(pVisible);
53      }
54  
55      @Override
56      protected void registerListeners() {
57          /* Set context menu listener */
58          final OceanusEventRegistrar<TethysUIEvent> myRegistrar = getMenu().getEventRegistrar();
59          myRegistrar.addEventListener(TethysUIEvent.NEWVALUE, e -> handleToggleItem());
60          myRegistrar.addEventListener(TethysUIEvent.WINDOWCLOSED, e -> handleMenuClosed());
61      }
62  
63      @Override
64      public TethysUIFXScrollMenu<T> getMenu() {
65          return (TethysUIFXScrollMenu<T>) super.getMenu();
66      }
67  
68      @Override
69      protected void showMenu() {
70          getMenu().showMenuAtPosition(getNode().getNode(), Side.BOTTOM);
71      }
72  
73      @Override
74      public void setPreferredWidth(final Integer pWidth) {
75          getNode().setPreferredWidth(pWidth);
76      }
77  
78      @Override
79      public void setPreferredHeight(final Integer pHeight) {
80          getNode().setPreferredHeight(pHeight);
81      }
82  
83      @Override
84      public void setBorderPadding(final Integer pPadding) {
85          super.setBorderPadding(pPadding);
86          getNode().createWrapperPane(getBorderTitle(), getBorderPadding());
87      }
88  
89      @Override
90      public void setBorderTitle(final String pTitle) {
91          super.setBorderTitle(pTitle);
92          getNode().createWrapperPane(getBorderTitle(), getBorderPadding());
93      }
94  }