package moppydesk.testing;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.UnsupportedCommOperationException;
import java.io.IOException;
import java.util.HashMap;
import java.util.TooManyListenersException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
/**
*
* @author Sam
*/
public class FloppySimWindow extends javax.swing.JFrame {
MoppyFloppySim app;
HashMap<Integer,FloppyDisplay> displays = new HashMap<Integer,FloppyDisplay>();
FloppySimWindow(MoppyFloppySim app) {
this.app = app;
initComponents();
setupDrivesPanel();
}
private void setupDrivesPanel(){
displays.clear();
drivesPanel.removeAll();
//Just 8 drives for now; this can be altered to create larger setups.
for (int p=2;p<=16;p+=2){
FloppyDisplay newDisplay = new FloppyDisplay(p/2, p);
displays.put(p, newDisplay);
drivesPanel.add(newDisplay);
}
}
public void displayNote(int pin, String note){
if (displays.containsKey(pin)){
displays.get(pin).setNote(note);
}
}
public String getSelectedCOM(){
return (String) comComboBox.getSelectedItem();
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
comComboBox = new javax.swing.JComboBox();
drivesPanel = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Moppy Floppy Simulator");
setMinimumSize(new java.awt.Dimension(500, 350));
jLabel1.setText("Listen on:");
comComboBox.setModel(new DefaultComboBoxModel(app.getAvailableCOMPorts()));
comComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comComboBoxActionPerformed(evt);
}
});
drivesPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(drivesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 356, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(comComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(drivesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void comComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comComboBoxActionPerformed
String comPort = (String) ((JComboBox) evt.getSource()).getSelectedItem();
try {
app.mCom.openPort(comPort);
} catch (Exception ex){
JOptionPane.showMessageDialog(rootPane, ex);
Logger.getLogger(FloppySimWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_comComboBoxActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox comComboBox;
private javax.swing.JPanel drivesPanel;
private javax.swing.JLabel jLabel1;
// End of variables declaration//GEN-END:variables
}