package gui; import java.awt.*; import java.awt.event.*; //import javax.swing.*; // Gabor imports import util.*; import analyze.PlotOutput; import output.Analyze; import model.ModelConst; import image.create.*; /** This class installs Vision Modeling Menus. It is a modification of the menu class developed and written by Wayne Rashaband for ImageJ. @version 0.0.1 */ public class Menus { // alt key short cuts for menus public static final char FILE_MENU = 'f'; public static final char IMAGE_MENU = 'i'; public static final char MODEL_MENU = 'm'; public static final char GABOR_DISPLAY_MENU = 'g'; public static final char SETTINGS_MENU = 's'; public static final char ANALYSIS_MENU = 's'; public static final char HELP_MENU = 'h'; public static final int WINDOW_MENU_ITEMS = 5; // fixed items at top of Window menu // the current menu bar private static MenuBar mbar; private Menu image, model, view, settings, gaborDisp,analysis; // image submenus private Menu basic, contrast, illusion; private boolean showSettings = true; // Menu Item Lists private String [] fItems, iItems, mItems, vItems, gItems, sItems, aItems, hItems; // image sumbemu item lists private String [] biItems, ciItems, iiItems; // a swing JFrame with an action listener enabled. // allows the menu actions to be recorded. private static MainFrame frame; // Analysis Object private static Analyze control; /** * Basic menu constructor * @param fr the frame to hold the menus. This frame must * implement an action listener. * @param showFileMenu boolean flag if the file menu * is to be show. It should not be shown on applets */ public Menus(MainFrame fr, Analyze gabor) { frame = fr; control = gabor; addMenuBar(); } /** * Menu constructor which allows * for the settings menu to be made visible or not * @param fr the frame to hold the menus. This frame must * implement an action listener. * @param showFileMenu boolean flag if the file menu * is to be show. It should not be shown on applets * @param boolean showSet flag to control the visibility * of the settings menu. */ public Menus(MainFrame fr, Analyze gabor, boolean showSet) { frame = fr; control = gabor; showSettings = showSet; addMenuBar(); } /** * Method to create and add the menu bar to the frame * passed in the constructor. * @return String error state */ public void addMenuBar() { // create the File Menu fItems = MenuConst.FILE_ITEMS; int [] shortCt = {0,KeyEvent.VK_O, KeyEvent.VK_S,KeyEvent.VK_T}; boolean [] shift = {false,false,false,false}; Menu file = new Menu(fItems[0]); for (int i = 1; i < fItems.length; i ++){ addItem(file, fItems[i],shortCt[i], shift[i]); } // create the Image submenus // basic images biItems = MenuConst.BASIC_ITEMS; basic = new Menu(biItems[0]); for (int i = 1; i < biItems.length; i ++){ addItem(basic, biItems[i],0, false); } // contrast effect images ciItems = MenuConst.CONTRAST_ITEMS; contrast = new Menu(ciItems[0]); for (int i = 1; i < ciItems.length; i ++){ addItem(contrast, ciItems[i],0, false); } // illusions iiItems = MenuConst.ILLUSION_ITEMS; illusion = new Menu(iiItems[0]); for (int i = 1; i < iiItems.length; i ++){ addItem(illusion, iiItems[i],0, false); } // create the Image Menu iItems = MenuConst.IMAGE_ITEMS; image = new Menu(iItems[0]); image.add(basic); image.add(contrast); image.add(illusion); // create the Model menu mItems = MenuConst.MODEL_ITEMS; shortCt = MenuConst.MODEL_SHORT; model = new Menu(mItems[0]); for (int i = 1; i < mItems.length; i ++){ addItem(model, mItems[i],shortCt[i], false); } // create the view menu vItems = MenuConst.VIEW_ITEMS; shortCt = MenuConst.VIEW_SHORT; view = new Menu(vItems[0]); for (int i = 1; i < vItems.length; i ++){ addItem(view,vItems[i],shortCt[i],false); } // create the Gabor Menu. gItems = PlotOutput.ANANAMES; gaborDisp = new Menu(gItems[0]); for (int i = 1; i < gItems.length; i ++){ addItem(gaborDisp, gItems[i],0, false); } // create the Settings Menu. sItems = MenuConst.SET_ITEMS; shortCt = MenuConst.SET_SHORT; settings = new Menu(sItems[0]); for (int i = 1; i < sItems.length; i ++){ addItem(settings, sItems[i],shortCt[i], false); } // create the Analysis Menus aItems = MenuConst.ANALYSIS_ITEMS; shortCt = MenuConst.ANA_SHORT; analysis = new Menu(aItems[0]); for (int i = 1; i < aItems.length; i ++){ addItem(analysis, aItems[i],shortCt[i], false); } // Create the help menu hItems = MenuConst.HELP_ITEMS; shortCt = MenuConst.HELP_SHORT; Menu help = new Menu(hItems[0]); for (int i = 1; i < hItems.length; i ++){ addItem(help, hItems[i],shortCt[i], false); } // create and set up the menu bar mbar = new MenuBar(); mbar.setFont(new Font("SansSerif", Font.PLAIN, 14)); if (control.getShowFile()) mbar.add(file); mbar.add(image); mbar.add(model); mbar.add(view); if (showSettings){ mbar.add(gaborDisp); mbar.add(settings); mbar.add(analysis); } mbar.setHelpMenu(help); if (frame!=null) frame.setMenuBar(mbar); } //add a menu item void addItem(Menu menu, String label, int shortcut, boolean shift) { if (menu==null) return; MenuItem item; // handle the shortcuts if (shortcut==0) item = new MenuItem(label); else { if (shift) { item = new MenuItem(label, new MenuShortcut(shortcut, true)); } else { item = new MenuItem(label, new MenuShortcut(shortcut)); } } menu.add(item); // let the frame listen to the menu item.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if ((e.getSource() instanceof MenuItem)) { // get the item that called the actionlistener MenuItem item = (MenuItem)e.getSource(); // what menu did the item belong to. Menu menu = (Menu)item.getParent(); // find the right menu to search if (menu.getLabel()==fItems[0]){ // search the file menu checkFile(item); } else if (menu.getLabel()== iItems[0]){ // search the image menu checkImage(item); } else if (menu.getLabel()==biItems[0]){ // search the basic images submenu checkBasic(item); } else if (menu.getLabel() == ciItems[0]){ // check the contrast images submenu checkContrast(item); } else if (menu.getLabel()==iiItems[0]){ // search the illusion submenu checkIllusion(item); } else if (menu.getLabel()==mItems[0]){ // search the model menus checkModel(item); } else if (menu.getLabel()==vItems[0]){ // search the view menu checkView(item); } else if (menu.getLabel()==gItems[0]){ // search the Analysis menu checkGaborDisp(item); } else if (menu.getLabel()==sItems[0]){ // search the settings menu checkSettings(item); } else if (menu.getLabel()==aItems[0]){ // search the settings menu checkAnalysis(item); } else if (menu.getLabel()==hItems[0]){ // search help menu checkHelp(item); } } } }); } // checking the menus private void checkFile(MenuItem item){ if (item.getLabel() == fItems[MenuConst.OPEN_IMAGE]){ control.resetModelDone(ModelConst.SIMPLE_CELL); control.resetModelDone(ModelConst.DOG_CELL); control.getImage(); } else if (item.getLabel() == fItems[MenuConst.SAVE_CORTEX]){ control.saveCortex(); } else if (item.getLabel() == fItems[MenuConst.SAVE_CELL]){ control.saveCell(); } }// end checkFile private void checkImage(MenuItem item){ }// end checkImage private void checkBasic(MenuItem item){ if (item.getLabel() == biItems[MenuConst.SINE_WAVE]){ control.createImage(new SineGrat()); } else if (item.getLabel() == biItems[MenuConst.SQUARE_WAVE]){ control.createImage(new SquareGrat()); } else if (item.getLabel() == biItems[MenuConst.BASIC_SHAPE]){ control.createImage(new BasicShape()); } }// end checkBasic private void checkContrast(MenuItem item){ if (item.getLabel() == ciItems[MenuConst.HERMANN]){ control.createImage(new Hermann()); } else if (item.getLabel() == ciItems[MenuConst.CRAIK]){ control.createImage(new ContourObject()); } }// end checkBasic private void checkIllusion(MenuItem item){ if (item.getLabel() == iiItems[MenuConst.POGGENDORF]){ control.createImage(new Poggendorf()); } }// end checkIllusion private void checkModel(MenuItem item){ if (item.getLabel() == mItems[MenuConst.CELL]){ control.setCellModel(); } else if (item.getLabel() == mItems[MenuConst.PARAMETERS]){ control.resetCurrentModelDone(); control.setParameters(); } else if (item.getLabel() == mItems[MenuConst.RUN_MODEL]){ control.runModel(); } else if (item.getLabel() == mItems[MenuConst.PLOT]){ control.showPlot(); } }// end checkModel private void checkView(MenuItem item){ if (item.getLabel() == vItems[MenuConst.SIMPLE_CELL]){ control.setCellModel(ModelConst.SIMPLE_CELL); } else if (item.getLabel()==vItems[MenuConst.DOG_CELL]){ control.setCellModel(ModelConst.DOG_CELL); } control.runModel(); } private void checkGaborDisp(MenuItem item){ int temp = 0; for (int i = 1; i < gItems.length; i ++){ if (gItems[i] == item.getLabel()) temp = i; } control.setGaborDisp(temp); } private void checkSettings(MenuItem item){ if (item.getLabel() == sItems[MenuConst.CHANGE_THRESH]){ control.changeThresholds(); } else if (item.getLabel() == sItems[MenuConst.DRAW_OPT]){ control.changeDrawingOptions(); } else if (item.getLabel() == sItems[MenuConst.RANGE]){ control.changeRange(); } } private void checkAnalysis(MenuItem item){ if (item.getLabel() == aItems[MenuConst.R_WITHIN]){ control.correlWithin(); } else if (item.getLabel() == aItems[MenuConst.PLOT_DIFF]){ control.diffPlot(); } } private void checkHelp(MenuItem item){ } // menu control options public void enableSettings(boolean b){ settings.setEnabled(b); } public void enableModel(boolean b){ model.setEnabled(b); } public void enableAnalysis(boolean b){ gaborDisp.setEnabled(b); } }