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.HiddenColumns;
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.MessageManager;
35 import java.awt.Color;
36 import java.awt.Dimension;
38 import java.awt.FontMetrics;
39 import java.awt.Graphics;
40 import java.awt.Graphics2D;
41 import java.awt.Image;
42 import java.awt.MediaTracker;
43 import java.awt.RenderingHints;
44 import java.awt.Toolkit;
45 import java.awt.datatransfer.StringSelection;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.ActionListener;
48 import java.awt.event.MouseEvent;
49 import java.awt.event.MouseListener;
50 import java.awt.event.MouseMotionListener;
51 import java.awt.geom.AffineTransform;
52 import java.awt.image.BufferedImage;
53 import java.util.Arrays;
54 import java.util.Collections;
55 import java.util.Iterator;
56 import java.util.regex.Pattern;
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;
71 public class AnnotationLabels extends JPanel
72 implements MouseListener, MouseMotionListener, ActionListener
74 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
77 String TOGGLE_LABELSCALE = MessageManager
78 .getString("label.scale_label_to_column");
80 String ADDNEW = MessageManager.getString("label.add_new_row");
82 String EDITNAME = MessageManager
83 .getString("label.edit_label_description");
85 String HIDE = MessageManager.getString("label.hide_row");
87 String DELETE = MessageManager.getString("label.delete_row");
89 String SHOWALL = MessageManager.getString("label.show_all_hidden_rows");
91 String OUTPUT_TEXT = MessageManager.getString("label.export_annotation");
93 String COPYCONS_SEQ = MessageManager
94 .getString("label.copy_consensus_sequence");
96 boolean resizePanel = false;
104 boolean resizing = false;
106 MouseEvent dragEvent;
112 private int scrollOffset = 0;
114 Font font = new Font("Arial", Font.PLAIN, 11);
116 private boolean hasHiddenRows;
119 * Creates a new AnnotationLabels object.
124 public AnnotationLabels(AlignmentPanel ap)
128 ToolTipManager.sharedInstance().registerComponent(this);
130 java.net.URL url = getClass().getResource("/images/idwidth.gif");
135 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
140 MediaTracker mt = new MediaTracker(this);
141 mt.addImage(temp, 0);
143 } catch (Exception ex)
147 BufferedImage bi = new BufferedImage(temp.getHeight(this),
148 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
149 Graphics2D g = (Graphics2D) bi.getGraphics();
150 g.rotate(Math.toRadians(90));
151 g.drawImage(temp, 0, -bi.getWidth(this), this);
154 addMouseListener(this);
155 addMouseMotionListener(this);
156 addMouseWheelListener(ap.getAnnotationPanel());
159 public AnnotationLabels(AlignViewport av)
170 public void setScrollOffset(int y)
177 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
181 * coordinate position to search for a row
183 void getSelectedRow(int y)
186 AlignmentAnnotation[] aa = ap.av.getAlignment()
187 .getAlignmentAnnotation();
191 for (int i = 0; i < aa.length; i++)
199 height += aa[i].height;
218 public void actionPerformed(ActionEvent evt)
220 AlignmentAnnotation[] aa = ap.av.getAlignment()
221 .getAlignmentAnnotation();
223 boolean fullRepaint = false;
224 if (evt.getActionCommand().equals(ADDNEW))
226 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
227 null, new Annotation[ap.av.getAlignment().getWidth()]);
229 if (!editLabelDescription(newAnnotation))
234 ap.av.getAlignment().addAnnotation(newAnnotation);
235 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
238 else if (evt.getActionCommand().equals(EDITNAME))
240 String name = aa[selectedRow].label;
241 editLabelDescription(aa[selectedRow]);
242 if (!name.equalsIgnoreCase(aa[selectedRow].label))
247 else if (evt.getActionCommand().equals(HIDE))
249 aa[selectedRow].visible = false;
251 else if (evt.getActionCommand().equals(DELETE))
253 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
254 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
257 else if (evt.getActionCommand().equals(SHOWALL))
259 for (int i = 0; i < aa.length; i++)
261 if (!aa[i].visible && aa[i].annotations != null)
263 aa[i].visible = true;
268 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
270 new AnnotationExporter().exportAnnotations(ap,
271 new AlignmentAnnotation[]
272 { aa[selectedRow] });
274 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
276 SequenceI cons = null;
277 if (aa[selectedRow].groupRef != null)
279 cons = aa[selectedRow].groupRef.getConsensusSeq();
283 cons = av.getConsensusSeq();
287 copy_annotseqtoclipboard(cons);
291 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
293 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
296 ap.refresh(fullRepaint);
306 boolean editLabelDescription(AlignmentAnnotation annotation)
309 EditNameDialog dialog = new EditNameDialog(annotation.label,
310 annotation.description, " Annotation Name ",
311 "Annotation Description ", "Edit Annotation Name/Description",
319 annotation.label = dialog.getName();
321 String text = dialog.getDescription();
322 if (text != null && text.length() == 0)
326 annotation.description = text;
332 public void mousePressed(MouseEvent evt)
334 getSelectedRow(evt.getY() - getScrollOffset());
336 if (evt.isPopupTrigger())
343 * Build and show the Pop-up menu at the right-click mouse position
347 void showPopupMenu(MouseEvent evt)
350 final AlignmentAnnotation[] aa = ap.av.getAlignment()
351 .getAlignmentAnnotation();
353 JPopupMenu pop = new JPopupMenu(
354 MessageManager.getString("label.annotations"));
355 JMenuItem item = new JMenuItem(ADDNEW);
356 item.addActionListener(this);
361 { // let the user make everything visible again
362 item = new JMenuItem(SHOWALL);
363 item.addActionListener(this);
366 pop.show(this, evt.getX(), evt.getY());
369 item = new JMenuItem(EDITNAME);
370 item.addActionListener(this);
372 item = new JMenuItem(HIDE);
373 item.addActionListener(this);
375 // JAL-1264 hide all sequence-specific annotations of this type
376 if (selectedRow < aa.length)
378 if (aa[selectedRow].sequenceRef != null)
380 final String label = aa[selectedRow].label;
381 JMenuItem hideType = new JMenuItem();
382 String text = MessageManager.getString("label.hide_all") + " "
384 hideType.setText(text);
385 hideType.addActionListener(new ActionListener()
388 public void actionPerformed(ActionEvent e)
390 AlignmentUtils.showOrHideSequenceAnnotations(
391 ap.av.getAlignment(), Collections.singleton(label),
393 // for (AlignmentAnnotation ann : ap.av.getAlignment()
394 // .getAlignmentAnnotation())
396 // if (ann.sequenceRef != null && ann.label != null
397 // && ann.label.equals(label))
399 // ann.visible = false;
408 item = new JMenuItem(DELETE);
409 item.addActionListener(this);
413 item = new JMenuItem(SHOWALL);
414 item.addActionListener(this);
417 item = new JMenuItem(OUTPUT_TEXT);
418 item.addActionListener(this);
420 // TODO: annotation object should be typed for autocalculated/derived
422 if (selectedRow < aa.length)
424 final String label = aa[selectedRow].label;
425 if (!aa[selectedRow].autoCalculated)
427 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
429 // display formatting settings for this row.
431 // av and sequencegroup need to implement same interface for
432 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
433 aa[selectedRow].scaleColLabel);
434 item.addActionListener(this);
438 else if (label.indexOf("Consensus") > -1)
441 // av and sequencegroup need to implement same interface for
442 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
443 MessageManager.getString("label.ignore_gaps_consensus"),
444 (aa[selectedRow].groupRef != null)
445 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
446 : ap.av.isIgnoreGapsConsensus());
447 final AlignmentAnnotation aaa = aa[selectedRow];
448 cbmi.addActionListener(new ActionListener()
451 public void actionPerformed(ActionEvent e)
453 if (aaa.groupRef != null)
455 // TODO: pass on reference to ap so the view can be updated.
456 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
457 ap.getAnnotationPanel()
458 .paint(ap.getAnnotationPanel().getGraphics());
462 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
464 ap.alignmentChanged();
468 // av and sequencegroup need to implement same interface for
469 if (aaa.groupRef != null)
471 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
472 MessageManager.getString("label.show_group_histogram"),
473 aa[selectedRow].groupRef.isShowConsensusHistogram());
474 chist.addActionListener(new ActionListener()
477 public void actionPerformed(ActionEvent e)
479 // TODO: pass on reference
485 aaa.groupRef.setShowConsensusHistogram(chist.getState());
487 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
491 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
492 MessageManager.getString("label.show_group_logo"),
493 aa[selectedRow].groupRef.isShowSequenceLogo());
494 cprofl.addActionListener(new ActionListener()
497 public void actionPerformed(ActionEvent e)
499 // TODO: pass on reference
505 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
507 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
511 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
512 MessageManager.getString("label.normalise_group_logo"),
513 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
514 cproflnorm.addActionListener(new ActionListener()
517 public void actionPerformed(ActionEvent e)
520 // TODO: pass on reference
526 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
527 // automatically enable logo display if we're clicked
528 aaa.groupRef.setshowSequenceLogo(true);
530 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
537 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
538 MessageManager.getString("label.show_histogram"),
539 av.isShowConsensusHistogram());
540 chist.addActionListener(new ActionListener()
543 public void actionPerformed(ActionEvent e)
545 // TODO: pass on reference
551 av.setShowConsensusHistogram(chist.getState());
552 ap.alignFrame.setMenusForViewport();
554 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
558 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
559 MessageManager.getString("label.show_logo"),
560 av.isShowSequenceLogo());
561 cprof.addActionListener(new ActionListener()
564 public void actionPerformed(ActionEvent e)
566 // TODO: pass on reference
572 av.setShowSequenceLogo(cprof.getState());
573 ap.alignFrame.setMenusForViewport();
575 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
579 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
580 MessageManager.getString("label.normalise_logo"),
581 av.isNormaliseSequenceLogo());
582 cprofnorm.addActionListener(new ActionListener()
585 public void actionPerformed(ActionEvent e)
587 // TODO: pass on reference
593 av.setShowSequenceLogo(true);
594 av.setNormaliseSequenceLogo(cprofnorm.getState());
595 ap.alignFrame.setMenusForViewport();
597 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
602 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
603 consclipbrd.addActionListener(this);
604 pop.add(consclipbrd);
607 pop.show(this, evt.getX(), evt.getY());
617 public void mouseReleased(MouseEvent evt)
619 if (evt.isPopupTrigger())
625 int start = selectedRow;
626 getSelectedRow(evt.getY() - getScrollOffset());
627 int end = selectedRow;
631 // Swap these annotations
632 AlignmentAnnotation startAA = ap.av.getAlignment()
633 .getAlignmentAnnotation()[start];
636 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
638 AlignmentAnnotation endAA = ap.av.getAlignment()
639 .getAlignmentAnnotation()[end];
641 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
642 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
648 ap.getAnnotationPanel().repaint();
658 public void mouseEntered(MouseEvent evt)
674 public void mouseExited(MouseEvent evt)
676 if (dragEvent == null)
690 public void mouseDragged(MouseEvent evt)
696 Dimension d = ap.annotationScroller.getPreferredSize();
697 int dif = evt.getY() - oldY;
699 dif /= ap.av.getCharHeight();
700 dif *= ap.av.getCharHeight();
702 if ((d.height - dif) > 20)
704 ap.annotationScroller
705 .setPreferredSize(new Dimension(d.width, d.height - dif));
706 d = ap.annotationSpaceFillerHolder.getPreferredSize();
707 ap.annotationSpaceFillerHolder
708 .setPreferredSize(new Dimension(d.width, d.height - dif));
709 ap.paintAlignment(true, false);
727 public void mouseMoved(MouseEvent evt)
729 resizePanel = evt.getY() < 10;
731 getSelectedRow(evt.getY() - getScrollOffset());
733 if (selectedRow > -1 && ap.av.getAlignment()
734 .getAlignmentAnnotation().length > selectedRow)
736 AlignmentAnnotation aa = ap.av.getAlignment()
737 .getAlignmentAnnotation()[selectedRow];
739 StringBuffer desc = new StringBuffer();
740 if (aa.description != null
741 && !aa.description.equals("New description"))
743 // TODO: we could refactor and merge this code with the code in
744 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
746 desc.append(aa.getDescription(true).trim());
747 // check to see if the description is an html fragment.
748 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
749 .indexOf("<html>") < 0))
751 // clean the description ready for embedding in html
752 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
753 .replaceAll("<"));
754 desc.insert(0, "<html>");
758 // remove terminating html if any
759 int i = desc.substring(desc.length() - 7).toLowerCase()
760 .lastIndexOf("</html>");
763 desc.setLength(desc.length() - 7 + i);
768 desc.append("<br/>");
770 // if (aa.hasProperties())
772 // desc.append("<table>");
773 // for (String prop : aa.getProperties())
775 // desc.append("<tr><td>" + prop + "</td><td>"
776 // + aa.getProperty(prop) + "</td><tr>");
778 // desc.append("</table>");
783 // begin the tooltip's html fragment
784 desc.append("<html>");
787 // TODO: limit precision of score to avoid noise from imprecise
789 // (64.7 becomes 64.7+/some tiny value).
790 desc.append(" Score: " + aa.score);
793 if (desc.length() > 6)
795 desc.append("</html>");
796 this.setToolTipText(desc.toString());
800 this.setToolTipText(null);
806 public void mouseClicked(MouseEvent evt)
808 final AlignmentAnnotation[] aa = ap.av.getAlignment()
809 .getAlignmentAnnotation();
810 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
812 if (selectedRow > -1 && selectedRow < aa.length)
814 if (aa[selectedRow].groupRef != null)
816 if (evt.getClickCount() >= 2)
818 // todo: make the ap scroll to the selection - not necessary, first
819 // click highlights/scrolls, second selects
820 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
822 SequenceGroup sg = ap.av.getSelectionGroup();
823 if (sg == null || sg == aa[selectedRow].groupRef
824 || !(jalview.util.Platform.isControlDown(evt)
825 || evt.isShiftDown()))
827 if (jalview.util.Platform.isControlDown(evt)
828 || evt.isShiftDown())
830 // clone a new selection group from the associated group
831 ap.av.setSelectionGroup(
832 new SequenceGroup(aa[selectedRow].groupRef));
836 // set selection to the associated group so it can be edited
837 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
842 // modify current selection with associated group
843 int remainToAdd = aa[selectedRow].groupRef.getSize();
844 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
846 if (jalview.util.Platform.isControlDown(evt))
848 sg.addOrRemove(sgs, --remainToAdd == 0);
852 // notionally, we should also add intermediate sequences from
853 // last added sequence ?
854 sg.addSequence(sgs, --remainToAdd == 0);
859 ap.paintAlignment(false, false);
860 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
861 ap.av.sendSelection();
865 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
866 aa[selectedRow].groupRef.getSequences(null));
870 else if (aa[selectedRow].sequenceRef != null)
872 if (evt.getClickCount() == 1)
874 ap.getSeqPanel().ap.getIdPanel()
875 .highlightSearchResults(Arrays.asList(new SequenceI[]
876 { aa[selectedRow].sequenceRef }));
878 else if (evt.getClickCount() >= 2)
880 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
881 SequenceGroup sg = ap.av.getSelectionGroup();
884 // we make a copy rather than edit the current selection if no
886 // see Enhancement JAL-1557
887 if (!(jalview.util.Platform.isControlDown(evt)
888 || evt.isShiftDown()))
890 sg = new SequenceGroup(sg);
892 sg.addSequence(aa[selectedRow].sequenceRef, false);
896 if (jalview.util.Platform.isControlDown(evt))
898 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
902 // notionally, we should also add intermediate sequences from
903 // last added sequence ?
904 sg.addSequence(aa[selectedRow].sequenceRef, true);
910 sg = new SequenceGroup();
912 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
913 sg.addSequence(aa[selectedRow].sequenceRef, false);
915 ap.av.setSelectionGroup(sg);
916 ap.paintAlignment(false, false);
917 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
918 ap.av.sendSelection();
928 * do a single sequence copy to jalview and the system clipboard
931 * sequence to be copied to clipboard
933 protected void copy_annotseqtoclipboard(SequenceI sq)
935 SequenceI[] seqs = new SequenceI[] { sq };
936 String[] omitHidden = null;
937 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
938 if (dseqs[0] == null)
940 dseqs[0] = new Sequence(sq);
941 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
942 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
944 sq.setDatasetSequence(dseqs[0]);
946 Alignment ds = new Alignment(dseqs);
947 if (av.hasHiddenColumns())
949 Iterator<int[]> it = av.getAlignment().getHiddenColumns()
950 .getVisContigsIterator(0, sq.getLength(), false);
951 omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
954 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
955 if (av.hasHiddenColumns())
957 alignmentStartEnd = av.getAlignment().getHiddenColumns()
958 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
961 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
962 seqs, omitHidden, alignmentStartEnd);
964 Toolkit.getDefaultToolkit().getSystemClipboard()
965 .setContents(new StringSelection(output), Desktop.instance);
967 HiddenColumns hiddenColumns = null;
969 if (av.hasHiddenColumns())
971 hiddenColumns = new HiddenColumns(
972 av.getAlignment().getHiddenColumns());
975 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
977 // sequence ? need to
979 // sequence as special.
990 public void paintComponent(Graphics g)
993 int width = getWidth();
996 width = ap.calculateIdWidth().width + 4;
999 Graphics2D g2 = (Graphics2D) g;
1002 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1003 RenderingHints.VALUE_ANTIALIAS_ON);
1006 drawComponent(g2, true, width);
1011 * Draw the full set of annotation Labels for the alignment at the given
1015 * Graphics2D instance (needed for font scaling)
1017 * Width for scaling labels
1020 public void drawComponent(Graphics g, int width)
1022 drawComponent(g, false, width);
1025 private final boolean debugRedraw = false;
1028 * Draw the full set of annotation Labels for the alignment at the given
1032 * Graphics2D instance (needed for font scaling)
1034 * - true indicates that only current visible area needs to be
1037 * Width for scaling labels
1039 public void drawComponent(Graphics g, boolean clip, int width)
1041 if (av.getFont().getSize() < 10)
1047 g.setFont(av.getFont());
1050 FontMetrics fm = g.getFontMetrics(g.getFont());
1051 g.setColor(Color.white);
1052 g.fillRect(0, 0, getWidth(), getHeight());
1054 g.translate(0, getScrollOffset());
1055 g.setColor(Color.black);
1057 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1058 int fontHeight = g.getFont().getSize();
1061 int graphExtras = 0;
1063 Font baseFont = g.getFont();
1064 FontMetrics baseMetrics = fm;
1065 int ofontH = fontHeight;
1068 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1069 ? ap.getAnnotationPanel().getVisibleVRange()
1071 if (clip && visr != null)
1074 visHeight = visr[1];
1076 boolean visible = true, before = false, after = false;
1079 hasHiddenRows = false;
1081 for (int i = 0; i < aa.length; i++)
1086 hasHiddenRows = true;
1099 System.out.println("before vis: " + i);
1103 // don't draw what isn't visible
1106 if (olY > visHeight)
1114 "Scroll offset: " + sOffset + " after vis: " + i);
1118 // don't draw what isn't visible
1122 g.setColor(Color.black);
1124 offset = -aa[i].height / 2;
1128 offset += fm.getHeight() / 2;
1129 offset -= fm.getDescent();
1133 offset += fm.getDescent();
1136 x = width - fm.stringWidth(aa[i].label) - 3;
1138 if (aa[i].graphGroup > -1)
1141 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1142 // computed efficiently for all visible labels
1143 for (int gg = 0; gg < aa.length; gg++)
1145 if (aa[gg].graphGroup == aa[i].graphGroup)
1150 if (groupSize * (fontHeight + 8) < aa[i].height)
1152 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1157 // scale font to fit
1158 float h = aa[i].height / (float) groupSize, s;
1165 fontHeight = -8 + (int) h;
1166 s = ((float) fontHeight) / (float) ofontH;
1168 .deriveFont(AffineTransform.getScaleInstance(s, s));
1170 fm = g.getFontMetrics();
1171 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1177 for (int gg = 0; gg < aa.length; gg++)
1179 if (aa[gg].graphGroup == aa[i].graphGroup)
1181 x = width - fm.stringWidth(aa[gg].label) - 3;
1182 g.drawString(aa[gg].label, x, y - graphExtras);
1184 if (aa[gg]._linecolour != null)
1187 g.setColor(aa[gg]._linecolour);
1188 g.drawLine(x, y - graphExtras + 3,
1189 x + fm.stringWidth(aa[gg].label),
1190 y - graphExtras + 3);
1193 g.setColor(Color.black);
1194 graphExtras += fontHeight + 8;
1198 g.setFont(baseFont);
1200 fontHeight = ofontH;
1204 g.drawString(aa[i].label, x, y + offset);
1211 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1213 else if (dragEvent != null && aa != null)
1215 g.setColor(Color.lightGray);
1216 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1217 dragEvent.getY() - getScrollOffset());
1220 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1222 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1223 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1228 public int getScrollOffset()
1230 return scrollOffset;