1 /*
2 * Copyright (c) 1997, 2014, 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
271 (newValue instanceof Document)) {
272 // New document will have changed selection to 0,0.
273 updateInputAttributes(0, 0, (JTextComponent)source);
274 }
275 }
276
277 public void caretUpdate(CaretEvent e) {
278 updateInputAttributes(e.getDot(), e.getMark(),
279 (JTextComponent)e.getSource());
280 }
281 }
282
283 /**
284 * Copies the key/values in <code>element</code>s AttributeSet into
285 * <code>set</code>. This does not copy component, icon, or element
286 * names attributes. Subclasses may wish to refine what is and what
287 * isn't copied here. But be sure to first remove all the attributes that
288 * are in <code>set</code>.<p>
289 * This is called anytime the caret moves over a different location.
290 *
291 */
292 protected void createInputAttributes(Element element,
293 MutableAttributeSet set) {
294 if (element.getAttributes().getAttributeCount() > 0
295 || element.getEndOffset() - element.getStartOffset() > 1
296 || element.getEndOffset() < element.getDocument().getLength()) {
297 set.removeAttributes(set);
298 set.addAttributes(element.getAttributes());
299 set.removeAttribute(StyleConstants.ComponentAttribute);
300 set.removeAttribute(StyleConstants.IconAttribute);
301 set.removeAttribute(AbstractDocument.ElementNameAttribute);
302 set.removeAttribute(StyleConstants.ComposedTextAttribute);
303 }
304 }
305
306 // ---- default ViewFactory implementation ---------------------
307
308 static class StyledViewFactory implements ViewFactory {
309
310 public View create(Element elem) {
|
1 /*
2 * Copyright (c) 1997, 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
271 (newValue instanceof Document)) {
272 // New document will have changed selection to 0,0.
273 updateInputAttributes(0, 0, (JTextComponent)source);
274 }
275 }
276
277 public void caretUpdate(CaretEvent e) {
278 updateInputAttributes(e.getDot(), e.getMark(),
279 (JTextComponent)e.getSource());
280 }
281 }
282
283 /**
284 * Copies the key/values in <code>element</code>s AttributeSet into
285 * <code>set</code>. This does not copy component, icon, or element
286 * names attributes. Subclasses may wish to refine what is and what
287 * isn't copied here. But be sure to first remove all the attributes that
288 * are in <code>set</code>.<p>
289 * This is called anytime the caret moves over a different location.
290 *
291 * @param element the element
292 * @param set the attributes
293 */
294 protected void createInputAttributes(Element element,
295 MutableAttributeSet set) {
296 if (element.getAttributes().getAttributeCount() > 0
297 || element.getEndOffset() - element.getStartOffset() > 1
298 || element.getEndOffset() < element.getDocument().getLength()) {
299 set.removeAttributes(set);
300 set.addAttributes(element.getAttributes());
301 set.removeAttribute(StyleConstants.ComponentAttribute);
302 set.removeAttribute(StyleConstants.IconAttribute);
303 set.removeAttribute(AbstractDocument.ElementNameAttribute);
304 set.removeAttribute(StyleConstants.ComposedTextAttribute);
305 }
306 }
307
308 // ---- default ViewFactory implementation ---------------------
309
310 static class StyledViewFactory implements ViewFactory {
311
312 public View create(Element elem) {
|