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(ap).exportAnnotation(aa[selectedRow]);
295 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
297 SequenceI cons = null;
298 if (aa[selectedRow].groupRef != null)
300 cons = aa[selectedRow].groupRef.getConsensusSeq();
304 cons = av.getConsensusSeq();
308 copy_annotseqtoclipboard(cons);
312 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
314 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
317 ap.refresh(fullRepaint);
327 boolean editLabelDescription(AlignmentAnnotation annotation)
330 EditNameDialog dialog = new EditNameDialog(annotation.label,
331 annotation.description, " Annotation Name ",
332 "Annotation Description ", "Edit Annotation Name/Description",
340 annotation.label = dialog.getName();
342 String text = dialog.getDescription();
343 if (text != null && text.length() == 0)
347 annotation.description = text;
353 public void mousePressed(MouseEvent evt)
355 getSelectedRow(evt.getY() - getScrollOffset());
357 if (evt.isPopupTrigger())
364 * Build and show the Pop-up menu at the right-click mouse position
368 void showPopupMenu(MouseEvent evt)
371 final AlignmentAnnotation[] aa = ap.av.getAlignment()
372 .getAlignmentAnnotation();
374 JPopupMenu pop = new JPopupMenu(
375 MessageManager.getString("label.annotations"));
376 JMenuItem item = new JMenuItem(ADDNEW);
377 item.addActionListener(this);
382 { // let the user make everything visible again
383 item = new JMenuItem(SHOWALL);
384 item.addActionListener(this);
387 pop.show(this, evt.getX(), evt.getY());
390 item = new JMenuItem(EDITNAME);
391 item.addActionListener(this);
393 item = new JMenuItem(HIDE);
394 item.addActionListener(this);
396 // JAL-1264 hide all sequence-specific annotations of this type
397 if (selectedRow < aa.length)
399 if (aa[selectedRow].sequenceRef != null)
401 final String label = aa[selectedRow].label;
402 JMenuItem hideType = new JMenuItem();
403 String text = MessageManager.getString("label.hide_all") + " "
405 hideType.setText(text);
406 hideType.addActionListener(new ActionListener()
409 public void actionPerformed(ActionEvent e)
411 AlignmentUtils.showOrHideSequenceAnnotations(
412 ap.av.getAlignment(), Collections.singleton(label),
414 // for (AlignmentAnnotation ann : ap.av.getAlignment()
415 // .getAlignmentAnnotation())
417 // if (ann.sequenceRef != null && ann.label != null
418 // && ann.label.equals(label))
420 // ann.visible = false;
429 item = new JMenuItem(DELETE);
430 item.addActionListener(this);
434 item = new JMenuItem(SHOWALL);
435 item.addActionListener(this);
438 item = new JMenuItem(OUTPUT_TEXT);
439 item.addActionListener(this);
441 // TODO: annotation object should be typed for autocalculated/derived
443 if (selectedRow < aa.length)
445 final String label = aa[selectedRow].label;
446 if (!aa[selectedRow].autoCalculated)
448 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
450 // display formatting settings for this row.
452 // av and sequencegroup need to implement same interface for
453 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
454 aa[selectedRow].scaleColLabel);
455 item.addActionListener(this);
459 else if (label.indexOf("Consensus") > -1)
462 // av and sequencegroup need to implement same interface for
463 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
464 MessageManager.getString("label.ignore_gaps_consensus"),
465 (aa[selectedRow].groupRef != null)
466 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
467 : ap.av.isIgnoreGapsConsensus());
468 final AlignmentAnnotation aaa = aa[selectedRow];
469 cbmi.addActionListener(new ActionListener()
472 public void actionPerformed(ActionEvent e)
474 if (aaa.groupRef != null)
476 // TODO: pass on reference to ap so the view can be updated.
477 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
478 ap.getAnnotationPanel()
479 .paint(ap.getAnnotationPanel().getGraphics());
483 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
485 ap.alignmentChanged();
489 // av and sequencegroup need to implement same interface for
490 if (aaa.groupRef != null)
492 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
493 MessageManager.getString("label.show_group_histogram"),
494 aa[selectedRow].groupRef.isShowConsensusHistogram());
495 chist.addActionListener(new ActionListener()
498 public void actionPerformed(ActionEvent e)
500 // TODO: pass on reference
506 aaa.groupRef.setShowConsensusHistogram(chist.getState());
508 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
512 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
513 MessageManager.getString("label.show_group_logo"),
514 aa[selectedRow].groupRef.isShowSequenceLogo());
515 cprofl.addActionListener(new ActionListener()
518 public void actionPerformed(ActionEvent e)
520 // TODO: pass on reference
526 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
528 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
532 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
533 MessageManager.getString("label.normalise_group_logo"),
534 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
535 cproflnorm.addActionListener(new ActionListener()
538 public void actionPerformed(ActionEvent e)
541 // TODO: pass on reference
547 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
548 // automatically enable logo display if we're clicked
549 aaa.groupRef.setshowSequenceLogo(true);
551 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
558 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
559 MessageManager.getString("label.show_histogram"),
560 av.isShowConsensusHistogram());
561 chist.addActionListener(new ActionListener()
564 public void actionPerformed(ActionEvent e)
566 // TODO: pass on reference
572 av.setShowConsensusHistogram(chist.getState());
573 ap.alignFrame.setMenusForViewport();
575 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
579 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
580 MessageManager.getString("label.show_logo"),
581 av.isShowSequenceLogo());
582 cprof.addActionListener(new ActionListener()
585 public void actionPerformed(ActionEvent e)
587 // TODO: pass on reference
593 av.setShowSequenceLogo(cprof.getState());
594 ap.alignFrame.setMenusForViewport();
596 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
600 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
601 MessageManager.getString("label.normalise_logo"),
602 av.isNormaliseSequenceLogo());
603 cprofnorm.addActionListener(new ActionListener()
606 public void actionPerformed(ActionEvent e)
608 // TODO: pass on reference
614 av.setShowSequenceLogo(true);
615 av.setNormaliseSequenceLogo(cprofnorm.getState());
616 ap.alignFrame.setMenusForViewport();
618 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
623 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
624 consclipbrd.addActionListener(this);
625 pop.add(consclipbrd);
628 pop.show(this, evt.getX(), evt.getY());
632 * Reorders annotation rows after a drag of a label
637 public void mouseReleased(MouseEvent evt)
639 if (evt.isPopupTrigger())
645 int start = selectedRow;
646 getSelectedRow(evt.getY() - getScrollOffset());
647 int end = selectedRow;
650 * if dragging to resize instead, start == end
654 // Swap these annotations
655 AlignmentAnnotation startAA = ap.av.getAlignment()
656 .getAlignmentAnnotation()[start];
659 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
661 AlignmentAnnotation endAA = ap.av.getAlignment()
662 .getAlignmentAnnotation()[end];
664 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
665 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
671 ap.getAnnotationPanel().repaint();
675 * Removes the height adjuster image on leaving the panel, unless currently
679 public void mouseExited(MouseEvent evt)
681 if (resizePanel && dragEvent == null)
689 * A mouse drag may be either an adjustment of the panel height (if flag
690 * resizePanel is set on), or a reordering of the annotation rows. The former
691 * is dealt with by this method, the latter in mouseReleased.
696 public void mouseDragged(MouseEvent evt)
702 Dimension d = ap.annotationScroller.getPreferredSize();
703 int dif = evt.getY() - oldY;
705 dif /= ap.av.getCharHeight();
706 dif *= ap.av.getCharHeight();
708 if ((d.height - dif) > 20)
710 ap.annotationScroller
711 .setPreferredSize(new Dimension(d.width, d.height - dif));
712 d = ap.annotationSpaceFillerHolder.getPreferredSize();
713 ap.annotationSpaceFillerHolder
714 .setPreferredSize(new Dimension(d.width, d.height - dif));
715 ap.paintAlignment(true, false);
727 * Updates the tooltip as the mouse moves over the labels
732 public void mouseMoved(MouseEvent evt)
734 showOrHideAdjuster(evt);
736 getSelectedRow(evt.getY() - getScrollOffset());
738 if (selectedRow > -1 && ap.av.getAlignment()
739 .getAlignmentAnnotation().length > selectedRow)
741 AlignmentAnnotation aa = ap.av.getAlignment()
742 .getAlignmentAnnotation()[selectedRow];
744 StringBuffer desc = new StringBuffer();
745 if (aa.description != null
746 && !aa.description.equals("New description"))
748 // TODO: we could refactor and merge this code with the code in
749 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
751 desc.append(aa.getDescription(true).trim());
752 // check to see if the description is an html fragment.
753 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
754 .indexOf("<html>") < 0))
756 // clean the description ready for embedding in html
757 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
758 .replaceAll("<"));
759 desc.insert(0, "<html>");
763 // remove terminating html if any
764 int i = desc.substring(desc.length() - 7).toLowerCase()
765 .lastIndexOf("</html>");
768 desc.setLength(desc.length() - 7 + i);
773 desc.append("<br/>");
775 // if (aa.hasProperties())
777 // desc.append("<table>");
778 // for (String prop : aa.getProperties())
780 // desc.append("<tr><td>" + prop + "</td><td>"
781 // + aa.getProperty(prop) + "</td><tr>");
783 // desc.append("</table>");
788 // begin the tooltip's html fragment
789 desc.append("<html>");
792 // TODO: limit precision of score to avoid noise from imprecise
794 // (64.7 becomes 64.7+/some tiny value).
795 desc.append(" Score: " + aa.score);
798 if (desc.length() > 6)
800 desc.append("</html>");
801 this.setToolTipText(desc.toString());
805 this.setToolTipText(null);
811 * Shows the height adjuster image if the mouse moves into the top left
812 * region, or hides it if the mouse leaves the regio
816 protected void showOrHideAdjuster(MouseEvent evt)
818 boolean was = resizePanel;
819 resizePanel = evt.getY() < adjusterImageHeight && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
821 if (resizePanel != was)
823 setCursor(Cursor.getPredefinedCursor(
824 resizePanel ? Cursor.S_RESIZE_CURSOR
825 : Cursor.DEFAULT_CURSOR));
831 public void mouseClicked(MouseEvent evt)
833 final AlignmentAnnotation[] aa = ap.av.getAlignment()
834 .getAlignmentAnnotation();
835 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
837 if (selectedRow > -1 && selectedRow < aa.length)
839 if (aa[selectedRow].groupRef != null)
841 if (evt.getClickCount() >= 2)
843 // todo: make the ap scroll to the selection - not necessary, first
844 // click highlights/scrolls, second selects
845 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
847 SequenceGroup sg = ap.av.getSelectionGroup();
848 if (sg == null || sg == aa[selectedRow].groupRef
849 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
851 if (Platform.isControlDown(evt) || evt.isShiftDown())
853 // clone a new selection group from the associated group
854 ap.av.setSelectionGroup(
855 new SequenceGroup(aa[selectedRow].groupRef));
859 // set selection to the associated group so it can be edited
860 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
865 // modify current selection with associated group
866 int remainToAdd = aa[selectedRow].groupRef.getSize();
867 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
869 if (jalview.util.Platform.isControlDown(evt))
871 sg.addOrRemove(sgs, --remainToAdd == 0);
875 // notionally, we should also add intermediate sequences from
876 // last added sequence ?
877 sg.addSequence(sgs, --remainToAdd == 0);
882 ap.paintAlignment(false, false);
883 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
884 ap.av.sendSelection();
888 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
889 aa[selectedRow].groupRef.getSequences(null));
893 else if (aa[selectedRow].sequenceRef != null)
895 if (evt.getClickCount() == 1)
897 ap.getSeqPanel().ap.getIdPanel()
898 .highlightSearchResults(Arrays.asList(new SequenceI[]
899 { aa[selectedRow].sequenceRef }));
901 else if (evt.getClickCount() >= 2)
903 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
904 SequenceGroup sg = ap.av.getSelectionGroup();
907 // we make a copy rather than edit the current selection if no
909 // see Enhancement JAL-1557
910 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
912 sg = new SequenceGroup(sg);
914 sg.addSequence(aa[selectedRow].sequenceRef, false);
918 if (Platform.isControlDown(evt))
920 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
924 // notionally, we should also add intermediate sequences from
925 // last added sequence ?
926 sg.addSequence(aa[selectedRow].sequenceRef, true);
932 sg = new SequenceGroup();
934 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
935 sg.addSequence(aa[selectedRow].sequenceRef, false);
937 ap.av.setSelectionGroup(sg);
938 ap.paintAlignment(false, false);
939 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
940 ap.av.sendSelection();
950 * do a single sequence copy to jalview and the system clipboard
953 * sequence to be copied to clipboard
955 protected void copy_annotseqtoclipboard(SequenceI sq)
957 SequenceI[] seqs = new SequenceI[] { sq };
958 String[] omitHidden = null;
959 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
960 if (dseqs[0] == null)
962 dseqs[0] = new Sequence(sq);
963 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
964 sq.getSequenceAsString()));
966 sq.setDatasetSequence(dseqs[0]);
968 Alignment ds = new Alignment(dseqs);
969 if (av.hasHiddenColumns())
971 omitHidden = av.getAlignment().getHiddenColumns()
972 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
975 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
976 if (av.hasHiddenColumns())
978 alignmentStartEnd = av.getAlignment().getHiddenColumns()
979 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
982 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
983 seqs, omitHidden, alignmentStartEnd);
985 Toolkit.getDefaultToolkit().getSystemClipboard()
986 .setContents(new StringSelection(output), Desktop.instance);
988 ArrayList<int[]> hiddenColumns = null;
990 if (av.hasHiddenColumns())
992 hiddenColumns = av.getAlignment().getHiddenColumns()
993 .getHiddenColumnsCopy();
996 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
998 // sequence ? need to
1000 // sequence as special.
1011 public void paintComponent(Graphics g)
1014 int width = getWidth();
1017 width = ap.calculateIdWidth().width + 4;
1020 Graphics2D g2 = (Graphics2D) g;
1023 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1024 RenderingHints.VALUE_ANTIALIAS_ON);
1027 drawComponent(g2, true, width);
1032 * Draw the full set of annotation Labels for the alignment at the given
1036 * Graphics2D instance (needed for font scaling)
1038 * Width for scaling labels
1041 public void drawComponent(Graphics g, int width)
1043 drawComponent(g, false, width);
1047 * Draw the full set of annotation Labels for the alignment at the given
1051 * Graphics2D instance (needed for font scaling)
1053 * - true indicates that only current visible area needs to be
1056 * Width for scaling labels
1058 public void drawComponent(Graphics g, boolean clip, int width)
1060 if (av.getFont().getSize() < 10)
1066 g.setFont(av.getFont());
1069 FontMetrics fm = g.getFontMetrics(g.getFont());
1070 g.setColor(Color.white);
1071 g.fillRect(0, 0, getWidth(), getHeight());
1073 g.translate(0, getScrollOffset());
1074 g.setColor(Color.black);
1076 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1077 int fontHeight = g.getFont().getSize();
1080 int graphExtras = 0;
1082 Font baseFont = g.getFont();
1083 FontMetrics baseMetrics = fm;
1084 int ofontH = fontHeight;
1087 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1088 ? ap.getAnnotationPanel().getVisibleVRange()
1090 if (clip && visr != null)
1093 visHeight = visr[1];
1095 boolean visible = true, before = false, after = false;
1098 hasHiddenRows = false;
1100 for (int i = 0; i < aa.length; i++)
1105 hasHiddenRows = true;
1118 System.out.println("before vis: " + i);
1122 // don't draw what isn't visible
1125 if (olY > visHeight)
1133 "Scroll offset: " + sOffset + " after vis: " + i);
1137 // don't draw what isn't visible
1141 g.setColor(Color.black);
1143 offset = -aa[i].height / 2;
1147 offset += fm.getHeight() / 2;
1148 offset -= fm.getDescent();
1152 offset += fm.getDescent();
1155 x = width - fm.stringWidth(aa[i].label) - 3;
1157 if (aa[i].graphGroup > -1)
1160 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1161 // computed efficiently for all visible labels
1162 for (int gg = 0; gg < aa.length; gg++)
1164 if (aa[gg].graphGroup == aa[i].graphGroup)
1169 if (groupSize * (fontHeight + 8) < aa[i].height)
1171 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1176 // scale font to fit
1177 float h = aa[i].height / (float) groupSize, s;
1184 fontHeight = -8 + (int) h;
1185 s = ((float) fontHeight) / (float) ofontH;
1187 .deriveFont(AffineTransform.getScaleInstance(s, s));
1189 fm = g.getFontMetrics();
1190 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1196 for (int gg = 0; gg < aa.length; gg++)
1198 if (aa[gg].graphGroup == aa[i].graphGroup)
1200 x = width - fm.stringWidth(aa[gg].label) - 3;
1201 g.drawString(aa[gg].label, x, y - graphExtras);
1203 if (aa[gg]._linecolour != null)
1206 g.setColor(aa[gg]._linecolour);
1207 g.drawLine(x, y - graphExtras + 3,
1208 x + fm.stringWidth(aa[gg].label),
1209 y - graphExtras + 3);
1212 g.setColor(Color.black);
1213 graphExtras += fontHeight + 8;
1217 g.setFont(baseFont);
1219 fontHeight = ofontH;
1223 g.drawString(aa[i].label, x, y + offset);
1230 // g.drawImage(adjusterImage, 2, 0 - getScrollOffset(), this);
1232 else if (dragEvent != null && aa != null)
1234 g.setColor(Color.lightGray);
1235 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1236 dragEvent.getY() - getScrollOffset());
1239 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1241 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1242 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1247 public int getScrollOffset()
1249 return scrollOffset;
1253 public void mouseEntered(MouseEvent e)