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;
37 import jalview.util.dialogrunner.RunResponse;
39 import java.awt.Color;
40 import java.awt.Cursor;
41 import java.awt.Dimension;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
46 import java.awt.RenderingHints;
47 import java.awt.Toolkit;
48 import java.awt.datatransfer.StringSelection;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.MouseEvent;
52 import java.awt.event.MouseListener;
53 import java.awt.event.MouseMotionListener;
54 import java.awt.geom.AffineTransform;
55 import java.util.Arrays;
56 import java.util.Collections;
57 import java.util.Iterator;
58 import java.util.regex.Pattern;
60 import javax.swing.JCheckBoxMenuItem;
61 import javax.swing.JMenuItem;
62 import javax.swing.JPanel;
63 import javax.swing.JPopupMenu;
64 import javax.swing.SwingUtilities;
65 import javax.swing.ToolTipManager;
68 * The panel that holds the labels for alignment annotations, providing
69 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
72 public class AnnotationLabels extends JPanel
73 implements MouseListener, MouseMotionListener, ActionListener
76 * width in pixels within which height adjuster arrows are shown and active
78 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
81 * height in pixels for allowing height adjuster to be active
83 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
85 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
88 private static final Font font = new Font("Arial", Font.PLAIN, 11);
90 private static final String TOGGLE_LABELSCALE = MessageManager
91 .getString("label.scale_label_to_column");
93 private static final String ADDNEW = MessageManager
94 .getString("label.add_new_row");
96 private static final String EDITNAME = MessageManager
97 .getString("label.edit_label_description");
99 private static final String HIDE = MessageManager
100 .getString("label.hide_row");
102 private static final String DELETE = MessageManager
103 .getString("label.delete_row");
105 private static final String SHOWALL = MessageManager
106 .getString("label.show_all_hidden_rows");
108 private static final String OUTPUT_TEXT = MessageManager
109 .getString("label.export_annotation");
111 private static final String COPYCONS_SEQ = MessageManager
112 .getString("label.copy_consensus_sequence");
114 private final boolean debugRedraw = false;
116 private AlignmentPanel ap;
120 private MouseEvent dragEvent;
124 private int selectedRow;
126 private int scrollOffset = 0;
128 private boolean hasHiddenRows;
130 private boolean resizePanel = false;
133 * Creates a new AnnotationLabels object
137 public AnnotationLabels(AlignmentPanel ap)
141 ToolTipManager.sharedInstance().registerComponent(this);
143 addMouseListener(this);
144 addMouseMotionListener(this);
145 addMouseWheelListener(ap.getAnnotationPanel());
148 public AnnotationLabels(AlignViewport av)
159 public void setScrollOffset(int y)
166 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
170 * coordinate position to search for a row
172 void getSelectedRow(int y)
175 AlignmentAnnotation[] aa = ap.av.getAlignment()
176 .getAlignmentAnnotation();
180 for (int i = 0; i < aa.length; i++)
188 height += aa[i].height;
207 public void actionPerformed(ActionEvent evt)
209 AlignmentAnnotation[] aa = ap.av.getAlignment()
210 .getAlignmentAnnotation();
212 String action = evt.getActionCommand();
213 if (ADDNEW.equals(action))
216 * non-returning dialog
218 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
219 null, new Annotation[ap.av.getAlignment().getWidth()]);
220 editLabelDescription(newAnnotation, true);
222 else if (EDITNAME.equals(action))
225 * non-returning dialog
227 editLabelDescription(aa[selectedRow], false);
229 else if (HIDE.equals(action))
231 aa[selectedRow].visible = false;
233 else if (DELETE.equals(action))
235 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
236 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
238 else if (SHOWALL.equals(action))
240 for (int i = 0; i < aa.length; i++)
242 if (!aa[i].visible && aa[i].annotations != null)
244 aa[i].visible = true;
248 else if (OUTPUT_TEXT.equals(action))
250 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
252 else if (COPYCONS_SEQ.equals(action))
254 SequenceI cons = null;
255 if (aa[selectedRow].groupRef != null)
257 cons = aa[selectedRow].groupRef.getConsensusSeq();
261 cons = av.getConsensusSeq();
265 copy_annotseqtoclipboard(cons);
268 else if (TOGGLE_LABELSCALE.equals(action))
270 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
277 * Shows a dialog where the annotation name and description may be edited. If
278 * parameter addNew is true, then on confirmation, a new AlignmentAnnotation
279 * is added, else an existing annotation is updated.
284 void editLabelDescription(AlignmentAnnotation annotation, boolean addNew)
286 String name = MessageManager.getString("label.annotation_name");
287 String description = MessageManager
288 .getString("label.annotation_description");
289 String title = MessageManager
290 .getString("label.edit_annotation_name_description");
291 EditNameDialog dialog = new EditNameDialog(annotation.label,
292 annotation.description, name, description);
294 dialog.showDialog(ap.alignFrame, title,
295 new RunResponse(JvOptionPane.OK_OPTION)
300 annotation.label = dialog.getName();
301 String text = dialog.getDescription();
302 if (text != null && text.length() == 0)
306 annotation.description = text;
309 ap.av.getAlignment().addAnnotation(annotation);
310 ap.av.getAlignment().setAnnotationIndex(annotation, 0);
318 public void mousePressed(MouseEvent evt)
320 getSelectedRow(evt.getY() - getScrollOffset());
322 if (evt.isPopupTrigger())
329 * Build and show the Pop-up menu at the right-click mouse position
333 void showPopupMenu(MouseEvent evt)
336 final AlignmentAnnotation[] aa = ap.av.getAlignment()
337 .getAlignmentAnnotation();
339 JPopupMenu pop = new JPopupMenu(
340 MessageManager.getString("label.annotations"));
341 JMenuItem item = new JMenuItem(ADDNEW);
342 item.addActionListener(this);
347 { // let the user make everything visible again
348 item = new JMenuItem(SHOWALL);
349 item.addActionListener(this);
352 pop.show(this, evt.getX(), evt.getY());
355 item = new JMenuItem(EDITNAME);
356 item.addActionListener(this);
358 item = new JMenuItem(HIDE);
359 item.addActionListener(this);
361 // JAL-1264 hide all sequence-specific annotations of this type
362 if (selectedRow < aa.length)
364 if (aa[selectedRow].sequenceRef != null)
366 final String label = aa[selectedRow].label;
367 JMenuItem hideType = new JMenuItem();
368 String text = MessageManager.getString("label.hide_all") + " "
370 hideType.setText(text);
371 hideType.addActionListener(new ActionListener()
374 public void actionPerformed(ActionEvent e)
376 AlignmentUtils.showOrHideSequenceAnnotations(
377 ap.av.getAlignment(), Collections.singleton(label),
379 // for (AlignmentAnnotation ann : ap.av.getAlignment()
380 // .getAlignmentAnnotation())
382 // if (ann.sequenceRef != null && ann.label != null
383 // && ann.label.equals(label))
385 // ann.visible = false;
394 item = new JMenuItem(DELETE);
395 item.addActionListener(this);
399 item = new JMenuItem(SHOWALL);
400 item.addActionListener(this);
403 item = new JMenuItem(OUTPUT_TEXT);
404 item.addActionListener(this);
406 // TODO: annotation object should be typed for autocalculated/derived
408 if (selectedRow < aa.length)
410 final String label = aa[selectedRow].label;
411 if (!aa[selectedRow].autoCalculated)
413 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
415 // display formatting settings for this row.
417 // av and sequencegroup need to implement same interface for
418 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
419 aa[selectedRow].scaleColLabel);
420 item.addActionListener(this);
424 else if (label.indexOf("Consensus") > -1)
427 // av and sequencegroup need to implement same interface for
428 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
429 MessageManager.getString("label.ignore_gaps_consensus"),
430 (aa[selectedRow].groupRef != null)
431 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
432 : ap.av.isIgnoreGapsConsensus());
433 final AlignmentAnnotation aaa = aa[selectedRow];
434 cbmi.addActionListener(new ActionListener()
437 public void actionPerformed(ActionEvent e)
439 if (aaa.groupRef != null)
441 // TODO: pass on reference to ap so the view can be updated.
442 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
443 ap.getAnnotationPanel()
444 .paint(ap.getAnnotationPanel().getGraphics());
448 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
450 ap.alignmentChanged();
454 // av and sequencegroup need to implement same interface for
455 if (aaa.groupRef != null)
457 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
458 MessageManager.getString("label.show_group_histogram"),
459 aa[selectedRow].groupRef.isShowConsensusHistogram());
460 chist.addActionListener(new ActionListener()
463 public void actionPerformed(ActionEvent e)
465 // TODO: pass on reference
471 aaa.groupRef.setShowConsensusHistogram(chist.getState());
473 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
477 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
478 MessageManager.getString("label.show_group_logo"),
479 aa[selectedRow].groupRef.isShowSequenceLogo());
480 cprofl.addActionListener(new ActionListener()
483 public void actionPerformed(ActionEvent e)
485 // TODO: pass on reference
491 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
493 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
497 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
498 MessageManager.getString("label.normalise_group_logo"),
499 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
500 cproflnorm.addActionListener(new ActionListener()
503 public void actionPerformed(ActionEvent e)
506 // TODO: pass on reference
512 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
513 // automatically enable logo display if we're clicked
514 aaa.groupRef.setshowSequenceLogo(true);
516 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
523 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
524 MessageManager.getString("label.show_histogram"),
525 av.isShowConsensusHistogram());
526 chist.addActionListener(new ActionListener()
529 public void actionPerformed(ActionEvent e)
531 // TODO: pass on reference
537 av.setShowConsensusHistogram(chist.getState());
538 ap.alignFrame.setMenusForViewport();
540 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
544 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
545 MessageManager.getString("label.show_logo"),
546 av.isShowSequenceLogo());
547 cprof.addActionListener(new ActionListener()
550 public void actionPerformed(ActionEvent e)
552 // TODO: pass on reference
558 av.setShowSequenceLogo(cprof.getState());
559 ap.alignFrame.setMenusForViewport();
561 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
565 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
566 MessageManager.getString("label.normalise_logo"),
567 av.isNormaliseSequenceLogo());
568 cprofnorm.addActionListener(new ActionListener()
571 public void actionPerformed(ActionEvent e)
573 // TODO: pass on reference
579 av.setShowSequenceLogo(true);
580 av.setNormaliseSequenceLogo(cprofnorm.getState());
581 ap.alignFrame.setMenusForViewport();
583 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
588 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
589 consclipbrd.addActionListener(this);
590 pop.add(consclipbrd);
593 pop.show(this, evt.getX(), evt.getY());
597 * Reorders annotation rows after a drag of a label
602 public void mouseReleased(MouseEvent evt)
604 if (evt.isPopupTrigger())
610 int start = selectedRow;
611 getSelectedRow(evt.getY() - getScrollOffset());
612 int end = selectedRow;
615 * if dragging to resize instead, start == end
619 // Swap these annotations
620 AlignmentAnnotation startAA = ap.av.getAlignment()
621 .getAlignmentAnnotation()[start];
624 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
626 AlignmentAnnotation endAA = ap.av.getAlignment()
627 .getAlignmentAnnotation()[end];
629 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
630 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
636 ap.getAnnotationPanel().repaint();
640 * Removes the height adjuster image on leaving the panel, unless currently
644 public void mouseExited(MouseEvent evt)
646 if (resizePanel && dragEvent == null)
654 * A mouse drag may be either an adjustment of the panel height (if flag
655 * resizePanel is set on), or a reordering of the annotation rows. The former
656 * is dealt with by this method, the latter in mouseReleased.
661 public void mouseDragged(MouseEvent evt)
667 Dimension d = ap.annotationScroller.getPreferredSize();
668 int dif = evt.getY() - oldY;
670 dif /= ap.av.getCharHeight();
671 dif *= ap.av.getCharHeight();
673 if ((d.height - dif) > 20)
675 ap.annotationScroller
676 .setPreferredSize(new Dimension(d.width, d.height - dif));
677 d = ap.annotationSpaceFillerHolder.getPreferredSize();
678 ap.annotationSpaceFillerHolder
679 .setPreferredSize(new Dimension(d.width, d.height - dif));
680 ap.paintAlignment(true, false);
692 * Updates the tooltip as the mouse moves over the labels
697 public void mouseMoved(MouseEvent evt)
699 showOrHideAdjuster(evt);
701 getSelectedRow(evt.getY() - getScrollOffset());
703 if (selectedRow > -1 && ap.av.getAlignment()
704 .getAlignmentAnnotation().length > selectedRow)
706 AlignmentAnnotation aa = ap.av.getAlignment()
707 .getAlignmentAnnotation()[selectedRow];
709 StringBuffer desc = new StringBuffer();
710 if (aa.description != null
711 && !aa.description.equals("New description"))
713 // TODO: we could refactor and merge this code with the code in
714 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
716 desc.append(aa.getDescription(true).trim());
717 // check to see if the description is an html fragment.
718 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
719 .indexOf("<html>") < 0))
721 // clean the description ready for embedding in html
722 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
723 .replaceAll("<"));
724 desc.insert(0, "<html>");
728 // remove terminating html if any
729 int i = desc.substring(desc.length() - 7).toLowerCase()
730 .lastIndexOf("</html>");
733 desc.setLength(desc.length() - 7 + i);
738 desc.append("<br/>");
740 // if (aa.hasProperties())
742 // desc.append("<table>");
743 // for (String prop : aa.getProperties())
745 // desc.append("<tr><td>" + prop + "</td><td>"
746 // + aa.getProperty(prop) + "</td><tr>");
748 // desc.append("</table>");
753 // begin the tooltip's html fragment
754 desc.append("<html>");
757 // TODO: limit precision of score to avoid noise from imprecise
759 // (64.7 becomes 64.7+/some tiny value).
760 desc.append(" Score: " + aa.score);
763 if (desc.length() > 6)
765 desc.append("</html>");
766 this.setToolTipText(desc.toString());
770 this.setToolTipText(null);
776 * Shows the height adjuster image if the mouse moves into the top left
777 * region, or hides it if the mouse leaves the regio
781 protected void showOrHideAdjuster(MouseEvent evt)
783 boolean was = resizePanel;
784 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT
785 && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
787 if (resizePanel != was)
790 .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR
791 : Cursor.DEFAULT_CURSOR));
797 public void mouseClicked(MouseEvent evt)
799 final AlignmentAnnotation[] aa = ap.av.getAlignment()
800 .getAlignmentAnnotation();
801 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
803 if (selectedRow > -1 && selectedRow < aa.length)
805 if (aa[selectedRow].groupRef != null)
807 if (evt.getClickCount() >= 2)
809 // todo: make the ap scroll to the selection - not necessary, first
810 // click highlights/scrolls, second selects
811 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
813 SequenceGroup sg = ap.av.getSelectionGroup();
814 if (sg == null || sg == aa[selectedRow].groupRef
815 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
817 if (Platform.isControlDown(evt) || evt.isShiftDown())
819 // clone a new selection group from the associated group
820 ap.av.setSelectionGroup(
821 new SequenceGroup(aa[selectedRow].groupRef));
825 // set selection to the associated group so it can be edited
826 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
831 // modify current selection with associated group
832 int remainToAdd = aa[selectedRow].groupRef.getSize();
833 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
835 if (jalview.util.Platform.isControlDown(evt))
837 sg.addOrRemove(sgs, --remainToAdd == 0);
841 // notionally, we should also add intermediate sequences from
842 // last added sequence ?
843 sg.addSequence(sgs, --remainToAdd == 0);
848 ap.paintAlignment(false, false);
849 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
850 ap.av.sendSelection();
854 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
855 aa[selectedRow].groupRef.getSequences(null));
859 else if (aa[selectedRow].sequenceRef != null)
861 if (evt.getClickCount() == 1)
863 ap.getSeqPanel().ap.getIdPanel()
864 .highlightSearchResults(Arrays.asList(new SequenceI[]
865 { aa[selectedRow].sequenceRef }));
867 else if (evt.getClickCount() >= 2)
869 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
870 SequenceGroup sg = ap.av.getSelectionGroup();
873 // we make a copy rather than edit the current selection if no
875 // see Enhancement JAL-1557
876 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
878 sg = new SequenceGroup(sg);
880 sg.addSequence(aa[selectedRow].sequenceRef, false);
884 if (Platform.isControlDown(evt))
886 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
890 // notionally, we should also add intermediate sequences from
891 // last added sequence ?
892 sg.addSequence(aa[selectedRow].sequenceRef, true);
898 sg = new SequenceGroup();
900 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
901 sg.addSequence(aa[selectedRow].sequenceRef, false);
903 ap.av.setSelectionGroup(sg);
904 ap.paintAlignment(false, false);
905 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
906 ap.av.sendSelection();
916 * do a single sequence copy to jalview and the system clipboard
919 * sequence to be copied to clipboard
921 protected void copy_annotseqtoclipboard(SequenceI sq)
923 SequenceI[] seqs = new SequenceI[] { sq };
924 String[] omitHidden = null;
925 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
926 if (dseqs[0] == null)
928 dseqs[0] = new Sequence(sq);
929 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
930 sq.getSequenceAsString()));
932 sq.setDatasetSequence(dseqs[0]);
934 Alignment ds = new Alignment(dseqs);
935 if (av.hasHiddenColumns())
937 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
938 .getVisContigsIterator(0, sq.getLength(), false);
939 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
942 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
943 if (av.hasHiddenColumns())
945 alignmentStartEnd = av.getAlignment().getHiddenColumns()
946 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
949 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
950 seqs, omitHidden, alignmentStartEnd);
952 Toolkit.getDefaultToolkit().getSystemClipboard()
953 .setContents(new StringSelection(output), Desktop.instance);
955 HiddenColumns hiddenColumns = null;
957 if (av.hasHiddenColumns())
959 hiddenColumns = new HiddenColumns(
960 av.getAlignment().getHiddenColumns());
963 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
965 // sequence ? need to
967 // sequence as special.
978 public void paintComponent(Graphics g)
981 int width = getWidth();
984 width = ap.calculateIdWidth().width + 4;
987 Graphics2D g2 = (Graphics2D) g;
990 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
991 RenderingHints.VALUE_ANTIALIAS_ON);
994 drawComponent(g2, true, width);
999 * Draw the full set of annotation Labels for the alignment at the given
1003 * Graphics2D instance (needed for font scaling)
1005 * Width for scaling labels
1008 public void drawComponent(Graphics g, int width)
1010 drawComponent(g, false, width);
1014 * Draw the full set of annotation Labels for the alignment at the given
1018 * Graphics2D instance (needed for font scaling)
1020 * - true indicates that only current visible area needs to be
1023 * Width for scaling labels
1025 public void drawComponent(Graphics g, boolean clip, int width)
1027 if (av.getFont().getSize() < 10)
1033 g.setFont(av.getFont());
1036 FontMetrics fm = g.getFontMetrics(g.getFont());
1037 g.setColor(Color.white);
1038 g.fillRect(0, 0, getWidth(), getHeight());
1040 g.translate(0, getScrollOffset());
1041 g.setColor(Color.black);
1043 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1044 int fontHeight = g.getFont().getSize();
1047 int graphExtras = 0;
1049 Font baseFont = g.getFont();
1050 FontMetrics baseMetrics = fm;
1051 int ofontH = fontHeight;
1054 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1055 ? ap.getAnnotationPanel().getVisibleVRange()
1057 if (clip && visr != null)
1060 visHeight = visr[1];
1062 boolean visible = true, before = false, after = false;
1065 hasHiddenRows = false;
1067 for (int i = 0; i < aa.length; i++)
1072 hasHiddenRows = true;
1085 System.out.println("before vis: " + i);
1089 // don't draw what isn't visible
1092 if (olY > visHeight)
1100 "Scroll offset: " + sOffset + " after vis: " + i);
1104 // don't draw what isn't visible
1108 g.setColor(Color.black);
1110 offset = -aa[i].height / 2;
1114 offset += fm.getHeight() / 2;
1115 offset -= fm.getDescent();
1119 offset += fm.getDescent();
1122 x = width - fm.stringWidth(aa[i].label) - 3;
1124 if (aa[i].graphGroup > -1)
1127 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1128 // computed efficiently for all visible labels
1129 for (int gg = 0; gg < aa.length; gg++)
1131 if (aa[gg].graphGroup == aa[i].graphGroup)
1136 if (groupSize * (fontHeight + 8) < aa[i].height)
1138 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1143 // scale font to fit
1144 float h = aa[i].height / (float) groupSize, s;
1151 fontHeight = -8 + (int) h;
1152 s = ((float) fontHeight) / (float) ofontH;
1154 .deriveFont(AffineTransform.getScaleInstance(s, s));
1156 fm = g.getFontMetrics();
1157 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1163 for (int gg = 0; gg < aa.length; gg++)
1165 if (aa[gg].graphGroup == aa[i].graphGroup)
1167 x = width - fm.stringWidth(aa[gg].label) - 3;
1168 g.drawString(aa[gg].label, x, y - graphExtras);
1170 if (aa[gg]._linecolour != null)
1173 g.setColor(aa[gg]._linecolour);
1174 g.drawLine(x, y - graphExtras + 3,
1175 x + fm.stringWidth(aa[gg].label),
1176 y - graphExtras + 3);
1179 g.setColor(Color.black);
1180 graphExtras += fontHeight + 8;
1184 g.setFont(baseFont);
1186 fontHeight = ofontH;
1190 g.drawString(aa[i].label, x, y + offset);
1195 if (!resizePanel && dragEvent != null && aa != null)
1197 g.setColor(Color.lightGray);
1198 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1199 dragEvent.getY() - getScrollOffset());
1202 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1204 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1205 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1210 public int getScrollOffset()
1212 return scrollOffset;
1216 public void mouseEntered(MouseEvent e)