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.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 ap.refresh(fullRepaint);
304 boolean editLabelDescription(AlignmentAnnotation annotation)
307 EditNameDialog dialog = new EditNameDialog(annotation.label,
308 annotation.description, " Annotation Name ",
309 "Annotation Description ", "Edit Annotation Name/Description",
317 annotation.label = dialog.getName();
319 String text = dialog.getDescription();
320 if (text != null && text.length() == 0)
324 annotation.description = text;
330 public void mousePressed(MouseEvent evt)
332 getSelectedRow(evt.getY() - getScrollOffset());
334 if (evt.isPopupTrigger())
341 * Build and show the Pop-up menu at the right-click mouse position
345 void showPopupMenu(MouseEvent evt)
348 final AlignmentAnnotation[] aa = ap.av.getAlignment()
349 .getAlignmentAnnotation();
351 JPopupMenu pop = new JPopupMenu(
352 MessageManager.getString("label.annotations"));
353 JMenuItem item = new JMenuItem(ADDNEW);
354 item.addActionListener(this);
359 { // let the user make everything visible again
360 item = new JMenuItem(SHOWALL);
361 item.addActionListener(this);
364 pop.show(this, evt.getX(), evt.getY());
367 item = new JMenuItem(EDITNAME);
368 item.addActionListener(this);
370 item = new JMenuItem(HIDE);
371 item.addActionListener(this);
373 // JAL-1264 hide all sequence-specific annotations of this type
374 if (selectedRow < aa.length)
376 if (aa[selectedRow].sequenceRef != null)
378 final String label = aa[selectedRow].label;
379 JMenuItem hideType = new JMenuItem();
380 String text = MessageManager.getString("label.hide_all") + " "
382 hideType.setText(text);
383 hideType.addActionListener(new ActionListener()
386 public void actionPerformed(ActionEvent e)
388 AlignmentUtils.showOrHideSequenceAnnotations(
389 ap.av.getAlignment(), Collections.singleton(label),
391 // for (AlignmentAnnotation ann : ap.av.getAlignment()
392 // .getAlignmentAnnotation())
394 // if (ann.sequenceRef != null && ann.label != null
395 // && ann.label.equals(label))
397 // ann.visible = false;
406 item = new JMenuItem(DELETE);
407 item.addActionListener(this);
411 item = new JMenuItem(SHOWALL);
412 item.addActionListener(this);
415 item = new JMenuItem(OUTPUT_TEXT);
416 item.addActionListener(this);
418 // TODO: annotation object should be typed for autocalculated/derived
420 if (selectedRow < aa.length)
422 final String label = aa[selectedRow].label;
423 if (!aa[selectedRow].autoCalculated)
425 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
427 // display formatting settings for this row.
429 // av and sequencegroup need to implement same interface for
430 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
431 aa[selectedRow].scaleColLabel);
432 item.addActionListener(this);
436 else if (label.indexOf("Consensus") > -1)
439 // av and sequencegroup need to implement same interface for
440 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
441 MessageManager.getString("label.ignore_gaps_consensus"),
442 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
443 .getIgnoreGapsConsensus() : ap.av
444 .isIgnoreGapsConsensus());
445 final AlignmentAnnotation aaa = aa[selectedRow];
446 cbmi.addActionListener(new ActionListener()
449 public void actionPerformed(ActionEvent e)
451 if (aaa.groupRef != null)
453 // TODO: pass on reference to ap so the view can be updated.
454 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
455 ap.getAnnotationPanel().paint(
456 ap.getAnnotationPanel().getGraphics());
460 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
462 ap.alignmentChanged();
466 // av and sequencegroup need to implement same interface for
467 if (aaa.groupRef != null)
469 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
470 MessageManager.getString("label.show_group_histogram"),
471 aa[selectedRow].groupRef.isShowConsensusHistogram());
472 chist.addActionListener(new ActionListener()
475 public void actionPerformed(ActionEvent e)
477 // TODO: pass on reference
483 aaa.groupRef.setShowConsensusHistogram(chist.getState());
485 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
489 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
490 MessageManager.getString("label.show_group_logo"),
491 aa[selectedRow].groupRef.isShowSequenceLogo());
492 cprofl.addActionListener(new ActionListener()
495 public void actionPerformed(ActionEvent e)
497 // TODO: pass on reference
503 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
505 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
509 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
510 MessageManager.getString("label.normalise_group_logo"),
511 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
512 cproflnorm.addActionListener(new ActionListener()
515 public void actionPerformed(ActionEvent e)
518 // TODO: pass on reference
524 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
525 // automatically enable logo display if we're clicked
526 aaa.groupRef.setshowSequenceLogo(true);
528 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
535 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
536 MessageManager.getString("label.show_histogram"),
537 av.isShowConsensusHistogram());
538 chist.addActionListener(new ActionListener()
541 public void actionPerformed(ActionEvent e)
543 // TODO: pass on reference
549 av.setShowConsensusHistogram(chist.getState());
550 ap.alignFrame.setMenusForViewport();
552 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
556 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
557 MessageManager.getString("label.show_logo"),
558 av.isShowSequenceLogo());
559 cprof.addActionListener(new ActionListener()
562 public void actionPerformed(ActionEvent e)
564 // TODO: pass on reference
570 av.setShowSequenceLogo(cprof.getState());
571 ap.alignFrame.setMenusForViewport();
573 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
577 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
578 MessageManager.getString("label.normalise_logo"),
579 av.isNormaliseSequenceLogo());
580 cprofnorm.addActionListener(new ActionListener()
583 public void actionPerformed(ActionEvent e)
585 // TODO: pass on reference
591 av.setShowSequenceLogo(true);
592 av.setNormaliseSequenceLogo(cprofnorm.getState());
593 ap.alignFrame.setMenusForViewport();
595 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
600 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
601 consclipbrd.addActionListener(this);
602 pop.add(consclipbrd);
605 pop.show(this, evt.getX(), evt.getY());
615 public void mouseReleased(MouseEvent evt)
617 if (evt.isPopupTrigger())
623 int start = selectedRow;
624 getSelectedRow(evt.getY() - getScrollOffset());
625 int end = selectedRow;
629 // Swap these annotations
630 AlignmentAnnotation startAA = ap.av.getAlignment()
631 .getAlignmentAnnotation()[start];
634 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
636 AlignmentAnnotation endAA = ap.av.getAlignment()
637 .getAlignmentAnnotation()[end];
639 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
640 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
646 ap.getAnnotationPanel().repaint();
656 public void mouseEntered(MouseEvent evt)
672 public void mouseExited(MouseEvent evt)
674 if (dragEvent == null)
688 public void mouseDragged(MouseEvent evt)
694 Dimension d = ap.annotationScroller.getPreferredSize();
695 int dif = evt.getY() - oldY;
697 dif /= ap.av.getCharHeight();
698 dif *= ap.av.getCharHeight();
700 if ((d.height - dif) > 20)
702 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
704 d = ap.annotationSpaceFillerHolder.getPreferredSize();
705 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
706 d.width, d.height - dif));
707 ap.paintAlignment(true);
725 public void mouseMoved(MouseEvent evt)
727 resizePanel = evt.getY() < 10;
729 getSelectedRow(evt.getY() - getScrollOffset());
732 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
734 AlignmentAnnotation aa = ap.av.getAlignment()
735 .getAlignmentAnnotation()[selectedRow];
737 StringBuffer desc = new StringBuffer();
738 if (aa.description != null
739 && !aa.description.equals("New description"))
741 // TODO: we could refactor and merge this code with the code in
742 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
744 desc.append(aa.getDescription(true).trim());
745 // check to see if the description is an html fragment.
746 if (desc.length() < 6
747 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
749 // clean the description ready for embedding in html
750 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
751 .replaceAll("<"));
752 desc.insert(0, "<html>");
756 // remove terminating html if any
757 int i = desc.substring(desc.length() - 7).toLowerCase()
758 .lastIndexOf("</html>");
761 desc.setLength(desc.length() - 7 + i);
766 desc.append("<br/>");
768 // if (aa.hasProperties())
770 // desc.append("<table>");
771 // for (String prop : aa.getProperties())
773 // desc.append("<tr><td>" + prop + "</td><td>"
774 // + aa.getProperty(prop) + "</td><tr>");
776 // desc.append("</table>");
781 // begin the tooltip's html fragment
782 desc.append("<html>");
785 // TODO: limit precision of score to avoid noise from imprecise
787 // (64.7 becomes 64.7+/some tiny value).
788 desc.append(" Score: " + aa.score);
791 if (desc.length() > 6)
793 desc.append("</html>");
794 this.setToolTipText(desc.toString());
798 this.setToolTipText(null);
804 public void mouseClicked(MouseEvent evt)
806 final AlignmentAnnotation[] aa = ap.av.getAlignment()
807 .getAlignmentAnnotation();
808 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
810 if (selectedRow > -1 && selectedRow < aa.length)
812 if (aa[selectedRow].groupRef != null)
814 if (evt.getClickCount() >= 2)
816 // todo: make the ap scroll to the selection - not necessary, first
817 // click highlights/scrolls, second selects
818 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
820 SequenceGroup sg = ap.av.getSelectionGroup();
822 || sg == aa[selectedRow].groupRef
823 || !(jalview.util.Platform.isControlDown(evt) || evt
826 if (jalview.util.Platform.isControlDown(evt)
827 || evt.isShiftDown())
829 // clone a new selection group from the associated group
830 ap.av.setSelectionGroup(new SequenceGroup(
831 aa[selectedRow].groupRef));
835 // set selection to the associated group so it can be edited
836 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
841 // modify current selection with associated group
842 int remainToAdd = aa[selectedRow].groupRef.getSize();
843 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
845 if (jalview.util.Platform.isControlDown(evt))
847 sg.addOrRemove(sgs, --remainToAdd == 0);
851 // notionally, we should also add intermediate sequences from
852 // last added sequence ?
853 sg.addSequence(sgs, --remainToAdd == 0);
858 ap.paintAlignment(false);
859 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
860 ap.av.sendSelection();
864 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
865 aa[selectedRow].groupRef.getSequences(null));
869 else if (aa[selectedRow].sequenceRef != null)
871 if (evt.getClickCount() == 1)
875 .highlightSearchResults(
876 Arrays.asList(new SequenceI[] { 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) || evt
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);
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 omitHidden = av.getAlignment().getHiddenColumns()
950 .getVisibleSequenceStrings(0,
951 sq.getLength(), seqs);
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 ArrayList<int[]> hiddenColumns = null;
969 if (av.hasHiddenColumns())
971 hiddenColumns = av.getAlignment().getHiddenColumns()
972 .getHiddenColumnsCopy();
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) ? ap
1069 .getAnnotationPanel().getVisibleVRange() : null;
1070 if (clip && visr != null)
1073 visHeight = visr[1];
1075 boolean visible = true, before = false, after = false;
1078 hasHiddenRows = false;
1080 for (int i = 0; i < aa.length; i++)
1085 hasHiddenRows = true;
1098 System.out.println("before vis: " + i);
1102 // don't draw what isn't visible
1105 if (olY > visHeight)
1112 System.out.println("Scroll offset: " + sOffset
1113 + " after vis: " + i);
1117 // don't draw what isn't visible
1121 g.setColor(Color.black);
1123 offset = -aa[i].height / 2;
1127 offset += fm.getHeight() / 2;
1128 offset -= fm.getDescent();
1132 offset += fm.getDescent();
1135 x = width - fm.stringWidth(aa[i].label) - 3;
1137 if (aa[i].graphGroup > -1)
1140 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1141 // computed efficiently for all visible labels
1142 for (int gg = 0; gg < aa.length; gg++)
1144 if (aa[gg].graphGroup == aa[i].graphGroup)
1149 if (groupSize * (fontHeight + 8) < aa[i].height)
1151 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1155 // scale font to fit
1156 float h = aa[i].height / (float) groupSize, s;
1163 fontHeight = -8 + (int) h;
1164 s = ((float) fontHeight) / (float) ofontH;
1165 Font f = baseFont.deriveFont(AffineTransform
1166 .getScaleInstance(s, s));
1168 fm = g.getFontMetrics();
1169 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1174 for (int gg = 0; gg < aa.length; gg++)
1176 if (aa[gg].graphGroup == aa[i].graphGroup)
1178 x = width - fm.stringWidth(aa[gg].label) - 3;
1179 g.drawString(aa[gg].label, x, y - graphExtras);
1181 if (aa[gg]._linecolour != null)
1184 g.setColor(aa[gg]._linecolour);
1185 g.drawLine(x, y - graphExtras + 3,
1186 x + fm.stringWidth(aa[gg].label), y - graphExtras
1190 g.setColor(Color.black);
1191 graphExtras += fontHeight + 8;
1195 g.setFont(baseFont);
1197 fontHeight = ofontH;
1201 g.drawString(aa[i].label, x, y + offset);
1208 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1210 else if (dragEvent != null && aa != null)
1212 g.setColor(Color.lightGray);
1213 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1214 dragEvent.getY() - getScrollOffset());
1217 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1219 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1220 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1225 public int getScrollOffset()
1227 return scrollOffset;