package cologne.eck.all_peas.gui;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.accessibility.AccessibleContext;
import javax.swing.Action;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import cologne.eck.all_peas.control.PeaControl;
import cologne.eck.all_peas.data.PeaProperties;
@SuppressWarnings("serial")
public class HelpMenu extends JMenu implements ActionListener {
private ResourceBundle languagesBundle;
public HelpMenu() {
languagesBundle = PeaProperties.getBundle();
this.setText(languagesBundle.getString("help"));
// int fontSize = PswDialogView.getFontsize();
// this.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
//help.setMnemonic(KeyEvent.VK_H);
this.setMnemonic(KeyStroke.getKeyStroke(languagesBundle.getString("help_mnemonic")).getKeyCode());
JMenuItem instructionItem = new JMenuItem(languagesBundle.getString("instruction"));
instructionItem.setActionCommand("instruction");
// instructionItem.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
//instructionItem.setMnemonic(KeyEvent.VK_I);
instructionItem.setMnemonic(KeyStroke.getKeyStroke(languagesBundle.getString("instruction_mnemonic")).getKeyCode());
instructionItem.addActionListener(this);
this.add(instructionItem);
JMenuItem webItem = new JMenuItem(languagesBundle.getString("web"));
webItem.setActionCommand("web");
// webItem.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
//webItem.setMnemonic(KeyEvent.VK_I);
webItem.setMnemonic(KeyStroke.getKeyStroke(languagesBundle.getString("web_mnemonic")).getKeyCode());
webItem.addActionListener(this);
this.add(webItem);
JMenuItem pathFileItem = new JMenuItem(languagesBundle.getString("path_file"));
pathFileItem.setActionCommand("pathFile");
// pathFileItem.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
//webItem.setMnemonic(KeyEvent.VK_I);
pathFileItem.setMnemonic(KeyStroke.getKeyStroke(languagesBundle.getString("path_file_mnemonic")).getKeyCode());
pathFileItem.addActionListener(this);
this.add(pathFileItem);
JMenuItem aboutItem = new JMenuItem(languagesBundle.getString("about"));
aboutItem.setActionCommand("about");
// aboutItem.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, fontSize));
aboutItem.setMnemonic(KeyStroke.getKeyStroke(languagesBundle.getString("about_mnemonic")).getKeyCode());
aboutItem.addActionListener(this);
this.add(aboutItem);
}
public HelpMenu(String s) {
super(s);
// TODO Auto-generated constructor stub
}
public HelpMenu(Action a) {
super(a);
// TODO Auto-generated constructor stub
}
public HelpMenu(String s, boolean b) {
super(s, b);
// TODO Auto-generated constructor stub
}
@Override
public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand();
String fileType = PeaProperties.getFileType();
// get the parent window: PswDialog or ContentUtilities
Window parentWindow = null;
if (PeaControl.getDialog().getLockFrame() != null) {
// set ContentUtilities as parent
parentWindow = (Window) PeaControl.getDialog().getLockFrame();
} else { // in PswDialog: set PswDialog as parent
parentWindow = PswDialogView.getView();
}
//System.out.println("command: " + command);
if (command.equals("instruction")){
String message = null;
if (fileType.equals("file")){
message = PeaProperties.getBundle().getString("file_instruction");
} else if (fileType.equals("image")) {
message = PeaProperties.getBundle().getString("image_instruction");
} else if (fileType.equals("text")) {
message = PeaProperties.getBundle().getString("text_instruction");
} else if (fileType.equals("text file")) {
message = PeaProperties.getBundle().getString("text_instruction");
} else {
message = "invalid PEA type: " + fileType;
}
JOptionPane.showMessageDialog(parentWindow,
message,
null,
JOptionPane.INFORMATION_MESSAGE);
} else if (command.equals("web")){
PswDialogView.showInfoDialog(parentWindow);
/* if (PeaControl.getDialog().getLockFrame() != null) {
// set ContentUtilities as parent
PswDialogView.showInfoDialog(PeaControl.getDialog().getLockFrame());
} else { // in PswDialog: set PswDialog as parent
PswDialogView.showInfoDialog(PswDialogView.getView());
}*/
} else if (command.equals("pathFile")){
PathFileSetting ps = PathFileSetting.getInstance(parentWindow, parentWindow.getLocation());
if (ps.isVisible() == false) {
ps.setVisible(true);
}
} else if (command.equals("about")) {
String peaName = null;
if (PeaProperties.getFileType().equals("image")){
peaName = "Image Lock PEA";
} else if (PeaProperties.getFileType().equals("file")){
peaName = "File Lock PEA";
} else if (PeaProperties.getFileType().equals("text file")){
peaName = "Notebook PEA";
}
PswDialogView.showAboutDialog(peaName, null, parentWindow);
/* if (PeaControl.getDialog().getLockFrame() != null) {
// set ContentUtilities as parent
PswDialogView.showAboutDialog("Notebook PEA", null, PeaControl.getDialog().getLockFrame());
} else { // in PswDialog: set PswDialog as parent
PswDialogView.showAboutDialog("Notebook PEA", null, PswDialogView.getView());
}*/
} else {
System.out.println("Invalid command in help menu");
}
}
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleHelpMenu();
}
return accessibleContext;
}
protected class AccessibleHelpMenu extends AccessibleJMenu {
//Inherit everything, override nothing.
}
}