From 8482845730fe333547448ee9c9d43b249ce4ed8e Mon Sep 17 00:00:00 2001 From: Bengt Martensson Date: Wed, 4 Sep 2024 13:49:21 +0200 Subject: [PATCH] Reorganized baud rate setting in GirsClientBean. Baudrates were taken from nrjavaserial. Resolves #534, --- .../guicomponents/GirsClientBean.form | 15 ++----- .../guicomponents/GirsClientBean.java | 11 ++--- .../guicomponents/SerialPortBean.form | 18 +++----- .../guicomponents/SerialPortBean.java | 45 +++++++++++++++++-- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.form b/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.form index 475bb0c9..a5534ded 100644 --- a/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.form +++ b/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.form @@ -162,24 +162,15 @@ - - - - - - - - - - - + + - + diff --git a/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java b/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java index c09dce21..6c97f8b1 100644 --- a/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java +++ b/src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import javax.swing.DefaultComboBoxModel; +import static org.harctoolbox.guicomponents.SerialPortBean.KNOWN_BAUD_RATES; import org.harctoolbox.harchardware.HarcHardwareException; import org.harctoolbox.harchardware.comm.LocalSerialPort; import org.harctoolbox.harchardware.comm.LocalSerialPortBuffered; @@ -204,7 +205,7 @@ public int getBaud() { public void setBaud(int baud) { int oldBaud = this.baud; this.baud = baud; - this.baudComboBox.setSelectedItem(Integer.toString(baud)); + this.baudComboBox.setSelectedItem(baud); propertyChangeSupport.firePropertyChange(PROP_BAUD, oldBaud, baud); } @@ -402,7 +403,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); - baudComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "115200", "57600", "38400", "19200", "9600", "4800", "2400", "1200" })); + baudComboBox.setModel(new DefaultComboBoxModel(KNOWN_BAUD_RATES)); baudComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { baudComboBoxActionPerformed(evt); @@ -584,7 +585,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addComponent(serialTcpTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 535, Short.MAX_VALUE) + .addComponent(serialTcpTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() @@ -640,7 +641,7 @@ private void portComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN- }//GEN-LAST:event_portComboBoxActionPerformed private void baudComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_baudComboBoxActionPerformed - setBaud(Integer.parseInt((String) baudComboBox.getSelectedItem())); + setBaud((Integer) baudComboBox.getSelectedItem()); }//GEN-LAST:event_baudComboBoxActionPerformed private void ipNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ipNameTextFieldActionPerformed @@ -701,7 +702,7 @@ private void useReceiveForCaptureCheckBoxActionPerformed(java.awt.event.ActionEv }//GEN-LAST:event_useReceiveForCaptureCheckBoxActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JComboBox baudComboBox; + private javax.swing.JComboBox baudComboBox; private javax.swing.JLabel baudRateLabel; private javax.swing.JButton browseButton; private javax.swing.JPanel ethernetPanel; diff --git a/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.form b/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.form index a2038097..55ac9837 100644 --- a/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.form +++ b/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.form @@ -210,27 +210,19 @@ - - - - - - - - - - - + + - + - + + diff --git a/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java b/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java index 687f5fd3..ed38b8d6 100644 --- a/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java +++ b/src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java @@ -48,6 +48,42 @@ public final class SerialPortBean extends javax.swing.JPanel { public static final String PROP_PARITY = "PROP_PARITY"; public static final String PROP_STOPBITS = "PROP_STOPBITS"; //public static final String PROP_PORT = "PROP_PORT"; + public static final Integer[] KNOWN_BAUD_RATES = { // from nrjavaserial + 50, + 75, + 110, + 134, + 150, + 200, + 300, + 600, + 1200, + 1800, + 2400, + 4800, + 9600, + 14400, + 19200, + 28800, + 38400, + 57600, + 115200, + 128000, + 230400, + 256000, + 460800, + 500000, + 576000, + 921600, + 1000000, + 1152000, + 1500000, + 2000000, + 2500000, + 3000000, + 3500000, + 4000000 + }; /** * Creates new form SerialPortSimpleBean @@ -240,7 +276,7 @@ private void initComponents() { jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); - baudComboBox = new javax.swing.JComboBox<>(); + baudComboBox = new javax.swing.JComboBox(); jLabel7 = new javax.swing.JLabel(); openToggleButton = new javax.swing.JToggleButton(); @@ -298,8 +334,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jLabel5.setText("stop bits"); - baudComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "115200", "57600", "38400", "19200", "9600", "4800", "2400", "1200" })); - baudComboBox.setSelectedItem("9600"); + baudComboBox.setModel(new DefaultComboBoxModel(KNOWN_BAUD_RATES) + ); + baudComboBox.setSelectedItem(9600); baudComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { baudComboBoxActionPerformed(evt); @@ -428,7 +465,7 @@ private void openToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {// }//GEN-LAST:event_openToggleButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JComboBox baudComboBox; + private javax.swing.JComboBox baudComboBox; private javax.swing.JComboBox bitsComboBox; private javax.swing.JComboBox flowControlComboBox; private javax.swing.JLabel jLabel1;