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) {
31 Container pane = getContentPane();
32 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
39 toolbar = new MooToolbar();
40 pane.add(toolbar, BorderLayout.NORTH);
43 view = new MooView(seq.getTracks());
44 pane.add(view, BorderLayout.CENTER);
47 statusBar = new JLabel("Welcome to Moosique!", JLabel.CENTER);
48 statusBar.setFont(FONT);
49 pane.add(statusBar, BorderLayout.SOUTH);
51 // Brings on the colors!
54 setBackground(toolbar);
56 statusBar.setBackground(bgColor);
57 view.setBackground(bgColor);
59 // Sets up global key listener
60 ActionMap am = getRootPane().getActionMap();
62 Action playAction = new AbstractAction() {
63 public void actionPerformed(ActionEvent ae) {
64 if (!Moosique.getSequencer().isRunning()) {
70 am.put("Play", playAction);
72 InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
73 KeyStroke playKey = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
74 im.put(playKey, "Play");
77 addWindowListener(new MooGUICloser());
79 setIconImage(Toolkit.getDefaultToolkit().getImage("images/moose.gif"));
80 Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
81 setSize(bounds.width,bounds.height - 40);
83 // setResizable(false);
84 setBackground(Color.white);
89 private void setBackground(Container c) {
90 c.setBackground(bgColor);
91 Component[] comps = c.getComponents();
92 for (int i = 0; i < comps.length; i++) {
93 comps[i].setBackground(bgColor);
98 * Changes the sequence of the GUI.
99 * @param sequence the MIDI sequence to visualize
101 public void setSequence(Sequence sequence) {
103 view.setTracks(seq.getTracks());
104 toolbar.resetProgInd();
108 * Shows the given message in the status bar.
109 * @param text the message to show
111 public void setStatus(String text) {
112 statusBar.setText(text);
116 * Calls on the main view to update the track views,
117 * and on the toolbar to update the progress indicator.
119 public void update(long tickPosition){
120 view.update(tickPosition);
121 toolbar.updateProgInd(tickPosition);
124 class MooGUICloser extends WindowAdapter {
125 public void windowClosing(WindowEvent e) {