1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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
202 @SuppressWarnings("serial")// Safe: outer class is non-serializable.
203 final class ScrollableJTextArea extends JScrollPane {
204
205 ScrollableJTextArea() {
206 super();
207 getViewport().setView(new JTextAreaDelegate());
208 }
209
210 public JTextArea getView() {
211 return (JTextArea) getViewport().getView();
212 }
213
214 @Override
215 public void setEnabled(final boolean enabled) {
216 getViewport().getView().setEnabled(enabled);
217 super.setEnabled(enabled);
218 }
219
220 private final class JTextAreaDelegate extends JTextArea {
221
222 // Empty non private constructor was added because access to this
223 // class shouldn't be emulated by a synthetic accessor method.
224 JTextAreaDelegate() {
225 super();
226 }
227
228 @Override
229 public void replaceSelection(String content) {
230 getDocument().removeDocumentListener(LWTextAreaPeer.this);
231 super.replaceSelection(content);
232 // post only one text event in this case
233 postTextEvent();
234 getDocument().addDocumentListener(LWTextAreaPeer.this);
235 }
236
237 @Override
238 public boolean hasFocus() {
239 return getTarget().hasFocus();
240 }
241
242 @Override
243 public Point getLocationOnScreen() {
244 return LWTextAreaPeer.this.getLocationOnScreen();
245 }
246 }
247 }
|
1 /*
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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
202 @SuppressWarnings("serial")// Safe: outer class is non-serializable.
203 final class ScrollableJTextArea extends JScrollPane {
204
205 ScrollableJTextArea() {
206 super();
207 getViewport().setView(new JTextAreaDelegate());
208 }
209
210 public JTextArea getView() {
211 return (JTextArea) getViewport().getView();
212 }
213
214 @Override
215 public void setEnabled(final boolean enabled) {
216 getViewport().getView().setEnabled(enabled);
217 super.setEnabled(enabled);
218 }
219
220 private final class JTextAreaDelegate extends JTextArea {
221
222 @Override
223 public void replaceSelection(String content) {
224 getDocument().removeDocumentListener(LWTextAreaPeer.this);
225 super.replaceSelection(content);
226 // post only one text event in this case
227 postTextEvent();
228 getDocument().addDocumentListener(LWTextAreaPeer.this);
229 }
230
231 @Override
232 public boolean hasFocus() {
233 return getTarget().hasFocus();
234 }
235
236 @Override
237 public Point getLocationOnScreen() {
238 return LWTextAreaPeer.this.getLocationOnScreen();
239 }
240 }
241 }
|