43
43
import java .text .CharacterIterator ;
44
44
import java .util .ArrayList ;
45
45
import java .util .List ;
46
+ import java .util .concurrent .atomic .AtomicInteger ;
47
+ import java .util .concurrent .atomic .AtomicReference ;
46
48
47
49
/**
48
50
* A utility class containing the functions to support Input Methods
@@ -60,58 +62,59 @@ public InputMethodRequestsAdapter(javafx.scene.input.InputMethodRequests fxReque
60
62
61
63
@ Override
62
64
public Rectangle getTextLocation (TextHitInfo offset ) {
63
- Point2D [] location = { new Point2D (0.0 , 0.0 ) } ;
65
+ AtomicReference < Point2D > location = new AtomicReference <>( new Point2D (0.0 , 0.0 )) ;
64
66
if (fxRequests != null ) {
65
67
PlatformImpl .runAndWait (() -> {
66
- location [ 0 ] = fxRequests .getTextLocation (offset .getInsertionIndex ());
68
+ location . set ( fxRequests .getTextLocation (offset .getInsertionIndex () ));
67
69
});
68
70
}
69
- return new Rectangle ((int )location [ 0 ]. getX (), (int )location [ 0 ] .getY (), 0 , 0 );
71
+ return new Rectangle ((int )location . get (). getX (), (int )location . get () .getY (), 0 , 0 );
70
72
}
71
73
72
74
@ Override
73
75
public TextHitInfo getLocationOffset (int x , int y ) {
74
- int [] offset = { 0 } ;
76
+ AtomicInteger offset = new AtomicInteger ( 0 ) ;
75
77
if (fxRequests != null ) {
76
78
PlatformImpl .runAndWait (() -> {
77
- offset [ 0 ] = fxRequests .getLocationOffset (x , y );
79
+ offset . set ( fxRequests .getLocationOffset (x , y ) );
78
80
});
79
81
}
80
- return TextHitInfo .afterOffset (offset [ 0 ] );
82
+ return TextHitInfo .afterOffset (offset . get () );
81
83
}
82
84
83
85
@ Override
84
86
public int getInsertPositionOffset () {
85
- int [] offset = { 0 } ;
87
+ AtomicInteger offset = new AtomicInteger ( 0 ) ;
86
88
if (fxRequests instanceof ExtendedInputMethodRequests ) {
87
89
PlatformImpl .runAndWait (() -> {
88
- offset [ 0 ] = (( ExtendedInputMethodRequests )fxRequests ).getInsertPositionOffset ();
90
+ offset . set ((( ExtendedInputMethodRequests )fxRequests ).getInsertPositionOffset () );
89
91
});
90
92
}
91
- return offset [ 0 ] ;
93
+ return offset . get () ;
92
94
}
93
95
94
96
@ Override
95
97
public AttributedCharacterIterator getCommittedText (int beginIndex , int endIndex , AttributedCharacterIterator .Attribute [] attributes ) {
96
- String [] comitted = { null } ;
98
+ AtomicReference < String > committed = new AtomicReference <>( null ) ;
97
99
if (fxRequests instanceof ExtendedInputMethodRequests ) {
98
100
PlatformImpl .runAndWait (() -> {
99
- comitted [ 0 ] = (( ExtendedInputMethodRequests )fxRequests ).getCommittedText (beginIndex , endIndex );
101
+ committed . set ((( ExtendedInputMethodRequests )fxRequests ).getCommittedText (beginIndex , endIndex ) );
100
102
});
101
103
}
102
- if (comitted [0 ] == null ) comitted [0 ] = "" ;
103
- return new AttributedString (comitted [0 ]).getIterator ();
104
+ String text = committed .get ();
105
+ if (text == null ) text = "" ;
106
+ return new AttributedString (text ).getIterator ();
104
107
}
105
108
106
109
@ Override
107
110
public int getCommittedTextLength () {
108
- int [] length = { 0 } ;
111
+ AtomicInteger length = new AtomicInteger ( 0 ) ;
109
112
if (fxRequests instanceof ExtendedInputMethodRequests ) {
110
113
PlatformImpl .runAndWait (() -> {
111
- length [ 0 ] = (( ExtendedInputMethodRequests )fxRequests ).getCommittedTextLength ();
114
+ length . set ((( ExtendedInputMethodRequests )fxRequests ).getCommittedTextLength () );
112
115
});
113
116
}
114
- return length [ 0 ] ;
117
+ return length . get () ;
115
118
}
116
119
117
120
@ Override
@@ -122,14 +125,15 @@ public AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacter
122
125
123
126
@ Override
124
127
public AttributedCharacterIterator getSelectedText (AttributedCharacterIterator .Attribute [] attributes ) {
125
- String [] selected = { null } ;
128
+ AtomicReference < String > selected = new AtomicReference <>( null ) ;
126
129
if (fxRequests != null ) {
127
130
PlatformImpl .runAndWait (() -> {
128
- selected [ 0 ] = fxRequests .getSelectedText ();
131
+ selected . set ( fxRequests .getSelectedText () );
129
132
});
130
133
}
131
- if (selected [0 ] == null ) selected [0 ] = "" ;
132
- return new AttributedString (selected [0 ]).getIterator ();
134
+ String text = selected .get ();
135
+ if (text == null ) text = "" ;
136
+ return new AttributedString (text ).getIterator ();
133
137
}
134
138
}
135
139
0 commit comments