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;
58 import javax.swing.JCheckBoxMenuItem;
59 import javax.swing.JMenuItem;
60 import javax.swing.JPanel;
61 import javax.swing.JPopupMenu;
62 import javax.swing.SwingUtilities;
63 import javax.swing.ToolTipManager;
66 * The panel that holds the labels for alignment annotations, providing
67 * tooltips, context menus, drag to reorder rows, and drag to adjust panel
70 public class AnnotationLabels extends JPanel
71 implements MouseListener, MouseMotionListener, ActionListener
73 private static final String HTML_END_TAG = "</html>";
75 private static final String HTML_START_TAG = "<html>";
78 * width in pixels within which height adjuster arrows are shown and active
80 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
83 * height in pixels for allowing height adjuster to be active
85 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
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 boolean fullRepaint = false;
212 if (evt.getActionCommand().equals(ADDNEW))
214 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
215 null, new Annotation[ap.av.getAlignment().getWidth()]);
217 if (!editLabelDescription(newAnnotation))
222 ap.av.getAlignment().addAnnotation(newAnnotation);
223 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
226 else if (evt.getActionCommand().equals(EDITNAME))
228 String name = aa[selectedRow].label;
229 editLabelDescription(aa[selectedRow]);
230 if (!name.equalsIgnoreCase(aa[selectedRow].label))
235 else if (evt.getActionCommand().equals(HIDE))
237 aa[selectedRow].visible = false;
239 else if (evt.getActionCommand().equals(DELETE))
241 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
242 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
245 else if (evt.getActionCommand().equals(SHOWALL))
247 for (int i = 0; i < aa.length; i++)
249 if (!aa[i].visible && aa[i].annotations != null)
251 aa[i].visible = true;
256 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
258 new AnnotationExporter(ap).exportAnnotation(aa[selectedRow]);
260 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
262 SequenceI cons = null;
263 if (aa[selectedRow].groupRef != null)
265 cons = aa[selectedRow].groupRef.getConsensusSeq();
269 cons = av.getConsensusSeq();
273 copy_annotseqtoclipboard(cons);
277 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
279 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
282 ap.refresh(fullRepaint);
292 boolean editLabelDescription(AlignmentAnnotation annotation)
295 EditNameDialog dialog = new EditNameDialog(annotation.label,
296 annotation.description, " Annotation Name ",
297 "Annotation Description ", "Edit Annotation Name/Description",
305 annotation.label = dialog.getName();
307 String text = dialog.getDescription();
308 if (text != null && text.length() == 0)
312 annotation.description = text;
318 public void mousePressed(MouseEvent evt)
320 getSelectedRow(evt.getY() - getScrollOffset());
322 if (evt.isPopupTrigger())
329 * Build and show the Pop-up menu at the right-click mouse position
333 void showPopupMenu(MouseEvent evt)
336 final AlignmentAnnotation[] aa = ap.av.getAlignment()
337 .getAlignmentAnnotation();
339 JPopupMenu pop = new JPopupMenu(
340 MessageManager.getString("label.annotations"));
341 JMenuItem item = new JMenuItem(ADDNEW);
342 item.addActionListener(this);
347 { // let the user make everything visible again
348 item = new JMenuItem(SHOWALL);
349 item.addActionListener(this);
352 pop.show(this, evt.getX(), evt.getY());
355 item = new JMenuItem(EDITNAME);
356 item.addActionListener(this);
358 item = new JMenuItem(HIDE);
359 item.addActionListener(this);
361 // JAL-1264 hide all sequence-specific annotations of this type
362 if (selectedRow < aa.length)
364 if (aa[selectedRow].sequenceRef != null)
366 final String label = aa[selectedRow].label;
367 JMenuItem hideType = new JMenuItem();
368 String text = MessageManager.getString("label.hide_all") + " "
370 hideType.setText(text);
371 hideType.addActionListener(new ActionListener()
374 public void actionPerformed(ActionEvent e)
376 AlignmentUtils.showOrHideSequenceAnnotations(
377 ap.av.getAlignment(), Collections.singleton(label),
385 item = new JMenuItem(DELETE);
386 item.addActionListener(this);
390 item = new JMenuItem(SHOWALL);
391 item.addActionListener(this);
394 item = new JMenuItem(OUTPUT_TEXT);
395 item.addActionListener(this);
397 // TODO: annotation object should be typed for autocalculated/derived
399 if (selectedRow < aa.length)
401 final String label = aa[selectedRow].label;
402 if (!aa[selectedRow].autoCalculated)
404 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
406 // display formatting settings for this row.
408 // av and sequencegroup need to implement same interface for
409 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
410 aa[selectedRow].scaleColLabel);
411 item.addActionListener(this);
415 else if (label.indexOf("Consensus") > -1)
417 addConsensusMenuOptions(ap, aa[selectedRow], pop);
419 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
420 consclipbrd.addActionListener(this);
421 pop.add(consclipbrd);
424 pop.show(this, evt.getX(), evt.getY());
428 * A helper method that adds menu options for calculation and visualisation of
429 * group and/or alignment consensus annotation to a popup menu. This is
430 * designed to be reusable for either unwrapped mode (popup menu is shown on
431 * component AnnotationLabels), or wrapped mode (popup menu is shown on
432 * IdPanel when the mouse is over an annotation label).
438 static void addConsensusMenuOptions(AlignmentPanel ap,
439 AlignmentAnnotation ann,
444 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
445 MessageManager.getString("label.ignore_gaps_consensus"),
446 (ann.groupRef != null) ? ann.groupRef.getIgnoreGapsConsensus()
447 : ap.av.isIgnoreGapsConsensus());
448 final AlignmentAnnotation aaa = ann;
449 cbmi.addActionListener(new ActionListener()
452 public void actionPerformed(ActionEvent e)
454 if (aaa.groupRef != null)
456 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
457 ap.getAnnotationPanel()
458 .paint(ap.getAnnotationPanel().getGraphics());
462 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
464 ap.alignmentChanged();
469 if (aaa.groupRef != null)
472 * group consensus options
474 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
475 MessageManager.getString("label.show_group_histogram"),
476 ann.groupRef.isShowConsensusHistogram());
477 chist.addActionListener(new ActionListener()
480 public void actionPerformed(ActionEvent e)
482 aaa.groupRef.setShowConsensusHistogram(chist.getState());
487 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
488 MessageManager.getString("label.show_group_logo"),
489 ann.groupRef.isShowSequenceLogo());
490 cprofl.addActionListener(new ActionListener()
493 public void actionPerformed(ActionEvent e)
495 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
500 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
501 MessageManager.getString("label.normalise_group_logo"),
502 ann.groupRef.isNormaliseSequenceLogo());
503 cproflnorm.addActionListener(new ActionListener()
506 public void actionPerformed(ActionEvent e)
508 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
509 // automatically enable logo display if we're clicked
510 aaa.groupRef.setshowSequenceLogo(true);
519 * alignment consensus options
521 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
522 MessageManager.getString("label.show_histogram"),
523 ap.av.isShowConsensusHistogram());
524 chist.addActionListener(new ActionListener()
527 public void actionPerformed(ActionEvent e)
529 ap.av.setShowConsensusHistogram(chist.getState());
530 ap.alignFrame.setMenusForViewport();
535 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
536 MessageManager.getString("label.show_logo"),
537 ap.av.isShowSequenceLogo());
538 cprof.addActionListener(new ActionListener()
541 public void actionPerformed(ActionEvent e)
543 ap.av.setShowSequenceLogo(cprof.getState());
544 ap.alignFrame.setMenusForViewport();
549 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
550 MessageManager.getString("label.normalise_logo"),
551 ap.av.isNormaliseSequenceLogo());
552 cprofnorm.addActionListener(new ActionListener()
555 public void actionPerformed(ActionEvent e)
557 ap.av.setShowSequenceLogo(true);
558 ap.av.setNormaliseSequenceLogo(cprofnorm.getState());
559 ap.alignFrame.setMenusForViewport();
568 * Reorders annotation rows after a drag of a label
573 public void mouseReleased(MouseEvent evt)
575 if (evt.isPopupTrigger())
581 int start = selectedRow;
582 getSelectedRow(evt.getY() - getScrollOffset());
583 int end = selectedRow;
586 * if dragging to resize instead, start == end
590 // Swap these annotations
591 AlignmentAnnotation startAA = ap.av.getAlignment()
592 .getAlignmentAnnotation()[start];
595 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
597 AlignmentAnnotation endAA = ap.av.getAlignment()
598 .getAlignmentAnnotation()[end];
600 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
601 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
607 ap.getAnnotationPanel().repaint();
611 * Removes the height adjuster image on leaving the panel, unless currently
615 public void mouseExited(MouseEvent evt)
617 if (resizePanel && dragEvent == null)
625 * A mouse drag may be either an adjustment of the panel height (if flag
626 * resizePanel is set on), or a reordering of the annotation rows. The former
627 * is dealt with by this method, the latter in mouseReleased.
632 public void mouseDragged(MouseEvent evt)
638 Dimension d = ap.annotationScroller.getPreferredSize();
639 int dif = evt.getY() - oldY;
641 dif /= ap.av.getCharHeight();
642 dif *= ap.av.getCharHeight();
644 if ((d.height - dif) > 20)
646 ap.annotationScroller
647 .setPreferredSize(new Dimension(d.width, d.height - dif));
648 d = ap.annotationSpaceFillerHolder.getPreferredSize();
649 ap.annotationSpaceFillerHolder
650 .setPreferredSize(new Dimension(d.width, d.height - dif));
651 ap.paintAlignment(true, false);
663 * Updates the tooltip as the mouse moves over the labels
668 public void mouseMoved(MouseEvent evt)
670 showOrHideAdjuster(evt);
672 getSelectedRow(evt.getY() - getScrollOffset());
674 if (selectedRow > -1 && ap.av.getAlignment()
675 .getAlignmentAnnotation().length > selectedRow)
677 AlignmentAnnotation aa = ap.av.getAlignment()
678 .getAlignmentAnnotation()[selectedRow];
680 String desc = getTooltip(aa);
681 this.setToolTipText(desc);
682 ap.alignFrame.setStatus(aa.label);
687 * Answers a tooltip, formatted as html, containing the annotation description
688 * (prefixed by associated sequence id if applicable), and the annotation
689 * (non-positional) score if it has one. Answers null if neither description
690 * nor score is found.
695 static String getTooltip(AlignmentAnnotation aa)
701 StringBuilder tooltip = new StringBuilder();
702 if (aa.description != null && !aa.description.equals("New description"))
704 // TODO: we could refactor and merge this code with the code in
705 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
707 String desc = aa.getDescription(true).trim();
708 if (!desc.toLowerCase().startsWith(HTML_START_TAG))
710 tooltip.append(HTML_START_TAG);
711 desc = desc.replace("<", "<");
713 else if (desc.toLowerCase().endsWith(HTML_END_TAG))
715 desc = desc.substring(0, desc.length() - HTML_END_TAG.length());
717 tooltip.append(desc);
721 // begin the tooltip's html fragment
722 tooltip.append(HTML_START_TAG);
726 if (tooltip.length() > HTML_START_TAG.length())
728 tooltip.append("<br/>");
730 // TODO: limit precision of score to avoid noise from imprecise
732 // (64.7 becomes 64.7+/some tiny value).
733 tooltip.append(" Score: ").append(String.valueOf(aa.score));
736 if (tooltip.length() > HTML_START_TAG.length())
738 return tooltip.append(HTML_END_TAG).toString();
742 * nothing in the tooltip (except "<html>")
748 * Shows the height adjuster image if the mouse moves into the top left
749 * region, or hides it if the mouse leaves the regio
753 protected void showOrHideAdjuster(MouseEvent evt)
755 boolean was = resizePanel;
756 resizePanel = evt.getY() < HEIGHT_ADJUSTER_HEIGHT && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
758 if (resizePanel != was)
760 setCursor(Cursor.getPredefinedCursor(
761 resizePanel ? Cursor.S_RESIZE_CURSOR
762 : Cursor.DEFAULT_CURSOR));
768 public void mouseClicked(MouseEvent evt)
770 final AlignmentAnnotation[] aa = ap.av.getAlignment()
771 .getAlignmentAnnotation();
772 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
774 if (selectedRow > -1 && selectedRow < aa.length)
776 if (aa[selectedRow].groupRef != null)
778 if (evt.getClickCount() >= 2)
780 // todo: make the ap scroll to the selection - not necessary, first
781 // click highlights/scrolls, second selects
782 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
784 SequenceGroup sg = ap.av.getSelectionGroup();
785 if (sg == null || sg == aa[selectedRow].groupRef
786 || !(Platform.isControlDown(evt) || evt.isShiftDown()))
788 if (Platform.isControlDown(evt) || evt.isShiftDown())
790 // clone a new selection group from the associated group
791 ap.av.setSelectionGroup(
792 new SequenceGroup(aa[selectedRow].groupRef));
796 // set selection to the associated group so it can be edited
797 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
802 // modify current selection with associated group
803 int remainToAdd = aa[selectedRow].groupRef.getSize();
804 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
806 if (jalview.util.Platform.isControlDown(evt))
808 sg.addOrRemove(sgs, --remainToAdd == 0);
812 // notionally, we should also add intermediate sequences from
813 // last added sequence ?
814 sg.addSequence(sgs, --remainToAdd == 0);
819 ap.paintAlignment(false, false);
820 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
821 ap.av.sendSelection();
825 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
826 aa[selectedRow].groupRef.getSequences(null));
830 else if (aa[selectedRow].sequenceRef != null)
832 if (evt.getClickCount() == 1)
834 ap.getSeqPanel().ap.getIdPanel()
835 .highlightSearchResults(Arrays.asList(new SequenceI[]
836 { aa[selectedRow].sequenceRef }));
838 else if (evt.getClickCount() >= 2)
840 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
841 SequenceGroup sg = ap.av.getSelectionGroup();
844 // we make a copy rather than edit the current selection if no
846 // see Enhancement JAL-1557
847 if (!(Platform.isControlDown(evt) || evt.isShiftDown()))
849 sg = new SequenceGroup(sg);
851 sg.addSequence(aa[selectedRow].sequenceRef, false);
855 if (Platform.isControlDown(evt))
857 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
861 // notionally, we should also add intermediate sequences from
862 // last added sequence ?
863 sg.addSequence(aa[selectedRow].sequenceRef, true);
869 sg = new SequenceGroup();
871 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
872 sg.addSequence(aa[selectedRow].sequenceRef, false);
874 ap.av.setSelectionGroup(sg);
875 ap.paintAlignment(false, false);
876 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
877 ap.av.sendSelection();
887 * do a single sequence copy to jalview and the system clipboard
890 * sequence to be copied to clipboard
892 protected void copy_annotseqtoclipboard(SequenceI sq)
894 SequenceI[] seqs = new SequenceI[] { sq };
895 String[] omitHidden = null;
896 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
897 if (dseqs[0] == null)
899 dseqs[0] = new Sequence(sq);
900 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
901 sq.getSequenceAsString()));
903 sq.setDatasetSequence(dseqs[0]);
905 Alignment ds = new Alignment(dseqs);
906 if (av.hasHiddenColumns())
908 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
909 .getVisContigsIterator(0, sq.getLength(), false);
910 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
913 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
914 if (av.hasHiddenColumns())
916 alignmentStartEnd = av.getAlignment().getHiddenColumns()
917 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
920 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
921 seqs, omitHidden, alignmentStartEnd);
923 Toolkit.getDefaultToolkit().getSystemClipboard()
924 .setContents(new StringSelection(output), Desktop.instance);
926 HiddenColumns hiddenColumns = null;
928 if (av.hasHiddenColumns())
930 hiddenColumns = new HiddenColumns(
931 av.getAlignment().getHiddenColumns());
934 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
936 // sequence ? need to
938 // sequence as special.
949 public void paintComponent(Graphics g)
952 int width = getWidth();
955 width = ap.calculateIdWidth().width + 4;
958 Graphics2D g2 = (Graphics2D) g;
961 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
962 RenderingHints.VALUE_ANTIALIAS_ON);
965 drawComponent(g2, true, width);
970 * Draw the full set of annotation Labels for the alignment at the given
974 * Graphics2D instance (needed for font scaling)
976 * Width for scaling labels
979 public void drawComponent(Graphics g, int width)
981 drawComponent(g, false, width);
985 * Draw the full set of annotation Labels for the alignment at the given
989 * Graphics2D instance (needed for font scaling)
991 * - true indicates that only current visible area needs to be
994 * Width for scaling labels
996 public void drawComponent(Graphics g, boolean clip, int width)
998 if (av.getFont().getSize() < 10)
1004 g.setFont(av.getFont());
1007 FontMetrics fm = g.getFontMetrics(g.getFont());
1008 g.setColor(Color.white);
1009 g.fillRect(0, 0, getWidth(), getHeight());
1011 g.translate(0, getScrollOffset());
1012 g.setColor(Color.black);
1014 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1015 int fontHeight = g.getFont().getSize();
1018 int graphExtras = 0;
1020 Font baseFont = g.getFont();
1021 FontMetrics baseMetrics = fm;
1022 int ofontH = fontHeight;
1025 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1026 ? ap.getAnnotationPanel().getVisibleVRange()
1028 if (clip && visr != null)
1031 visHeight = visr[1];
1033 boolean visible = true, before = false, after = false;
1036 hasHiddenRows = false;
1038 for (int i = 0; i < aa.length; i++)
1043 hasHiddenRows = true;
1056 System.out.println("before vis: " + i);
1060 // don't draw what isn't visible
1063 if (olY > visHeight)
1071 "Scroll offset: " + sOffset + " after vis: " + i);
1075 // don't draw what isn't visible
1079 g.setColor(Color.black);
1081 offset = -aa[i].height / 2;
1085 offset += fm.getHeight() / 2;
1086 offset -= fm.getDescent();
1090 offset += fm.getDescent();
1093 x = width - fm.stringWidth(aa[i].label) - 3;
1095 if (aa[i].graphGroup > -1)
1098 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1099 // computed efficiently for all visible labels
1100 for (int gg = 0; gg < aa.length; gg++)
1102 if (aa[gg].graphGroup == aa[i].graphGroup)
1107 if (groupSize * (fontHeight + 8) < aa[i].height)
1109 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1114 // scale font to fit
1115 float h = aa[i].height / (float) groupSize, s;
1122 fontHeight = -8 + (int) h;
1123 s = ((float) fontHeight) / (float) ofontH;
1125 .deriveFont(AffineTransform.getScaleInstance(s, s));
1127 fm = g.getFontMetrics();
1128 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1134 for (int gg = 0; gg < aa.length; gg++)
1136 if (aa[gg].graphGroup == aa[i].graphGroup)
1138 x = width - fm.stringWidth(aa[gg].label) - 3;
1139 g.drawString(aa[gg].label, x, y - graphExtras);
1141 if (aa[gg]._linecolour != null)
1144 g.setColor(aa[gg]._linecolour);
1145 g.drawLine(x, y - graphExtras + 3,
1146 x + fm.stringWidth(aa[gg].label),
1147 y - graphExtras + 3);
1150 g.setColor(Color.black);
1151 graphExtras += fontHeight + 8;
1155 g.setFont(baseFont);
1157 fontHeight = ofontH;
1161 g.drawString(aa[i].label, x, y + offset);
1166 if (!resizePanel && dragEvent != null && aa != null)
1168 g.setColor(Color.lightGray);
1169 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1170 dragEvent.getY() - getScrollOffset());
1173 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1175 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1176 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1181 public int getScrollOffset()
1183 return scrollOffset;
1187 public void mouseEntered(MouseEvent e)