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]);
248 else if (evt.getActionCommand().equals(SHOWALL))
250 for (int i = 0; i < aa.length; i++)
252 if (!aa[i].visible && aa[i].annotations != null)
254 aa[i].visible = true;
258 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
260 new AnnotationExporter().exportAnnotations(ap,
261 new AlignmentAnnotation[] { aa[selectedRow] });
263 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
265 SequenceI cons = null;
266 if (aa[selectedRow].groupRef != null)
268 cons = aa[selectedRow].groupRef.getConsensusSeq();
272 cons = av.getConsensusSeq();
276 copy_annotseqtoclipboard(cons);
280 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
282 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
292 protected void refresh()
294 ap.validateAnnotationDimensions(false);
305 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())
339 // handle popup menu event
340 final AlignmentAnnotation[] aa = ap.av.getAlignment()
341 .getAlignmentAnnotation();
343 JPopupMenu pop = new JPopupMenu(
344 MessageManager.getString("label.annotations"));
345 JMenuItem item = new JMenuItem(ADDNEW);
346 item.addActionListener(this);
351 { // let the user make everything visible again
352 item = new JMenuItem(SHOWALL);
353 item.addActionListener(this);
356 pop.show(this, evt.getX(), evt.getY());
359 item = new JMenuItem(EDITNAME);
360 item.addActionListener(this);
362 item = new JMenuItem(HIDE);
363 item.addActionListener(this);
365 // JAL-1264 hide all sequence-specific annotations of this type
366 if (selectedRow < aa.length)
368 if (aa[selectedRow].sequenceRef != null)
370 final String label = aa[selectedRow].label;
371 JMenuItem hideType = new JMenuItem();
372 String text = MessageManager.getString("label.hide_all") + " "
374 hideType.setText(text);
375 hideType.addActionListener(new ActionListener()
378 public void actionPerformed(ActionEvent e)
380 AlignmentUtils.showOrHideSequenceAnnotations(
381 ap.av.getAlignment(), Collections.singleton(label),
383 // for (AlignmentAnnotation ann : ap.av.getAlignment()
384 // .getAlignmentAnnotation())
386 // if (ann.sequenceRef != null && ann.label != null
387 // && ann.label.equals(label))
389 // ann.visible = false;
398 item = new JMenuItem(DELETE);
399 item.addActionListener(this);
403 item = new JMenuItem(SHOWALL);
404 item.addActionListener(this);
407 item = new JMenuItem(OUTPUT_TEXT);
408 item.addActionListener(this);
410 // TODO: annotation object should be typed for autocalculated/derived
412 if (selectedRow < aa.length)
414 final String label = aa[selectedRow].label;
415 if (!aa[selectedRow].autoCalculated)
417 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
419 // display formatting settings for this row.
421 // av and sequencegroup need to implement same interface for
422 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
423 aa[selectedRow].scaleColLabel);
424 item.addActionListener(this);
428 else if (label.indexOf("Consensus") > -1)
431 // av and sequencegroup need to implement same interface for
432 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
433 MessageManager.getString("label.ignore_gaps_consensus"),
434 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
435 .getIgnoreGapsConsensus() : ap.av
436 .isIgnoreGapsConsensus());
437 final AlignmentAnnotation aaa = aa[selectedRow];
438 cbmi.addActionListener(new ActionListener()
441 public void actionPerformed(ActionEvent e)
443 if (aaa.groupRef != null)
445 // TODO: pass on reference to ap so the view can be updated.
446 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
447 ap.getAnnotationPanel().paint(
448 ap.getAnnotationPanel().getGraphics());
452 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
457 // av and sequencegroup need to implement same interface for
458 if (aaa.groupRef != null)
460 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
461 MessageManager.getString("label.show_group_histogram"),
462 aa[selectedRow].groupRef.isShowConsensusHistogram());
463 chist.addActionListener(new ActionListener()
466 public void actionPerformed(ActionEvent e)
468 // TODO: pass on reference
474 aaa.groupRef.setShowConsensusHistogram(chist.getState());
476 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
480 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
481 MessageManager.getString("label.show_group_logo"),
482 aa[selectedRow].groupRef.isShowSequenceLogo());
483 cprofl.addActionListener(new ActionListener()
486 public void actionPerformed(ActionEvent e)
488 // TODO: pass on reference
494 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
496 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
500 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
501 MessageManager.getString("label.normalise_group_logo"),
502 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
503 cproflnorm.addActionListener(new ActionListener()
506 public void actionPerformed(ActionEvent e)
509 // TODO: pass on reference
515 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
516 // automatically enable logo display if we're clicked
517 aaa.groupRef.setshowSequenceLogo(true);
519 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
526 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
527 MessageManager.getString("label.show_histogram"),
528 av.isShowConsensusHistogram());
529 chist.addActionListener(new ActionListener()
532 public void actionPerformed(ActionEvent e)
534 // TODO: pass on reference
540 av.setShowConsensusHistogram(chist.getState());
541 ap.alignFrame.setMenusForViewport();
543 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
547 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
548 MessageManager.getString("label.show_logo"),
549 av.isShowSequenceLogo());
550 cprof.addActionListener(new ActionListener()
553 public void actionPerformed(ActionEvent e)
555 // TODO: pass on reference
561 av.setShowSequenceLogo(cprof.getState());
562 ap.alignFrame.setMenusForViewport();
564 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
568 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
569 MessageManager.getString("label.normalise_logo"),
570 av.isNormaliseSequenceLogo());
571 cprofnorm.addActionListener(new ActionListener()
574 public void actionPerformed(ActionEvent e)
576 // TODO: pass on reference
582 av.setShowSequenceLogo(true);
583 av.setNormaliseSequenceLogo(cprofnorm.getState());
584 ap.alignFrame.setMenusForViewport();
586 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
591 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
592 consclipbrd.addActionListener(this);
593 pop.add(consclipbrd);
596 pop.show(this, evt.getX(), evt.getY());
607 public void mouseReleased(MouseEvent evt)
609 int start = selectedRow;
610 getSelectedRow(evt.getY() - getScrollOffset());
611 int end = selectedRow;
615 // Swap these annotations
616 AlignmentAnnotation startAA = ap.av.getAlignment()
617 .getAlignmentAnnotation()[start];
620 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
622 AlignmentAnnotation endAA = ap.av.getAlignment()
623 .getAlignmentAnnotation()[end];
625 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
626 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
632 ap.getAnnotationPanel().repaint();
642 public void mouseEntered(MouseEvent evt)
658 public void mouseExited(MouseEvent evt)
660 if (dragEvent == null)
674 public void mouseDragged(MouseEvent evt)
680 Dimension d = ap.annotationScroller.getPreferredSize();
681 int dif = evt.getY() - oldY;
683 dif /= ap.av.getCharHeight();
684 dif *= ap.av.getCharHeight();
686 if ((d.height - dif) > 20)
688 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
690 d = ap.annotationSpaceFillerHolder.getPreferredSize();
691 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
692 d.width, d.height - dif));
693 ap.paintAlignment(true);
711 public void mouseMoved(MouseEvent evt)
713 resizePanel = evt.getY() < 10;
715 getSelectedRow(evt.getY() - getScrollOffset());
718 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
720 AlignmentAnnotation aa = ap.av.getAlignment()
721 .getAlignmentAnnotation()[selectedRow];
723 StringBuffer desc = new StringBuffer();
724 if (aa.description != null
725 && !aa.description.equals("New description"))
727 // TODO: we could refactor and merge this code with the code in
728 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
730 desc.append(aa.getDescription(true).trim());
731 // check to see if the description is an html fragment.
732 if (desc.length() < 6
733 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
735 // clean the description ready for embedding in html
736 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
737 .replaceAll("<"));
738 desc.insert(0, "<html>");
742 // remove terminating html if any
743 int i = desc.substring(desc.length() - 7).toLowerCase()
744 .lastIndexOf("</html>");
747 desc.setLength(desc.length() - 7 + i);
752 desc.append("<br/>");
754 // if (aa.hasProperties())
756 // desc.append("<table>");
757 // for (String prop : aa.getProperties())
759 // desc.append("<tr><td>" + prop + "</td><td>"
760 // + aa.getProperty(prop) + "</td><tr>");
762 // desc.append("</table>");
767 // begin the tooltip's html fragment
768 desc.append("<html>");
771 // TODO: limit precision of score to avoid noise from imprecise
773 // (64.7 becomes 64.7+/some tiny value).
774 desc.append(" Score: " + aa.score);
777 if (desc.length() > 6)
779 desc.append("</html>");
780 this.setToolTipText(desc.toString());
784 this.setToolTipText(null);
790 public void mouseClicked(MouseEvent evt)
792 final AlignmentAnnotation[] aa = ap.av.getAlignment()
793 .getAlignmentAnnotation();
794 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
796 if (selectedRow > -1 && selectedRow < aa.length)
798 if (aa[selectedRow].groupRef != null)
800 if (evt.getClickCount() >= 2)
802 // todo: make the ap scroll to the selection - not necessary, first
803 // click highlights/scrolls, second selects
804 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
806 SequenceGroup sg = ap.av.getSelectionGroup();
808 || sg == aa[selectedRow].groupRef
809 || !(jalview.util.Platform.isControlDown(evt) || evt
812 if (jalview.util.Platform.isControlDown(evt)
813 || evt.isShiftDown())
815 // clone a new selection group from the associated group
816 ap.av.setSelectionGroup(new SequenceGroup(
817 aa[selectedRow].groupRef));
821 // set selection to the associated group so it can be edited
822 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
827 // modify current selection with associated group
828 int remainToAdd = aa[selectedRow].groupRef.getSize();
829 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
831 if (jalview.util.Platform.isControlDown(evt))
833 sg.addOrRemove(sgs, --remainToAdd == 0);
837 // notionally, we should also add intermediate sequences from
838 // last added sequence ?
839 sg.addSequence(sgs, --remainToAdd == 0);
844 ap.paintAlignment(false);
845 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
846 ap.av.sendSelection();
850 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
851 aa[selectedRow].groupRef.getSequences(null));
855 else if (aa[selectedRow].sequenceRef != null)
857 if (evt.getClickCount() == 1)
861 .highlightSearchResults(
862 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
864 else if (evt.getClickCount() >= 2)
866 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
867 SequenceGroup sg = ap.av.getSelectionGroup();
870 // we make a copy rather than edit the current selection if no
872 // see Enhancement JAL-1557
873 if (!(jalview.util.Platform.isControlDown(evt) || evt
876 sg = new SequenceGroup(sg);
878 sg.addSequence(aa[selectedRow].sequenceRef, false);
882 if (jalview.util.Platform.isControlDown(evt))
884 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
888 // notionally, we should also add intermediate sequences from
889 // last added sequence ?
890 sg.addSequence(aa[selectedRow].sequenceRef, true);
896 sg = new SequenceGroup();
898 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
899 sg.addSequence(aa[selectedRow].sequenceRef, false);
901 ap.av.setSelectionGroup(sg);
902 ap.paintAlignment(false);
903 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
904 ap.av.sendSelection();
914 * do a single sequence copy to jalview and the system clipboard
917 * sequence to be copied to clipboard
919 protected void copy_annotseqtoclipboard(SequenceI sq)
921 SequenceI[] seqs = new SequenceI[] { sq };
922 String[] omitHidden = null;
923 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
924 if (dseqs[0] == null)
926 dseqs[0] = new Sequence(sq);
927 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
928 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
930 sq.setDatasetSequence(dseqs[0]);
932 Alignment ds = new Alignment(dseqs);
933 if (av.hasHiddenColumns())
935 omitHidden = av.getColumnSelection().getVisibleSequenceStrings(0,
936 sq.getLength(), seqs);
939 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
940 List<int[]> hiddenCols = av.getColumnSelection().getHiddenColumns();
941 if (hiddenCols != null)
943 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
946 String output = new FormatAdapter().formatSequences("Fasta", seqs,
947 omitHidden, alignmentStartEnd);
949 Toolkit.getDefaultToolkit().getSystemClipboard()
950 .setContents(new StringSelection(output), Desktop.instance);
952 ArrayList<int[]> hiddenColumns = null;
953 if (av.hasHiddenColumns())
955 hiddenColumns = new ArrayList<int[]>();
956 for (int[] region : av.getColumnSelection().getHiddenColumns())
958 hiddenColumns.add(new int[] { region[0], region[1] });
962 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
964 // sequence ? need to
966 // sequence as special.
977 public void paintComponent(Graphics g)
980 int width = getWidth();
983 width = ap.calculateIdWidth().width + 4;
986 Graphics2D g2 = (Graphics2D) g;
989 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
990 RenderingHints.VALUE_ANTIALIAS_ON);
993 drawComponent(g2, true, width);
998 * Draw the full set of annotation Labels for the alignment at the given
1002 * Graphics2D instance (needed for font scaling)
1004 * Width for scaling labels
1007 public void drawComponent(Graphics g, int width)
1009 drawComponent(g, false, width);
1012 private final boolean debugRedraw = false;
1015 * Draw the full set of annotation Labels for the alignment at the given
1019 * Graphics2D instance (needed for font scaling)
1021 * - true indicates that only current visible area needs to be
1024 * Width for scaling labels
1026 public void drawComponent(Graphics g, boolean clip, int width)
1028 if (av.getFont().getSize() < 10)
1034 g.setFont(av.getFont());
1037 FontMetrics fm = g.getFontMetrics(g.getFont());
1038 g.setColor(Color.white);
1039 g.fillRect(0, 0, getWidth(), getHeight());
1041 g.translate(0, getScrollOffset());
1042 g.setColor(Color.black);
1044 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1045 int fontHeight = g.getFont().getSize();
1048 int graphExtras = 0;
1050 Font baseFont = g.getFont();
1051 FontMetrics baseMetrics = fm;
1052 int ofontH = fontHeight;
1055 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1056 .getAnnotationPanel().getVisibleVRange() : null;
1057 if (clip && visr != null)
1060 visHeight = visr[1];
1062 boolean visible = true, before = false, after = false;
1065 hasHiddenRows = false;
1067 for (int i = 0; i < aa.length; i++)
1072 hasHiddenRows = true;
1085 System.out.println("before vis: " + i);
1089 // don't draw what isn't visible
1092 if (olY > visHeight)
1099 System.out.println("Scroll offset: " + sOffset
1100 + " after vis: " + i);
1104 // don't draw what isn't visible
1108 g.setColor(Color.black);
1110 offset = -aa[i].height / 2;
1114 offset += fm.getHeight() / 2;
1115 offset -= fm.getDescent();
1119 offset += fm.getDescent();
1122 x = width - fm.stringWidth(aa[i].label) - 3;
1124 if (aa[i].graphGroup > -1)
1127 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1128 // computed efficiently for all visible labels
1129 for (int gg = 0; gg < aa.length; gg++)
1131 if (aa[gg].graphGroup == aa[i].graphGroup)
1136 if (groupSize * (fontHeight + 8) < aa[i].height)
1138 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1142 // scale font to fit
1143 float h = aa[i].height / (float) groupSize, s;
1150 fontHeight = -8 + (int) h;
1151 s = ((float) fontHeight) / (float) ofontH;
1152 Font f = baseFont.deriveFont(AffineTransform
1153 .getScaleInstance(s, s));
1155 fm = g.getFontMetrics();
1156 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1161 for (int gg = 0; gg < aa.length; gg++)
1163 if (aa[gg].graphGroup == aa[i].graphGroup)
1165 x = width - fm.stringWidth(aa[gg].label) - 3;
1166 g.drawString(aa[gg].label, x, y - graphExtras);
1168 if (aa[gg]._linecolour != null)
1171 g.setColor(aa[gg]._linecolour);
1172 g.drawLine(x, y - graphExtras + 3,
1173 x + fm.stringWidth(aa[gg].label), y - graphExtras
1177 g.setColor(Color.black);
1178 graphExtras += fontHeight + 8;
1182 g.setFont(baseFont);
1184 fontHeight = ofontH;
1188 g.drawString(aa[i].label, x, y + offset);
1195 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1197 else if (dragEvent != null && aa != null)
1199 g.setColor(Color.lightGray);
1200 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1201 dragEvent.getY() - getScrollOffset());
1204 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1206 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1207 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1212 public int getScrollOffset()
1214 return scrollOffset;