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;
37 import jalview.util.dialogrunner.RunResponse;
39 import java.awt.Color;
40 import java.awt.Cursor;
41 import java.awt.Dimension;
43 import java.awt.FontMetrics;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
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.util.Arrays;
56 import java.util.Collections;
57 import java.util.Iterator;
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
76 * width in pixels within which height adjuster arrows are shown and active
78 private static final int HEIGHT_ADJUSTER_WIDTH = 50;
81 * height in pixels for allowing height adjuster to be active
83 private static int HEIGHT_ADJUSTER_HEIGHT = 10;
85 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
88 private static final Font font = new Font("Arial", Font.PLAIN, 11);
90 private static final String TOGGLE_LABELSCALE = MessageManager
91 .getString("label.scale_label_to_column");
93 private static final String ADDNEW = MessageManager
94 .getString("label.add_new_row");
96 private static final String EDITNAME = MessageManager
97 .getString("label.edit_label_description");
99 private static final String HIDE = MessageManager
100 .getString("label.hide_row");
102 private static final String DELETE = MessageManager
103 .getString("label.delete_row");
105 private static final String SHOWALL = MessageManager
106 .getString("label.show_all_hidden_rows");
108 private static final String OUTPUT_TEXT = MessageManager
109 .getString("label.export_annotation");
111 private static final String COPYCONS_SEQ = MessageManager
112 .getString("label.copy_consensus_sequence");
114 private final boolean debugRedraw = false;
120 private MouseEvent dragEvent;
124 private int selectedRow;
126 private int scrollOffset = 0;
128 private boolean hasHiddenRows;
130 private boolean resizePanel = false;
133 * Creates a new AnnotationLabels object
137 public AnnotationLabels(AlignmentPanel ap)
141 ToolTipManager.sharedInstance().registerComponent(this);
143 addMouseListener(this);
144 addMouseMotionListener(this);
145 addMouseWheelListener(ap.getAnnotationPanel());
148 public AnnotationLabels(AlignViewport av)
159 public void setScrollOffset(int y)
166 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
170 * coordinate position to search for a row
172 void getSelectedRow(int y)
175 AlignmentAnnotation[] aa = ap.av.getAlignment()
176 .getAlignmentAnnotation();
180 for (int i = 0; i < aa.length; i++)
188 height += aa[i].height;
201 * Set all annotations visible
205 AlignmentAnnotation[] aa = ap.av.getAlignment()
206 .getAlignmentAnnotation();
207 for (int i = 0; i < aa.length; i++)
209 if (!aa[i].visible && aa[i].annotations != null)
211 aa[i].visible = true;
218 * Shows a dialog where the annotation name and description may be edited. If
219 * parameter addNew is true, then on confirmation, a new AlignmentAnnotation
220 * is added, else an existing annotation is updated.
225 void editLabelDescription(AlignmentAnnotation annotation, boolean addNew)
227 String name = MessageManager.getString("label.annotation_name");
228 String description = MessageManager
229 .getString("label.annotation_description");
230 String title = MessageManager
231 .getString("label.edit_annotation_name_description");
232 EditNameDialog dialog = new EditNameDialog(annotation.label,
233 annotation.description, name, description);
235 dialog.showDialog(ap.alignFrame, title,
236 new RunResponse(JvOptionPane.OK_OPTION)
241 annotation.label = dialog.getName();
242 String text = dialog.getDescription();
243 if (text != null && text.length() == 0)
247 annotation.description = text;
250 ap.av.getAlignment().addAnnotation(annotation);
251 ap.av.getAlignment().setAnnotationIndex(annotation, 0);
259 public void mousePressed(MouseEvent evt)
261 getSelectedRow(evt.getY() - getScrollOffset());
263 if (evt.isPopupTrigger())
265 showPopupMenu(evt, selectedRow);
270 * Build and show the Pop-up menu at the right-click mouse position
275 void showPopupMenu(MouseEvent evt, final int row)
278 final AlignmentAnnotation[] aa = ap.av.getAlignment()
279 .getAlignmentAnnotation();
280 JPopupMenu pop = new JPopupMenu(
281 MessageManager.getString("label.annotations"));
286 JMenuItem item = new JMenuItem(ADDNEW);
287 item.addActionListener(new ActionListener()
290 public void actionPerformed(ActionEvent e)
292 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
293 null, new Annotation[ap.av.getAlignment().getWidth()]);
294 editLabelDescription(newAnnotation, true);
300 * if no rows shown, add option to show all
301 * (if rows are hidden), nothing else to add
307 item = new JMenuItem(SHOWALL);
308 item.addActionListener(new ActionListener()
311 public void actionPerformed(ActionEvent e)
318 pop.show(this, evt.getX(), evt.getY());
323 * Edit Name/Description
325 item = new JMenuItem(EDITNAME);
326 item.addActionListener(new ActionListener()
329 public void actionPerformed(ActionEvent e)
331 editLabelDescription(aa[row], false);
340 item = new JMenuItem(HIDE);
341 item.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent e)
346 aa[row].visible = false;
353 * JAL-1264 hide all sequence-specific annotations of this type
357 if (aa[row].sequenceRef != null)
359 final String label = aa[row].label;
360 JMenuItem hideType = new JMenuItem();
361 String text = MessageManager.getString("label.hide_all") + " "
363 hideType.setText(text);
364 hideType.addActionListener(new ActionListener()
367 public void actionPerformed(ActionEvent e)
369 AlignmentUtils.showOrHideSequenceAnnotations(
370 ap.av.getAlignment(), Collections.singleton(label),
382 item = new JMenuItem(DELETE);
383 item.addActionListener(new ActionListener()
387 public void actionPerformed(ActionEvent e)
389 ap.av.getAlignment().deleteAnnotation(aa[row]);
390 ap.av.getCalcManager().removeWorkerForAnnotation(aa[row]);
401 item = new JMenuItem(SHOWALL);
402 item.addActionListener(new ActionListener()
405 public void actionPerformed(ActionEvent e)
416 item = new JMenuItem(OUTPUT_TEXT);
417 item.addActionListener(new ActionListener()
419 public void actionPerformed(ActionEvent e)
421 new AnnotationExporter(ap).exportAnnotation(aa[row]);
426 // TODO: annotation object should be typed for autocalculated/derived
430 final String label = aa[row].label;
431 if (!aa[row].autoCalculated)
433 if (aa[row].graph == AlignmentAnnotation.NO_GRAPH)
435 // display formatting settings for this row.
439 * scale label to column
441 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
442 aa[row].scaleColLabel);
443 item.addActionListener(new ActionListener()
446 public void actionPerformed(ActionEvent e)
448 aa[row].scaleColLabel = !aa[row].scaleColLabel;
455 else if (label.indexOf("Consensus") > -1)
457 addConsensusMenuItems(pop, aa[row]);
460 pop.show(this, evt.getX(), evt.getY());
464 * Helper method to add Consensus-specific menu items, for alignment or group
465 * consensus annotation
470 private void addConsensusMenuItems(JPopupMenu menu,
471 final AlignmentAnnotation aa)
476 * ignore gaps in consensus
478 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
479 MessageManager.getString("label.ignore_gaps_consensus"),
480 (aa.groupRef != null)
481 ? aa.groupRef.getIgnoreGapsConsensus()
482 : ap.av.isIgnoreGapsConsensus());
483 cbmi.addActionListener(new ActionListener()
486 public void actionPerformed(ActionEvent e)
488 if (aa.groupRef != null)
490 aa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
491 // AnnotationLabels.this.repaint();
492 // ap.getAnnotationPanel()
493 // .paint(ap.getAnnotationPanel().getGraphics());
497 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
499 ap.alignmentChanged();
504 if (aa.groupRef != null)
507 * show group histogram
509 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
510 MessageManager.getString("label.show_group_histogram"),
511 aa.groupRef.isShowConsensusHistogram());
512 chist.addActionListener(new ActionListener()
515 public void actionPerformed(ActionEvent e)
517 aa.groupRef.setShowConsensusHistogram(chist.getState());
526 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
527 MessageManager.getString("label.show_group_logo"),
528 aa.groupRef.isShowSequenceLogo());
529 cprofl.addActionListener(new ActionListener()
532 public void actionPerformed(ActionEvent e)
534 aa.groupRef.setshowSequenceLogo(cprofl.getState());
541 * normalise group logo
543 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
544 MessageManager.getString("label.normalise_group_logo"),
545 aa.groupRef.isNormaliseSequenceLogo());
546 cproflnorm.addActionListener(new ActionListener()
549 public void actionPerformed(ActionEvent e)
551 aa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
552 // automatically enable logo display if we're clicked
553 aa.groupRef.setshowSequenceLogo(true);
557 menu.add(cproflnorm);
564 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
565 MessageManager.getString("label.show_histogram"),
566 av.isShowConsensusHistogram());
567 chist.addActionListener(new ActionListener()
570 public void actionPerformed(ActionEvent e)
572 av.setShowConsensusHistogram(chist.getState());
573 ap.alignFrame.setMenusForViewport();
582 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
583 MessageManager.getString("label.show_logo"),
584 av.isShowSequenceLogo());
585 cprof.addActionListener(new ActionListener()
588 public void actionPerformed(ActionEvent e)
590 av.setShowSequenceLogo(cprof.getState());
591 ap.alignFrame.setMenusForViewport();
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 av.setShowSequenceLogo(true);
609 av.setNormaliseSequenceLogo(cprofnorm.getState());
610 ap.alignFrame.setMenusForViewport();
618 * copy consensus sequence
620 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
621 consclipbrd.addActionListener(new ActionListener()
624 public void actionPerformed(ActionEvent e)
626 copy_annotseqtoclipboard(aa);
629 menu.add(consclipbrd);
633 * Reorders annotation rows after a drag of a label
638 public void mouseReleased(MouseEvent evt)
640 if (evt.isPopupTrigger())
642 showPopupMenu(evt, selectedRow);
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() < HEIGHT_ADJUSTER_HEIGHT
821 && evt.getX() < HEIGHT_ADJUSTER_WIDTH;
823 if (resizePanel != was)
826 .getPredefinedCursor(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 * Consensus annotation
957 protected void copy_annotseqtoclipboard(AlignmentAnnotation cons)
960 if (cons.groupRef != null)
962 sq = cons.groupRef.getConsensusSeq();
966 sq = av.getConsensusSeq();
973 SequenceI[] seqs = new SequenceI[] { sq };
974 String[] omitHidden = null;
975 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
976 if (dseqs[0] == null)
978 dseqs[0] = new Sequence(sq);
979 dseqs[0].setSequence(AlignSeq.extractGaps(Comparison.GapChars,
980 sq.getSequenceAsString()));
982 sq.setDatasetSequence(dseqs[0]);
984 Alignment ds = new Alignment(dseqs);
985 if (av.hasHiddenColumns())
987 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
988 .getVisContigsIterator(0, sq.getLength(), false);
989 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
992 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
993 if (av.hasHiddenColumns())
995 alignmentStartEnd = av.getAlignment().getHiddenColumns()
996 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
999 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1000 seqs, omitHidden, alignmentStartEnd);
1002 Toolkit.getDefaultToolkit().getSystemClipboard()
1003 .setContents(new StringSelection(output), Desktop.instance);
1005 HiddenColumns hiddenColumns = null;
1007 if (av.hasHiddenColumns())
1009 hiddenColumns = new HiddenColumns(
1010 av.getAlignment().getHiddenColumns());
1013 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1015 // sequence ? need to
1017 // sequence as special.
1028 public void paintComponent(Graphics g)
1031 int width = getWidth();
1034 width = ap.calculateIdWidth().width + 4;
1037 Graphics2D g2 = (Graphics2D) g;
1040 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1041 RenderingHints.VALUE_ANTIALIAS_ON);
1044 drawComponent(g2, true, width);
1049 * Draw the full set of annotation Labels for the alignment at the given
1053 * Graphics2D instance (needed for font scaling)
1055 * Width for scaling labels
1058 public void drawComponent(Graphics g, int width)
1060 drawComponent(g, false, width);
1064 * Draw the full set of annotation Labels for the alignment at the given
1068 * Graphics2D instance (needed for font scaling)
1070 * - true indicates that only current visible area needs to be
1073 * Width for scaling labels
1075 public void drawComponent(Graphics g, boolean clip, int width)
1077 if (av.getFont().getSize() < 10)
1083 g.setFont(av.getFont());
1086 FontMetrics fm = g.getFontMetrics(g.getFont());
1087 g.setColor(Color.white);
1088 g.fillRect(0, 0, getWidth(), getHeight());
1090 g.translate(0, getScrollOffset());
1091 g.setColor(Color.black);
1093 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1094 int fontHeight = g.getFont().getSize();
1097 int graphExtras = 0;
1099 Font baseFont = g.getFont();
1100 FontMetrics baseMetrics = fm;
1101 int ofontH = fontHeight;
1104 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1105 ? ap.getAnnotationPanel().getVisibleVRange()
1107 if (clip && visr != null)
1110 visHeight = visr[1];
1112 boolean visible = true, before = false, after = false;
1115 hasHiddenRows = false;
1117 for (int i = 0; i < aa.length; i++)
1122 hasHiddenRows = true;
1135 System.out.println("before vis: " + i);
1139 // don't draw what isn't visible
1142 if (olY > visHeight)
1150 "Scroll offset: " + sOffset + " after vis: " + i);
1154 // don't draw what isn't visible
1158 g.setColor(Color.black);
1160 offset = -aa[i].height / 2;
1164 offset += fm.getHeight() / 2;
1165 offset -= fm.getDescent();
1169 offset += fm.getDescent();
1172 x = width - fm.stringWidth(aa[i].label) - 3;
1174 if (aa[i].graphGroup > -1)
1177 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1178 // computed efficiently for all visible labels
1179 for (int gg = 0; gg < aa.length; gg++)
1181 if (aa[gg].graphGroup == aa[i].graphGroup)
1186 if (groupSize * (fontHeight + 8) < aa[i].height)
1188 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1193 // scale font to fit
1194 float h = aa[i].height / (float) groupSize, s;
1201 fontHeight = -8 + (int) h;
1202 s = ((float) fontHeight) / (float) ofontH;
1204 .deriveFont(AffineTransform.getScaleInstance(s, s));
1206 fm = g.getFontMetrics();
1207 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1213 for (int gg = 0; gg < aa.length; gg++)
1215 if (aa[gg].graphGroup == aa[i].graphGroup)
1217 x = width - fm.stringWidth(aa[gg].label) - 3;
1218 g.drawString(aa[gg].label, x, y - graphExtras);
1220 if (aa[gg]._linecolour != null)
1223 g.setColor(aa[gg]._linecolour);
1224 g.drawLine(x, y - graphExtras + 3,
1225 x + fm.stringWidth(aa[gg].label),
1226 y - graphExtras + 3);
1229 g.setColor(Color.black);
1230 graphExtras += fontHeight + 8;
1234 g.setFont(baseFont);
1236 fontHeight = ofontH;
1240 g.drawString(aa[i].label, x, y + offset);
1245 if (!resizePanel && dragEvent != null && aa != null)
1247 g.setColor(Color.lightGray);
1248 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1249 dragEvent.getY() - getScrollOffset());
1252 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1254 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1255 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1260 public int getScrollOffset()
1262 return scrollOffset;
1266 public void mouseEntered(MouseEvent e)