2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.AlignmentI;
25 import jalview.datamodel.Annotation;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.HiddenColumns;
28 import jalview.datamodel.SequenceI;
29 import jalview.renderer.AnnotationRenderer;
30 import jalview.renderer.AwtRenderPanelI;
31 import jalview.schemes.ResidueProperties;
32 import jalview.util.Comparison;
33 import jalview.util.MessageManager;
34 import jalview.util.Platform;
35 import jalview.viewmodel.ViewportListenerI;
36 import jalview.viewmodel.ViewportRanges;
38 import java.awt.AlphaComposite;
39 import java.awt.Color;
40 import java.awt.Dimension;
41 import java.awt.FontMetrics;
42 import java.awt.Graphics;
43 import java.awt.Graphics2D;
44 import java.awt.Image;
45 import java.awt.Rectangle;
46 import java.awt.RenderingHints;
47 import java.awt.event.ActionEvent;
48 import java.awt.event.ActionListener;
49 import java.awt.event.AdjustmentEvent;
50 import java.awt.event.AdjustmentListener;
51 import java.awt.event.MouseEvent;
52 import java.awt.event.MouseListener;
53 import java.awt.event.MouseMotionListener;
54 import java.awt.event.MouseWheelEvent;
55 import java.awt.event.MouseWheelListener;
56 import java.awt.image.BufferedImage;
57 import java.beans.PropertyChangeEvent;
58 import java.util.ArrayList;
59 import java.util.Collections;
60 import java.util.List;
62 import javax.swing.JColorChooser;
63 import javax.swing.JMenuItem;
64 import javax.swing.JPanel;
65 import javax.swing.JPopupMenu;
66 import javax.swing.Scrollable;
67 import javax.swing.ToolTipManager;
70 * AnnotationPanel displays visible portion of annotation rows below unwrapped
76 public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
77 MouseListener, MouseWheelListener, MouseMotionListener,
78 ActionListener, AdjustmentListener, Scrollable, ViewportListenerI
80 String HELIX = MessageManager.getString("label.helix");
82 String SHEET = MessageManager.getString("label.sheet");
85 * For RNA secondary structure "stems" aka helices
87 String STEM = MessageManager.getString("label.rna_helix");
89 String LABEL = MessageManager.getString("label.label");
91 String REMOVE = MessageManager.getString("label.remove_annotation");
93 String COLOUR = MessageManager.getString("action.colour");
95 public final Color HELIX_COLOUR = Color.red.darker();
97 public final Color SHEET_COLOUR = Color.green.darker().darker();
99 public final Color STEM_COLOUR = Color.blue.darker();
102 public AlignViewport av;
106 public int activeRow = -1;
108 public BufferedImage image;
110 public volatile BufferedImage fadedImage;
114 public FontMetrics fm;
116 public int imgWidth = 0;
118 boolean fastPaint = false;
120 // Used For mouse Dragging and resizing graphs
121 int graphStretch = -1;
123 int graphStretchY = -1;
125 int min; // used by mouseDragged to see if user
127 int max; // used by mouseDragged to see if user
129 boolean mouseDragging = false;
131 // for editing cursor
136 public final AnnotationRenderer renderer;
138 private MouseWheelListener[] _mwl;
141 * Creates a new AnnotationPanel object.
146 public AnnotationPanel(AlignmentPanel ap)
148 ToolTipManager.sharedInstance().registerComponent(this);
149 ToolTipManager.sharedInstance().setInitialDelay(0);
150 ToolTipManager.sharedInstance().setDismissDelay(10000);
153 this.setLayout(null);
154 addMouseListener(this);
155 addMouseMotionListener(this);
156 ap.annotationScroller.getVerticalScrollBar()
157 .addAdjustmentListener(this);
158 // save any wheel listeners on the scroller, so we can propagate scroll
160 _mwl = ap.annotationScroller.getMouseWheelListeners();
161 // and then set our own listener to consume all mousewheel events
162 ap.annotationScroller.addMouseWheelListener(this);
163 renderer = new AnnotationRenderer();
165 av.getRanges().addPropertyChangeListener(this);
168 public AnnotationPanel(AlignViewport av)
171 renderer = new AnnotationRenderer();
175 public void mouseWheelMoved(MouseWheelEvent e)
180 double wheelRotation = e.getPreciseWheelRotation();
181 if (wheelRotation > 0)
183 av.getRanges().scrollRight(true);
185 else if (wheelRotation < 0)
187 av.getRanges().scrollRight(false);
192 // TODO: find the correct way to let the event bubble up to
193 // ap.annotationScroller
194 for (MouseWheelListener mwl : _mwl)
198 mwl.mouseWheelMoved(e);
209 public Dimension getPreferredScrollableViewportSize()
211 Dimension ps = getPreferredSize();
212 return new Dimension(ps.width, adjustForAlignFrame(false, ps.height));
216 public int getScrollableBlockIncrement(Rectangle visibleRect,
217 int orientation, int direction)
223 public boolean getScrollableTracksViewportHeight()
229 public boolean getScrollableTracksViewportWidth()
235 public int getScrollableUnitIncrement(Rectangle visibleRect,
236 int orientation, int direction)
245 * java.awt.event.AdjustmentListener#adjustmentValueChanged(java.awt.event
249 public void adjustmentValueChanged(AdjustmentEvent evt)
251 // update annotation label display
252 ap.getAlabels().setScrollOffset(-evt.getValue());
256 * Calculates the height of the annotation displayed in the annotation panel.
257 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
258 * all annotation associated components are updated correctly.
261 public int adjustPanelHeight()
263 int height = av.calcPanelHeight();
264 this.setPreferredSize(new Dimension(1, height));
267 // revalidate only when the alignment panel is fully constructed
281 public void actionPerformed(ActionEvent evt)
283 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
288 Annotation[] anot = aa[activeRow].annotations;
290 if (anot.length < av.getColumnSelection().getMax())
292 Annotation[] temp = new Annotation[av.getColumnSelection().getMax()
294 System.arraycopy(anot, 0, temp, 0, anot.length);
296 aa[activeRow].annotations = anot;
299 String action = evt.getActionCommand();
300 if (action.equals(REMOVE))
302 for (int index : av.getColumnSelection().getSelected())
304 if (av.getAlignment().getHiddenColumns().isVisible(index))
310 else if (action.equals(LABEL))
312 String exMesg = collectAnnotVals(anot, LABEL);
313 String label = JvOptionPane.showInputDialog(this,
314 MessageManager.getString("label.enter_label"), exMesg);
321 if ((label.length() > 0) && !aa[activeRow].hasText)
323 aa[activeRow].hasText = true;
326 for (int index : av.getColumnSelection().getSelected())
328 if (!av.getAlignment().getHiddenColumns().isVisible(index))
333 if (anot[index] == null)
335 anot[index] = new Annotation(label, "", ' ', 0);
339 anot[index].displayCharacter = label;
343 else if (action.equals(COLOUR))
345 Color col = JColorChooser.showDialog(this,
346 MessageManager.getString("label.select_foreground_colour"),
349 for (int index : av.getColumnSelection().getSelected())
351 if (!av.getAlignment().getHiddenColumns().isVisible(index))
356 if (anot[index] == null)
358 anot[index] = new Annotation("", "", ' ', 0);
361 anot[index].colour = col;
365 // HELIX, SHEET or STEM
368 String symbol = "\u03B1"; // alpha
370 if (action.equals(HELIX))
374 else if (action.equals(SHEET))
377 symbol = "\u03B2"; // beta
380 // Added by LML to color stems
381 else if (action.equals(STEM))
384 int column = av.getColumnSelection().getSelectedRanges().get(0)[0];
385 symbol = aa[activeRow].getDefaultRnaHelixSymbol(column);
388 if (!aa[activeRow].hasIcons)
390 aa[activeRow].hasIcons = true;
393 String label = JvOptionPane.showInputDialog(MessageManager
394 .getString("label.enter_label_for_the_structure"), symbol);
401 if ((label.length() > 0) && !aa[activeRow].hasText)
403 aa[activeRow].hasText = true;
404 if (action.equals(STEM))
406 aa[activeRow].showAllColLabels = true;
409 for (int index : av.getColumnSelection().getSelected())
411 if (!av.getAlignment().getHiddenColumns().isVisible(index))
416 if (anot[index] == null)
418 anot[index] = new Annotation(label, "", type, 0);
421 anot[index].secondaryStructure = type != 'S' ? type
422 : label.length() == 0 ? ' ' : label.charAt(0);
423 anot[index].displayCharacter = label;
428 av.getAlignment().validateAnnotation(aa[activeRow]);
429 ap.alignmentChanged();
430 ap.alignFrame.setMenusForViewport();
438 * Returns any existing annotation concatenated as a string. For each
439 * annotation, takes the description, if any, else the secondary structure
440 * character (if type is HELIX, SHEET or STEM), else the display character (if
447 private String collectAnnotVals(Annotation[] anots, String type)
449 // TODO is this method wanted? why? 'last' is not used
451 StringBuilder collatedInput = new StringBuilder(64);
453 ColumnSelection viscols = av.getColumnSelection();
454 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
457 * the selection list (read-only view) is in selection order, not
458 * column order; make a copy so we can sort it
460 List<Integer> selected = new ArrayList<>(viscols.getSelected());
461 Collections.sort(selected);
462 for (int index : selected)
464 // always check for current display state - just in case
465 if (!hidden.isVisible(index))
469 String tlabel = null;
470 if (anots[index] != null)
471 { // LML added stem code
472 if (type.equals(HELIX) || type.equals(SHEET) || type.equals(STEM)
473 || type.equals(LABEL))
475 tlabel = anots[index].description;
476 if (tlabel == null || tlabel.length() < 1)
478 if (type.equals(HELIX) || type.equals(SHEET)
479 || type.equals(STEM))
481 tlabel = "" + anots[index].secondaryStructure;
485 tlabel = "" + anots[index].displayCharacter;
489 if (tlabel != null && !tlabel.equals(last))
491 if (last.length() > 0)
493 collatedInput.append(" ");
495 collatedInput.append(tlabel);
499 return collatedInput.toString();
509 public void mousePressed(MouseEvent evt)
512 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
521 final int y = evt.getY();
522 for (int i = 0; i < aa.length; i++)
526 height += aa[i].height;
535 else if (aa[i].graph > 0)
547 * isPopupTrigger fires in mousePressed on Mac,
548 * not until mouseRelease on Windows
550 if (evt.isPopupTrigger() && activeRow != -1)
552 showPopupMenu(y, evt.getX());
556 ap.getScalePanel().mousePressed(evt);
560 * Construct and display a context menu at the right-click position
565 void showPopupMenu(final int y, int x)
567 if (av.getColumnSelection() == null
568 || av.getColumnSelection().isEmpty())
573 JPopupMenu pop = new JPopupMenu(
574 MessageManager.getString("label.structure_type"));
577 * Just display the needed structure options
579 if (av.getAlignment().isNucleotide())
581 item = new JMenuItem(STEM);
582 item.addActionListener(this);
587 item = new JMenuItem(HELIX);
588 item.addActionListener(this);
590 item = new JMenuItem(SHEET);
591 item.addActionListener(this);
594 item = new JMenuItem(LABEL);
595 item.addActionListener(this);
597 item = new JMenuItem(COLOUR);
598 item.addActionListener(this);
600 item = new JMenuItem(REMOVE);
601 item.addActionListener(this);
603 pop.show(this, x, y);
613 public void mouseReleased(MouseEvent evt)
617 mouseDragging = false;
618 ap.getScalePanel().mouseReleased(evt);
621 * isPopupTrigger is set in mouseReleased on Windows
622 * (in mousePressed on Mac)
624 if (evt.isPopupTrigger() && activeRow != -1)
626 showPopupMenu(evt.getY(), evt.getX());
638 public void mouseEntered(MouseEvent evt)
640 ap.getScalePanel().mouseEntered(evt);
650 public void mouseExited(MouseEvent evt)
652 ap.getScalePanel().mouseExited(evt);
662 public void mouseDragged(MouseEvent evt)
664 if (graphStretch > -1)
667 .getAlignmentAnnotation()[graphStretch].graphHeight += graphStretchY
669 if (av.getAlignment()
670 .getAlignmentAnnotation()[graphStretch].graphHeight < 0)
673 .getAlignmentAnnotation()[graphStretch].graphHeight = 0;
675 graphStretchY = evt.getY();
677 ap.paintAlignment(false, false);
681 ap.getScalePanel().mouseDragged(evt);
686 * Constructs the tooltip, and constructs and displays a status message, for
687 * the current mouse position
692 public void mouseMoved(MouseEvent evt)
694 int yPos = evt.getY();
695 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
697 int row = getRowIndex(yPos, aa);
701 this.setToolTipText(null);
705 int column = (evt.getX() / av.getCharWidth())
706 + av.getRanges().getStartRes();
708 if (av.hasHiddenColumns())
710 column = av.getAlignment().getHiddenColumns()
711 .visibleToAbsoluteColumn(column);
714 AlignmentAnnotation ann = aa[row];
715 if (row > -1 && ann.annotations != null
716 && column < ann.annotations.length)
718 setToolTipText(buildToolTip(ann, column, aa));
719 String msg = getStatusMessage(av.getAlignment(), column, ann);
720 ap.alignFrame.statusBar.setText(msg);
724 this.setToolTipText(null);
725 ap.alignFrame.statusBar.setText(" ");
730 * Answers the index in the annotations array of the visible annotation at the
731 * given y position. This is done by adding the heights of visible annotations
732 * until the y position has been exceeded. Answers -1 if no annotations are
733 * visible, or the y position is below all annotations.
739 static int getRowIndex(int yPos, AlignmentAnnotation[] aa)
748 for (int i = 0; i < aa.length; i++)
752 height += aa[i].height;
765 * Answers a tooltip for the annotation at the current mouse position
771 static String buildToolTip(AlignmentAnnotation ann, int column,
772 AlignmentAnnotation[] anns)
774 String tooltip = null;
775 if (ann.graphGroup > -1)
777 StringBuilder tip = new StringBuilder(32);
778 tip.append("<html>");
779 for (int i = 0; i < anns.length; i++)
781 if (anns[i].graphGroup == ann.graphGroup
782 && anns[i].annotations[column] != null)
784 tip.append(anns[i].label);
785 String description = anns[i].annotations[column].description;
786 if (description != null && description.length() > 0)
788 tip.append(" ").append(description);
793 if (tip.length() != 6)
795 tip.setLength(tip.length() - 4);
796 tooltip = tip.toString() + "</html>";
799 else if (column < ann.annotations.length
800 && ann.annotations[column] != null)
802 String description = ann.annotations[column].description;
803 if (description != null && description.length() > 0)
805 tooltip = JvSwingUtils.wrapTooltip(true, description);
809 tooltip = null; // no tooltip if null or empty description
814 // clear the tooltip.
821 * Constructs and returns the status bar message
827 static String getStatusMessage(AlignmentI al, int column,
828 AlignmentAnnotation ann)
831 * show alignment column and annotation description if any
833 StringBuilder text = new StringBuilder(32);
834 text.append(MessageManager.getString("label.column")).append(" ")
837 if (column < ann.annotations.length && ann.annotations[column] != null)
839 String description = ann.annotations[column].description;
840 if (description != null && description.trim().length() > 0)
842 text.append(" ").append(description);
847 * if the annotation is sequence-specific, show the sequence number
848 * in the alignment, and (if not a gap) the residue and position
850 SequenceI seqref = ann.sequenceRef;
853 int seqIndex = al.findIndex(seqref);
856 text.append(", ").append(MessageManager.getString("label.sequence"))
857 .append(" ").append(seqIndex + 1);
858 char residue = seqref.getCharAt(column);
859 if (!Comparison.isGap(residue))
863 if (al.isNucleotide())
865 name = ResidueProperties.nucleotideName
866 .get(String.valueOf(residue));
867 text.append(" Nucleotide: ")
868 .append(name != null ? name : residue);
872 name = 'X' == residue ? "X"
873 : ('*' == residue ? "STOP"
874 : ResidueProperties.aa2Triplet
875 .get(String.valueOf(residue)));
876 text.append(" Residue: ").append(name != null ? name : residue);
878 int residuePos = seqref.findPosition(column);
879 text.append(" (").append(residuePos).append(")");
884 return text.toString();
894 public void mouseClicked(MouseEvent evt)
896 // if (activeRow != -1)
898 // AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
899 // AlignmentAnnotation anot = aa[activeRow];
903 // TODO mouseClicked-content and drawCursor are quite experimental!
904 public void drawCursor(Graphics graphics, SequenceI seq, int res, int x1,
907 int pady = av.getCharHeight() / 5;
909 graphics.setColor(Color.black);
910 graphics.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight());
912 if (av.validCharWidth)
914 graphics.setColor(Color.white);
916 char s = seq.getCharAt(res);
918 charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
919 graphics.drawString(String.valueOf(s), charOffset + x1,
920 (y1 + av.getCharHeight()) - pady);
925 private volatile boolean imageFresh = false;
934 public void paintComponent(Graphics g)
936 super.paintComponent(g);
938 g.setColor(Color.white);
939 g.fillRect(0, 0, getWidth(), getHeight());
943 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
944 || (getVisibleRect().height != g.getClipBounds().height))
946 g.drawImage(image, 0, 0, this);
951 imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes()
952 + 1) * av.getCharWidth();
957 if (image == null || imgWidth != image.getWidth(this)
958 || image.getHeight(this) != getHeight())
962 image = new BufferedImage(imgWidth,
963 ap.getAnnotationPanel().getHeight(),
964 BufferedImage.TYPE_INT_RGB);
965 } catch (OutOfMemoryError oom)
970 } catch (Exception x)
975 "Couldn't allocate memory to redraw screen. Please restart Jalview",
979 gg = (Graphics2D) image.getGraphics();
983 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
984 RenderingHints.VALUE_ANTIALIAS_ON);
987 gg.setFont(av.getFont());
988 fm = gg.getFontMetrics();
989 gg.setColor(Color.white);
990 gg.fillRect(0, 0, imgWidth, image.getHeight());
994 drawComponent(gg, av.getRanges().getStartRes(),
995 av.getRanges().getEndRes() + 1);
997 g.drawImage(image, 0, 0, this);
1001 * set true to enable redraw timing debug output on stderr
1003 private final boolean debugRedraw = false;
1006 * non-Thread safe repaint
1009 * repaint with horizontal shift in alignment
1011 public void fastPaint(int horizontal)
1013 if ((horizontal == 0) || gg == null
1014 || av.getAlignment().getAlignmentAnnotation() == null
1015 || av.getAlignment().getAlignmentAnnotation().length < 1
1016 || av.isCalcInProgress())
1022 int sr = av.getRanges().getStartRes();
1023 int er = av.getRanges().getEndRes() + 1;
1026 gg.copyArea(0, 0, imgWidth, getHeight(),
1027 -horizontal * av.getCharWidth(), 0);
1029 if (horizontal > 0) // scrollbar pulled right, image to the left
1031 transX = (er - sr - horizontal) * av.getCharWidth();
1032 sr = er - horizontal;
1034 else if (horizontal < 0)
1036 er = sr - horizontal;
1039 gg.translate(transX, 0);
1041 drawComponent(gg, sr, er);
1043 gg.translate(-transX, 0);
1047 // Call repaint on alignment panel so that repaints from other alignment
1048 // panel components can be aggregated. Otherwise performance of the overview
1049 // window and others may be adversely affected.
1050 av.getAlignPanel().repaint();
1053 private volatile boolean lastImageGood = false;
1065 public void drawComponent(Graphics g, int startRes, int endRes)
1067 BufferedImage oldFaded = fadedImage;
1068 if (av.isCalcInProgress())
1072 lastImageGood = false;
1075 // We'll keep a record of the old image,
1076 // and draw a faded image until the calculation
1079 && (fadedImage == null || fadedImage.getWidth() != imgWidth
1080 || fadedImage.getHeight() != image.getHeight()))
1082 // System.err.println("redraw faded image ("+(fadedImage==null ?
1083 // "null image" : "") + " lastGood="+lastImageGood+")");
1084 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
1085 BufferedImage.TYPE_INT_RGB);
1087 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
1089 fadedG.setColor(Color.white);
1090 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
1092 fadedG.setComposite(
1093 AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .3f));
1094 fadedG.drawImage(image, 0, 0, this);
1097 // make sure we don't overwrite the last good faded image until all
1098 // calculations have finished
1099 lastImageGood = false;
1104 if (fadedImage != null)
1106 oldFaded = fadedImage;
1111 g.setColor(Color.white);
1112 g.fillRect(0, 0, (endRes - startRes) * av.getCharWidth(), getHeight());
1114 g.setFont(av.getFont());
1117 fm = g.getFontMetrics();
1120 if ((av.getAlignment().getAlignmentAnnotation() == null)
1121 || (av.getAlignment().getAlignmentAnnotation().length < 1))
1123 g.setColor(Color.white);
1124 g.fillRect(0, 0, getWidth(), getHeight());
1125 g.setColor(Color.black);
1126 if (av.validCharWidth)
1128 g.drawString(MessageManager
1129 .getString("label.alignment_has_no_annotations"), 20, 15);
1134 lastImageGood = renderer.drawComponent(this, av, g, activeRow, startRes,
1136 if (!lastImageGood && fadedImage == null)
1138 fadedImage = oldFaded;
1143 public FontMetrics getFontMetrics()
1149 public Image getFadedImage()
1155 public int getFadedImageWidth()
1160 private int[] bounds = new int[2];
1163 public int[] getVisibleVRange()
1165 if (ap != null && ap.getAlabels() != null)
1167 int sOffset = -ap.getAlabels().getScrollOffset();
1168 int visHeight = sOffset + ap.annotationSpaceFillerHolder.getHeight();
1169 bounds[0] = sOffset;
1170 bounds[1] = visHeight;
1180 * Try to ensure any references held are nulled
1182 public void dispose()
1192 * I created the renderer so I will dispose of it
1194 if (renderer != null)
1201 public void propertyChange(PropertyChangeEvent evt)
1203 // Respond to viewport range changes (e.g. alignment panel was scrolled)
1204 // Both scrolling and resizing change viewport ranges: scrolling changes
1205 // both start and end points, but resize only changes end values.
1206 // Here we only want to fastpaint on a scroll, with resize using a normal
1207 // paint, so scroll events are identified as changes to the horizontal or
1208 // vertical start value.
1209 if (evt.getPropertyName().equals(ViewportRanges.STARTRES))
1211 fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
1213 else if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ))
1215 fastPaint(((int[]) evt.getNewValue())[0]
1216 - ((int[]) evt.getOldValue())[0]);
1218 else if (evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT))
1225 * computes the visible height of the annotation panel
1227 * @param adjustPanelHeight
1228 * - when false, just adjust existing height according to other
1230 * @param annotationHeight
1231 * @return height to use for the ScrollerPreferredVisibleSize
1233 public int adjustForAlignFrame(boolean adjustPanelHeight,
1234 int annotationHeight)
1237 * Estimate available height in the AlignFrame for alignment +
1238 * annotations. Deduct an estimate for title bar, menu bar, scale panel,
1239 * hscroll, status bar, insets.
1241 int stuff = (ap.getViewName() != null ? 30 : 0)
1242 + (Platform.isAMac() ? 120 : 140);
1243 int availableHeight = ap.alignFrame.getHeight() - stuff;
1244 int rowHeight = av.getCharHeight();
1246 if (adjustPanelHeight)
1248 int alignmentHeight = rowHeight * av.getAlignment().getHeight();
1251 * If not enough vertical space, maximize annotation height while keeping
1252 * at least two rows of alignment visible
1254 if (annotationHeight + alignmentHeight > availableHeight)
1256 annotationHeight = Math.min(annotationHeight,
1257 availableHeight - 2 * rowHeight);
1262 // maintain same window layout whilst updating sliders
1263 annotationHeight = Math.min(ap.annotationScroller.getSize().height,
1264 availableHeight - 2 * rowHeight);
1266 return annotationHeight;