10
10
import java .awt .event .ActionListener ;
11
11
import java .awt .event .WindowAdapter ;
12
12
import java .awt .event .WindowEvent ;
13
+ import java .nio .charset .Charset ;
14
+ import java .nio .charset .StandardCharsets ;
13
15
import java .text .SimpleDateFormat ;
14
16
import java .util .Date ;
15
17
import java .util .StringTokenizer ;
@@ -40,6 +42,8 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
40
42
protected JButton clearButton ;
41
43
protected JCheckBox autoscrollBox ;
42
44
protected JCheckBox addTimeStampBox ;
45
+ protected JComboBox <String > sendEncoding ;
46
+ protected JComboBox <String > receiveEncoding ;
43
47
protected JComboBox lineEndings ;
44
48
protected JComboBox serialRates ;
45
49
@@ -103,6 +107,45 @@ public void windowGainedFocus(WindowEvent e) {
103
107
minimumSize .setSize (minimumSize .getWidth () / 3 , minimumSize .getHeight ());
104
108
noLineEndingAlert .setMinimumSize (minimumSize );
105
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
+ // sendEncoding.setForeground(pane.getBackground());
125
+ }
126
+ });
127
+ String sendEncodingStr = PreferencesData .get ("serial.send_encoding" );
128
+ if (sendEncodingStr != null ) {
129
+ sendEncoding .setSelectedItem (sendAs + sendEncodingStr );
130
+ }
131
+ sendEncoding .setMaximumSize (sendEncoding .getMinimumSize ());
132
+
133
+ String receiveAs = tr ("Receive as" ) + " " ;
134
+ receiveEncoding = new JComboBox <>(new String [] {
135
+ receiveAs + EncodingOption .SYSTEM_DEFAULT ,
136
+ receiveAs + EncodingOption .BYTES ,
137
+ receiveAs + EncodingOption .UTF_8 ,
138
+ receiveAs + EncodingOption .UTF_16 ,
139
+ receiveAs + EncodingOption .UTF_16BE ,
140
+ receiveAs + EncodingOption .UTF_16LE ,
141
+ receiveAs + EncodingOption .ISO_8859_1 ,
142
+ receiveAs + EncodingOption .US_ASCII });
143
+ String receiveEncodingStr = PreferencesData .get ("serial.receive_encoding" );
144
+ if (receiveEncodingStr != null ) {
145
+ receiveEncoding .setSelectedItem (receiveAs + receiveEncodingStr );
146
+ }
147
+ receiveEncoding .setMaximumSize (receiveEncoding .getMinimumSize ());
148
+
106
149
lineEndings = new JComboBox (new String []{tr ("No line ending" ), tr ("Newline" ), tr ("Carriage return" ), tr ("Both NL & CR" )});
107
150
lineEndings .addActionListener (new ActionListener () {
108
151
public void actionPerformed (ActionEvent event ) {
@@ -121,21 +164,23 @@ public void actionPerformed(ActionEvent e) {
121
164
PreferencesData .setBoolean ("serial.show_timestamp" , addTimeStampBox .isSelected ());
122
165
}
123
166
});
124
-
125
167
lineEndings .setMaximumSize (lineEndings .getMinimumSize ());
126
168
127
169
serialRates = new JComboBox ();
128
170
for (String rate : serialRateStrings ) {
129
171
serialRates .addItem (rate + " " + tr ("baud" ));
130
172
}
131
-
132
173
serialRates .setMaximumSize (serialRates .getMinimumSize ());
133
174
134
175
pane .add (autoscrollBox );
135
176
pane .add (addTimeStampBox );
136
177
pane .add (Box .createHorizontalGlue ());
137
178
pane .add (noLineEndingAlert );
138
179
pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
180
+ pane .add (sendEncoding );
181
+ pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
182
+ pane .add (receiveEncoding );
183
+ pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
139
184
pane .add (lineEndings );
140
185
pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
141
186
pane .add (serialRates );
@@ -154,6 +199,8 @@ protected void onEnableWindow(boolean enable)
154
199
sendButton .setEnabled (enable );
155
200
autoscrollBox .setEnabled (enable );
156
201
addTimeStampBox .setEnabled (enable );
202
+ sendEncoding .setEnabled (enable );
203
+ receiveEncoding .setEnabled (enable );
157
204
lineEndings .setEnabled (enable );
158
205
serialRates .setEnabled (enable );
159
206
}
@@ -171,6 +218,10 @@ public void onSerialRateChange(ActionListener listener) {
171
218
serialRates .addActionListener (listener );
172
219
}
173
220
221
+ public void onReceiveEncodingChange (ActionListener listener ) {
222
+ receiveEncoding .addActionListener (listener );
223
+ }
224
+
174
225
public void message (String msg ) {
175
226
SwingUtilities .invokeLater (() -> updateTextArea (msg ));
176
227
}
0 commit comments