001: /**********************************************************************************
002: * $URL$
003: * $Id$
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.audio;
021:
022: import java.io.File;
023: import java.util.Vector;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Dimension;
027: import java.awt.Toolkit;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030: import java.awt.event.WindowAdapter;
031: import java.awt.event.WindowEvent;
032: import javax.swing.JFrame;
033: import javax.swing.JMenu;
034: import javax.swing.JMenuBar;
035: import javax.swing.JMenuItem;
036: import javax.swing.JPanel;
037: import javax.swing.JTabbedPane;
038: import javax.swing.border.BevelBorder;
039: import javax.swing.border.CompoundBorder;
040: import javax.swing.border.EmptyBorder;
041: import javax.swing.event.ChangeEvent;
042: import javax.swing.event.ChangeListener;
043: import java.util.ResourceBundle;
044: import java.util.Locale;
045: import javax.swing.Box;
046: import java.awt.event.KeyEvent;
047: import javax.swing.SwingUtilities;
048: import javax.swing.UIManager;
049:
050: /**
051: * The Java Sound Samples : MidiSynth, Juke, CapturePlayback, Groove.
052: *
053: * @version @(#)JavaSound.java 1.15 00/01/31
054: * @author Brian Lichtenwalter
055: */
056: public class AudioPanel extends JPanel implements ChangeListener,
057: Runnable {
058: static ResourceBundle res = AudioUtil.getInstance()
059: .getResourceBundle();
060:
061: Vector tabPanels = new Vector(4);
062: JTabbedPane tabPane = new JTabbedPane();
063: int width = 450, height = 350;
064: int index;
065: AudioRecorderParams params;
066:
067: /**
068: *
069: * @param audioDirectory
070: */
071: public AudioPanel(String audioDirectory, AudioRecorderParams params) {
072: this .params = params;
073:
074: setLayout(new BorderLayout());
075:
076: JMenuBar menuBar = new JMenuBar();
077:
078: if (isStandalone()) {
079: configureFileMenu(menuBar);
080: }
081: configureHelpMenu(menuBar);
082: add(menuBar, BorderLayout.NORTH);
083:
084: tabPane.addChangeListener(this );
085:
086: EmptyBorder eb = new EmptyBorder(5, 5, 5, 5);
087: BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
088: CompoundBorder cb = new CompoundBorder(eb, bb);
089: JPanel p = new JPanel(new BorderLayout());
090: //p.setBorder(new CompoundBorder(cb, new EmptyBorder(0, 0, 90, 0)));
091: p
092: .setBorder(new CompoundBorder(cb, new EmptyBorder(0, 0,
093: 0, 0)));
094:
095: new Thread(this ).start();
096:
097: add(tabPane, BorderLayout.CENTER);
098: }
099:
100: private boolean isStandalone() {
101: if (AudioRecorderApplet.applet == null
102: || AudioRecorderApplet.applet.isStandalone) {
103: return true;
104: }
105:
106: return false;
107: }
108:
109: /**
110: * Helper method.
111: * @param menuBar
112: */
113: private void configureHelpMenu(JMenuBar menuBar) {
114: // Move help menu to right side
115: menuBar.add(Box.createHorizontalGlue());
116:
117: // Help Menu, F1, H - Mnemonic
118: JMenu options = (JMenu) menuBar.add(new JMenu(res
119: .getString("Help")));
120: options.setMnemonic(KeyEvent.VK_H);
121:
122: JMenuItem item = (JMenuItem) options.add(new JMenuItem(res
123: .getString("Configuration")));
124: item.addActionListener(new ActionListener() {
125: public void actionPerformed(ActionEvent e) {
126: AudioConfigHelp help = new AudioConfigHelp();
127: help.configHelp();
128: }
129: });
130:
131: /* comment out - SAK-8436
132: JMenuItem about = (JMenuItem) options.add(new JMenuItem(res.getString("About")));
133: about.addActionListener(new ActionListener()
134: {
135: public void actionPerformed(ActionEvent e)
136: {
137: AudioConfigHelp.infoHelp();
138: }
139: });
140: */
141: }
142:
143: /**
144: * Helper method.
145: * @param menuBar
146: */
147: private void configureFileMenu(JMenuBar menuBar) {
148: // File Menu, F - Mnemonic
149: JMenu fileMenu = (JMenu) menuBar.add(new JMenu(res
150: .getString("File")));
151: fileMenu.setMnemonic(KeyEvent.VK_F);
152:
153: JMenuItem item = (JMenuItem) fileMenu.add(new JMenuItem(res
154: .getString("Exit")));
155: item.addActionListener(new ActionListener() {
156: public void actionPerformed(ActionEvent e) {
157: System.exit(0);
158: }
159: });
160: }
161:
162: /**
163: * Handle state changes.
164: * @param e the Cahnge Event
165: */
166: public void stateChanged(ChangeEvent e) {
167: close();
168: System.gc();
169: index = tabPane.getSelectedIndex();
170: open();
171: }
172:
173: public void close() {
174: ((AudioControlContext) tabPanels.get(index)).close();
175: }
176:
177: public void open() {
178: ((AudioControlContext) tabPanels.get(index)).open();
179: }
180:
181: public Dimension getPreferredSize() {
182: return new Dimension(width, height);
183: }
184:
185: /**
186: * Lazy load the tabbed pane
187: */
188: public void run() {
189: EmptyBorder eb = new EmptyBorder(5, 5, 5, 5);
190: BevelBorder bb = new BevelBorder(BevelBorder.LOWERED);
191: CompoundBorder cb = new CompoundBorder(eb, bb);
192: JPanel p = new JPanel(new BorderLayout());
193: //p.setBorder(new CompoundBorder(cb, new EmptyBorder(0, 0, 90, 0)));
194: p
195: .setBorder(new CompoundBorder(cb, new EmptyBorder(0, 0,
196: 0, 0)));
197: AudioRecorder recorder = new AudioRecorder(params);
198: tabPanels.add(recorder);
199: p.add(recorder);
200: tabPane.addTab(res.getString("Audio_Recorder"), p);
201:
202: /* samigo 2.2 did not asked for advnacd settings so commented it out
203: JPanel fp = new JPanel(new BorderLayout());
204: fp.setBorder(new CompoundBorder(cb, new EmptyBorder(0, 0, 0, 0)));
205: JPanel format = recorder.getFormatControlsPanel();
206: tabPanels.add(format);
207: fp.add(format);
208: tabPane.addTab(res.getString("Advanced_Settings"), fp);
209: */
210: }
211:
212: /**
213: *
214: * @param args
215: */
216: public static void main(String[] args) {
217: String media = res.getString("_audio");
218: if (args.length > 0) {
219: File file = new File(args[0]);
220: if (file == null && !file.isDirectory()) {
221: System.out.println(res
222: .getString("usage_java_JavaSound"));
223: } else {
224: media = args[0];
225: }
226: }
227:
228: AudioRecorderParams params = new AudioRecorderParams();
229:
230: final AudioPanel tabPanel = new AudioPanel(media, params);
231: JFrame f = new JFrame(res.getString("Audio_Recorder"));
232: f.addWindowListener(new WindowAdapter() {
233: public void windowClosing(WindowEvent e) {
234: System.exit(0);
235: }
236:
237: public void windowDeiconified(WindowEvent e) {
238: tabPanel.open();
239: }
240:
241: public void windowIconified(WindowEvent e) {
242: tabPanel.close();
243: }
244: });
245: f.getContentPane().add("Center", tabPanel);
246: f.pack();
247: Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
248: f.setLocation(d.width / 2 - tabPanel.width / 2, d.height / 2
249: - tabPanel.height / 2);
250: f.setSize(new Dimension(tabPanel.width, tabPanel.height));
251: f.setVisible(true);
252: }
253: }
|