X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignmentPanel.java;h=7f1ce31d11bfcd6f8f88b5eae6763cc8e1e775b2;hb=e4f893546d61b043b3381c9548f0cfbf7084fd78;hp=8619ad0d7deb8abfb3284dcb2c38b96547181739;hpb=9a9de4a2b0432d0c5e65b033f51ac7e95e8bbbda;p=jalview.git diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 8619ad0..7f1ce31 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -25,6 +25,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -33,6 +34,7 @@ import jalview.jbgui.GAlignmentPanel; import jalview.math.AlignmentDimension; import jalview.schemes.ResidueProperties; import jalview.structure.StructureSelectionManager; +import jalview.util.Comparison; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.viewmodel.ViewportListenerI; @@ -104,12 +106,14 @@ public class AlignmentPanel extends GAlignmentPanel implements /* * Flag set while scrolling to follow complementary cDNA/protein scroll. When - * true, suppresses invoking the same method recursively. + * false, suppresses invoking the same method recursively. */ - private boolean dontScrollComplement; + private boolean scrollComplementaryPanel = true; private PropertyChangeListener propertyChangeListener; + private CalculationChooser calculationDialog; + /** * Creates a new AlignmentPanel object. * @@ -156,19 +160,17 @@ public class AlignmentPanel extends GAlignmentPanel implements { int widthInRes = getSeqPanel().seqCanvas .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); - vpRanges.setStartEndRes(vpRanges.getStartRes(), - vpRanges.getStartRes() + widthInRes); + vpRanges.setViewportWidth(widthInRes); } else { - int widthInRes = (getSeqPanel().seqCanvas.getWidth() / av - .getCharWidth()) - 1; - int heightInSeq = (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight()) - 1; + int widthInRes = getSeqPanel().seqCanvas.getWidth() + / av.getCharWidth(); + int heightInSeq = getSeqPanel().seqCanvas.getHeight() + / av.getCharHeight(); - vpRanges.setStartEndRes(vpRanges.getStartRes(), - vpRanges.getStartRes() + widthInRes); - vpRanges.setStartEndSeq(vpRanges.getStartSeq(), - vpRanges.getStartSeq() + heightInSeq); + vpRanges.setViewportWidth(widthInRes); + vpRanges.setViewportHeight(heightInSeq); } } @@ -205,6 +207,11 @@ public class AlignmentPanel extends GAlignmentPanel implements { av.alignmentChanged(this); + if (getCalculationDialog() != null) + { + getCalculationDialog().validateCalcTypes(); + } + alignFrame.updateEditMenuBar(); paintAlignment(true); @@ -403,9 +410,6 @@ public class AlignmentPanel extends GAlignmentPanel implements } int start = r[0]; int end = r[1]; - // DEBUG - // System.err.println(this.av.viewName + " Seq : " + seqIndex - // + " Scroll to " + start + "," + end); /* * To centre results, scroll to positions half the visible width @@ -413,7 +417,8 @@ public class AlignmentPanel extends GAlignmentPanel implements */ if (centre) { - int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 - 1; + int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 + - 1; start = Math.max(start - offset, 0); end = end + offset - 1; } @@ -427,11 +432,12 @@ public class AlignmentPanel extends GAlignmentPanel implements } if (av.hasHiddenColumns()) { - start = av.getColumnSelection().findColumnPosition(start); - end = av.getColumnSelection().findColumnPosition(end); + HiddenColumns hidden = av.getAlignment().getHiddenColumns(); + start = hidden.findColumnPosition(start); + end = hidden.findColumnPosition(end); if (start == end) { - if (!av.getColumnSelection().isVisible(r[0])) + if (!hidden.isVisible(r[0])) { // don't scroll - position isn't visible return false; @@ -444,9 +450,6 @@ public class AlignmentPanel extends GAlignmentPanel implements */ seqIndex = Math.max(0, seqIndex - verticalOffset); - // System.out.println("start=" + start + ", end=" + end + ", startv=" - // + av.getStartRes() + ", endv=" + av.getEndRes() + ", starts=" - // + av.getStartSeq() + ", ends=" + av.getEndSeq()); if (!av.getWrapAlignment()) { if ((startv = vpRanges.getStartRes()) >= start) @@ -454,7 +457,6 @@ public class AlignmentPanel extends GAlignmentPanel implements /* * Scroll left to make start of search results visible */ - // setScrollValues(start - 1, seqIndex); // plus one residue setScrollValues(start, seqIndex); } else if ((endv = vpRanges.getEndRes()) <= end) @@ -462,7 +464,6 @@ public class AlignmentPanel extends GAlignmentPanel implements /* * Scroll right to make end of search results visible */ - // setScrollValues(startv + 1 + end - endv, seqIndex); // plus one setScrollValues(startv + end - endv, seqIndex); } else if ((starts = vpRanges.getStartSeq()) > seqIndex) @@ -633,8 +634,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { int widthInRes = getSeqPanel().seqCanvas .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); - vpRanges.setStartEndRes(vpRanges.getStartRes(), - vpRanges.getStartRes() + widthInRes - 1); + vpRanges.setViewportWidth(widthInRes); } else { @@ -643,8 +643,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int heightInSeq = (getSeqPanel().seqCanvas.getHeight() / av .getCharHeight()) - 1; - vpRanges.setStartEndRes(vpRanges.getStartRes(), widthInRes); - vpRanges.setStartEndSeq(vpRanges.getStartSeq(), heightInSeq); + vpRanges.setViewportWidth(widthInRes); + vpRanges.setViewportHeight(heightInSeq); } idSpaceFillerPanel1.setVisible(!wrap); @@ -662,8 +662,11 @@ public class AlignmentPanel extends GAlignmentPanel implements * visible row to scroll to * */ - public void setScrollValues(int x, int y) + public void setScrollValues(int xpos, int ypos) { + int x = xpos; + int y = ypos; + if (av == null || av.getAlignment() == null) { return; @@ -675,14 +678,13 @@ public class AlignmentPanel extends GAlignmentPanel implements } else { - int width = av.getAlignment().getWidth(); int height = av.getAlignment().getHeight(); if (av.hasHiddenColumns()) { // reset the width to exclude hidden columns - width = av.getColumnSelection().findColumnPosition(width); + width = av.getAlignment().getHiddenColumns().findColumnPosition(width); } hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); @@ -725,10 +727,11 @@ public class AlignmentPanel extends GAlignmentPanel implements } /** - * DOCUMENT ME! + * Respond to adjustment event when horizontal or vertical scrollbar is + * changed * * @param evt - * DOCUMENT ME! + * adjustment event encoding whether hscroll or vscroll changed */ @Override public void adjustmentValueChanged(AdjustmentEvent evt) @@ -759,23 +762,31 @@ public class AlignmentPanel extends GAlignmentPanel implements } else if (offy > -1) { - vpRanges.setStartEndRes(offy * rowSize, (offy + 1) * rowSize - 1); + vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize); } - else + } + else + { + // This is only called if file loaded is a jar file that + // was wrapped when saved and user has wrap alignment true + // as preference setting + SwingUtilities.invokeLater(new Runnable() { - // This is only called if file loaded is a jar file that - // was wrapped when saved and user has wrap alignment true - // as preference setting - SwingUtilities.invokeLater(new Runnable() - { - @Override - public void run() - { - setScrollValues(vpRanges.getStartRes(), - vpRanges.getStartSeq()); - } - }); - } + @Override + public void run() + { + // When updating scrolling to use ViewportChange events, this code + // could not be validated and it is not clear if it is now being + // called. Log warning here in case it is called and unforeseen + // problems occur + Cache.log + .warn("Unexpected path through code: Wrapped jar file opened with wrap alignment set in preferences"); + + // scroll to start of panel + vpRanges.setStartRes(0); + vpRanges.setStartSeq(0); + } + }); } repaint(); } @@ -785,7 +796,7 @@ public class AlignmentPanel extends GAlignmentPanel implements if (evt.getSource() == hscroll) { int x = hscroll.getValue(); - int width = (getSeqPanel().seqCanvas.getWidth() / av.getCharWidth()) - 1; + int width = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); // if we're scrolling to the position we're already at, stop // this prevents infinite recursion of events when the scroll/viewport @@ -794,13 +805,13 @@ public class AlignmentPanel extends GAlignmentPanel implements { return; } - vpRanges.setStartEndRes(x, x + width); + vpRanges.setViewportStartAndWidth(x, width); } else if (evt.getSource() == vscroll) { int y = vscroll.getValue(); - int height = (getSeqPanel().seqCanvas.getHeight() / av - .getCharHeight()) - 1; + int height = getSeqPanel().seqCanvas.getHeight() + / av.getCharHeight(); // if we're scrolling to the position we're already at, stop // this prevents infinite recursion of events when the scroll/viewport @@ -809,7 +820,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { return; } - vpRanges.setStartEndSeq(y, y + height); + vpRanges.setViewportStartAndHeight(y, height); } if (!fastPaint) { @@ -876,7 +887,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } // get the width of the canvas in residues @@ -1161,7 +1173,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int resWidth = getSeqPanel().seqCanvas.getWrappedCanvasWidth(pwidth @@ -1355,7 +1368,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth); + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth); } int height = ((av.getAlignment().getHeight() + 1) * av.getCharHeight()) @@ -1438,11 +1452,10 @@ public class AlignmentPanel extends GAlignmentPanel implements sy = s * av.getCharHeight() + scaleHeight; SequenceI seq = av.getAlignment().getSequenceAt(s); - SequenceFeature[] features = seq.getSequenceFeatures(); SequenceGroup[] groups = av.getAlignment().findAllGroups(seq); for (res = 0; res < alwidth; res++) { - StringBuilder text = new StringBuilder(); + StringBuilder text = new StringBuilder(512); String triplet = null; if (av.getAlignment().isNucleotide()) { @@ -1460,7 +1473,7 @@ public class AlignmentPanel extends GAlignmentPanel implements continue; } - int alIndex = seq.findPosition(res); + int seqPos = seq.findPosition(res); gSize = groups.length; for (g = 0; g < gSize; g++) { @@ -1472,7 +1485,7 @@ public class AlignmentPanel extends GAlignmentPanel implements .append((idWidth + (res + 1) * av.getCharWidth())) .append(",").append((av.getCharHeight() + sy)) .append("\"").append(" onMouseOver=\"toolTip('") - .append(alIndex).append(" ").append(triplet); + .append(seqPos).append(" ").append(triplet); } if (groups[g].getStartRes() < res @@ -1483,61 +1496,51 @@ public class AlignmentPanel extends GAlignmentPanel implements } } - if (features != null) + if (text.length() < 1) { - if (text.length() < 1) - { - text.append(" features = seq.findFeatures(seqPos, + seqPos); + for (SequenceFeature sf : features) { - - if ((features[f].getBegin() <= seq.findPosition(res)) - && (features[f].getEnd() >= seq.findPosition(res))) + if (sf.isContactFeature()) { - if (features[f].isContactFeature()) - { - if (features[f].getBegin() == seq.findPosition(res) - || features[f].getEnd() == seq - .findPosition(res)) - { - text.append("
").append(features[f].getType()) - .append(" ").append(features[f].getBegin()) - .append(":").append(features[f].getEnd()); - } - } - else + text.append("
").append(sf.getType()).append(" ") + .append(sf.getBegin()).append(":") + .append(sf.getEnd()); + } + else + { + text.append("
"); + text.append(sf.getType()); + String description = sf.getDescription(); + if (description != null + && !sf.getType().equals(description)) { - text.append("
"); - text.append(features[f].getType()); - if (features[f].getDescription() != null - && !features[f].getType().equals( - features[f].getDescription())) - { - text.append(" ").append(features[f].getDescription()); - } - - if (features[f].getValue("status") != null) - { - text.append(" (").append(features[f].getValue("status")) - .append(")"); - } + description = description.replace("\"", """); + text.append(" ").append(description); } } - + String status = sf.getStatus(); + if (status != null && !"".equals(status)) + { + text.append(" (").append(status).append(")"); + } + } + if (text.length() > 1) + { + text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">"); + out.println(text.toString()); } - } - if (text.length() > 1) - { - text.append("')\"; onMouseOut=\"toolTip()\"; href=\"#\">"); - out.println(text.toString()); } } } @@ -1585,7 +1588,8 @@ public class AlignmentPanel extends GAlignmentPanel implements int maxwidth = av.getAlignment().getWidth(); if (av.hasHiddenColumns()) { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + maxwidth = av.getAlignment().getHiddenColumns() + .findColumnPosition(maxwidth) - 1; } int height = ((maxwidth / chunkWidth) + 1) * cHeight; @@ -1603,6 +1607,8 @@ public class AlignmentPanel extends GAlignmentPanel implements PaintRefresher.RemoveComponent(getIdPanel().getIdCanvas()); PaintRefresher.RemoveComponent(this); + closeChildFrames(); + /* * try to ensure references are nulled */ @@ -1634,6 +1640,17 @@ public class AlignmentPanel extends GAlignmentPanel implements } /** + * Close any open dialogs that would be orphaned when this one is closed + */ + protected void closeChildFrames() + { + if (calculationDialog != null) + { + calculationDialog.closeFrame(); + } + } + + /** * hides or shows dynamic annotation rows based on groups and av state flags */ public void updateAnnotation() @@ -1831,14 +1848,19 @@ public class AlignmentPanel extends GAlignmentPanel implements * * @param b */ - protected void setDontScrollComplement(boolean b) + protected void setToScrollComplementPanel(boolean b) { - this.dontScrollComplement = b; + this.scrollComplementaryPanel = b; } - protected boolean isDontScrollComplement() + /** + * Get whether to scroll complement panel + * + * @return true if cDNA/protein complement panels should be scrolled + */ + protected boolean isSetToScrollComplementPanel() { - return this.dontScrollComplement; + return this.scrollComplementaryPanel; } /** @@ -1877,11 +1899,31 @@ public class AlignmentPanel extends GAlignmentPanel implements // now update any complementary alignment (its viewport ranges object // is different so does not get automatically updated) - if (!isDontScrollComplement()) + if (isSetToScrollComplementPanel()) { - setDontScrollComplement(true); + setToScrollComplementPanel(false); av.scrollComplementaryAlignment(); - setDontScrollComplement(false); + setToScrollComplementPanel(true); } } + + /** + * Set the reference to the PCA/Tree chooser dialog for this panel. This + * reference should be nulled when the dialog is closed. + * + * @param calculationChooser + */ + public void setCalculationDialog(CalculationChooser calculationChooser) + { + calculationDialog = calculationChooser; + } + + /** + * Returns the reference to the PCA/Tree chooser dialog for this panel (null + * if none is open) + */ + public CalculationChooser getCalculationDialog() + { + return calculationDialog; + } }