1 import javax.sound.midi.*;
4 import java.awt.event.*;
7 * Moosique's graphical user interface.
9 * @author Einar Pehrson
12 public class MooGUI extends JFrame {
16 private MooToolbar toolbar;
18 private JLabel statusBar;
19 public static final Font FONT = new Font("Helvetica", Font.PLAIN, 10);
20 public static final Color bgColor = new Color(192, 224, 255);
25 public MooGUI(Sequence seq) {
30 Container pane = getContentPane();
31 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
38 toolbar = new MooToolbar();
39 pane.add(toolbar, BorderLayout.NORTH);
42 view = new MooView(seq.getTracks());
43 pane.add(view, BorderLayout.CENTER);
46 statusBar = new JLabel("Welcome to Moosique!", JLabel.CENTER);
47 statusBar.setFont(FONT);
48 pane.add(statusBar, BorderLayout.SOUTH);
50 // Brings on the colors!
53 setBackground(toolbar);
55 statusBar.setBackground(bgColor);
56 view.setBackground(bgColor);
58 // Sets up global key listener
59 ActionMap am = getRootPane().getActionMap();
61 Action playAction = new AbstractAction() {
62 public void actionPerformed(ActionEvent ae) {
63 if (!Moosique.getSequencer().isRunning()) {
69 am.put("Play", playAction);
71 InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
72 KeyStroke playKey = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
73 im.put(playKey, "Play");
76 addWindowListener(new MooGUICloser());
78 setIconImage(Toolkit.getDefaultToolkit().getImage("images/moose.gif"));
79 Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
80 setSize(bounds.width,bounds.height - 40);
82 // setResizable(false);
83 setBackground(Color.white);
88 private void setBackground(Container c) {
89 c.setBackground(bgColor);
90 Component[] comps = c.getComponents();
91 for (int i = 0; i < comps.length; i++) {
92 comps[i].setBackground(bgColor);
97 * Changes the sequence of the GUI.
98 * @param sequence the MIDI sequence to visualize
100 public void setSequence(Sequence sequence) {
102 view.setTracks(seq.getTracks());
106 * Shows the given message in the status bar.
107 * @param text the message to show
109 public void setStatus(String text) {
110 statusBar.setText(text);
114 * Calls on the main view to update the track views,
115 * and on the toolbar to update the progress indicator.
117 public void update(){
119 toolbar.updateProgInd();
122 class MooGUICloser extends WindowAdapter {
123 public void windowClosing(WindowEvent e) {