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.analysis.AlignSeq;
24 import jalview.analysis.AlignmentUtils;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.Annotation;
28 import jalview.datamodel.HiddenColumns;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.io.FileFormat;
33 import jalview.io.FormatAdapter;
34 import jalview.util.Comparison;
35 import jalview.util.MessageManager;
36 import jalview.util.Platform;
38 import java.awt.Color;
39 import java.awt.Cursor;
40 import java.awt.Dimension;
42 import java.awt.FontMetrics;
43 import java.awt.Graphics;
44 import java.awt.Graphics2D;
45 import java.awt.RenderingHints;
46 import java.awt.Toolkit;
47 import java.awt.datatransfer.StringSelection;
48 import java.awt.event.ActionEvent;
49 import java.awt.event.ActionListener;
50 import java.awt.event.MouseEvent;
51 import java.awt.event.MouseListener;
52 import java.awt.event.MouseMotionListener;
53 import java.awt.geom.AffineTransform;
54 import java.awt.image.BufferedImage;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.Collections;
58 import java.util.Iterator;
59 import java.util.regex.Pattern;
61 import javax.swing.JCheckBoxMenuItem;
62 import javax.swing.JMenuItem;
63 import javax.swing.JPanel;
64 import javax.swing.JPopupMenu;
65 import javax.swing.SwingUtilities;
66 import javax.swing.ToolTipManager;
69 * The panel that holds the labels for alignment annotations, providing
70 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
73 public class AnnotationLabels extends JPanel
74 implements MouseListener, MouseMotionListener, ActionListener
77 * width in pixels within which height adjuster arrows are shown and active
79 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
82 * height in pixels for allowing height adjuster to be active
84 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
86 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
89 private static final Font font = new Font("Arial", Font.PLAIN, 11);
91 private static final String TOGGLE_LABELSCALE = MessageManager
92 .getString("label.scale_label_to_column");
94 private static final String ADDNEW = MessageManager
95 .getString("label.add_new_row");
97 private static final String EDITNAME = MessageManager
98 .getString("label.edit_label_description");
100 private static final String HIDE = MessageManager
101 .getString("label.hide_row");
103 private static final String DELETE = MessageManager
104 .getString("label.delete_row");
106 private static final String SHOWALL = MessageManager
107 .getString("label.show_all_hidden_rows");
109 private static final String OUTPUT_TEXT = MessageManager
110 .getString("label.export_annotation");
112 private static final String COPYCONS_SEQ = MessageManager
113 .getString("label.copy_consensus_sequence");
115 private final boolean debugRedraw = false;
117 private AlignmentPanel ap;
121 private MouseEvent dragEvent;
125 private int selectedRow;
127 private int scrollOffset = 0;
129 private boolean hasHiddenRows;
131 private boolean resizePanel = false;
134 * Creates a new AnnotationLabels object
138 public AnnotationLabels(AlignmentPanel ap)
142 ToolTipManager.sharedInstance().registerComponent(this);
144 addMouseListener(this);
145 addMouseMotionListener(this);
146 addMouseWheelListener(ap.getAnnotationPanel());
149 public AnnotationLabels(AlignViewport av)
160 public void setScrollOffset(int y)
167 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
171 * coordinate position to search for a row
173 void getSelectedRow(int y)
176 AlignmentAnnotation[] aa = ap.av.getAlignment()
177 .getAlignmentAnnotation();
181 for (int i = 0; i < aa.length; i++)
189 height += aa[i].height;
208 public void actionPerformed(ActionEvent evt)
210 AlignmentAnnotation[] aa = ap.av.getAlignment()
211 .getAlignmentAnnotation();
213 boolean fullRepaint = false;
214 if (evt.getActionCommand().equals(ADDNEW))
216 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
217 null, new Annotation[ap.av.getAlignment().getWidth()]);
219 if (!editLabelDescription(newAnnotation))
224 ap.av.getAlignment().addAnnotation(newAnnotation);
225 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
228 else if (evt.getActionCommand().equals(EDITNAME))
230 String name = aa[selectedRow].label;
231 editLabelDescription(aa[selectedRow]);
232 if (!name.equalsIgnoreCase(aa[selectedRow].label))
237 else if (evt.getActionCommand().equals(HIDE))
239 aa[selectedRow].visible = false;
241 else if (evt.getActionCommand().equals(DELETE))
243 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
244 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
247 else if (evt.getActionCommand().equals(SHOWALL))
249 for (int i = 0; i < aa.length; i++)
251 if (!aa[i].visible && aa[i].annotations != null)
253 aa[i].visible = true;
258 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
260 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
262 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
264 SequenceI cons = null;
265 if (aa[selectedRow].groupRef != null)
267 cons = aa[selectedRow].groupRef.getConsensusSeq();
271 cons = av.getConsensusSeq();
275 copy_annotseqtoclipboard(cons);
279 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
281 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
284 ap.refresh(fullRepaint);
294 boolean editLabelDescription(AlignmentAnnotation annotation)
297 EditNameDialog dialog = new EditNameDialog(annotation.label,
298 annotation.description, " Annotation Name ",
299 "Annotation Description ", "Edit Annotation Name/Description",
307 annotation.label = dialog.getName();
309 String text = dialog.getDescription();
310 if (text != null && text.length() == 0)
314 annotation.description = text;
320 public void mousePressed(MouseEvent evt)
322 getSelectedRow(evt.getY() - getScrollOffset());
324 if (evt.isPopupTrigger())
331 * Build and show the Pop-up menu at the right-click mouse position
335 void showPopupMenu(MouseEvent evt)
338 final AlignmentAnnotation[] aa = ap.av.getAlignment()
339 .getAlignmentAnnotation();
341 JPopupMenu pop = new JPopupMenu(
342 MessageManager.getString("label.annotations"));
343 JMenuItem item = new JMenuItem(ADDNEW);
344 item.addActionListener(this);
349 { // let the user make everything visible again
350 item = new JMenuItem(SHOWALL);
351 item.addActionListener(this);
354 pop.show(this, evt.getX(), evt.getY());
357 item = new JMenuItem(EDITNAME);
358 item.addActionListener(this);
360 item = new JMenuItem(HIDE);
361 item.addActionListener(this);
363 // JAL-1264 hide all sequence-specific annotations of this type
364 if (selectedRow < aa.length)
366 if (aa[selectedRow].sequenceRef != null)
368 final String label = aa[selectedRow].label;
369 JMenuItem hideType = new JMenuItem();
370 String text = MessageManager.getString("label.hide_all") + " "
372 hideType.setText(text);
373 hideType.addActionListener(new ActionListener()
376 public void actionPerformed(ActionEvent e)
378 AlignmentUtils.showOrHideSequenceAnnotations(
379 ap.av.getAlignment(), Collections.singleton(label),
381 // for (AlignmentAnnotation ann : ap.av.getAlignment()
382 // .getAlignmentAnnotation())
384 // if (ann.sequenceRef != null && ann.label != null
385 // && ann.label.equals(label))
387 // ann.visible = false;
396 item = new JMenuItem(DELETE);
397 item.addActionListener(this);
401 item = new JMenuItem(SHOWALL);
402 item.addActionListener(this);
405 item = new JMenuItem(OUTPUT_TEXT);
406 item.addActionListener(this);
408 // TODO: annotation object should be typed for autocalculated/derived
410 if (selectedRow < aa.length)
412 final String label = aa[selectedRow].label;
413 if (!aa[selectedRow].autoCalculated)
415 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
417 // display formatting settings for this row.
419 // av and sequencegroup need to implement same interface for
420 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
421 aa[selectedRow].scaleColLabel);
422 item.addActionListener(this);
426 else if (label.indexOf("Consensus") > -1)
429 // av and sequencegroup need to implement same interface for
430 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
431 MessageManager.getString("label.ignore_gaps_consensus"),
432 (aa[selectedRow].groupRef != null)
433 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
434 : ap.av.isIgnoreGapsConsensus());
435 final AlignmentAnnotation aaa = aa[selectedRow];
436 cbmi.addActionListener(new ActionListener()
439 public void actionPerformed(ActionEvent e)
441 if (aaa.groupRef != null)
443 // TODO: pass on reference to ap so the view can be updated.
444 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
445 ap.getAnnotationPanel()
446 .paint(ap.getAnnotationPanel().getGraphics());
450 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
452 ap.alignmentChanged();
456 // av and sequencegroup need to implement same interface for
457 if (aaa.groupRef != null)
459 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
460 MessageManager.getString("label.show_group_histogram"),
461 aa[selectedRow].groupRef.isShowConsensusHistogram());
462 chist.addActionListener(new ActionListener()
465 public void actionPerformed(ActionEvent e)
467 // TODO: pass on reference
473 aaa.groupRef.setShowConsensusHistogram(chist.getState());
475 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
479 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
480 MessageManager.getString("label.show_group_logo"),
481 aa[selectedRow].groupRef.isShowSequenceLogo());
482 cprofl.addActionListener(new ActionListener()
485 public void actionPerformed(ActionEvent e)
487 // TODO: pass on reference
493 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
495 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
499 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
500 MessageManager.getString("label.normalise_group_logo"),
501 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
502 cproflnorm.addActionListener(new ActionListener()
505 public void actionPerformed(ActionEvent e)
508 // TODO: pass on reference
514 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
515 // automatically enable logo display if we're clicked
516 aaa.groupRef.setshowSequenceLogo(true);
518 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
525 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
526 MessageManager.getString("label.show_histogram"),
527 av.isShowConsensusHistogram());
528 chist.addActionListener(new ActionListener()
531 public void actionPerformed(ActionEvent e)
533 // TODO: pass on reference
539 av.setShowConsensusHistogram(chist.getState());
540 ap.alignFrame.setMenusForViewport();
542 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
546 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
547 MessageManager.getString("label.show_logo"),
548 av.isShowSequenceLogo());
549 cprof.addActionListener(new ActionListener()
552 public void actionPerformed(ActionEvent e)
554 // TODO: pass on reference
560 av.setShowSequenceLogo(cprof.getState());
561 ap.alignFrame.setMenusForViewport();
563 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
567 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
568 MessageManager.getString("label.normalise_logo"),
569 av.isNormaliseSequenceLogo());
570 cprofnorm.addActionListener(new ActionListener()
573 public void actionPerformed(ActionEvent e)
575 // TODO: pass on reference
581 av.setShowSequenceLogo(true);
582 av.setNormaliseSequenceLogo(cprofnorm.getState());
583 ap.alignFrame.setMenusForViewport();
585 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
590 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
591 consclipbrd.addActionListener(this);
592 pop.add(consclipbrd);
595 pop.show(this, evt.getX(), evt.getY());
599 * Reorders annotation rows after a drag of a label
604 public void mouseReleased(MouseEvent evt)
606 if (evt.isPopupTrigger())
612 int start = selectedRow;
613 getSelectedRow(evt.getY() - getScrollOffset());
614 int end = selectedRow;
617 * if dragging to resize instead, start == end
621 // Swap these annotations
622 AlignmentAnnotation startAA = ap.av.getAlignment()
623 .getAlignmentAnnotation()[start];
626 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
628 AlignmentAnnotation endAA = ap.av.getAlignment()
629 .getAlignmentAnnotation()[end];
631 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
632 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
638 ap.getAnnotationPanel().repaint();
642 * Removes the height adjuster image on leaving the panel, unless currently
646 public void mouseExited(MouseEvent evt)
648 if (resizePanel && dragEvent == null)
656 * A mouse drag may be either an adjustment of the panel height (if flag
657 * resizePanel is set on), or a reordering of the annotation rows. The former
658 * is dealt with by this method, the latter in mouseReleased.
663 public void mouseDragged(MouseEvent evt)
669 Dimension d = ap.annotationScroller.getPreferredSize();
670 int dif = evt.getY() - oldY;
672 dif /= ap.av.getCharHeight();
673 dif *= ap.av.getCharHeight();
675 if ((d.height - dif) > 20)
677 ap.annotationScroller
678 .setPreferredSize(new Dimension(d.width, d.height - dif));
679 d = ap.annotationSpaceFillerHolder.getPreferredSize();
680 ap.annotationSpaceFillerHolder
681 .setPreferredSize(new Dimension(d.width, d.height - dif));
682 ap.paintAlignment(true, false);
694 * Updates the tooltip as the mouse moves over the labels
699 public void mouseMoved(MouseEvent evt)
701 showOrHideAdjuster(evt);
703 getSelectedRow(evt.getY() - getScrollOffset());
705 if (selectedRow > -1 && ap.av.getAlignment()
706 .getAlignmentAnnotation().length > selectedRow)
708 AlignmentAnnotation aa = ap.av.getAlignment()
709 .getAlignmentAnnotation()[selectedRow];
711 StringBuffer desc = new StringBuffer();
712 if (aa.description != null
713 && !aa.description.equals("New description"))
715 // TODO: we could refactor and merge this code with the code in
716 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
718 desc.append(aa.getDescription(true).trim());
719 // check to see if the description is an html fragment.
720 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
721 .indexOf("<html>") < 0))
723 // clean the description ready for embedding in html
724 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
725 .replaceAll("<"));
726 desc.insert(0, "<html>");
730 // remove terminating html if any
731 int i = desc.substring(desc.length() - 7).toLowerCase()
732 .lastIndexOf("</html>");
735 desc.setLength(desc.length() - 7 + i);
740 desc.append("<br/>");
742 // if (aa.hasProperties())
744 // desc.append("<table>");
745 // for (String prop : aa.getProperties())
747 // desc.append("<tr><td>" + prop + "</td><td>"
748 // + aa.getProperty(prop) + "</td><tr>");
750 // desc.append("</table>");
755 // begin the tooltip's html fragment
756 desc.append("<html>");
759 // TODO: limit precision of score to avoid noise from imprecise
761 // (64.7 becomes 64.7+/some tiny value).
762 desc.append(" Score: " + aa.score);
765 if (desc.length() > 6)
767 desc.append("</html>");
768 this.setToolTipText(desc.toString());
772 this.setToolTipText(null);
778 * Shows the height adjuster image if the mouse moves into the top left
779 * region, or hides it if the mouse leaves the regio
783 protected void showOrHideAdjuster(MouseEvent evt)
785 boolean was = resizePanel;
786 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
788 if (resizePanel != was)
790 setCursor(Cursor.getPredefinedCursor(
791 resizePanel ? Cursor.S_RESIZE_CURSOR
792 : Cursor.DEFAULT_CURSOR));
798 public void mouseClicked(MouseEvent evt)
800 final AlignmentAnnotation[] aa = ap.av.getAlignment()
801 .getAlignmentAnnotation();
802 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
804 if (selectedRow > -1 && selectedRow < aa.length)
806 if (aa[selectedRow].groupRef != null)
808 if (evt.getClickCount() >= 2)
810 // todo: make the ap scroll to the selection - not necessary, first
811 // click highlights/scrolls, second selects
812 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
814 SequenceGroup sg = ap.av.getSelectionGroup();
815 if (sg == null || sg == aa[selectedRow].groupRef
816 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
818 if (Platform.isControlDown(evt) || evt.isShiftDown())
820 // clone a new selection group from the associated group
821 ap.av.setSelectionGroup(
822 new SequenceGroup(aa[selectedRow].groupRef));
826 // set selection to the associated group so it can be edited
827 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
832 // modify current selection with associated group
833 int remainToAdd = aa[selectedRow].groupRef.getSize();
834 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
836 if (jalview.util.Platform.isControlDown(evt))
838 sg.addOrRemove(sgs, --remainToAdd == 0);
842 // notionally, we should also add intermediate sequences from
843 // last added sequence ?
844 sg.addSequence(sgs, --remainToAdd == 0);
849 ap.paintAlignment(false, false);
850 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
851 ap.av.sendSelection();
855 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
856 aa[selectedRow].groupRef.getSequences(null));
860 else if (aa[selectedRow].sequenceRef != null)
862 if (evt.getClickCount() == 1)
864 ap.getSeqPanel().ap.getIdPanel()
865 .highlightSearchResults(Arrays.asList(new SequenceI[]
866 { aa[selectedRow].sequenceRef }));
868 else if (evt.getClickCount() >= 2)
870 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
871 SequenceGroup sg = ap.av.getSelectionGroup();
874 // we make a copy rather than edit the current selection if no
876 // see Enhancement JAL-1557
877 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
879 sg = new SequenceGroup(sg);
881 sg.addSequence(aa[selectedRow].sequenceRef, false);
885 if (Platform.isControlDown(evt))
887 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
891 // notionally, we should also add intermediate sequences from
892 // last added sequence ?
893 sg.addSequence(aa[selectedRow].sequenceRef, true);
899 sg = new SequenceGroup();
901 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
902 sg.addSequence(aa[selectedRow].sequenceRef, false);
904 ap.av.setSelectionGroup(sg);
905 ap.paintAlignment(false, false);
906 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
907 ap.av.sendSelection();
917 * do a single sequence copy to jalview and the system clipboard
920 * sequence to be copied to clipboard
922 protected void copy_annotseqtoclipboard(SequenceI sq)
924 SequenceI[] seqs = new SequenceI[] { sq };
925 String[] omitHidden = null;
926 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
927 if (dseqs[0] == null)
929 dseqs[0] = new Sequence(sq);
930 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
931 sq.getSequenceAsString()));
933 sq.setDatasetSequence(dseqs[0]);
935 Alignment ds = new Alignment(dseqs);
936 if (av.hasHiddenColumns())
938 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
939 .getVisContigsIterator(0, sq.getLength(), false);
940 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
943 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
944 if (av.hasHiddenColumns())
946 alignmentStartEnd = av.getAlignment().getHiddenColumns()
947 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
950 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
951 seqs, omitHidden, alignmentStartEnd);
953 Toolkit.getDefaultToolkit().getSystemClipboard()
954 .setContents(new StringSelection(output), Desktop.instance);
956 HiddenColumns hiddenColumns = null;
958 if (av.hasHiddenColumns())
960 hiddenColumns = new HiddenColumns(
961 av.getAlignment().getHiddenColumns());
964 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
966 // sequence ? need to
968 // sequence as special.
979 public void paintComponent(Graphics g)
982 int width = getWidth();
985 width = ap.calculateIdWidth().width + 4;
988 Graphics2D g2 = (Graphics2D) g;
991 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
992 RenderingHints.VALUE_ANTIALIAS_ON);
995 drawComponent(g2, true, width);
1000 * Draw the full set of annotation Labels for the alignment at the given
1004 * Graphics2D instance (needed for font scaling)
1006 * Width for scaling labels
1009 public void drawComponent(Graphics g, int width)
1011 drawComponent(g, false, width);
1015 * Draw the full set of annotation Labels for the alignment at the given
1019 * Graphics2D instance (needed for font scaling)
1021 * - true indicates that only current visible area needs to be
1024 * Width for scaling labels
1026 public void drawComponent(Graphics g, boolean clip, int width)
1028 if (av.getFont().getSize() < 10)
1034 g.setFont(av.getFont());
1037 FontMetrics fm = g.getFontMetrics(g.getFont());
1038 g.setColor(Color.white);
1039 g.fillRect(0, 0, getWidth(), getHeight());
1041 g.translate(0, getScrollOffset());
1042 g.setColor(Color.black);
1044 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1045 int fontHeight = g.getFont().getSize();
1048 int graphExtras = 0;
1050 Font baseFont = g.getFont();
1051 FontMetrics baseMetrics = fm;
1052 int ofontH = fontHeight;
1055 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1056 ? ap.getAnnotationPanel().getVisibleVRange()
1058 if (clip && visr != null)
1061 visHeight = visr[1];
1063 boolean visible = true, before = false, after = false;
1066 hasHiddenRows = false;
1068 for (int i = 0; i < aa.length; i++)
1073 hasHiddenRows = true;
1086 System.out.println("before vis: " + i);
1090 // don't draw what isn't visible
1093 if (olY > visHeight)
1101 "Scroll offset: " + sOffset + " after vis: " + i);
1105 // don't draw what isn't visible
1109 g.setColor(Color.black);
1111 offset = -aa[i].height / 2;
1115 offset += fm.getHeight() / 2;
1116 offset -= fm.getDescent();
1120 offset += fm.getDescent();
1123 x = width - fm.stringWidth(aa[i].label) - 3;
1125 if (aa[i].graphGroup > -1)
1128 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1129 // computed efficiently for all visible labels
1130 for (int gg = 0; gg < aa.length; gg++)
1132 if (aa[gg].graphGroup == aa[i].graphGroup)
1137 if (groupSize * (fontHeight + 8) < aa[i].height)
1139 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1144 // scale font to fit
1145 float h = aa[i].height / (float) groupSize, s;
1152 fontHeight = -8 + (int) h;
1153 s = ((float) fontHeight) / (float) ofontH;
1155 .deriveFont(AffineTransform.getScaleInstance(s, s));
1157 fm = g.getFontMetrics();
1158 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1164 for (int gg = 0; gg < aa.length; gg++)
1166 if (aa[gg].graphGroup == aa[i].graphGroup)
1168 x = width - fm.stringWidth(aa[gg].label) - 3;
1169 g.drawString(aa[gg].label, x, y - graphExtras);
1171 if (aa[gg]._linecolour != null)
1174 g.setColor(aa[gg]._linecolour);
1175 g.drawLine(x, y - graphExtras + 3,
1176 x + fm.stringWidth(aa[gg].label),
1177 y - graphExtras + 3);
1180 g.setColor(Color.black);
1181 graphExtras += fontHeight + 8;
1185 g.setFont(baseFont);
1187 fontHeight = ofontH;
1191 g.drawString(aa[i].label, x, y + offset);
1196 if (!resizePanel && dragEvent != null && aa != null)
1198 g.setColor(Color.lightGray);
1199 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1200 dragEvent.getY() - getScrollOffset());
1203 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1205 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1206 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1211 public int getScrollOffset()
1213 return scrollOffset;
1217 public void mouseEntered(MouseEvent e)