3
3
import cpw .mods .fml .client .FMLClientHandler ;
4
4
import net .minecraft .client .gui .GuiChat ;
5
5
import net .minecraft .client .gui .inventory .GuiEditSign ;
6
- import org .devinprogress .YAIF .Bridges .CommonBridge ;
7
6
import org .devinprogress .YAIF .Bridges .EditSignBridge ;
8
7
import org .devinprogress .YAIF .Bridges .GuiChatBridge ;
9
8
import org .devinprogress .YAIF .Bridges .IActionBridge ;
24
23
* Created by recursiveg on 14-9-11.
25
24
*/
26
25
public class InputFieldWrapper {
27
- private static final int TextFieldHeight = 25 ;
26
+ private static final int fontSize = 20 ;
28
27
29
28
private static boolean hasInitiated =false ;
30
29
private boolean enabled =true ; //Reserved for Further Use
@@ -33,8 +32,9 @@ public class InputFieldWrapper {
33
32
private IActionBridge bridge =null ;
34
33
35
34
private AWTGLCanvas canvas = null ;
36
- private final JFrame frame =new JFrame ("Minecraft" );
37
- private JTextField txtField = null ;
35
+ private JFrame frame =null ;
36
+ private JTextField textField = null ;
37
+ private JPanel panel =null ;
38
38
39
39
public InputFieldWrapper (int Width ,int Height ){ //Should be Called only once
40
40
if (hasInitiated ){
@@ -43,54 +43,66 @@ public InputFieldWrapper(int Width,int Height){ //Should be Called only once
43
43
}
44
44
hasInitiated =true ;
45
45
46
+ // Create Instances
46
47
try {
47
48
canvas = new AWTGLCanvas ();
48
49
}catch (Exception e ){
49
50
e .printStackTrace ();
50
51
}
51
- canvas .setFocusable (true );
52
- txtField =new JTextField ();
52
+ frame =new JFrame ("Minecraft 1.7.10" );
53
+ textField =new JTextField ();
54
+ panel =new JPanel ();
53
55
56
+ // Setup Canvas
57
+ canvas .setFocusable (true );
58
+ try {
59
+ Display .setParent (canvas );
60
+ }catch (Exception e ){
61
+ e .printStackTrace ();
62
+ }
63
+ canvas .setPreferredSize (new Dimension (Width , Height ));
64
+
65
+ // Setup TextField
66
+ //textField.setVisible(false);
67
+ textField .setVisible (true );
68
+ textField .setFont (new Font ("Times New Roman" ,Font .PLAIN , fontSize ));
69
+
70
+ // Setup Panel
71
+ panel .setLayout (new BorderLayout ());
72
+ panel .add (canvas , BorderLayout .CENTER );
73
+ panel .add (textField , BorderLayout .PAGE_END );
74
+ panel .setVisible (true );
75
+ panel .validate ();
76
+
77
+ // Setup frame
78
+ frame .setUndecorated (false );
54
79
frame .setDefaultCloseOperation (WindowConstants .DO_NOTHING_ON_CLOSE );
80
+ frame .setContentPane (panel );
55
81
frame .addWindowListener (new WindowAdapter () {
56
82
@ Override
57
83
public void windowClosing (WindowEvent e ) {
58
84
FMLClientHandler .instance ().getClient ().shutdown ();
59
85
}
60
86
});
61
- frame .setLayout (new BorderLayout ());
62
- frame .setVisible (true );
63
- frame .add (canvas ,BorderLayout .CENTER );
64
- try {
65
- Display .setParent (canvas );
66
- }catch (Exception e ){
67
- e .printStackTrace ();
68
- }
69
- frame .setPreferredSize (new Dimension (Width , Height ));
70
- frame .pack ();
71
-
72
- txtField .setVisible (false );
73
- txtField .setPreferredSize (new Dimension (Width , TextFieldHeight ));
74
- bindKeys ();
75
- frame .add (txtField , BorderLayout .PAGE_END );
76
-
77
87
frame .pack ();
78
88
frame .validate ();
89
+ frame .setLocationRelativeTo (null );
90
+ frame .setVisible (true );
79
91
}
80
92
81
93
public void onTabComplete (){
82
94
if (bridge !=null )
83
- bridge .onTabComplete (txtField );
95
+ bridge .onTabComplete (textField );
84
96
}
85
97
86
98
private void bindKeys (){
87
99
//Should be Called Only Once
88
- //Be careful about txtField .setText(). It will trigger here and further trigger the bridges.
89
- InputMap inputmap = txtField .getInputMap ();
90
- ActionMap actionmap = txtField .getActionMap ();
100
+ //Be careful about textField .setText(). It will trigger here and further trigger the bridges.
101
+ InputMap inputmap = textField .getInputMap ();
102
+ ActionMap actionmap = textField .getActionMap ();
91
103
92
- txtField .setFocusTraversalKeys (KeyboardFocusManager .FORWARD_TRAVERSAL_KEYS , Collections .EMPTY_SET );
93
- txtField .setFocusTraversalKeys (KeyboardFocusManager .BACKWARD_TRAVERSAL_KEYS , Collections .EMPTY_SET );
104
+ textField .setFocusTraversalKeys (KeyboardFocusManager .FORWARD_TRAVERSAL_KEYS , Collections .EMPTY_SET );
105
+ textField .setFocusTraversalKeys (KeyboardFocusManager .BACKWARD_TRAVERSAL_KEYS , Collections .EMPTY_SET );
94
106
KeyStroke enter = KeyStroke .getKeyStroke (KeyEvent .VK_ENTER , 0 );
95
107
KeyStroke esc = KeyStroke .getKeyStroke (KeyEvent .VK_ESCAPE , 0 );
96
108
KeyStroke tab =KeyStroke .getKeyStroke (KeyEvent .VK_TAB ,0 );
@@ -102,51 +114,51 @@ private void bindKeys(){
102
114
Action enterAction = new AbstractAction () {
103
115
@ Override
104
116
public void actionPerformed (ActionEvent event ) {
105
- if (bridge !=null )DoActions (bridge .onEnter (txtField ),null );
117
+ if (bridge !=null )DoActions (bridge .onEnter (textField ),null );
106
118
}
107
119
};
108
120
Action escAction = new AbstractAction () {
109
121
@ Override
110
122
public void actionPerformed (ActionEvent event ) {
111
- if (bridge !=null )DoActions (bridge .onEsc (txtField ),null );
123
+ if (bridge !=null )DoActions (bridge .onEsc (textField ),null );
112
124
}
113
125
};
114
126
Action tabAction = new AbstractAction () {
115
127
@ Override
116
128
public void actionPerformed (ActionEvent event ) {
117
- if (bridge !=null )DoActions (bridge .onTab (txtField ),null );
129
+ if (bridge !=null )DoActions (bridge .onTab (textField ),null );
118
130
}
119
131
};
120
132
Action upAction = new AbstractAction () {
121
133
@ Override
122
134
public void actionPerformed (ActionEvent event ) {
123
- if (bridge !=null )DoActions (bridge .onUp (txtField ),null );
135
+ if (bridge !=null )DoActions (bridge .onUp (textField ),null );
124
136
}
125
137
};
126
138
Action downAction = new AbstractAction () {
127
139
@ Override
128
140
public void actionPerformed (ActionEvent event ) {
129
- if (bridge !=null )DoActions (bridge .onDown (txtField ),null );
141
+ if (bridge !=null )DoActions (bridge .onDown (textField ),null );
130
142
}
131
143
};
132
144
Action backspAction =new AbstractAction () {
133
145
@ Override
134
146
public void actionPerformed (ActionEvent e ) {
135
- if (bridge !=null )DoActions (bridge .onBackspace (txtField ),null );
147
+ if (bridge !=null )DoActions (bridge .onBackspace (textField ),null );
136
148
}
137
149
};
138
- txtField .getDocument ().addDocumentListener (new DocumentListener () {
150
+ textField .getDocument ().addDocumentListener (new DocumentListener () {
139
151
@ Override
140
152
public void insertUpdate (DocumentEvent e ) {
141
153
if (bridge !=null &&doTriggerOnChangeEvent )
142
- DoActions (bridge .onChange (txtField ), null );
154
+ DoActions (bridge .onChange (textField ), null );
143
155
doTriggerOnChangeEvent = true ;
144
156
}
145
157
146
158
@ Override
147
159
public void removeUpdate (DocumentEvent e ) {
148
160
if (bridge !=null &&doTriggerOnChangeEvent )
149
- DoActions (bridge .onChange (txtField ), null );
161
+ DoActions (bridge .onChange (textField ), null );
150
162
doTriggerOnChangeEvent = true ;
151
163
}
152
164
@@ -177,10 +189,10 @@ public void show(){//called when GuiTextField: New/Re-click/change
177
189
bridge =getBridge ();
178
190
if ((!shown )&&bridge !=null ) {
179
191
shown = true ;
180
- frame .setSize (new Dimension (frame .getWidth (), frame .getHeight () + TextFieldHeight ));
181
- txtField .setVisible (true );
192
+ frame .setSize (new Dimension (frame .getWidth (), frame .getHeight () + fontSize ));
193
+ textField .setVisible (true );
182
194
FMLClientHandler .instance ().getClient ().setIngameNotInFocus ();
183
- txtField .requestFocus ();
195
+ textField .requestFocus ();
184
196
frame .validate ();
185
197
}
186
198
}
@@ -189,8 +201,8 @@ public void hide(){
189
201
bridge =null ;
190
202
if (!shown )return ;
191
203
shown =false ;
192
- txtField .setVisible (false );
193
- frame .setSize (new Dimension (frame .getWidth (), frame .getHeight () - TextFieldHeight ));
204
+ textField .setVisible (false );
205
+ frame .setSize (new Dimension (frame .getWidth (), frame .getHeight () - fontSize ));
194
206
195
207
canvas .requestFocusInWindow ();
196
208
frame .validate ();
@@ -231,8 +243,8 @@ public void setTextNoEvent(final String str){
231
243
SwingUtilities .invokeLater (new Runnable () {
232
244
@ Override
233
245
public void run () {
234
- txtField .setText (str );
235
- txtField .setCaretPosition (txtField .getText ().length ());
246
+ textField .setText (str );
247
+ textField .setCaretPosition (textField .getText ().length ());
236
248
}
237
249
});
238
250
}
0 commit comments