001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * created at May 24, 2008
021 */
022package org.biojava.nbio.structure.align.gui;
023
024
025import org.biojava.nbio.structure.align.gui.jmol.AbstractAlignmentJmol;
026import org.biojava.nbio.structure.align.model.AFPChain;
027import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
028import org.biojava.nbio.structure.align.util.UserConfiguration;
029import org.biojava.nbio.structure.align.webstart.WebStartMain;
030
031import javax.swing.*;
032
033import java.awt.*;
034import java.awt.event.*;
035import java.io.File;
036
037
038/**
039 * Create the menus for structure alignment GUI windows (JFrames).
040 * <p>
041 * Examples: Text Frames, Alignment Panels, Jmol Panels.
042 *
043 * @author Andreas Prlic
044 * @author Aleix Lafita
045 * @author Spencer Bliven
046 * @since 1.7
047 *
048 */
049public class MenuCreator {
050
051        public static final String PRINT     = "Print";
052        public static final String ALIGNMENT_PANEL = "Alignment Panel";
053        public static final String TEXT_ONLY = "View Text Only";
054        public static final String PAIRS_ONLY = "View Aligned Pairs";
055        public static final String SELECT_EQR = "Select Equivalent Positions";
056        public static final String SIMILARITY_COLOR = "Color By Similarity";
057        public static final String EQR_COLOR = "Color By EQR";
058        public static final String FATCAT_BLOCK = "Color By Alignment Block";
059        public static final String LOAD_DB_RESULTS = "Load DB search results";
060        public static final String SAVE_ALIGNMENT_XML = "Save Alignment XML";
061        public static final String LOAD_ALIGNMENT_XML = "Load Alignment XML";
062        public static final String FATCAT_TEXT = "View as FATCAT result";
063        public static final String FASTA_FORMAT = "View FASTA Alignment";
064        public static final String DIST_MATRICES = "Show Distance Matrices";
065        public static final String DOT_PLOT = "Show Dot Plot";
066        public static final String PAIRWISE_ALIGN = "New Pairwise Alignment";
067        public static final String MULTIPLE_ALIGN = "New Multiple Alignment";
068        public static final String PHYLOGENETIC_TREE = "Phylogenetic Tree";
069        protected static final int keyMask =
070                        Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
071
072        /**
073         * Provide a JMenuBar that can be added to a JFrame containing
074         * a JmolPanel. The alignment has to be either an AFPChain or a
075         * MultipleAlignment: set the other parameter to null.<p>
076         * Menus included:
077         * <ul><li>File: open, save, export, import, exit.
078         * <li>Align: new pairwise alignment, new multiple alignment.
079         * <li>View: aligment panel, aligned pairs, text format,
080         * FatCat format, distance matrices, dot plot.
081         * <li>Help
082         * </ul>
083         *
084         * @return a JMenuBar
085         */
086        public static JMenuBar initJmolMenu(JFrame frame,
087                        AbstractAlignmentJmol parent, AFPChain afpChain,
088                        MultipleAlignment msa) {
089
090                JMenuBar menu = new JMenuBar();
091
092/// FILE MENU
093                JMenu file= new JMenu("File");
094                file.setMnemonic(KeyEvent.VK_F);
095                file.getAccessibleContext().setAccessibleDescription("File Menu");
096                //Load
097                if (parent != null){
098                        JMenuItem loadF = getLoadMenuItem();
099                        loadF.addActionListener(new MyAlignmentLoadListener());
100                        file.add(loadF);
101                }
102                //Save
103                JMenuItem saveF = getSaveAlignmentMenuItem(afpChain, msa);
104                file.add(saveF);
105                //Open PDB
106                JMenuItem openPDB = getShowPDBMenuItem();
107                file.add(openPDB);
108                //Open Import
109                JMenuItem openI = getOpenPDBMenuItem();
110                file.add(openI);
111                //Export
112                if (parent != null){
113                        JMenuItem exportI =  getExportPDBMenuItem(parent);
114                        file.add(exportI);
115                }
116                //Open DBI
117                JMenuItem openDBI = getDBResultMenuItem();
118                file.add(openDBI);
119                file.addSeparator();
120                //Print
121                if ( parent != null){
122                        JMenuItem print = getPrintMenuItem();
123                        print.addActionListener(parent.getJmolPanel());
124                        file.add(print);
125                }
126                file.addSeparator();
127                //Close Frame
128                JMenuItem closeI = getCloseMenuItem(frame);
129                file.add(closeI);
130                //Exit
131                JMenuItem exitI = getExitMenuItem();
132                file.add(exitI);
133
134                menu.add(file);
135
136/// ALIGN MENU
137                JMenu align = new JMenu("Align");
138                align.setMnemonic(KeyEvent.VK_A);
139                //new Pairwise alignment
140                JMenuItem pairI = getPairwiseAlignmentMenuItem();
141                align.add(pairI);
142                //new Multiple alignment
143                JMenuItem multI = getMultipleAlignmentMenuItem();
144                align.add(multI);
145
146                menu.add(align);
147
148/// VIEW MENU
149                JMenu view = new JMenu("View");
150                view.getAccessibleContext().setAccessibleDescription("View Menu");
151                view.setMnemonic(KeyEvent.VK_V);
152
153                if ( parent != null){
154                        //Alignment Panel
155                        JMenuItem apI = MenuCreator.getIcon(parent,ALIGNMENT_PANEL);
156                        apI.setMnemonic(KeyEvent.VK_M);
157                        apI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, keyMask));
158                        view.add(apI);
159                        //Text Format
160                        JMenuItem textI = MenuCreator.getIcon(parent,TEXT_ONLY);
161                        textI.setMnemonic(KeyEvent.VK_T);
162                        view.add(textI);
163                        //Alignment Pairs
164                        JMenuItem pairsI = MenuCreator.getIcon(parent,PAIRS_ONLY);
165                        pairsI.setMnemonic(KeyEvent.VK_P);
166                        view.add(pairsI);
167                        //FatCat Format
168                        JMenuItem textF = MenuCreator.getIcon(parent,FATCAT_TEXT);
169                        textF.setMnemonic(KeyEvent.VK_F);
170                        view.add(textF);
171                        //Distance Matrices
172                        JMenuItem distMax = new  JMenuItem(DIST_MATRICES);
173                        distMax.setMnemonic(KeyEvent.VK_D);
174                        distMax.addActionListener(new MyDistMaxListener(parent));
175                        view.add(distMax);
176                        //Dot Plot - only if the alignment was an afpChain
177                        if (afpChain != null){
178                                JMenuItem dotplot = new JMenuItem(DOT_PLOT);
179                                dotplot.setMnemonic(KeyEvent.VK_O);
180                                dotplot.addActionListener(new DotPlotListener(afpChain));
181                                view.add(dotplot);
182                        }
183                        //Phylogenetics - only if it is a MultipleAlignment
184                        if (afpChain == null){
185                                JMenuItem tree = getIcon(parent, PHYLOGENETIC_TREE);
186                                tree.setMnemonic(KeyEvent.VK_T);
187                                view.add(tree);
188                        }
189                }
190                menu.add(view);
191
192/// HELP MENU
193                JMenu about = new JMenu("Help");
194                about.setMnemonic(KeyEvent.VK_H);
195
196                JMenuItem helpM = getHelpMenuItem();
197                about.add(helpM);
198
199                JMenuItem aboutM = getAboutMenuItem();
200                about.add(aboutM);
201
202                menu.add(Box.createGlue());
203                menu.add(about);
204
205                return menu;
206        }
207
208
209        public static JMenuItem getDBResultMenuItem() {
210
211                ImageIcon saveicon = createImageIcon("/icons/kpdf.png");
212                JMenuItem saveI = null;
213
214                if ( saveicon == null)
215                        saveI = new JMenuItem(LOAD_DB_RESULTS);
216                else
217                        saveI = new JMenuItem(LOAD_DB_RESULTS, saveicon);
218
219                saveI.addActionListener(new ActionListener() {
220
221                        @Override
222                        public void actionPerformed(ActionEvent e) {
223                                final JFileChooser fc = new JFileChooser();
224
225                                //                                      In response to a button click:
226                                int returnVal = fc.showOpenDialog(null);
227                                if ( returnVal == JFileChooser.APPROVE_OPTION) {
228                                        File file = fc.getSelectedFile();
229
230                                        UserConfiguration config = WebStartMain.getWebStartConfig();
231                                        DBResultTable table = new DBResultTable();
232                                        table.show(file,config);
233                                }
234
235                        }
236                } );
237
238                return saveI;
239        }
240
241        public static JMenuItem getShowPDBMenuItem() {
242                ImageIcon loadI = createImageIcon("/icons/background.png");
243                JMenuItem openI = null;
244
245                if ( loadI == null)
246                        openI =new JMenuItem("Show By ID");
247                else
248                        openI =new JMenuItem("Show By ID", loadI);
249                openI.setMnemonic(KeyEvent.VK_O);
250                openI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, keyMask));
251                openI.addActionListener(new ShowPDBIDListener());
252                return openI;
253        }
254
255
256        public static JMenuItem getOpenPDBMenuItem() {
257                ImageIcon loadI = createImageIcon("/icons/background.png");
258                JMenuItem openI = null;
259
260                if ( loadI == null)
261                        openI =new JMenuItem("Open PDB file");
262                else
263                        openI =new JMenuItem("Open PDB file", loadI);
264                openI.setMnemonic(KeyEvent.VK_F);
265                openI.addActionListener(new MyOpenPdbFileListener());
266                return openI;
267        }
268
269
270        public static JMenuItem getLoadMenuItem() {
271
272                JMenuItem loadF = null;
273                ImageIcon loadI = createImageIcon("/icons/revert.png");
274                if ( loadI == null)
275                        loadF = new JMenuItem(LOAD_ALIGNMENT_XML);
276                else
277                        loadF = new JMenuItem(LOAD_ALIGNMENT_XML, loadI);
278                loadF.setMnemonic(KeyEvent.VK_L);
279                loadF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, keyMask));
280
281                return loadF;
282        }
283
284
285        /**
286         * Create the menu for the Alignment Panel representation of
287         * Structural Alignments. The alignment can be in AFPChain format
288         * or in the MultipleAlignment format.
289         *
290         * @param frame
291         * @param actionListener
292         * @param afpChain
293         * @param MultipleAlignment
294         * @return a JMenuBar
295         */
296        public static JMenuBar getAlignmentPanelMenu(JFrame frame,
297                        ActionListener actionListener, AFPChain afpChain,
298                        MultipleAlignment msa){
299
300                JMenuBar menu = new JMenuBar();
301
302                JMenu file= new JMenu("File");
303                file.getAccessibleContext().setAccessibleDescription("File Menu");
304                menu.add(file);
305
306                ImageIcon saveicon = createImageIcon("/icons/filesave.png");
307
308                JMenuItem saveF = null;
309
310                if (saveicon != null)
311                        saveF = new JMenuItem("Save text display", saveicon);
312                else
313                        saveF = new JMenuItem("Save text display");
314
315                saveF.setMnemonic(KeyEvent.VK_S);
316                MySaveFileListener listener = new MySaveFileListener(afpChain, msa);
317                listener.setTextOutput(true);
318                saveF.addActionListener(listener);
319                file.add(saveF);
320
321                file.addSeparator();
322
323                JMenuItem print = getPrintMenuItem();
324                print.addActionListener(actionListener);
325                file.add(print);
326
327                file.addSeparator();
328
329                JMenuItem closeI = MenuCreator.getCloseMenuItem(frame);
330                file.add(closeI);
331                JMenuItem exitI = MenuCreator.getExitMenuItem();
332                file.add(exitI);
333
334                JMenu edit = new JMenu("Edit");
335                edit.setMnemonic(KeyEvent.VK_E);
336                menu.add(edit);
337
338                JMenuItem eqrI = MenuCreator.getIcon(actionListener,SELECT_EQR);
339                edit.add(eqrI);
340
341                JMenuItem eqrcI = MenuCreator.getIcon(actionListener,EQR_COLOR);
342                edit.add(eqrcI);
343
344                JMenuItem simI = MenuCreator.getIcon(actionListener, SIMILARITY_COLOR);
345                edit.add(simI);
346
347                JMenuItem fatcatI = MenuCreator.getIcon(actionListener, FATCAT_BLOCK );
348                edit.add(fatcatI);
349
350                JMenu view= new JMenu("View");
351                view.getAccessibleContext().setAccessibleDescription("View Menu");
352                view.setMnemonic(KeyEvent.VK_V);
353                menu.add(view);
354
355                JMenuItem textI = MenuCreator.getIcon(actionListener,TEXT_ONLY);
356                view.add(textI);
357
358                JMenuItem fastaI = MenuCreator.getIcon(actionListener,FASTA_FORMAT);
359                view.add(fastaI);
360
361                JMenuItem pairsI = MenuCreator.getIcon(actionListener,PAIRS_ONLY);
362                view.add(pairsI);
363
364                JMenuItem textF = MenuCreator.getIcon(actionListener,FATCAT_TEXT);
365                view.add(textF);
366
367                JMenu about = new JMenu("Help");
368                about.setMnemonic(KeyEvent.VK_A);
369
370                JMenuItem helpM = MenuCreator.getHelpMenuItem();
371                about.add(helpM);
372
373                JMenuItem aboutM = MenuCreator.getAboutMenuItem();
374                about.add(aboutM);
375
376
377                menu.add(Box.createGlue());
378                menu.add(about);
379
380                return menu;
381        }
382
383        /**
384         * Create the menu for the Text representations of Structural Alignments.
385         * @param frame
386         * @param actionListener
387         * @param afpChain
388         * @param msa
389         * @return a JMenuBar
390         */
391        public static JMenuBar getAlignmentTextMenu(JFrame frame,
392                        ActionListener actionListener, AFPChain afpChain,
393                        MultipleAlignment msa){
394
395                JMenuBar menu = new JMenuBar();
396
397                JMenu file= new JMenu("File");
398                file.getAccessibleContext().setAccessibleDescription("File Menu");
399                menu.add(file);
400
401                ImageIcon saveicon = createImageIcon("/icons/filesave.png");
402
403                JMenuItem saveF = null;
404
405                if (saveicon != null )
406                        saveF = new JMenuItem("Save text display", saveicon);
407                else
408                        saveF = new JMenuItem("Save text display");
409
410                saveF.setMnemonic(KeyEvent.VK_S);
411                MySaveFileListener listener =
412                                new MySaveFileListener(afpChain, msa);
413                listener.setTextOutput(true);
414                saveF.addActionListener(listener);
415                file.add(saveF);
416                file.addSeparator();
417
418                JMenuItem print = getPrintMenuItem();
419                print.addActionListener(actionListener);
420                file.add(print);
421
422                file.addSeparator();
423
424                JMenuItem closeI = MenuCreator.getCloseMenuItem(frame);
425                file.add(closeI);
426                JMenuItem exitI = MenuCreator.getExitMenuItem();
427                file.add(exitI);
428
429                JMenu view= new JMenu("View");
430                view.getAccessibleContext().setAccessibleDescription("View Menu");
431                view.setMnemonic(KeyEvent.VK_V);
432                menu.add(view);
433
434                JMenuItem textI = MenuCreator.getIcon(actionListener,TEXT_ONLY);
435                view.add(textI);
436
437                JMenuItem fastaI = MenuCreator.getIcon(actionListener,FASTA_FORMAT);
438                view.add(fastaI);
439
440                JMenuItem pairsI = MenuCreator.getIcon(actionListener,PAIRS_ONLY);
441                view.add(pairsI);
442
443                JMenuItem textF = MenuCreator.getIcon(actionListener,FATCAT_TEXT);
444                view.add(textF);
445
446                JMenu about = new JMenu("Help");
447                about.setMnemonic(KeyEvent.VK_A);
448
449                JMenuItem helpM = MenuCreator.getHelpMenuItem();
450                about.add(helpM);
451
452                JMenuItem aboutM = MenuCreator.getAboutMenuItem();
453                about.add(aboutM);
454
455                menu.add(Box.createGlue());
456                menu.add(about);
457
458                return menu;
459        }
460
461        protected static JMenuItem getIcon(ActionListener actionListener, String text) {
462                JMenuItem to = new JMenuItem(text);
463
464                to.setMnemonic(KeyEvent.VK_E);
465                to.addActionListener(actionListener);
466
467                return to;
468        }
469
470        public static JMenuItem getPrintMenuItem() {
471
472                //ImageIcon printIcon = createImageIcon("/icons/print_printer.png");
473                ImageIcon printIcon = createImageIcon("/icons/fileprint.png");
474                JMenuItem print ;
475
476                if ( printIcon == null)
477                        print = new JMenuItem(PRINT);
478                else
479                        print= new JMenuItem(PRINT,printIcon);
480
481
482                print.setMnemonic(KeyEvent.VK_P);
483                print.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, keyMask));
484
485                return print;
486        }
487
488        public static JMenuItem getExportPDBMenuItem(AbstractAlignmentJmol parent) {
489                ImageIcon saveicon = createImageIcon("/icons/compfile.png");
490                JMenuItem exportI = null;
491
492                if ( saveicon == null)
493                        exportI = new JMenuItem("Export PDB file");
494                else
495                        exportI = new JMenuItem("Export PDB file", saveicon);
496
497                exportI.setMnemonic(KeyEvent.VK_E);
498                exportI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, keyMask));
499                exportI.addActionListener(new MyExportListener(parent));
500                return exportI;
501        }
502
503        public static JMenuItem getSaveAlignmentMenuItem(AFPChain afpChain,
504                        MultipleAlignment msa){
505
506                ImageIcon saveicon = createImageIcon("/icons/filesave.png");
507                JMenuItem saveF = null;
508
509                if (saveicon == null)
510                        saveF = new JMenuItem(SAVE_ALIGNMENT_XML);
511                else
512                        saveF = new JMenuItem(SAVE_ALIGNMENT_XML, saveicon);
513
514                saveF.setMnemonic(KeyEvent.VK_S);
515                saveF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask));
516                saveF.addActionListener(new MySaveFileListener(afpChain, msa));
517
518                return saveF;
519        }
520
521        public static JMenuItem getAboutMenuItem() {
522
523                ImageIcon helpIcon = createImageIcon("/icons/help.png");
524
525                JMenuItem aboutM = null;
526
527                if ( helpIcon == null)
528                        aboutM = new  JMenuItem("About this Software");
529                else
530                        aboutM = new  JMenuItem("About this Software", helpIcon);
531
532                aboutM.setMnemonic(KeyEvent.VK_A);
533                aboutM.addActionListener(new ActionListener(){
534
535                        @Override
536                        public void actionPerformed(ActionEvent e) {
537                                MenuCreator.showAboutDialog();
538
539                        }
540                });
541                return aboutM;
542        }
543
544
545        private static JMenuItem getSystemInfoItem()
546        {
547
548                ImageIcon helpIcon = createImageIcon("/icons/help.png");
549
550                JMenuItem aboutM = null;
551
552                if ( helpIcon == null)
553                        aboutM = new  JMenuItem("System Info");
554                else
555                        aboutM = new  JMenuItem("System Info", helpIcon);
556
557                aboutM.setMnemonic(KeyEvent.VK_S);
558                aboutM.addActionListener(new ActionListener(){
559
560                        @Override
561                        public void actionPerformed(ActionEvent e) {
562                                MenuCreator.showSystemInfo();
563
564                        }
565                });
566                return aboutM;
567        }
568
569        public static JMenuItem getExitMenuItem(){
570
571                ImageIcon exitIcon = createImageIcon("/icons/exit.png");
572
573
574                JMenuItem exitI;
575
576                if ( exitIcon == null)
577                        exitI = new JMenuItem("Quit");
578                else
579                        exitI = new JMenuItem("Quit",exitIcon);
580                exitI.setMnemonic(KeyEvent.VK_Q);
581                exitI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, keyMask));
582                exitI.addActionListener(new ActionListener(){
583
584                        @Override
585                        public void actionPerformed(ActionEvent e) {
586                                String cmd = e.getActionCommand();
587
588                                if ( cmd.equals("Quit")){
589                                        System.exit(0);
590                                }
591                        }
592                });
593                return exitI;
594        }
595
596
597
598
599
600        public static JMenuItem getHelpMenuItem(){
601                ImageIcon helpIcon = createImageIcon("/icons/help.png");
602                JMenuItem helpM ;
603
604                if ( helpIcon == null )
605                        helpM = new JMenuItem("Help");
606                else
607                        helpM = new JMenuItem("Help", helpIcon);
608
609                helpM.setMnemonic(KeyEvent.VK_H);
610                helpM.addActionListener(new ActionListener(){
611
612                        @Override
613                        public void actionPerformed(ActionEvent e) {
614                                HelpDialog d = new HelpDialog();
615                                d.showDialog();
616
617                        }
618                });
619
620                return helpM;
621        }
622
623        public static JMenuItem getCloseMenuItem(JFrame frame){
624
625                ImageIcon closeIcon = createImageIcon("/icons/editdelete.png");
626
627                JMenuItem closeI ;
628
629                if ( closeIcon == null )
630                        closeI = new JMenuItem("Close Frame");
631                else
632                        closeI = new JMenuItem("Close Frame", closeIcon);
633
634                closeI.setMnemonic(KeyEvent.VK_C);
635                closeI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, keyMask));
636
637                class MyCloseListener implements ActionListener{
638                        JFrame f;
639                        MyCloseListener(JFrame frame){
640                                f=frame;
641                        }
642                        @Override
643                        public void actionPerformed(ActionEvent e) {
644                                String cmd = e.getActionCommand();
645
646                                if ( cmd.equals("Close Frame")){
647                                        f.dispose();
648                                }
649                        }
650
651                }
652
653                closeI.addActionListener(new MyCloseListener(frame));
654                return closeI;
655        }
656
657
658        /**
659         * Provide a display for the pairwise structure alignment.
660         */
661        private static void showPairDialog(){
662                AlignmentGui gui =  AlignmentGui.getInstance();
663                gui.setVisible(true);
664        }
665
666        /**
667         * Provide a display for the multiple structure alignment.
668         */
669        private static void showMultipleDialog(){
670                MultipleAlignmentGUI gui =  MultipleAlignmentGUI.getInstance();
671                gui.setVisible(true);
672        }
673
674        /**
675         * Show some info about this GUI
676         *
677         */
678        public static void showAboutDialog(){
679
680                AboutDialog dialog = new AboutDialog();
681                dialog.showDialog();
682        }
683
684        public static void showSystemInfo(){
685                SystemInfo dialog = new SystemInfo();
686                dialog.showDialog();
687        }
688
689        /**
690         * Returns an ImageIcon, or null if the path was invalid.
691         * @param path the path to the icon
692         * @return ImageIcon object
693         */
694        public static ImageIcon createImageIcon(String path) {
695
696                java.net.URL imgURL = MenuCreator.class.getResource(path);
697
698                if (imgURL != null) {
699                        return new ImageIcon(imgURL);
700                } else {
701                        System.err.println("Couldn't find file: " + path);
702                        return null;
703                }
704        }
705
706        protected static JMenuItem getPairwiseAlignmentMenuItem() {
707                ImageIcon alignIcon = createImageIcon("/icons/window_new.png");
708
709                JMenuItem pairI ;
710                if ( alignIcon == null)
711                        pairI = new JMenuItem(PAIRWISE_ALIGN);
712                else
713                        pairI = new JMenuItem(PAIRWISE_ALIGN, alignIcon);
714                pairI.setMnemonic(KeyEvent.VK_N);
715                pairI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, keyMask));
716                pairI.addActionListener(new ActionListener() {
717                        @Override
718                        public void actionPerformed(ActionEvent e) {
719                                String cmd = e.getActionCommand();
720
721                                if ( cmd.equals(PAIRWISE_ALIGN)){
722                                        MenuCreator.showPairDialog();
723                                }
724                        }
725                });
726                return pairI;
727        }
728
729        protected static JMenuItem getMultipleAlignmentMenuItem() {
730                ImageIcon alignIcon = createImageIcon("/icons/window_new.png");
731
732                JMenuItem multipleI ;
733                if ( alignIcon == null)
734                        multipleI = new JMenuItem(MULTIPLE_ALIGN);
735                else
736                        multipleI = new JMenuItem(MULTIPLE_ALIGN, alignIcon);
737                multipleI.setMnemonic(KeyEvent.VK_N);
738                multipleI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, keyMask));
739                multipleI.addActionListener(new ActionListener() {
740                        @Override
741                        public void actionPerformed(ActionEvent e) {
742                                String cmd = e.getActionCommand();
743
744                                if ( cmd.equals(MULTIPLE_ALIGN)){
745                                        MenuCreator.showMultipleDialog();
746                                }
747                        }
748                });
749                return multipleI;
750        }
751
752        /**
753         * Creates a frame to display a DotPlotPanel.
754         * Used by the 'View>Show Dot Plot' menu item
755         *
756         */
757        public static class DotPlotListener implements ActionListener {
758                private final AFPChain afpChain;
759                public DotPlotListener(AFPChain afpChain) {
760                        this.afpChain = afpChain;
761                }
762                @Override
763                public void actionPerformed(ActionEvent e) {
764                        String title = String.format("%s vs. %s",
765                                        afpChain.getName1(),afpChain.getName2());
766
767                        // Create window
768                        JFrame frame = new JFrame(title);
769                        frame.addWindowListener(new WindowAdapter(){
770                                @Override
771                                public void windowClosing(WindowEvent e){
772                                        JFrame f = (JFrame) e.getSource();
773                                        f.setVisible(false);
774                                        f.dispose();
775                                }
776                        });
777
778                        DotPlotPanel dotplot = new DotPlotPanel(afpChain);
779
780                        frame.getContentPane().add(dotplot);
781                        frame.pack();
782                        frame.setVisible(true);
783                }
784        }
785
786        public static JMenuBar initAlignmentGUIMenu(JFrame frame) {
787
788                JMenu file= new JMenu("File");
789                file.getAccessibleContext().setAccessibleDescription("File Menu");
790
791                JMenuItem loadF = MenuCreator.getLoadMenuItem();
792                loadF.addActionListener(new MyAlignmentLoadListener());
793                file.add(loadF);
794
795                JMenuItem openPDB = MenuCreator.getShowPDBMenuItem();
796                file.add(openPDB);
797
798                JMenuItem openI = MenuCreator.getOpenPDBMenuItem();
799                file.add(openI);
800
801                JMenuItem dbI = MenuCreator.getDBResultMenuItem();
802                file.add(dbI);
803                file.addSeparator();
804
805                JMenuItem configI = MenuCreator.getConfigMenuItem();
806                file.add(configI);
807                file.addSeparator();
808
809                JMenuItem closeI = MenuCreator.getCloseMenuItem(frame);
810                file.add(closeI);
811                JMenuItem exitI = MenuCreator.getExitMenuItem();
812                file.add(exitI);
813
814                JMenuBar menu = new JMenuBar();
815                menu.add(file);
816
817                //JMenu alig = new JMenu("Align");
818                //menu.add(alig);
819
820                //JMenuItem pw = MenuCreator.getPairwiseAlignmentMenuItem();
821                //alig.add(pw);
822
823
824                JMenu about = new JMenu("Help");
825                about.setMnemonic(KeyEvent.VK_A);
826
827                JMenuItem aboutM = MenuCreator.getAboutMenuItem();
828                about.add(aboutM);
829
830
831                JMenuItem techM = MenuCreator.getSystemInfoItem();
832                about.add(techM);
833
834                JMenuItem memM = MenuCreator.getMemoryMonitorItem();
835                about.add(memM);
836
837                menu.add(Box.createGlue());
838                menu.add(about);
839
840                return menu;
841
842        }
843
844        private static JMenuItem getMemoryMonitorItem() {
845                ImageIcon helpIcon = createImageIcon("/icons/help.png");
846
847                JMenuItem aboutM = null;
848
849                if ( helpIcon == null)
850                        aboutM = new  JMenuItem("Memory Monitor");
851                else
852                        aboutM = new  JMenuItem("Memory Monitor", helpIcon);
853
854                aboutM.setMnemonic(KeyEvent.VK_M);
855                aboutM.addActionListener(new ActionListener(){
856
857                        @Override
858                        public void actionPerformed(ActionEvent e) {
859                                MenuCreator.showMemoryMonitor();
860
861                        }
862                });
863                return aboutM;
864        }
865
866        protected static void showMemoryMonitor() {
867                final MemoryMonitor demo = new MemoryMonitor();
868
869                final JFrame f = new JFrame("MemoryMonitor");
870                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
871
872                WindowListener l = new WindowAdapter() {
873                        @Override
874                        public void windowClosing(WindowEvent e) {}
875                        @Override
876                        public void windowDeiconified(WindowEvent e) { demo.surf.start(); }
877                        @Override
878                        public void windowIconified(WindowEvent e) { demo.surf.stop(); }
879                };
880
881                f.addWindowListener(l);
882
883
884                Box vBox = Box.createVerticalBox();
885
886                vBox.add(demo);
887
888                Box b = Box.createHorizontalBox();
889                JButton b1 = new JButton("Run Garbage Collector");
890
891                b1.addActionListener(new ActionListener() {
892
893                        @Override
894                        public void actionPerformed(ActionEvent e) {
895                                System.gc();
896
897                        }
898                });
899
900                b.add(b1);
901                b.add(Box.createGlue());
902
903                vBox.add(b);
904                f.getContentPane().add("Center",vBox);
905                f.pack();
906                f.setSize(new Dimension(200,200));
907                f.setVisible(true);
908                demo.surf.start();
909
910        }
911
912        private static JMenuItem getConfigMenuItem() {
913
914                ImageIcon configIcon = createImageIcon("/icons/configure.png");
915
916                JMenuItem configI;
917
918                if ( configIcon == null)
919                        configI = new JMenuItem("Settings");
920                else
921                        configI = new JMenuItem("Settings",configIcon);
922                configI.setMnemonic(KeyEvent.VK_S);
923                configI.addActionListener(new ActionListener(){
924
925                        @Override
926                        public void actionPerformed(ActionEvent e) {
927                                String cmd = e.getActionCommand();
928
929                                if ( cmd.equals("Settings")){
930                                        ConfigPDBInstallPanel.showDialog();
931                                }
932                        }
933                });
934                return configI;
935        }
936}