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.AlignmentUtils;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.Annotation;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceGroup;
29 import jalview.datamodel.SequenceI;
30 import jalview.io.FormatAdapter;
31 import jalview.util.MessageManager;
33 import java.awt.Color;
34 import java.awt.Dimension;
36 import java.awt.FontMetrics;
37 import java.awt.Graphics;
38 import java.awt.Graphics2D;
39 import java.awt.Image;
40 import java.awt.MediaTracker;
41 import java.awt.RenderingHints;
42 import java.awt.Toolkit;
43 import java.awt.datatransfer.StringSelection;
44 import java.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
46 import java.awt.event.MouseEvent;
47 import java.awt.event.MouseListener;
48 import java.awt.event.MouseMotionListener;
49 import java.awt.geom.AffineTransform;
50 import java.awt.image.BufferedImage;
51 import java.util.ArrayList;
52 import java.util.Arrays;
53 import java.util.Collections;
54 import java.util.List;
55 import java.util.regex.Pattern;
57 import javax.swing.JCheckBoxMenuItem;
58 import javax.swing.JMenuItem;
59 import javax.swing.JPanel;
60 import javax.swing.JPopupMenu;
61 import javax.swing.SwingUtilities;
62 import javax.swing.ToolTipManager;
70 public class AnnotationLabels extends JPanel implements MouseListener,
71 MouseMotionListener, ActionListener
73 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
76 String TOGGLE_LABELSCALE = MessageManager
77 .getString("label.scale_label_to_column");
79 String ADDNEW = MessageManager.getString("label.add_new_row");
81 String EDITNAME = MessageManager
82 .getString("label.edit_label_description");
84 String HIDE = MessageManager.getString("label.hide_row");
86 String DELETE = MessageManager.getString("label.delete_row");
88 String SHOWALL = MessageManager.getString("label.show_all_hidden_rows");
90 String OUTPUT_TEXT = MessageManager.getString("label.export_annotation");
92 String COPYCONS_SEQ = MessageManager
93 .getString("label.copy_consensus_sequence");
95 boolean resizePanel = false;
103 boolean resizing = false;
105 MouseEvent dragEvent;
111 private int scrollOffset = 0;
113 Font font = new Font("Arial", Font.PLAIN, 11);
115 private boolean hasHiddenRows;
118 * Creates a new AnnotationLabels object.
123 public AnnotationLabels(AlignmentPanel ap)
127 ToolTipManager.sharedInstance().registerComponent(this);
129 java.net.URL url = getClass().getResource("/images/idwidth.gif");
134 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
139 MediaTracker mt = new MediaTracker(this);
140 mt.addImage(temp, 0);
142 } catch (Exception ex)
146 BufferedImage bi = new BufferedImage(temp.getHeight(this),
147 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
148 Graphics2D g = (Graphics2D) bi.getGraphics();
149 g.rotate(Math.toRadians(90));
150 g.drawImage(temp, 0, -bi.getWidth(this), this);
153 addMouseListener(this);
154 addMouseMotionListener(this);
155 addMouseWheelListener(ap.getAnnotationPanel());
158 public AnnotationLabels(AlignViewport av)
169 public void setScrollOffset(int y)
176 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
180 * coordinate position to search for a row
182 void getSelectedRow(int y)
185 AlignmentAnnotation[] aa = ap.av.getAlignment()
186 .getAlignmentAnnotation();
190 for (int i = 0; i < aa.length; i++)
198 height += aa[i].height;
217 public void actionPerformed(ActionEvent evt)
219 AlignmentAnnotation[] aa = ap.av.getAlignment()
220 .getAlignmentAnnotation();
222 boolean fullRepaint = false;
223 if (evt.getActionCommand().equals(ADDNEW))
225 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
226 null, new Annotation[ap.av.getAlignment().getWidth()]);
228 if (!editLabelDescription(newAnnotation))
233 ap.av.getAlignment().addAnnotation(newAnnotation);
234 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
237 else if (evt.getActionCommand().equals(EDITNAME))
239 String name = aa[selectedRow].label;
240 editLabelDescription(aa[selectedRow]);
241 if (!name.equalsIgnoreCase(aa[selectedRow].label))
246 else if (evt.getActionCommand().equals(HIDE))
248 aa[selectedRow].visible = false;
250 else if (evt.getActionCommand().equals(DELETE))
252 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
253 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
256 else if (evt.getActionCommand().equals(SHOWALL))
258 for (int i = 0; i < aa.length; i++)
260 if (!aa[i].visible && aa[i].annotations != null)
262 aa[i].visible = true;
267 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
269 new AnnotationExporter().exportAnnotations(ap,
270 new AlignmentAnnotation[] { aa[selectedRow] });
272 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
274 SequenceI cons = null;
275 if (aa[selectedRow].groupRef != null)
277 cons = aa[selectedRow].groupRef.getConsensusSeq();
281 cons = av.getConsensusSeq();
285 copy_annotseqtoclipboard(cons);
289 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
291 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
294 refresh(fullRepaint);
301 * @adjustHeight if true, try to recalculate panel height for visible
304 protected void refresh(boolean adjustHeight)
306 ap.validateAnnotationDimensions(adjustHeight);
310 // sort, repaint, update overview
311 ap.paintAlignment(true);
315 // lightweight repaint
326 boolean editLabelDescription(AlignmentAnnotation annotation)
329 EditNameDialog dialog = new EditNameDialog(annotation.label,
330 annotation.description, " Annotation Name ",
331 "Annotation Description ", "Edit Annotation Name/Description",
339 annotation.label = dialog.getName();
341 String text = dialog.getDescription();
342 if (text != null && text.length() == 0)
346 annotation.description = text;
352 public void mousePressed(MouseEvent evt)
354 getSelectedRow(evt.getY() - getScrollOffset());
356 if (evt.isPopupTrigger())
363 * Build and show the Pop-up menu at the right-click mouse position
367 void showPopupMenu(MouseEvent evt)
370 final AlignmentAnnotation[] aa = ap.av.getAlignment()
371 .getAlignmentAnnotation();
373 JPopupMenu pop = new JPopupMenu(
374 MessageManager.getString("label.annotations"));
375 JMenuItem item = new JMenuItem(ADDNEW);
376 item.addActionListener(this);
381 { // let the user make everything visible again
382 item = new JMenuItem(SHOWALL);
383 item.addActionListener(this);
386 pop.show(this, evt.getX(), evt.getY());
389 item = new JMenuItem(EDITNAME);
390 item.addActionListener(this);
392 item = new JMenuItem(HIDE);
393 item.addActionListener(this);
395 // JAL-1264 hide all sequence-specific annotations of this type
396 if (selectedRow < aa.length)
398 if (aa[selectedRow].sequenceRef != null)
400 final String label = aa[selectedRow].label;
401 JMenuItem hideType = new JMenuItem();
402 String text = MessageManager.getString("label.hide_all") + " "
404 hideType.setText(text);
405 hideType.addActionListener(new ActionListener()
408 public void actionPerformed(ActionEvent e)
410 AlignmentUtils.showOrHideSequenceAnnotations(
411 ap.av.getAlignment(), Collections.singleton(label),
413 // for (AlignmentAnnotation ann : ap.av.getAlignment()
414 // .getAlignmentAnnotation())
416 // if (ann.sequenceRef != null && ann.label != null
417 // && ann.label.equals(label))
419 // ann.visible = false;
428 item = new JMenuItem(DELETE);
429 item.addActionListener(this);
433 item = new JMenuItem(SHOWALL);
434 item.addActionListener(this);
437 item = new JMenuItem(OUTPUT_TEXT);
438 item.addActionListener(this);
440 // TODO: annotation object should be typed for autocalculated/derived
442 if (selectedRow < aa.length)
444 final String label = aa[selectedRow].label;
445 if (!aa[selectedRow].autoCalculated)
447 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
449 // display formatting settings for this row.
451 // av and sequencegroup need to implement same interface for
452 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
453 aa[selectedRow].scaleColLabel);
454 item.addActionListener(this);
458 else if (label.indexOf("Consensus") > -1)
461 // av and sequencegroup need to implement same interface for
462 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
463 MessageManager.getString("label.ignore_gaps_consensus"),
464 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
465 .getIgnoreGapsConsensus() : ap.av
466 .isIgnoreGapsConsensus());
467 final AlignmentAnnotation aaa = aa[selectedRow];
468 cbmi.addActionListener(new ActionListener()
471 public void actionPerformed(ActionEvent e)
473 if (aaa.groupRef != null)
475 // TODO: pass on reference to ap so the view can be updated.
476 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
477 ap.getAnnotationPanel().paint(
478 ap.getAnnotationPanel().getGraphics());
482 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
484 ap.alignmentChanged();
488 // av and sequencegroup need to implement same interface for
489 if (aaa.groupRef != null)
491 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
492 MessageManager.getString("label.show_group_histogram"),
493 aa[selectedRow].groupRef.isShowConsensusHistogram());
494 chist.addActionListener(new ActionListener()
497 public void actionPerformed(ActionEvent e)
499 // TODO: pass on reference
505 aaa.groupRef.setShowConsensusHistogram(chist.getState());
507 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
511 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
512 MessageManager.getString("label.show_group_logo"),
513 aa[selectedRow].groupRef.isShowSequenceLogo());
514 cprofl.addActionListener(new ActionListener()
517 public void actionPerformed(ActionEvent e)
519 // TODO: pass on reference
525 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
527 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
531 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
532 MessageManager.getString("label.normalise_group_logo"),
533 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
534 cproflnorm.addActionListener(new ActionListener()
537 public void actionPerformed(ActionEvent e)
540 // TODO: pass on reference
546 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
547 // automatically enable logo display if we're clicked
548 aaa.groupRef.setshowSequenceLogo(true);
550 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
557 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
558 MessageManager.getString("label.show_histogram"),
559 av.isShowConsensusHistogram());
560 chist.addActionListener(new ActionListener()
563 public void actionPerformed(ActionEvent e)
565 // TODO: pass on reference
571 av.setShowConsensusHistogram(chist.getState());
572 ap.alignFrame.setMenusForViewport();
574 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
578 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
579 MessageManager.getString("label.show_logo"),
580 av.isShowSequenceLogo());
581 cprof.addActionListener(new ActionListener()
584 public void actionPerformed(ActionEvent e)
586 // TODO: pass on reference
592 av.setShowSequenceLogo(cprof.getState());
593 ap.alignFrame.setMenusForViewport();
595 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
599 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
600 MessageManager.getString("label.normalise_logo"),
601 av.isNormaliseSequenceLogo());
602 cprofnorm.addActionListener(new ActionListener()
605 public void actionPerformed(ActionEvent e)
607 // TODO: pass on reference
613 av.setShowSequenceLogo(true);
614 av.setNormaliseSequenceLogo(cprofnorm.getState());
615 ap.alignFrame.setMenusForViewport();
617 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
622 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
623 consclipbrd.addActionListener(this);
624 pop.add(consclipbrd);
627 pop.show(this, evt.getX(), evt.getY());
637 public void mouseReleased(MouseEvent evt)
639 if (evt.isPopupTrigger())
645 int start = selectedRow;
646 getSelectedRow(evt.getY() - getScrollOffset());
647 int end = selectedRow;
651 // Swap these annotations
652 AlignmentAnnotation startAA = ap.av.getAlignment()
653 .getAlignmentAnnotation()[start];
656 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
658 AlignmentAnnotation endAA = ap.av.getAlignment()
659 .getAlignmentAnnotation()[end];
661 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
662 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
668 ap.getAnnotationPanel().repaint();
678 public void mouseEntered(MouseEvent evt)
694 public void mouseExited(MouseEvent evt)
696 if (dragEvent == null)
710 public void mouseDragged(MouseEvent evt)
716 Dimension d = ap.annotationScroller.getPreferredSize();
717 int dif = evt.getY() - oldY;
719 dif /= ap.av.getCharHeight();
720 dif *= ap.av.getCharHeight();
722 if ((d.height - dif) > 20)
724 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
726 d = ap.annotationSpaceFillerHolder.getPreferredSize();
727 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
728 d.width, d.height - dif));
729 ap.paintAlignment(true);
747 public void mouseMoved(MouseEvent evt)
749 resizePanel = evt.getY() < 10;
751 getSelectedRow(evt.getY() - getScrollOffset());
754 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
756 AlignmentAnnotation aa = ap.av.getAlignment()
757 .getAlignmentAnnotation()[selectedRow];
759 StringBuffer desc = new StringBuffer();
760 if (aa.description != null
761 && !aa.description.equals("New description"))
763 // TODO: we could refactor and merge this code with the code in
764 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
766 desc.append(aa.getDescription(true).trim());
767 // check to see if the description is an html fragment.
768 if (desc.length() < 6
769 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
771 // clean the description ready for embedding in html
772 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
773 .replaceAll("<"));
774 desc.insert(0, "<html>");
778 // remove terminating html if any
779 int i = desc.substring(desc.length() - 7).toLowerCase()
780 .lastIndexOf("</html>");
783 desc.setLength(desc.length() - 7 + i);
788 desc.append("<br/>");
790 // if (aa.hasProperties())
792 // desc.append("<table>");
793 // for (String prop : aa.getProperties())
795 // desc.append("<tr><td>" + prop + "</td><td>"
796 // + aa.getProperty(prop) + "</td><tr>");
798 // desc.append("</table>");
803 // begin the tooltip's html fragment
804 desc.append("<html>");
807 // TODO: limit precision of score to avoid noise from imprecise
809 // (64.7 becomes 64.7+/some tiny value).
810 desc.append(" Score: " + aa.score);
813 if (desc.length() > 6)
815 desc.append("</html>");
816 this.setToolTipText(desc.toString());
820 this.setToolTipText(null);
826 public void mouseClicked(MouseEvent evt)
828 final AlignmentAnnotation[] aa = ap.av.getAlignment()
829 .getAlignmentAnnotation();
830 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
832 if (selectedRow > -1 && selectedRow < aa.length)
834 if (aa[selectedRow].groupRef != null)
836 if (evt.getClickCount() >= 2)
838 // todo: make the ap scroll to the selection - not necessary, first
839 // click highlights/scrolls, second selects
840 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
842 SequenceGroup sg = ap.av.getSelectionGroup();
844 || sg == aa[selectedRow].groupRef
845 || !(jalview.util.Platform.isControlDown(evt) || evt
848 if (jalview.util.Platform.isControlDown(evt)
849 || evt.isShiftDown())
851 // clone a new selection group from the associated group
852 ap.av.setSelectionGroup(new SequenceGroup(
853 aa[selectedRow].groupRef));
857 // set selection to the associated group so it can be edited
858 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
863 // modify current selection with associated group
864 int remainToAdd = aa[selectedRow].groupRef.getSize();
865 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
867 if (jalview.util.Platform.isControlDown(evt))
869 sg.addOrRemove(sgs, --remainToAdd == 0);
873 // notionally, we should also add intermediate sequences from
874 // last added sequence ?
875 sg.addSequence(sgs, --remainToAdd == 0);
880 ap.paintAlignment(false);
881 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
882 ap.av.sendSelection();
886 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
887 aa[selectedRow].groupRef.getSequences(null));
891 else if (aa[selectedRow].sequenceRef != null)
893 if (evt.getClickCount() == 1)
897 .highlightSearchResults(
898 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
900 else if (evt.getClickCount() >= 2)
902 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
903 SequenceGroup sg = ap.av.getSelectionGroup();
906 // we make a copy rather than edit the current selection if no
908 // see Enhancement JAL-1557
909 if (!(jalview.util.Platform.isControlDown(evt) || evt
912 sg = new SequenceGroup(sg);
914 sg.addSequence(aa[selectedRow].sequenceRef, false);
918 if (jalview.util.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);
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(jalview.analysis.AlignSeq.extractGaps(
964 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
966 sq.setDatasetSequence(dseqs[0]);
968 Alignment ds = new Alignment(dseqs);
969 if (av.hasHiddenColumns())
971 omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0,
972 sq.getLength(), seqs);
975 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
976 List<int[]> hiddenCols = av.getColumnSelection().getHiddenColumns();
977 if (hiddenCols != null)
979 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
982 String output = new FormatAdapter().formatSequences("Fasta", seqs,
983 omitHidden, alignmentStartEnd);
985 Toolkit.getDefaultToolkit().getSystemClipboard()
986 .setContents(new StringSelection(output), Desktop.instance);
988 ArrayList<int[]> hiddenColumns = null;
989 if (av.hasHiddenColumns())
991 hiddenColumns = new ArrayList<int[]>();
992 for (int[] region : av.getColumnSelection().getHiddenColumns())
994 hiddenColumns.add(new int[] { region[0], region[1] });
998 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1000 // sequence ? need to
1002 // sequence as special.
1013 public void paintComponent(Graphics g)
1016 int width = getWidth();
1019 width = ap.calculateIdWidth().width + 4;
1022 Graphics2D g2 = (Graphics2D) g;
1025 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1026 RenderingHints.VALUE_ANTIALIAS_ON);
1029 drawComponent(g2, true, width);
1034 * Draw the full set of annotation Labels for the alignment at the given
1038 * Graphics2D instance (needed for font scaling)
1040 * Width for scaling labels
1043 public void drawComponent(Graphics g, int width)
1045 drawComponent(g, false, width);
1048 private final boolean debugRedraw = false;
1051 * Draw the full set of annotation Labels for the alignment at the given
1055 * Graphics2D instance (needed for font scaling)
1057 * - true indicates that only current visible area needs to be
1060 * Width for scaling labels
1062 public void drawComponent(Graphics g, boolean clip, int width)
1064 if (av.getFont().getSize() < 10)
1070 g.setFont(av.getFont());
1073 FontMetrics fm = g.getFontMetrics(g.getFont());
1074 g.setColor(Color.white);
1075 g.fillRect(0, 0, getWidth(), getHeight());
1077 g.translate(0, getScrollOffset());
1078 g.setColor(Color.black);
1080 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1081 int fontHeight = g.getFont().getSize();
1084 int graphExtras = 0;
1086 Font baseFont = g.getFont();
1087 FontMetrics baseMetrics = fm;
1088 int ofontH = fontHeight;
1091 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1092 .getAnnotationPanel().getVisibleVRange() : null;
1093 if (clip && visr != null)
1096 visHeight = visr[1];
1098 boolean visible = true, before = false, after = false;
1101 hasHiddenRows = false;
1103 for (int i = 0; i < aa.length; i++)
1108 hasHiddenRows = true;
1121 System.out.println("before vis: " + i);
1125 // don't draw what isn't visible
1128 if (olY > visHeight)
1135 System.out.println("Scroll offset: " + sOffset
1136 + " after vis: " + i);
1140 // don't draw what isn't visible
1144 g.setColor(Color.black);
1146 offset = -aa[i].height / 2;
1150 offset += fm.getHeight() / 2;
1151 offset -= fm.getDescent();
1155 offset += fm.getDescent();
1158 x = width - fm.stringWidth(aa[i].label) - 3;
1160 if (aa[i].graphGroup > -1)
1163 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1164 // computed efficiently for all visible labels
1165 for (int gg = 0; gg < aa.length; gg++)
1167 if (aa[gg].graphGroup == aa[i].graphGroup)
1172 if (groupSize * (fontHeight + 8) < aa[i].height)
1174 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1178 // scale font to fit
1179 float h = aa[i].height / (float) groupSize, s;
1186 fontHeight = -8 + (int) h;
1187 s = ((float) fontHeight) / (float) ofontH;
1188 Font f = baseFont.deriveFont(AffineTransform
1189 .getScaleInstance(s, s));
1191 fm = g.getFontMetrics();
1192 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1197 for (int gg = 0; gg < aa.length; gg++)
1199 if (aa[gg].graphGroup == aa[i].graphGroup)
1201 x = width - fm.stringWidth(aa[gg].label) - 3;
1202 g.drawString(aa[gg].label, x, y - graphExtras);
1204 if (aa[gg]._linecolour != null)
1207 g.setColor(aa[gg]._linecolour);
1208 g.drawLine(x, y - graphExtras + 3,
1209 x + fm.stringWidth(aa[gg].label), y - graphExtras
1213 g.setColor(Color.black);
1214 graphExtras += fontHeight + 8;
1218 g.setFont(baseFont);
1220 fontHeight = ofontH;
1224 g.drawString(aa[i].label, x, y + offset);
1231 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1233 else if (dragEvent != null && aa != null)
1235 g.setColor(Color.lightGray);
1236 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1237 dragEvent.getY() - getScrollOffset());
1240 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1242 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1243 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1248 public int getScrollOffset()
1250 return scrollOffset;