X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAlignmentPanel.java;h=f2fca589848182a743d78f3228be7d8282fc73ec;hb=ab43013b7e357b84b4abade0dba949668dfb2a0e;hp=ba6d8735118473ceab00691f1aa93b8455bd9e4a;hpb=e8ede151da126e8fe205392c64f1604d80adda6d;p=jalview.git diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index ba6d873..f2fca58 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -1,32 +1,46 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) - * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1) + * Copyright (C) 2014 The Jalview Authors * * This file is part of Jalview. * * Jalview 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 3 of the License, or (at your option) any later version. - * + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * * Jalview 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 Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.appletgui; -import java.awt.*; -import java.awt.event.*; -import java.util.Hashtable; -import java.util.Vector; - import jalview.api.AlignmentViewPanel; -import jalview.datamodel.*; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceI; import jalview.structure.StructureSelectionManager; -public class AlignmentPanel extends Panel implements AdjustmentListener, AlignmentViewPanel +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Panel; +import java.awt.Scrollbar; +import java.awt.event.AdjustmentEvent; +import java.awt.event.AdjustmentListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +public class AlignmentPanel extends Panel implements AdjustmentListener, + AlignmentViewPanel { public AlignViewport av; @@ -49,19 +63,21 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme // this value is set false when selection area being dragged boolean fastPaint = true; - - public void finalize() { - alignFrame=null; - av=null; - seqPanel=null; - seqPanelHolder=null; - sequenceHolderPanel=null; - scalePanel=null; - scalePanelHolder=null; - annotationPanel=null; - annotationPanelHolder=null; - annotationSpaceFillerHolder=null; + + public void finalize() + { + alignFrame = null; + av = null; + seqPanel = null; + seqPanelHolder = null; + sequenceHolderPanel = null; + scalePanel = null; + scalePanelHolder = null; + annotationPanel = null; + annotationPanelHolder = null; + annotationSpaceFillerHolder = null; } + public AlignmentPanel(AlignFrame af, final AlignViewport av) { try @@ -82,7 +98,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme annotationPanelHolder.add(annotationPanel, BorderLayout.CENTER); sequenceHolderPanel.add(annotationPanelHolder, BorderLayout.SOUTH); - alabels = new AnnotationLabels(this); setAnnotationVisible(av.showAnnotation); @@ -105,12 +120,14 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme public void componentResized(ComponentEvent evt) { setScrollValues(av.getStartRes(), av.getStartSeq()); - if (getSize().height>0 && annotationPanelHolder.getSize().height>0) { + if (getSize().height > 0 + && annotationPanelHolder.getSize().height > 0) + { validateAnnotationDimensions(false); } repaint(); } - + }); Dimension d = calculateIdWidth(); @@ -134,7 +151,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme } } }); - } public SequenceRenderer getSequenceRenderer() @@ -177,10 +193,10 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme Dimension d = calculateIdWidth(); d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height); alabels.setSize(d.width + 4, ap); - + idPanel.idCanvas.setSize(d); hscrollFillerPanel.setSize(d); - + validateAnnotationDimensions(false); annotationPanel.repaint(); validate(); @@ -196,7 +212,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme { idPanel.idCanvas.setSize(w, h); idPanelHolder.setSize(w, idPanelHolder.getSize().height); - annotationSpaceFillerHolder.setSize(w,annotationSpaceFillerHolder.getSize().height); + annotationSpaceFillerHolder.setSize(w, + annotationSpaceFillerHolder.getSize().height); alabels.setSize(w, alabels.getSize().height); validate(); } @@ -282,31 +299,36 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme public boolean scrollToPosition(SearchResults results, boolean redrawOverview) { - + // do we need to scroll the panel? if (results != null && results.getSize() > 0) { - AlignmentI alignment=av.getAlignment(); + AlignmentI alignment = av.getAlignment(); int seqIndex = alignment.findIndex(results); if (seqIndex == -1) { return false; } SequenceI seq = alignment.getSequenceAt(seqIndex); - int[] r = results.getResults(seq, 0,alignment.getWidth()); + int[] r = results.getResults(seq, 0, alignment.getWidth()); if (r == null) { - if (av.applet.debug) {// DEBUG - System.out.println("DEBUG: scroll didn't happen - results not within alignment : "+seq.getStart()+","+seq.getEnd()); + if (av.applet.debug) + {// DEBUG + System.out + .println("DEBUG: scroll didn't happen - results not within alignment : " + + seq.getStart() + "," + seq.getEnd()); } return false; } - if (av.applet.debug) { + if (av.applet.debug) + { // DEBUG - /*System.out.println("DEBUG: scroll: start=" + r[0] - + " av.getStartRes()=" + av.getStartRes() + " end=" + r[1] - + " seq.end=" + seq.getEnd() + " av.getEndRes()=" - + av.getEndRes() + " hextent=" + hextent); + /* + * System.out.println("DEBUG: scroll: start=" + r[0] + + * " av.getStartRes()=" + av.getStartRes() + " end=" + r[1] + + * " seq.end=" + seq.getEnd() + " av.getEndRes()=" + av.getEndRes() + + * " hextent=" + hextent); */ } int start = r[0]; @@ -323,11 +345,13 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme } return true; } - public boolean scrollTo(int ostart, int end, int seqIndex, boolean scrollToNearest, boolean redrawOverview) + + public boolean scrollTo(int ostart, int end, int seqIndex, + boolean scrollToNearest, boolean redrawOverview) { - int startv, endv, starts, ends, width; + int startv, endv, starts, ends, width; - int start=-1; + int start = -1; if (av.hasHiddenColumns()) { start = av.getColumnSelection().findColumnPosition(ostart); @@ -347,58 +371,47 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme } if (!av.wrapAlignment) { - /* - int spos=av.getStartRes(),sqpos=av.getStartSeq(); - if ((startv = av.getStartRes()) >= start) - { - spos=start-1; -// seqIn -// setScrollValues(start - 1, seqIndex); - } - else if ((endv = av.getEndRes()) <= end) - { -// setScrollValues(spos=startv + 1 + end - endv, seqIndex); - spos=startv + 1 + end - endv; - } - else if ((starts = av.getStartSeq()) > seqIndex) - { - setScrollValues(av.getStartRes(), seqIndex); - } - else if ((ends = av.getEndSeq()) <= seqIndex) + /* + * int spos=av.getStartRes(),sqpos=av.getStartSeq(); if ((startv = + * av.getStartRes()) >= start) { spos=start-1; // seqIn // + * setScrollValues(start - 1, seqIndex); } else if ((endv = + * av.getEndRes()) <= end) { // setScrollValues(spos=startv + 1 + end - + * endv, seqIndex); spos=startv + 1 + end - endv; } else if ((starts = + * av.getStartSeq()) > seqIndex) { setScrollValues(av.getStartRes(), + * seqIndex); } else if ((ends = av.getEndSeq()) <= seqIndex) { + * setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1); } + * + * /* + */ + if ((av.getStartRes() > end) + || (av.getEndRes() < start) + || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))) + { + if (start > av.getAlignment().getWidth() - hextent) + { + start = av.getAlignment().getWidth() - hextent; + if (start < 0) { - setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1); + start = 0; } - /* */ - if ((av.getStartRes() > end) - || (av.getEndRes() < start) - || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))) + } + if (seqIndex > av.getAlignment().getHeight() - vextent) { - if (start > av.getAlignment().getWidth() - hextent) - { - start = av.getAlignment().getWidth() - hextent; - if (start < 0) - { - start = 0; - } - - } - if (seqIndex > av.getAlignment().getHeight() - vextent) + seqIndex = av.getAlignment().getHeight() - vextent; + if (seqIndex < 0) { - seqIndex = av.getAlignment().getHeight() - vextent; - if (seqIndex < 0) - { - seqIndex = 0; - } + seqIndex = 0; } - // System.out.println("trying to scroll to: "+start+" "+seqIndex); - setScrollValues(start, seqIndex); - }/**/ - } - else - { - scrollToWrappedVisible(start); - } + } + // System.out.println("trying to scroll to: "+start+" "+seqIndex); + setScrollValues(start, seqIndex); + }/**/ + } + else + { + scrollToWrappedVisible(start); + } if (redrawOverview && overviewPanel != null) { overviewPanel.setBoxPosition(); @@ -435,10 +448,15 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme annotationSpaceFillerHolder.setVisible(b); annotationPanelHolder.setVisible(b); } + else + { + annotationSpaceFillerHolder.setVisible(false); + annotationPanelHolder.setVisible(false); + } validate(); repaint(); } - + /** * automatically adjust annotation panel height for new annotation whilst * ensuring the alignment is still visible. @@ -458,55 +476,76 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme validate(); paintAlignment(true); } + /** * calculate the annotation dimensions and refresh slider values accordingly. - * need to do repaints/notifys afterwards. + * need to do repaints/notifys afterwards. */ - protected void validateAnnotationDimensions(boolean adjustPanelHeight) { - boolean modified=false; + protected void validateAnnotationDimensions(boolean adjustPanelHeight) + { + boolean modified = false; int height = av.calcPanelHeight(); - int minsize=0; + int minsize = 0; if (hscroll.isVisible()) { - height += (minsize=hscroll.getPreferredSize().height); + height += (minsize = hscroll.getPreferredSize().height); } - if (apvscroll.isVisible()) { - minsize+=apvscroll.getPreferredSize().height; + if (apvscroll.isVisible()) + { + minsize += apvscroll.getPreferredSize().height; } int mheight = height; - Dimension d=sequenceHolderPanel.getSize(),e=idPanel.getSize(); - int seqandannot=d.height-scalePanelHolder.getSize().height; - // sets initial preferred height - if ((height+40) > seqandannot / 2) - { - height = seqandannot / 2; + Dimension d = sequenceHolderPanel.getSize(), e = idPanel.getSize(); + int seqandannot = d.height - scalePanelHolder.getSize().height; + + if (adjustPanelHeight) + { + // NOTE: this logic is different in the application. Need a better + // algorithm to define behaviour + // sets initial preferred height + // try and set height according to alignment + float sscaling = (float) ((av.getCharHeight() * av.getAlignment() + .getHeight()) / (1.0 * mheight)); + if (sscaling > 0.5) + { + // if the alignment is too big then + // default is 0.5 split + height = seqandannot / 2; + } + else + { + // otherwise just set the panel so that one row of sequence is visible + height = -av.getCharHeight() * 1 + + (int) (seqandannot * (1 - sscaling)); + } } - if (!adjustPanelHeight) + else { // maintain same window layout whilst updating sliders - height=annotationPanelHolder.getSize().height; + height = annotationPanelHolder.getSize().height; } - - if (seqandannot-height<5) + + if (seqandannot - height < 5) { height = seqandannot; } - annotationPanel.setSize(new Dimension(d.width,height)); - alabels.setSize(new Dimension(e.width,height)); + annotationPanel.setSize(new Dimension(d.width, height)); + alabels.setSize(new Dimension(e.width, height)); annotationSpaceFillerHolder.setSize(new Dimension(e.width, height)); annotationPanelHolder.setSize(new Dimension(d.width, height)); - seqPanelHolder.setSize(d.width,seqandannot-height); - seqPanel.seqCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height); - int s=apvscroll.getValue(); - if (s>mheight-height) + // seqPanelHolder.setSize(d.width, seqandannot - height); + seqPanel.seqCanvas + .setSize(d.width, seqPanel.seqCanvas.getSize().height); + int s = apvscroll.getValue(); + if (s > mheight - height) { s = 0; } apvscroll.setValues(s, height, 0, mheight); - annotationPanel.setScrollOffset(apvscroll.getValue()); - alabels.setScrollOffset(apvscroll.getValue()); + annotationPanel.setScrollOffset(apvscroll.getValue(), false); + alabels.setScrollOffset(apvscroll.getValue(), false); } - + public void setWrapAlignment(boolean wrap) { av.startSeq = 0; @@ -532,6 +571,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme fontChanged(); // This is so that the scalePanel is resized correctly validate(); + sequenceHolderPanel.validate(); repaint(); } @@ -596,11 +636,15 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme { width = av.getColumnSelection().findColumnPosition(width); } - if (x<0) { x = 0; }; + if (x < 0) + { + x = 0; + } + ; hextent = seqPanel.seqCanvas.getSize().width / av.charWidth; vextent = seqPanel.seqCanvas.getSize().height / av.charHeight; - + if (hextent > width) { hextent = width; @@ -613,7 +657,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme if ((hextent + x) > width) { - System.err.println("hextent was "+hextent+" and x was "+x); + System.err.println("hextent was " + hextent + " and x was " + x); x = width - hextent; } @@ -630,7 +674,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme if (x < 0) { - System.err.println("x was "+x); + System.err.println("x was " + x); x = 0; } @@ -655,7 +699,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme } sendViewPosition(); - } public void adjustmentValueChanged(AdjustmentEvent evt) @@ -665,8 +708,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme if (evt == null || evt.getSource() == apvscroll) { - annotationPanel.setScrollOffset(apvscroll.getValue()); - alabels.setScrollOffset(apvscroll.getValue()); + annotationPanel.setScrollOffset(apvscroll.getValue(), false); + alabels.setScrollOffset(apvscroll.getValue(), false); // annotationPanel.image=null; // alabels.image=null; // alabels.repaint(); @@ -735,9 +778,12 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme sendViewPosition(); } + private void sendViewPosition() { - StructureSelectionManager.getStructureSelectionManager(av.applet).sendViewPosition(this, av.startRes, av.endRes, av.startSeq, av.endSeq); + StructureSelectionManager.getStructureSelectionManager(av.applet) + .sendViewPosition(this, av.startRes, av.endRes, av.startSeq, + av.endSeq); } public void paintAlignment(boolean updateOverview) @@ -747,7 +793,8 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme if (updateOverview) { jalview.structure.StructureSelectionManager - .getStructureSelectionManager(av.applet).sequenceColoursChanged(this); + .getStructureSelectionManager(av.applet) + .sequenceColoursChanged(this); if (overviewPanel != null) { @@ -766,7 +813,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme invalidate(); Dimension d = idPanel.idCanvas.getSize(); idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height); - + if (av.getWrapAlignment()) { int maxwidth = av.getAlignment().getWidth(); @@ -792,12 +839,18 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme setScrollValues(av.getStartRes(), av.getStartSeq()); } - alabels.repaint(); - seqPanel.seqCanvas.repaint(); - scalePanel.repaint(); - annotationPanel.repaint(); idPanel.idCanvas.repaint(); + if (!av.wrapAlignment) + { + if (av.showAnnotation) + { + alabels.repaint(); + annotationPanel.repaint(); + } + scalePanel.repaint(); + } + } protected Panel sequenceHolderPanel = new Panel(); @@ -849,7 +902,7 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme // idPanelHolder.setPreferredSize(new Dimension(70, 10)); this.setLayout(borderLayout7); - //sequenceHolderPanel.setPreferredSize(new Dimension(150, 150)); + // sequenceHolderPanel.setPreferredSize(new Dimension(150, 150)); sequenceHolderPanel.setLayout(borderLayout3); seqPanelHolder.setLayout(borderLayout1); scalePanelHolder.setBackground(Color.white); @@ -906,65 +959,14 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme public void updateAnnotation(boolean applyGlobalSettings) { - // TODO: this should be merged with other annotation update stuff - that - // sits on AlignViewport - boolean updateCalcs = false; - boolean conv = av.isShowGroupConservation(); - boolean cons = av.isShowGroupConsensus(); - boolean showprf = av.isShowSequenceLogo(); - boolean showConsHist = av.isShowConsensusHistogram(); - - boolean sortg = true; - - // remove old automatic annotation - // add any new annotation - - ; // OrderedBy(av.alignment.getSequencesArray()); - // intersect alignment annotation with alignment groups + updateAnnotation(applyGlobalSettings, false); + } - AlignmentAnnotation[] aan = av.getAlignment().getAlignmentAnnotation(); - Hashtable oldrfs = new Hashtable(); - if (aan != null) - { - for (int an = 0; an < aan.length; an++) - { - if (aan[an].autoCalculated && aan[an].groupRef != null) - { - oldrfs.put(aan[an].groupRef, aan[an].groupRef); - av.getAlignment().deleteAnnotation(aan[an]); - aan[an] = null; - } - } - } - if (av.getAlignment().getGroups()!= null) - { - for (SequenceGroup sg:av.getAlignment().getGroups()) - { - updateCalcs = false; - if (applyGlobalSettings || !oldrfs.containsKey(sg)) - { - // set defaults for this group's conservation/consensus - sg.setshowSequenceLogo(showprf); - sg.setShowConsensusHistogram(showConsHist); - } - if (conv) - { - updateCalcs = true; - av.getAlignment().addAnnotation(sg.getConservationRow(), 0); - } - if (cons) - { - updateCalcs = true; - av.getAlignment().addAnnotation(sg.getConsensus(), 0); - } - // refresh the annotation rows - if (updateCalcs) - { - sg.recalcConservation(); - } - } - } - oldrfs.clear(); + public void updateAnnotation(boolean applyGlobalSettings, + boolean preserveNewGroupSettings) + { + av.updateGroupAnnotationSettings(applyGlobalSettings, + preserveNewGroupSettings); adjustAnnotationHeight(); } @@ -973,16 +975,25 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, Alignme { return av.getAlignment(); } + + @Override + public String getViewName() + { + return getName(); + } + @Override public StructureSelectionManager getStructureSelectionManager() { - return StructureSelectionManager.getStructureSelectionManager(av.applet); + return StructureSelectionManager + .getStructureSelectionManager(av.applet); } + @Override public void raiseOOMWarning(String string, OutOfMemoryError error) { // TODO: JAL-960 - System.err.println("Out of memory whilst '"+string+"'"); + System.err.println("Out of memory whilst '" + string + "'"); error.printStackTrace(); }