Added Initial UI code.

No comments in code yet / needs cleaning.
This commit is contained in:
Sam Archer 2011-10-09 03:17:53 -07:00
parent ff335bbc81
commit e7b18aa8ef
4 changed files with 510 additions and 0 deletions

View File

@ -0,0 +1,172 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="comSelectionMenu" min="-2" pref="79" max="-2" attributes="0"/>
<Component id="statusLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jSeparator1" alignment="1" pref="380" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="sequenceNameLabel" min="-2" max="-2" attributes="0"/>
<Component id="jSlider1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="bpmLabel" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="30" max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<Component id="startButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="stopButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="loadButton" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="comSelectionMenu" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="107" max="32767" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="sequenceNameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="loadButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
<Component id="bpmLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="startButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="stopButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jSlider1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
<Component id="jSeparator1" min="-2" pref="8" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="statusLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="startButton">
<Properties>
<Property name="text" type="java.lang.String" value="Start"/>
<Property name="enabled" type="boolean" value="false"/>
<Property name="name" type="java.lang.String" value="startButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="startButtonClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="stopButton">
<Properties>
<Property name="text" type="java.lang.String" value="Stop/Reset"/>
<Property name="name" type="java.lang.String" value="stopButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="stopResetClicked"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="comSelectionMenu">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
<Property name="name" type="java.lang.String" value="comSelectionMenu" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="comPortSelected"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="statusLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Loading application..."/>
<Property name="name" type="java.lang.String" value="statusLabel" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JSeparator" name="jSeparator1">
<Properties>
<Property name="name" type="java.lang.String" value="jSeparator1" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="loadButton">
<Properties>
<Property name="text" type="java.lang.String" value="Load Sequence"/>
<Property name="name" type="java.lang.String" value="loadButton" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="loadSequence"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="sequenceNameLabel">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;None loaded&gt;"/>
<Property name="name" type="java.lang.String" value="sequenceNameLabel" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Current Sequence:"/>
<Property name="name" type="java.lang.String" value="jLabel1" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JSlider" name="jSlider1">
<Properties>
<Property name="majorTickSpacing" type="int" value="10"/>
<Property name="maximum" type="int" value="210"/>
<Property name="minimum" type="int" value="20"/>
<Property name="paintTicks" type="boolean" value="true"/>
<Property name="value" type="int" value="120"/>
<Property name="name" type="java.lang.String" value="jSlider1" noResource="true"/>
</Properties>
<Events>
<EventHandler event="mouseDragged" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="tempoSliderChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="bpmLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="jSlider1.getValue() + &quot; bpm&quot;" type="code"/>
</Property>
<Property name="name" type="java.lang.String" value="bpmLabel" noResource="true"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,296 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MoppyMainWindow.java
*
* Created on Oct 8, 2011, 8:34:57 PM
*/
package moppydesk;
import gnu.io.CommPortIdentifier;
import java.io.File;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JSlider;
/**
*
* @author Sam
*/
public class MoppyMainWindow extends javax.swing.JFrame implements MoppyStatusConsumer{
static String PREF_COM_PORT = "comPort";
static String PREF_LOADED_SEQ = "loadedSequencePath";
MoppyUI app;
Preferences prefs = Preferences.userNodeForPackage(MoppyUI.class);
final JFileChooser sequenceChooser = new JFileChooser();
boolean comboBoxReady = false;
/** Creates new form MoppyMainWindow */
public MoppyMainWindow(MoppyUI app) {
this.app = app;
initComponents();
updateComSelectionMenu();
initializeSequencer((String) comSelectionMenu.getSelectedItem());
String previouslyLoadedFile = prefs.get(PREF_LOADED_SEQ, null);
if (previouslyLoadedFile != null){
loadSequenceFile(new File(previouslyLoadedFile));
}
}
private void updateComSelectionMenu() {
comboBoxReady = false;
comSelectionMenu.removeAllItems();
Enumeration<CommPortIdentifier> e = CommPortIdentifier.getPortIdentifiers();
while (e.hasMoreElements()) {
comSelectionMenu.addItem(e.nextElement().getName());
}
comSelectionMenu.setSelectedItem(prefs.get(PREF_COM_PORT, ""));
comboBoxReady = true;
}
private void initializeSequencer(String comPort) {
statusLabel.setText("Initializing sequencer...");
if (app.ms != null) {
app.ms.closeSequencer();
}
try {
app.ms = new MoppySequencer(comPort);
app.ms.addListener(this);
} catch (Exception ex) {
Logger.getLogger(MoppyMainWindow.class.getName()).log(Level.SEVERE, null, ex);
statusLabel.setText("Sequencer initialization error!");
JOptionPane.showMessageDialog(rootPane, ex);
}
statusLabel.setText("Sequencer connected to " + comPort);
}
/** 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() {
startButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
comSelectionMenu = new javax.swing.JComboBox();
statusLabel = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
loadButton = new javax.swing.JButton();
sequenceNameLabel = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jSlider1 = new javax.swing.JSlider();
bpmLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
MoppyMainWindow.this.windowClosing(evt);
}
});
startButton.setText("Start");
startButton.setEnabled(false);
startButton.setName("startButton"); // NOI18N
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startButtonClicked(evt);
}
});
stopButton.setText("Stop/Reset");
stopButton.setName("stopButton"); // NOI18N
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopResetClicked(evt);
}
});
comSelectionMenu.setName("comSelectionMenu"); // NOI18N
comSelectionMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comPortSelected(evt);
}
});
statusLabel.setText("Loading application...");
statusLabel.setName("statusLabel"); // NOI18N
jSeparator1.setName("jSeparator1"); // NOI18N
loadButton.setText("Load Sequence");
loadButton.setName("loadButton"); // NOI18N
loadButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loadSequence(evt);
}
});
sequenceNameLabel.setText("<None loaded>");
sequenceNameLabel.setName("sequenceNameLabel"); // NOI18N
jLabel1.setText("Current Sequence:");
jLabel1.setName("jLabel1"); // NOI18N
jSlider1.setMajorTickSpacing(10);
jSlider1.setMaximum(210);
jSlider1.setMinimum(20);
jSlider1.setPaintTicks(true);
jSlider1.setValue(120);
jSlider1.setName("jSlider1"); // NOI18N
jSlider1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
tempoSliderChanged(evt);
}
});
bpmLabel.setText(jSlider1.getValue() + " bpm");
bpmLabel.setName("bpmLabel"); // NOI18N
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(comSelectionMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(statusLabel)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sequenceNameLabel)
.addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(bpmLabel, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(startButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(stopButton))
.addComponent(loadButton)))
.addComponent(jLabel1))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(comSelectionMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sequenceNameLabel)
.addComponent(loadButton))
.addGap(18, 18, 18)
.addComponent(bpmLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(startButton)
.addComponent(stopButton))
.addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(11, 11, 11)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusLabel)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void stopResetClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopResetClicked
statusLabel.setText("Stopping...");
app.ms.stopSequencer();
startButton.setEnabled(true);
statusLabel.setText("Stopped");
}//GEN-LAST:event_stopResetClicked
private void startButtonClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonClicked
startButton.setEnabled(false);
app.ms.startSequencer();
}//GEN-LAST:event_startButtonClicked
private void loadSequence(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadSequence
String previouslyLoaded = prefs.get(PREF_LOADED_SEQ, null);
if (previouslyLoaded != null){
sequenceChooser.setCurrentDirectory(new File(previouslyLoaded));
}
int returnVal = sequenceChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
loadSequenceFile(sequenceChooser.getSelectedFile());
} else {
//Cancelled
}
}//GEN-LAST:event_loadSequence
private void loadSequenceFile(File sequenceFile){
try {
statusLabel.setText("Loading file...");
app.ms.loadFile(sequenceFile.getPath());
sequenceNameLabel.setText(sequenceFile.getName());
prefs.put(PREF_LOADED_SEQ, sequenceFile.getPath());
statusLabel.setText("Loaded " + sequenceFile.getName());
startButton.setEnabled(true);
} catch (Exception ex) {
Logger.getLogger(MoppyMainWindow.class.getName()).log(Level.SEVERE, null, ex);
statusLabel.setText("File loading error!");
JOptionPane.showMessageDialog(rootPane, ex);
}
}
private void tempoSliderChanged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tempoSliderChanged
JSlider s = (JSlider) evt.getSource();
app.ms.setTempo(s.getValue());
bpmLabel.setText(s.getValue() + " bpm");
}//GEN-LAST:event_tempoSliderChanged
private void comPortSelected(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comPortSelected
JComboBox cb = (JComboBox) evt.getSource();
if (comboBoxReady) {
String comPort = (String) cb.getSelectedItem();
initializeSequencer(comPort);
prefs.put(PREF_COM_PORT, comPort);
}
}//GEN-LAST:event_comPortSelected
private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
app.ms.closeSequencer();
}//GEN-LAST:event_windowClosing
public void tempoChanged(int newTempo) {
jSlider1.setValue(newTempo);
bpmLabel.setText(newTempo + " bpm");
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel bpmLabel;
private javax.swing.JComboBox comSelectionMenu;
private javax.swing.JLabel jLabel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSlider jSlider1;
private javax.swing.JButton loadButton;
private javax.swing.JLabel sequenceNameLabel;
private javax.swing.JButton startButton;
private javax.swing.JLabel statusLabel;
private javax.swing.JButton stopButton;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,13 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package moppydesk;
/**
*
* @author Sam
*/
public interface MoppyStatusConsumer {
public void tempoChanged(int newTempo);
}

View File

@ -0,0 +1,29 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package moppydesk;
import org.jdesktop.application.SingleFrameApplication;
/**
*
* @author Sam
*/
public class MoppyUI extends SingleFrameApplication{
MoppySequencer ms = null;
@Override
protected void startup() {
show(new MoppyMainWindow(this));
}
/**
* Main method launching the application.
*/
public static void main(String[] args) {
launch(MoppyUI.class, args);
}
}