X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPopupMenu.java;h=e2865a89e124b7caf20c6d0ba874bddf743ec05d;hb=075b2506c45bf8ae70e7a3ce3bb29029a21824b1;hp=546ce6514253706217dc0cf5e93d93ddf99231a1;hpb=c35461ed2a5a258cab842e8ccb89b7a973722799;p=jalview.git diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 546ce65..e2865a8 100755 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1,17 +1,17 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) + * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA @@ -30,78 +30,125 @@ import jalview.commands.*; import jalview.datamodel.*; import jalview.io.*; import jalview.schemes.*; +import jalview.util.UrlLink; /** * DOCUMENT ME! - * + * * @author $author$ * @version $Revision$ */ -public class PopupMenu - extends JPopupMenu +public class PopupMenu extends JPopupMenu { JMenu groupMenu = new JMenu(); + JMenuItem groupName = new JMenuItem(); + protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem(); - protected JRadioButtonMenuItem hydrophobicityColour = 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(); + Sequence sequence; + JMenuItem unGroupMenuItem = new JMenuItem(); + JMenuItem outline = new JMenuItem(); + JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem(); + JMenu colourMenu = new JMenu(); + JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem(); + JCheckBoxMenuItem showText = new JCheckBoxMenuItem(); + JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem(); + + JCheckBoxMenuItem displayNonconserved = new JCheckBoxMenuItem(); + JMenu editMenu = new JMenu(); + JMenuItem cut = new JMenuItem(); + JMenuItem copy = new JMenuItem(); + JMenuItem upperCase = new JMenuItem(); + JMenuItem lowerCase = new JMenuItem(); + JMenuItem toggle = new JMenuItem(); + JMenu pdbMenu = new JMenu(); + JMenuItem pdbFromFile = new JMenuItem(); + JMenuItem enterPDB = new JMenuItem(); + JMenuItem discoverPDB = new JMenuItem(); + JMenu outputMenu = new JMenu(); + JMenuItem sequenceFeature = new JMenuItem(); + JMenuItem textColour = new JMenuItem(); + JMenu jMenu1 = new JMenu(); + JMenu structureMenu = new JMenu(); + JMenu viewStructureMenu = new JMenu(); - // JMenu colStructureMenu = new JMenu(); + + // JMenu colStructureMenu = new JMenu(); JMenuItem editSequence = new JMenuItem(); - // JMenuItem annotationMenuItem = new JMenuItem(); + + // JMenuItem annotationMenuItem = new JMenuItem(); /** * Creates a new PopupMenu object. - * - * @param ap DOCUMENT ME! - * @param seq DOCUMENT ME! + * + * @param ap + * DOCUMENT ME! + * @param seq + * DOCUMENT ME! */ public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links) { - /////////////////////////////////////////////////////////// + // ///////////////////////////////////////////////////////// // 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; @@ -122,8 +169,8 @@ public class PopupMenu for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++) { - JMenuItem item = new JMenuItem(jalview.io.FormatAdapter.WRITEABLE_FORMATS[ - i]); + JMenuItem item = new JMenuItem( + jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]); item.addActionListener(new java.awt.event.ActionListener() { @@ -139,8 +186,7 @@ public class PopupMenu try { jbInit(); - } - catch (Exception e) + } catch (Exception e) { e.printStackTrace(); } @@ -151,10 +197,10 @@ public class PopupMenu JMenuItem menuItem; if (seq.getDatasetSequence().getPDBId() != null - && seq.getDatasetSequence().getPDBId().size()>0) + && seq.getDatasetSequence().getPDBId().size() > 0) { - java.util.Enumeration e = seq.getDatasetSequence().getPDBId(). - elements(); + java.util.Enumeration e = seq.getDatasetSequence().getPDBId() + .elements(); while (e.hasMoreElements()) { @@ -169,48 +215,46 @@ public class PopupMenu Vector seqs = new Vector(); for (int i = 0; i < ap.av.alignment.getHeight(); i++) { - Vector pdbs = ap.av.alignment.getSequenceAt(i).getDatasetSequence().getPDBId(); - if(pdbs==null) + Vector pdbs = ap.av.alignment.getSequenceAt(i) + .getDatasetSequence().getPDBId(); + if (pdbs == null) continue; - for(int p=0; p 1) + && ap.av.getSelectionGroup().getSize() > 1) { menuItem = new JMenuItem("Represent Group with " + seq.getName()); menuItem.addActionListener(new java.awt.event.ActionListener() @@ -241,8 +285,8 @@ public class PopupMenu { final int index = ap.av.alignment.findIndex(seq); - if (ap.av.adjustForHiddenSeqs(index) - - ap.av.adjustForHiddenSeqs(index - 1) > 1) + if (ap.av.adjustForHiddenSeqs(index) + - ap.av.adjustForHiddenSeqs(index - 1) > 1) { menuItem = new JMenuItem("Reveal Sequences"); menuItem.addActionListener(new ActionListener() @@ -336,7 +380,7 @@ public class PopupMenu { conservationMenuItem.setSelected(true); } - + displayNonconserved.setSelected(sg.getShowunconserved()); showText.setSelected(sg.getDisplayText()); showColourText.setSelected(sg.getColourText()); showBoxes.setSelected(sg.getDisplayBoxes()); @@ -361,53 +405,110 @@ public class PopupMenu if (links != null && links.size() > 0) { JMenu linkMenu = new JMenu("Link"); - + Vector linkset = new Vector(); for (int i = 0; i < links.size(); i++) { String link = links.elementAt(i).toString(); - final String label = link.substring(0, link.indexOf("|")); - - - if (link.indexOf("$SEQUENCE_ID$") > -1) + UrlLink urlLink = null; + try + { + urlLink = new UrlLink(link); + } catch (Exception foo) + { + jalview.bin.Cache.log.error("Exception for URLLink '" + link + + "'", foo); + continue; + } + ; + if (!urlLink.isValid()) + { + jalview.bin.Cache.log.error(urlLink.getInvalidMessage()); + continue; + } + final String label = urlLink.getLabel(); + if (urlLink.isDynamic()) { - // Substitute SEQUENCE_ID string and any matching database reference accessions - String url_pref = link.substring(link.indexOf("|") + 1, - link.indexOf("$SEQUENCE_ID$")); - - String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13); // collect matching db-refs - DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new String[]{label}); + DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq + .getDBRef(), new String[] + { urlLink.getTarget() }); // collect id string too String id = seq.getName(); - if (id.indexOf("|") > -1) + String descr = seq.getDescription(); + if (descr!=null && descr.length()<1) { - id = id.substring(id.lastIndexOf("|") + 1); + descr = null; } - if (dbr!=null) + if (dbr != null) { - for (int r=0;r -1) { JOptionPane.showMessageDialog(ap, - "Spaces have been converted to \"_\"", - "No spaces allowed in Sequence Name", - JOptionPane.WARNING_MESSAGE); + "Spaces have been converted to \"_\"", + "No spaces allowed in Sequence Name", + JOptionPane.WARNING_MESSAGE); } sequence.setName(dialog.getName().replace(' ', '_')); @@ -1158,15 +1292,16 @@ public class PopupMenu sequence.setDescription(dialog.getDescription()); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() + .getSequences()); } /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ void unGroupMenuItem_actionPerformed() { @@ -1178,14 +1313,15 @@ public class PopupMenu /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ protected void outline_actionPerformed() { SequenceGroup sg = getGroup(); Color col = JColorChooser.showDialog(this, "Select Outline Colour", - Color.BLUE); + Color.BLUE); if (col != null) { @@ -1197,8 +1333,9 @@ public class PopupMenu /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ public void showBoxes_actionPerformed() { @@ -1208,8 +1345,9 @@ public class PopupMenu /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ public void showText_actionPerformed() { @@ -1219,8 +1357,9 @@ public class PopupMenu /** * DOCUMENT ME! - * - * @param e DOCUMENT ME! + * + * @param e + * DOCUMENT ME! */ public void showColourText_actionPerformed() { @@ -1233,15 +1372,14 @@ public class PopupMenu try { jalview.util.BrowserLauncher.openURL(url); - } - catch (Exception ex) + } catch (Exception ex) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Unixers: Couldn't find default web browser." - + - "\nAdd the full path to your browser in Preferences.", - "Web browser not found", - JOptionPane.WARNING_MESSAGE); + JOptionPane + .showInternalMessageDialog( + Desktop.desktop, + "Unixers: Couldn't find default web browser." + + "\nAdd the full path to your browser in Preferences.", + "Web browser not found", JOptionPane.WARNING_MESSAGE); ex.printStackTrace(); } @@ -1253,7 +1391,7 @@ public class PopupMenu if (sg == null || sg.getSize() < 1) { ap.av.hideSequence(new SequenceI[] - {sequence}); + { sequence }); return; } @@ -1278,6 +1416,7 @@ public class PopupMenu } ap.av.hideSequence(hseqs); + ap.av.sendSelection(); } public void copy_actionPerformed() @@ -1297,8 +1436,8 @@ public class PopupMenu if (sg != null) { - int[][] startEnd = ap.av.getVisibleRegionBoundaries( - sg.getStartRes(), sg.getEndRes() + 1); + int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(), + sg.getEndRes() + 1); String description; int caseChange; @@ -1319,15 +1458,14 @@ public class PopupMenu caseChange = ChangeCaseCommand.TO_LOWER; } - ChangeCaseCommand caseCommand = new ChangeCaseCommand( - description, sg.getSequencesAsArray(ap.av.hiddenRepSequences), - startEnd, caseChange - ); + ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg + .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd, + caseChange); ap.alignFrame.addHistoryItem(caseCommand); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() + .getSequences()); } } @@ -1336,36 +1474,33 @@ public class PopupMenu { CutAndPasteTransfer cap = new CutAndPasteTransfer(); cap.setForInput(null); - Desktop.addInternalFrame(cap, - "Alignment output - " + e.getActionCommand(), 600, - 500); + Desktop.addInternalFrame(cap, "Alignment output - " + + e.getActionCommand(), 600, 500); String[] omitHidden = null; - System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens or we simply trust the user wants wysiwig behaviour + System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens + // or we simply trust the user wants + // wysiwig behaviour SequenceGroup sg = ap.av.getSelectionGroup(); ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection()); omitHidden = ap.av.getViewAsString(true); Alignment oal = new Alignment(ap.av.getSequenceSelection()); AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation(); - for (int i=0; i 0) { PDBEntry entry = new PDBEntry(); entry.setId(id.toUpperCase()); - sequence.getDatasetSequence() - .addPDBId(entry); + sequence.getDatasetSequence().addPDBId(entry); } } public void discoverPDB_actionPerformed() { - SequenceI[] sequences = - ap.av.selectionGroup == null ? - new Sequence[]{sequence} - : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment); - new jalview.ws.DBRefFetcher(sequences, - ap.alignFrame).fetchDBRefs(false); + final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[] + { sequence } + : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment)); + Thread discpdb = new Thread(new Runnable() + { + public void run() + { + + new jalview.ws.DBRefFetcher(sequences, ap.alignFrame) + .fetchDBRefs(false); + } + + }); + discpdb.start(); } public void sequenceFeature_actionPerformed() @@ -1454,14 +1596,14 @@ public class PopupMenu seqs[i] = sg.getSequenceAt(i).getDatasetSequence(); int start = sg.getSequenceAt(i).findPosition(sg.getStartRes()); int end = sg.findEndRes(sg.getSequenceAt(i)); - features[i] = new SequenceFeature(null, null, null, start, end, "Jalview"); + features[i] = new SequenceFeature(null, null, null, start, end, + "Jalview"); } - if (ap.seqPanel.seqCanvas.getFeatureRenderer() - .amendFeatures(seqs, features, true, ap)) + if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs, + features, true, ap)) { - ap.alignFrame.showSeqFeatures.setSelected(true); - ap.av.setShowSequenceFeatures(true); + ap.alignFrame.setShowSeqFeatures(true); ap.highlightSearchResults(null); } } @@ -1477,57 +1619,51 @@ public class PopupMenu public void colourByStructure(String pdbid) { - Annotation [] anots = jalview.structure.StructureSelectionManager.getStructureSelectionManager() - .colourSequenceFromStructure(sequence, pdbid); + Annotation[] anots = jalview.structure.StructureSelectionManager + .getStructureSelectionManager().colourSequenceFromStructure( + sequence, pdbid); - AlignmentAnnotation an = new AlignmentAnnotation( - "Structure", "Coloured by "+pdbid, anots); + AlignmentAnnotation an = new AlignmentAnnotation("Structure", + "Coloured by " + pdbid, anots); ap.av.alignment.addAnnotation(an); an.createSequenceMapping(sequence, 0, true); - //an.adjustForAlignment(); - ap.av.alignment.setAnnotationIndex(an,0); + // an.adjustForAlignment(); + ap.av.alignment.setAnnotationIndex(an, 0); ap.adjustAnnotationHeight(); sequence.addAlignmentAnnotation(an); - } + } public void editSequence_actionPerformed(ActionEvent actionEvent) { - SequenceGroup sg = ap.av.getSelectionGroup(); + SequenceGroup sg = ap.av.getSelectionGroup(); - if(sg!=null) - { - if (sequence == null) - sequence = (Sequence) sg.getSequenceAt(0); + if (sg != null) + { + if (sequence == null) + sequence = (Sequence) sg.getSequenceAt(0); - EditNameDialog dialog = new EditNameDialog( - sequence.getSequenceAsString( - sg.getStartRes(), - sg.getEndRes() + 1), - null, - "Edit Sequence ", - null, - "Edit Sequence"); + EditNameDialog dialog = new EditNameDialog(sequence + .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1), + null, "Edit Sequence ", null, "Edit Sequence"); - if (dialog.accept) - { - EditCommand editCommand = new EditCommand( - "Edit Sequences", EditCommand.REPLACE, - dialog.getName().replace(' ', ap.av.getGapCharacter()), - sg.getSequencesAsArray(ap.av.hiddenRepSequences), - sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment - ); + if (dialog.accept) + { + EditCommand editCommand = new EditCommand("Edit Sequences", + EditCommand.REPLACE, dialog.getName().replace(' ', + ap.av.getGapCharacter()), sg + .getSequencesAsArray(ap.av.hiddenRepSequences), sg + .getStartRes(), sg.getEndRes() + 1, ap.av.alignment); - ap.alignFrame.addHistoryItem(editCommand); + ap.alignFrame.addHistoryItem(editCommand); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - } + ap.av.firePropertyChange("alignment", null, ap.av.getAlignment() + .getSequences()); } + } } - }