@@ -40,6 +40,8 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
40
40
protected JButton clearButton ;
41
41
protected JCheckBox autoscrollBox ;
42
42
protected JCheckBox addTimeStampBox ;
43
+ protected JComboBox <String > sendEncoding ;
44
+ protected JComboBox <String > receiveEncoding ;
43
45
protected JComboBox <String > lineEndings ;
44
46
protected JComboBox <String > serialRates ;
45
47
@@ -105,6 +107,44 @@ public void windowGainedFocus(WindowEvent e) {
105
107
minimumSize .setSize (minimumSize .getWidth () / 3 , minimumSize .getHeight ());
106
108
noLineEndingAlert .setMinimumSize (minimumSize );
107
109
110
+ String sendAs = tr ("Send as" ) + " " ;
111
+ sendEncoding = new JComboBox <>(new String [] {
112
+ sendAs + EncodingOption .SYSTEM_DEFAULT ,
113
+ sendAs + EncodingOption .BYTES ,
114
+ sendAs + EncodingOption .UTF_8 ,
115
+ sendAs + EncodingOption .UTF_16 ,
116
+ sendAs + EncodingOption .UTF_16BE ,
117
+ sendAs + EncodingOption .UTF_16LE ,
118
+ sendAs + EncodingOption .ISO_8859_1 ,
119
+ sendAs + EncodingOption .US_ASCII });
120
+ sendEncoding .addActionListener (new ActionListener () {
121
+ public void actionPerformed (ActionEvent event ) {
122
+ PreferencesData .set ("serial.send_encoding" , sendEncoding .getItemAt (
123
+ sendEncoding .getSelectedIndex ()).substring (sendAs .length ()));
124
+ }
125
+ });
126
+ String sendEncodingStr = PreferencesData .get ("serial.send_encoding" );
127
+ if (sendEncodingStr != null ) {
128
+ sendEncoding .setSelectedItem (sendAs + sendEncodingStr );
129
+ }
130
+ sendEncoding .setMaximumSize (sendEncoding .getMinimumSize ());
131
+
132
+ String receiveAs = tr ("Receive as" ) + " " ;
133
+ receiveEncoding = new JComboBox <>(new String [] {
134
+ receiveAs + EncodingOption .SYSTEM_DEFAULT ,
135
+ receiveAs + EncodingOption .BYTES ,
136
+ receiveAs + EncodingOption .UTF_8 ,
137
+ receiveAs + EncodingOption .UTF_16 ,
138
+ receiveAs + EncodingOption .UTF_16BE ,
139
+ receiveAs + EncodingOption .UTF_16LE ,
140
+ receiveAs + EncodingOption .ISO_8859_1 ,
141
+ receiveAs + EncodingOption .US_ASCII });
142
+ String receiveEncodingStr = PreferencesData .get ("serial.receive_encoding" );
143
+ if (receiveEncodingStr != null ) {
144
+ receiveEncoding .setSelectedItem (receiveAs + receiveEncodingStr );
145
+ }
146
+ receiveEncoding .setMaximumSize (receiveEncoding .getMinimumSize ());
147
+
108
148
lineEndings = new JComboBox <String >(new String []{tr ("No line ending" ), tr ("Newline" ), tr ("Carriage return" ), tr ("Both NL & CR" )});
109
149
lineEndings .addActionListener ((ActionEvent event ) -> {
110
150
PreferencesData .setInteger ("serial.line_ending" , lineEndings .getSelectedIndex ());
@@ -127,6 +167,10 @@ public void windowGainedFocus(WindowEvent e) {
127
167
pane .add (Box .createHorizontalGlue ());
128
168
pane .add (noLineEndingAlert );
129
169
pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
170
+ pane .add (sendEncoding );
171
+ pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
172
+ pane .add (receiveEncoding );
173
+ pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
130
174
pane .add (lineEndings );
131
175
pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
132
176
pane .add (serialRates );
@@ -139,15 +183,16 @@ public void windowGainedFocus(WindowEvent e) {
139
183
}
140
184
141
185
@ Override
142
- protected void onEnableWindow (boolean enable )
143
- {
186
+ protected void onEnableWindow (boolean enable ) {
144
187
textArea .setEnabled (enable );
145
188
clearButton .setEnabled (enable );
146
189
scrollPane .setEnabled (enable );
147
190
textField .setEnabled (enable );
148
191
sendButton .setEnabled (enable );
149
192
autoscrollBox .setEnabled (enable );
150
193
addTimeStampBox .setEnabled (enable );
194
+ sendEncoding .setEnabled (enable );
195
+ receiveEncoding .setEnabled (enable );
151
196
lineEndings .setEnabled (enable );
152
197
serialRates .setEnabled (enable );
153
198
}
@@ -165,6 +210,10 @@ public void onSerialRateChange(ActionListener listener) {
165
210
serialRates .addActionListener (listener );
166
211
}
167
212
213
+ public void onReceiveEncodingChange (ActionListener listener ) {
214
+ receiveEncoding .addActionListener (listener );
215
+ }
216
+
168
217
@ Override
169
218
public void message (String msg ) {
170
219
SwingUtilities .invokeLater (() -> updateTextArea (msg ));
0 commit comments