package instantbach.gui;
// Control
import instantbach.InstantBach;
// Custom GUI
import instantbach.gui.tab.InformationPanel;
import instantbach.gui.tab.ProgressionPanel;
import instantbach.gui.tab.TranspositionPanel;
// Standard GUI
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
// Custom Data
import instantbach.data.SymbolList;
import instantbach.data.Chord;
// Standard Data
import java.util.ArrayList;
/**
* <p>Title: Main Frame</p>
*
* <p>Description: Represents the GUI tier of this application</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author John Valentino II
* @version 1.0
*/
public class MainFrame extends JFrame {
/** Reference to the parent controller */
private InstantBach parent;
/** Represents the panel used to display the progression */
private ProgressionPanel progressionPanel;
/** Represents the panel used to display the transposition options */
private TranspositionPanel transpositionPanel;
/** Represents the information panel */
private InformationPanel informationPanel;
/**
* Creates the frame for this application
* @param parent InstantBach
* @param availableSymbols SymbolList
*/
public MainFrame(InstantBach parent, SymbolList availableSymbols) {
this.parent = parent;
progressionPanel = new ProgressionPanel(this, availableSymbols);
transpositionPanel = new TranspositionPanel(this);
informationPanel = new InformationPanel(this);
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add(progressionPanel, "Progression");
tabbedPane.add(transpositionPanel, "Transposition");
tabbedPane.add(informationPanel, "Information");
tabbedPane.setEnabledAt(1, false);
setContentPane(tabbedPane);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("Instant Bach v"+parent.getVersion() + " - John Valentino II");
}
/**
* Displays the givne chords for the given progression
* @param prog SymbolList
* @param chords Chord[]
*/
public synchronized void displayChords(SymbolList prog, Chord[] chords) {
progressionPanel.displayChords(prog, chords);
}
/**
* Generates a random progression and attempts to voice it
*/
public synchronized void generateAndVoiceProgression() {
parent.generateAndVoiceProgression();
}
/**
* Attempts to voice the specified progression
* @param progression SymbolList
*/
public synchronized void voiceProgression(SymbolList progression) {
parent.voiceProgression(progression);
}
/**
* Displays the given error
* @param errors ArrayList
*/
public synchronized void displayErrors(final ArrayList<String> errors) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String text = "";
for (int i = 0; i < errors.size(); i++) {
text += errors.get(i) + "\n";
}
JOptionPane.showMessageDialog(null,
text,
"Error",
JOptionPane.ERROR_MESSAGE);
}
});
}
/**
* Appends the given text to the information area
* @param line String
*/
public synchronized void appendInfo(String line) {
informationPanel.appendInfo(line);
}
/**
* Clears the information area
*/
public synchronized void clearArea() {
informationPanel.clear();
}
}