Skip to content

Commit

Permalink
Reorganized baud rate setting in GirsClientBean.
Browse files Browse the repository at this point in the history
Baudrates were taken from nrjavaserial. Resolves #534,
  • Loading branch information
bengtmartensson committed Sep 4, 2024
1 parent 9f3264a commit 8482845
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 34 deletions.
15 changes: 3 additions & 12 deletions src/main/java/org/harctoolbox/guicomponents/GirsClientBean.form
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,15 @@
</Component>
<Component class="javax.swing.JComboBox" name="baudComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="8">
<StringItem index="0" value="115200"/>
<StringItem index="1" value="57600"/>
<StringItem index="2" value="38400"/>
<StringItem index="3" value="19200"/>
<StringItem index="4" value="9600"/>
<StringItem index="5" value="4800"/>
<StringItem index="6" value="2400"/>
<StringItem index="7" value="1200"/>
</StringArray>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new DefaultComboBoxModel&lt;Integer&gt;(KNOWN_BAUD_RATES)" type="code"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="baudComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;Integer&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="serialPortLabel">
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/harctoolbox/guicomponents/GirsClientBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<Integer>(KNOWN_BAUD_RATES));
baudComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
baudComboBoxActionPerformed(evt);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String> baudComboBox;
private javax.swing.JComboBox<Integer> baudComboBox;
private javax.swing.JLabel baudRateLabel;
private javax.swing.JButton browseButton;
private javax.swing.JPanel ethernetPanel;
Expand Down
18 changes: 5 additions & 13 deletions src/main/java/org/harctoolbox/guicomponents/SerialPortBean.form
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,19 @@
</Component>
<Component class="javax.swing.JComboBox" name="baudComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="8">
<StringItem index="0" value="115200"/>
<StringItem index="1" value="57600"/>
<StringItem index="2" value="38400"/>
<StringItem index="3" value="19200"/>
<StringItem index="4" value="9600"/>
<StringItem index="5" value="4800"/>
<StringItem index="6" value="2400"/>
<StringItem index="7" value="1200"/>
</StringArray>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new DefaultComboBoxModel&lt;Integer&gt;(KNOWN_BAUD_RATES)&#xa;" type="code"/>
</Property>
<Property name="selectedItem" type="java.lang.Object" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="&quot;9600&quot;" type="code"/>
<Connection code="9600" type="code"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="baudComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new javax.swing.JComboBox&lt;Integer&gt;()"/>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;Integer&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="jLabel7">
Expand Down
45 changes: 41 additions & 4 deletions src/main/java/org/harctoolbox/guicomponents/SerialPortBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Integer>();
jLabel7 = new javax.swing.JLabel();
openToggleButton = new javax.swing.JToggleButton();

Expand Down Expand Up @@ -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<Integer>(KNOWN_BAUD_RATES)
);
baudComboBox.setSelectedItem(9600);
baudComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
baudComboBoxActionPerformed(evt);
Expand Down Expand Up @@ -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<String> baudComboBox;
private javax.swing.JComboBox<Integer> baudComboBox;
private javax.swing.JComboBox<String> bitsComboBox;
private javax.swing.JComboBox<String> flowControlComboBox;
private javax.swing.JLabel jLabel1;
Expand Down

0 comments on commit 8482845

Please sign in to comment.