]> ruin.nu Git - moosique.git/blob - MooGUI.java
no message
[moosique.git] / MooGUI.java
1 import javax.sound.midi.*;
2 import javax.swing.*;
3 import java.awt.*;
4 import java.awt.event.*;
5
6 /**
7  * Moosique's graphical user interface.
8  * 
9  * @author  Einar Pehrson
10  */
11  
12 public class MooGUI extends JFrame {
13
14         private Sequence seq;
15         private MooMenu menu;
16         private MooToolbar toolbar;
17         private MooView view;
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);
21         
22         /** 
23          * Creates the GUI.
24          */
25         public MooGUI(Sequence seq) {
26                 super("Moosique");
27
28                 this.seq = seq;
29                 
30                 Container pane = getContentPane();
31                 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
32
33                 // Adds menu bar.
34                 menu = new MooMenu();
35                 setJMenuBar(menu);
36
37                 // Adds toolbar.
38                 toolbar = new MooToolbar();
39                 pane.add(toolbar, BorderLayout.NORTH);
40
41                 // Adds main view.
42                 view = new MooView(seq.getTracks());
43                 pane.add(view, BorderLayout.CENTER);
44
45                 // Adds status bar.
46                 statusBar = new JLabel("Welcome to Moosique!", JLabel.CENTER);
47                 statusBar.setFont(FONT);
48                 pane.add(statusBar, BorderLayout.SOUTH);
49
50                 // Brings on the colors!
51                 setBackground(pane);
52                 setBackground(menu);
53                 setBackground(toolbar);
54                 setBackground(view);
55                 statusBar.setBackground(bgColor);
56                 view.setBackground(bgColor);
57
58                 // Configures window.
59                 addWindowListener(new MooGUICloser());
60                 pack();
61                 Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
62                 setSize(bounds.width,bounds.height - 40);
63                 setLocation(0, 0);
64                 // setResizable(false);
65                 setBackground(Color.white);
66                 setVisible(true);
67                 show();
68         }
69
70         private void setBackground(Container c) {
71                 c.setBackground(bgColor);
72                 Component[] comps = c.getComponents();
73                 for (int i = 0; i < comps.length; i++) {
74                         comps[i].setBackground(bgColor);
75                 }
76         }
77         
78         /** 
79          * Changes the sequence of the GUI.
80          * @param sequence      the MIDI sequence to visualize
81          */
82         public void setSequence(Sequence sequence) {
83                 seq = sequence;
84                 view.update(seq.getTracks());
85         }
86
87         /** 
88          * Shows the given message in the status bar.
89          * @param text  the message to show
90          */
91         public void setStatus(String text) {
92                 statusBar.setText(text);
93         }
94         
95         class MooGUICloser extends WindowAdapter {
96                 public void windowClosing(WindowEvent e) {
97                         Moosique.quit();
98                 }
99         }
100 }