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.util.Arrays;
55 import java.util.Collections;
56 import java.util.Iterator;
57 import java.util.regex.Pattern;
59 import javax.swing.JCheckBoxMenuItem;
60 import javax.swing.JMenuItem;
61 import javax.swing.JPanel;
62 import javax.swing.JPopupMenu;
63 import javax.swing.SwingUtilities;
64 import javax.swing.ToolTipManager;
67 * The panel that holds the labels for alignment annotations, providing
68 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
71 public class AnnotationLabels extends JPanel
72 implements MouseListener, MouseMotionListener, ActionListener
75 * width in pixels within which height adjuster arrows are shown and active
77 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
80 * height in pixels for allowing height adjuster to be active
82 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
84 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
87 private static final Font font = new Font("Arial", Font.PLAIN, 11);
89 private static final String TOGGLE_LABELSCALE = MessageManager
90 .getString("label.scale_label_to_column");
92 private static final String ADDNEW = MessageManager
93 .getString("label.add_new_row");
95 private static final String EDITNAME = MessageManager
96 .getString("label.edit_label_description");
98 private static final String HIDE = MessageManager
99 .getString("label.hide_row");
101 private static final String DELETE = MessageManager
102 .getString("label.delete_row");
104 private static final String SHOWALL = MessageManager
105 .getString("label.show_all_hidden_rows");
107 private static final String OUTPUT_TEXT = MessageManager
108 .getString("label.export_annotation");
110 private static final String COPYCONS_SEQ = MessageManager
111 .getString("label.copy_consensus_sequence");
113 private final boolean debugRedraw = false;
115 private AlignmentPanel ap;
119 private MouseEvent dragEvent;
123 private int selectedRow;
125 private int scrollOffset = 0;
127 private boolean hasHiddenRows;
129 private boolean resizePanel = false;
132 * Creates a new AnnotationLabels object
136 public AnnotationLabels(AlignmentPanel ap)
140 ToolTipManager.sharedInstance().registerComponent(this);
142 addMouseListener(this);
143 addMouseMotionListener(this);
144 addMouseWheelListener(ap.getAnnotationPanel());
147 public AnnotationLabels(AlignViewport av)
158 public void setScrollOffset(int y)
165 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
169 * coordinate position to search for a row
171 void getSelectedRow(int y)
174 AlignmentAnnotation[] aa = ap.av.getAlignment()
175 .getAlignmentAnnotation();
179 for (int i = 0; i < aa.length; i++)
187 height += aa[i].height;
206 public void actionPerformed(ActionEvent evt)
208 AlignmentAnnotation[] aa = ap.av.getAlignment()
209 .getAlignmentAnnotation();
211 String action = evt.getActionCommand();
212 if (ADDNEW.equals(action))
215 * non-returning dialog
217 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
218 null, new Annotation[ap.av.getAlignment().getWidth()]);
219 editLabelDescription(newAnnotation, true);
221 else if (EDITNAME.equals(action))
224 * non-returning dialog
226 editLabelDescription(aa[selectedRow], false);
228 else if (HIDE.equals(action))
230 aa[selectedRow].visible = false;
232 else if (DELETE.equals(action))
234 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
235 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
237 else if (SHOWALL.equals(action))
239 for (int i = 0; i < aa.length; i++)
241 if (!aa[i].visible && aa[i].annotations != null)
243 aa[i].visible = true;
247 else if (OUTPUT_TEXT.equals(action))
249 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
251 else if (COPYCONS_SEQ.equals(action))
253 SequenceI cons = null;
254 if (aa[selectedRow].groupRef != null)
256 cons = aa[selectedRow].groupRef.getConsensusSeq();
260 cons = av.getConsensusSeq();
264 copy_annotseqtoclipboard(cons);
267 else if (TOGGLE_LABELSCALE.equals(action))
269 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
276 * Shows a dialog where the annotation name and description may be edited. If
277 * parameter addNew is true, then on confirmation, a new AlignmentAnnotation
278 * is added, else an existing annotation is updated.
283 void editLabelDescription(AlignmentAnnotation annotation, boolean addNew)
285 String name = MessageManager.getString("label.annotation_name");
286 String description = MessageManager
287 .getString("label.annotation_description");
288 String title = MessageManager
289 .getString("label.edit_annotation_name_description");
290 EditNameDialog dialog = new EditNameDialog(annotation.label,
291 annotation.description, name, description);
293 dialog.showDialog(ap.alignFrame, title,
299 annotation.label = dialog.getName();
300 String text = dialog.getDescription();
301 if (text != null && text.length() == 0)
305 annotation.description = text;
308 ap.av.getAlignment().addAnnotation(annotation);
309 ap.av.getAlignment().setAnnotationIndex(annotation, 0);
317 public void mousePressed(MouseEvent evt)
319 getSelectedRow(evt.getY() - getScrollOffset());
321 if (evt.isPopupTrigger())
328 * Build and show the Pop-up menu at the right-click mouse position
332 void showPopupMenu(MouseEvent evt)
335 final AlignmentAnnotation[] aa = ap.av.getAlignment()
336 .getAlignmentAnnotation();
338 JPopupMenu pop = new JPopupMenu(
339 MessageManager.getString("label.annotations"));
340 JMenuItem item = new JMenuItem(ADDNEW);
341 item.addActionListener(this);
346 { // let the user make everything visible again
347 item = new JMenuItem(SHOWALL);
348 item.addActionListener(this);
351 pop.show(this, evt.getX(), evt.getY());
354 item = new JMenuItem(EDITNAME);
355 item.addActionListener(this);
357 item = new JMenuItem(HIDE);
358 item.addActionListener(this);
360 // JAL-1264 hide all sequence-specific annotations of this type
361 if (selectedRow < aa.length)
363 if (aa[selectedRow].sequenceRef != null)
365 final String label = aa[selectedRow].label;
366 JMenuItem hideType = new JMenuItem();
367 String text = MessageManager.getString("label.hide_all") + " "
369 hideType.setText(text);
370 hideType.addActionListener(new ActionListener()
373 public void actionPerformed(ActionEvent e)
375 AlignmentUtils.showOrHideSequenceAnnotations(
376 ap.av.getAlignment(), Collections.singleton(label),
378 // for (AlignmentAnnotation ann : ap.av.getAlignment()
379 // .getAlignmentAnnotation())
381 // if (ann.sequenceRef != null && ann.label != null
382 // && ann.label.equals(label))
384 // ann.visible = false;
393 item = new JMenuItem(DELETE);
394 item.addActionListener(this);
398 item = new JMenuItem(SHOWALL);
399 item.addActionListener(this);
402 item = new JMenuItem(OUTPUT_TEXT);
403 item.addActionListener(this);
405 // TODO: annotation object should be typed for autocalculated/derived
407 if (selectedRow < aa.length)
409 final String label = aa[selectedRow].label;
410 if (!aa[selectedRow].autoCalculated)
412 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
414 // display formatting settings for this row.
416 // av and sequencegroup need to implement same interface for
417 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
418 aa[selectedRow].scaleColLabel);
419 item.addActionListener(this);
423 else if (label.indexOf("Consensus") > -1)
426 // av and sequencegroup need to implement same interface for
427 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
428 MessageManager.getString("label.ignore_gaps_consensus"),
429 (aa[selectedRow].groupRef != null)
430 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
431 : ap.av.isIgnoreGapsConsensus());
432 final AlignmentAnnotation aaa = aa[selectedRow];
433 cbmi.addActionListener(new ActionListener()
436 public void actionPerformed(ActionEvent e)
438 if (aaa.groupRef != null)
440 // TODO: pass on reference to ap so the view can be updated.
441 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
442 ap.getAnnotationPanel()
443 .paint(ap.getAnnotationPanel().getGraphics());
447 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
449 ap.alignmentChanged();
453 // av and sequencegroup need to implement same interface for
454 if (aaa.groupRef != null)
456 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
457 MessageManager.getString("label.show_group_histogram"),
458 aa[selectedRow].groupRef.isShowConsensusHistogram());
459 chist.addActionListener(new ActionListener()
462 public void actionPerformed(ActionEvent e)
464 // TODO: pass on reference
470 aaa.groupRef.setShowConsensusHistogram(chist.getState());
472 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
476 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
477 MessageManager.getString("label.show_group_logo"),
478 aa[selectedRow].groupRef.isShowSequenceLogo());
479 cprofl.addActionListener(new ActionListener()
482 public void actionPerformed(ActionEvent e)
484 // TODO: pass on reference
490 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
492 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
496 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
497 MessageManager.getString("label.normalise_group_logo"),
498 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
499 cproflnorm.addActionListener(new ActionListener()
502 public void actionPerformed(ActionEvent e)
505 // TODO: pass on reference
511 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
512 // automatically enable logo display if we're clicked
513 aaa.groupRef.setshowSequenceLogo(true);
515 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
522 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
523 MessageManager.getString("label.show_histogram"),
524 av.isShowConsensusHistogram());
525 chist.addActionListener(new ActionListener()
528 public void actionPerformed(ActionEvent e)
530 // TODO: pass on reference
536 av.setShowConsensusHistogram(chist.getState());
537 ap.alignFrame.setMenusForViewport();
539 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
543 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
544 MessageManager.getString("label.show_logo"),
545 av.isShowSequenceLogo());
546 cprof.addActionListener(new ActionListener()
549 public void actionPerformed(ActionEvent e)
551 // TODO: pass on reference
557 av.setShowSequenceLogo(cprof.getState());
558 ap.alignFrame.setMenusForViewport();
560 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
564 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
565 MessageManager.getString("label.normalise_logo"),
566 av.isNormaliseSequenceLogo());
567 cprofnorm.addActionListener(new ActionListener()
570 public void actionPerformed(ActionEvent e)
572 // TODO: pass on reference
578 av.setShowSequenceLogo(true);
579 av.setNormaliseSequenceLogo(cprofnorm.getState());
580 ap.alignFrame.setMenusForViewport();
582 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
587 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
588 consclipbrd.addActionListener(this);
589 pop.add(consclipbrd);
592 pop.show(this, evt.getX(), evt.getY());
596 * Reorders annotation rows after a drag of a label
601 public void mouseReleased(MouseEvent evt)
603 if (evt.isPopupTrigger())
609 int start = selectedRow;
610 getSelectedRow(evt.getY() - getScrollOffset());
611 int end = selectedRow;
614 * if dragging to resize instead, start == end
618 // Swap these annotations
619 AlignmentAnnotation startAA = ap.av.getAlignment()
620 .getAlignmentAnnotation()[start];
623 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
625 AlignmentAnnotation endAA = ap.av.getAlignment()
626 .getAlignmentAnnotation()[end];
628 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
629 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
635 ap.getAnnotationPanel().repaint();
639 * Removes the height adjuster image on leaving the panel, unless currently
643 public void mouseExited(MouseEvent evt)
645 if (resizePanel && dragEvent == null)
653 * A mouse drag may be either an adjustment of the panel height (if flag
654 * resizePanel is set on), or a reordering of the annotation rows. The former
655 * is dealt with by this method, the latter in mouseReleased.
660 public void mouseDragged(MouseEvent evt)
666 Dimension d = ap.annotationScroller.getPreferredSize();
667 int dif = evt.getY() - oldY;
669 dif /= ap.av.getCharHeight();
670 dif *= ap.av.getCharHeight();
672 if ((d.height - dif) > 20)
674 ap.annotationScroller
675 .setPreferredSize(new Dimension(d.width, d.height - dif));
676 d = ap.annotationSpaceFillerHolder.getPreferredSize();
677 ap.annotationSpaceFillerHolder
678 .setPreferredSize(new Dimension(d.width, d.height - dif));
679 ap.paintAlignment(true, false);
691 * Updates the tooltip as the mouse moves over the labels
696 public void mouseMoved(MouseEvent evt)
698 showOrHideAdjuster(evt);
700 getSelectedRow(evt.getY() - getScrollOffset());
702 if (selectedRow > -1 && ap.av.getAlignment()
703 .getAlignmentAnnotation().length > selectedRow)
705 AlignmentAnnotation aa = ap.av.getAlignment()
706 .getAlignmentAnnotation()[selectedRow];
708 StringBuffer desc = new StringBuffer();
709 if (aa.description != null
710 && !aa.description.equals("New description"))
712 // TODO: we could refactor and merge this code with the code in
713 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
715 desc.append(aa.getDescription(true).trim());
716 // check to see if the description is an html fragment.
717 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
718 .indexOf("<html>") < 0))
720 // clean the description ready for embedding in html
721 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
722 .replaceAll("<"));
723 desc.insert(0, "<html>");
727 // remove terminating html if any
728 int i = desc.substring(desc.length() - 7).toLowerCase()
729 .lastIndexOf("</html>");
732 desc.setLength(desc.length() - 7 + i);
737 desc.append("<br/>");
739 // if (aa.hasProperties())
741 // desc.append("<table>");
742 // for (String prop : aa.getProperties())
744 // desc.append("<tr><td>" + prop + "</td><td>"
745 // + aa.getProperty(prop) + "</td><tr>");
747 // desc.append("</table>");
752 // begin the tooltip's html fragment
753 desc.append("<html>");
756 // TODO: limit precision of score to avoid noise from imprecise
758 // (64.7 becomes 64.7+/some tiny value).
759 desc.append(" Score: " + aa.score);
762 if (desc.length() > 6)
764 desc.append("</html>");
765 this.setToolTipText(desc.toString());
769 this.setToolTipText(null);
775 * Shows the height adjuster image if the mouse moves into the top left
776 * region, or hides it if the mouse leaves the regio
780 protected void showOrHideAdjuster(MouseEvent evt)
782 boolean was = resizePanel;
783 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT
784 && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
786 if (resizePanel != was)
789 .getPredefinedCursor(resizePanel ? Cursor.S_RESIZE_CURSOR
790 : Cursor.DEFAULT_CURSOR));
796 public void mouseClicked(MouseEvent evt)
798 final AlignmentAnnotation[] aa = ap.av.getAlignment()
799 .getAlignmentAnnotation();
800 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
802 if (selectedRow > -1 && selectedRow < aa.length)
804 if (aa[selectedRow].groupRef != null)
806 if (evt.getClickCount() >= 2)
808 // todo: make the ap scroll to the selection - not necessary, first
809 // click highlights/scrolls, second selects
810 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
812 SequenceGroup sg = ap.av.getSelectionGroup();
813 if (sg == null || sg == aa[selectedRow].groupRef
814 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
816 if (Platform.isControlDown(evt) || evt.isShiftDown())
818 // clone a new selection group from the associated group
819 ap.av.setSelectionGroup(
820 new SequenceGroup(aa[selectedRow].groupRef));
824 // set selection to the associated group so it can be edited
825 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
830 // modify current selection with associated group
831 int remainToAdd = aa[selectedRow].groupRef.getSize();
832 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
834 if (jalview.util.Platform.isControlDown(evt))
836 sg.addOrRemove(sgs, --remainToAdd == 0);
840 // notionally, we should also add intermediate sequences from
841 // last added sequence ?
842 sg.addSequence(sgs, --remainToAdd == 0);
847 ap.paintAlignment(false, false);
848 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
849 ap.av.sendSelection();
853 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
854 aa[selectedRow].groupRef.getSequences(null));
858 else if (aa[selectedRow].sequenceRef != null)
860 if (evt.getClickCount() == 1)
862 ap.getSeqPanel().ap.getIdPanel()
863 .highlightSearchResults(Arrays.asList(new SequenceI[]
864 { aa[selectedRow].sequenceRef }));
866 else if (evt.getClickCount() >= 2)
868 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
869 SequenceGroup sg = ap.av.getSelectionGroup();
872 // we make a copy rather than edit the current selection if no
874 // see Enhancement JAL-1557
875 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
877 sg = new SequenceGroup(sg);
879 sg.addSequence(aa[selectedRow].sequenceRef, false);
883 if (Platform.isControlDown(evt))
885 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
889 // notionally, we should also add intermediate sequences from
890 // last added sequence ?
891 sg.addSequence(aa[selectedRow].sequenceRef, true);
897 sg = new SequenceGroup();
899 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
900 sg.addSequence(aa[selectedRow].sequenceRef, false);
902 ap.av.setSelectionGroup(sg);
903 ap.paintAlignment(false, false);
904 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
905 ap.av.sendSelection();
915 * do a single sequence copy to jalview and the system clipboard
918 * sequence to be copied to clipboard
920 protected void copy_annotseqtoclipboard(SequenceI sq)
922 SequenceI[] seqs = new SequenceI[] { sq };
923 String[] omitHidden = null;
924 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
925 if (dseqs[0] == null)
927 dseqs[0] = new Sequence(sq);
928 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
929 sq.getSequenceAsString()));
931 sq.setDatasetSequence(dseqs[0]);
933 Alignment ds = new Alignment(dseqs);
934 if (av.hasHiddenColumns())
936 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
937 .getVisContigsIterator(0, sq.getLength(), false);
938 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
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 HiddenColumns hiddenColumns = null;
956 if (av.hasHiddenColumns())
958 hiddenColumns = new HiddenColumns(
959 av.getAlignment().getHiddenColumns());
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)