From: gmungoc Date: Thu, 14 Apr 2016 12:30:03 +0000 (+0100) Subject: JAL-1421 typed map / lists, explicit imports, method refactoring X-Git-Tag: Release_2_10_0~249^2~21 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=2672f9a72ffb8ffaf4b48a08e64de7f3d83ce061 JAL-1421 typed map / lists, explicit imports, method refactoring --- diff --git a/src/jalview/appletgui/FeatureSettings.java b/src/jalview/appletgui/FeatureSettings.java index 584a69a..40a2ce5 100755 --- a/src/jalview/appletgui/FeatureSettings.java +++ b/src/jalview/appletgui/FeatureSettings.java @@ -59,8 +59,8 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Arrays; import java.util.Enumeration; -import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.Vector; public class FeatureSettings extends Panel implements ItemListener, @@ -201,7 +201,8 @@ public class FeatureSettings extends Panel implements ItemListener, 60); } - protected void popupSort(final MyCheckbox check, final Hashtable minmax, + protected void popupSort(final MyCheckbox check, + final Map minmax, int x, int y) { final String type = check.type; @@ -239,7 +240,7 @@ public class FeatureSettings extends Panel implements ItemListener, men.add(dens); if (minmax != null) { - final Object typeMinMax = minmax.get(type); + final float[][] typeMinMax = minmax.get(type); /* * final java.awt.CheckboxMenuItem chb = new * java.awt.CheckboxMenuItem("Vary Height"); // this is broken at the @@ -252,7 +253,7 @@ public class FeatureSettings extends Panel implements ItemListener, * * }); men.add(chb); */ - if (typeMinMax != null && ((float[][]) typeMinMax)[0] != null) + if (typeMinMax != null && typeMinMax[0] != null) { // graduated colourschemes for those where minmax exists for the // positional features @@ -338,7 +339,7 @@ public class FeatureSettings extends Panel implements ItemListener, { SequenceFeature[] tmpfeatures; String group = null, type; - Vector visibleChecks = new Vector(); + Vector visibleChecks = new Vector(); AlignmentI alignment = av.getAlignment(); for (int i = 0; i < alignment.getHeight(); i++) { @@ -404,7 +405,7 @@ public class FeatureSettings extends Panel implements ItemListener, // now add checkboxes which should be visible, // if they have not already been added - Enumeration en = visibleChecks.elements(); + Enumeration en = visibleChecks.elements(); while (en.hasMoreElements()) { diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 6ca0769..c2be241 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -58,6 +58,7 @@ import java.util.Arrays; import java.util.Hashtable; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.Vector; @@ -277,7 +278,8 @@ public class FeatureSettings extends JPanel implements } protected void popupSort(final int selectedRow, final String type, - final Object typeCol, final Hashtable minmax, int x, int y) + final Object typeCol, final Map minmax, int x, + int y) { JPopupMenu men = new JPopupMenu(MessageManager.formatMessage( "label.settings_for_param", new String[] { type })); @@ -312,7 +314,7 @@ public class FeatureSettings extends JPanel implements men.add(dens); if (minmax != null) { - final Object typeMinMax = minmax.get(type); + final float[][] typeMinMax = minmax.get(type); /* * final JCheckBoxMenuItem chb = new JCheckBoxMenuItem("Vary Height"); // * this is broken at the moment and isn't that useful anyway! @@ -327,7 +329,7 @@ public class FeatureSettings extends JPanel implements * * men.add(chb); */ - if (typeMinMax != null && ((float[][]) typeMinMax)[0] != null) + if (typeMinMax != null && typeMinMax[0] != null) { // if (table.getValueAt(row, column)); // graduated colourschemes for those where minmax exists for the diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index bbffbab..eb5faa1 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -321,24 +321,28 @@ public class IdPanel extends JPanel implements MouseListener, 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(Preferences.sequenceURLLinks); - SequenceFeature sf[] = sq == null ? null : sq.getSequenceFeatures(); - for (int sl = 0; sf != null && sl < sf.length; sl++) + Vector nlinks = new Vector( + Preferences.sequenceURLLinks); + SequenceFeature sfs[] = sq == null ? null : sq.getSequenceFeatures(); + if (sfs != null) { - if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) + for (SequenceFeature sf : sfs) { - if (sf[sl].links != null && sf[sl].links.size() > 0) + if (sf.begin == sf.end && sf.begin == 0) { - for (int l = 0, lSize = sf[sl].links.size(); l < lSize; l++) + if (sf.links != null && sf.links.size() > 0) { - nlinks.addElement(sf[sl].links.elementAt(l)); + for (int l = 0, lSize = sf.links.size(); l < lSize; l++) + { + nlinks.addElement(sf.links.elementAt(l)); + } } } } } - jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel, sq, - nlinks, new Vector(Preferences.getGroupURLLinks())); + PopupMenu pop = new PopupMenu(alignPanel, sq, nlinks, + Preferences.getGroupURLLinks()); pop.show(this, e.getX(), e.getY()); return; diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index ab8c398..1e0772a 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -24,6 +24,7 @@ import jalview.analysis.AAFrequency; import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; import jalview.analysis.Conservation; +import jalview.bin.Cache; import jalview.commands.ChangeCaseCommand; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; @@ -54,6 +55,7 @@ import jalview.schemes.TaylorColourScheme; import jalview.schemes.TurnColourScheme; import jalview.schemes.UserColourScheme; import jalview.schemes.ZappoColourScheme; +import jalview.util.DBRefUtils; import jalview.util.GroupUrlLink; import jalview.util.GroupUrlLink.UrlStringTooLongException; import jalview.util.MessageManager; @@ -62,6 +64,7 @@ import jalview.util.UrlLink; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Hashtable; @@ -90,8 +93,6 @@ public class PopupMenu extends JPopupMenu { private static final String ALL_ANNOTATIONS = "All"; - private static final String COMMA = ","; - JMenu groupMenu = new JMenu(); JMenuItem groupName = new JMenuItem(); @@ -216,7 +217,7 @@ public class PopupMenu extends JPopupMenu * @param seq * DOCUMENT ME! */ - public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links) + public PopupMenu(final AlignmentPanel ap, Sequence seq, List links) { this(ap, seq, links, null); } @@ -229,7 +230,7 @@ public class PopupMenu extends JPopupMenu * @param groupLinks */ public PopupMenu(final AlignmentPanel ap, final SequenceI seq, - Vector links, Vector groupLinks) + List links, List groupLinks) { // ///////////////////////////////////////////////////////// // If this is activated from the sequence panel, the user may want to @@ -608,124 +609,130 @@ public class PopupMenu extends JPopupMenu if (links != null && links.size() > 0) { + addFeatureLinks(seq, links); + } + } - JMenu linkMenu = new JMenu(MessageManager.getString("action.link")); - Vector linkset = new Vector(); - for (int i = 0; i < links.size(); i++) + /** + * Adds a 'Link' menu item with a sub-menu item for each hyperlink provided. + * + * @param seq + * @param links + */ + void addFeatureLinks(final SequenceI seq, List links) + { + JMenu linkMenu = new JMenu(MessageManager.getString("action.link")); + List linkset = new ArrayList(); + for (String link : links) + { + UrlLink urlLink = null; + try { - String link = links.elementAt(i).toString(); - 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()) + urlLink = new UrlLink(link); + } catch (Exception foo) + { + Cache.log.error("Exception for URLLink '" + link + "'", foo); + continue; + } + ; + if (!urlLink.isValid()) + { + Cache.log.error(urlLink.getInvalidMessage()); + continue; + } + final String label = urlLink.getLabel(); + if (seq != null && urlLink.isDynamic()) + { + + // collect matching db-refs + DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(), + new String[] { urlLink.getTarget() }); + // collect id string too + String id = seq.getName(); + String descr = seq.getDescription(); + if (descr != null && descr.length() < 1) { - jalview.bin.Cache.log.error(urlLink.getInvalidMessage()); - continue; + descr = null; } - final String label = urlLink.getLabel(); - if (seq != null && urlLink.isDynamic()) - { - // collect matching db-refs - DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs( - seq.getDBRefs(), new String[] { urlLink.getTarget() }); - // collect id string too - String id = seq.getName(); - String descr = seq.getDescription(); - if (descr != null && descr.length() < 1) - { - descr = null; - } - - if (dbr != null) + if (dbr != null) + { + for (int r = 0; r < dbr.length; r++) { - for (int r = 0; r < dbr.length; r++) + if (id != null && dbr[r].getAccessionId().equals(id)) { - if (id != null && dbr[r].getAccessionId().equals(id)) - { - // suppress duplicate link creation for the bare sequence ID - // string with this link - id = null; - } - // create Bare ID link for this RUL - String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), - true); - if (urls != null) - { - for (int u = 0; u < urls.length; u += 2) - { - if (!linkset.contains(urls[u] + "|" + urls[u + 1])) - { - linkset.addElement(urls[u] + "|" + urls[u + 1]); - addshowLink(linkMenu, label + "|" + urls[u], - urls[u + 1]); - } - } - } + // suppress duplicate link creation for the bare sequence ID + // string with this link + id = null; } - } - if (id != null) - { - // create Bare ID link for this RUL - String[] urls = urlLink.makeUrls(id, true); + // create Bare ID link for this URL + String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true); if (urls != null) { for (int u = 0; u < urls.length; u += 2) { if (!linkset.contains(urls[u] + "|" + urls[u + 1])) { - linkset.addElement(urls[u] + "|" + urls[u + 1]); - addshowLink(linkMenu, label, urls[u + 1]); + linkset.add(urls[u] + "|" + urls[u + 1]); + addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]); } } } } - // Create urls from description but only for URL links which are regex - // links - if (descr != null && urlLink.getRegexReplace() != null) + } + if (id != null) + { + // create Bare ID link for this URL + String[] urls = urlLink.makeUrls(id, true); + if (urls != null) { - // create link for this URL from description where regex matches - String[] urls = urlLink.makeUrls(descr, true); - if (urls != null) + for (int u = 0; u < urls.length; u += 2) { - for (int u = 0; u < urls.length; u += 2) + if (!linkset.contains(urls[u] + "|" + urls[u + 1])) { - if (!linkset.contains(urls[u] + "|" + urls[u + 1])) - { - linkset.addElement(urls[u] + "|" + urls[u + 1]); - addshowLink(linkMenu, label, urls[u + 1]); - } + linkset.add(urls[u] + "|" + urls[u + 1]); + addshowLink(linkMenu, label, urls[u + 1]); } } } } - else + // Create urls from description but only for URL links which are regex + // links + if (descr != null && urlLink.getRegexReplace() != null) { - if (!linkset.contains(label + "|" + urlLink.getUrl_prefix())) + // create link for this URL from description where regex matches + String[] urls = urlLink.makeUrls(descr, true); + if (urls != null) { - linkset.addElement(label + "|" + urlLink.getUrl_prefix()); - // Add a non-dynamic link - addshowLink(linkMenu, label, urlLink.getUrl_prefix()); + for (int u = 0; u < urls.length; u += 2) + { + if (!linkset.contains(urls[u] + "|" + urls[u + 1])) + { + linkset.add(urls[u] + "|" + urls[u + 1]); + addshowLink(linkMenu, label, urls[u + 1]); + } + } } } } - if (sequence != null) - { - sequenceMenu.add(linkMenu); - } else { - add(linkMenu); + if (!linkset.contains(label + "|" + urlLink.getUrl_prefix())) + { + linkset.add(label + "|" + urlLink.getUrl_prefix()); + // Add a non-dynamic link + addshowLink(linkMenu, label, urlLink.getUrl_prefix()); + } } } + if (sequence != null) + { + sequenceMenu.add(linkMenu); + } + else + { + add(linkMenu); + } } /** @@ -855,7 +862,7 @@ public class PopupMenu extends JPopupMenu showOrHideMenu.add(item); } - private void buildGroupURLMenu(SequenceGroup sg, Vector groupLinks) + private void buildGroupURLMenu(SequenceGroup sg, List groupLinks) { // TODO: usability: thread off the generation of group url content so root @@ -864,19 +871,15 @@ public class PopupMenu extends JPopupMenu // ID/regex match URLs groupLinksMenu = new JMenu( MessageManager.getString("action.group_link")); + // three types of url that might be created. JMenu[] linkMenus = new JMenu[] { null, new JMenu(MessageManager.getString("action.ids")), new JMenu(MessageManager.getString("action.sequences")), - new JMenu(MessageManager.getString("action.ids_sequences")) }; // three - // types - // of url - // that - // might - // be - // created. + new JMenu(MessageManager.getString("action.ids_sequences")) }; + SequenceI[] seqs = ap.av.getSelectionAsNewSequence(); String[][] idandseqs = GroupUrlLink.formStrings(seqs); - Hashtable commonDbrefs = new Hashtable(); + Hashtable commonDbrefs = new Hashtable(); for (int sq = 0; sq < seqs.length; sq++) { @@ -896,7 +899,7 @@ public class PopupMenu extends JPopupMenu for (int d = 0; d < dbr.length; d++) { String src = dbr[d].getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(); - Object[] sarray = (Object[]) commonDbrefs.get(src); + Object[] sarray = commonDbrefs.get(src); if (sarray == null) { sarray = new Object[2]; @@ -921,30 +924,29 @@ public class PopupMenu extends JPopupMenu // now create group links for all distinct ID/sequence sets. boolean addMenu = false; // indicates if there are any group links to give // to user - for (int i = 0; i < groupLinks.size(); i++) + for (String link : groupLinks) { - String link = groupLinks.elementAt(i).toString(); GroupUrlLink urlLink = null; try { urlLink = new GroupUrlLink(link); } catch (Exception foo) { - jalview.bin.Cache.log.error("Exception for GroupURLLink '" + link + Cache.log.error("Exception for GroupURLLink '" + link + "'", foo); continue; } ; if (!urlLink.isValid()) { - jalview.bin.Cache.log.error(urlLink.getInvalidMessage()); + Cache.log.error(urlLink.getInvalidMessage()); continue; } final String label = urlLink.getLabel(); boolean usingNames = false; // Now see which parts of the group apply for this URL String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget()); - Object[] idset = (Object[]) commonDbrefs.get(ltarget.toUpperCase()); + Object[] idset = commonDbrefs.get(ltarget.toUpperCase()); String[] seqstr, ids; // input to makeUrl if (idset != null) { @@ -1062,7 +1064,7 @@ public class PopupMenu extends JPopupMenu new Object[] { urlgenerator.getUrl_prefix(), urlgenerator.getNumberInvolved(urlstub) })); // TODO: put in info about what is being sent. - item.addActionListener(new java.awt.event.ActionListener() + item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) @@ -1076,7 +1078,7 @@ public class PopupMenu extends JPopupMenu try { showLink(urlgenerator.constructFrom(urlstub)); - } catch (UrlStringTooLongException e) + } catch (UrlStringTooLongException e2) { } } diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index cce2ee0..1f1dd2f 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.api.AlignViewportI; +import jalview.bin.Cache; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; @@ -54,11 +55,12 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; +import java.util.ArrayList; import java.util.List; -import java.util.Vector; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; /** @@ -509,6 +511,7 @@ public class SeqPanel extends JPanel implements MouseListener, void insertNucAtCursor(boolean group, String nuc) { + // TODO not called - delete? groupEditing = group; startseq = seqCanvas.cursorY; lastres = seqCanvas.cursorX; @@ -599,7 +602,7 @@ public class SeqPanel extends JPanel implements MouseListener, { lastMousePress = evt.getPoint(); - if (javax.swing.SwingUtilities.isMiddleMouseButton(evt)) + if (SwingUtilities.isMiddleMouseButton(evt)) { mouseWheelPressed = true; return; @@ -1171,8 +1174,7 @@ public class SeqPanel extends JPanel implements MouseListener, { for (int j = 0; j < startres - lastres; j++) { - if (!jalview.util.Comparison.isGap(groupSeqs[g] - .getCharAt(fixedRight - j))) + if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j))) { blank = false; break; @@ -1234,7 +1236,7 @@ public class SeqPanel extends JPanel implements MouseListener, continue; } - if (!jalview.util.Comparison.isGap(groupSeqs[g].getCharAt(j))) + if (!Comparison.isGap(groupSeqs[g].getCharAt(j))) { // Not a gap, block edit not valid endEditing(); @@ -1366,7 +1368,7 @@ public class SeqPanel extends JPanel implements MouseListener, for (blankColumn = fixedColumn; blankColumn > j; blankColumn--) { - if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn))) + if (Comparison.isGap(seq[s].getCharAt(blankColumn))) { // Theres a space, so break and insert the gap break; @@ -1597,24 +1599,24 @@ public class SeqPanel extends JPanel implements MouseListener, } - if (javax.swing.SwingUtilities.isRightMouseButton(evt)) + if (SwingUtilities.isRightMouseButton(evt)) { List allFeatures = ap.getFeatureRenderer() .findFeaturesAtRes(sequence.getDatasetSequence(), sequence.findPosition(res)); - Vector links = new Vector(); + List links = new ArrayList(); for (SequenceFeature sf : allFeatures) { if (sf.links != null) { - for (int j = 0; j < sf.links.size(); j++) + for (String link : sf.links) { - links.addElement(sf.links.elementAt(j)); + links.add(link); } } } - jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links); + PopupMenu pop = new PopupMenu(ap, null, links); pop.show(this, evt.getX(), evt.getY()); return; } @@ -1955,7 +1957,7 @@ public class SeqPanel extends JPanel implements MouseListener, { if (av.getAlignment() == null) { - jalview.bin.Cache.log.warn("alignviewport av SeqSetId=" + Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId() + " ViewId=" + av.getViewId() + " 's alignment is NULL! returning immediately."); return; diff --git a/src/jalview/io/SequenceAnnotationReport.java b/src/jalview/io/SequenceAnnotationReport.java index d3a1d09..676404b 100644 --- a/src/jalview/io/SequenceAnnotationReport.java +++ b/src/jalview/io/SequenceAnnotationReport.java @@ -23,11 +23,12 @@ package jalview.io; import jalview.datamodel.DBRefEntry; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; +import jalview.util.DBRefUtils; import jalview.util.UrlLink; import java.util.ArrayList; -import java.util.Hashtable; import java.util.List; +import java.util.Map; /** * generate HTML reports for a sequence @@ -44,165 +45,183 @@ public class SequenceAnnotationReport } /** - * appends the features at rpos to the given stringbuffer ready for display in - * a tooltip + * Append text for the list of features to the tooltip * * @param tooltipText2 - * @param linkImageURL * @param rpos * @param features - * TODO refactor to Jalview 'utilities' somehow. + * @param minmax */ public void appendFeatures(final StringBuffer tooltipText2, int rpos, - List features) + List features, Map minmax) { - appendFeatures(tooltipText2, rpos, features, null); + if (features != null) + { + for (SequenceFeature feature : features) + { + appendFeature(tooltipText2, rpos, minmax, feature); + } + } } - public void appendFeatures(final StringBuffer tooltipText2, int rpos, - List features, Hashtable minmax) + /** + * Appends text for one sequence feature to the string buffer + * + * @param sb + * @param rpos + * @param minmax + * {{min, max}, {min, max}} positional and non-positional feature + * scores for this type + * @param feature + */ + void appendFeature(final StringBuffer sb, int rpos, + Map minmax, SequenceFeature feature) { - String tmpString; - if (features != null) + if ("disulfide bond".equals(feature.getType())) { - for (SequenceFeature feature : features) + if (feature.getBegin() == rpos || feature.getEnd() == rpos) { - if (feature.getType().equals("disulfide bond")) + if (sb.length() > 6) { - if (feature.getBegin() == rpos || feature.getEnd() == rpos) - { - if (tooltipText2.length() > 6) - { - tooltipText2.append("
"); - } - tooltipText2.append("disulfide bond " + feature.getBegin() - + ":" + feature.getEnd()); - } + sb.append("
"); } - else + sb.append("disulfide bond ").append(feature.getBegin()).append(":") + .append(feature.getEnd()); + } + } + else + { + if (sb.length() > 6) + { + sb.append("
"); + } + // TODO: remove this hack to display link only features + boolean linkOnly = feature.getValue("linkonly") != null; + if (!linkOnly) + { + sb.append(feature.getType()).append(" "); + if (rpos != 0) { - if (tooltipText2.length() > 6) + // we are marking a positional feature + sb.append(feature.begin); + } + if (feature.begin != feature.end) + { + sb.append(" " + feature.end); + } + + if (feature.getDescription() != null + && !feature.description.equals(feature.getType())) + { + String tmpString = feature.getDescription(); + String tmp2up = tmpString.toUpperCase(); + final int startTag = tmp2up.indexOf(""); + if (startTag > -1) { - tooltipText2.append("
"); + tmpString = tmpString.substring(startTag + 6); + tmp2up = tmp2up.substring(startTag + 6); } - // TODO: remove this hack to display link only features - boolean linkOnly = feature.getValue("linkonly") != null; - if (!linkOnly) + // TODO strips off but not - is that intended? + int endTag = tmp2up.indexOf(""); + if (endTag > -1) { - tooltipText2.append(feature.getType() + " "); - if (rpos != 0) - { - // we are marking a positional feature - tooltipText2.append(feature.begin); - } - if (feature.begin != feature.end) - { - tooltipText2.append(" " + feature.end); - } - - if (feature.getDescription() != null - && !feature.description.equals(feature.getType())) - { - tmpString = feature.getDescription(); - String tmp2up = tmpString.toUpperCase(); - int startTag = tmp2up.indexOf(""); - if (startTag > -1) - { - tmpString = tmpString.substring(startTag + 6); - tmp2up = tmp2up.substring(startTag + 6); - } - int endTag = tmp2up.indexOf(""); - if (endTag > -1) - { - tmpString = tmpString.substring(0, endTag); - tmp2up = tmp2up.substring(0, endTag); - } - endTag = tmp2up.indexOf(""); - if (endTag > -1) - { - tmpString = tmpString.substring(0, endTag); - } - - if (startTag > -1) - { - tooltipText2.append("; " + tmpString); - } - else - { - if (tmpString.indexOf("<") > -1 - || tmpString.indexOf(">") > -1) - { - // The description does not specify html is to - // be used, so we must remove < > symbols - tmpString = tmpString.replaceAll("<", "<"); - tmpString = tmpString.replaceAll(">", ">"); - - tooltipText2.append("; "); - tooltipText2.append(tmpString); + tmpString = tmpString.substring(0, endTag); + tmp2up = tmp2up.substring(0, endTag); + } + endTag = tmp2up.indexOf(""); + if (endTag > -1) + { + tmpString = tmpString.substring(0, endTag); + } - } - else - { - tooltipText2.append("; " + tmpString); - } - } - } - // check score should be shown - if (!Float.isNaN(feature.getScore())) + if (startTag > -1) + { + sb.append("; ").append(tmpString); + } + else + { + if (tmpString.indexOf("<") > -1 + || tmpString.indexOf(">") > -1) { - float[][] rng = (minmax == null) ? null : ((float[][]) minmax - .get(feature.getType())); - if (rng != null && rng[0] != null && rng[0][0] != rng[0][1]) - { - tooltipText2.append(" Score=" + feature.getScore()); - } + // The description does not specify html is to + // be used, so we must remove < > symbols + tmpString = tmpString.replaceAll("<", "<"); + tmpString = tmpString.replaceAll(">", ">"); + sb.append("; ").append(tmpString); } - if (feature.getValue("status") != null) + else { - String status = feature.getValue("status").toString(); - if (status.length() > 0) - { - tooltipText2.append("; (" + feature.getValue("status") - + ")"); - } + sb.append("; ").append(tmpString); } } } - if (feature.links != null) + + /* + * score should be shown if there is one, and min != max + * for this feature type (e.g. not all 0) + */ + if (!Float.isNaN(feature.getScore())) { - if (linkImageURL != null) + float[][] rng = (minmax == null) ? null : minmax.get(feature + .getType()); + if (rng != null && rng[0] != null && rng[0][0] != rng[0][1]) { - tooltipText2.append(" "); + sb.append(" Score=").append( + String.valueOf(feature.getScore())); } - else + } + String status = (String) feature.getValue("status"); + if (status != null && status.length() > 0) + { + sb.append("; (").append(status).append(")"); + } + } + } + appendLinks(sb, feature); + } + + /** + * Format and appends any hyperlinks for the sequence feature to the string + * buffer + * + * @param sb + * @param feature + */ + void appendLinks(final StringBuffer sb, SequenceFeature feature) + { + if (feature.links != null) + { + if (linkImageURL != null) + { + sb.append(" "); + } + else + { + for (String urlstring : feature.links) + { + try { - for (String urlstring : feature.links) + for (String[] urllink : createLinksFrom(null, urlstring)) { - try - { - for (String[] urllink : createLinksFrom(null, urlstring)) - { - tooltipText2.append("
" - + (urllink[0].toLowerCase().equals( - urllink[1].toLowerCase()) ? urllink[0] - : (urllink[0] + ":" + urllink[1])) - + "
"); - } - } catch (Exception x) - { - System.err.println("problem when creating links from " - + urlstring); - x.printStackTrace(); - } + sb.append("
" + + (urllink[0].toLowerCase().equals( + urllink[1].toLowerCase()) ? urllink[0] + : (urllink[0] + ":" + urllink[1])) + + "
"); } + } catch (Exception x) + { + System.err.println("problem when creating links from " + + urlstring); + x.printStackTrace(); } - } } + } } @@ -213,63 +232,72 @@ public class SequenceAnnotationReport * @return String[][] { String[] { link target, link label, dynamic component * inserted (if any), url }} */ - public String[][] createLinksFrom(SequenceI seq, String link) + String[][] createLinksFrom(SequenceI seq, String link) { - ArrayList urlSets = new ArrayList(); - ArrayList uniques = new ArrayList(); + List urlSets = new ArrayList(); + List uniques = new ArrayList(); UrlLink urlLink = new UrlLink(link); if (!urlLink.isValid()) { System.err.println(urlLink.getInvalidMessage()); return null; } - final String target = urlLink.getTarget(); // link.substring(0, - // link.indexOf("|")); - final String label = urlLink.getLabel(); if (seq != null && urlLink.isDynamic()) { - - // collect matching db-refs - DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq.getDBRefs(), - new String[] { target }); - // collect id string too - String id = seq.getName(); - String descr = seq.getDescription(); - if (descr != null && descr.length() < 1) + urlSets.addAll(createDynamicLinks(seq, urlLink, uniques)); + } + else + { + String target = urlLink.getTarget(); + String label = urlLink.getLabel(); + String unq = label + "|" + urlLink.getUrl_prefix(); + if (!uniques.contains(unq)) { - descr = null; + uniques.add(unq); + urlSets.add(new String[] { target, label, null, + urlLink.getUrl_prefix() }); } - if (dbr != null) + } + + return urlSets.toArray(new String[][] {}); + } + + /** + * Formats and returns a list of dynamic href links + * + * @param seq + * @param urlLink + * @param uniques + */ + List createDynamicLinks(SequenceI seq, UrlLink urlLink, + List uniques) + { + List result = new ArrayList(); + final String target = urlLink.getTarget(); + final String label = urlLink.getLabel(); + + // collect matching db-refs + DBRefEntry[] dbr = DBRefUtils.selectRefs(seq.getDBRefs(), + new String[] { target }); + // collect id string too + String id = seq.getName(); + String descr = seq.getDescription(); + if (descr != null && descr.length() < 1) + { + descr = null; + } + if (dbr != null) + { + for (int r = 0; r < dbr.length; r++) { - for (int r = 0; r < dbr.length; r++) + if (id != null && dbr[r].getAccessionId().equals(id)) { - if (id != null && dbr[r].getAccessionId().equals(id)) - { - // suppress duplicate link creation for the bare sequence ID - // string with this link - id = null; - } - // create Bare ID link for this RUL - String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true); - if (urls != null) - { - for (int u = 0; u < urls.length; u += 2) - { - String unq = urls[u] + "|" + urls[u + 1]; - if (!uniques.contains(unq)) - { - urlSets.add(new String[] { target, label, urls[u], - urls[u + 1] }); - uniques.add(unq); - } - } - } + // suppress duplicate link creation for the bare sequence ID + // string with this link + id = null; } - } - if (id != null) - { - // create Bare ID link for this RUL - String[] urls = urlLink.makeUrls(id, true); + // create Bare ID link for this URL + String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(), true); if (urls != null) { for (int u = 0; u < urls.length; u += 2) @@ -277,51 +305,56 @@ public class SequenceAnnotationReport String unq = urls[u] + "|" + urls[u + 1]; if (!uniques.contains(unq)) { - urlSets.add(new String[] { target, label, urls[u], + result.add(new String[] { target, label, urls[u], urls[u + 1] }); uniques.add(unq); } } } } - if (descr != null && urlLink.getRegexReplace() != null) + } + if (id != null) + { + // create Bare ID link for this URL + String[] urls = urlLink.makeUrls(id, true); + if (urls != null) { - // create link for this URL from description only if regex matches - String[] urls = urlLink.makeUrls(descr, true); - if (urls != null) + for (int u = 0; u < urls.length; u += 2) { - for (int u = 0; u < urls.length; u += 2) + String unq = urls[u] + "|" + urls[u + 1]; + if (!uniques.contains(unq)) { - String unq = urls[u] + "|" + urls[u + 1]; - if (!uniques.contains(unq)) - { - urlSets.add(new String[] { target, label, urls[u], - urls[u + 1] }); - uniques.add(unq); - } + result.add(new String[] { target, label, urls[u], + urls[u + 1] }); + uniques.add(unq); } } } - } - else + if (descr != null && urlLink.getRegexReplace() != null) { - String unq = label + "|" + urlLink.getUrl_prefix(); - if (!uniques.contains(unq)) + // create link for this URL from description only if regex matches + String[] urls = urlLink.makeUrls(descr, true); + if (urls != null) { - uniques.add(unq); - // Add a non-dynamic link - urlSets.add(new String[] { target, label, null, - urlLink.getUrl_prefix() }); + for (int u = 0; u < urls.length; u += 2) + { + String unq = urls[u] + "|" + urls[u + 1]; + if (!uniques.contains(unq)) + { + result.add(new String[] { target, label, urls[u], + urls[u + 1] }); + uniques.add(unq); + } + } } } - - return urlSets.toArray(new String[][] {}); + return result; } public void createSequenceAnnotationReport(final StringBuffer tip, SequenceI sequence, boolean showDbRefs, boolean showNpFeats, - Hashtable minmax) + Map minmax) { createSequenceAnnotationReport(tip, sequence, showDbRefs, showNpFeats, true, minmax); @@ -329,7 +362,7 @@ public class SequenceAnnotationReport public void createSequenceAnnotationReport(final StringBuffer tip, SequenceI sequence, boolean showDbRefs, boolean showNpFeats, - boolean tableWrap, Hashtable minmax) + boolean tableWrap, Map minmax) { String tmp; tip.append(""); diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 5b55e05..848f565 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -68,6 +68,12 @@ public abstract class FeatureRendererModel implements protected AlignmentViewport av; + /* + * map holds per feature type, {{min, max}, {min, max}} feature score + * values for positional and non-positional features respectively + */ + private Map minmax = new Hashtable(); + @Override public AlignViewportI getViewport() { @@ -194,9 +200,7 @@ public abstract class FeatureRendererModel implements renderOrder = neworder; } - protected Hashtable minmax = new Hashtable(); - - public Hashtable getMinMax() + public Map getMinMax() { return minmax; } @@ -210,7 +214,7 @@ public abstract class FeatureRendererModel implements */ protected final byte[] normaliseScore(SequenceFeature sequenceFeature) { - float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0]; + float[] mm = minmax.get(sequenceFeature.type)[0]; final byte[] r = new byte[] { 0, (byte) 255 }; if (mm != null) { @@ -341,7 +345,7 @@ public abstract class FeatureRendererModel implements } if (minmax == null) { - minmax = new Hashtable(); + minmax = new Hashtable(); } AlignmentI alignment = av.getAlignment(); for (int i = 0; i < alignment.getHeight(); i++) @@ -396,7 +400,7 @@ public abstract class FeatureRendererModel implements if (!Float.isNaN(features[index].score)) { int nonpos = features[index].getBegin() >= 1 ? 0 : 1; - float[][] mm = (float[][]) minmax.get(features[index].getType()); + float[][] mm = minmax.get(features[index].getType()); if (mm == null) { mm = new float[][] { null, null }; @@ -819,7 +823,7 @@ public abstract class FeatureRendererModel implements changeSupport.removePropertyChangeListener(listener); } - public Set getAllFeatureColours() + public Set getAllFeatureColours() { return featureColours.keySet(); }