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 if (evt.getActionCommand().equals(ADDNEW))
224 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
225 null, new Annotation[ap.av.getAlignment().getWidth()]);
227 if (!editLabelDescription(newAnnotation))
232 ap.av.getAlignment().addAnnotation(newAnnotation);
233 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
235 else if (evt.getActionCommand().equals(EDITNAME))
237 editLabelDescription(aa[selectedRow]);
240 else if (evt.getActionCommand().equals(HIDE))
242 aa[selectedRow].visible = false;
244 else if (evt.getActionCommand().equals(DELETE))
246 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
247 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
249 else if (evt.getActionCommand().equals(SHOWALL))
251 for (int i = 0; i < aa.length; i++)
253 if (!aa[i].visible && aa[i].annotations != null)
255 aa[i].visible = true;
259 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
261 new AnnotationExporter().exportAnnotations(ap,
262 new AlignmentAnnotation[] { aa[selectedRow] });
264 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
266 SequenceI cons = null;
267 if (aa[selectedRow].groupRef != null)
269 cons = aa[selectedRow].groupRef.getConsensusSeq();
273 cons = av.getConsensusSeq();
277 copy_annotseqtoclipboard(cons);
281 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
283 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
293 protected void refresh()
295 ap.validateAnnotationDimensions(false);
306 boolean editLabelDescription(AlignmentAnnotation annotation)
308 EditNameDialog dialog = new EditNameDialog(annotation.label,
309 annotation.description, " Annotation Name ",
310 "Annotation Description ", "Edit Annotation Name/Description",
318 annotation.label = dialog.getName();
320 String text = dialog.getDescription();
321 if (text != null && text.length() == 0)
325 annotation.description = text;
331 public void mousePressed(MouseEvent evt)
333 getSelectedRow(evt.getY() - getScrollOffset());
335 if (!evt.isPopupTrigger())
340 // handle popup menu event
341 final AlignmentAnnotation[] aa = ap.av.getAlignment()
342 .getAlignmentAnnotation();
344 JPopupMenu pop = new JPopupMenu(
345 MessageManager.getString("label.annotations"));
346 JMenuItem item = new JMenuItem(ADDNEW);
347 item.addActionListener(this);
352 { // let the user make everything visible again
353 item = new JMenuItem(SHOWALL);
354 item.addActionListener(this);
357 pop.show(this, evt.getX(), evt.getY());
360 item = new JMenuItem(EDITNAME);
361 item.addActionListener(this);
363 item = new JMenuItem(HIDE);
364 item.addActionListener(this);
366 // JAL-1264 hide all sequence-specific annotations of this type
367 if (selectedRow < aa.length)
369 if (aa[selectedRow].sequenceRef != null)
371 final String label = aa[selectedRow].label;
372 JMenuItem hideType = new JMenuItem();
373 String text = MessageManager.getString("label.hide_all") + " "
375 hideType.setText(text);
376 hideType.addActionListener(new ActionListener()
379 public void actionPerformed(ActionEvent e)
381 AlignmentUtils.showOrHideSequenceAnnotations(
382 ap.av.getAlignment(), Collections.singleton(label),
384 // for (AlignmentAnnotation ann : ap.av.getAlignment()
385 // .getAlignmentAnnotation())
387 // if (ann.sequenceRef != null && ann.label != null
388 // && ann.label.equals(label))
390 // ann.visible = false;
399 item = new JMenuItem(DELETE);
400 item.addActionListener(this);
404 item = new JMenuItem(SHOWALL);
405 item.addActionListener(this);
408 item = new JMenuItem(OUTPUT_TEXT);
409 item.addActionListener(this);
411 // TODO: annotation object should be typed for autocalculated/derived
413 if (selectedRow < aa.length)
415 final String label = aa[selectedRow].label;
416 if (!aa[selectedRow].autoCalculated)
418 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
420 // display formatting settings for this row.
422 // av and sequencegroup need to implement same interface for
423 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
424 aa[selectedRow].scaleColLabel);
425 item.addActionListener(this);
429 else if (label.indexOf("Consensus") > -1)
432 // av and sequencegroup need to implement same interface for
433 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
434 MessageManager.getString("label.ignore_gaps_consensus"),
435 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
436 .getIgnoreGapsConsensus() : ap.av
437 .isIgnoreGapsConsensus());
438 final AlignmentAnnotation aaa = aa[selectedRow];
439 cbmi.addActionListener(new ActionListener()
442 public void actionPerformed(ActionEvent e)
444 if (aaa.groupRef != null)
446 // TODO: pass on reference to ap so the view can be updated.
447 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
448 ap.getAnnotationPanel().paint(
449 ap.getAnnotationPanel().getGraphics());
453 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
458 // av and sequencegroup need to implement same interface for
459 if (aaa.groupRef != null)
461 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
462 MessageManager.getString("label.show_group_histogram"),
463 aa[selectedRow].groupRef.isShowConsensusHistogram());
464 chist.addActionListener(new ActionListener()
467 public void actionPerformed(ActionEvent e)
469 // TODO: pass on reference
475 aaa.groupRef.setShowConsensusHistogram(chist.getState());
477 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
481 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
482 MessageManager.getString("label.show_group_logo"),
483 aa[selectedRow].groupRef.isShowSequenceLogo());
484 cprofl.addActionListener(new ActionListener()
487 public void actionPerformed(ActionEvent e)
489 // TODO: pass on reference
495 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
497 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
501 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
502 MessageManager.getString("label.normalise_group_logo"),
503 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
504 cproflnorm.addActionListener(new ActionListener()
507 public void actionPerformed(ActionEvent e)
510 // TODO: pass on reference
516 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
517 // automatically enable logo display if we're clicked
518 aaa.groupRef.setshowSequenceLogo(true);
520 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
527 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
528 MessageManager.getString("label.show_histogram"),
529 av.isShowConsensusHistogram());
530 chist.addActionListener(new ActionListener()
533 public void actionPerformed(ActionEvent e)
535 // TODO: pass on reference
541 av.setShowConsensusHistogram(chist.getState());
542 ap.alignFrame.setMenusForViewport();
544 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
548 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
549 MessageManager.getString("label.show_logo"),
550 av.isShowSequenceLogo());
551 cprof.addActionListener(new ActionListener()
554 public void actionPerformed(ActionEvent e)
556 // TODO: pass on reference
562 av.setShowSequenceLogo(cprof.getState());
563 ap.alignFrame.setMenusForViewport();
565 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
569 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
570 MessageManager.getString("label.normalise_logo"),
571 av.isNormaliseSequenceLogo());
572 cprofnorm.addActionListener(new ActionListener()
575 public void actionPerformed(ActionEvent e)
577 // TODO: pass on reference
583 av.setShowSequenceLogo(true);
584 av.setNormaliseSequenceLogo(cprofnorm.getState());
585 ap.alignFrame.setMenusForViewport();
587 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
592 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
593 consclipbrd.addActionListener(this);
594 pop.add(consclipbrd);
597 pop.show(this, evt.getX(), evt.getY());
608 public void mouseReleased(MouseEvent evt)
610 int start = selectedRow;
611 getSelectedRow(evt.getY() - getScrollOffset());
612 int end = selectedRow;
616 // Swap these annotations
617 AlignmentAnnotation startAA = ap.av.getAlignment()
618 .getAlignmentAnnotation()[start];
621 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
623 AlignmentAnnotation endAA = ap.av.getAlignment()
624 .getAlignmentAnnotation()[end];
626 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
627 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
633 ap.getAnnotationPanel().repaint();
643 public void mouseEntered(MouseEvent evt)
659 public void mouseExited(MouseEvent evt)
661 if (dragEvent == null)
675 public void mouseDragged(MouseEvent evt)
681 Dimension d = ap.annotationScroller.getPreferredSize();
682 int dif = evt.getY() - oldY;
684 dif /= ap.av.getCharHeight();
685 dif *= ap.av.getCharHeight();
687 if ((d.height - dif) > 20)
689 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
691 d = ap.annotationSpaceFillerHolder.getPreferredSize();
692 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
693 d.width, d.height - dif));
694 ap.paintAlignment(true);
712 public void mouseMoved(MouseEvent evt)
714 resizePanel = evt.getY() < 10;
716 getSelectedRow(evt.getY() - getScrollOffset());
719 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
721 AlignmentAnnotation aa = ap.av.getAlignment()
722 .getAlignmentAnnotation()[selectedRow];
724 StringBuffer desc = new StringBuffer();
725 if (aa.description != null
726 && !aa.description.equals("New description"))
728 // TODO: we could refactor and merge this code with the code in
729 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
731 desc.append(aa.getDescription(true).trim());
732 // check to see if the description is an html fragment.
733 if (desc.length() < 6
734 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
736 // clean the description ready for embedding in html
737 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
738 .replaceAll("<"));
739 desc.insert(0, "<html>");
743 // remove terminating html if any
744 int i = desc.substring(desc.length() - 7).toLowerCase()
745 .lastIndexOf("</html>");
748 desc.setLength(desc.length() - 7 + i);
753 desc.append("<br/>");
755 // if (aa.hasProperties())
757 // desc.append("<table>");
758 // for (String prop : aa.getProperties())
760 // desc.append("<tr><td>" + prop + "</td><td>"
761 // + aa.getProperty(prop) + "</td><tr>");
763 // desc.append("</table>");
768 // begin the tooltip's html fragment
769 desc.append("<html>");
772 // TODO: limit precision of score to avoid noise from imprecise
774 // (64.7 becomes 64.7+/some tiny value).
775 desc.append(" Score: " + aa.score);
778 if (desc.length() > 6)
780 desc.append("</html>");
781 this.setToolTipText(desc.toString());
785 this.setToolTipText(null);
791 public void mouseClicked(MouseEvent evt)
793 final AlignmentAnnotation[] aa = ap.av.getAlignment()
794 .getAlignmentAnnotation();
795 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
797 if (selectedRow > -1 && selectedRow < aa.length)
799 if (aa[selectedRow].groupRef != null)
801 if (evt.getClickCount() >= 2)
803 // todo: make the ap scroll to the selection - not necessary, first
804 // click highlights/scrolls, second selects
805 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
807 SequenceGroup sg = ap.av.getSelectionGroup();
809 || sg == aa[selectedRow].groupRef
810 || !(jalview.util.Platform.isControlDown(evt) || evt
813 if (jalview.util.Platform.isControlDown(evt)
814 || evt.isShiftDown())
816 // clone a new selection group from the associated group
817 ap.av.setSelectionGroup(new SequenceGroup(
818 aa[selectedRow].groupRef));
822 // set selection to the associated group so it can be edited
823 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
828 // modify current selection with associated group
829 int remainToAdd = aa[selectedRow].groupRef.getSize();
830 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
832 if (jalview.util.Platform.isControlDown(evt))
834 sg.addOrRemove(sgs, --remainToAdd == 0);
838 // notionally, we should also add intermediate sequences from
839 // last added sequence ?
840 sg.addSequence(sgs, --remainToAdd == 0);
845 ap.paintAlignment(false);
846 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
847 ap.av.sendSelection();
851 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
852 aa[selectedRow].groupRef.getSequences(null));
856 else if (aa[selectedRow].sequenceRef != null)
858 if (evt.getClickCount() == 1)
862 .highlightSearchResults(
863 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
865 else if (evt.getClickCount() >= 2)
867 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
868 SequenceGroup sg = ap.av.getSelectionGroup();
871 // we make a copy rather than edit the current selection if no
873 // see Enhancement JAL-1557
874 if (!(jalview.util.Platform.isControlDown(evt) || evt
877 sg = new SequenceGroup(sg);
879 sg.addSequence(aa[selectedRow].sequenceRef, false);
883 if (jalview.util.Platform.isControlDown(evt))
885 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
889 // notionally, we should also add intermediate sequences from
890 // last added sequence ?
891 sg.addSequence(aa[selectedRow].sequenceRef, true);
897 sg = new SequenceGroup();
899 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
900 sg.addSequence(aa[selectedRow].sequenceRef, false);
902 ap.av.setSelectionGroup(sg);
903 ap.paintAlignment(false);
904 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
905 ap.av.sendSelection();
915 * do a single sequence copy to jalview and the system clipboard
918 * sequence to be copied to clipboard
920 protected void copy_annotseqtoclipboard(SequenceI sq)
922 SequenceI[] seqs = new SequenceI[] { sq };
923 String[] omitHidden = null;
924 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
925 if (dseqs[0] == null)
927 dseqs[0] = new Sequence(sq);
928 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
929 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
931 sq.setDatasetSequence(dseqs[0]);
933 Alignment ds = new Alignment(dseqs);
934 if (av.hasHiddenColumns())
936 omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0,
937 sq.getLength(), seqs);
940 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
941 List<int[]> hiddenCols = av.getColumnSelection().getHiddenColumns();
942 if (hiddenCols != null)
944 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
947 String output = new FormatAdapter().formatSequences("Fasta", seqs,
948 omitHidden, alignmentStartEnd);
950 Toolkit.getDefaultToolkit().getSystemClipboard()
951 .setContents(new StringSelection(output), Desktop.instance);
953 ArrayList<int[]> hiddenColumns = null;
954 if (av.hasHiddenColumns())
956 hiddenColumns = new ArrayList<int[]>();
957 for (int[] region : av.getColumnSelection().getHiddenColumns())
959 hiddenColumns.add(new int[] { region[0], region[1] });
963 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
965 // sequence ? need to
967 // sequence as special.
978 public void paintComponent(Graphics g)
981 int width = getWidth();
984 width = ap.calculateIdWidth().width + 4;
987 Graphics2D g2 = (Graphics2D) g;
990 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
991 RenderingHints.VALUE_ANTIALIAS_ON);
994 drawComponent(g2, true, width);
999 * Draw the full set of annotation Labels for the alignment at the given
1003 * Graphics2D instance (needed for font scaling)
1005 * Width for scaling labels
1008 public void drawComponent(Graphics g, int width)
1010 drawComponent(g, false, width);
1013 private final boolean debugRedraw = false;
1016 * Draw the full set of annotation Labels for the alignment at the given
1020 * Graphics2D instance (needed for font scaling)
1022 * - true indicates that only current visible area needs to be
1025 * Width for scaling labels
1027 public void drawComponent(Graphics g, boolean clip, int width)
1029 if (av.getFont().getSize() < 10)
1035 g.setFont(av.getFont());
1038 FontMetrics fm = g.getFontMetrics(g.getFont());
1039 g.setColor(Color.white);
1040 g.fillRect(0, 0, getWidth(), getHeight());
1042 g.translate(0, getScrollOffset());
1043 g.setColor(Color.black);
1045 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1046 int fontHeight = g.getFont().getSize();
1049 int graphExtras = 0;
1051 Font baseFont = g.getFont();
1052 FontMetrics baseMetrics = fm;
1053 int ofontH = fontHeight;
1056 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1057 .getAnnotationPanel().getVisibleVRange() : null;
1058 if (clip && visr != null)
1061 visHeight = visr[1];
1063 boolean visible = true, before = false, after = false;
1066 hasHiddenRows = false;
1068 for (int i = 0; i < aa.length; i++)
1073 hasHiddenRows = true;
1086 System.out.println("before vis: " + i);
1090 // don't draw what isn't visible
1093 if (olY > visHeight)
1100 System.out.println("Scroll offset: " + sOffset
1101 + " after vis: " + i);
1105 // don't draw what isn't visible
1109 g.setColor(Color.black);
1111 offset = -aa[i].height / 2;
1115 offset += fm.getHeight() / 2;
1116 offset -= fm.getDescent();
1120 offset += fm.getDescent();
1123 x = width - fm.stringWidth(aa[i].label) - 3;
1125 if (aa[i].graphGroup > -1)
1128 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1129 // computed efficiently for all visible labels
1130 for (int gg = 0; gg < aa.length; gg++)
1132 if (aa[gg].graphGroup == aa[i].graphGroup)
1137 if (groupSize * (fontHeight + 8) < aa[i].height)
1139 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1143 // scale font to fit
1144 float h = aa[i].height / (float) groupSize, s;
1151 fontHeight = -8 + (int) h;
1152 s = ((float) fontHeight) / (float) ofontH;
1153 Font f = baseFont.deriveFont(AffineTransform
1154 .getScaleInstance(s, s));
1156 fm = g.getFontMetrics();
1157 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1162 for (int gg = 0; gg < aa.length; gg++)
1164 if (aa[gg].graphGroup == aa[i].graphGroup)
1166 x = width - fm.stringWidth(aa[gg].label) - 3;
1167 g.drawString(aa[gg].label, x, y - graphExtras);
1169 if (aa[gg]._linecolour != null)
1172 g.setColor(aa[gg]._linecolour);
1173 g.drawLine(x, y - graphExtras + 3,
1174 x + fm.stringWidth(aa[gg].label), y - graphExtras
1178 g.setColor(Color.black);
1179 graphExtras += fontHeight + 8;
1183 g.setFont(baseFont);
1185 fontHeight = ofontH;
1189 g.drawString(aa[i].label, x, y + offset);
1196 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1198 else if (dragEvent != null && aa != null)
1200 g.setColor(Color.lightGray);
1201 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1202 dragEvent.getY() - getScrollOffset());
1205 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1207 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1208 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1213 public int getScrollOffset()
1215 return scrollOffset;