/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.joshondesign.arduinox;
import com.joshondesign.arduino.common.Device;
import com.joshondesign.arduino.common.Util;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
*
* @author josh
*/
public class DeviceChooser extends javax.swing.JPanel {
/**
* Creates new form DeviceChooser
*/
public DeviceChooser() {
initComponents();
Global g = Global.getGlobal();
serialPortList.setModel(new DefaultComboBoxModel(Global.getGlobal().getPorts().toArray()));
serialPortList.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if(comp instanceof JLabel && value instanceof SerialPort) {
JLabel label = (JLabel) comp;
SerialPort port = (SerialPort) value;
label.setText(port.shortName);
}
return comp;
}
});
deviceList.setModel(new DefaultComboBoxModel(Global.getGlobal().getDevices().toArray()));
deviceList.setCellRenderer(new DefaultListCellRenderer(){
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if(comp instanceof JLabel && value instanceof Device) {
JLabel label = (JLabel) comp;
Device device = (Device) value;
label.setText(device.getName());
}
return comp;
}
});
deviceList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if(e.getValueIsAdjusting()) return;
Device device = (Device) deviceList.getSelectedValue();
deviceName.setText(device.getName());
deviceMaxSize.setText(""+device.getMaxSize());
deviceMaxSpeed.setText(""+device.getUploadSpeed());
deviceCPUName.setText(device.getMCU());
}
});
}
/**
* 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() {
closeButton = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
deviceList = new javax.swing.JList();
configList = new javax.swing.JComboBox();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
serialPortList = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
newConfigButton = new javax.swing.JButton();
deleteConfigButton = new javax.swing.JButton();
deviceMaxSize = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
deviceMaxSpeed = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
deviceName = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
deviceCPUName = new javax.swing.JLabel();
closeButton.setText("Close");
closeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeButtonActionPerformed(evt);
}
});
deviceList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
deviceList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
deviceListValueChanged(evt);
}
});
jScrollPane2.setViewportView(deviceList);
configList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jLabel1.setText("Configuration");
jLabel2.setText("Serial Port");
serialPortList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jLabel3.setText("Device");
jLabel4.setText("Name:");
newConfigButton.setText("New");
newConfigButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newConfigButtonActionPerformed(evt);
}
});
deleteConfigButton.setText("Delete");
deleteConfigButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteConfigButtonActionPerformed(evt);
}
});
deviceMaxSize.setText("jLabel5");
jLabel6.setText("Max Size:");
deviceMaxSpeed.setText("jLabel7");
jLabel8.setText("Upload Speed:");
deviceName.setText("deviceName");
jLabel5.setText("CPU:");
deviceCPUName.setText("jLabel7");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 290, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(12, 12, 12)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel8)
.add(jLabel6)
.add(jLabel4)
.add(jLabel5))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(deviceName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
.add(deviceMaxSize, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(deviceMaxSpeed, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(deviceCPUName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jLabel2)
.add(serialPortList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3))
.add(0, 0, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(0, 0, Short.MAX_VALUE)
.add(closeButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 79, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(configList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(newConfigButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(deleteConfigButton)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(7, 7, 7)
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(configList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(newConfigButton)
.add(deleteConfigButton))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(serialPortList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createSequentialGroup()
.add(deviceName)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(deviceMaxSize)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(deviceMaxSpeed)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(deviceCPUName))
.add(layout.createSequentialGroup()
.add(jLabel4)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel6)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel8)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel5)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(closeButton)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void newConfigButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newConfigButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_newConfigButtonActionPerformed
private void deleteConfigButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteConfigButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_deleteConfigButtonActionPerformed
private void deviceListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_deviceListValueChanged
Util.p("yours is the hardest");
}//GEN-LAST:event_deviceListValueChanged
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
SwingUtilities.getWindowAncestor(this).setVisible(false);
SwingUtilities.getWindowAncestor(this).dispose();
}//GEN-LAST:event_closeButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton closeButton;
private javax.swing.JComboBox configList;
private javax.swing.JButton deleteConfigButton;
private javax.swing.JLabel deviceCPUName;
private javax.swing.JList deviceList;
private javax.swing.JLabel deviceMaxSize;
private javax.swing.JLabel deviceMaxSpeed;
private javax.swing.JLabel deviceName;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel8;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton newConfigButton;
private javax.swing.JComboBox serialPortList;
// End of variables declaration//GEN-END:variables
}