Java tutorial
// *************************************************************************** // * Copyright (C) 2015 by Chavdar Levkov // * ch.levkov@gmail.com // * // * This program is free software; you can redistribute it and/or modify // * it under the terms of the GNU General Public License as published by // * the Free Software Foundation; either version 2 of the License, or // * (at your option) any later version. // * // * This program is distributed in the hope that it will be useful, // * but WITHOUT ANY WARRANTY; without even the implied warranty of // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // * GNU General Public License for more details. // * // * You should have received a copy of the GNU General Public License // * along with this program; if not, write to the // * Free Software Foundation, Inc., // * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // *************************************************************************** package org.lz1aq.jatu; import org.lz1aq.py.rig.I_SerialSettings; import org.lz1aq.py.rig.I_Radio; import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JProgressBar; import javax.swing.JToggleButton; import javax.swing.filechooser.FileNameExtensionFilter; import jssc.SerialPortList; import org.lz1aq.rsi.Radio; import org.lz1aq.rsi.event.RadioListener; import org.apache.commons.lang3.StringUtils; import org.lz1aq.rsi.event.ActiveVfoEvent; import org.lz1aq.rsi.event.ConfirmationEvent; import org.lz1aq.rsi.event.FrequencyEvent; import org.lz1aq.rsi.event.ModeEvent; import org.lz1aq.rsi.event.NotsupportedEvent; import org.lz1aq.rsi.event.SmeterEvent; import org.lz1aq.utils.Misc; import org.lz1aq.utils.RadioVfos; public class SimpleRadioPanel extends javax.swing.JFrame { private Radio radio; private JFileChooser chooser; private I_Radio radioParser; private static final Logger logger = Logger.getLogger(Radio.class.getName()); /** * Creates new form SimpleRadioPanel */ public SimpleRadioPanel() { initComponents(); // Generated by the Form Editor init(); // Custom initializations } /** * Method called within the constructor to do initializations different than * the ones done by the Form Editor */ private void init() { // Configure the FileChooser this.chooser = new JFileChooser(); chooser.setFileFilter(new FileNameExtensionFilter("Python files", "py")); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); } /** * @return Returns a new DefaultComboBoxModel containing all available bands */ private DefaultComboBoxModel getBandsComboboxModel() { return new DefaultComboBoxModel(new String[] { "1.8", "3.5", "7", "10", "14", "18", "21", "24", "28" }); } /** * @return Returns a new DefaultComboBoxModel containing all available bands */ private DefaultComboBoxModel getVfoComboboxModel() { return new DefaultComboBoxModel(new String[] { "VFO A", "VFO B" }); } private int getVfo() { if (String.valueOf(vfoCombobox.getSelectedItem()).equals("VFO A")) { return 0; } else { return 1; } } /** * @return Returns a new DefaultComboBoxModel containing all available COM ports */ private DefaultComboBoxModel getComportsComboboxModel() { String[] portNames = SerialPortList.getPortNames(); return new DefaultComboBoxModel(portNames); } /** * Fills the combo box "Modes" with the available Modes */ private void initModesCombobox() { DefaultComboBoxModel comboMode = new DefaultComboBoxModel( this.radioParser.getAvailableModes().toUpperCase().split(" ")); modesCombobox.setModel(comboMode); } private void initInfoTextarea() { String manufacturer = radioParser.getManufacturer(); infoTextarea.append("\n"); infoTextarea.append("manufacturer: " + manufacturer); infoTextarea.append("\n"); infoTextarea.append("model: " + radioParser.getModel()); infoTextarea.append("\n"); I_SerialSettings serialSettings = radioParser.getSerialPortSettings(); infoTextarea.append("serial port settings: " + serialSettings.toString()); infoTextarea.append("\n"); } /** * Handlers for events coming from the radio */ private class LocalRadioListener implements RadioListener { @Override public void eventNotsupported(NotsupportedEvent e) { } // not interested @Override public void eventConfirmation(ConfirmationEvent e) { } // not interested @Override public void eventFrequency(final FrequencyEvent e) { /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { if (e.getVfo() == RadioVfos.A) frequencyATextfield.setText(Misc.formatFrequency(e.getFrequency())); else if (e.getVfo() == RadioVfos.B) frequencyBTextfield.setText(Misc.formatFrequency(e.getFrequency())); else { frequencyATextfield.setText(Misc.formatFrequency(e.getFrequency())); logger.warning("Frequency event from unknown VFO!"); } } }); } @Override public void eventMode(final ModeEvent e) { /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { if (e.getVfo() == RadioVfos.A) modeATextfield.setText(e.getMode().toString()); else if (e.getVfo() == RadioVfos.B) modeBTextfield.setText(e.getMode().toString()); else { modeATextfield.setText(e.getMode().toString()); logger.warning("Mode event from unknown VFO!"); } } }); } @Override public void eventSmeter(final SmeterEvent e) { /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { meterProgressBar.setValue(e.getValue()); } }); } @Override public void eventActiveVfo(ActiveVfoEvent e) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; radioPanel = new javax.swing.JPanel(); displayPanel = new javax.swing.JPanel(); vfoAPanel = new javax.swing.JPanel(); frequencyATextfield = new javax.swing.JTextField(); modeATextfield = new javax.swing.JTextField(); vfoBPanel = new javax.swing.JPanel(); frequencyBTextfield = new javax.swing.JTextField(); modeBTextfield = new javax.swing.JTextField(); meterProgressBar = new javax.swing.JProgressBar(); settingsPanel = new javax.swing.JPanel(); comportCombobox = new javax.swing.JComboBox(); customComportTextfield = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); connectToRadioButton = new javax.swing.JToggleButton(); chooseRadioButton = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); infoTextarea = new javax.swing.JTextArea(); controlPanel = new javax.swing.JPanel(); bandsCombobox = new javax.swing.JComboBox(); modesCombobox = new javax.swing.JComboBox(); vfoCombobox = new javax.swing.JComboBox(); frequencyTextLabel = new javax.swing.JLabel(); modeTextLabel = new javax.swing.JLabel(); vfoTextLabel = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenu2 = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setName("Form"); // NOI18N radioPanel.setName("radioPanel"); // NOI18N radioPanel.setLayout(new java.awt.GridBagLayout()); displayPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("")); displayPanel.setName("displayPanel"); // NOI18N displayPanel.setLayout(new java.awt.GridBagLayout()); java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/lz1aq/jatu/Bundle"); // NOI18N vfoAPanel.setBorder(javax.swing.BorderFactory .createTitledBorder(bundle.getString("SimpleRadioPanel.vfoAPanel.border.title"))); // NOI18N vfoAPanel.setName("vfoAPanel"); // NOI18N vfoAPanel.setLayout(new java.awt.GridBagLayout()); frequencyATextfield.setBackground(new java.awt.Color(1, 1, 1)); frequencyATextfield.setFont(new java.awt.Font("Dialog", 0, 36)); // NOI18N frequencyATextfield.setForeground(new java.awt.Color(230, 230, 230)); frequencyATextfield.setHorizontalAlignment(javax.swing.JTextField.CENTER); frequencyATextfield.setText(bundle.getString("SimpleRadioPanel.frequencyATextfield.text")); // NOI18N frequencyATextfield.setCaretColor(new java.awt.Color(230, 230, 230)); frequencyATextfield.setName("frequencyATextfield"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; vfoAPanel.add(frequencyATextfield, gridBagConstraints); modeATextfield.setBackground(new java.awt.Color(1, 1, 1)); modeATextfield.setFont(new java.awt.Font("Dialog", 0, 36)); // NOI18N modeATextfield.setForeground(new java.awt.Color(230, 230, 230)); modeATextfield.setHorizontalAlignment(javax.swing.JTextField.CENTER); modeATextfield.setText(bundle.getString("SimpleRadioPanel.modeATextfield.text")); // NOI18N modeATextfield.setCaretColor(new java.awt.Color(230, 230, 230)); modeATextfield.setName("modeATextfield"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; vfoAPanel.add(modeATextfield, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); displayPanel.add(vfoAPanel, gridBagConstraints); vfoBPanel.setBorder(javax.swing.BorderFactory .createTitledBorder(bundle.getString("SimpleRadioPanel.vfoBPanel.border.title"))); // NOI18N vfoBPanel.setName("vfoBPanel"); // NOI18N vfoBPanel.setLayout(new java.awt.GridBagLayout()); frequencyBTextfield.setBackground(new java.awt.Color(1, 1, 1)); frequencyBTextfield.setFont(new java.awt.Font("Dialog", 0, 36)); // NOI18N frequencyBTextfield.setForeground(new java.awt.Color(230, 230, 230)); frequencyBTextfield.setHorizontalAlignment(javax.swing.JTextField.CENTER); frequencyBTextfield.setText(bundle.getString("SimpleRadioPanel.frequencyBTextfield.text")); // NOI18N frequencyBTextfield.setCaretColor(new java.awt.Color(230, 230, 230)); frequencyBTextfield.setName("frequencyBTextfield"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; vfoBPanel.add(frequencyBTextfield, gridBagConstraints); modeBTextfield.setBackground(new java.awt.Color(1, 1, 1)); modeBTextfield.setFont(new java.awt.Font("Dialog", 0, 36)); // NOI18N modeBTextfield.setForeground(new java.awt.Color(230, 230, 230)); modeBTextfield.setHorizontalAlignment(javax.swing.JTextField.CENTER); modeBTextfield.setText(bundle.getString("SimpleRadioPanel.modeBTextfield.text")); // NOI18N modeBTextfield.setCaretColor(new java.awt.Color(230, 230, 230)); modeBTextfield.setName("modeBTextfield"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; vfoBPanel.add(modeBTextfield, gridBagConstraints); meterProgressBar.setMaximum(30); meterProgressBar.setName("meterProgressBar"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); vfoBPanel.add(meterProgressBar, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); displayPanel.add(vfoBPanel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; radioPanel.add(displayPanel, gridBagConstraints); settingsPanel.setBackground(new java.awt.Color(210, 210, 210)); settingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("")); settingsPanel.setName("settingsPanel"); // NOI18N settingsPanel.setLayout(new java.awt.GridBagLayout()); comportCombobox.setModel(getComportsComboboxModel()); comportCombobox.setName("comportCombobox"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(20, 20, 0, 5); settingsPanel.add(comportCombobox, gridBagConstraints); customComportTextfield .setToolTipText(bundle.getString("SimpleRadioPanel.customComportTextfield.toolTipText")); // NOI18N customComportTextfield.setName("customComportTextfield"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(20, 5, 0, 5); settingsPanel.add(customComportTextfield, gridBagConstraints); jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setText(bundle.getString("SimpleRadioPanel.jLabel4.text")); // NOI18N jLabel4.setName("jLabel4"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 20, 20, 5); settingsPanel.add(jLabel4, gridBagConstraints); jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel5.setText(bundle.getString("SimpleRadioPanel.jLabel5.text")); // NOI18N jLabel5.setName("jLabel5"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 5, 20, 5); settingsPanel.add(jLabel5, gridBagConstraints); connectToRadioButton.setText(bundle.getString("SimpleRadioPanel.connectToRadioButton.text")); // NOI18N connectToRadioButton.setName("connectToRadioButton"); // NOI18N connectToRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { connectToRadioButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 20, 5, 5); settingsPanel.add(connectToRadioButton, gridBagConstraints); chooseRadioButton.setText(bundle.getString("SimpleRadioPanel.chooseRadioButton.text")); // NOI18N chooseRadioButton.setName("chooseRadioButton"); // NOI18N chooseRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseRadioButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 20, 5, 5); settingsPanel.add(chooseRadioButton, gridBagConstraints); jScrollPane1.setName("jScrollPane1"); // NOI18N infoTextarea.setColumns(20); infoTextarea.setRows(5); infoTextarea.setName("infoTextarea"); // NOI18N jScrollPane1.setViewportView(infoTextarea); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 20, 5, 5); settingsPanel.add(jScrollPane1, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; gridBagConstraints.weightx = 0.3; gridBagConstraints.weighty = 1.0; radioPanel.add(settingsPanel, gridBagConstraints); controlPanel.setBackground(new java.awt.Color(200, 200, 200)); controlPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("")); controlPanel.setName("controlPanel"); // NOI18N controlPanel.setLayout(new java.awt.GridBagLayout()); bandsCombobox.setModel(getBandsComboboxModel()); bandsCombobox.setName("bandsCombobox"); // NOI18N bandsCombobox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bandsComboboxActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(20, 20, 3, 20); controlPanel.add(bandsCombobox, gridBagConstraints); modesCombobox.setModel( new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); modesCombobox.setName("modesCombobox"); // NOI18N modesCombobox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { modesComboboxActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(20, 20, 3, 20); controlPanel.add(modesCombobox, gridBagConstraints); vfoCombobox.setModel(getVfoComboboxModel()); vfoCombobox.setName("vfoCombobox"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(20, 20, 3, 20); controlPanel.add(vfoCombobox, gridBagConstraints); frequencyTextLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); frequencyTextLabel.setText(bundle.getString("SimpleRadioPanel.frequencyTextLabel.text")); // NOI18N frequencyTextLabel.setToolTipText(bundle.getString("SimpleRadioPanel.frequencyTextLabel.toolTipText")); // NOI18N frequencyTextLabel.setName("frequencyTextLabel"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(1, 20, 1, 20); controlPanel.add(frequencyTextLabel, gridBagConstraints); modeTextLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); modeTextLabel.setText(bundle.getString("SimpleRadioPanel.modeTextLabel.text")); // NOI18N modeTextLabel.setName("modeTextLabel"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(1, 20, 1, 20); controlPanel.add(modeTextLabel, gridBagConstraints); vfoTextLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); vfoTextLabel.setText(bundle.getString("SimpleRadioPanel.vfoTextLabel.text")); // NOI18N vfoTextLabel.setName("vfoTextLabel"); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(1, 20, 1, 20); controlPanel.add(vfoTextLabel, gridBagConstraints); jButton1.setText(bundle.getString("SimpleRadioPanel.jButton1.text")); // NOI18N jButton1.setName("jButton1"); // NOI18N jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); controlPanel.add(jButton1, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 0.3; radioPanel.add(controlPanel, gridBagConstraints); jMenuBar1.setMargin(new java.awt.Insets(2, 2, 2, 2)); jMenuBar1.setName("jMenuBar1"); // NOI18N jMenu1.setText(bundle.getString("SimpleRadioPanel.jMenu1.text")); // NOI18N jMenu1.setName("jMenu1"); // NOI18N jMenuBar1.add(jMenu1); jMenu2.setText(bundle.getString("SimpleRadioPanel.jMenu2.text")); // NOI18N jMenu2.setToolTipText(bundle.getString("SimpleRadioPanel.jMenu2.toolTipText")); // NOI18N jMenu2.setName("jMenu2"); // NOI18N jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(radioPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 793, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(radioPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)); pack(); }// </editor-fold>//GEN-END:initComponents private void chooseRadioButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chooseRadioButtonActionPerformed {//GEN-HEADEREND:event_chooseRadioButtonActionPerformed int returnVal = chooser.showOpenDialog(this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { String moduleName = chooser.getSelectedFile().getName(); moduleName = StringUtils.removeEnd(moduleName, ".py"); String className = StringUtils.capitalize(moduleName); // The name of the Class withing the module(file) should be with the same name but with capital letter // Create radioParser object from the python Class JythonObjectFactory f2 = new JythonObjectFactory(I_Radio.class, moduleName, className); radioParser = (I_Radio) f2.createObject(); this.initModesCombobox(); this.initInfoTextarea(); } }//GEN-LAST:event_chooseRadioButtonActionPerformed private void connectToRadioButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_connectToRadioButtonActionPerformed {//GEN-HEADEREND:event_connectToRadioButtonActionPerformed JToggleButton tBtn = (JToggleButton) evt.getSource(); try { // Connect // ---------- if (tBtn.isSelected()) { if (radioParser == null) { JOptionPane.showMessageDialog(null, "Choose a radio first!", "Warning...", JOptionPane.INFORMATION_MESSAGE); connectToRadioButton.setSelected(false); return; } // Get comm port name String name = customComportTextfield.getText(); if (name.isEmpty()) name = String.valueOf(comportCombobox.getSelectedItem()); // Create the radio object using the selected Com port radio = new Radio(radioParser, name); radio.addEventListener(new LocalRadioListener()); radio.connect(); // Let's not forget to call connect(). Calling disconnects() later will close the Com Port } // Disconnect // ---------- else { if (radio != null) { radio.disconnect(); radio = null; } } } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } }//GEN-LAST:event_connectToRadioButtonActionPerformed private void bandsComboboxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bandsComboboxActionPerformed {//GEN-HEADEREND:event_bandsComboboxActionPerformed if (radio != null) { String freq = bandsCombobox.getSelectedItem().toString(); try { switch (freq) { case "1.8": radio.setFrequency(1810000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "3.5": radio.setFrequency(3500000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "7": radio.setFrequency(7000000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "10": radio.setFrequency(10000000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "14": radio.setFrequency(14000000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "18": radio.setFrequency(18000000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "21": radio.setFrequency(21000000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "24": radio.setFrequency(24000000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; case "28": radio.setFrequency(28000000, getVfo()); //radio.getFrequency(0); // after setting the frequency let's ask which will update our display break; } } catch (Exception exc) { logger.log(Level.SEVERE, null, exc); } //freq = freq.replaceAll("[^0-9]+", ""); // remove all non-digits } }//GEN-LAST:event_bandsComboboxActionPerformed private void modesComboboxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_modesComboboxActionPerformed {//GEN-HEADEREND:event_modesComboboxActionPerformed if (radio != null) { String mode = modesCombobox.getSelectedItem().toString(); try { radio.setMode(mode, getVfo()); } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } } }//GEN-LAST:event_modesComboboxActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed {//GEN-HEADEREND:event_jButton1ActionPerformed try { radio.sendCW("LZ1ABC"); } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { logger.log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { logger.log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { logger.log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { logger.log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SimpleRadioPanel().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox bandsCombobox; private javax.swing.JButton chooseRadioButton; private javax.swing.JComboBox comportCombobox; private javax.swing.JToggleButton connectToRadioButton; private javax.swing.JPanel controlPanel; private javax.swing.JTextField customComportTextfield; private javax.swing.JPanel displayPanel; private javax.swing.JTextField frequencyATextfield; private javax.swing.JTextField frequencyBTextfield; private javax.swing.JLabel frequencyTextLabel; private javax.swing.JTextArea infoTextarea; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JProgressBar meterProgressBar; private javax.swing.JTextField modeATextfield; private javax.swing.JTextField modeBTextfield; private javax.swing.JLabel modeTextLabel; private javax.swing.JComboBox modesCombobox; private javax.swing.JPanel radioPanel; private javax.swing.JPanel settingsPanel; private javax.swing.JPanel vfoAPanel; private javax.swing.JPanel vfoBPanel; private javax.swing.JComboBox vfoCombobox; private javax.swing.JLabel vfoTextLabel; // End of variables declaration//GEN-END:variables }