View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
19   */
20  
21  package org.onemind.awtbridge.peer;
22  
23  import java.awt.*;
24  import java.awt.peer.TextAreaPeer;
25  import org.onemind.awtbridge.BridgeContext;
26  /***
27   * A TextArea Peer
28   * @author TiongHiang Lee (thlee@onemindsoft.org)
29   * @version $Id: BridgeTextAreaPeer.java,v 1.3 2005/03/12 23:03:11 thlee Exp $ $Name: awtbridge-1_0_0 $
30   */
31  public class BridgeTextAreaPeer extends BridgeTextComponentPeer
32          implements
33              TextAreaPeer
34  {
35  
36      /***
37       * {@inheritDoc}
38       */
39      public BridgeTextAreaPeer(Object componentObject, BridgeContext context)
40      {
41          super(componentObject, context);
42      }
43  
44      /***
45       * {@inheritDoc}
46       */
47      public Dimension getMinimumSize(int rows, int columns)
48      {
49          return preferredSize(rows, columns);
50      }
51  
52      /***
53       * {@inheritDoc}
54       */
55      public Dimension getPreferredSize(int rows, int columns)
56      {
57          return preferredSize(rows, columns);
58      }
59  
60      /***
61       * {@inheritDoc}
62       */
63      public void insert(String text, int pos)
64      {
65          getTextBuffer().insert(pos, text);
66      }
67  
68      /***
69       * TODO: TBI {@inheritDoc}
70       */
71      public void insertText(String txt, int pos)
72      {
73          getTextBuffer().insert(pos, txt);
74      }
75  
76      /***
77       * {@inheritDoc}
78       */
79      public Dimension minimumSize(int rows, int cols)
80      {
81          return preferredSize(rows, cols);
82      }
83  
84      /***
85       * {@inheritDoc}
86       */
87      public final Dimension preferredSize(int rows, int cols)
88      {
89          FontMetrics m = getCurrentFontMetrics();
90          return new Dimension(cols * m.charWidth('A'), rows * m.getHeight());
91      }
92  
93      /***
94       * {@inheritDoc}
95       * TODO: TBI
96       */
97      public void replaceRange(String text, int start, int end)
98      {
99          getTextBuffer().replace(start, end, text);
100     }
101 
102     /***
103      * {@inheritDoc}
104      * TODO: TBI
105      */
106     public void replaceText(String txt, int start, int end)
107     {
108         getTextBuffer().replace(start, end, txt);
109     }
110 
111     /***
112      * {@inheritDoc}
113      * TODO: TBI
114      */
115     public Dimension preferredSize()
116     {
117         TextArea area = (TextArea) getComponent();
118         return preferredSize(area.getRows(), area.getColumns());
119     }
120 }