src/macosx/classes/sun/lwawt/LWTextAreaPeer.java

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 package sun.lwawt;
  28 
  29 import java.awt.Component;

  30 import java.awt.Dimension;
  31 import java.awt.Point;
  32 import java.awt.TextArea;
  33 import java.awt.event.TextEvent;
  34 import java.awt.peer.TextAreaPeer;
  35 
  36 import javax.swing.JScrollBar;
  37 import javax.swing.JScrollPane;
  38 import javax.swing.JTextArea;
  39 import javax.swing.ScrollPaneConstants;
  40 import javax.swing.text.Document;
  41 import javax.swing.text.JTextComponent;
  42 
  43 final class LWTextAreaPeer
  44         extends LWTextComponentPeer<TextArea, LWTextAreaPeer.ScrollableJTextArea>
  45         implements TextAreaPeer {
  46 
  47     private static final int DEFAULT_COLUMNS = 60;
  48     private static final int DEFAULT_ROWS = 10;
  49 


  52         super(target, platformComponent);
  53     }
  54 
  55     @Override
  56     protected ScrollableJTextArea createDelegate() {
  57         return new ScrollableJTextArea();
  58     }
  59 
  60     @Override
  61     public void initialize() {
  62         super.initialize();
  63         final int visibility = getTarget().getScrollbarVisibility();
  64         synchronized (getDelegateLock()) {
  65             setScrollBarVisibility(visibility);
  66         }
  67     }
  68 
  69     @Override
  70     JTextComponent getTextComponent() {
  71         return getDelegate().getView();









  72     }
  73 
  74     @Override
  75     protected Component getDelegateFocusOwner() {
  76         return getTextComponent();
  77     }
  78 
  79     @Override
  80     public Dimension getMinimumSize() {
  81         return getMinimumSize(DEFAULT_ROWS, DEFAULT_COLUMNS);
  82     }
  83 
  84     @Override
  85     public Dimension getMinimumSize(final int rows, final int columns) {
  86         return getPreferredSize(rows, columns);
  87     }
  88 
  89     @Override
  90     public Dimension getPreferredSize(final int rows, final int columns) {
  91         final Dimension size = super.getPreferredSize(rows, columns);




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 package sun.lwawt;
  28 
  29 import java.awt.Component;
  30 import java.awt.Cursor;
  31 import java.awt.Dimension;
  32 import java.awt.Point;
  33 import java.awt.TextArea;
  34 import java.awt.event.TextEvent;
  35 import java.awt.peer.TextAreaPeer;
  36 
  37 import javax.swing.JScrollBar;
  38 import javax.swing.JScrollPane;
  39 import javax.swing.JTextArea;
  40 import javax.swing.ScrollPaneConstants;
  41 import javax.swing.text.Document;
  42 import javax.swing.text.JTextComponent;
  43 
  44 final class LWTextAreaPeer
  45         extends LWTextComponentPeer<TextArea, LWTextAreaPeer.ScrollableJTextArea>
  46         implements TextAreaPeer {
  47 
  48     private static final int DEFAULT_COLUMNS = 60;
  49     private static final int DEFAULT_ROWS = 10;
  50 


  53         super(target, platformComponent);
  54     }
  55 
  56     @Override
  57     protected ScrollableJTextArea createDelegate() {
  58         return new ScrollableJTextArea();
  59     }
  60 
  61     @Override
  62     public void initialize() {
  63         super.initialize();
  64         final int visibility = getTarget().getScrollbarVisibility();
  65         synchronized (getDelegateLock()) {
  66             setScrollBarVisibility(visibility);
  67         }
  68     }
  69 
  70     @Override
  71     JTextComponent getTextComponent() {
  72         return getDelegate().getView();
  73     }
  74 
  75     @Override
  76     protected Cursor getCursor(final Point p) {
  77         final boolean isContains;
  78         synchronized (getDelegateLock()) {
  79             isContains = getDelegate().getViewport().getBounds().contains(p);
  80         }
  81         return isContains ? super.getCursor(p) : null;
  82     }
  83 
  84     @Override
  85     protected Component getDelegateFocusOwner() {
  86         return getTextComponent();
  87     }
  88 
  89     @Override
  90     public Dimension getMinimumSize() {
  91         return getMinimumSize(DEFAULT_ROWS, DEFAULT_COLUMNS);
  92     }
  93 
  94     @Override
  95     public Dimension getMinimumSize(final int rows, final int columns) {
  96         return getPreferredSize(rows, columns);
  97     }
  98 
  99     @Override
 100     public Dimension getPreferredSize(final int rows, final int columns) {
 101         final Dimension size = super.getPreferredSize(rows, columns);