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 java.awt.AlphaComposite;
24 import java.awt.Color;
25 import java.awt.Dimension;
26 import java.awt.FontMetrics;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.Image;
30 import java.awt.Rectangle;
31 import java.awt.RenderingHints;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.AdjustmentEvent;
35 import java.awt.event.AdjustmentListener;
36 import java.awt.event.MouseEvent;
37 import java.awt.event.MouseListener;
38 import java.awt.event.MouseMotionListener;
39 import java.awt.event.MouseWheelEvent;
40 import java.awt.event.MouseWheelListener;
41 import java.awt.image.BufferedImage;
42 import java.beans.PropertyChangeEvent;
43 import java.util.ArrayList;
44 import java.util.Collections;
45 import java.util.List;
47 import javax.swing.JMenuItem;
48 import javax.swing.JPanel;
49 import javax.swing.JPopupMenu;
50 import javax.swing.Scrollable;
51 import javax.swing.ToolTipManager;
53 import jalview.datamodel.AlignmentAnnotation;
54 import jalview.datamodel.AlignmentI;
55 import jalview.datamodel.Annotation;
56 import jalview.datamodel.ColumnSelection;
57 import jalview.datamodel.HiddenColumns;
58 import jalview.datamodel.SequenceI;
59 import jalview.gui.JalviewColourChooser.ColourChooserListener;
60 import jalview.renderer.AnnotationRenderer;
61 import jalview.renderer.AwtRenderPanelI;
62 import jalview.schemes.ResidueProperties;
63 import jalview.util.Comparison;
64 import jalview.util.MessageManager;
65 import jalview.util.Platform;
66 import jalview.viewmodel.ViewportListenerI;
67 import jalview.viewmodel.ViewportRanges;
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
82 Select, Resize, Undefined
85 String HELIX = MessageManager.getString("label.helix");
87 String SHEET = MessageManager.getString("label.sheet");
90 * For RNA secondary structure "stems" aka helices
92 String STEM = MessageManager.getString("label.rna_helix");
94 String LABEL = MessageManager.getString("label.label");
96 String REMOVE = MessageManager.getString("label.remove_annotation");
98 String COLOUR = MessageManager.getString("action.colour");
100 public final Color HELIX_COLOUR = Color.red.darker();
102 public final Color SHEET_COLOUR = Color.green.darker().darker();
104 public final Color STEM_COLOUR = Color.blue.darker();
107 public AlignViewport av;
111 public int activeRow = -1;
113 public BufferedImage image;
115 public volatile BufferedImage fadedImage;
117 // private Graphics2D gg;
119 public FontMetrics fm;
121 public int imgWidth = 0;
123 boolean fastPaint = false;
125 // Used For mouse Dragging and resizing graphs
126 int graphStretch = -1;
128 int mouseDragLastX = -1;
130 int mouseDragLastY = -1;
132 DragMode dragMode = DragMode.Undefined;
134 boolean mouseDragging = false;
136 // for editing cursor
141 public final AnnotationRenderer renderer;
143 private MouseWheelListener[] _mwl;
146 * Creates a new AnnotationPanel object.
151 public AnnotationPanel(AlignmentPanel ap)
153 setName("AnnotationPanel");
154 ToolTipManager.sharedInstance().registerComponent(this);
155 ToolTipManager.sharedInstance().setInitialDelay(0);
156 ToolTipManager.sharedInstance().setDismissDelay(10000);
159 this.setLayout(null);
160 addMouseListener(this);
161 addMouseMotionListener(this);
162 ap.annotationScroller.getVerticalScrollBar()
163 .addAdjustmentListener(this);
164 // save any wheel listeners on the scroller, so we can propagate scroll
166 _mwl = ap.annotationScroller.getMouseWheelListeners();
167 // and then set our own listener to consume all mousewheel events
168 ap.annotationScroller.addMouseWheelListener(this);
169 renderer = new AnnotationRenderer();
171 av.getRanges().addPropertyChangeListener(this);
174 public AnnotationPanel(AlignViewport av)
177 renderer = new AnnotationRenderer();
181 public void mouseWheelMoved(MouseWheelEvent e)
186 double wheelRotation = e.getPreciseWheelRotation();
187 if (wheelRotation > 0)
189 av.getRanges().scrollRight(true);
191 else if (wheelRotation < 0)
193 av.getRanges().scrollRight(false);
198 // TODO: find the correct way to let the event bubble up to
199 // ap.annotationScroller
200 for (MouseWheelListener mwl : _mwl)
204 mwl.mouseWheelMoved(e);
215 public Dimension getPreferredScrollableViewportSize()
217 Dimension ps = getPreferredSize();
218 return new Dimension(ps.width, adjustForAlignFrame(false, ps.height));
222 public int getScrollableBlockIncrement(Rectangle visibleRect,
223 int orientation, int direction)
229 public boolean getScrollableTracksViewportHeight()
235 public boolean getScrollableTracksViewportWidth()
241 public int getScrollableUnitIncrement(Rectangle visibleRect,
242 int orientation, int direction)
251 * java.awt.event.AdjustmentListener#adjustmentValueChanged(java.awt.event
255 public void adjustmentValueChanged(AdjustmentEvent evt)
257 // update annotation label display
258 ap.getAlabels().setScrollOffset(-evt.getValue());
262 * Calculates the height of the annotation displayed in the annotation panel.
263 * Callers should normally call the ap.adjustAnnotationHeight method to ensure
264 * all annotation associated components are updated correctly.
267 public int adjustPanelHeight()
269 int height = av.calcPanelHeight();
270 this.setPreferredSize(new Dimension(1, height));
273 // revalidate only when the alignment panel is fully constructed
287 public void actionPerformed(ActionEvent evt)
289 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
294 Annotation[] anot = aa[activeRow].annotations;
296 if (anot.length < av.getColumnSelection().getMax())
298 Annotation[] temp = new Annotation[av.getColumnSelection().getMax()
300 System.arraycopy(anot, 0, temp, 0, anot.length);
302 aa[activeRow].annotations = anot;
305 String action = evt.getActionCommand();
306 if (action.equals(REMOVE))
308 for (int index : av.getColumnSelection().getSelected())
310 if (av.getAlignment().getHiddenColumns().isVisible(index))
316 else if (action.equals(LABEL))
318 String exMesg = collectAnnotVals(anot, LABEL);
319 String label = JvOptionPane.showInputDialog(
320 MessageManager.getString("label.enter_label"), exMesg);
327 if ((label.length() > 0) && !aa[activeRow].hasText)
329 aa[activeRow].hasText = true;
332 for (int index : av.getColumnSelection().getSelected())
334 if (!av.getAlignment().getHiddenColumns().isVisible(index))
339 if (anot[index] == null)
341 anot[index] = new Annotation(label, "", ' ', 0);
345 anot[index].displayCharacter = label;
349 else if (action.equals(COLOUR))
351 final Annotation[] fAnot = anot;
352 String title = MessageManager
353 .getString("label.select_foreground_colour");
354 ColourChooserListener listener = new ColourChooserListener()
357 public void colourSelected(Color c)
359 HiddenColumns hiddenColumns = av.getAlignment()
361 for (int index : av.getColumnSelection().getSelected())
363 if (hiddenColumns.isVisible(index))
365 if (fAnot[index] == null)
367 fAnot[index] = new Annotation("", "", ' ', 0);
369 fAnot[index].colour = c;
374 JalviewColourChooser.showColourChooser(this, title, Color.black,
378 // HELIX, SHEET or STEM
381 String symbol = "\u03B1"; // alpha
383 if (action.equals(HELIX))
387 else if (action.equals(SHEET))
390 symbol = "\u03B2"; // beta
393 // Added by LML to color stems
394 else if (action.equals(STEM))
397 int column = av.getColumnSelection().getSelectedRanges().get(0)[0];
398 symbol = aa[activeRow].getDefaultRnaHelixSymbol(column);
401 if (!aa[activeRow].hasIcons)
403 aa[activeRow].hasIcons = true;
406 String label = JvOptionPane.showInputDialog(MessageManager
407 .getString("label.enter_label_for_the_structure"), symbol);
414 if ((label.length() > 0) && !aa[activeRow].hasText)
416 aa[activeRow].hasText = true;
417 if (action.equals(STEM))
419 aa[activeRow].showAllColLabels = true;
422 for (int index : av.getColumnSelection().getSelected())
424 if (!av.getAlignment().getHiddenColumns().isVisible(index))
429 if (anot[index] == null)
431 anot[index] = new Annotation(label, "", type, 0);
434 anot[index].secondaryStructure = type != 'S' ? type
435 : label.length() == 0 ? ' ' : label.charAt(0);
436 anot[index].displayCharacter = label;
441 av.getAlignment().validateAnnotation(aa[activeRow]);
442 ap.alignmentChanged();
443 ap.alignFrame.setMenusForViewport();
451 * Returns any existing annotation concatenated as a string. For each
452 * annotation, takes the description, if any, else the secondary structure
453 * character (if type is HELIX, SHEET or STEM), else the display character (if
460 private String collectAnnotVals(Annotation[] anots, String type)
462 // TODO is this method wanted? why? 'last' is not used
464 StringBuilder collatedInput = new StringBuilder(64);
466 ColumnSelection viscols = av.getColumnSelection();
467 HiddenColumns hidden = av.getAlignment().getHiddenColumns();
470 * the selection list (read-only view) is in selection order, not
471 * column order; make a copy so we can sort it
473 List<Integer> selected = new ArrayList<>(viscols.getSelected());
474 Collections.sort(selected);
475 for (int index : selected)
477 // always check for current display state - just in case
478 if (!hidden.isVisible(index))
482 String tlabel = null;
483 if (anots[index] != null)
484 { // LML added stem code
485 if (type.equals(HELIX) || type.equals(SHEET) || type.equals(STEM)
486 || type.equals(LABEL))
488 tlabel = anots[index].description;
489 if (tlabel == null || tlabel.length() < 1)
491 if (type.equals(HELIX) || type.equals(SHEET)
492 || type.equals(STEM))
494 tlabel = "" + anots[index].secondaryStructure;
498 tlabel = "" + anots[index].displayCharacter;
502 if (tlabel != null && !tlabel.equals(last))
504 if (last.length() > 0)
506 collatedInput.append(" ");
508 collatedInput.append(tlabel);
512 return collatedInput.toString();
516 * Action on right mouse pressed on Mac is to show a pop-up menu for the
517 * annotation. Action on left mouse pressed is to find which annotation is
518 * pressed and mark the start of a column selection or graph resize operation.
523 public void mousePressed(MouseEvent evt)
526 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
531 mouseDragLastX = evt.getX();
532 mouseDragLastY = evt.getY();
535 * add visible annotation heights until we reach the y
536 * position, to find which annotation it is in
541 final int y = evt.getY();
542 for (int i = 0; i < aa.length; i++)
546 height += aa[i].height;
555 else if (aa[i].graph > 0)
558 * we have clicked on a resizable graph annotation
567 * isPopupTrigger fires in mousePressed on Mac,
568 * not until mouseRelease on Windows
570 if (evt.isPopupTrigger() && activeRow != -1)
572 showPopupMenu(y, evt.getX());
576 ap.getScalePanel().mousePressed(evt);
580 * Construct and display a context menu at the right-click position
585 void showPopupMenu(final int y, int x)
587 if (av.getColumnSelection() == null
588 || av.getColumnSelection().isEmpty())
593 JPopupMenu pop = new JPopupMenu(
594 MessageManager.getString("label.structure_type"));
597 * Just display the needed structure options
599 if (av.getAlignment().isNucleotide())
601 item = new JMenuItem(STEM);
602 item.addActionListener(this);
607 item = new JMenuItem(HELIX);
608 item.addActionListener(this);
610 item = new JMenuItem(SHEET);
611 item.addActionListener(this);
614 item = new JMenuItem(LABEL);
615 item.addActionListener(this);
617 item = new JMenuItem(COLOUR);
618 item.addActionListener(this);
620 item = new JMenuItem(REMOVE);
621 item.addActionListener(this);
623 pop.show(this, x, y);
627 * Action on mouse up is to clear mouse drag data and call mouseReleased on
628 * ScalePanel, to deal with defining the selection group (if any) defined by
634 public void mouseReleased(MouseEvent evt)
639 mouseDragging = false;
640 dragMode = DragMode.Undefined;
641 ap.getScalePanel().mouseReleased(evt);
644 * isPopupTrigger is set in mouseReleased on Windows
645 * (in mousePressed on Mac)
647 if (evt.isPopupTrigger() && activeRow != -1)
649 showPopupMenu(evt.getY(), evt.getX());
661 public void mouseEntered(MouseEvent evt)
663 this.mouseDragging = false;
664 ap.getScalePanel().mouseEntered(evt);
668 * On leaving the panel, calls ScalePanel.mouseExited to deal with scrolling
669 * with column selection on a mouse drag
674 public void mouseExited(MouseEvent evt)
676 ap.getScalePanel().mouseExited(evt);
686 public void mouseDragged(MouseEvent evt)
689 * todo: if dragMode is Undefined:
690 * - set to Select if dx > dy
691 * - set to Resize if dy > dx
692 * - do nothing if dx == dy
694 final int x = evt.getX();
695 final int y = evt.getY();
696 if (dragMode == DragMode.Undefined)
698 int dx = Math.abs(x - mouseDragLastX);
699 int dy = Math.abs(y - mouseDragLastY);
700 if (graphStretch == -1 || dx > dy)
703 * mostly horizontal drag, or not a graph annotation
705 dragMode = DragMode.Select;
710 * mostly vertical drag
712 dragMode = DragMode.Resize;
716 if (dragMode == DragMode.Undefined)
719 * drag is diagonal - defer deciding whether to
720 * treat as up/down or left/right
726 if (dragMode == DragMode.Resize)
729 * resize graph annotation if mouse was dragged up or down
731 int deltaY = mouseDragLastY - evt.getY();
734 AlignmentAnnotation graphAnnotation = av.getAlignment()
735 .getAlignmentAnnotation()[graphStretch];
736 int newHeight = Math.max(0, graphAnnotation.graphHeight + deltaY);
737 graphAnnotation.graphHeight = newHeight;
740 ap.paintAlignment(false, false);
746 * for mouse drag left or right, delegate to
747 * ScalePanel to adjust the column selection
749 ap.getScalePanel().mouseDragged(evt);
759 * Constructs the tooltip, and constructs and displays a status message, for
760 * the current mouse position
765 public void mouseMoved(MouseEvent evt)
767 int yPos = evt.getY();
768 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
770 int row = getRowIndex(yPos, aa);
774 this.setToolTipText(null);
778 int column = (evt.getX() / av.getCharWidth())
779 + av.getRanges().getStartRes();
780 column = Math.min(column, av.getRanges().getEndRes());
782 if (av.hasHiddenColumns())
784 column = av.getAlignment().getHiddenColumns()
785 .visibleToAbsoluteColumn(column);
788 AlignmentAnnotation ann = aa[row];
789 if (row > -1 && ann.annotations != null
790 && column < ann.annotations.length)
792 String toolTip = buildToolTip(ann, column, aa);
793 setToolTipText(toolTip == null ? null
794 : JvSwingUtils.wrapTooltip(true, toolTip));
795 String msg = getStatusMessage(av.getAlignment(), column, ann);
796 ap.alignFrame.setStatus(msg);
800 this.setToolTipText(null);
801 ap.alignFrame.setStatus(" ");
806 * Answers the index in the annotations array of the visible annotation at the
807 * given y position. This is done by adding the heights of visible annotations
808 * until the y position has been exceeded. Answers -1 if no annotations are
809 * visible, or the y position is below all annotations.
815 static int getRowIndex(int yPos, AlignmentAnnotation[] aa)
824 for (int i = 0; i < aa.length; i++)
828 height += aa[i].height;
841 * Answers a tooltip for the annotation at the current mouse position, not
842 * wrapped in <html> tags (apply if wanted). Answers null if there is no
849 static String buildToolTip(AlignmentAnnotation ann, int column,
850 AlignmentAnnotation[] anns)
852 String tooltip = null;
853 if (ann.graphGroup > -1)
855 StringBuilder tip = new StringBuilder(32);
856 boolean first = true;
857 for (int i = 0; i < anns.length; i++)
859 if (anns[i].graphGroup == ann.graphGroup
860 && anns[i].annotations[column] != null)
867 tip.append(anns[i].label);
868 String description = anns[i].annotations[column].description;
869 if (description != null && description.length() > 0)
871 tip.append(" ").append(description);
875 tooltip = first ? null : tip.toString();
877 else if (column < ann.annotations.length
878 && ann.annotations[column] != null)
880 tooltip = ann.annotations[column].description;
881 if ("".equals(tooltip))
891 * Constructs and returns the status bar message
897 static String getStatusMessage(AlignmentI al, int column,
898 AlignmentAnnotation ann)
901 * show alignment column and annotation description if any
903 StringBuilder text = new StringBuilder(32);
904 text.append(MessageManager.getString("label.column")).append(" ")
907 if (column < ann.annotations.length && ann.annotations[column] != null)
909 String description = ann.annotations[column].description;
910 if (description != null && description.trim().length() > 0)
912 text.append(" ").append(description);
917 * if the annotation is sequence-specific, show the sequence number
918 * in the alignment, and (if not a gap) the residue and position
920 SequenceI seqref = ann.sequenceRef;
923 int seqIndex = al.findIndex(seqref);
926 text.append(", ").append(MessageManager.getString("label.sequence"))
927 .append(" ").append(seqIndex + 1);
928 char residue = seqref.getCharAt(column);
929 if (!Comparison.isGap(residue))
933 if (al.isNucleotide())
935 name = ResidueProperties.nucleotideName
936 .get(String.valueOf(residue));
937 text.append(" Nucleotide: ")
938 .append(name != null ? name : residue);
942 name = 'X' == residue ? "X"
943 : ('*' == residue ? "STOP"
944 : ResidueProperties.aa2Triplet
945 .get(String.valueOf(residue)));
946 text.append(" Residue: ").append(name != null ? name : residue);
948 int residuePos = seqref.findPosition(column);
949 text.append(" (").append(residuePos).append(")");
954 return text.toString();
964 public void mouseClicked(MouseEvent evt)
966 // if (activeRow != -1)
968 // AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
969 // AlignmentAnnotation anot = aa[activeRow];
973 // TODO mouseClicked-content and drawCursor are quite experimental!
974 public void drawCursor(Graphics graphics, SequenceI seq, int res, int x1,
977 int pady = av.getCharHeight() / 5;
979 graphics.setColor(Color.black);
980 graphics.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight());
982 if (av.validCharWidth)
984 graphics.setColor(Color.white);
986 char s = seq.getCharAt(res);
988 charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
989 graphics.drawString(String.valueOf(s), charOffset + x1,
990 (y1 + av.getCharHeight()) - pady);
995 private volatile boolean imageFresh = false;
997 private Rectangle visibleRect = new Rectangle(),
998 clipBounds = new Rectangle();
1007 public void paintComponent(Graphics g)
1010 // BH: note that this method is generally recommended to
1011 // call super.paintComponent(g). Otherwise, the children of this
1012 // component will not be rendered. That is not needed here
1013 // because AnnotationPanel does not have any children. It is
1014 // just a JPanel contained in a JViewPort.
1016 computeVisibleRect(visibleRect);
1018 g.setColor(Color.white);
1019 g.fillRect(0, 0, visibleRect.width, visibleRect.height);
1021 ViewportRanges ranges = av.getRanges();
1023 if (allowFastPaint && image != null)
1025 // BH 2018 optimizing generation of new Rectangle().
1027 || (visibleRect.width != (clipBounds = g
1028 .getClipBounds(clipBounds)).width)
1029 || (visibleRect.height != clipBounds.height))
1031 g.drawImage(image, 0, 0, this);
1037 imgWidth = (ranges.getEndRes() - ranges.getStartRes() + 1)
1038 * av.getCharWidth();
1046 if (image == null || imgWidth != image.getWidth(this)
1047 || image.getHeight(this) != getHeight())
1051 image = new BufferedImage(imgWidth,
1052 ap.getAnnotationPanel().getHeight(),
1053 BufferedImage.TYPE_INT_RGB);
1054 } catch (OutOfMemoryError oom)
1059 } catch (Exception x)
1064 "Couldn't allocate memory to redraw screen. Please restart Jalview",
1068 gg = (Graphics2D) image.getGraphics();
1072 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1073 RenderingHints.VALUE_ANTIALIAS_ON);
1076 gg.setFont(av.getFont());
1077 fm = gg.getFontMetrics();
1078 gg.setColor(Color.white);
1079 gg.fillRect(0, 0, imgWidth, image.getHeight());
1084 gg = (Graphics2D) image.getGraphics();
1088 drawComponent(gg, ranges.getStartRes(), av.getRanges().getEndRes() + 1);
1091 g.drawImage(image, 0, 0, this);
1095 * non-Thread safe repaint
1098 * repaint with horizontal shift in alignment
1100 public void fastPaint(int horizontal)
1102 if ((horizontal == 0) || image == null
1103 || av.getAlignment().getAlignmentAnnotation() == null
1104 || av.getAlignment().getAlignmentAnnotation().length < 1
1105 || av.isCalcInProgress())
1111 int sr = av.getRanges().getStartRes();
1112 int er = av.getRanges().getEndRes() + 1;
1121 Graphics2D gg = (Graphics2D) image.getGraphics();
1123 gg.copyArea(0, 0, imgWidth, getHeight(),
1124 -horizontal * av.getCharWidth(), 0);
1126 if (horizontal > 0) // scrollbar pulled right, image to the left
1128 transX = (er - sr - horizontal) * av.getCharWidth();
1129 sr = er - horizontal;
1131 else if (horizontal < 0)
1133 er = sr - horizontal;
1136 gg.translate(transX, 0);
1138 drawComponent(gg, sr, er);
1140 gg.translate(-transX, 0);
1146 // Call repaint on alignment panel so that repaints from other alignment
1147 // panel components can be aggregated. Otherwise performance of the overview
1148 // window and others may be adversely affected.
1149 av.getAlignPanel().repaint();
1152 private volatile boolean lastImageGood = false;
1164 public void drawComponent(Graphics g, int startRes, int endRes)
1166 BufferedImage oldFaded = fadedImage;
1167 if (av.isCalcInProgress())
1171 lastImageGood = false;
1174 // We'll keep a record of the old image,
1175 // and draw a faded image until the calculation
1178 && (fadedImage == null || fadedImage.getWidth() != imgWidth
1179 || fadedImage.getHeight() != image.getHeight()))
1181 // System.err.println("redraw faded image ("+(fadedImage==null ?
1182 // "null image" : "") + " lastGood="+lastImageGood+")");
1183 fadedImage = new BufferedImage(imgWidth, image.getHeight(),
1184 BufferedImage.TYPE_INT_RGB);
1186 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
1188 fadedG.setColor(Color.white);
1189 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
1191 fadedG.setComposite(
1192 AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .3f));
1193 fadedG.drawImage(image, 0, 0, this);
1196 // make sure we don't overwrite the last good faded image until all
1197 // calculations have finished
1198 lastImageGood = false;
1203 if (fadedImage != null)
1205 oldFaded = fadedImage;
1210 g.setColor(Color.white);
1211 g.fillRect(0, 0, (endRes - startRes) * av.getCharWidth(), getHeight());
1213 g.setFont(av.getFont());
1216 fm = g.getFontMetrics();
1219 if ((av.getAlignment().getAlignmentAnnotation() == null)
1220 || (av.getAlignment().getAlignmentAnnotation().length < 1))
1222 g.setColor(Color.white);
1223 g.fillRect(0, 0, getWidth(), getHeight());
1224 g.setColor(Color.black);
1225 if (av.validCharWidth)
1227 g.drawString(MessageManager
1228 .getString("label.alignment_has_no_annotations"), 20, 15);
1233 lastImageGood = renderer.drawComponent(this, av, g, activeRow, startRes,
1235 if (!lastImageGood && fadedImage == null)
1237 fadedImage = oldFaded;
1242 public FontMetrics getFontMetrics()
1248 public Image getFadedImage()
1254 public int getFadedImageWidth()
1259 private int[] bounds = new int[2];
1261 private boolean allowFastPaint;
1264 public int[] getVisibleVRange()
1266 if (ap != null && ap.getAlabels() != null)
1268 int sOffset = -ap.getAlabels().getScrollOffset();
1269 int visHeight = sOffset + ap.annotationSpaceFillerHolder.getHeight();
1270 bounds[0] = sOffset;
1271 bounds[1] = visHeight;
1281 * Try to ensure any references held are nulled
1283 public void dispose()
1293 * I created the renderer so I will dispose of it
1295 if (renderer != null)
1302 public void propertyChange(PropertyChangeEvent evt)
1304 // Respond to viewport range changes (e.g. alignment panel was scrolled)
1305 // Both scrolling and resizing change viewport ranges: scrolling changes
1306 // both start and end points, but resize only changes end values.
1307 // Here we only want to fastpaint on a scroll, with resize using a normal
1308 // paint, so scroll events are identified as changes to the horizontal or
1309 // vertical start value.
1310 if (evt.getPropertyName().equals(ViewportRanges.STARTRES))
1312 fastPaint((int) evt.getNewValue() - (int) evt.getOldValue());
1314 else if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ))
1316 fastPaint(((int[]) evt.getNewValue())[0]
1317 - ((int[]) evt.getOldValue())[0]);
1319 else if (evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT))
1326 * computes the visible height of the annotation panel
1328 * @param adjustPanelHeight
1329 * - when false, just adjust existing height according to other
1331 * @param annotationHeight
1332 * @return height to use for the ScrollerPreferredVisibleSize
1334 public int adjustForAlignFrame(boolean adjustPanelHeight,
1335 int annotationHeight)
1338 * Estimate available height in the AlignFrame for alignment +
1339 * annotations. Deduct an estimate for title bar, menu bar, scale panel,
1340 * hscroll, status bar, insets.
1342 int stuff = (ap.getViewName() != null ? 30 : 0)
1343 + (Platform.isAMacAndNotJS() ? 120 : 140);
1344 int availableHeight = ap.alignFrame.getHeight() - stuff;
1345 int rowHeight = av.getCharHeight();
1347 if (adjustPanelHeight)
1349 int alignmentHeight = rowHeight * av.getAlignment().getHeight();
1352 * If not enough vertical space, maximize annotation height while keeping
1353 * at least two rows of alignment visible
1355 if (annotationHeight + alignmentHeight > availableHeight)
1357 annotationHeight = Math.min(annotationHeight,
1358 availableHeight - 2 * rowHeight);
1363 // maintain same window layout whilst updating sliders
1364 annotationHeight = Math.min(ap.annotationScroller.getSize().height,
1365 availableHeight - 2 * rowHeight);
1367 return annotationHeight;
1371 * Clears the flag that allows a 'fast paint' on the next repaint, so
1372 * requiring a full repaint
1374 public void setNoFastPaint()
1376 allowFastPaint = false;