1 import javax.sound.midi.*;
4 import java.awt.event.*;
8 * Moosique's graphical user interface.
10 * @author Einar Pehrson
13 public class MooGUI extends JFrame {
17 private MooToolbar toolbar;
19 private JLabel statusBar;
20 private java.util.Timer timer;
21 public static final int statusResetDelay = 3000;
22 public static final Font FONT = new Font("Helvetica", Font.PLAIN, 10);
23 public static final Color bgColor = new Color(192, 224, 255);
28 public MooGUI(Sequence seq) {
33 Container pane = getContentPane();
34 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
41 toolbar = new MooToolbar();
42 pane.add(toolbar, BorderLayout.NORTH);
45 view = new MooView(seq.getTracks());
46 pane.add(view, BorderLayout.CENTER);
49 statusBar = new JLabel("Welcome to Moosique!", JLabel.CENTER);
50 statusBar.setFont(FONT);
51 pane.add(statusBar, BorderLayout.SOUTH);
53 // Brings on the colors!
56 setBackground(toolbar);
58 statusBar.setBackground(bgColor);
59 view.setBackground(bgColor);
62 timer = new java.util.Timer();
64 // Sets up global key listener
65 ActionMap am = getRootPane().getActionMap();
67 Action playAction = new AbstractAction() {
68 public void actionPerformed(ActionEvent ae) {
69 if (!Moosique.getSequencer().isRunning()) {
75 am.put("Play", playAction);
77 InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
78 KeyStroke playKey = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
79 im.put(playKey, "Play");
82 addWindowListener(new MooGUICloser());
84 setIconImage(Toolkit.getDefaultToolkit().getImage("images/moose.gif"));
85 Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
86 setSize(bounds.width,bounds.height - 40);
88 // setResizable(false);
89 setBackground(Color.white);
94 private void setBackground(Container c) {
95 c.setBackground(bgColor);
96 Component[] comps = c.getComponents();
97 for (int i = 0; i < comps.length; i++) {
98 comps[i].setBackground(bgColor);
103 * Changes the sequence of the GUI.
104 * @param sequence the MIDI sequence to visualize
106 public void setSequence(Sequence sequence) {
108 view.setTracks(seq.getTracks());
109 toolbar.resetProgInd();
113 * Shows the given message in the status bar.
114 * @param text the message to show
116 public void setStatus(String text) {
117 statusBar.setText(text);
118 timer.schedule(new StatusResetTask(), statusResetDelay);
122 * Calls on the main view to update the track views,
123 * and on the toolbar to update the progress indicator.
125 public void update(long tickPosition){
126 view.update(tickPosition);
127 toolbar.updateProgInd(tickPosition);
130 class MooGUICloser extends WindowAdapter {
131 public void windowClosing(WindowEvent e) {
136 class StatusResetTask extends TimerTask {