From f60bd625292b277e70cda0125f04756ac7ca05de Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 30 Aug 2011 15:41:19 +0100 Subject: [PATCH] JAL-915 - ensured that exceptions are not raised in applet or application, and that sequence ID popup menu includes the 'reveal all' item to show all sequences again. --- src/jalview/appletgui/APopupMenu.java | 4 +- src/jalview/appletgui/IdPanel.java | 109 ++++++++++++++++++--------------- src/jalview/gui/IdPanel.java | 2 +- src/jalview/gui/PopupMenu.java | 12 ++-- 4 files changed, 69 insertions(+), 58 deletions(-) diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index c202fd2..5d05ec3 100755 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -169,7 +169,7 @@ public class APopupMenu extends java.awt.PopupMenu implements remove(groupMenu); } - if (links != null && links.size() > 0) + if (seq!=null && links != null && links.size() > 0) { Menu linkMenu = new Menu("Link"); String link; @@ -185,7 +185,7 @@ public class APopupMenu extends java.awt.PopupMenu implements final String target = urlLink.getTarget(); // link.substring(0, // link.indexOf("|")); final String label = urlLink.getLabel(); - if (urlLink.isDynamic()) + if (seq!=null && urlLink.isDynamic()) { // collect matching db-refs diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index 402a8bf..a3955c0 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -89,61 +89,62 @@ public class IdPanel extends Panel implements MouseListener, // look for non-pos features StringBuffer tooltiptext = new StringBuffer(); - - if (sequence.getDescription() != null) + if (sequence != null) { - tooltiptext.append(sequence.getDescription()); - tooltiptext.append("\n"); - } + if (sequence.getDescription() != null) + { + tooltiptext.append(sequence.getDescription()); + tooltiptext.append("\n"); + } - SequenceFeature sf[] = sequence.getSequenceFeatures(); - for (int sl = 0; sf != null && sl < sf.length; sl++) - { - if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) + SequenceFeature sf[] = sequence.getSequenceFeatures(); + for (int sl = 0; sf != null && sl < sf.length; sl++) { - boolean nl = false; - if (sf[sl].getFeatureGroup() != null) - { - tooltiptext.append(sf[sl].getFeatureGroup()); - nl = true; - } - ; - if (sf[sl].getType() != null) - { - tooltiptext.append(" "); - tooltiptext.append(sf[sl].getType()); - nl = true; - } - ; - if (sf[sl].getDescription() != null) - { - tooltiptext.append(" "); - tooltiptext.append(sf[sl].getDescription()); - nl = true; - } - ; - if (sf[sl].getScore() != Float.NaN && sf[sl].getScore() != 0f) - { - tooltiptext.append(" Score = "); - tooltiptext.append(sf[sl].getScore()); - nl = true; - } - ; - if (sf[sl].getStatus() != null && sf[sl].getStatus().length() > 0) - { - tooltiptext.append(" ("); - tooltiptext.append(sf[sl].getStatus()); - tooltiptext.append(")"); - nl = true; - } - ; - if (nl) + if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) { - tooltiptext.append("\n"); + boolean nl = false; + if (sf[sl].getFeatureGroup() != null) + { + tooltiptext.append(sf[sl].getFeatureGroup()); + nl = true; + } + ; + if (sf[sl].getType() != null) + { + tooltiptext.append(" "); + tooltiptext.append(sf[sl].getType()); + nl = true; + } + ; + if (sf[sl].getDescription() != null) + { + tooltiptext.append(" "); + tooltiptext.append(sf[sl].getDescription()); + nl = true; + } + ; + if (sf[sl].getScore() != Float.NaN && sf[sl].getScore() != 0f) + { + tooltiptext.append(" Score = "); + tooltiptext.append(sf[sl].getScore()); + nl = true; + } + ; + if (sf[sl].getStatus() != null && sf[sl].getStatus().length() > 0) + { + tooltiptext.append(" ("); + tooltiptext.append(sf[sl].getStatus()); + tooltiptext.append(")"); + nl = true; + } + ; + if (nl) + { + tooltiptext.append("\n"); + } } } } - if (tooltiptext.length() == 0) { // nothing to display - so clear tooltip if one is visible @@ -196,7 +197,12 @@ public class IdPanel extends Panel implements MouseListener, // DEFAULT LINK IS FIRST IN THE LINK LIST int seq = alignPanel.seqPanel.findSeq(e); - String id = av.getAlignment().getSequenceAt(seq).getName(); + SequenceI sq = av.getAlignment().getSequenceAt(seq); + if (sq==null) + { + return; + } + String id = sq.getName(); String target = null; String url = null; @@ -290,6 +296,7 @@ public class IdPanel extends Panel implements MouseListener, if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq); + // build a new links menu based on the current links + any non-positional // features Vector nlinks = new Vector(); @@ -297,7 +304,7 @@ public class IdPanel extends Panel implements MouseListener, { nlinks.addElement(links.elementAt(l)); } - SequenceFeature sf[] = sq.getSequenceFeatures(); + SequenceFeature sf[] = sq==null ? null:sq.getSequenceFeatures(); for (int sl = 0; sf != null && sl < sf.length; sl++) { if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) @@ -363,7 +370,7 @@ public class IdPanel extends Panel implements MouseListener, end = tmp; lastid = end; } - if (av.getSelectionGroup()==null) + if (av.getSelectionGroup() == null) { av.setSelectionGroup(new SequenceGroup()); } diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 5b689bf..ea8b711 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -314,7 +314,7 @@ public class IdPanel extends JPanel implements MouseListener, // build a new links menu based on the current links + any non-positional // features Vector nlinks = new Vector(Preferences.sequenceURLLinks); - SequenceFeature sf[] = sq.getDatasetSequence().getSequenceFeatures(); + SequenceFeature sf[] = sq==null ? null : sq.getDatasetSequence().getSequenceFeatures(); for (int sl = 0; sf != null && sl < sf.length; sl++) { if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 477136f..ca6b199 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -208,11 +208,11 @@ public class PopupMenu extends JPopupMenu e.printStackTrace(); } + JMenuItem menuItem; if (seq != null) { sequenceMenu.setText(sequence.getName()); - JMenuItem menuItem; if (seq.getDatasetSequence().getPDBId() != null && seq.getDatasetSequence().getPDBId().size() > 0) { @@ -297,7 +297,11 @@ public class PopupMenu extends JPopupMenu }); add(menuItem); } - + } + } + // for the case when no sequences are even visible + if (ap.av.hasHiddenRows) { + { menuItem = new JMenuItem("Reveal All"); menuItem.addActionListener(new ActionListener() { @@ -318,7 +322,7 @@ public class PopupMenu extends JPopupMenu SequenceGroup sg = ap.av.getSelectionGroup(); - if (sg != null) + if (sg != null&& sg.getSize()>0) { groupName.setText("Name: "+sg.getName()); groupName.setText("Edit name and description of current group."); @@ -431,7 +435,7 @@ public class PopupMenu extends JPopupMenu structureMenu.setVisible(false); } - if (links != null && links.size() > 0) + if (seq !=null && links != null && links.size() > 0) { JMenu linkMenu = new JMenu("Link"); -- 1.7.10.2