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.control;
18  
19  import javax.swing.JTextArea;
20  
21  import io.github.tonywasher.joceanus.tethys.core.factory.TethysUICoreFactory;
22  import io.github.tonywasher.joceanus.tethys.core.control.TethysUICoreTextArea;
23  import io.github.tonywasher.joceanus.tethys.swing.base.TethysUISwingNode;
24  
25  /**
26   * Swing TextArea.
27   */
28  public class TethysUISwingTextArea
29          extends TethysUICoreTextArea {
30      /**
31       * The Node.
32       */
33      private final TethysUISwingNode theNode;
34  
35      /**
36       * TextArea.
37       */
38      private final JTextArea theArea;
39  
40      /**
41       * Constructor.
42       *
43       * @param pFactory the GUI Factory
44       */
45      TethysUISwingTextArea(final TethysUICoreFactory<?> pFactory) {
46          /* Create resources */
47          super(pFactory);
48          theArea = new JTextArea();
49          theArea.setEditable(false);
50          theNode = new TethysUISwingNode(theArea);
51      }
52  
53      @Override
54      public TethysUISwingNode getNode() {
55          return theNode;
56      }
57  
58      @Override
59      public void setEnabled(final boolean pEnabled) {
60          theArea.setEnabled(pEnabled);
61      }
62  
63      @Override
64      public void setVisible(final boolean pVisible) {
65          theArea.setVisible(pVisible);
66      }
67  
68      @Override
69      public void setPreferredWidth(final Integer pWidth) {
70          theNode.setPreferredWidth(pWidth);
71      }
72  
73      @Override
74      public void setPreferredHeight(final Integer pHeight) {
75          theNode.setPreferredHeight(pHeight);
76      }
77  
78      @Override
79      public void setBorderPadding(final Integer pPadding) {
80          super.setBorderPadding(pPadding);
81          theNode.createWrapperPane(getBorderTitle(), getBorderPadding());
82      }
83  
84      @Override
85      public void setBorderTitle(final String pTitle) {
86          super.setBorderTitle(pTitle);
87          theNode.createWrapperPane(getBorderTitle(), getBorderPadding());
88      }
89  
90      @Override
91      public void setText(final String pText) {
92          theArea.setText(pText);
93      }
94  
95      @Override
96      public void appendText(final String pText) {
97          theArea.append(pText);
98      }
99  
100     @Override
101     public void insertText(final String pText,
102                            final int pPos) {
103         theArea.insert(pText, pPos);
104     }
105 
106     @Override
107     public void replaceText(final String pText,
108                             final int pStart,
109                             final int pEnd) {
110         theArea.replaceRange(pText, pStart, pEnd);
111     }
112 
113     @Override
114     public void setCaretPosition(final int pPos) {
115         theArea.setCaretPosition(pPos);
116     }
117 
118     @Override
119     public int getCaretPosition() {
120         return theArea.getCaretPosition();
121     }
122 
123     @Override
124     public int getTextLength() {
125         return theArea.getText().length();
126     }
127 }