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                //Print
117                if ( parent != null){
118                        JMenuItem print = getPrintMenuItem();
119                        print.addActionListener(parent.getJmolPanel());
120                        file.add(print);
121                }
122                file.addSeparator();
123                //Close Frame
124                JMenuItem closeI = getCloseMenuItem(frame);
125                file.add(closeI);
126                //Exit
127                JMenuItem exitI = getExitMenuItem();
128                file.add(exitI);
129
130                menu.add(file);
131
132/// ALIGN MENU
133                JMenu align = new JMenu("Align");
134                align.setMnemonic(KeyEvent.VK_A);
135                //new Pairwise alignment
136                JMenuItem pairI = getPairwiseAlignmentMenuItem();
137                align.add(pairI);
138                //new Multiple alignment
139                JMenuItem multI = getMultipleAlignmentMenuItem();
140                align.add(multI);
141
142                menu.add(align);
143
144/// VIEW MENU
145                JMenu view = new JMenu("View");
146                view.getAccessibleContext().setAccessibleDescription("View Menu");
147                view.setMnemonic(KeyEvent.VK_V);
148
149                if ( parent != null){
150                        //Alignment Panel
151                        JMenuItem apI = MenuCreator.getIcon(parent,ALIGNMENT_PANEL);
152                        apI.setMnemonic(KeyEvent.VK_M);
153                        apI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, keyMask));
154                        view.add(apI);
155                        //Text Format
156                        JMenuItem textI = MenuCreator.getIcon(parent,TEXT_ONLY);
157                        textI.setMnemonic(KeyEvent.VK_T);
158                        view.add(textI);
159                        //Alignment Pairs
160                        JMenuItem pairsI = MenuCreator.getIcon(parent,PAIRS_ONLY);
161                        pairsI.setMnemonic(KeyEvent.VK_P);
162                        view.add(pairsI);
163                        //FatCat Format
164                        JMenuItem textF = MenuCreator.getIcon(parent,FATCAT_TEXT);
165                        textF.setMnemonic(KeyEvent.VK_F);
166                        view.add(textF);
167                        //Distance Matrices
168                        JMenuItem distMax = new  JMenuItem(DIST_MATRICES);
169                        distMax.setMnemonic(KeyEvent.VK_D);
170                        distMax.addActionListener(new MyDistMaxListener(parent));
171                        view.add(distMax);
172                        //Dot Plot - only if the alignment was an afpChain
173                        if (afpChain != null){
174                                JMenuItem dotplot = new JMenuItem(DOT_PLOT);
175                                dotplot.setMnemonic(KeyEvent.VK_O);
176                                dotplot.addActionListener(new DotPlotListener(afpChain));
177                                view.add(dotplot);
178                        }
179                        //Phylogenetics - only if it is a MultipleAlignment
180                        if (afpChain == null){
181                                JMenuItem tree = getIcon(parent, PHYLOGENETIC_TREE);
182                                tree.setMnemonic(KeyEvent.VK_T);
183                                view.add(tree);
184                        }
185                }
186                menu.add(view);
187
188/// HELP MENU
189                JMenu about = new JMenu("Help");
190                about.setMnemonic(KeyEvent.VK_H);
191
192                JMenuItem helpM = getHelpMenuItem();
193                about.add(helpM);
194
195                JMenuItem aboutM = getAboutMenuItem();
196                about.add(aboutM);
197
198                menu.add(Box.createGlue());
199                menu.add(about);
200
201                return menu;
202        }
203
204        public static JMenuItem getShowPDBMenuItem() {
205                ImageIcon loadI = createImageIcon("/icons/background.png");
206                JMenuItem openI = null;
207
208                if ( loadI == null)
209                        openI =new JMenuItem("Show By ID");
210                else
211                        openI =new JMenuItem("Show By ID", loadI);
212                openI.setMnemonic(KeyEvent.VK_O);
213                openI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, keyMask));
214                openI.addActionListener(new ShowPDBIDListener());
215                return openI;
216        }
217
218
219        public static JMenuItem getOpenPDBMenuItem() {
220                ImageIcon loadI = createImageIcon("/icons/background.png");
221                JMenuItem openI = null;
222
223                if ( loadI == null)
224                        openI =new JMenuItem("Open PDB file");
225                else
226                        openI =new JMenuItem("Open PDB file", loadI);
227                openI.setMnemonic(KeyEvent.VK_F);
228                openI.addActionListener(new MyOpenPdbFileListener());
229                return openI;
230        }
231
232
233        public static JMenuItem getLoadMenuItem() {
234
235                JMenuItem loadF = null;
236                ImageIcon loadI = createImageIcon("/icons/revert.png");
237                if ( loadI == null)
238                        loadF = new JMenuItem(LOAD_ALIGNMENT_XML);
239                else
240                        loadF = new JMenuItem(LOAD_ALIGNMENT_XML, loadI);
241                loadF.setMnemonic(KeyEvent.VK_L);
242                loadF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, keyMask));
243
244                return loadF;
245        }
246
247
248        /**
249         * Create the menu for the Alignment Panel representation of
250         * Structural Alignments. The alignment can be in AFPChain format
251         * or in the MultipleAlignment format.
252         *
253         * @param frame
254         * @param actionListener
255         * @param afpChain
256         * @param msa
257         * @return a JMenuBar
258         */
259        public static JMenuBar getAlignmentPanelMenu(JFrame frame,
260                        ActionListener actionListener, AFPChain afpChain,
261                        MultipleAlignment msa){
262
263                JMenuBar menu = new JMenuBar();
264
265                JMenu file= new JMenu("File");
266                file.getAccessibleContext().setAccessibleDescription("File Menu");
267                menu.add(file);
268
269                ImageIcon saveicon = createImageIcon("/icons/filesave.png");
270
271                JMenuItem saveF = null;
272
273                if (saveicon != null)
274                        saveF = new JMenuItem("Save text display", saveicon);
275                else
276                        saveF = new JMenuItem("Save text display");
277
278                saveF.setMnemonic(KeyEvent.VK_S);
279                MySaveFileListener listener = new MySaveFileListener(afpChain, msa);
280                listener.setTextOutput(true);
281                saveF.addActionListener(listener);
282                file.add(saveF);
283
284                file.addSeparator();
285
286                JMenuItem print = getPrintMenuItem();
287                print.addActionListener(actionListener);
288                file.add(print);
289
290                file.addSeparator();
291
292                JMenuItem closeI = MenuCreator.getCloseMenuItem(frame);
293                file.add(closeI);
294                JMenuItem exitI = MenuCreator.getExitMenuItem();
295                file.add(exitI);
296
297                JMenu edit = new JMenu("Edit");
298                edit.setMnemonic(KeyEvent.VK_E);
299                menu.add(edit);
300
301                JMenuItem eqrI = MenuCreator.getIcon(actionListener,SELECT_EQR);
302                edit.add(eqrI);
303
304                JMenuItem eqrcI = MenuCreator.getIcon(actionListener,EQR_COLOR);
305                edit.add(eqrcI);
306
307                JMenuItem simI = MenuCreator.getIcon(actionListener, SIMILARITY_COLOR);
308                edit.add(simI);
309
310                JMenuItem fatcatI = MenuCreator.getIcon(actionListener, FATCAT_BLOCK );
311                edit.add(fatcatI);
312
313                JMenu view= new JMenu("View");
314                view.getAccessibleContext().setAccessibleDescription("View Menu");
315                view.setMnemonic(KeyEvent.VK_V);
316                menu.add(view);
317
318                JMenuItem textI = MenuCreator.getIcon(actionListener,TEXT_ONLY);
319                view.add(textI);
320
321                JMenuItem fastaI = MenuCreator.getIcon(actionListener,FASTA_FORMAT);
322                view.add(fastaI);
323
324                JMenuItem pairsI = MenuCreator.getIcon(actionListener,PAIRS_ONLY);
325                view.add(pairsI);
326
327                JMenuItem textF = MenuCreator.getIcon(actionListener,FATCAT_TEXT);
328                view.add(textF);
329
330                JMenu about = new JMenu("Help");
331                about.setMnemonic(KeyEvent.VK_A);
332
333                JMenuItem helpM = MenuCreator.getHelpMenuItem();
334                about.add(helpM);
335
336                JMenuItem aboutM = MenuCreator.getAboutMenuItem();
337                about.add(aboutM);
338
339
340                menu.add(Box.createGlue());
341                menu.add(about);
342
343                return menu;
344        }
345
346        /**
347         * Create the menu for the Text representations of Structural Alignments.
348         * @param frame
349         * @param actionListener
350         * @param afpChain
351         * @param msa
352         * @return a JMenuBar
353         */
354        public static JMenuBar getAlignmentTextMenu(JFrame frame,
355                        ActionListener actionListener, AFPChain afpChain,
356                        MultipleAlignment msa){
357
358                JMenuBar menu = new JMenuBar();
359
360                JMenu file= new JMenu("File");
361                file.getAccessibleContext().setAccessibleDescription("File Menu");
362                menu.add(file);
363
364                ImageIcon saveicon = createImageIcon("/icons/filesave.png");
365
366                JMenuItem saveF = null;
367
368                if (saveicon != null )
369                        saveF = new JMenuItem("Save text display", saveicon);
370                else
371                        saveF = new JMenuItem("Save text display");
372
373                saveF.setMnemonic(KeyEvent.VK_S);
374                MySaveFileListener listener =
375                                new MySaveFileListener(afpChain, msa);
376                listener.setTextOutput(true);
377                saveF.addActionListener(listener);
378                file.add(saveF);
379                file.addSeparator();
380
381                JMenuItem print = getPrintMenuItem();
382                print.addActionListener(actionListener);
383                file.add(print);
384
385                file.addSeparator();
386
387                JMenuItem closeI = MenuCreator.getCloseMenuItem(frame);
388                file.add(closeI);
389                JMenuItem exitI = MenuCreator.getExitMenuItem();
390                file.add(exitI);
391
392                JMenu view= new JMenu("View");
393                view.getAccessibleContext().setAccessibleDescription("View Menu");
394                view.setMnemonic(KeyEvent.VK_V);
395                menu.add(view);
396
397                JMenuItem textI = MenuCreator.getIcon(actionListener,TEXT_ONLY);
398                view.add(textI);
399
400                JMenuItem fastaI = MenuCreator.getIcon(actionListener,FASTA_FORMAT);
401                view.add(fastaI);
402
403                JMenuItem pairsI = MenuCreator.getIcon(actionListener,PAIRS_ONLY);
404                view.add(pairsI);
405
406                JMenuItem textF = MenuCreator.getIcon(actionListener,FATCAT_TEXT);
407                view.add(textF);
408
409                JMenu about = new JMenu("Help");
410                about.setMnemonic(KeyEvent.VK_A);
411
412                JMenuItem helpM = MenuCreator.getHelpMenuItem();
413                about.add(helpM);
414
415                JMenuItem aboutM = MenuCreator.getAboutMenuItem();
416                about.add(aboutM);
417
418                menu.add(Box.createGlue());
419                menu.add(about);
420
421                return menu;
422        }
423
424        protected static JMenuItem getIcon(ActionListener actionListener, String text) {
425                JMenuItem to = new JMenuItem(text);
426
427                to.setMnemonic(KeyEvent.VK_E);
428                to.addActionListener(actionListener);
429
430                return to;
431        }
432
433        public static JMenuItem getPrintMenuItem() {
434
435                //ImageIcon printIcon = createImageIcon("/icons/print_printer.png");
436                ImageIcon printIcon = createImageIcon("/icons/fileprint.png");
437                JMenuItem print ;
438
439                if ( printIcon == null)
440                        print = new JMenuItem(PRINT);
441                else
442                        print= new JMenuItem(PRINT,printIcon);
443
444
445                print.setMnemonic(KeyEvent.VK_P);
446                print.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, keyMask));
447
448                return print;
449        }
450
451        public static JMenuItem getExportPDBMenuItem(AbstractAlignmentJmol parent) {
452                ImageIcon saveicon = createImageIcon("/icons/compfile.png");
453                JMenuItem exportI = null;
454
455                if ( saveicon == null)
456                        exportI = new JMenuItem("Export PDB file");
457                else
458                        exportI = new JMenuItem("Export PDB file", saveicon);
459
460                exportI.setMnemonic(KeyEvent.VK_E);
461                exportI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, keyMask));
462                exportI.addActionListener(new MyExportListener(parent));
463                return exportI;
464        }
465
466        public static JMenuItem getSaveAlignmentMenuItem(AFPChain afpChain,
467                        MultipleAlignment msa){
468
469                ImageIcon saveicon = createImageIcon("/icons/filesave.png");
470                JMenuItem saveF = null;
471
472                if (saveicon == null)
473                        saveF = new JMenuItem(SAVE_ALIGNMENT_XML);
474                else
475                        saveF = new JMenuItem(SAVE_ALIGNMENT_XML, saveicon);
476
477                saveF.setMnemonic(KeyEvent.VK_S);
478                saveF.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask));
479                saveF.addActionListener(new MySaveFileListener(afpChain, msa));
480
481                return saveF;
482        }
483
484        public static JMenuItem getAboutMenuItem() {
485
486                ImageIcon helpIcon = createImageIcon("/icons/help.png");
487
488                JMenuItem aboutM = null;
489
490                if ( helpIcon == null)
491                        aboutM = new  JMenuItem("About this Software");
492                else
493                        aboutM = new  JMenuItem("About this Software", helpIcon);
494
495                aboutM.setMnemonic(KeyEvent.VK_A);
496                aboutM.addActionListener(new ActionListener(){
497
498                        @Override
499                        public void actionPerformed(ActionEvent e) {
500                                MenuCreator.showAboutDialog();
501
502                        }
503                });
504                return aboutM;
505        }
506
507
508        private static JMenuItem getSystemInfoItem()
509        {
510
511                ImageIcon helpIcon = createImageIcon("/icons/help.png");
512
513                JMenuItem aboutM = null;
514
515                if ( helpIcon == null)
516                        aboutM = new  JMenuItem("System Info");
517                else
518                        aboutM = new  JMenuItem("System Info", helpIcon);
519
520                aboutM.setMnemonic(KeyEvent.VK_S);
521                aboutM.addActionListener(new ActionListener(){
522
523                        @Override
524                        public void actionPerformed(ActionEvent e) {
525                                MenuCreator.showSystemInfo();
526
527                        }
528                });
529                return aboutM;
530        }
531
532        public static JMenuItem getExitMenuItem(){
533
534                ImageIcon exitIcon = createImageIcon("/icons/exit.png");
535
536
537                JMenuItem exitI;
538
539                if ( exitIcon == null)
540                        exitI = new JMenuItem("Quit");
541                else
542                        exitI = new JMenuItem("Quit",exitIcon);
543                exitI.setMnemonic(KeyEvent.VK_Q);
544                exitI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, keyMask));
545                exitI.addActionListener(new ActionListener(){
546
547                        @Override
548                        public void actionPerformed(ActionEvent e) {
549                                String cmd = e.getActionCommand();
550
551                                if ( cmd.equals("Quit")){
552                                        System.exit(0);
553                                }
554                        }
555                });
556                return exitI;
557        }
558
559
560
561
562
563        public static JMenuItem getHelpMenuItem(){
564                ImageIcon helpIcon = createImageIcon("/icons/help.png");
565                JMenuItem helpM ;
566
567                if ( helpIcon == null )
568                        helpM = new JMenuItem("Help");
569                else
570                        helpM = new JMenuItem("Help", helpIcon);
571
572                helpM.setMnemonic(KeyEvent.VK_H);
573                helpM.addActionListener(new ActionListener(){
574
575                        @Override
576                        public void actionPerformed(ActionEvent e) {
577                                HelpDialog d = new HelpDialog();
578                                d.showDialog();
579
580                        }
581                });
582
583                return helpM;
584        }
585
586        public static JMenuItem getCloseMenuItem(JFrame frame){
587
588                ImageIcon closeIcon = createImageIcon("/icons/editdelete.png");
589
590                JMenuItem closeI ;
591
592                if ( closeIcon == null )
593                        closeI = new JMenuItem("Close Frame");
594                else
595                        closeI = new JMenuItem("Close Frame", closeIcon);
596
597                closeI.setMnemonic(KeyEvent.VK_C);
598                closeI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, keyMask));
599
600                class MyCloseListener implements ActionListener{
601                        JFrame f;
602                        MyCloseListener(JFrame frame){
603                                f=frame;
604                        }
605                        @Override
606                        public void actionPerformed(ActionEvent e) {
607                                String cmd = e.getActionCommand();
608
609                                if ( cmd.equals("Close Frame")){
610                                        f.dispose();
611                                }
612                        }
613
614                }
615
616                closeI.addActionListener(new MyCloseListener(frame));
617                return closeI;
618        }
619
620
621        /**
622         * Provide a display for the pairwise structure alignment.
623         */
624        private static void showPairDialog(){
625                AlignmentGui gui =  AlignmentGui.getInstance();
626                gui.setVisible(true);
627        }
628
629        /**
630         * Provide a display for the multiple structure alignment.
631         */
632        private static void showMultipleDialog(){
633                MultipleAlignmentGUI gui =  MultipleAlignmentGUI.getInstance();
634                gui.setVisible(true);
635        }
636
637        /**
638         * Show some info about this GUI
639         *
640         */
641        public static void showAboutDialog(){
642
643                AboutDialog dialog = new AboutDialog();
644                dialog.showDialog();
645        }
646
647        public static void showSystemInfo(){
648                SystemInfo dialog = new SystemInfo();
649                dialog.showDialog();
650        }
651
652        /**
653         * Returns an ImageIcon, or null if the path was invalid.
654         * @param path the path to the icon
655         * @return ImageIcon object
656         */
657        public static ImageIcon createImageIcon(String path) {
658
659                java.net.URL imgURL = MenuCreator.class.getResource(path);
660
661                if (imgURL != null) {
662                        return new ImageIcon(imgURL);
663                } else {
664                        System.err.println("Couldn't find file: " + path);
665                        return null;
666                }
667        }
668
669        protected static JMenuItem getPairwiseAlignmentMenuItem() {
670                ImageIcon alignIcon = createImageIcon("/icons/window_new.png");
671
672                JMenuItem pairI ;
673                if ( alignIcon == null)
674                        pairI = new JMenuItem(PAIRWISE_ALIGN);
675                else
676                        pairI = new JMenuItem(PAIRWISE_ALIGN, alignIcon);
677                pairI.setMnemonic(KeyEvent.VK_N);
678                pairI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, keyMask));
679                pairI.addActionListener(new ActionListener() {
680                        @Override
681                        public void actionPerformed(ActionEvent e) {
682                                String cmd = e.getActionCommand();
683
684                                if ( cmd.equals(PAIRWISE_ALIGN)){
685                                        MenuCreator.showPairDialog();
686                                }
687                        }
688                });
689                return pairI;
690        }
691
692        protected static JMenuItem getMultipleAlignmentMenuItem() {
693                ImageIcon alignIcon = createImageIcon("/icons/window_new.png");
694
695                JMenuItem multipleI ;
696                if ( alignIcon == null)
697                        multipleI = new JMenuItem(MULTIPLE_ALIGN);
698                else
699                        multipleI = new JMenuItem(MULTIPLE_ALIGN, alignIcon);
700                multipleI.setMnemonic(KeyEvent.VK_N);
701                multipleI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, keyMask));
702                multipleI.addActionListener(new ActionListener() {
703                        @Override
704                        public void actionPerformed(ActionEvent e) {
705                                String cmd = e.getActionCommand();
706
707                                if ( cmd.equals(MULTIPLE_ALIGN)){
708                                        MenuCreator.showMultipleDialog();
709                                }
710                        }
711                });
712                return multipleI;
713        }
714
715        /**
716         * Creates a frame to display a DotPlotPanel.
717         * Used by the 'View>Show Dot Plot' menu item
718         *
719         */
720        public static class DotPlotListener implements ActionListener {
721                private final AFPChain afpChain;
722                public DotPlotListener(AFPChain afpChain) {
723                        this.afpChain = afpChain;
724                }
725                @Override
726                public void actionPerformed(ActionEvent e) {
727                        String title = String.format("%s vs. %s",
728                                        afpChain.getName1(),afpChain.getName2());
729
730                        // Create window
731                        JFrame frame = new JFrame(title);
732                        frame.addWindowListener(new WindowAdapter(){
733                                @Override
734                                public void windowClosing(WindowEvent e){
735                                        JFrame f = (JFrame) e.getSource();
736                                        f.setVisible(false);
737                                        f.dispose();
738                                }
739                        });
740
741                        DotPlotPanel dotplot = new DotPlotPanel(afpChain);
742
743                        frame.getContentPane().add(dotplot);
744                        frame.pack();
745                        frame.setVisible(true);
746                }
747        }
748
749        public static JMenuBar initAlignmentGUIMenu(JFrame frame) {
750
751                JMenu file= new JMenu("File");
752                file.getAccessibleContext().setAccessibleDescription("File Menu");
753
754                JMenuItem loadF = MenuCreator.getLoadMenuItem();
755                loadF.addActionListener(new MyAlignmentLoadListener());
756                file.add(loadF);
757
758                JMenuItem openPDB = MenuCreator.getShowPDBMenuItem();
759                file.add(openPDB);
760
761                JMenuItem openI = MenuCreator.getOpenPDBMenuItem();
762                file.add(openI);
763
764                JMenuItem configI = MenuCreator.getConfigMenuItem();
765                file.add(configI);
766                file.addSeparator();
767
768                JMenuItem closeI = MenuCreator.getCloseMenuItem(frame);
769                file.add(closeI);
770                JMenuItem exitI = MenuCreator.getExitMenuItem();
771                file.add(exitI);
772
773                JMenuBar menu = new JMenuBar();
774                menu.add(file);
775
776                //JMenu alig = new JMenu("Align");
777                //menu.add(alig);
778
779                //JMenuItem pw = MenuCreator.getPairwiseAlignmentMenuItem();
780                //alig.add(pw);
781
782
783                JMenu about = new JMenu("Help");
784                about.setMnemonic(KeyEvent.VK_A);
785
786                JMenuItem aboutM = MenuCreator.getAboutMenuItem();
787                about.add(aboutM);
788
789
790                JMenuItem techM = MenuCreator.getSystemInfoItem();
791                about.add(techM);
792
793                JMenuItem memM = MenuCreator.getMemoryMonitorItem();
794                about.add(memM);
795
796                menu.add(Box.createGlue());
797                menu.add(about);
798
799                return menu;
800
801        }
802
803        private static JMenuItem getMemoryMonitorItem() {
804                ImageIcon helpIcon = createImageIcon("/icons/help.png");
805
806                JMenuItem aboutM = null;
807
808                if ( helpIcon == null)
809                        aboutM = new  JMenuItem("Memory Monitor");
810                else
811                        aboutM = new  JMenuItem("Memory Monitor", helpIcon);
812
813                aboutM.setMnemonic(KeyEvent.VK_M);
814                aboutM.addActionListener(new ActionListener(){
815
816                        @Override
817                        public void actionPerformed(ActionEvent e) {
818                                MenuCreator.showMemoryMonitor();
819
820                        }
821                });
822                return aboutM;
823        }
824
825        protected static void showMemoryMonitor() {
826                final MemoryMonitor demo = new MemoryMonitor();
827
828                final JFrame f = new JFrame("MemoryMonitor");
829                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
830
831                WindowListener l = new WindowAdapter() {
832                        @Override
833                        public void windowClosing(WindowEvent e) {}
834                        @Override
835                        public void windowDeiconified(WindowEvent e) { demo.surf.start(); }
836                        @Override
837                        public void windowIconified(WindowEvent e) { demo.surf.stop(); }
838                };
839
840                f.addWindowListener(l);
841
842
843                Box vBox = Box.createVerticalBox();
844
845                vBox.add(demo);
846
847                Box b = Box.createHorizontalBox();
848                JButton b1 = new JButton("Run Garbage Collector");
849
850                b1.addActionListener(new ActionListener() {
851
852                        @Override
853                        public void actionPerformed(ActionEvent e) {
854                                System.gc();
855
856                        }
857                });
858
859                b.add(b1);
860                b.add(Box.createGlue());
861
862                vBox.add(b);
863                f.getContentPane().add("Center",vBox);
864                f.pack();
865                f.setSize(new Dimension(200,200));
866                f.setVisible(true);
867                demo.surf.start();
868
869        }
870
871        private static JMenuItem getConfigMenuItem() {
872
873                ImageIcon configIcon = createImageIcon("/icons/configure.png");
874
875                JMenuItem configI;
876
877                if ( configIcon == null)
878                        configI = new JMenuItem("Settings");
879                else
880                        configI = new JMenuItem("Settings",configIcon);
881                configI.setMnemonic(KeyEvent.VK_S);
882                configI.addActionListener(new ActionListener(){
883
884                        @Override
885                        public void actionPerformed(ActionEvent e) {
886                                String cmd = e.getActionCommand();
887
888                                if ( cmd.equals("Settings")){
889                                        ConfigPDBInstallPanel.showDialog();
890                                }
891                        }
892                });
893                return configI;
894        }
895}