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
52 import javafx.scene.Node;
53 import javafx.scene.Scene;
54 import javafx.scene.control.IndexRange;
55 import javafx.scene.control.SkinBase;
56 import javafx.scene.control.TextInputControl;
57 import javafx.scene.input.InputMethodEvent;
58 import javafx.scene.input.InputMethodHighlight;
59 import javafx.scene.input.InputMethodTextRun;
60 import javafx.scene.layout.StackPane;
61 import javafx.scene.paint.Color;
62 import javafx.scene.paint.Paint;
63 import javafx.scene.shape.ClosePath;
64 import javafx.scene.shape.HLineTo;
65 import javafx.scene.shape.Line;
66 import javafx.scene.shape.LineTo;
67 import javafx.scene.shape.MoveTo;
68 import javafx.scene.shape.Path;
69 import javafx.scene.shape.PathElement;
70 import javafx.scene.shape.Shape;
71 import javafx.scene.shape.VLineTo;
72 import javafx.stage.Window;
73 import javafx.util.Duration;
74 import java.lang.ref.WeakReference;
75 import java.util.ArrayList;
76 import java.util.Collections;
77 import java.util.List;
78 import com.sun.javafx.PlatformUtil;
79 import javafx.css.converter.BooleanConverter;
80 import javafx.css.converter.PaintConverter;
81 import com.sun.javafx.scene.control.behavior.TextInputControlBehavior;
82 import com.sun.javafx.scene.text.HitInfo;
83 import com.sun.javafx.tk.FontMetrics;
84 import com.sun.javafx.tk.Toolkit;
85 import static com.sun.javafx.PlatformUtil.isWindows;
86 import java.security.AccessController;
87 import java.security.PrivilegedAction;
88
89 /**
90 * Abstract base class for text input skins.
91 *
92 * @since 9
93 * @see TextFieldSkin
94 * @see TextAreaSkin
95 */
96 public abstract class TextInputControlSkin<T extends TextInputControl> extends SkinBase<T> {
97
98 /**************************************************************************
99 *
100 * Static fields / blocks
101 *
102 **************************************************************************/
967 /**
968 * {@inheritDoc}
969 */
970 @Override public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
971 return getClassCssMetaData();
972 }
973
974 @Override protected void executeAccessibleAction(AccessibleAction action, Object... parameters) {
975 switch (action) {
976 case SHOW_TEXT_RANGE: {
977 Integer start = (Integer)parameters[0];
978 Integer end = (Integer)parameters[1];
979 if (start != null && end != null) {
980 scrollCharacterToVisible(end);
981 scrollCharacterToVisible(start);
982 scrollCharacterToVisible(end);
983 }
984 break;
985 }
986 default: super.executeAccessibleAction(action, parameters);
987 }
988 }
989
990 /**
991 * This class represents the hit information for a Text node.
992 */
993 public static class TextPosInfo {
994
995 TextPosInfo(HitInfo hit) {
996 this(hit.getCharIndex(), hit.isLeading());
997 }
998
999 /**
1000 * Create a TextPosInfo object representing a text index and forward bias.
1001 *
1002 * @param charIndex the character index.
1003 * @param leading whether the hit is on the leading edge of the character. If it is false, it represents the trailing edge.
1004 */
1005 public TextPosInfo(int charIndex, boolean leading) {
1006 setCharIndex(charIndex);
1007 setLeading(leading);
1008 }
1009
1010 /**
1011 * The index of the character which this hit information refers to.
1012 */
1013 private int charIndex;
1014 public int getCharIndex() { return charIndex; }
1015 void setCharIndex(int charIndex) { this.charIndex = charIndex; }
1016
1017 /**
1018 * Indicates whether the hit is on the leading edge of the character.
1019 * If it is false, it represents the trailing edge.
1020 */
1021 private boolean leading;
1022 public boolean isLeading() { return leading; }
1023 void setLeading(boolean leading) { this.leading = leading; }
1024
1025 /**
1026 * Returns the index of the insertion position.
1027 */
1028 public int getInsertionIndex() {
1029 return leading ? charIndex : charIndex + 1;
1030 }
1031
1032 @Override public String toString() {
1033 return "charIndex: " + charIndex + ", isLeading: " + leading;
1034 }
1035 }
1036 }
|
1 /*
2 * Copyright (c) 2011, 2016, 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
52 import javafx.scene.Node;
53 import javafx.scene.Scene;
54 import javafx.scene.control.IndexRange;
55 import javafx.scene.control.SkinBase;
56 import javafx.scene.control.TextInputControl;
57 import javafx.scene.input.InputMethodEvent;
58 import javafx.scene.input.InputMethodHighlight;
59 import javafx.scene.input.InputMethodTextRun;
60 import javafx.scene.layout.StackPane;
61 import javafx.scene.paint.Color;
62 import javafx.scene.paint.Paint;
63 import javafx.scene.shape.ClosePath;
64 import javafx.scene.shape.HLineTo;
65 import javafx.scene.shape.Line;
66 import javafx.scene.shape.LineTo;
67 import javafx.scene.shape.MoveTo;
68 import javafx.scene.shape.Path;
69 import javafx.scene.shape.PathElement;
70 import javafx.scene.shape.Shape;
71 import javafx.scene.shape.VLineTo;
72 import javafx.scene.text.HitInfo;
73 import javafx.stage.Window;
74 import javafx.util.Duration;
75 import java.lang.ref.WeakReference;
76 import java.util.ArrayList;
77 import java.util.Collections;
78 import java.util.List;
79 import com.sun.javafx.PlatformUtil;
80 import javafx.css.converter.BooleanConverter;
81 import javafx.css.converter.PaintConverter;
82 import com.sun.javafx.scene.control.behavior.TextInputControlBehavior;
83 import com.sun.javafx.tk.FontMetrics;
84 import com.sun.javafx.tk.Toolkit;
85 import static com.sun.javafx.PlatformUtil.isWindows;
86 import java.security.AccessController;
87 import java.security.PrivilegedAction;
88
89 /**
90 * Abstract base class for text input skins.
91 *
92 * @since 9
93 * @see TextFieldSkin
94 * @see TextAreaSkin
95 */
96 public abstract class TextInputControlSkin<T extends TextInputControl> extends SkinBase<T> {
97
98 /**************************************************************************
99 *
100 * Static fields / blocks
101 *
102 **************************************************************************/
967 /**
968 * {@inheritDoc}
969 */
970 @Override public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
971 return getClassCssMetaData();
972 }
973
974 @Override protected void executeAccessibleAction(AccessibleAction action, Object... parameters) {
975 switch (action) {
976 case SHOW_TEXT_RANGE: {
977 Integer start = (Integer)parameters[0];
978 Integer end = (Integer)parameters[1];
979 if (start != null && end != null) {
980 scrollCharacterToVisible(end);
981 scrollCharacterToVisible(start);
982 scrollCharacterToVisible(end);
983 }
984 break;
985 }
986 default: super.executeAccessibleAction(action, parameters);
987 }
988 }
989 }
|