]> ruin.nu Git - moosique.git/blob - MooTrackTitle.java
sets and gets the channel..
[moosique.git] / MooTrackTitle.java
1 import javax.swing.*;
2 import java.awt.*;
3 import java.awt.event.*;
4 import javax.sound.midi.*;
5
6 /**
7  * The title bar for each track with track name, channel, instrument etc.
8  * 
9  * @author  Andersson, Andreen, Lanneskog, Pehrson
10  * @version 1
11  */
12  
13 public class MooTrackTitle extends JPanel {
14
15         private JTextField title;
16         private MooInstrumentList instruments;
17         private JComboBox channel;
18         private JCheckBox mute;
19         private JCheckBox solo;
20         private Track track;
21         /** 
22          * Creates the title bar.
23          */
24         public MooTrackTitle (Track aTrack) {
25                 track = aTrack;
26                 setLayout(new GridLayout(4,1));
27                 setBorder(BorderFactory.createLineBorder(Color.black));
28
29                 setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
30                 title = new JTextField(); // JTextField(String text, int columns) 
31                 title.setFont(Moosique.getGUI().FONT);
32                 title.addFocusListener(new TitleFocusListener());
33                 add(title);
34
35                 instruments = new MooInstrumentList();
36                 add(instruments);
37
38                 JPanel checkboxes = new JPanel();
39                 checkboxes.setLayout(new GridLayout(1,3));
40
41                 channel = new JComboBox();
42                 channel.setFont(Moosique.getGUI().FONT);
43                 for (int i = 1; i <= 16; i++)
44                         channel.addItem(new Integer(i));
45
46                 for (int j = 0; j < track.size(); j++) {
47                         MidiEvent me = track.get(j);
48                 if (me instanceof MooNote){
49                                 MooNote mn = (MooNote)me;
50                                 channel.setSelectedIndex(mn.getChannel());
51                                 break;
52                         }
53         }
54
55                 channel.addItemListener(new ItemListener(){
56                                 public void itemStateChanged(ItemEvent e){
57                                         Object ob = channel.getSelectedItem();
58                                         if (ob instanceof Integer){
59                                                 int chan = ((Integer)ob).intValue();
60                                                 //set channel
61                                                 MidiEvent me;
62                                                 MooNote mn;
63                                                 for (int j = 0; j < track.size(); j++) {
64                                                         me = track.get(j);
65                                                 if (me instanceof MooNote){
66                                                                 mn = (MooNote)me;
67                                                                 mn.setChannel(chan);
68                                                                 System.out.println(ob);
69                                                         }
70                                     }
71                                         }
72                                 }});
73
74                 add(channel);
75                 
76
77                 mute = new JCheckBox("Mute");
78                 mute.setFont(Moosique.getGUI().FONT);
79                 mute.addActionListener(new ActionListener(){
80                                 public void actionPerformed(ActionEvent event){
81                                         //setMute
82                                         solo.setSelected(false);
83                                 }});
84                 checkboxes.add(mute);
85
86                 solo = new JCheckBox("Solo");
87                 solo.setFont(Moosique.getGUI().FONT);
88                 solo.addActionListener(new ActionListener(){
89                                 public void actionPerformed(ActionEvent event){
90                                         //setSolo
91                                         mute.setSelected(false);
92                                 }});
93                 checkboxes.add(solo);
94                 add(checkboxes);
95         }
96
97         class TitleFocusListener extends FocusAdapter {
98                 public void focusLost(FocusEvent e) {
99                         // Update the MidiEvent containing the title of this track
100                 }
101         }
102 }