Subversion Repositories svn.mios

Rev

Rev 741 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
628 adamjking 1
/*
2
 * @(#)VirtualKeyboardGUI.java  beta8   2006/04/23
3
 *
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
5
 *
6
 * This application is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this application; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
package org.midibox.apps.virtualkeyboard.gui;
22
 
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
 
28
import javax.swing.BorderFactory;
29
import javax.swing.JCheckBoxMenuItem;
30
import javax.swing.JMenu;
31
import javax.swing.JMenuBar;
32
import javax.swing.JOptionPane;
33
import javax.swing.JPanel;
34
import javax.swing.UIManager;
35
import javax.swing.event.MenuEvent;
36
import javax.swing.event.MenuListener;
37
 
38
import org.midibox.apps.virtualkeyboard.VirtualKeyboard;
662 adamjking 39
import org.midibox.midi.MidiRouterDevice;
628 adamjking 40
import org.midibox.midi.gui.MidiDeviceRoutingGUI;
41
import org.midibox.midi.gui.MidiKeyboardControllerGUI;
662 adamjking 42
import org.midibox.utils.gui.ImageLoader;
628 adamjking 43
 
44
public class VirtualKeyboardGUI extends JPanel {
45
 
46
    private MidiKeyboardControllerGUI midiKeyboardControllerGUI;
47
 
48
    private MidiDeviceRoutingGUI midiDeviceRoutingGUI;
49
 
50
    private JMenu fileMenu;
51
 
52
    private boolean showConnections;
53
 
54
    private JCheckBoxMenuItem showConnectionsItem;
55
 
56
    private JMenu lookAndFeelMenu;
57
 
58
    private String lookAndFeel;
741 adamjking 59
 
60
    protected VirtualKeyboard virtualKeyboard;
628 adamjking 61
 
62
    public VirtualKeyboardGUI(VirtualKeyboard virtualKeyboard) {
63
 
64
        super(new GridBagLayout());
65
 
741 adamjking 66
        this.virtualKeyboard = virtualKeyboard;
67
 
628 adamjking 68
        lookAndFeel = UIManager.getLookAndFeel().getClass().getName();
69
 
70
        GridBagConstraints gbc = new GridBagConstraints();
71
        gbc.gridx = 0;
72
        gbc.gridy = 0;
73
        gbc.gridheight = 1;
74
        gbc.gridwidth = 1;
75
        gbc.fill = GridBagConstraints.BOTH;
76
        gbc.weightx = 1;
77
        gbc.weighty = 1;
78
 
79
        midiDeviceRoutingGUI = new MidiDeviceRoutingGUI(virtualKeyboard
80
                .getMidiDeviceRouting());
81
 
82
        midiDeviceRoutingGUI.setBorder(BorderFactory.createEtchedBorder());
83
 
662 adamjking 84
        midiDeviceRoutingGUI.addMidiDeviceIcon(MidiRouterDevice.class,
85
                ImageLoader.getImageIcon("virtualMidiDevice.png"));
86
 
628 adamjking 87
        add(midiDeviceRoutingGUI, gbc);
88
 
89
        gbc.gridy++;
90
 
91
        gbc.fill = GridBagConstraints.NONE;
92
        gbc.weightx = 0;
93
        gbc.weighty = 0;
94
 
95
        midiKeyboardControllerGUI = new MidiKeyboardControllerGUI(
96
                virtualKeyboard.getMidiKeyboardControllerDevice()
97
                        .getMidiKeyboardController());
98
 
99
        midiKeyboardControllerGUI.setBorder(BorderFactory.createEtchedBorder());
100
 
101
        add(midiKeyboardControllerGUI, gbc);
102
    }
103
 
104
    public JMenuBar createMenuBar() {
105
        JMenuBar menuBar = new JMenuBar();
106
 
107
        fileMenu = new JMenu("File");
108
 
109
        menuBar.add(fileMenu);
110
 
738 adamjking 111
        JMenu optionsMenu = new JMenu("Options");
628 adamjking 112
 
113
        showConnectionsItem = new JCheckBoxMenuItem("Show Connections",
114
                isShowConnections());
738 adamjking 115
 
628 adamjking 116
        showConnectionsItem.addActionListener(new ActionListener() {
117
            public void actionPerformed(ActionEvent ae) {
118
                setShowConnections(showConnectionsItem.isSelected());
119
            }
120
        });
121
 
738 adamjking 122
        optionsMenu.add(showConnectionsItem);
628 adamjking 123
 
124
        lookAndFeelMenu = new JMenu("Look & Feel");
738 adamjking 125
 
628 adamjking 126
        lookAndFeelMenu.addMenuListener(new MenuListener() {
127
 
128
            public void menuCanceled(MenuEvent arg0) {
129
 
130
            }
131
 
132
            public void menuDeselected(MenuEvent e) {
133
                lookAndFeelMenu.removeAll();
134
            }
135
 
136
            public void menuSelected(MenuEvent e) {
137
                buildLookAndFeel();
138
            }
139
        });
140
 
141
        optionsMenu.add(lookAndFeelMenu);
142
        menuBar.add(optionsMenu);
143
 
144
        return menuBar;
145
    }
146
 
147
    private void buildLookAndFeel() {
148
 
149
        JCheckBoxMenuItem item;
150
 
151
        for (int i = 0; i < UIManager.getInstalledLookAndFeels().length; i++) {
152
            final int l = i;
153
            item = new JCheckBoxMenuItem(
154
                    UIManager.getInstalledLookAndFeels()[i].getName());
155
            lookAndFeelMenu.add(item);
156
            if (UIManager.getInstalledLookAndFeels()[i].getClassName().equals(
157
                    lookAndFeel)) {
158
                item.setSelected(true);
159
            }
160
            item.addActionListener(new ActionListener() {
161
                public void actionPerformed(ActionEvent ae) {
162
                    try {
741 adamjking 163
 
164
                        setLookAndFeel(UIManager.getInstalledLookAndFeels()[l]
165
                                .getClassName());
166
 
628 adamjking 167
                    } catch (Exception e) {
168
                        System.out.println(e.toString());
169
                    }
170
                }
171
            });
172
        }
741 adamjking 173
    }
628 adamjking 174
 
741 adamjking 175
    public void setLookAndFeel(String lookAndFeel) {
176
 
177
        this.lookAndFeel = lookAndFeel;
178
 
179
        if (!lookAndFeel.equals(UIManager.getLookAndFeel().getClass().getName())) {
180
 
181
            JOptionPane
182
            .showMessageDialog(
183
                            VirtualKeyboardGUI.this,
184
                            "The selected Look & Feel will be applied the next time you restart Virtual Keyboard",
185
                            "ALERT", JOptionPane.ERROR_MESSAGE);
186
        }
628 adamjking 187
    }
741 adamjking 188
 
189
    public VirtualKeyboard getVirtualKeyboard() {
190
        return virtualKeyboard;
191
    }
628 adamjking 192
 
193
    public boolean isShowConnections() {
194
        return showConnections;
195
    }
196
 
197
    public void setShowConnections(boolean showConnections) {
198
        this.showConnections = showConnections;
199
        midiDeviceRoutingGUI.setVisible(showConnections);
200
        revalidate();
201
    }
202
 
203
    public MidiDeviceRoutingGUI getMidiDeviceRoutingGUI() {
204
        return midiDeviceRoutingGUI;
205
    }
206
 
207
    public JMenu getFileMenu() {
208
        return fileMenu;
209
    }
210
 
211
    public String getLookAndFeel() {
212
        return lookAndFeel;
213
    }
214
}