| 1 |
/** |
| 2 |
* Copyright Copyright 2010-17 Simon Andrews |
| 3 |
* |
| 4 |
* This file is part of FastQC. |
| 5 |
* |
| 6 |
* FastQC 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 3 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* FastQC 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 FastQC; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
*/ |
| 20 |
package uk.ac.babraham.FastQC; |
| 21 |
|
| 22 |
import java.awt.Toolkit; |
| 23 |
import java.awt.event.ActionEvent; |
| 24 |
import java.awt.event.ActionListener; |
| 25 |
import java.awt.event.KeyEvent; |
| 26 |
import java.io.File; |
| 27 |
import java.io.UnsupportedEncodingException; |
| 28 |
import java.net.URLDecoder; |
| 29 |
|
| 30 |
import javax.swing.JMenu; |
| 31 |
import javax.swing.JMenuBar; |
| 32 |
import javax.swing.JMenuItem; |
| 33 |
import javax.swing.JOptionPane; |
| 34 |
import javax.swing.KeyStroke; |
| 35 |
|
| 36 |
import uk.ac.babraham.FastQC.Dialogs.AboutDialog; |
| 37 |
import uk.ac.babraham.FastQC.Help.HelpDialog; |
| 38 |
|
| 39 |
public class FastQCMenuBar extends JMenuBar implements ActionListener { |
| 40 |
|
| 41 |
private FastQCApplication application; |
| 42 |
|
| 43 |
public FastQCMenuBar (FastQCApplication application) { |
| 44 |
this.application = application; |
| 45 |
|
| 46 |
JMenu fileMenu = new JMenu("File"); |
| 47 |
fileMenu.setMnemonic(KeyEvent.VK_F); |
| 48 |
|
| 49 |
JMenuItem fileOpen = new JMenuItem("Open..."); |
| 50 |
fileOpen.setMnemonic(KeyEvent.VK_O); |
| 51 |
fileOpen.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); |
| 52 |
fileOpen.setActionCommand("open"); |
| 53 |
fileOpen.addActionListener(this); |
| 54 |
fileMenu.add(fileOpen); |
| 55 |
|
| 56 |
fileMenu.addSeparator(); |
| 57 |
|
| 58 |
JMenuItem fileSave = new JMenuItem("Save report..."); |
| 59 |
fileSave.setMnemonic(KeyEvent.VK_S); |
| 60 |
fileSave.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); |
| 61 |
fileSave.setActionCommand("save"); |
| 62 |
fileSave.addActionListener(this); |
| 63 |
fileMenu.add(fileSave); |
| 64 |
|
| 65 |
fileMenu.addSeparator(); |
| 66 |
|
| 67 |
JMenuItem fileClose = new JMenuItem("Close"); |
| 68 |
fileClose.setMnemonic(KeyEvent.VK_C); |
| 69 |
fileClose.setAccelerator(KeyStroke.getKeyStroke('W', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); |
| 70 |
fileClose.setActionCommand("close"); |
| 71 |
fileClose.addActionListener(this); |
| 72 |
fileMenu.add(fileClose); |
| 73 |
|
| 74 |
|
| 75 |
JMenuItem fileCloseAll = new JMenuItem("Close All"); |
| 76 |
fileCloseAll.setMnemonic(KeyEvent.VK_A); |
| 77 |
fileCloseAll.setActionCommand("close_all"); |
| 78 |
fileCloseAll.addActionListener(this); |
| 79 |
fileMenu.add(fileCloseAll); |
| 80 |
|
| 81 |
|
| 82 |
fileMenu.addSeparator(); |
| 83 |
|
| 84 |
JMenuItem fileExit = new JMenuItem("Exit"); |
| 85 |
fileExit.setMnemonic(KeyEvent.VK_X); |
| 86 |
fileExit.setActionCommand("exit"); |
| 87 |
fileExit.addActionListener(this); |
| 88 |
fileMenu.add(fileExit); |
| 89 |
|
| 90 |
add(fileMenu); |
| 91 |
|
| 92 |
JMenu helpMenu = new JMenu("Help"); |
| 93 |
helpMenu.setMnemonic(KeyEvent.VK_H); |
| 94 |
|
| 95 |
JMenuItem helpContents = new JMenuItem("Contents..."); |
| 96 |
helpContents.setMnemonic(KeyEvent.VK_C); |
| 97 |
helpContents.setActionCommand("help_contents"); |
| 98 |
helpContents.addActionListener(this); |
| 99 |
helpMenu.add(helpContents); |
| 100 |
|
| 101 |
helpMenu.addSeparator(); |
| 102 |
|
| 103 |
JMenuItem helpAbout = new JMenuItem("About FastQC"); |
| 104 |
helpAbout.setMnemonic(KeyEvent.VK_A); |
| 105 |
helpAbout.setActionCommand("about"); |
| 106 |
helpAbout.addActionListener(this); |
| 107 |
|
| 108 |
helpMenu.add(helpAbout); |
| 109 |
|
| 110 |
add(helpMenu); |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
public void actionPerformed(ActionEvent e) { |
| 115 |
|
| 116 |
String command = e.getActionCommand(); |
| 117 |
|
| 118 |
if (command.equals("exit")) { |
| 119 |
System.exit(0); |
| 120 |
} |
| 121 |
else if (command.equals("open")) { |
| 122 |
application.openFile(); |
| 123 |
} |
| 124 |
else if (command.equals("save")) { |
| 125 |
application.saveReport(); |
| 126 |
} |
| 127 |
else if (command.equals("close")) { |
| 128 |
application.close(); |
| 129 |
} |
| 130 |
else if (command.equals("close_all")) { |
| 131 |
application.closeAll(); |
| 132 |
} |
| 133 |
else if (command.equals("help_contents")) { |
| 134 |
try { |
| 135 |
new HelpDialog(application,new File(URLDecoder.decode(ClassLoader.getSystemResource("Help").getFile(),"UTF-8"))); |
| 136 |
} |
| 137 |
catch (UnsupportedEncodingException e1) { |
| 138 |
e1.printStackTrace(); |
| 139 |
} |
| 140 |
} |
| 141 |
else if (command.equals("about")) { |
| 142 |
new AboutDialog(application); |
| 143 |
} |
| 144 |
else { |
| 145 |
JOptionPane.showMessageDialog(application, "Unknown menu command "+command, "Unknown command", JOptionPane.ERROR_MESSAGE); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
} |