/*
* Created on 2004/12/10
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.repeatrecorder;
import org.apache.commons.beanutils.MethodUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.jpn.xucker.commons.swt.ui.MenuItemContainerImp;
import java.lang.reflect.InvocationTargetException;
public class RepeatRecorderMenu extends MenuItemContainerImp implements SelectionListener,ControledObject{
/**
* @param shell
*/
private MenuItem file;
private MenuItem open;
private MenuItem exit;
private MenuItem help;
private MenuItem about;
private MenuItem homepage;
public RepeatRecorderMenu(Shell parent) {
Menu root_menu=new Menu(parent,SWT.BAR);
parent.setMenuBar(root_menu);
//File
Menu file_menu=new Menu(root_menu);
file=new MenuItem(root_menu,SWT.CASCADE);
file.setText("File");
file.setMenu(file_menu);
addMenuItem(file,"file");
//Open
open=new MenuItem(file_menu,SWT.PUSH);
open.setText("Open");
open.addSelectionListener(this);
addMenuItem(open,"open");
MenuItem separatemenu3=new MenuItem(file_menu,SWT.SEPARATOR);
addMenuItem(separatemenu3,"separatemenu3");
//Exit
exit=new MenuItem(file_menu,SWT.PUSH);
exit.setText("Exit");
exit.addSelectionListener(this);
addMenuItem(exit,"exit");
//Help
Menu help_menu=new Menu(root_menu);
help=new MenuItem(root_menu,SWT.CASCADE);
help.setText("Help");
help.setMenu(help_menu);
addMenuItem(help,"help");
//About
about=new MenuItem(help_menu,SWT.PUSH);
about.setText("About");
about.addSelectionListener(this);
addMenuItem(about,"about");
//Homepage
homepage=new MenuItem(help_menu,SWT.PUSH);
homepage.setText("Homepage");
homepage.addSelectionListener(this);
addMenuItem(homepage,"homepage");
}
public void widgetSelected(SelectionEvent event) {
Object target=event.getSource();
if(target==null){
//
throw new RuntimeException("selected target is null");
}
//Open
else if(target==open){
call_event("open");
}
//Exit
else if(target==exit){
call_event("exit");
}
//About
else if(target==about){
call_event("about");
}
//Homepage
else if(target==homepage){
call_event("homepage");
}
}
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
/*
public void action_open(MenuItemContainer menuItemContainer){}
public void action_exit(MenuItemContainer menuItemContainer){}
public void action_about(MenuItemContainer menuItemContainer){}
public void action_homepage(MenuItemContainer menuItemContainer){}
*/
public void call_event(String keyName){
Object object=getExecuteObject();
try {
MethodUtils.invokeMethod(object,"action_"+keyName,(ControledObject)this);
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see org.jpn.xucker.repeatrecorder.ControledObject#setSelection(java.lang.String, boolean)
*/
public void setSelection(String key, boolean value) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.jpn.xucker.repeatrecorder.ControledObject#getSelection(java.lang.String)
*/
public boolean getSelection(String key) {
// TODO Auto-generated method stub
return false;
}
}
|