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.Sequence;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.io.FileFormat;
32 import jalview.io.FormatAdapter;
33 import jalview.util.Comparison;
34 import jalview.util.MessageManager;
35 import jalview.util.Platform;
37 import java.awt.Color;
38 import java.awt.Cursor;
39 import java.awt.Dimension;
41 import java.awt.FontMetrics;
42 import java.awt.Graphics;
43 import java.awt.Graphics2D;
44 import java.awt.RenderingHints;
45 import java.awt.Toolkit;
46 import java.awt.datatransfer.StringSelection;
47 import java.awt.event.ActionEvent;
48 import java.awt.event.ActionListener;
49 import java.awt.event.MouseEvent;
50 import java.awt.event.MouseListener;
51 import java.awt.event.MouseMotionListener;
52 import java.awt.geom.AffineTransform;
53 import java.util.ArrayList;
54 import java.util.Arrays;
55 import java.util.Collections;
56 import java.util.regex.Pattern;
58 import javax.swing.JCheckBoxMenuItem;
59 import javax.swing.JMenuItem;
60 import javax.swing.JPanel;
61 import javax.swing.JPopupMenu;
62 import javax.swing.SwingUtilities;
63 import javax.swing.ToolTipManager;
66 * The panel that holds the labels for alignment annotations, providing
67 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
70 public class AnnotationLabels extends JPanel
71 implements MouseListener, MouseMotionListener, ActionListener
74 * width in pixels within which height adjuster arrows are shown and active
76 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
79 * height in pixels for allowing height adjuster to be active
81 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
83 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
86 private static final Font font = new Font("Arial", Font.PLAIN, 11);
88 private static final String TOGGLE_LABELSCALE = MessageManager
89 .getString("label.scale_label_to_column");
91 private static final String ADDNEW = MessageManager
92 .getString("label.add_new_row");
94 private static final String EDITNAME = MessageManager
95 .getString("label.edit_label_description");
97 private static final String HIDE = MessageManager
98 .getString("label.hide_row");
100 private static final String DELETE = MessageManager
101 .getString("label.delete_row");
103 private static final String SHOWALL = MessageManager
104 .getString("label.show_all_hidden_rows");
106 private static final String OUTPUT_TEXT = MessageManager
107 .getString("label.export_annotation");
109 private static final String COPYCONS_SEQ = MessageManager
110 .getString("label.copy_consensus_sequence");
112 private final boolean debugRedraw = false;
114 private AlignmentPanel ap;
118 private MouseEvent dragEvent;
122 private int selectedRow;
124 private int scrollOffset = 0;
126 private boolean hasHiddenRows;
128 private boolean resizePanel = false;
131 * Creates a new AnnotationLabels object
135 public AnnotationLabels(AlignmentPanel ap)
139 ToolTipManager.sharedInstance().registerComponent(this);
141 addMouseListener(this);
142 addMouseMotionListener(this);
143 addMouseWheelListener(ap.getAnnotationPanel());
146 public AnnotationLabels(AlignViewport av)
157 public void setScrollOffset(int y)
164 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
168 * coordinate position to search for a row
170 void getSelectedRow(int y)
173 AlignmentAnnotation[] aa = ap.av.getAlignment()
174 .getAlignmentAnnotation();
178 for (int i = 0; i < aa.length; i++)
186 height += aa[i].height;
205 public void actionPerformed(ActionEvent evt)
207 AlignmentAnnotation[] aa = ap.av.getAlignment()
208 .getAlignmentAnnotation();
210 boolean fullRepaint = false;
211 if (evt.getActionCommand().equals(ADDNEW))
213 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
214 null, new Annotation[ap.av.getAlignment().getWidth()]);
216 if (!editLabelDescription(newAnnotation))
221 ap.av.getAlignment().addAnnotation(newAnnotation);
222 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
225 else if (evt.getActionCommand().equals(EDITNAME))
227 String name = aa[selectedRow].label;
228 editLabelDescription(aa[selectedRow]);
229 if (!name.equalsIgnoreCase(aa[selectedRow].label))
234 else if (evt.getActionCommand().equals(HIDE))
236 aa[selectedRow].visible = false;
238 else if (evt.getActionCommand().equals(DELETE))
240 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
241 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
244 else if (evt.getActionCommand().equals(SHOWALL))
246 for (int i = 0; i < aa.length; i++)
248 if (!aa[i].visible && aa[i].annotations != null)
250 aa[i].visible = true;
255 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
257 new AnnotationExporter().exportAnnotations(ap,
258 new AlignmentAnnotation[]
259 { aa[selectedRow] });
261 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
263 SequenceI cons = null;
264 if (aa[selectedRow].groupRef != null)
266 cons = aa[selectedRow].groupRef.getConsensusSeq();
270 cons = av.getConsensusSeq();
274 copy_annotseqtoclipboard(cons);
278 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
280 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
283 ap.refresh(fullRepaint);
293 boolean editLabelDescription(AlignmentAnnotation annotation)
296 EditNameDialog dialog = new EditNameDialog(annotation.label,
297 annotation.description, " Annotation Name ",
298 "Annotation Description ", "Edit Annotation Name/Description",
306 annotation.label = dialog.getName();
308 String text = dialog.getDescription();
309 if (text != null && text.length() == 0)
313 annotation.description = text;
319 public void mousePressed(MouseEvent evt)
321 getSelectedRow(evt.getY() - getScrollOffset());
323 if (evt.isPopupTrigger())
330 * Build and show the Pop-up menu at the right-click mouse position
334 void showPopupMenu(MouseEvent evt)
337 final AlignmentAnnotation[] aa = ap.av.getAlignment()
338 .getAlignmentAnnotation();
340 JPopupMenu pop = new JPopupMenu(
341 MessageManager.getString("label.annotations"));
342 JMenuItem item = new JMenuItem(ADDNEW);
343 item.addActionListener(this);
348 { // let the user make everything visible again
349 item = new JMenuItem(SHOWALL);
350 item.addActionListener(this);
353 pop.show(this, evt.getX(), evt.getY());
356 item = new JMenuItem(EDITNAME);
357 item.addActionListener(this);
359 item = new JMenuItem(HIDE);
360 item.addActionListener(this);
362 // JAL-1264 hide all sequence-specific annotations of this type
363 if (selectedRow < aa.length)
365 if (aa[selectedRow].sequenceRef != null)
367 final String label = aa[selectedRow].label;
368 JMenuItem hideType = new JMenuItem();
369 String text = MessageManager.getString("label.hide_all") + " "
371 hideType.setText(text);
372 hideType.addActionListener(new ActionListener()
375 public void actionPerformed(ActionEvent e)
377 AlignmentUtils.showOrHideSequenceAnnotations(
378 ap.av.getAlignment(), Collections.singleton(label),
380 // for (AlignmentAnnotation ann : ap.av.getAlignment()
381 // .getAlignmentAnnotation())
383 // if (ann.sequenceRef != null && ann.label != null
384 // && ann.label.equals(label))
386 // ann.visible = false;
395 item = new JMenuItem(DELETE);
396 item.addActionListener(this);
400 item = new JMenuItem(SHOWALL);
401 item.addActionListener(this);
404 item = new JMenuItem(OUTPUT_TEXT);
405 item.addActionListener(this);
407 // TODO: annotation object should be typed for autocalculated/derived
409 if (selectedRow < aa.length)
411 final String label = aa[selectedRow].label;
412 if (!aa[selectedRow].autoCalculated)
414 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
416 // display formatting settings for this row.
418 // av and sequencegroup need to implement same interface for
419 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
420 aa[selectedRow].scaleColLabel);
421 item.addActionListener(this);
425 else if (label.indexOf("Consensus") > -1)
428 // av and sequencegroup need to implement same interface for
429 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
430 MessageManager.getString("label.ignore_gaps_consensus"),
431 (aa[selectedRow].groupRef != null)
432 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
433 : ap.av.isIgnoreGapsConsensus());
434 final AlignmentAnnotation aaa = aa[selectedRow];
435 cbmi.addActionListener(new ActionListener()
438 public void actionPerformed(ActionEvent e)
440 if (aaa.groupRef != null)
442 // TODO: pass on reference to ap so the view can be updated.
443 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
444 ap.getAnnotationPanel()
445 .paint(ap.getAnnotationPanel().getGraphics());
449 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
451 ap.alignmentChanged();
455 // av and sequencegroup need to implement same interface for
456 if (aaa.groupRef != null)
458 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
459 MessageManager.getString("label.show_group_histogram"),
460 aa[selectedRow].groupRef.isShowConsensusHistogram());
461 chist.addActionListener(new ActionListener()
464 public void actionPerformed(ActionEvent e)
466 // TODO: pass on reference
472 aaa.groupRef.setShowConsensusHistogram(chist.getState());
474 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
478 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
479 MessageManager.getString("label.show_group_logo"),
480 aa[selectedRow].groupRef.isShowSequenceLogo());
481 cprofl.addActionListener(new ActionListener()
484 public void actionPerformed(ActionEvent e)
486 // TODO: pass on reference
492 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
494 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
498 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
499 MessageManager.getString("label.normalise_group_logo"),
500 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
501 cproflnorm.addActionListener(new ActionListener()
504 public void actionPerformed(ActionEvent e)
507 // TODO: pass on reference
513 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
514 // automatically enable logo display if we're clicked
515 aaa.groupRef.setshowSequenceLogo(true);
517 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
524 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
525 MessageManager.getString("label.show_histogram"),
526 av.isShowConsensusHistogram());
527 chist.addActionListener(new ActionListener()
530 public void actionPerformed(ActionEvent e)
532 // TODO: pass on reference
538 av.setShowConsensusHistogram(chist.getState());
539 ap.alignFrame.setMenusForViewport();
541 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
545 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
546 MessageManager.getString("label.show_logo"),
547 av.isShowSequenceLogo());
548 cprof.addActionListener(new ActionListener()
551 public void actionPerformed(ActionEvent e)
553 // TODO: pass on reference
559 av.setShowSequenceLogo(cprof.getState());
560 ap.alignFrame.setMenusForViewport();
562 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
566 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
567 MessageManager.getString("label.normalise_logo"),
568 av.isNormaliseSequenceLogo());
569 cprofnorm.addActionListener(new ActionListener()
572 public void actionPerformed(ActionEvent e)
574 // TODO: pass on reference
580 av.setShowSequenceLogo(true);
581 av.setNormaliseSequenceLogo(cprofnorm.getState());
582 ap.alignFrame.setMenusForViewport();
584 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
589 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
590 consclipbrd.addActionListener(this);
591 pop.add(consclipbrd);
594 pop.show(this, evt.getX(), evt.getY());
598 * Reorders annotation rows after a drag of a label
603 public void mouseReleased(MouseEvent evt)
605 if (evt.isPopupTrigger())
611 int start = selectedRow;
612 getSelectedRow(evt.getY() - getScrollOffset());
613 int end = selectedRow;
616 * if dragging to resize instead, start == end
620 // Swap these annotations
621 AlignmentAnnotation startAA = ap.av.getAlignment()
622 .getAlignmentAnnotation()[start];
625 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
627 AlignmentAnnotation endAA = ap.av.getAlignment()
628 .getAlignmentAnnotation()[end];
630 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
631 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
637 ap.getAnnotationPanel().repaint();
641 * Removes the height adjuster image on leaving the panel, unless currently
645 public void mouseExited(MouseEvent evt)
647 if (resizePanel && dragEvent == null)
655 * A mouse drag may be either an adjustment of the panel height (if flag
656 * resizePanel is set on), or a reordering of the annotation rows. The former
657 * is dealt with by this method, the latter in mouseReleased.
662 public void mouseDragged(MouseEvent evt)
668 Dimension d = ap.annotationScroller.getPreferredSize();
669 int dif = evt.getY() - oldY;
671 dif /= ap.av.getCharHeight();
672 dif *= ap.av.getCharHeight();
674 if ((d.height - dif) > 20)
676 ap.annotationScroller
677 .setPreferredSize(new Dimension(d.width, d.height - dif));
678 d = ap.annotationSpaceFillerHolder.getPreferredSize();
679 ap.annotationSpaceFillerHolder
680 .setPreferredSize(new Dimension(d.width, d.height - dif));
681 ap.paintAlignment(true, false);
693 * Updates the tooltip as the mouse moves over the labels
698 public void mouseMoved(MouseEvent evt)
700 showOrHideAdjuster(evt);
702 getSelectedRow(evt.getY() - getScrollOffset());
704 if (selectedRow > -1 && ap.av.getAlignment()
705 .getAlignmentAnnotation().length > selectedRow)
707 AlignmentAnnotation aa = ap.av.getAlignment()
708 .getAlignmentAnnotation()[selectedRow];
710 StringBuffer desc = new StringBuffer();
711 if (aa.description != null
712 && !aa.description.equals("New description"))
714 // TODO: we could refactor and merge this code with the code in
715 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
717 desc.append(aa.getDescription(true).trim());
718 // check to see if the description is an html fragment.
719 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
720 .indexOf("<html>") < 0))
722 // clean the description ready for embedding in html
723 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
724 .replaceAll("<"));
725 desc.insert(0, "<html>");
729 // remove terminating html if any
730 int i = desc.substring(desc.length() - 7).toLowerCase()
731 .lastIndexOf("</html>");
734 desc.setLength(desc.length() - 7 + i);
739 desc.append("<br/>");
741 // if (aa.hasProperties())
743 // desc.append("<table>");
744 // for (String prop : aa.getProperties())
746 // desc.append("<tr><td>" + prop + "</td><td>"
747 // + aa.getProperty(prop) + "</td><tr>");
749 // desc.append("</table>");
754 // begin the tooltip's html fragment
755 desc.append("<html>");
758 // TODO: limit precision of score to avoid noise from imprecise
760 // (64.7 becomes 64.7+/some tiny value).
761 desc.append(" Score: " + aa.score);
764 if (desc.length() > 6)
766 desc.append("</html>");
767 this.setToolTipText(desc.toString());
771 this.setToolTipText(null);
777 * Shows the height adjuster image if the mouse moves into the top left
778 * region, or hides it if the mouse leaves the regio
782 protected void showOrHideAdjuster(MouseEvent evt)
784 boolean was = resizePanel;
785 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
787 if (resizePanel != was)
789 setCursor(Cursor.getPredefinedCursor(
790 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 omitHidden = av.getAlignment().getHiddenColumns()
938 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
941 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
942 if (av.hasHiddenColumns())
944 alignmentStartEnd = av.getAlignment().getHiddenColumns()
945 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
948 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
949 seqs, omitHidden, alignmentStartEnd);
951 Toolkit.getDefaultToolkit().getSystemClipboard()
952 .setContents(new StringSelection(output), Desktop.instance);
954 ArrayList<int[]> hiddenColumns = null;
956 if (av.hasHiddenColumns())
958 hiddenColumns = av.getAlignment().getHiddenColumns()
959 .getHiddenColumnsCopy();
962 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
964 // sequence ? need to
966 // sequence as special.
977 public void paintComponent(Graphics g)
980 int width = getWidth();
983 width = ap.calculateIdWidth().width + 4;
986 Graphics2D g2 = (Graphics2D) g;
989 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
990 RenderingHints.VALUE_ANTIALIAS_ON);
993 drawComponent(g2, true, width);
998 * Draw the full set of annotation Labels for the alignment at the given
1002 * Graphics2D instance (needed for font scaling)
1004 * Width for scaling labels
1007 public void drawComponent(Graphics g, int width)
1009 drawComponent(g, false, width);
1013 * Draw the full set of annotation Labels for the alignment at the given
1017 * Graphics2D instance (needed for font scaling)
1019 * - true indicates that only current visible area needs to be
1022 * Width for scaling labels
1024 public void drawComponent(Graphics g, boolean clip, int width)
1026 if (av.getFont().getSize() < 10)
1032 g.setFont(av.getFont());
1035 FontMetrics fm = g.getFontMetrics(g.getFont());
1036 g.setColor(Color.white);
1037 g.fillRect(0, 0, getWidth(), getHeight());
1039 g.translate(0, getScrollOffset());
1040 g.setColor(Color.black);
1042 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1043 int fontHeight = g.getFont().getSize();
1046 int graphExtras = 0;
1048 Font baseFont = g.getFont();
1049 FontMetrics baseMetrics = fm;
1050 int ofontH = fontHeight;
1053 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1054 ? ap.getAnnotationPanel().getVisibleVRange()
1056 if (clip && visr != null)
1059 visHeight = visr[1];
1061 boolean visible = true, before = false, after = false;
1064 hasHiddenRows = false;
1066 for (int i = 0; i < aa.length; i++)
1071 hasHiddenRows = true;
1084 System.out.println("before vis: " + i);
1088 // don't draw what isn't visible
1091 if (olY > visHeight)
1099 "Scroll offset: " + sOffset + " after vis: " + i);
1103 // don't draw what isn't visible
1107 g.setColor(Color.black);
1109 offset = -aa[i].height / 2;
1113 offset += fm.getHeight() / 2;
1114 offset -= fm.getDescent();
1118 offset += fm.getDescent();
1121 x = width - fm.stringWidth(aa[i].label) - 3;
1123 if (aa[i].graphGroup > -1)
1126 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1127 // computed efficiently for all visible labels
1128 for (int gg = 0; gg < aa.length; gg++)
1130 if (aa[gg].graphGroup == aa[i].graphGroup)
1135 if (groupSize * (fontHeight + 8) < aa[i].height)
1137 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1142 // scale font to fit
1143 float h = aa[i].height / (float) groupSize, s;
1150 fontHeight = -8 + (int) h;
1151 s = ((float) fontHeight) / (float) ofontH;
1153 .deriveFont(AffineTransform.getScaleInstance(s, s));
1155 fm = g.getFontMetrics();
1156 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1162 for (int gg = 0; gg < aa.length; gg++)
1164 if (aa[gg].graphGroup == aa[i].graphGroup)
1166 x = width - fm.stringWidth(aa[gg].label) - 3;
1167 g.drawString(aa[gg].label, x, y - graphExtras);
1169 if (aa[gg]._linecolour != null)
1172 g.setColor(aa[gg]._linecolour);
1173 g.drawLine(x, y - graphExtras + 3,
1174 x + fm.stringWidth(aa[gg].label),
1175 y - graphExtras + 3);
1178 g.setColor(Color.black);
1179 graphExtras += fontHeight + 8;
1183 g.setFont(baseFont);
1185 fontHeight = ofontH;
1189 g.drawString(aa[i].label, x, y + offset);
1194 if (!resizePanel && dragEvent != null && aa != null)
1196 g.setColor(Color.lightGray);
1197 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1198 dragEvent.getY() - getScrollOffset());
1201 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1203 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1204 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1209 public int getScrollOffset()
1211 return scrollOffset;
1215 public void mouseEntered(MouseEvent e)