From: gmungoc Date: Mon, 29 Jun 2015 15:31:40 +0000 (+0100) Subject: JAL-1799 adjusted annotation height calculation X-Git-Tag: Release_2_10_0~585^2~12 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4a7adcc9f6c0d05e12f8ea5460b0c9372020b98a;p=jalview.git JAL-1799 adjusted annotation height calculation --- diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index ca1d158..eaf93c2 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -927,7 +927,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, : showForSequences); aa.visible = visible; } - alignPanel.validateAnnotationDimensions(false); + alignPanel.validateAnnotationDimensions(true); } private void setAnnotationSortOrder(SequenceAnnotationOrder order) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 01a22ed..d2e247f 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -5991,7 +5991,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, aa.visible = visible; } } - alignPanel.validateAnnotationDimensions(false); + alignPanel.validateAnnotationDimensions(true); alignPanel.alignmentChanged(); } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 5bc46f4..588411e 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -20,6 +20,21 @@ */ package jalview.gui; +import jalview.analysis.AnnotationSorter; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.jbgui.GAlignmentPanel; +import jalview.math.AlignmentDimension; +import jalview.schemes.ResidueProperties; +import jalview.structure.StructureSelectionManager; +import jalview.util.MessageManager; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; @@ -27,6 +42,7 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; +import java.awt.Insets; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import java.awt.print.PageFormat; @@ -41,21 +57,6 @@ import java.util.List; import javax.swing.SwingUtilities; -import jalview.analysis.AnnotationSorter; -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.bin.Cache; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.SearchResults; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceGroup; -import jalview.datamodel.SequenceI; -import jalview.jbgui.GAlignmentPanel; -import jalview.math.AlignmentDimension; -import jalview.schemes.ResidueProperties; -import jalview.structure.StructureSelectionManager; -import jalview.util.MessageManager; - /** * DOCUMENT ME! * @@ -511,47 +512,46 @@ public class AlignmentPanel extends GAlignmentPanel implements */ protected void validateAnnotationDimensions(boolean adjustPanelHeight) { - int height = getAnnotationPanel().adjustPanelHeight(); - - int theight = av.getCharHeight() - * (av.getAlignment().getHeight() + (!av.hasHiddenRows() ? 0 - : av.getAlignment().getHiddenSequences().getSize())); - float sscaling = (float) (theight / (1.0 * theight + height)); - float ascaling = (float) (height * 1.0 / alignFrame.getHeight()); - int rheight = alignFrame.getHeight() - height - av.getCharHeight(); + int annotationHeight = getAnnotationPanel().adjustPanelHeight(); + if (adjustPanelHeight) { - // NOTE: this logic is different in the applet. Need a better algorithm to - // define behaviour - // try and set height according to alignment - if (ascaling > 0 && sscaling < 0.5) - { - // if the alignment is too big then - // default is 0.5 split - height = alignFrame.getHeight() / 2; - } - else + int rowHeight = av.getCharHeight(); + int alignmentHeight = rowHeight * av.getAlignment().getHeight(); + + /* + * Estimate available height in the AlignFrame for alignment + + * annotations. Deduct an estimate of 75 for menu bar, scale panel, + * hscroll, status bar (as these are not laid out we can't inspect their + * actual heights). Insets gives borders including title bar. + */ + Insets insets = alignFrame.getInsets(); + int availableHeight = alignFrame.getHeight() - 75 - insets.top + - insets.bottom; + + /* + * If not enough vertical space, maximize annotation height while keeping + * at least two rows of alignment visible + */ + if (annotationHeight + alignmentHeight > availableHeight) { - // if space for more than one sequence row left when annotation is fully - // displayed then set height to annotation height - // otherwise, leave at least two lines of sequence shown. - height = (rheight > av.getCharHeight()) ? height - : (-av.getCharHeight() * 3 + (int) (alignFrame.getHeight() * (1 - sscaling))); + annotationHeight = Math.min(annotationHeight, availableHeight - 2 + * rowHeight); } } else { // maintain same window layout whilst updating sliders - height = annotationScroller.getSize().height; + annotationHeight = annotationScroller.getSize().height; } hscroll.addNotify(); annotationScroller.setPreferredSize(new Dimension(annotationScroller - .getWidth(), height)); + .getWidth(), annotationHeight)); annotationSpaceFillerHolder.setPreferredSize(new Dimension( - annotationSpaceFillerHolder.getWidth(), height)); - annotationScroller.validate();// repaint(); + annotationSpaceFillerHolder.getWidth(), annotationHeight)); + annotationScroller.validate(); annotationScroller.addNotify(); }