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.pane;
18  
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import io.github.tonywasher.joceanus.tethys.api.base.TethysUIComponent;
24  import io.github.tonywasher.joceanus.tethys.api.pane.TethysUIBoxPaneManager;
25  import io.github.tonywasher.joceanus.tethys.core.base.TethysUICoreComponent;
26  import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
27  import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory.TethysUIParentComponent;
28  
29  /**
30   * Core Box Pane Manager.
31   */
32  public abstract class TethysUICoreBoxPaneManager
33          extends TethysUICoreComponent
34          implements TethysUIBoxPaneManager, TethysUIParentComponent {
35      /**
36       * Strut Size.
37       */
38      private static final int STRUT_SIZE = 4;
39  
40      /**
41       * The id.
42       */
43      private final Integer theId;
44  
45      /**
46       * The ChildManager.
47       */
48      private final TethysUICoreFactory<?> theFactory;
49  
50      /**
51       * Node List.
52       */
53      private final List<TethysUIComponent> theNodeList;
54  
55      /**
56       * The Horizontal Gap.
57       */
58      private Integer theGap;
59  
60      /**
61       * Constructor.
62       *
63       * @param pFactory the Factory
64       */
65      protected TethysUICoreBoxPaneManager(final TethysUICoreFactory<?> pFactory) {
66          theFactory = pFactory;
67          theId = theFactory.getNextId();
68          theNodeList = new ArrayList<>();
69          theGap = STRUT_SIZE;
70      }
71  
72      @Override
73      public Integer getId() {
74          return theId;
75      }
76  
77      @Override
78      public Integer getGap() {
79          return theGap;
80      }
81  
82      @Override
83      public void setGap(final Integer pGap) {
84          theGap = pGap;
85      }
86  
87      /**
88       * Add Spacer Node.
89       *
90       * @param pNode the node
91       */
92      protected void addSpacerNode(final TethysUIComponent pNode) {
93          theNodeList.add(pNode);
94      }
95  
96      @Override
97      public void addNode(final TethysUIComponent pNode) {
98          theNodeList.add(pNode);
99          theFactory.registerChild(this, pNode);
100     }
101 
102     @Override
103     public void setEnabled(final boolean pEnabled) {
104         for (TethysUIComponent myNode : theNodeList) {
105             myNode.setEnabled(pEnabled);
106         }
107     }
108 
109     @Override
110     public Iterator<TethysUIComponent> iterator() {
111         return theNodeList.iterator();
112     }
113 }
114