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.base;
18
19 import javafx.scene.Node;
20 import javafx.scene.layout.Region;
21
22 import io.github.tonywasher.joceanus.tethys.api.base.TethysUIComponent;
23 import io.github.tonywasher.joceanus.tethys.api.base.TethysUINode;
24
25 /**
26 * javaFX Node.
27 */
28 public class TethysUIFXNode
29 implements TethysUINode {
30 /**
31 * The node.
32 */
33 private final Node theUnderlying;
34
35 /**
36 * The node.
37 */
38 private Node theNode;
39
40 /**
41 * Constructor.
42 *
43 * @param pNode the node
44 */
45 public TethysUIFXNode(final Node pNode) {
46 theUnderlying = pNode;
47 theNode = theUnderlying;
48 }
49
50 /**
51 * Obtain the node that this represents.
52 *
53 * @return the node
54 */
55 public Node getNode() {
56 return theNode;
57 }
58
59 /**
60 * Obtain the node.
61 *
62 * @param pChild the Tethys child component
63 * @return the javaFX node.
64 */
65 public static Node getNode(final TethysUIComponent pChild) {
66 return pChild == null
67 ? null
68 : ((TethysUIFXNode) pChild.getNode()).getNode();
69 }
70
71 /**
72 * Is the node visible?
73 *
74 * @return true/false
75 */
76 public boolean isVisible() {
77 return theNode.isVisible();
78 }
79
80 /**
81 * Set visibility of node.
82 *
83 * @param pVisible set node visible true/false?
84 */
85 public void setVisible(final boolean pVisible) {
86 theNode.setVisible(pVisible);
87 }
88
89 /**
90 * Set managed state of node.
91 *
92 * @param pManaged set node managed true/false?
93 */
94 public void setManaged(final boolean pManaged) {
95 theNode.setManaged(pManaged);
96 }
97
98 /**
99 * Set the preferred width of the underlying node.
100 *
101 * @param pWidth the preferred width
102 */
103 public void setPreferredWidth(final Integer pWidth) {
104 ((Region) theUnderlying).setPrefWidth(pWidth);
105 }
106
107 /**
108 * Set the preferred height of the underlying node.
109 *
110 * @param pHeight the preferred height
111 */
112 public void setPreferredHeight(final Integer pHeight) {
113 ((Region) theUnderlying).setPrefHeight(pHeight);
114 }
115
116 /**
117 * create wrapper pane.
118 *
119 * @param pTitle the title
120 * @param pPadding the padding
121 */
122 public void createWrapperPane(final String pTitle,
123 final Integer pPadding) {
124 theNode = TethysUIFXUtils.getBorderedPane(pTitle, pPadding, theUnderlying);
125 }
126 }