1010import java .awt .event .ActionListener ;
1111import java .awt .event .WindowAdapter ;
1212import java .awt .event .WindowEvent ;
13+ import java .nio .charset .Charset ;
14+ import java .nio .charset .StandardCharsets ;
1315import java .text .SimpleDateFormat ;
1416import java .util .Date ;
1517import java .util .StringTokenizer ;
@@ -40,6 +42,8 @@ public abstract class AbstractTextMonitor extends AbstractMonitor {
4042 protected JButton clearButton ;
4143 protected JCheckBox autoscrollBox ;
4244 protected JCheckBox addTimeStampBox ;
45+ protected JComboBox <String > sendEncoding ;
46+ protected JComboBox <String > receiveEncoding ;
4347 protected JComboBox lineEndings ;
4448 protected JComboBox serialRates ;
4549
@@ -103,6 +107,45 @@ public void windowGainedFocus(WindowEvent e) {
103107 minimumSize .setSize (minimumSize .getWidth () / 3 , minimumSize .getHeight ());
104108 noLineEndingAlert .setMinimumSize (minimumSize );
105109
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+
106149 lineEndings = new JComboBox (new String []{tr ("No line ending" ), tr ("Newline" ), tr ("Carriage return" ), tr ("Both NL & CR" )});
107150 lineEndings .addActionListener (new ActionListener () {
108151 public void actionPerformed (ActionEvent event ) {
@@ -121,21 +164,23 @@ public void actionPerformed(ActionEvent e) {
121164 PreferencesData .setBoolean ("serial.show_timestamp" , addTimeStampBox .isSelected ());
122165 }
123166 });
124-
125167 lineEndings .setMaximumSize (lineEndings .getMinimumSize ());
126168
127169 serialRates = new JComboBox ();
128170 for (String rate : serialRateStrings ) {
129171 serialRates .addItem (rate + " " + tr ("baud" ));
130172 }
131-
132173 serialRates .setMaximumSize (serialRates .getMinimumSize ());
133174
134175 pane .add (autoscrollBox );
135176 pane .add (addTimeStampBox );
136177 pane .add (Box .createHorizontalGlue ());
137178 pane .add (noLineEndingAlert );
138179 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 )));
139184 pane .add (lineEndings );
140185 pane .add (Box .createRigidArea (new Dimension (8 , 0 )));
141186 pane .add (serialRates );
@@ -154,6 +199,8 @@ protected void onEnableWindow(boolean enable)
154199 sendButton .setEnabled (enable );
155200 autoscrollBox .setEnabled (enable );
156201 addTimeStampBox .setEnabled (enable );
202+ sendEncoding .setEnabled (enable );
203+ receiveEncoding .setEnabled (enable );
157204 lineEndings .setEnabled (enable );
158205 serialRates .setEnabled (enable );
159206 }
@@ -171,6 +218,10 @@ public void onSerialRateChange(ActionListener listener) {
171218 serialRates .addActionListener (listener );
172219 }
173220
221+ public void onReceiveEncodingChange (ActionListener listener ) {
222+ receiveEncoding .addActionListener (listener );
223+ }
224+
174225 public void message (String msg ) {
175226 SwingUtilities .invokeLater (() -> updateTextArea (msg ));
176227 }
0 commit comments