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().exportAnnotations(ap,
261 new AlignmentAnnotation[]
262 { aa[selectedRow] });
264 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
266 SequenceI cons = null;
267 if (aa[selectedRow].groupRef != null)
269 cons = aa[selectedRow].groupRef.getConsensusSeq();
273 cons = av.getConsensusSeq();
277 copy_annotseqtoclipboard(cons);
281 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
283 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
286 ap.refresh(fullRepaint);
296 boolean editLabelDescription(AlignmentAnnotation annotation)
299 EditNameDialog dialog = new EditNameDialog(annotation.label,
300 annotation.description, " Annotation Name ",
301 "Annotation Description ", "Edit Annotation Name/Description",
309 annotation.label = dialog.getName();
311 String text = dialog.getDescription();
312 if (text != null && text.length() == 0)
316 annotation.description = text;
322 public void mousePressed(MouseEvent evt)
324 getSelectedRow(evt.getY() - getScrollOffset());
326 if (evt.isPopupTrigger())
333 * Build and show the Pop-up menu at the right-click mouse position
337 void showPopupMenu(MouseEvent evt)
340 final AlignmentAnnotation[] aa = ap.av.getAlignment()
341 .getAlignmentAnnotation();
343 JPopupMenu pop = new JPopupMenu(
344 MessageManager.getString("label.annotations"));
345 JMenuItem item = new JMenuItem(ADDNEW);
346 item.addActionListener(this);
351 { // let the user make everything visible again
352 item = new JMenuItem(SHOWALL);
353 item.addActionListener(this);
356 pop.show(this, evt.getX(), evt.getY());
359 item = new JMenuItem(EDITNAME);
360 item.addActionListener(this);
362 item = new JMenuItem(HIDE);
363 item.addActionListener(this);
365 // JAL-1264 hide all sequence-specific annotations of this type
366 if (selectedRow < aa.length)
368 if (aa[selectedRow].sequenceRef != null)
370 final String label = aa[selectedRow].label;
371 JMenuItem hideType = new JMenuItem();
372 String text = MessageManager.getString("label.hide_all") + " "
374 hideType.setText(text);
375 hideType.addActionListener(new ActionListener()
378 public void actionPerformed(ActionEvent e)
380 AlignmentUtils.showOrHideSequenceAnnotations(
381 ap.av.getAlignment(), Collections.singleton(label),
383 // for (AlignmentAnnotation ann : ap.av.getAlignment()
384 // .getAlignmentAnnotation())
386 // if (ann.sequenceRef != null && ann.label != null
387 // && ann.label.equals(label))
389 // ann.visible = false;
398 item = new JMenuItem(DELETE);
399 item.addActionListener(this);
403 item = new JMenuItem(SHOWALL);
404 item.addActionListener(this);
407 item = new JMenuItem(OUTPUT_TEXT);
408 item.addActionListener(this);
410 // TODO: annotation object should be typed for autocalculated/derived
412 if (selectedRow < aa.length)
414 final String label = aa[selectedRow].label;
415 if (!aa[selectedRow].autoCalculated)
417 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
419 // display formatting settings for this row.
421 // av and sequencegroup need to implement same interface for
422 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
423 aa[selectedRow].scaleColLabel);
424 item.addActionListener(this);
428 else if (label.indexOf("Consensus") > -1)
431 // av and sequencegroup need to implement same interface for
432 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
433 MessageManager.getString("label.ignore_gaps_consensus"),
434 (aa[selectedRow].groupRef != null)
435 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
436 : ap.av.isIgnoreGapsConsensus());
437 final AlignmentAnnotation aaa = aa[selectedRow];
438 cbmi.addActionListener(new ActionListener()
441 public void actionPerformed(ActionEvent e)
443 if (aaa.groupRef != null)
445 // TODO: pass on reference to ap so the view can be updated.
446 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
447 ap.getAnnotationPanel()
448 .paint(ap.getAnnotationPanel().getGraphics());
452 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
454 ap.alignmentChanged();
458 // av and sequencegroup need to implement same interface for
459 if (aaa.groupRef != null)
461 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
462 MessageManager.getString("label.show_group_histogram"),
463 aa[selectedRow].groupRef.isShowConsensusHistogram());
464 chist.addActionListener(new ActionListener()
467 public void actionPerformed(ActionEvent e)
469 // TODO: pass on reference
475 aaa.groupRef.setShowConsensusHistogram(chist.getState());
477 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
481 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
482 MessageManager.getString("label.show_group_logo"),
483 aa[selectedRow].groupRef.isShowSequenceLogo());
484 cprofl.addActionListener(new ActionListener()
487 public void actionPerformed(ActionEvent e)
489 // TODO: pass on reference
495 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
497 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
501 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
502 MessageManager.getString("label.normalise_group_logo"),
503 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
504 cproflnorm.addActionListener(new ActionListener()
507 public void actionPerformed(ActionEvent e)
510 // TODO: pass on reference
516 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
517 // automatically enable logo display if we're clicked
518 aaa.groupRef.setshowSequenceLogo(true);
520 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
527 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
528 MessageManager.getString("label.show_histogram"),
529 av.isShowConsensusHistogram());
530 chist.addActionListener(new ActionListener()
533 public void actionPerformed(ActionEvent e)
535 // TODO: pass on reference
541 av.setShowConsensusHistogram(chist.getState());
542 ap.alignFrame.setMenusForViewport();
544 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
548 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
549 MessageManager.getString("label.show_logo"),
550 av.isShowSequenceLogo());
551 cprof.addActionListener(new ActionListener()
554 public void actionPerformed(ActionEvent e)
556 // TODO: pass on reference
562 av.setShowSequenceLogo(cprof.getState());
563 ap.alignFrame.setMenusForViewport();
565 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
569 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
570 MessageManager.getString("label.normalise_logo"),
571 av.isNormaliseSequenceLogo());
572 cprofnorm.addActionListener(new ActionListener()
575 public void actionPerformed(ActionEvent e)
577 // TODO: pass on reference
583 av.setShowSequenceLogo(true);
584 av.setNormaliseSequenceLogo(cprofnorm.getState());
585 ap.alignFrame.setMenusForViewport();
587 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
592 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
593 consclipbrd.addActionListener(this);
594 pop.add(consclipbrd);
597 pop.show(this, evt.getX(), evt.getY());
601 * Reorders annotation rows after a drag of a label
606 public void mouseReleased(MouseEvent evt)
608 if (evt.isPopupTrigger())
614 int start = selectedRow;
615 getSelectedRow(evt.getY() - getScrollOffset());
616 int end = selectedRow;
619 * if dragging to resize instead, start == end
623 // Swap these annotations
624 AlignmentAnnotation startAA = ap.av.getAlignment()
625 .getAlignmentAnnotation()[start];
628 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
630 AlignmentAnnotation endAA = ap.av.getAlignment()
631 .getAlignmentAnnotation()[end];
633 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
634 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
640 ap.getAnnotationPanel().repaint();
644 * Removes the height adjuster image on leaving the panel, unless currently
648 public void mouseExited(MouseEvent evt)
650 if (resizePanel && dragEvent == null)
658 * A mouse drag may be either an adjustment of the panel height (if flag
659 * resizePanel is set on), or a reordering of the annotation rows. The former
660 * is dealt with by this method, the latter in mouseReleased.
665 public void mouseDragged(MouseEvent evt)
671 Dimension d = ap.annotationScroller.getPreferredSize();
672 int dif = evt.getY() - oldY;
674 dif /= ap.av.getCharHeight();
675 dif *= ap.av.getCharHeight();
677 if ((d.height - dif) > 20)
679 ap.annotationScroller
680 .setPreferredSize(new Dimension(d.width, d.height - dif));
681 d = ap.annotationSpaceFillerHolder.getPreferredSize();
682 ap.annotationSpaceFillerHolder
683 .setPreferredSize(new Dimension(d.width, d.height - dif));
684 ap.paintAlignment(true, false);
696 * Updates the tooltip as the mouse moves over the labels
701 public void mouseMoved(MouseEvent evt)
703 showOrHideAdjuster(evt);
705 getSelectedRow(evt.getY() - getScrollOffset());
707 if (selectedRow > -1 && ap.av.getAlignment()
708 .getAlignmentAnnotation().length > selectedRow)
710 AlignmentAnnotation aa = ap.av.getAlignment()
711 .getAlignmentAnnotation()[selectedRow];
713 StringBuffer desc = new StringBuffer();
714 if (aa.description != null
715 && !aa.description.equals("New description"))
717 // TODO: we could refactor and merge this code with the code in
718 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
720 desc.append(aa.getDescription(true).trim());
721 // check to see if the description is an html fragment.
722 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
723 .indexOf("<html>") < 0))
725 // clean the description ready for embedding in html
726 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
727 .replaceAll("<"));
728 desc.insert(0, "<html>");
732 // remove terminating html if any
733 int i = desc.substring(desc.length() - 7).toLowerCase()
734 .lastIndexOf("</html>");
737 desc.setLength(desc.length() - 7 + i);
742 desc.append("<br/>");
744 // if (aa.hasProperties())
746 // desc.append("<table>");
747 // for (String prop : aa.getProperties())
749 // desc.append("<tr><td>" + prop + "</td><td>"
750 // + aa.getProperty(prop) + "</td><tr>");
752 // desc.append("</table>");
757 // begin the tooltip's html fragment
758 desc.append("<html>");
761 // TODO: limit precision of score to avoid noise from imprecise
763 // (64.7 becomes 64.7+/some tiny value).
764 desc.append(" Score: " + aa.score);
767 if (desc.length() > 6)
769 desc.append("</html>");
770 this.setToolTipText(desc.toString());
774 this.setToolTipText(null);
780 * Shows the height adjuster image if the mouse moves into the top left
781 * region, or hides it if the mouse leaves the regio
785 protected void showOrHideAdjuster(MouseEvent evt)
787 boolean was = resizePanel;
788 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
790 if (resizePanel != was)
792 setCursor(Cursor.getPredefinedCursor(
793 resizePanel ? Cursor.S_RESIZE_CURSOR
794 : Cursor.DEFAULT_CURSOR));
800 public void mouseClicked(MouseEvent evt)
802 final AlignmentAnnotation[] aa = ap.av.getAlignment()
803 .getAlignmentAnnotation();
804 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
806 if (selectedRow > -1 && selectedRow < aa.length)
808 if (aa[selectedRow].groupRef != null)
810 if (evt.getClickCount() >= 2)
812 // todo: make the ap scroll to the selection - not necessary, first
813 // click highlights/scrolls, second selects
814 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
816 SequenceGroup sg = ap.av.getSelectionGroup();
817 if (sg == null || sg == aa[selectedRow].groupRef
818 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
820 if (Platform.isControlDown(evt) || evt.isShiftDown())
822 // clone a new selection group from the associated group
823 ap.av.setSelectionGroup(
824 new SequenceGroup(aa[selectedRow].groupRef));
828 // set selection to the associated group so it can be edited
829 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
834 // modify current selection with associated group
835 int remainToAdd = aa[selectedRow].groupRef.getSize();
836 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
838 if (jalview.util.Platform.isControlDown(evt))
840 sg.addOrRemove(sgs, --remainToAdd == 0);
844 // notionally, we should also add intermediate sequences from
845 // last added sequence ?
846 sg.addSequence(sgs, --remainToAdd == 0);
851 ap.paintAlignment(false, false);
852 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
853 ap.av.sendSelection();
857 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
858 aa[selectedRow].groupRef.getSequences(null));
862 else if (aa[selectedRow].sequenceRef != null)
864 if (evt.getClickCount() == 1)
866 ap.getSeqPanel().ap.getIdPanel()
867 .highlightSearchResults(Arrays.asList(new SequenceI[]
868 { aa[selectedRow].sequenceRef }));
870 else if (evt.getClickCount() >= 2)
872 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
873 SequenceGroup sg = ap.av.getSelectionGroup();
876 // we make a copy rather than edit the current selection if no
878 // see Enhancement JAL-1557
879 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
881 sg = new SequenceGroup(sg);
883 sg.addSequence(aa[selectedRow].sequenceRef, false);
887 if (Platform.isControlDown(evt))
889 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
893 // notionally, we should also add intermediate sequences from
894 // last added sequence ?
895 sg.addSequence(aa[selectedRow].sequenceRef, true);
901 sg = new SequenceGroup();
903 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
904 sg.addSequence(aa[selectedRow].sequenceRef, false);
906 ap.av.setSelectionGroup(sg);
907 ap.paintAlignment(false, false);
908 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
909 ap.av.sendSelection();
919 * do a single sequence copy to jalview and the system clipboard
922 * sequence to be copied to clipboard
924 protected void copy_annotseqtoclipboard(SequenceI sq)
926 SequenceI[] seqs = new SequenceI[] { sq };
927 String[] omitHidden = null;
928 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
929 if (dseqs[0] == null)
931 dseqs[0] = new Sequence(sq);
932 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
933 sq.getSequenceAsString()));
935 sq.setDatasetSequence(dseqs[0]);
937 Alignment ds = new Alignment(dseqs);
938 if (av.hasHiddenColumns())
940 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
941 .getVisContigsIterator(0, sq.getLength(), false);
942 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
945 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
946 if (av.hasHiddenColumns())
948 alignmentStartEnd = av.getAlignment().getHiddenColumns()
949 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
952 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
953 seqs, omitHidden, alignmentStartEnd);
955 Toolkit.getDefaultToolkit().getSystemClipboard()
956 .setContents(new StringSelection(output), Desktop.instance);
958 HiddenColumns hiddenColumns = null;
960 if (av.hasHiddenColumns())
962 hiddenColumns = new HiddenColumns(
963 av.getAlignment().getHiddenColumns());
966 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
968 // sequence ? need to
970 // sequence as special.
981 public void paintComponent(Graphics g)
984 int width = getWidth();
987 width = ap.calculateIdWidth().width + 4;
990 Graphics2D g2 = (Graphics2D) g;
993 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
994 RenderingHints.VALUE_ANTIALIAS_ON);
997 drawComponent(g2, true, width);
1002 * Draw the full set of annotation Labels for the alignment at the given
1006 * Graphics2D instance (needed for font scaling)
1008 * Width for scaling labels
1011 public void drawComponent(Graphics g, int width)
1013 drawComponent(g, false, width);
1017 * Draw the full set of annotation Labels for the alignment at the given
1021 * Graphics2D instance (needed for font scaling)
1023 * - true indicates that only current visible area needs to be
1026 * Width for scaling labels
1028 public void drawComponent(Graphics g, boolean clip, int width)
1030 if (av.getFont().getSize() < 10)
1036 g.setFont(av.getFont());
1039 FontMetrics fm = g.getFontMetrics(g.getFont());
1040 g.setColor(Color.white);
1041 g.fillRect(0, 0, getWidth(), getHeight());
1043 g.translate(0, getScrollOffset());
1044 g.setColor(Color.black);
1046 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1047 int fontHeight = g.getFont().getSize();
1050 int graphExtras = 0;
1052 Font baseFont = g.getFont();
1053 FontMetrics baseMetrics = fm;
1054 int ofontH = fontHeight;
1057 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1058 ? ap.getAnnotationPanel().getVisibleVRange()
1060 if (clip && visr != null)
1063 visHeight = visr[1];
1065 boolean visible = true, before = false, after = false;
1068 hasHiddenRows = false;
1070 for (int i = 0; i < aa.length; i++)
1075 hasHiddenRows = true;
1088 System.out.println("before vis: " + i);
1092 // don't draw what isn't visible
1095 if (olY > visHeight)
1103 "Scroll offset: " + sOffset + " after vis: " + i);
1107 // don't draw what isn't visible
1111 g.setColor(Color.black);
1113 offset = -aa[i].height / 2;
1117 offset += fm.getHeight() / 2;
1118 offset -= fm.getDescent();
1122 offset += fm.getDescent();
1125 x = width - fm.stringWidth(aa[i].label) - 3;
1127 if (aa[i].graphGroup > -1)
1130 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1131 // computed efficiently for all visible labels
1132 for (int gg = 0; gg < aa.length; gg++)
1134 if (aa[gg].graphGroup == aa[i].graphGroup)
1139 if (groupSize * (fontHeight + 8) < aa[i].height)
1141 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1146 // scale font to fit
1147 float h = aa[i].height / (float) groupSize, s;
1154 fontHeight = -8 + (int) h;
1155 s = ((float) fontHeight) / (float) ofontH;
1157 .deriveFont(AffineTransform.getScaleInstance(s, s));
1159 fm = g.getFontMetrics();
1160 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1166 for (int gg = 0; gg < aa.length; gg++)
1168 if (aa[gg].graphGroup == aa[i].graphGroup)
1170 x = width - fm.stringWidth(aa[gg].label) - 3;
1171 g.drawString(aa[gg].label, x, y - graphExtras);
1173 if (aa[gg]._linecolour != null)
1176 g.setColor(aa[gg]._linecolour);
1177 g.drawLine(x, y - graphExtras + 3,
1178 x + fm.stringWidth(aa[gg].label),
1179 y - graphExtras + 3);
1182 g.setColor(Color.black);
1183 graphExtras += fontHeight + 8;
1187 g.setFont(baseFont);
1189 fontHeight = ofontH;
1193 g.drawString(aa[i].label, x, y + offset);
1198 if (!resizePanel && dragEvent != null && aa != null)
1200 g.setColor(Color.lightGray);
1201 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1202 dragEvent.getY() - getScrollOffset());
1205 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1207 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1208 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1213 public int getScrollOffset()
1215 return scrollOffset;
1219 public void mouseEntered(MouseEvent e)