From a2ada916efe9af351bf49c2c583488892762e0ab Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 6 Jul 2015 09:01:52 +0100 Subject: [PATCH] JAL-1799 equivalent logic in applet --- src/jalview/appletgui/AlignFrame.java | 2 + src/jalview/appletgui/AlignmentPanel.java | 88 ++++++++++++++--------------- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index eaf93c2..075f0d2 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -928,6 +928,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, aa.visible = visible; } alignPanel.validateAnnotationDimensions(true); + validate(); + repaint(); } private void setAnnotationSortOrder(SequenceAnnotationOrder order) diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 0516533..f321581 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -20,6 +20,15 @@ */ package jalview.appletgui; +import jalview.analysis.AnnotationSorter; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; +import jalview.bin.JalviewLite; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceI; +import jalview.structure.StructureSelectionManager; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -34,15 +43,6 @@ import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.List; -import jalview.analysis.AnnotationSorter; -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.bin.JalviewLite; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.SearchResults; -import jalview.datamodel.SequenceI; -import jalview.structure.StructureSelectionManager; - public class AlignmentPanel extends Panel implements AdjustmentListener, AlignmentViewPanel { @@ -552,70 +552,64 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, } /** - * calculate the annotation dimensions and refresh slider values accordingly. - * need to do repaints/notifys afterwards. + * Calculate the annotation dimensions and refresh slider values accordingly. + * Need to do repaints/notifys afterwards. */ protected void validateAnnotationDimensions(boolean adjustPanelHeight) { - boolean modified = false; - int height = av.calcPanelHeight(); - int minsize = 0; + int rowHeight = av.getCharHeight(); + int alignmentHeight = rowHeight * av.getAlignment().getHeight(); + int annotationHeight = av.calcPanelHeight(); + + int mheight = annotationHeight; + Dimension d = sequenceHolderPanel.getSize(); + + int availableHeight = d.height - scalePanelHolder.getSize().height; if (hscroll.isVisible()) { - height += (minsize = hscroll.getPreferredSize().height); - } - if (apvscroll.isVisible()) - { - minsize += apvscroll.getPreferredSize().height; + availableHeight -= hscroll.getPreferredSize().height; } - int mheight = height; - 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 + /* + * If not enough vertical space, maximize annotation height while keeping + * at least two rows of alignment visible + */ + if (annotationHeight + alignmentHeight > availableHeight) { - // otherwise just set the panel so that one row of sequence is visible - height = -av.getCharHeight() * 1 - + (int) (seqandannot * (1 - sscaling)); + annotationHeight = Math.min(annotationHeight, availableHeight - 2 + * rowHeight); } } else { // maintain same window layout whilst updating sliders - height = annotationPanelHolder.getSize().height; + annotationHeight = annotationPanelHolder.getSize().height; } - if (seqandannot - height < 5) + if (availableHeight - annotationHeight < 5) { - height = seqandannot; + annotationHeight = availableHeight; } - 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)); + + annotationPanel.setSize(new Dimension(d.width, annotationHeight)); + annotationPanelHolder.setSize(new Dimension(d.width, annotationHeight)); // seqPanelHolder.setSize(d.width, seqandannot - height); seqPanel.seqCanvas .setSize(d.width, seqPanel.seqCanvas.getSize().height); + + Dimension e = idPanel.getSize(); + alabels.setSize(new Dimension(e.width, annotationHeight)); + annotationSpaceFillerHolder.setSize(new Dimension(e.width, + annotationHeight)); + int s = apvscroll.getValue(); - if (s > mheight - height) + if (s > mheight - annotationHeight) { s = 0; } - apvscroll.setValues(s, height, 0, mheight); + apvscroll.setValues(s, annotationHeight, 0, mheight); annotationPanel.setScrollOffset(apvscroll.getValue(), false); alabels.setScrollOffset(apvscroll.getValue(), false); } -- 1.7.10.2