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.Image;
45 import java.awt.MediaTracker;
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.awt.image.BufferedImage;
56 import java.util.ArrayList;
57 import java.util.Arrays;
58 import java.util.Collections;
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
76 // width in pixels within which height adjuster arrows are shown and active
77 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
79 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
82 private static final Font font = new Font("Arial", Font.PLAIN, 11);
84 private static final String TOGGLE_LABELSCALE = MessageManager
85 .getString("label.scale_label_to_column");
87 private static final String ADDNEW = MessageManager
88 .getString("label.add_new_row");
90 private static final String EDITNAME = MessageManager
91 .getString("label.edit_label_description");
93 private static final String HIDE = MessageManager
94 .getString("label.hide_row");
96 private static final String DELETE = MessageManager
97 .getString("label.delete_row");
99 private static final String SHOWALL = MessageManager
100 .getString("label.show_all_hidden_rows");
102 private static final String OUTPUT_TEXT = MessageManager
103 .getString("label.export_annotation");
105 private static final String COPYCONS_SEQ = MessageManager
106 .getString("label.copy_consensus_sequence");
108 private static Image adjusterImage;
110 private static int adjusterImageHeight;
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 if (adjusterImage == null)
146 addMouseListener(this);
147 addMouseMotionListener(this);
148 addMouseWheelListener(ap.getAnnotationPanel());
151 public AnnotationLabels(AlignViewport av)
157 * Loads the gif for the panel height adjustment
159 protected void loadAdjusterImage()
161 java.net.URL url = getClass().getResource("/images/idwidth.gif");
166 temp = Toolkit.getDefaultToolkit().createImage(url);
171 MediaTracker mt = new MediaTracker(this);
172 mt.addImage(temp, 0);
174 } catch (Exception ex)
178 BufferedImage bi = new BufferedImage(temp.getHeight(this),
179 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
180 Graphics2D g = (Graphics2D) bi.getGraphics();
181 g.rotate(Math.toRadians(90));
182 g.drawImage(temp, 0, -bi.getWidth(this), this);
184 adjusterImageHeight = bi.getHeight();
193 public void setScrollOffset(int y)
200 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
204 * coordinate position to search for a row
206 void getSelectedRow(int y)
209 AlignmentAnnotation[] aa = ap.av.getAlignment()
210 .getAlignmentAnnotation();
214 for (int i = 0; i < aa.length; i++)
222 height += aa[i].height;
241 public void actionPerformed(ActionEvent evt)
243 AlignmentAnnotation[] aa = ap.av.getAlignment()
244 .getAlignmentAnnotation();
246 boolean fullRepaint = false;
247 if (evt.getActionCommand().equals(ADDNEW))
249 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
250 null, new Annotation[ap.av.getAlignment().getWidth()]);
252 if (!editLabelDescription(newAnnotation))
257 ap.av.getAlignment().addAnnotation(newAnnotation);
258 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
261 else if (evt.getActionCommand().equals(EDITNAME))
263 String name = aa[selectedRow].label;
264 editLabelDescription(aa[selectedRow]);
265 if (!name.equalsIgnoreCase(aa[selectedRow].label))
270 else if (evt.getActionCommand().equals(HIDE))
272 aa[selectedRow].visible = false;
274 else if (evt.getActionCommand().equals(DELETE))
276 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
277 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
280 else if (evt.getActionCommand().equals(SHOWALL))
282 for (int i = 0; i < aa.length; i++)
284 if (!aa[i].visible && aa[i].annotations != null)
286 aa[i].visible = true;
291 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
293 new AnnotationExporter().exportAnnotations(ap,
294 new AlignmentAnnotation[]
295 { aa[selectedRow] });
297 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
299 SequenceI cons = null;
300 if (aa[selectedRow].groupRef != null)
302 cons = aa[selectedRow].groupRef.getConsensusSeq();
306 cons = av.getConsensusSeq();
310 copy_annotseqtoclipboard(cons);
314 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
316 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
319 ap.refresh(fullRepaint);
329 boolean editLabelDescription(AlignmentAnnotation annotation)
332 EditNameDialog dialog = new EditNameDialog(annotation.label,
333 annotation.description, " Annotation Name ",
334 "Annotation Description ", "Edit Annotation Name/Description",
342 annotation.label = dialog.getName();
344 String text = dialog.getDescription();
345 if (text != null && text.length() == 0)
349 annotation.description = text;
355 public void mousePressed(MouseEvent evt)
357 getSelectedRow(evt.getY() - getScrollOffset());
359 if (evt.isPopupTrigger())
366 * Build and show the Pop-up menu at the right-click mouse position
370 void showPopupMenu(MouseEvent evt)
373 final AlignmentAnnotation[] aa = ap.av.getAlignment()
374 .getAlignmentAnnotation();
376 JPopupMenu pop = new JPopupMenu(
377 MessageManager.getString("label.annotations"));
378 JMenuItem item = new JMenuItem(ADDNEW);
379 item.addActionListener(this);
384 { // let the user make everything visible again
385 item = new JMenuItem(SHOWALL);
386 item.addActionListener(this);
389 pop.show(this, evt.getX(), evt.getY());
392 item = new JMenuItem(EDITNAME);
393 item.addActionListener(this);
395 item = new JMenuItem(HIDE);
396 item.addActionListener(this);
398 // JAL-1264 hide all sequence-specific annotations of this type
399 if (selectedRow < aa.length)
401 if (aa[selectedRow].sequenceRef != null)
403 final String label = aa[selectedRow].label;
404 JMenuItem hideType = new JMenuItem();
405 String text = MessageManager.getString("label.hide_all") + " "
407 hideType.setText(text);
408 hideType.addActionListener(new ActionListener()
411 public void actionPerformed(ActionEvent e)
413 AlignmentUtils.showOrHideSequenceAnnotations(
414 ap.av.getAlignment(), Collections.singleton(label),
416 // for (AlignmentAnnotation ann : ap.av.getAlignment()
417 // .getAlignmentAnnotation())
419 // if (ann.sequenceRef != null && ann.label != null
420 // && ann.label.equals(label))
422 // ann.visible = false;
431 item = new JMenuItem(DELETE);
432 item.addActionListener(this);
436 item = new JMenuItem(SHOWALL);
437 item.addActionListener(this);
440 item = new JMenuItem(OUTPUT_TEXT);
441 item.addActionListener(this);
443 // TODO: annotation object should be typed for autocalculated/derived
445 if (selectedRow < aa.length)
447 final String label = aa[selectedRow].label;
448 if (!aa[selectedRow].autoCalculated)
450 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
452 // display formatting settings for this row.
454 // av and sequencegroup need to implement same interface for
455 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
456 aa[selectedRow].scaleColLabel);
457 item.addActionListener(this);
461 else if (label.indexOf("Consensus") > -1)
464 // av and sequencegroup need to implement same interface for
465 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
466 MessageManager.getString("label.ignore_gaps_consensus"),
467 (aa[selectedRow].groupRef != null)
468 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
469 : ap.av.isIgnoreGapsConsensus());
470 final AlignmentAnnotation aaa = aa[selectedRow];
471 cbmi.addActionListener(new ActionListener()
474 public void actionPerformed(ActionEvent e)
476 if (aaa.groupRef != null)
478 // TODO: pass on reference to ap so the view can be updated.
479 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
480 ap.getAnnotationPanel()
481 .paint(ap.getAnnotationPanel().getGraphics());
485 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
487 ap.alignmentChanged();
491 // av and sequencegroup need to implement same interface for
492 if (aaa.groupRef != null)
494 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
495 MessageManager.getString("label.show_group_histogram"),
496 aa[selectedRow].groupRef.isShowConsensusHistogram());
497 chist.addActionListener(new ActionListener()
500 public void actionPerformed(ActionEvent e)
502 // TODO: pass on reference
508 aaa.groupRef.setShowConsensusHistogram(chist.getState());
510 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
514 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
515 MessageManager.getString("label.show_group_logo"),
516 aa[selectedRow].groupRef.isShowSequenceLogo());
517 cprofl.addActionListener(new ActionListener()
520 public void actionPerformed(ActionEvent e)
522 // TODO: pass on reference
528 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
530 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
534 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
535 MessageManager.getString("label.normalise_group_logo"),
536 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
537 cproflnorm.addActionListener(new ActionListener()
540 public void actionPerformed(ActionEvent e)
543 // TODO: pass on reference
549 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
550 // automatically enable logo display if we're clicked
551 aaa.groupRef.setshowSequenceLogo(true);
553 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
560 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
561 MessageManager.getString("label.show_histogram"),
562 av.isShowConsensusHistogram());
563 chist.addActionListener(new ActionListener()
566 public void actionPerformed(ActionEvent e)
568 // TODO: pass on reference
574 av.setShowConsensusHistogram(chist.getState());
575 ap.alignFrame.setMenusForViewport();
577 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
581 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
582 MessageManager.getString("label.show_logo"),
583 av.isShowSequenceLogo());
584 cprof.addActionListener(new ActionListener()
587 public void actionPerformed(ActionEvent e)
589 // TODO: pass on reference
595 av.setShowSequenceLogo(cprof.getState());
596 ap.alignFrame.setMenusForViewport();
598 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
602 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
603 MessageManager.getString("label.normalise_logo"),
604 av.isNormaliseSequenceLogo());
605 cprofnorm.addActionListener(new ActionListener()
608 public void actionPerformed(ActionEvent e)
610 // TODO: pass on reference
616 av.setShowSequenceLogo(true);
617 av.setNormaliseSequenceLogo(cprofnorm.getState());
618 ap.alignFrame.setMenusForViewport();
620 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
625 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
626 consclipbrd.addActionListener(this);
627 pop.add(consclipbrd);
630 pop.show(this, evt.getX(), evt.getY());
634 * Reorders annotation rows after a drag of a label
639 public void mouseReleased(MouseEvent evt)
641 if (evt.isPopupTrigger())
647 int start = selectedRow;
648 getSelectedRow(evt.getY() - getScrollOffset());
649 int end = selectedRow;
652 * if dragging to resize instead, start == end
656 // Swap these annotations
657 AlignmentAnnotation startAA = ap.av.getAlignment()
658 .getAlignmentAnnotation()[start];
661 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
663 AlignmentAnnotation endAA = ap.av.getAlignment()
664 .getAlignmentAnnotation()[end];
666 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
667 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
673 ap.getAnnotationPanel().repaint();
677 * Removes the height adjuster image on leaving the panel, unless currently
681 public void mouseExited(MouseEvent evt)
683 if (resizePanel && dragEvent == null)
691 * A mouse drag may be either an adjustment of the panel height (if flag
692 * resizePanel is set on), or a reordering of the annotation rows. The former
693 * is dealt with by this method, the latter in mouseReleased.
698 public void mouseDragged(MouseEvent evt)
704 Dimension d = ap.annotationScroller.getPreferredSize();
705 int dif = evt.getY() - oldY;
707 dif /= ap.av.getCharHeight();
708 dif *= ap.av.getCharHeight();
710 if ((d.height - dif) > 20)
712 ap.annotationScroller
713 .setPreferredSize(new Dimension(d.width, d.height - dif));
714 d = ap.annotationSpaceFillerHolder.getPreferredSize();
715 ap.annotationSpaceFillerHolder
716 .setPreferredSize(new Dimension(d.width, d.height - dif));
717 ap.paintAlignment(true, false);
729 * Updates the tooltip as the mouse moves over the labels
734 public void mouseMoved(MouseEvent evt)
736 showOrHideAdjuster(evt);
738 getSelectedRow(evt.getY() - getScrollOffset());
740 if (selectedRow > -1 && ap.av.getAlignment()
741 .getAlignmentAnnotation().length > selectedRow)
743 AlignmentAnnotation aa = ap.av.getAlignment()
744 .getAlignmentAnnotation()[selectedRow];
746 StringBuffer desc = new StringBuffer();
747 if (aa.description != null
748 && !aa.description.equals("New description"))
750 // TODO: we could refactor and merge this code with the code in
751 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
753 desc.append(aa.getDescription(true).trim());
754 // check to see if the description is an html fragment.
755 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
756 .indexOf("<html>") < 0))
758 // clean the description ready for embedding in html
759 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
760 .replaceAll("<"));
761 desc.insert(0, "<html>");
765 // remove terminating html if any
766 int i = desc.substring(desc.length() - 7).toLowerCase()
767 .lastIndexOf("</html>");
770 desc.setLength(desc.length() - 7 + i);
775 desc.append("<br/>");
777 // if (aa.hasProperties())
779 // desc.append("<table>");
780 // for (String prop : aa.getProperties())
782 // desc.append("<tr><td>" + prop + "</td><td>"
783 // + aa.getProperty(prop) + "</td><tr>");
785 // desc.append("</table>");
790 // begin the tooltip's html fragment
791 desc.append("<html>");
794 // TODO: limit precision of score to avoid noise from imprecise
796 // (64.7 becomes 64.7+/some tiny value).
797 desc.append(" Score: " + aa.score);
800 if (desc.length() > 6)
802 desc.append("</html>");
803 this.setToolTipText(desc.toString());
807 this.setToolTipText(null);
813 * Shows the height adjuster image if the mouse moves into the top left
814 * region, or hides it if the mouse leaves the regio
818 protected void showOrHideAdjuster(MouseEvent evt)
820 boolean was = resizePanel;
821 resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
823 if (resizePanel != was)
825 setCursor(Cursor.getPredefinedCursor(
826 resizePanel ? Cursor.S_RESIZE_CURSOR
827 : Cursor.DEFAULT_CURSOR));
833 public void mouseClicked(MouseEvent evt)
835 final AlignmentAnnotation[] aa = ap.av.getAlignment()
836 .getAlignmentAnnotation();
837 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
839 if (selectedRow > -1 && selectedRow < aa.length)
841 if (aa[selectedRow].groupRef != null)
843 if (evt.getClickCount() >= 2)
845 // todo: make the ap scroll to the selection - not necessary, first
846 // click highlights/scrolls, second selects
847 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
849 SequenceGroup sg = ap.av.getSelectionGroup();
850 if (sg == null || sg == aa[selectedRow].groupRef
851 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
853 if (Platform.isControlDown(evt) || evt.isShiftDown())
855 // clone a new selection group from the associated group
856 ap.av.setSelectionGroup(
857 new SequenceGroup(aa[selectedRow].groupRef));
861 // set selection to the associated group so it can be edited
862 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
867 // modify current selection with associated group
868 int remainToAdd = aa[selectedRow].groupRef.getSize();
869 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
871 if (jalview.util.Platform.isControlDown(evt))
873 sg.addOrRemove(sgs, --remainToAdd == 0);
877 // notionally, we should also add intermediate sequences from
878 // last added sequence ?
879 sg.addSequence(sgs, --remainToAdd == 0);
884 ap.paintAlignment(false, false);
885 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
886 ap.av.sendSelection();
890 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
891 aa[selectedRow].groupRef.getSequences(null));
895 else if (aa[selectedRow].sequenceRef != null)
897 if (evt.getClickCount() == 1)
899 ap.getSeqPanel().ap.getIdPanel()
900 .highlightSearchResults(Arrays.asList(new SequenceI[]
901 { aa[selectedRow].sequenceRef }));
903 else if (evt.getClickCount() >= 2)
905 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
906 SequenceGroup sg = ap.av.getSelectionGroup();
909 // we make a copy rather than edit the current selection if no
911 // see Enhancement JAL-1557
912 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
914 sg = new SequenceGroup(sg);
916 sg.addSequence(aa[selectedRow].sequenceRef, false);
920 if (Platform.isControlDown(evt))
922 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
926 // notionally, we should also add intermediate sequences from
927 // last added sequence ?
928 sg.addSequence(aa[selectedRow].sequenceRef, true);
934 sg = new SequenceGroup();
936 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
937 sg.addSequence(aa[selectedRow].sequenceRef, false);
939 ap.av.setSelectionGroup(sg);
940 ap.paintAlignment(false, false);
941 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
942 ap.av.sendSelection();
952 * do a single sequence copy to jalview and the system clipboard
955 * sequence to be copied to clipboard
957 protected void copy_annotseqtoclipboard(SequenceI sq)
959 SequenceI[] seqs = new SequenceI[] { sq };
960 String[] omitHidden = null;
961 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
962 if (dseqs[0] == null)
964 dseqs[0] = new Sequence(sq);
965 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
966 sq.getSequenceAsString()));
968 sq.setDatasetSequence(dseqs[0]);
970 Alignment ds = new Alignment(dseqs);
971 if (av.hasHiddenColumns())
973 omitHidden = av.getAlignment().getHiddenColumns()
974 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
977 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
978 if (av.hasHiddenColumns())
980 alignmentStartEnd = av.getAlignment().getHiddenColumns()
981 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
984 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
985 seqs, omitHidden, alignmentStartEnd);
987 Toolkit.getDefaultToolkit().getSystemClipboard()
988 .setContents(new StringSelection(output), Desktop.instance);
990 ArrayList<int[]> hiddenColumns = null;
992 if (av.hasHiddenColumns())
994 hiddenColumns = av.getAlignment().getHiddenColumns()
995 .getHiddenColumnsCopy();
998 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1000 // sequence ? need to
1002 // sequence as special.
1013 public void paintComponent(Graphics g)
1016 int width = getWidth();
1019 width = ap.calculateIdWidth().width + 4;
1022 Graphics2D g2 = (Graphics2D) g;
1025 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1026 RenderingHints.VALUE_ANTIALIAS_ON);
1029 drawComponent(g2, true, width);
1034 * Draw the full set of annotation Labels for the alignment at the given
1038 * Graphics2D instance (needed for font scaling)
1040 * Width for scaling labels
1043 public void drawComponent(Graphics g, int width)
1045 drawComponent(g, false, width);
1049 * Draw the full set of annotation Labels for the alignment at the given
1053 * Graphics2D instance (needed for font scaling)
1055 * - true indicates that only current visible area needs to be
1058 * Width for scaling labels
1060 public void drawComponent(Graphics g, boolean clip, int width)
1062 if (av.getFont().getSize() < 10)
1068 g.setFont(av.getFont());
1071 FontMetrics fm = g.getFontMetrics(g.getFont());
1072 g.setColor(Color.white);
1073 g.fillRect(0, 0, getWidth(), getHeight());
1075 g.translate(0, getScrollOffset());
1076 g.setColor(Color.black);
1078 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1079 int fontHeight = g.getFont().getSize();
1082 int graphExtras = 0;
1084 Font baseFont = g.getFont();
1085 FontMetrics baseMetrics = fm;
1086 int ofontH = fontHeight;
1089 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1090 ? ap.getAnnotationPanel().getVisibleVRange()
1092 if (clip && visr != null)
1095 visHeight = visr[1];
1097 boolean visible = true, before = false, after = false;
1100 hasHiddenRows = false;
1102 for (int i = 0; i < aa.length; i++)
1107 hasHiddenRows = true;
1120 System.out.println("before vis: " + i);
1124 // don't draw what isn't visible
1127 if (olY > visHeight)
1135 "Scroll offset: " + sOffset + " after vis: " + i);
1139 // don't draw what isn't visible
1143 g.setColor(Color.black);
1145 offset = -aa[i].height / 2;
1149 offset += fm.getHeight() / 2;
1150 offset -= fm.getDescent();
1154 offset += fm.getDescent();
1157 x = width - fm.stringWidth(aa[i].label) - 3;
1159 if (aa[i].graphGroup > -1)
1162 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1163 // computed efficiently for all visible labels
1164 for (int gg = 0; gg < aa.length; gg++)
1166 if (aa[gg].graphGroup == aa[i].graphGroup)
1171 if (groupSize * (fontHeight + 8) < aa[i].height)
1173 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1178 // scale font to fit
1179 float h = aa[i].height / (float) groupSize, s;
1186 fontHeight = -8 + (int) h;
1187 s = ((float) fontHeight) / (float) ofontH;
1189 .deriveFont(AffineTransform.getScaleInstance(s, s));
1191 fm = g.getFontMetrics();
1192 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1198 for (int gg = 0; gg < aa.length; gg++)
1200 if (aa[gg].graphGroup == aa[i].graphGroup)
1202 x = width - fm.stringWidth(aa[gg].label) - 3;
1203 g.drawString(aa[gg].label, x, y - graphExtras);
1205 if (aa[gg]._linecolour != null)
1208 g.setColor(aa[gg]._linecolour);
1209 g.drawLine(x, y - graphExtras + 3,
1210 x + fm.stringWidth(aa[gg].label),
1211 y - graphExtras + 3);
1214 g.setColor(Color.black);
1215 graphExtras += fontHeight + 8;
1219 g.setFont(baseFont);
1221 fontHeight = ofontH;
1225 g.drawString(aa[i].label, x, y + offset);
1230 if (!resizePanel && dragEvent != null && aa != null)
1232 g.setColor(Color.lightGray);
1233 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1234 dragEvent.getY() - getScrollOffset());
1237 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1239 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1240 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1245 public int getScrollOffset()
1247 return scrollOffset;
1251 public void mouseEntered(MouseEvent e)