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.Dimension;
40 import java.awt.FontMetrics;
41 import java.awt.Graphics;
42 import java.awt.Graphics2D;
43 import java.awt.Image;
44 import java.awt.MediaTracker;
45 import java.awt.RenderingHints;
46 import java.awt.Toolkit;
47 import java.awt.datatransfer.StringSelection;
48 import java.awt.event.ActionEvent;
49 import java.awt.event.ActionListener;
50 import java.awt.event.MouseEvent;
51 import java.awt.event.MouseListener;
52 import java.awt.event.MouseMotionListener;
53 import java.awt.geom.AffineTransform;
54 import java.awt.image.BufferedImage;
55 import java.util.ArrayList;
56 import java.util.Arrays;
57 import java.util.Collections;
58 import java.util.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
75 // width in pixels within which height adjuster arrows are shown and active
76 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
78 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
81 private static final Font font = new Font("Arial", Font.PLAIN, 11);
83 private static final String TOGGLE_LABELSCALE = MessageManager
84 .getString("label.scale_label_to_column");
86 private static final String ADDNEW = MessageManager
87 .getString("label.add_new_row");
89 private static final String EDITNAME = MessageManager
90 .getString("label.edit_label_description");
92 private static final String HIDE = MessageManager
93 .getString("label.hide_row");
95 private static final String DELETE = MessageManager
96 .getString("label.delete_row");
98 private static final String SHOWALL = MessageManager
99 .getString("label.show_all_hidden_rows");
101 private static final String OUTPUT_TEXT = MessageManager
102 .getString("label.export_annotation");
104 private static final String COPYCONS_SEQ = MessageManager
105 .getString("label.copy_consensus_sequence");
107 private static Image adjusterImage;
109 private static int adjusterImageHeight;
111 private final boolean debugRedraw = false;
113 private AlignmentPanel ap;
117 private MouseEvent dragEvent;
121 private int selectedRow;
123 private int scrollOffset = 0;
125 private boolean hasHiddenRows;
127 private boolean resizePanel = false;
130 * Creates a new AnnotationLabels object
134 public AnnotationLabels(AlignmentPanel ap)
138 ToolTipManager.sharedInstance().registerComponent(this);
140 if (adjusterImage == null)
145 addMouseListener(this);
146 addMouseMotionListener(this);
147 addMouseWheelListener(ap.getAnnotationPanel());
150 public AnnotationLabels(AlignViewport av)
156 * Loads the gif for the panel height adjustment
158 protected void loadAdjusterImage()
160 java.net.URL url = getClass().getResource("/images/idwidth.gif");
165 temp = Toolkit.getDefaultToolkit().createImage(url);
170 MediaTracker mt = new MediaTracker(this);
171 mt.addImage(temp, 0);
173 } catch (Exception ex)
177 BufferedImage bi = new BufferedImage(temp.getHeight(this),
178 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
179 Graphics2D g = (Graphics2D) bi.getGraphics();
180 g.rotate(Math.toRadians(90));
181 g.drawImage(temp, 0, -bi.getWidth(this), this);
183 adjusterImageHeight = bi.getHeight();
192 public void setScrollOffset(int y)
199 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
203 * coordinate position to search for a row
205 void getSelectedRow(int y)
208 AlignmentAnnotation[] aa = ap.av.getAlignment()
209 .getAlignmentAnnotation();
213 for (int i = 0; i < aa.length; i++)
221 height += aa[i].height;
240 public void actionPerformed(ActionEvent evt)
242 AlignmentAnnotation[] aa = ap.av.getAlignment()
243 .getAlignmentAnnotation();
245 boolean fullRepaint = false;
246 if (evt.getActionCommand().equals(ADDNEW))
248 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
249 null, new Annotation[ap.av.getAlignment().getWidth()]);
251 if (!editLabelDescription(newAnnotation))
256 ap.av.getAlignment().addAnnotation(newAnnotation);
257 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
260 else if (evt.getActionCommand().equals(EDITNAME))
262 String name = aa[selectedRow].label;
263 editLabelDescription(aa[selectedRow]);
264 if (!name.equalsIgnoreCase(aa[selectedRow].label))
269 else if (evt.getActionCommand().equals(HIDE))
271 aa[selectedRow].visible = false;
273 else if (evt.getActionCommand().equals(DELETE))
275 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
276 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
279 else if (evt.getActionCommand().equals(SHOWALL))
281 for (int i = 0; i < aa.length; i++)
283 if (!aa[i].visible && aa[i].annotations != null)
285 aa[i].visible = true;
290 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
292 new AnnotationExporter().exportAnnotations(ap,
293 new AlignmentAnnotation[]
294 { aa[selectedRow] });
296 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
298 SequenceI cons = null;
299 if (aa[selectedRow].groupRef != null)
301 cons = aa[selectedRow].groupRef.getConsensusSeq();
305 cons = av.getConsensusSeq();
309 copy_annotseqtoclipboard(cons);
313 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
315 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
318 ap.refresh(fullRepaint);
328 boolean editLabelDescription(AlignmentAnnotation annotation)
331 EditNameDialog dialog = new EditNameDialog(annotation.label,
332 annotation.description, " Annotation Name ",
333 "Annotation Description ", "Edit Annotation Name/Description",
341 annotation.label = dialog.getName();
343 String text = dialog.getDescription();
344 if (text != null && text.length() == 0)
348 annotation.description = text;
354 public void mousePressed(MouseEvent evt)
356 getSelectedRow(evt.getY() - getScrollOffset());
358 if (evt.isPopupTrigger())
365 * Build and show the Pop-up menu at the right-click mouse position
369 void showPopupMenu(MouseEvent evt)
372 final AlignmentAnnotation[] aa = ap.av.getAlignment()
373 .getAlignmentAnnotation();
375 JPopupMenu pop = new JPopupMenu(
376 MessageManager.getString("label.annotations"));
377 JMenuItem item = new JMenuItem(ADDNEW);
378 item.addActionListener(this);
383 { // let the user make everything visible again
384 item = new JMenuItem(SHOWALL);
385 item.addActionListener(this);
388 pop.show(this, evt.getX(), evt.getY());
391 item = new JMenuItem(EDITNAME);
392 item.addActionListener(this);
394 item = new JMenuItem(HIDE);
395 item.addActionListener(this);
397 // JAL-1264 hide all sequence-specific annotations of this type
398 if (selectedRow < aa.length)
400 if (aa[selectedRow].sequenceRef != null)
402 final String label = aa[selectedRow].label;
403 JMenuItem hideType = new JMenuItem();
404 String text = MessageManager.getString("label.hide_all") + " "
406 hideType.setText(text);
407 hideType.addActionListener(new ActionListener()
410 public void actionPerformed(ActionEvent e)
412 AlignmentUtils.showOrHideSequenceAnnotations(
413 ap.av.getAlignment(), Collections.singleton(label),
415 // for (AlignmentAnnotation ann : ap.av.getAlignment()
416 // .getAlignmentAnnotation())
418 // if (ann.sequenceRef != null && ann.label != null
419 // && ann.label.equals(label))
421 // ann.visible = false;
430 item = new JMenuItem(DELETE);
431 item.addActionListener(this);
435 item = new JMenuItem(SHOWALL);
436 item.addActionListener(this);
439 item = new JMenuItem(OUTPUT_TEXT);
440 item.addActionListener(this);
442 // TODO: annotation object should be typed for autocalculated/derived
444 if (selectedRow < aa.length)
446 final String label = aa[selectedRow].label;
447 if (!aa[selectedRow].autoCalculated)
449 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
451 // display formatting settings for this row.
453 // av and sequencegroup need to implement same interface for
454 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
455 aa[selectedRow].scaleColLabel);
456 item.addActionListener(this);
460 else if (label.indexOf("Consensus") > -1)
463 // av and sequencegroup need to implement same interface for
464 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
465 MessageManager.getString("label.ignore_gaps_consensus"),
466 (aa[selectedRow].groupRef != null)
467 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
468 : ap.av.isIgnoreGapsConsensus());
469 final AlignmentAnnotation aaa = aa[selectedRow];
470 cbmi.addActionListener(new ActionListener()
473 public void actionPerformed(ActionEvent e)
475 if (aaa.groupRef != null)
477 // TODO: pass on reference to ap so the view can be updated.
478 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
479 ap.getAnnotationPanel()
480 .paint(ap.getAnnotationPanel().getGraphics());
484 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
486 ap.alignmentChanged();
490 // av and sequencegroup need to implement same interface for
491 if (aaa.groupRef != null)
493 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
494 MessageManager.getString("label.show_group_histogram"),
495 aa[selectedRow].groupRef.isShowConsensusHistogram());
496 chist.addActionListener(new ActionListener()
499 public void actionPerformed(ActionEvent e)
501 // TODO: pass on reference
507 aaa.groupRef.setShowConsensusHistogram(chist.getState());
509 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
513 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
514 MessageManager.getString("label.show_group_logo"),
515 aa[selectedRow].groupRef.isShowSequenceLogo());
516 cprofl.addActionListener(new ActionListener()
519 public void actionPerformed(ActionEvent e)
521 // TODO: pass on reference
527 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
529 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
533 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
534 MessageManager.getString("label.normalise_group_logo"),
535 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
536 cproflnorm.addActionListener(new ActionListener()
539 public void actionPerformed(ActionEvent e)
542 // TODO: pass on reference
548 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
549 // automatically enable logo display if we're clicked
550 aaa.groupRef.setshowSequenceLogo(true);
552 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
559 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
560 MessageManager.getString("label.show_histogram"),
561 av.isShowConsensusHistogram());
562 chist.addActionListener(new ActionListener()
565 public void actionPerformed(ActionEvent e)
567 // TODO: pass on reference
573 av.setShowConsensusHistogram(chist.getState());
574 ap.alignFrame.setMenusForViewport();
576 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
580 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
581 MessageManager.getString("label.show_logo"),
582 av.isShowSequenceLogo());
583 cprof.addActionListener(new ActionListener()
586 public void actionPerformed(ActionEvent e)
588 // TODO: pass on reference
594 av.setShowSequenceLogo(cprof.getState());
595 ap.alignFrame.setMenusForViewport();
597 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
601 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
602 MessageManager.getString("label.normalise_logo"),
603 av.isNormaliseSequenceLogo());
604 cprofnorm.addActionListener(new ActionListener()
607 public void actionPerformed(ActionEvent e)
609 // TODO: pass on reference
615 av.setShowSequenceLogo(true);
616 av.setNormaliseSequenceLogo(cprofnorm.getState());
617 ap.alignFrame.setMenusForViewport();
619 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
624 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
625 consclipbrd.addActionListener(this);
626 pop.add(consclipbrd);
629 pop.show(this, evt.getX(), evt.getY());
633 * Reorders annotation rows after a drag of a label
638 public void mouseReleased(MouseEvent evt)
640 if (evt.isPopupTrigger())
646 int start = selectedRow;
647 getSelectedRow(evt.getY() - getScrollOffset());
648 int end = selectedRow;
651 * if dragging to resize instead, start == end
655 // Swap these annotations
656 AlignmentAnnotation startAA = ap.av.getAlignment()
657 .getAlignmentAnnotation()[start];
660 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
662 AlignmentAnnotation endAA = ap.av.getAlignment()
663 .getAlignmentAnnotation()[end];
665 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
666 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
672 ap.getAnnotationPanel().repaint();
676 * Removes the height adjuster image on leaving the panel, unless currently
680 public void mouseExited(MouseEvent evt)
682 if (resizePanel && dragEvent == null)
690 * A mouse drag may be either an adjustment of the panel height (if flag
691 * resizePanel is set on), or a reordering of the annotation rows. The former
692 * is dealt with by this method, the latter in mouseReleased.
697 public void mouseDragged(MouseEvent evt)
703 Dimension d = ap.annotationScroller.getPreferredSize();
704 int dif = evt.getY() - oldY;
706 dif /= ap.av.getCharHeight();
707 dif *= ap.av.getCharHeight();
709 if ((d.height - dif) > 20)
711 ap.annotationScroller
712 .setPreferredSize(new Dimension(d.width, d.height - dif));
713 d = ap.annotationSpaceFillerHolder.getPreferredSize();
714 ap.annotationSpaceFillerHolder
715 .setPreferredSize(new Dimension(d.width, d.height - dif));
716 ap.paintAlignment(true, false);
728 * Updates the tooltip as the mouse moves over the labels
733 public void mouseMoved(MouseEvent evt)
735 showOrHideAdjuster(evt);
737 getSelectedRow(evt.getY() - getScrollOffset());
739 if (selectedRow > -1 && ap.av.getAlignment()
740 .getAlignmentAnnotation().length > selectedRow)
742 AlignmentAnnotation aa = ap.av.getAlignment()
743 .getAlignmentAnnotation()[selectedRow];
745 StringBuffer desc = new StringBuffer();
746 if (aa.description != null
747 && !aa.description.equals("New description"))
749 // TODO: we could refactor and merge this code with the code in
750 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
752 desc.append(aa.getDescription(true).trim());
753 // check to see if the description is an html fragment.
754 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
755 .indexOf("<html>") < 0))
757 // clean the description ready for embedding in html
758 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
759 .replaceAll("<"));
760 desc.insert(0, "<html>");
764 // remove terminating html if any
765 int i = desc.substring(desc.length() - 7).toLowerCase()
766 .lastIndexOf("</html>");
769 desc.setLength(desc.length() - 7 + i);
774 desc.append("<br/>");
776 // if (aa.hasProperties())
778 // desc.append("<table>");
779 // for (String prop : aa.getProperties())
781 // desc.append("<tr><td>" + prop + "</td><td>"
782 // + aa.getProperty(prop) + "</td><tr>");
784 // desc.append("</table>");
789 // begin the tooltip's html fragment
790 desc.append("<html>");
793 // TODO: limit precision of score to avoid noise from imprecise
795 // (64.7 becomes 64.7+/some tiny value).
796 desc.append(" Score: " + aa.score);
799 if (desc.length() > 6)
801 desc.append("</html>");
802 this.setToolTipText(desc.toString());
806 this.setToolTipText(null);
812 * Shows the height adjuster image if the mouse moves into the top left
813 * region, or hides it if the mouse leaves the regio
817 protected void showOrHideAdjuster(MouseEvent evt)
819 boolean was = resizePanel;
820 resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
821 if (resizePanel != was)
828 public void mouseClicked(MouseEvent evt)
830 final AlignmentAnnotation[] aa = ap.av.getAlignment()
831 .getAlignmentAnnotation();
832 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
834 if (selectedRow > -1 && selectedRow < aa.length)
836 if (aa[selectedRow].groupRef != null)
838 if (evt.getClickCount() >= 2)
840 // todo: make the ap scroll to the selection - not necessary, first
841 // click highlights/scrolls, second selects
842 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
844 SequenceGroup sg = ap.av.getSelectionGroup();
845 if (sg == null || sg == aa[selectedRow].groupRef
846 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
848 if (Platform.isControlDown(evt) || evt.isShiftDown())
850 // clone a new selection group from the associated group
851 ap.av.setSelectionGroup(
852 new SequenceGroup(aa[selectedRow].groupRef));
856 // set selection to the associated group so it can be edited
857 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
862 // modify current selection with associated group
863 int remainToAdd = aa[selectedRow].groupRef.getSize();
864 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
866 if (jalview.util.Platform.isControlDown(evt))
868 sg.addOrRemove(sgs, --remainToAdd == 0);
872 // notionally, we should also add intermediate sequences from
873 // last added sequence ?
874 sg.addSequence(sgs, --remainToAdd == 0);
879 ap.paintAlignment(false, false);
880 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
881 ap.av.sendSelection();
885 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
886 aa[selectedRow].groupRef.getSequences(null));
890 else if (aa[selectedRow].sequenceRef != null)
892 if (evt.getClickCount() == 1)
894 ap.getSeqPanel().ap.getIdPanel()
895 .highlightSearchResults(Arrays.asList(new SequenceI[]
896 { aa[selectedRow].sequenceRef }));
898 else if (evt.getClickCount() >= 2)
900 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
901 SequenceGroup sg = ap.av.getSelectionGroup();
904 // we make a copy rather than edit the current selection if no
906 // see Enhancement JAL-1557
907 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
909 sg = new SequenceGroup(sg);
911 sg.addSequence(aa[selectedRow].sequenceRef, false);
915 if (Platform.isControlDown(evt))
917 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
921 // notionally, we should also add intermediate sequences from
922 // last added sequence ?
923 sg.addSequence(aa[selectedRow].sequenceRef, true);
929 sg = new SequenceGroup();
931 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
932 sg.addSequence(aa[selectedRow].sequenceRef, false);
934 ap.av.setSelectionGroup(sg);
935 ap.paintAlignment(false, false);
936 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
937 ap.av.sendSelection();
947 * do a single sequence copy to jalview and the system clipboard
950 * sequence to be copied to clipboard
952 protected void copy_annotseqtoclipboard(SequenceI sq)
954 SequenceI[] seqs = new SequenceI[] { sq };
955 String[] omitHidden = null;
956 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
957 if (dseqs[0] == null)
959 dseqs[0] = new Sequence(sq);
960 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
961 sq.getSequenceAsString()));
963 sq.setDatasetSequence(dseqs[0]);
965 Alignment ds = new Alignment(dseqs);
966 if (av.hasHiddenColumns())
968 omitHidden = av.getAlignment().getHiddenColumns()
969 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
972 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
973 if (av.hasHiddenColumns())
975 alignmentStartEnd = av.getAlignment().getHiddenColumns()
976 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
979 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
980 seqs, omitHidden, alignmentStartEnd);
982 Toolkit.getDefaultToolkit().getSystemClipboard()
983 .setContents(new StringSelection(output), Desktop.instance);
985 ArrayList<int[]> hiddenColumns = null;
987 if (av.hasHiddenColumns())
989 hiddenColumns = av.getAlignment().getHiddenColumns()
990 .getHiddenColumnsCopy();
993 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
995 // sequence ? need to
997 // sequence as special.
1008 public void paintComponent(Graphics g)
1011 int width = getWidth();
1014 width = ap.calculateIdWidth().width + 4;
1017 Graphics2D g2 = (Graphics2D) g;
1020 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1021 RenderingHints.VALUE_ANTIALIAS_ON);
1024 drawComponent(g2, true, width);
1029 * Draw the full set of annotation Labels for the alignment at the given
1033 * Graphics2D instance (needed for font scaling)
1035 * Width for scaling labels
1038 public void drawComponent(Graphics g, int width)
1040 drawComponent(g, false, width);
1044 * Draw the full set of annotation Labels for the alignment at the given
1048 * Graphics2D instance (needed for font scaling)
1050 * - true indicates that only current visible area needs to be
1053 * Width for scaling labels
1055 public void drawComponent(Graphics g, boolean clip, int width)
1057 if (av.getFont().getSize() < 10)
1063 g.setFont(av.getFont());
1066 FontMetrics fm = g.getFontMetrics(g.getFont());
1067 g.setColor(Color.white);
1068 g.fillRect(0, 0, getWidth(), getHeight());
1070 g.translate(0, getScrollOffset());
1071 g.setColor(Color.black);
1073 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1074 int fontHeight = g.getFont().getSize();
1077 int graphExtras = 0;
1079 Font baseFont = g.getFont();
1080 FontMetrics baseMetrics = fm;
1081 int ofontH = fontHeight;
1084 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1085 ? ap.getAnnotationPanel().getVisibleVRange()
1087 if (clip && visr != null)
1090 visHeight = visr[1];
1092 boolean visible = true, before = false, after = false;
1095 hasHiddenRows = false;
1097 for (int i = 0; i < aa.length; i++)
1102 hasHiddenRows = true;
1115 System.out.println("before vis: " + i);
1119 // don't draw what isn't visible
1122 if (olY > visHeight)
1130 "Scroll offset: " + sOffset + " after vis: " + i);
1134 // don't draw what isn't visible
1138 g.setColor(Color.black);
1140 offset = -aa[i].height / 2;
1144 offset += fm.getHeight() / 2;
1145 offset -= fm.getDescent();
1149 offset += fm.getDescent();
1152 x = width - fm.stringWidth(aa[i].label) - 3;
1154 if (aa[i].graphGroup > -1)
1157 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1158 // computed efficiently for all visible labels
1159 for (int gg = 0; gg < aa.length; gg++)
1161 if (aa[gg].graphGroup == aa[i].graphGroup)
1166 if (groupSize * (fontHeight + 8) < aa[i].height)
1168 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1173 // scale font to fit
1174 float h = aa[i].height / (float) groupSize, s;
1181 fontHeight = -8 + (int) h;
1182 s = ((float) fontHeight) / (float) ofontH;
1184 .deriveFont(AffineTransform.getScaleInstance(s, s));
1186 fm = g.getFontMetrics();
1187 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1193 for (int gg = 0; gg < aa.length; gg++)
1195 if (aa[gg].graphGroup == aa[i].graphGroup)
1197 x = width - fm.stringWidth(aa[gg].label) - 3;
1198 g.drawString(aa[gg].label, x, y - graphExtras);
1200 if (aa[gg]._linecolour != null)
1203 g.setColor(aa[gg]._linecolour);
1204 g.drawLine(x, y - graphExtras + 3,
1205 x + fm.stringWidth(aa[gg].label),
1206 y - graphExtras + 3);
1209 g.setColor(Color.black);
1210 graphExtras += fontHeight + 8;
1214 g.setFont(baseFont);
1216 fontHeight = ofontH;
1220 g.drawString(aa[i].label, x, y + offset);
1227 g.drawImage(adjusterImage, 2, 0 - getScrollOffset(), this);
1229 else if (dragEvent != null && aa != null)
1231 g.setColor(Color.lightGray);
1232 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1233 dragEvent.getY() - getScrollOffset());
1236 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1238 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1239 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1244 public int getScrollOffset()
1246 return scrollOffset;
1250 public void mouseEntered(MouseEvent e)