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.swing.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.TethysUICoreListButtonManager;
22  import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
23  import io.github.tonywasher.joceanus.tethys.swing.base.TethysUISwingNode;
24  import io.github.tonywasher.joceanus.tethys.swing.menu.TethysUISwingScrollMenu;
25  
26  import javax.swing.SwingConstants;
27  
28  /**
29   * PopUp menu that displays a list of checkMenu items.
30   *
31   * @param <T> the item type
32   */
33  public final class TethysUISwingListButtonManager<T extends Comparable<? super T>>
34          extends TethysUICoreListButtonManager<T> {
35      /**
36       * Constructor.
37       *
38       * @param pFactory the GUI factory
39       */
40      TethysUISwingListButtonManager(final TethysUICoreFactory<?> pFactory) {
41          /* Initialise the underlying class */
42          super(pFactory);
43      }
44  
45      @Override
46      public TethysUISwingNode getNode() {
47          return (TethysUISwingNode) super.getNode();
48      }
49  
50      @Override
51      public void setVisible(final boolean 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 TethysUISwingScrollMenu<T> getMenu() {
65          return (TethysUISwingScrollMenu<T>) super.getMenu();
66      }
67  
68      @Override
69      protected void showMenu() {
70          getMenu().showMenuAtPosition(getNode().getNode(), SwingConstants.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  }