X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FIdPanel.java;h=15e269c5a91b64c2269103088d6b8a8cf68b1060;hb=106a3890f956e2aa7780b2985f4326655912a558;hp=4e7c9cd3de1961cfc0800fb3020adaa6a208aaee;hpb=a45bb4b4b3f6ce4067fc94acbfc546637fb30b06;p=jalview.git diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index 4e7c9cd..15e269c 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -20,7 +20,6 @@ */ package jalview.appletgui; -import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -35,12 +34,12 @@ import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Vector; -public class IdPanel extends Panel implements MouseListener, - MouseMotionListener +public class IdPanel extends Panel + implements MouseListener, MouseMotionListener { protected IdCanvas idCanvas; @@ -57,11 +56,11 @@ public class IdPanel extends Panel implements MouseListener, UrlProviderI urlProvider = null; - public IdPanel(AlignViewport av, AlignmentPanel parent) + public IdPanel(AlignViewport viewport, AlignmentPanel parent) { - this.av = av; + this.av = viewport; alignPanel = parent; - idCanvas = new IdCanvas(av); + idCanvas = new IdCanvas(viewport); setLayout(new BorderLayout()); add(idCanvas, BorderLayout.CENTER); idCanvas.addMouseListener(this); @@ -71,21 +70,25 @@ public class IdPanel extends Panel implements MouseListener, // TODO: add in group link parameter // make a list of label,url pairs - HashMap urlList = new HashMap(); - if (av.applet != null) + HashMap urlList = new HashMap<>(); + if (viewport.applet != null) { for (int i = 1; i < 10; i++) { - label = av.applet.getParameter("linkLabel_" + i); - url = av.applet.getParameter("linkURL_" + i); + label = viewport.applet.getParameter("linkLabel_" + i); + url = viewport.applet.getParameter("linkURL_" + i); - urlList.put(label, url); + // only add non-null parameters + if (label != null) + { + urlList.put(label, url); + } } if (!urlList.isEmpty()) { // set default as first entry in list - String defaultUrl = av.applet.getParameter("linkLabel_1"); + String defaultUrl = viewport.applet.getParameter("linkLabel_1"); UrlProviderFactoryI factory = new AppletUrlProviderFactory( defaultUrl, urlList); urlProvider = factory.createUrlProvider(); @@ -102,64 +105,57 @@ public class IdPanel extends Panel implements MouseListener, SequenceI sequence = av.getAlignment().getSequenceAt(seq); - // look for non-pos features StringBuffer tooltiptext = new StringBuffer(); - if (sequence != null) + if (sequence == null) + { + return; + } + if (sequence.getDescription() != null) { - if (sequence.getDescription() != null) + tooltiptext.append(sequence.getDescription()); + tooltiptext.append("\n"); + } + + for (SequenceFeature sf : sequence.getFeatures() + .getNonPositionalFeatures()) + { + boolean nl = false; + if (sf.getFeatureGroup() != null) { - tooltiptext.append(sequence.getDescription()); - tooltiptext.append("\n"); + tooltiptext.append(sf.getFeatureGroup()); + nl = true; } - - SequenceFeature sf[] = sequence.getSequenceFeatures(); - for (int sl = 0; sf != null && sl < sf.length; sl++) + if (sf.getType() != null) { - if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) - { - 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 (!Float.isNaN(sf[sl].getScore()) && 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"); - } - } + tooltiptext.append(" "); + tooltiptext.append(sf.getType()); + nl = true; + } + if (sf.getDescription() != null) + { + tooltiptext.append(" "); + tooltiptext.append(sf.getDescription()); + nl = true; + } + if (!Float.isNaN(sf.getScore()) && sf.getScore() != 0f) + { + tooltiptext.append(" Score = "); + tooltiptext.append(sf.getScore()); + nl = true; + } + if (sf.getStatus() != null && sf.getStatus().length() > 0) + { + tooltiptext.append(" ("); + tooltiptext.append(sf.getStatus()); + tooltiptext.append(")"); + nl = true; + } + if (nl) + { + tooltiptext.append("\n"); } } + if (tooltiptext.length() == 0) { // nothing to display - so clear tooltip if one is visible @@ -173,13 +169,14 @@ public class IdPanel extends Panel implements MouseListener, } if (tooltip == null) { - tooltip = new Tooltip(sequence.getDisplayId(true) + "\n" - + tooltiptext.toString(), idCanvas); + tooltip = new Tooltip( + sequence.getDisplayId(true) + "\n" + tooltiptext.toString(), + idCanvas); } else { - tooltip.setTip(sequence.getDisplayId(true) + "\n" - + tooltiptext.toString()); + tooltip.setTip( + sequence.getDisplayId(true) + "\n" + tooltiptext.toString()); } tooltiptext = null; } @@ -201,7 +198,7 @@ public class IdPanel extends Panel implements MouseListener, } lastid = seq; - alignPanel.paintAlignment(false); + alignPanel.paintAlignment(false, false); } @Override @@ -222,8 +219,12 @@ public class IdPanel extends Panel implements MouseListener, String id = sq.getName(); // get the default url with the sequence details filled in - String url = urlProvider.getDefaultUrl(id); - String target = urlProvider.getDefaultTarget(id); + if (urlProvider == null) + { + return; + } + String url = urlProvider.getPrimaryUrl(id); + String target = urlProvider.getPrimaryTarget(id); try { alignPanel.alignFrame.showURL(url, target); @@ -250,13 +251,13 @@ public class IdPanel extends Panel implements MouseListener, return; } - if (mouseDragging && e.getY() < 0 && av.getStartSeq() > 0) + if (mouseDragging && e.getY() < 0 && av.getRanges().getStartSeq() > 0) { scrollThread = new ScrollThread(true); } if (mouseDragging && e.getY() >= getSize().height - && av.getAlignment().getHeight() > av.getEndSeq()) + && av.getAlignment().getHeight() > av.getRanges().getEndSeq()) { scrollThread = new ScrollThread(false); } @@ -278,25 +279,32 @@ public class IdPanel extends Panel implements MouseListener, int seq = alignPanel.seqPanel.findSeq(e); - if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) + if ((e.getModifiers() + & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - Sequence sq = (Sequence) av.getAlignment().getSequenceAt(seq); + SequenceI sq = av.getAlignment().getSequenceAt(seq); - // build a new links menu based on the current links + any non-positional - // features - Vector nlinks = urlProvider.getLinksForMenu(); + /* + * build a new links menu based on the current links + * and any non-positional features + */ + List nlinks; + if (urlProvider != null) + { + nlinks = urlProvider.getLinksForMenu(); + } + else + { + nlinks = new ArrayList<>(); + } - SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures(); - for (int sl = 0; sf != null && sl < sf.length; sl++) + for (SequenceFeature sf : sq.getFeatures().getNonPositionalFeatures()) { - if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) + if (sf.links != null) { - if (sf[sl].links != null && sf[sl].links.size() > 0) + for (String link : sf.links) { - for (int l = 0, lSize = sf[sl].links.size(); l < lSize; l++) - { - nlinks.addElement(sf[sl].links.elementAt(l)); - } + nlinks.add(link); } } } @@ -308,8 +316,8 @@ public class IdPanel extends Panel implements MouseListener, } if ((av.getSelectionGroup() == null) - || ((!jalview.util.Platform.isControlDown(e) && !e - .isShiftDown()) && av.getSelectionGroup() != null)) + || ((!jalview.util.Platform.isControlDown(e) + && !e.isShiftDown()) && av.getSelectionGroup() != null)) { av.setSelectionGroup(new SequenceGroup()); av.getSelectionGroup().setStartRes(0); @@ -325,7 +333,7 @@ public class IdPanel extends Panel implements MouseListener, selectSeq(seq); } - alignPanel.paintAlignment(false); + alignPanel.paintAlignment(false, false); } void selectSeq(int seq) @@ -358,8 +366,8 @@ public class IdPanel extends Panel implements MouseListener, } for (int i = start; i <= end; i++) { - av.getSelectionGroup().addSequence( - av.getAlignment().getSequenceAt(i), i == end); + av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), + i == end); } } @@ -395,9 +403,10 @@ public class IdPanel extends Panel implements MouseListener, int index = av.getAlignment().findIndex(list.get(0)); // do we need to scroll the panel? - if (av.getStartSeq() > index || av.getEndSeq() < index) + if (av.getRanges().getStartSeq() > index + || av.getRanges().getEndSeq() < index) { - alignPanel.setScrollValues(av.getStartRes(), index); + av.getRanges().setStartSeq(index); } } @@ -408,9 +417,9 @@ public class IdPanel extends Panel implements MouseListener, boolean up = true; - public ScrollThread(boolean up) + public ScrollThread(boolean isUp) { - this.up = up; + this.up = isUp; start(); } @@ -425,13 +434,13 @@ public class IdPanel extends Panel implements MouseListener, running = true; while (running) { - if (alignPanel.scrollUp(up)) + if (av.getRanges().scrollUp(up)) { // scroll was ok, so add new sequence to selection - int seq = av.getStartSeq(); + int seq = av.getRanges().getStartSeq(); if (!up) { - seq = av.getEndSeq(); + seq = av.getRanges().getEndSeq(); } if (seq < lastid) @@ -450,7 +459,7 @@ public class IdPanel extends Panel implements MouseListener, running = false; } - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); try { Thread.sleep(100);