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.FileFormat;
31 import jalview.io.FormatAdapter;
32 import jalview.util.MessageManager;
34 import java.awt.Color;
35 import java.awt.Dimension;
37 import java.awt.FontMetrics;
38 import java.awt.Graphics;
39 import java.awt.Graphics2D;
40 import java.awt.Image;
41 import java.awt.MediaTracker;
42 import java.awt.RenderingHints;
43 import java.awt.Toolkit;
44 import java.awt.datatransfer.StringSelection;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseListener;
49 import java.awt.event.MouseMotionListener;
50 import java.awt.geom.AffineTransform;
51 import java.awt.image.BufferedImage;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.Collections;
55 import java.util.List;
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 implements MouseListener,
72 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[] { aa[selectedRow] });
273 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
275 SequenceI cons = null;
276 if (aa[selectedRow].groupRef != null)
278 cons = aa[selectedRow].groupRef.getConsensusSeq();
282 cons = av.getConsensusSeq();
286 copy_annotseqtoclipboard(cons);
290 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
292 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
295 refresh(fullRepaint);
302 * @adjustHeight if true, try to recalculate panel height for visible
305 protected void refresh(boolean adjustHeight)
307 ap.validateAnnotationDimensions(adjustHeight);
311 // sort, repaint, update overview
312 ap.paintAlignment(true);
316 // lightweight repaint
327 boolean editLabelDescription(AlignmentAnnotation annotation)
330 EditNameDialog dialog = new EditNameDialog(annotation.label,
331 annotation.description, " Annotation Name ",
332 "Annotation Description ", "Edit Annotation Name/Description",
340 annotation.label = dialog.getName();
342 String text = dialog.getDescription();
343 if (text != null && text.length() == 0)
347 annotation.description = text;
353 public void mousePressed(MouseEvent evt)
355 getSelectedRow(evt.getY() - getScrollOffset());
357 if (evt.isPopupTrigger())
364 * Build and show the Pop-up menu at the right-click mouse position
368 void showPopupMenu(MouseEvent evt)
371 final AlignmentAnnotation[] aa = ap.av.getAlignment()
372 .getAlignmentAnnotation();
374 JPopupMenu pop = new JPopupMenu(
375 MessageManager.getString("label.annotations"));
376 JMenuItem item = new JMenuItem(ADDNEW);
377 item.addActionListener(this);
382 { // let the user make everything visible again
383 item = new JMenuItem(SHOWALL);
384 item.addActionListener(this);
387 pop.show(this, evt.getX(), evt.getY());
390 item = new JMenuItem(EDITNAME);
391 item.addActionListener(this);
393 item = new JMenuItem(HIDE);
394 item.addActionListener(this);
396 // JAL-1264 hide all sequence-specific annotations of this type
397 if (selectedRow < aa.length)
399 if (aa[selectedRow].sequenceRef != null)
401 final String label = aa[selectedRow].label;
402 JMenuItem hideType = new JMenuItem();
403 String text = MessageManager.getString("label.hide_all") + " "
405 hideType.setText(text);
406 hideType.addActionListener(new ActionListener()
409 public void actionPerformed(ActionEvent e)
411 AlignmentUtils.showOrHideSequenceAnnotations(
412 ap.av.getAlignment(), Collections.singleton(label),
414 // for (AlignmentAnnotation ann : ap.av.getAlignment()
415 // .getAlignmentAnnotation())
417 // if (ann.sequenceRef != null && ann.label != null
418 // && ann.label.equals(label))
420 // ann.visible = false;
429 item = new JMenuItem(DELETE);
430 item.addActionListener(this);
434 item = new JMenuItem(SHOWALL);
435 item.addActionListener(this);
438 item = new JMenuItem(OUTPUT_TEXT);
439 item.addActionListener(this);
441 // TODO: annotation object should be typed for autocalculated/derived
443 if (selectedRow < aa.length)
445 final String label = aa[selectedRow].label;
446 if (!aa[selectedRow].autoCalculated)
448 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
450 // display formatting settings for this row.
452 // av and sequencegroup need to implement same interface for
453 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
454 aa[selectedRow].scaleColLabel);
455 item.addActionListener(this);
459 else if (label.indexOf("Consensus") > -1)
462 // av and sequencegroup need to implement same interface for
463 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
464 MessageManager.getString("label.ignore_gaps_consensus"),
465 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
466 .getIgnoreGapsConsensus() : ap.av
467 .isIgnoreGapsConsensus());
468 final AlignmentAnnotation aaa = aa[selectedRow];
469 cbmi.addActionListener(new ActionListener()
472 public void actionPerformed(ActionEvent e)
474 if (aaa.groupRef != null)
476 // TODO: pass on reference to ap so the view can be updated.
477 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
478 ap.getAnnotationPanel().paint(
479 ap.getAnnotationPanel().getGraphics());
483 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
485 ap.alignmentChanged();
489 // av and sequencegroup need to implement same interface for
490 if (aaa.groupRef != null)
492 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
493 MessageManager.getString("label.show_group_histogram"),
494 aa[selectedRow].groupRef.isShowConsensusHistogram());
495 chist.addActionListener(new ActionListener()
498 public void actionPerformed(ActionEvent e)
500 // TODO: pass on reference
506 aaa.groupRef.setShowConsensusHistogram(chist.getState());
508 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
512 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
513 MessageManager.getString("label.show_group_logo"),
514 aa[selectedRow].groupRef.isShowSequenceLogo());
515 cprofl.addActionListener(new ActionListener()
518 public void actionPerformed(ActionEvent e)
520 // TODO: pass on reference
526 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
528 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
532 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
533 MessageManager.getString("label.normalise_group_logo"),
534 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
535 cproflnorm.addActionListener(new ActionListener()
538 public void actionPerformed(ActionEvent e)
541 // TODO: pass on reference
547 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
548 // automatically enable logo display if we're clicked
549 aaa.groupRef.setshowSequenceLogo(true);
551 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
558 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
559 MessageManager.getString("label.show_histogram"),
560 av.isShowConsensusHistogram());
561 chist.addActionListener(new ActionListener()
564 public void actionPerformed(ActionEvent e)
566 // TODO: pass on reference
572 av.setShowConsensusHistogram(chist.getState());
573 ap.alignFrame.setMenusForViewport();
575 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
579 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
580 MessageManager.getString("label.show_logo"),
581 av.isShowSequenceLogo());
582 cprof.addActionListener(new ActionListener()
585 public void actionPerformed(ActionEvent e)
587 // TODO: pass on reference
593 av.setShowSequenceLogo(cprof.getState());
594 ap.alignFrame.setMenusForViewport();
596 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
600 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
601 MessageManager.getString("label.normalise_logo"),
602 av.isNormaliseSequenceLogo());
603 cprofnorm.addActionListener(new ActionListener()
606 public void actionPerformed(ActionEvent e)
608 // TODO: pass on reference
614 av.setShowSequenceLogo(true);
615 av.setNormaliseSequenceLogo(cprofnorm.getState());
616 ap.alignFrame.setMenusForViewport();
618 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
623 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
624 consclipbrd.addActionListener(this);
625 pop.add(consclipbrd);
628 pop.show(this, evt.getX(), evt.getY());
638 public void mouseReleased(MouseEvent evt)
640 if (evt.isPopupTrigger())
646 int start = selectedRow;
647 getSelectedRow(evt.getY() - getScrollOffset());
648 int end = selectedRow;
652 // Swap these annotations
653 AlignmentAnnotation startAA = ap.av.getAlignment()
654 .getAlignmentAnnotation()[start];
657 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
659 AlignmentAnnotation endAA = ap.av.getAlignment()
660 .getAlignmentAnnotation()[end];
662 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
663 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
669 ap.getAnnotationPanel().repaint();
679 public void mouseEntered(MouseEvent evt)
695 public void mouseExited(MouseEvent evt)
697 if (dragEvent == null)
711 public void mouseDragged(MouseEvent evt)
717 Dimension d = ap.annotationScroller.getPreferredSize();
718 int dif = evt.getY() - oldY;
720 dif /= ap.av.getCharHeight();
721 dif *= ap.av.getCharHeight();
723 if ((d.height - dif) > 20)
725 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
727 d = ap.annotationSpaceFillerHolder.getPreferredSize();
728 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
729 d.width, d.height - dif));
730 ap.paintAlignment(true);
748 public void mouseMoved(MouseEvent evt)
750 resizePanel = evt.getY() < 10;
752 getSelectedRow(evt.getY() - getScrollOffset());
755 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
757 AlignmentAnnotation aa = ap.av.getAlignment()
758 .getAlignmentAnnotation()[selectedRow];
760 StringBuffer desc = new StringBuffer();
761 if (aa.description != null
762 && !aa.description.equals("New description"))
764 // TODO: we could refactor and merge this code with the code in
765 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
767 desc.append(aa.getDescription(true).trim());
768 // check to see if the description is an html fragment.
769 if (desc.length() < 6
770 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
772 // clean the description ready for embedding in html
773 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
774 .replaceAll("<"));
775 desc.insert(0, "<html>");
779 // remove terminating html if any
780 int i = desc.substring(desc.length() - 7).toLowerCase()
781 .lastIndexOf("</html>");
784 desc.setLength(desc.length() - 7 + i);
789 desc.append("<br/>");
791 // if (aa.hasProperties())
793 // desc.append("<table>");
794 // for (String prop : aa.getProperties())
796 // desc.append("<tr><td>" + prop + "</td><td>"
797 // + aa.getProperty(prop) + "</td><tr>");
799 // desc.append("</table>");
804 // begin the tooltip's html fragment
805 desc.append("<html>");
808 // TODO: limit precision of score to avoid noise from imprecise
810 // (64.7 becomes 64.7+/some tiny value).
811 desc.append(" Score: " + aa.score);
814 if (desc.length() > 6)
816 desc.append("</html>");
817 this.setToolTipText(desc.toString());
821 this.setToolTipText(null);
827 public void mouseClicked(MouseEvent evt)
829 final AlignmentAnnotation[] aa = ap.av.getAlignment()
830 .getAlignmentAnnotation();
831 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
833 if (selectedRow > -1 && selectedRow < aa.length)
835 if (aa[selectedRow].groupRef != null)
837 if (evt.getClickCount() >= 2)
839 // todo: make the ap scroll to the selection - not necessary, first
840 // click highlights/scrolls, second selects
841 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
843 SequenceGroup sg = ap.av.getSelectionGroup();
845 || sg == aa[selectedRow].groupRef
846 || !(jalview.util.Platform.isControlDown(evt) || evt
849 if (jalview.util.Platform.isControlDown(evt)
850 || evt.isShiftDown())
852 // clone a new selection group from the associated group
853 ap.av.setSelectionGroup(new SequenceGroup(
854 aa[selectedRow].groupRef));
858 // set selection to the associated group so it can be edited
859 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
864 // modify current selection with associated group
865 int remainToAdd = aa[selectedRow].groupRef.getSize();
866 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
868 if (jalview.util.Platform.isControlDown(evt))
870 sg.addOrRemove(sgs, --remainToAdd == 0);
874 // notionally, we should also add intermediate sequences from
875 // last added sequence ?
876 sg.addSequence(sgs, --remainToAdd == 0);
881 ap.paintAlignment(false);
882 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
883 ap.av.sendSelection();
887 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
888 aa[selectedRow].groupRef.getSequences(null));
892 else if (aa[selectedRow].sequenceRef != null)
894 if (evt.getClickCount() == 1)
898 .highlightSearchResults(
899 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
901 else if (evt.getClickCount() >= 2)
903 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
904 SequenceGroup sg = ap.av.getSelectionGroup();
907 // we make a copy rather than edit the current selection if no
909 // see Enhancement JAL-1557
910 if (!(jalview.util.Platform.isControlDown(evt) || evt
913 sg = new SequenceGroup(sg);
915 sg.addSequence(aa[selectedRow].sequenceRef, false);
919 if (jalview.util.Platform.isControlDown(evt))
921 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
925 // notionally, we should also add intermediate sequences from
926 // last added sequence ?
927 sg.addSequence(aa[selectedRow].sequenceRef, true);
933 sg = new SequenceGroup();
935 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
936 sg.addSequence(aa[selectedRow].sequenceRef, false);
938 ap.av.setSelectionGroup(sg);
939 ap.paintAlignment(false);
940 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
941 ap.av.sendSelection();
951 * do a single sequence copy to jalview and the system clipboard
954 * sequence to be copied to clipboard
956 protected void copy_annotseqtoclipboard(SequenceI sq)
958 SequenceI[] seqs = new SequenceI[] { sq };
959 String[] omitHidden = null;
960 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
961 if (dseqs[0] == null)
963 dseqs[0] = new Sequence(sq);
964 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
965 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
967 sq.setDatasetSequence(dseqs[0]);
969 Alignment ds = new Alignment(dseqs);
970 if (av.hasHiddenColumns())
972 omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0,
973 sq.getLength(), seqs);
976 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
977 List<int[]> hiddenCols = av.getColumnSelection().getHiddenColumns();
978 if (hiddenCols != null)
980 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
983 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
984 seqs, omitHidden, alignmentStartEnd);
986 Toolkit.getDefaultToolkit().getSystemClipboard()
987 .setContents(new StringSelection(output), Desktop.instance);
989 ArrayList<int[]> hiddenColumns = null;
990 if (av.hasHiddenColumns())
992 hiddenColumns = new ArrayList<int[]>();
993 for (int[] region : av.getColumnSelection().getHiddenColumns())
995 hiddenColumns.add(new int[] { region[0], region[1] });
999 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1001 // sequence ? need to
1003 // sequence as special.
1014 public void paintComponent(Graphics g)
1017 int width = getWidth();
1020 width = ap.calculateIdWidth().width + 4;
1023 Graphics2D g2 = (Graphics2D) g;
1026 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1027 RenderingHints.VALUE_ANTIALIAS_ON);
1030 drawComponent(g2, true, width);
1035 * Draw the full set of annotation Labels for the alignment at the given
1039 * Graphics2D instance (needed for font scaling)
1041 * Width for scaling labels
1044 public void drawComponent(Graphics g, int width)
1046 drawComponent(g, false, width);
1049 private final boolean debugRedraw = false;
1052 * Draw the full set of annotation Labels for the alignment at the given
1056 * Graphics2D instance (needed for font scaling)
1058 * - true indicates that only current visible area needs to be
1061 * Width for scaling labels
1063 public void drawComponent(Graphics g, boolean clip, int width)
1065 if (av.getFont().getSize() < 10)
1071 g.setFont(av.getFont());
1074 FontMetrics fm = g.getFontMetrics(g.getFont());
1075 g.setColor(Color.white);
1076 g.fillRect(0, 0, getWidth(), getHeight());
1078 g.translate(0, getScrollOffset());
1079 g.setColor(Color.black);
1081 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1082 int fontHeight = g.getFont().getSize();
1085 int graphExtras = 0;
1087 Font baseFont = g.getFont();
1088 FontMetrics baseMetrics = fm;
1089 int ofontH = fontHeight;
1092 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1093 .getAnnotationPanel().getVisibleVRange() : null;
1094 if (clip && visr != null)
1097 visHeight = visr[1];
1099 boolean visible = true, before = false, after = false;
1102 hasHiddenRows = false;
1104 for (int i = 0; i < aa.length; i++)
1109 hasHiddenRows = true;
1122 System.out.println("before vis: " + i);
1126 // don't draw what isn't visible
1129 if (olY > visHeight)
1136 System.out.println("Scroll offset: " + sOffset
1137 + " after vis: " + i);
1141 // don't draw what isn't visible
1145 g.setColor(Color.black);
1147 offset = -aa[i].height / 2;
1151 offset += fm.getHeight() / 2;
1152 offset -= fm.getDescent();
1156 offset += fm.getDescent();
1159 x = width - fm.stringWidth(aa[i].label) - 3;
1161 if (aa[i].graphGroup > -1)
1164 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1165 // computed efficiently for all visible labels
1166 for (int gg = 0; gg < aa.length; gg++)
1168 if (aa[gg].graphGroup == aa[i].graphGroup)
1173 if (groupSize * (fontHeight + 8) < aa[i].height)
1175 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1179 // scale font to fit
1180 float h = aa[i].height / (float) groupSize, s;
1187 fontHeight = -8 + (int) h;
1188 s = ((float) fontHeight) / (float) ofontH;
1189 Font f = baseFont.deriveFont(AffineTransform
1190 .getScaleInstance(s, s));
1192 fm = g.getFontMetrics();
1193 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1198 for (int gg = 0; gg < aa.length; gg++)
1200 if (aa[gg].graphGroup == aa[i].graphGroup)
1202 x = width - fm.stringWidth(aa[gg].label) - 3;
1203 g.drawString(aa[gg].label, x, y - graphExtras);
1205 if (aa[gg]._linecolour != null)
1208 g.setColor(aa[gg]._linecolour);
1209 g.drawLine(x, y - graphExtras + 3,
1210 x + fm.stringWidth(aa[gg].label), y - graphExtras
1214 g.setColor(Color.black);
1215 graphExtras += fontHeight + 8;
1219 g.setFont(baseFont);
1221 fontHeight = ofontH;
1225 g.drawString(aa[i].label, x, y + offset);
1232 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1234 else if (dragEvent != null && aa != null)
1236 g.setColor(Color.lightGray);
1237 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1238 dragEvent.getY() - getScrollOffset());
1241 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1243 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1244 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1249 public int getScrollOffset()
1251 return scrollOffset;