]> ruin.nu Git - moosique.git/blob - MooGUI.java
global keylistener..
[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);
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                 ActionMap am = getRootPane().getActionMap();
59
60                 Action playAction = new AbstractAction() {
61                         public void actionPerformed(ActionEvent ae) {
62                                 Moosique.resumepause();
63                         }};
64                 am.put("play", playAction);
65
66                 InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
67                 KeyStroke playKey = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
68                 im.put(playKey, "play");
69
70
71                 // Configures window.
72                 addWindowListener(new MooGUICloser());
73                 pack();
74                 Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
75                 setSize(bounds.width,bounds.height - 40);
76                 setLocation(0, 0);
77                 // setResizable(false);
78                 setBackground(Color.white);
79                 setVisible(true);
80                 show();
81         }
82
83         private void setBackground(Container c) {
84                 c.setBackground(bgColor);
85                 Component[] comps = c.getComponents();
86                 for (int i = 0; i < comps.length; i++) {
87                         comps[i].setBackground(bgColor);
88                 }
89         }
90
91         /** 
92          * Changes the sequence of the GUI.
93          * @param sequence      the MIDI sequence to visualize
94          */
95         public void setSequence(Sequence sequence) {
96                 seq = sequence;
97                 view.setSequence(seq);
98         }
99
100         /** 
101          * Shows the given message in the status bar.
102          * @param text  the message to show
103          */
104         public void setStatus(String text) {
105                 statusBar.setText(text);
106         }
107
108         /**
109          * Update the view.
110          */
111         public void update(){
112                 view.update();
113                 // Calls on the toolbar to update the progress indicator.
114                 //toolbar.updateProgInd();
115         }
116
117         class MooGUICloser extends WindowAdapter {
118                 public void windowClosing(WindowEvent e) {
119                         Moosique.quit();
120                 }
121         }
122 }