From 00506d5a86e6f2c09529134ef8ddbf114656b681 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 14 Dec 2004 11:24:26 +0000 Subject: [PATCH] New class for defining groups and selections --- src/jalview/gui/PopupMenu.java | 520 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 520 insertions(+) create mode 100755 src/jalview/gui/PopupMenu.java diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java new file mode 100755 index 0000000..4928189 --- /dev/null +++ b/src/jalview/gui/PopupMenu.java @@ -0,0 +1,520 @@ +package jalview.gui; + +import jalview.datamodel.*; +import jalview.analysis.*; +import jalview.schemes.*; +import javax.swing.*; +import java.awt.event.*; + + +public class PopupMenu extends JPopupMenu +{ + JMenuItem residueMenu = new JMenuItem(); + JMenu groupMenu = new JMenu(); + JMenuItem copyGroup = new JMenuItem(); + JMenuItem moveGroup = new JMenuItem(); + JMenuItem deleteSequences = new JMenuItem(); + JMenuItem analyze = new JMenuItem(); + JMenu defineMenu = new JMenu(); + JMenuItem groupName = new JMenuItem(); + JMenuItem groupAnnotation = new JMenuItem(); + protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem abovePIDColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem(); + JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(); + protected JMenuItem conservationColourIncMenuItem = new JMenuItem(); + protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem(); + + + AlignViewport av; + SeqPanel seqPanel; + + public PopupMenu(AlignViewport av, SeqPanel sp) + { + this.av = av; + seqPanel = sp; + + ButtonGroup colours = new ButtonGroup(); + colours.add(noColourmenuItem); + colours.add(clustalColour); + colours.add(zappoColour); + colours.add(taylorColour); + colours.add(hydrophobicityColour); + colours.add(helixColour); + colours.add(strandColour); + colours.add(turnColour); + colours.add(buriedColour); + colours.add(abovePIDColour); + colours.add(userDefinedColour); + colours.add(PIDColour); + colours.add(BLOSUM62Colour); + + try + { + jbInit(); + } + catch(Exception e) + { + e.printStackTrace(); + } + + SequenceGroup sg = av.getRubberbandGroup(); + groupName.setText( sg.getName() ); + } + private void jbInit() throws Exception + { + residueMenu.setText("Residue"); + groupMenu.setText("Group"); + copyGroup.setText("Copy region to new Alignment"); + copyGroup.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + copyGroup_actionPerformed(e); + } + }); + moveGroup.setText("Move sequences to new Alignment"); + moveGroup.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + moveGroup_actionPerformed(e); + } + }); + deleteSequences.setText("Delete sequences"); + deleteSequences.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + deleteSequences_actionPerformed(e); + } + }); + analyze.setText("Analyze"); + analyze.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + analyze_actionPerformed(e); + } + }); + defineMenu.setText("Define"); + groupName.setText("Name"); + groupName.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + groupName_actionPerformed(e); + } + }); + groupAnnotation.setText("Annotation"); + groupAnnotation.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + groupAnnotation_actionPerformed(e); + } + }); + add(groupMenu); + add(residueMenu); + groupMenu.add(defineMenu); + groupMenu.addSeparator(); + groupMenu.add(copyGroup); + groupMenu.add(moveGroup); + groupMenu.add(deleteSequences); + groupMenu.addSeparator(); + groupMenu.add(analyze); + defineMenu.add(groupName); + defineMenu.add(groupAnnotation); + defineMenu.addSeparator(); + defineMenu.add(noColourmenuItem); + defineMenu.add(clustalColour); + defineMenu.add(zappoColour); + defineMenu.add(taylorColour); + defineMenu.add(hydrophobicityColour); + defineMenu.add(helixColour); + defineMenu.add(strandColour); + defineMenu.add(turnColour); + defineMenu.add(buriedColour); + defineMenu.add(userDefinedColour); + defineMenu.addSeparator(); + defineMenu.add(conservationMenuItem); + defineMenu.add(conservationColourIncMenuItem); + defineMenu.addSeparator(); + defineMenu.add(abovePIDColour); + defineMenu.add(PIDColour); + defineMenu.add(BLOSUM62Colour); + + noColourmenuItem.setText("None"); + noColourmenuItem.setSelected(true); + noColourmenuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + noColourmenuItem_actionPerformed(e); + } + }); + + clustalColour.setEnabled(false); + clustalColour.setSelected(false); + clustalColour.setText("Clustalx colours"); + clustalColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + clustalColour_actionPerformed(e); + } + }); + zappoColour.setText("Zappo colour scheme"); + zappoColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + zappoColour_actionPerformed(e); + } + }); + taylorColour.setText("Taylor colour scheme"); + taylorColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + taylorColour_actionPerformed(e); + } + }); + hydrophobicityColour.setText("By hydrophobicity"); + hydrophobicityColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + hydrophobicityColour_actionPerformed(e); + } + }); + helixColour.setText("Helix propensity"); + helixColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + helixColour_actionPerformed(e); + } + }); + strandColour.setText("Strand propensity"); + strandColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + strandColour_actionPerformed(e); + } + }); + turnColour.setText("Turn propensity"); + turnColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + turnColour_actionPerformed(e); + } + }); + buriedColour.setText("Buried index"); + buriedColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + buriedColour_actionPerformed(e); + } + }); + abovePIDColour.setEnabled(false); + abovePIDColour.setText("Above PID threshold only"); + abovePIDColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + abovePIDColour_actionPerformed(e); + } + }); + userDefinedColour.setText("User defined colours"); + userDefinedColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + userDefinedColour_actionPerformed(e); + } + }); + PIDColour.setEnabled(false); + PIDColour.setText("By PID"); + PIDColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + PIDColour_actionPerformed(e); + } + }); + BLOSUM62Colour.setText("By BLOSUM62 score"); + BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + BLOSUM62Colour_actionPerformed(e); + } + }); + conservationMenuItem.setText("By conservation"); + conservationMenuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + conservationMenuItem_actionPerformed(e); + } + }); + + conservationColourIncMenuItem.setEnabled(false); + conservationColourIncMenuItem.setText("Conservation Colour Increment"); + conservationColourIncMenuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + conservationColourIncMenuItem_actionPerformed(e); + } + }); + + + } + + void refresh() + { + seqPanel.seqCanvas.paintFlag=true; + seqPanel.repaint(); + } + + protected void clustalColour_actionPerformed(ActionEvent e) + { + + } + + protected void zappoColour_actionPerformed(ActionEvent e) + { + getGroup().cs = new ZappoColourScheme(); + refresh(); + } + + protected void taylorColour_actionPerformed(ActionEvent e) + { + getGroup().cs = new TaylorColourScheme(); + refresh(); + } + + + protected void hydrophobicityColour_actionPerformed(ActionEvent e) + { + getGroup().cs = new HydrophobicColourScheme(); + refresh(); + } + + protected void helixColour_actionPerformed(ActionEvent e) + { + getGroup().cs = new HelixColourScheme(); + refresh(); + } + + protected void strandColour_actionPerformed(ActionEvent e) + { + getGroup().cs = new StrandColourScheme(); + refresh(); + } + + protected void turnColour_actionPerformed(ActionEvent e) + { + getGroup().cs = new TurnColourScheme(); + refresh(); + } + + protected void buriedColour_actionPerformed(ActionEvent e) + { + getGroup().cs = new BuriedColourScheme(); + refresh(); + } + + + protected void conservationColourIncMenuItem_actionPerformed(ActionEvent e) + { + +} +/* +public void conservationColourIncMenuItem_actionPerformed(ActionEvent e) +{ +ConservationIncrementPanel cip = new ConservationIncrementPanel(viewport, alignPanel); +JInternalFrame frame = new JInternalFrame(); +frame.setContentPane(cip); +Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400,90); +frame.setMaximizable(false); + + }*/ + + + protected void abovePIDColour_actionPerformed(ActionEvent e) + { + + } + + + protected void userDefinedColour_actionPerformed(ActionEvent e) + { + + } + + protected void PIDColour_actionPerformed(ActionEvent e) + { + + } + + protected void BLOSUM62Colour_actionPerformed(ActionEvent e) + { + getGroup().cs = new Blosum62ColourScheme(av); + refresh(); + } + + + protected void noColourmenuItem_actionPerformed(ActionEvent e) + { + getGroup().cs = null; + refresh(); + } + + protected void conservationMenuItem_actionPerformed(ActionEvent e) + { + SequenceGroup sg = getGroup(); + + Alignment al = (Alignment)av.getAlignment(); + Conservation c = new Conservation("Group", al.cons, + ResidueProperties.propHash, 3, sg.sequences, sg.getStartRes(), + sg.getEndRes() ); + + c.calculate(); + c.verdict(false, 100); + ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs); + + sg.cs = ccs; + + refresh(); + } + + protected void groupAnnotation_actionPerformed(ActionEvent e) + { + + } + + protected void groupName_actionPerformed(ActionEvent e) + { + SequenceGroup sg = getGroup(); + String reply = JOptionPane.showInternalInputDialog(Desktop.desktop, "Enter new group name", "Edit group name", JOptionPane.QUESTION_MESSAGE); + if(reply==null) + return; + + sg.setName(reply); + groupName.setText(reply); + } + /* public void deleteSelectedMenuItem_actionPerformed(ActionEvent e) + { + addHistoryItem("delete selection"); + + for (int i=0;i < viewport.getSelection().size(); i++) + viewport.getAlignment().deleteSequence(viewport.getSelection().sequenceAt(i)); + + viewport.getSelection().clear(); + viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getHeight()); + alignPanel.RefreshPanels(); + } + + public void moveSelectedMenuItem_actionPerformed(ActionEvent e) + { + copySelectedMenuItem_actionPerformed(null); + deleteSelectedMenuItem_actionPerformed(null); + alignPanel.repaint(); + } + + public void copySelectedMenuItem_actionPerformed(ActionEvent e) + { + if(viewport.getSelection().size()==0) + return; + + SequenceI[] s = new Sequence[viewport.getSelection().size()]; + for (int i=0; i < viewport.getSelection().size(); i++) { + s[i] = new Sequence(viewport.getSelection().sequenceAt(i)); + } + AlignFrame af = new AlignFrame(new Alignment(s)); + int newHeight = s.length * af.viewport.getCharHeight() + 200; + if(newHeight>500) + newHeight=500; + Desktop.addInternalFrame(af, "Copied sequences", 700,newHeight); + } +*/ + protected void copyGroup_actionPerformed(ActionEvent e) + { + SequenceGroup sg = av.getRubberbandGroup(); + + SequenceI[] s = new Sequence[sg.sequences.size()]; + for (int i=0; i < sg.sequences.size(); i++) + { + s[i] = new Sequence( sg.getSequenceAt(i)); + s[i].setSequence( s[i].getSequence(sg.getStartRes(), sg.getEndRes()+1) ); + } + AlignFrame af = new AlignFrame(new Alignment(s)); + int newHeight = s.length * af.viewport.getCharHeight() + 200; + if (newHeight > 500) + newHeight = 500; + Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight); + } + + protected void moveGroup_actionPerformed(ActionEvent e) + { + + } + + protected void deleteSequences_actionPerformed(ActionEvent e) + { + SequenceGroup sg = av.getRubberbandGroup(); + for (int i=0;i < sg.sequences.size(); i++) + av.getAlignment().deleteSequence(sg.getSequenceAt(i)); + + av.alignment.deleteGroup(sg); + av.resetSeqLimits(seqPanel.seqCanvas.getHeight()); + seqPanel.parent.RefreshPanels(); + + } + + protected void analyze_actionPerformed(ActionEvent e) + { + CutAndPasteTransfer cap = new CutAndPasteTransfer(false); + JInternalFrame frame = new JInternalFrame(); + cap.formatForOutput(); + frame.setContentPane(cap); + Desktop.addInternalFrame(frame, "Analyze this - ", 400, 300); + SequenceGroup sg = getGroup(); + StringBuffer sb = new StringBuffer(); + + for(int i=0; i