package jalview.gui; import jalview.datamodel.*; import jalview.analysis.*; import jalview.schemes.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import jalview.io.*; import MCview.*; public class PopupMenu extends JPopupMenu { JMenu groupMenu = new JMenu(); 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 JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem(); protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(); protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem(); protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem(); JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(); protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem(); AlignmentPanel ap; JMenu sequenceMenu = new JMenu(); JMenuItem sequenceName = new JMenuItem(); JMenu residueMenu = new JMenu(); JMenuItem annotateResidue = new JMenuItem(); Sequence sequence; JMenuItem unGroupMenuItem = new JMenuItem(); JMenuItem pdbMenuItem = new JMenuItem(); JMenuItem outline = new JMenuItem(); public PopupMenu(AlignmentPanel ap, Sequence seq) { /////////////////////////////////////////////////////////// // If this is activated from the sequence panel, the user may want to // edit or annotate a particular residue. Therefore display the residue menu // // If from the IDPanel, we must display the sequence menu ////////////////////////////////////////////////////////// this.ap = ap; sequence = seq; 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 = ap.av.getSelectionGroup(); if(sg!=null) { groupName.setText(sg.getName()); if(sg.cs instanceof ZappoColourScheme) zappoColour.setSelected(true); else if(sg.cs instanceof TaylorColourScheme) taylorColour.setSelected(true); else if (sg.cs instanceof PIDColourScheme) PIDColour.setSelected(true); else if (sg.cs instanceof Blosum62ColourScheme) BLOSUM62Colour.setSelected(true); else if (sg.cs instanceof UserColourScheme) userDefinedColour.setSelected(true); else if (sg.cs instanceof HydrophobicColourScheme) hydrophobicityColour.setSelected(true); else if (sg.cs instanceof HelixColourScheme) helixColour.setSelected(true); else if (sg.cs instanceof StrandColourScheme) strandColour.setSelected(true); else if (sg.cs instanceof TurnColourScheme) turnColour.setSelected(true); else if (sg.cs instanceof BuriedColourScheme) buriedColour.setSelected(true); else if (sg.cs instanceof ClustalxColourScheme) clustalColour.setSelected(true); else noColourmenuItem.setSelected(true); if (sg.cs instanceof ConservationColourScheme) conservationMenuItem.setSelected(true); } if(seq!=null) residueMenu.setVisible(false); else sequenceMenu.setVisible(false); } private void jbInit() throws Exception { groupMenu.setText("Group"); 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.setEnabled(false); groupAnnotation.setText("Annotation"); groupAnnotation.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { groupAnnotation_actionPerformed(e); } }); sequenceMenu.setText("Sequence"); sequenceName.setText("Edit name"); sequenceName.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { sequenceName_actionPerformed(e); } }); residueMenu.setText("Residue"); annotateResidue.setEnabled(false); annotateResidue.setActionCommand("annotate residue"); annotateResidue.setText("annotate residue???"); PIDColour.setFocusPainted(false); unGroupMenuItem.setText("Remove Group"); unGroupMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { unGroupMenuItem_actionPerformed(e); } }); pdbMenuItem.setText("View PDB structure"); pdbMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { pdbMenuItem_actionPerformed(e); } }); outline.setText("Border colour"); outline.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { outline_actionPerformed(e); } }); add(groupMenu); this.add(sequenceMenu); this.add(residueMenu); groupMenu.add(defineMenu); groupMenu.add(unGroupMenuItem); groupMenu.addSeparator(); groupMenu.add(analyze); defineMenu.add(groupName); defineMenu.add(groupAnnotation); defineMenu.addSeparator(); defineMenu.add(outline); 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.add(PIDColour); defineMenu.add(BLOSUM62Colour); defineMenu.addSeparator(); defineMenu.add(abovePIDColour); defineMenu.add(conservationMenuItem); sequenceMenu.add(sequenceName); sequenceMenu.add(pdbMenuItem); residueMenu.add(annotateResidue); noColourmenuItem.setText("None"); noColourmenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { noColourmenuItem_actionPerformed(e); } }); 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.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.setText("Percentage Identity"); PIDColour.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { PIDColour_actionPerformed(e); } }); BLOSUM62Colour.setText("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); } }); } void refresh() { SequenceGroup sg = getGroup(); SuperGroup superG = ap.av.alignment.getSuperGroup( sg ); if( superG !=null) superG.setSuperGroupProperties( sg ); ap.seqPanel.repaint(); } protected void clustalColour_actionPerformed(ActionEvent e) { SequenceGroup sg = getGroup(); sg.cs = new ClustalxColourScheme(sg.sequences, ap.av.alignment.getWidth()); refresh(); } 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 abovePIDColour_actionPerformed(ActionEvent e) { if(abovePIDColour.isSelected()) { Desktop.setPIDSliderSource(ap, getGroup().cs, getGroup().getName()); refresh(); } else // remove PIDColouring { ColourSchemeI cs = getGroup().cs; ResidueColourScheme rcs = (ResidueColourScheme)cs; rcs.setThreshold(0); getGroup().cs = rcs; refresh(); } } protected void userDefinedColour_actionPerformed(ActionEvent e) { JInternalFrame frame = new JInternalFrame(); UserDefinedColours chooser = new UserDefinedColours( frame, ap, getGroup()); frame.setContentPane(chooser); Desktop.addInternalFrame(frame,"User defined colours ("+getGroup().getName()+")", 450,540 ); frame.setResizable(false); frame.setIconifiable(false); frame.setMaximizable(false); } protected void PIDColour_actionPerformed(ActionEvent e) { } protected void BLOSUM62Colour_actionPerformed(ActionEvent e) { getGroup().cs = new Blosum62ColourScheme(ap.av); refresh(); } protected void noColourmenuItem_actionPerformed(ActionEvent e) { getGroup().cs = null; refresh(); } protected void conservationMenuItem_actionPerformed(ActionEvent e) { SequenceGroup sg = getGroup(); if(conservationMenuItem.isSelected()) { Conservation c = new Conservation("Group", ResidueProperties.propHash, 3, sg.sequences, 0, ap.av.alignment.getWidth()); c.calculate(); c.verdict(false, 100); ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs); sg.cs = ccs; Desktop.setConservationSliderSource(ap, ccs, sg.getName()); } else // remove ConservationColouring { ConservationColourScheme ccs = (ConservationColourScheme)sg.cs; sg.cs = ccs.cs; } 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); } 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