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();
707 column = Math.min(column, av.getRanges().getEndRes());
709 if (av.hasHiddenColumns())
711 column = av.getAlignment().getHiddenColumns()
712 .visibleToAbsoluteColumn(column);
715 AlignmentAnnotation ann = aa[row];
716 if (row > -1 && ann.annotations != null
717 && column < ann.annotations.length)
719 setToolTipText(buildToolTip(ann, column, aa));
720 String msg = getStatusMessage(av.getAlignment(), column, ann);
721 ap.alignFrame.setStatus(msg);
725 this.setToolTipText(null);
726 ap.alignFrame.setStatus(" ");
731 * Answers the index in the annotations array of the visible annotation at the
732 * given y position. This is done by adding the heights of visible annotations
733 * until the y position has been exceeded. Answers -1 if no annotations are
734 * visible, or the y position is below all annotations.
740 static int getRowIndex(int yPos, AlignmentAnnotation[] aa)
749 for (int i = 0; i < aa.length; i++)
753 height += aa[i].height;
766 * Answers a tooltip for the annotation at the current mouse position
772 static String buildToolTip(AlignmentAnnotation ann, int column,
773 AlignmentAnnotation[] anns)
775 String tooltip = null;
776 if (ann.graphGroup > -1)
778 StringBuilder tip = new StringBuilder(32);
779 tip.append("<html>");
780 for (int i = 0; i < anns.length; i++)
782 if (anns[i].graphGroup == ann.graphGroup
783 && anns[i].annotations[column] != null)
785 tip.append(anns[i].label);
786 String description = anns[i].annotations[column].description;
787 if (description != null && description.length() > 0)
789 tip.append(" ").append(description);
794 if (tip.length() != 6)
796 tip.setLength(tip.length() - 4);
797 tooltip = tip.toString() + "</html>";
800 else if (column < ann.annotations.length
801 && ann.annotations[column] != null)
803 String description = ann.annotations[column].description;
804 if (description != null && description.length() > 0)
806 tooltip = JvSwingUtils.wrapTooltip(true, description);
810 tooltip = null; // no tooltip if null or empty description
815 // clear the tooltip.
822 * Constructs and returns the status bar message
828 static String getStatusMessage(AlignmentI al, int column,
829 AlignmentAnnotation ann)
832 * show alignment column and annotation description if any
834 StringBuilder text = new StringBuilder(32);
835 text.append(MessageManager.getString("label.column")).append(" ")
838 if (column < ann.annotations.length && ann.annotations[column] != null)
840 String description = ann.annotations[column].description;
841 if (description != null && description.trim().length() > 0)
843 text.append(" ").append(description);
848 * if the annotation is sequence-specific, show the sequence number
849 * in the alignment, and (if not a gap) the residue and position
851 SequenceI seqref = ann.sequenceRef;
854 int seqIndex = al.findIndex(seqref);
857 text.append(", ").append(MessageManager.getString("label.sequence"))
858 .append(" ").append(seqIndex + 1);
859 char residue = seqref.getCharAt(column);
860 if (!Comparison.isGap(residue))
864 if (al.isNucleotide())
866 name = ResidueProperties.nucleotideName
867 .get(String.valueOf(residue));
868 text.append(" Nucleotide: ")
869 .append(name != null ? name : residue);
873 name = 'X' == residue ? "X"
874 : ('*' == residue ? "STOP"
875 : ResidueProperties.aa2Triplet
876 .get(String.valueOf(residue)));
877 text.append(" Residue: ").append(name != null ? name : residue);
879 int residuePos = seqref.findPosition(column);
880 text.append(" (").append(residuePos).append(")");
885 return text.toString();
895 public void mouseClicked(MouseEvent evt)
897 // if (activeRow != -1)
899 // AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
900 // AlignmentAnnotation anot = aa[activeRow];
904 // TODO mouseClicked-content and drawCursor are quite experimental!
905 public void drawCursor(Graphics graphics, SequenceI seq, int res, int x1,
908 int pady = av.getCharHeight() / 5;
910 graphics.setColor(Color.black);
911 graphics.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight());
913 if (av.validCharWidth)
915 graphics.setColor(Color.white);
917 char s = seq.getCharAt(res);
919 charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
920 graphics.drawString(String.valueOf(s), charOffset + x1,
921 (y1 + av.getCharHeight()) - pady);
926 private volatile boolean imageFresh = false;
935 public void paintComponent(Graphics g)
937 super.paintComponent(g);
939 g.setColor(Color.white);
940 g.fillRect(0, 0, getWidth(), getHeight());
944 if (fastPaint || (getVisibleRect().width != g.getClipBounds().width)
945 || (getVisibleRect().height != g.getClipBounds().height))
947 g.drawImage(image, 0, 0, this);
952 imgWidth = (av.getRanges().getEndRes() - av.getRanges().getStartRes()
953 + 1) * av.getCharWidth();
958 if (image == null || imgWidth != image.getWidth(this)
959 || image.getHeight(this) != getHeight())
963 image = new BufferedImage(imgWidth,
964 ap.getAnnotationPanel().getHeight(),
965 BufferedImage.TYPE_INT_RGB);
966 } catch (OutOfMemoryError oom)
971 } catch (Exception x)
976 "Couldn't allocate memory to redraw screen. Please restart Jalview",
980 gg = (Graphics2D) image.getGraphics();
984 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
985 RenderingHints.VALUE_ANTIALIAS_ON);
988 gg.setFont(av.getFont());
989 fm = gg.getFontMetrics();
990 gg.setColor(Color.white);
991 gg.fillRect(0, 0, imgWidth, image.getHeight());
995 drawComponent(gg, av.getRanges().getStartRes(),
996 av.getRanges().getEndRes() + 1);
998 g.drawImage(image, 0, 0, this);
1002 * set true to enable redraw timing debug output on stderr
1004 private final boolean debugRedraw = false;
1007 * non-Thread safe repaint
1010 * repaint with horizontal shift in alignment
1012 public void fastPaint(int horizontal)
1014 if ((horizontal == 0) || gg == null
1015 || av.getAlignment().getAlignmentAnnotation() == null
1016 || av.getAlignment().getAlignmentAnnotation().length < 1
1017 || av.isCalcInProgress())
1023 int sr = av.getRanges().getStartRes();
1024 int er = av.getRanges().getEndRes() + 1;
1027 gg.copyArea(0, 0, imgWidth, getHeight(),
1028 -horizontal * av.getCharWidth(), 0);
1030 if (horizontal > 0) // scrollbar pulled right, image to the left
1032 transX = (er - sr - horizontal) * av.getCharWidth();
1033 sr = er - horizontal;
1035 else if (horizontal < 0)
1037 er = sr - horizontal;
1040 gg.translate(transX, 0);
1042 drawComponent(gg, sr, er);
1044 gg.translate(-transX, 0);
1048 // Call repaint on alignment panel so that repaints from other alignment
1049 // panel components can be aggregated. Otherwise performance of the overview
1050 // window and others may be adversely affected.
1051 av.getAlignPanel().repaint();
1054 private volatile boolean lastImageGood = false;
1066 public void drawComponent(Graphics g, int startRes, int endRes)
1068 BufferedImage oldFaded = fadedImage;
1069 if (av.isCalcInProgress())
1073 lastImageGood = false;
1076 // We'll keep a record of the old image,
1077 // and draw a faded image until the calculation
1080 && (fadedImage == null || fadedImage.getWidth() != imgWidth
1081 || fadedImage.getHeight() != image.getHeight()))
1083 // System.err.println("redraw faded image ("+(fadedImage==null ?
1084 // "null image" : "") + " lastGood="+lastImageGood+")");
1085 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
1086 BufferedImage.TYPE_INT_RGB);
1088 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
1090 fadedG.setColor(Color.white);
1091 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
1093 fadedG.setComposite(
1094 AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .3f));
1095 fadedG.drawImage(image, 0, 0, this);
1098 // make sure we don't overwrite the last good faded image until all
1099 // calculations have finished
1100 lastImageGood = false;
1105 if (fadedImage != null)
1107 oldFaded = fadedImage;
1112 g.setColor(Color.white);
1113 g.fillRect(0, 0, (endRes - startRes) * av.getCharWidth(), getHeight());
1115 g.setFont(av.getFont());
1118 fm = g.getFontMetrics();
1121 if ((av.getAlignment().getAlignmentAnnotation() == null)
1122 || (av.getAlignment().getAlignmentAnnotation().length < 1))
1124 g.setColor(Color.white);
1125 g.fillRect(0, 0, getWidth(), getHeight());
1126 g.setColor(Color.black);
1127 if (av.validCharWidth)
1129 g.drawString(MessageManager
1130 .getString("label.alignment_has_no_annotations"), 20, 15);
1135 lastImageGood = renderer.drawComponent(this, av, g, activeRow, startRes,
1137 if (!lastImageGood && fadedImage == null)
1139 fadedImage = oldFaded;
1144 public FontMetrics getFontMetrics()
1150 public Image getFadedImage()
1156 public int getFadedImageWidth()
1161 private int[] bounds = new int[2];
1164 public int[] getVisibleVRange()
1166 if (ap != null && ap.getAlabels() != null)
1168 int sOffset = -ap.getAlabels().getScrollOffset();
1169 int visHeight = sOffset + ap.annotationSpaceFillerHolder.getHeight();
1170 bounds[0] = sOffset;
1171 bounds[1] = visHeight;
1181 * Try to ensure any references held are nulled
1183 public void dispose()
1193 * I created the renderer so I will dispose of it
1195 if (renderer != null)
1202 public void propertyChange(PropertyChangeEvent evt)
1204 // Respond to viewport range changes (e.g. alignment panel was scrolled)
1205 // Both scrolling and resizing change viewport ranges: scrolling changes
1206 // both start and end points, but resize only changes end values.
1207 // Here we only want to fastpaint on a scroll, with resize using a normal
1208 // paint, so scroll events are identified as changes to the horizontal or
1209 // vertical start value.
1210 if (evt.getPropertyName().equals(ViewportRanges.STARTRES))
1212 fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
1214 else if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ))
1216 fastPaint(((int[]) evt.getNewValue())[0]
1217 - ((int[]) evt.getOldValue())[0]);
1219 else if (evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT))
1226 * computes the visible height of the annotation panel
1228 * @param adjustPanelHeight
1229 * - when false, just adjust existing height according to other
1231 * @param annotationHeight
1232 * @return height to use for the ScrollerPreferredVisibleSize
1234 public int adjustForAlignFrame(boolean adjustPanelHeight,
1235 int annotationHeight)
1238 * Estimate available height in the AlignFrame for alignment +
1239 * annotations. Deduct an estimate for title bar, menu bar, scale panel,
1240 * hscroll, status bar, insets.
1242 int stuff = (ap.getViewName() != null ? 30 : 0)
1243 + (Platform.isAMac() ? 120 : 140);
1244 int availableHeight = ap.alignFrame.getHeight() - stuff;
1245 int rowHeight = av.getCharHeight();
1247 if (adjustPanelHeight)
1249 int alignmentHeight = rowHeight * av.getAlignment().getHeight();
1252 * If not enough vertical space, maximize annotation height while keeping
1253 * at least two rows of alignment visible
1255 if (annotationHeight + alignmentHeight > availableHeight)
1257 annotationHeight = Math.min(annotationHeight,
1258 availableHeight - 2 * rowHeight);
1263 // maintain same window layout whilst updating sliders
1264 annotationHeight = Math.min(ap.annotationScroller.getSize().height,
1265 availableHeight - 2 * rowHeight);
1267 return annotationHeight;