*/
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;
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;
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!
*
*/
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();
}