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 ap.refresh(fullRepaint);
305 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())
342 * Build and show the Pop-up menu at the right-click mouse position
346 void showPopupMenu(MouseEvent evt)
349 final AlignmentAnnotation[] aa = ap.av.getAlignment()
350 .getAlignmentAnnotation();
352 JPopupMenu pop = new JPopupMenu(
353 MessageManager.getString("label.annotations"));
354 JMenuItem item = new JMenuItem(ADDNEW);
355 item.addActionListener(this);
360 { // let the user make everything visible again
361 item = new JMenuItem(SHOWALL);
362 item.addActionListener(this);
365 pop.show(this, evt.getX(), evt.getY());
368 item = new JMenuItem(EDITNAME);
369 item.addActionListener(this);
371 item = new JMenuItem(HIDE);
372 item.addActionListener(this);
374 // JAL-1264 hide all sequence-specific annotations of this type
375 if (selectedRow < aa.length)
377 if (aa[selectedRow].sequenceRef != null)
379 final String label = aa[selectedRow].label;
380 JMenuItem hideType = new JMenuItem();
381 String text = MessageManager.getString("label.hide_all") + " "
383 hideType.setText(text);
384 hideType.addActionListener(new ActionListener()
387 public void actionPerformed(ActionEvent e)
389 AlignmentUtils.showOrHideSequenceAnnotations(
390 ap.av.getAlignment(), Collections.singleton(label),
392 // for (AlignmentAnnotation ann : ap.av.getAlignment()
393 // .getAlignmentAnnotation())
395 // if (ann.sequenceRef != null && ann.label != null
396 // && ann.label.equals(label))
398 // ann.visible = false;
407 item = new JMenuItem(DELETE);
408 item.addActionListener(this);
412 item = new JMenuItem(SHOWALL);
413 item.addActionListener(this);
416 item = new JMenuItem(OUTPUT_TEXT);
417 item.addActionListener(this);
419 // TODO: annotation object should be typed for autocalculated/derived
421 if (selectedRow < aa.length)
423 final String label = aa[selectedRow].label;
424 if (!aa[selectedRow].autoCalculated)
426 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
428 // display formatting settings for this row.
430 // av and sequencegroup need to implement same interface for
431 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
432 aa[selectedRow].scaleColLabel);
433 item.addActionListener(this);
437 else if (label.indexOf("Consensus") > -1)
440 // av and sequencegroup need to implement same interface for
441 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
442 MessageManager.getString("label.ignore_gaps_consensus"),
443 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
444 .getIgnoreGapsConsensus() : ap.av
445 .isIgnoreGapsConsensus());
446 final AlignmentAnnotation aaa = aa[selectedRow];
447 cbmi.addActionListener(new ActionListener()
450 public void actionPerformed(ActionEvent e)
452 if (aaa.groupRef != null)
454 // TODO: pass on reference to ap so the view can be updated.
455 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
456 ap.getAnnotationPanel().paint(
457 ap.getAnnotationPanel().getGraphics());
461 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
463 ap.alignmentChanged();
467 // av and sequencegroup need to implement same interface for
468 if (aaa.groupRef != null)
470 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
471 MessageManager.getString("label.show_group_histogram"),
472 aa[selectedRow].groupRef.isShowConsensusHistogram());
473 chist.addActionListener(new ActionListener()
476 public void actionPerformed(ActionEvent e)
478 // TODO: pass on reference
484 aaa.groupRef.setShowConsensusHistogram(chist.getState());
486 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
490 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
491 MessageManager.getString("label.show_group_logo"),
492 aa[selectedRow].groupRef.isShowSequenceLogo());
493 cprofl.addActionListener(new ActionListener()
496 public void actionPerformed(ActionEvent e)
498 // TODO: pass on reference
504 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
506 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
510 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
511 MessageManager.getString("label.normalise_group_logo"),
512 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
513 cproflnorm.addActionListener(new ActionListener()
516 public void actionPerformed(ActionEvent e)
519 // TODO: pass on reference
525 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
526 // automatically enable logo display if we're clicked
527 aaa.groupRef.setshowSequenceLogo(true);
529 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
536 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
537 MessageManager.getString("label.show_histogram"),
538 av.isShowConsensusHistogram());
539 chist.addActionListener(new ActionListener()
542 public void actionPerformed(ActionEvent e)
544 // TODO: pass on reference
550 av.setShowConsensusHistogram(chist.getState());
551 ap.alignFrame.setMenusForViewport();
553 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
557 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
558 MessageManager.getString("label.show_logo"),
559 av.isShowSequenceLogo());
560 cprof.addActionListener(new ActionListener()
563 public void actionPerformed(ActionEvent e)
565 // TODO: pass on reference
571 av.setShowSequenceLogo(cprof.getState());
572 ap.alignFrame.setMenusForViewport();
574 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
578 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
579 MessageManager.getString("label.normalise_logo"),
580 av.isNormaliseSequenceLogo());
581 cprofnorm.addActionListener(new ActionListener()
584 public void actionPerformed(ActionEvent e)
586 // TODO: pass on reference
592 av.setShowSequenceLogo(true);
593 av.setNormaliseSequenceLogo(cprofnorm.getState());
594 ap.alignFrame.setMenusForViewport();
596 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
601 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
602 consclipbrd.addActionListener(this);
603 pop.add(consclipbrd);
606 pop.show(this, evt.getX(), evt.getY());
616 public void mouseReleased(MouseEvent evt)
618 if (evt.isPopupTrigger())
624 int start = selectedRow;
625 getSelectedRow(evt.getY() - getScrollOffset());
626 int end = selectedRow;
630 // Swap these annotations
631 AlignmentAnnotation startAA = ap.av.getAlignment()
632 .getAlignmentAnnotation()[start];
635 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
637 AlignmentAnnotation endAA = ap.av.getAlignment()
638 .getAlignmentAnnotation()[end];
640 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
641 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
647 ap.getAnnotationPanel().repaint();
657 public void mouseEntered(MouseEvent evt)
673 public void mouseExited(MouseEvent evt)
675 if (dragEvent == null)
689 public void mouseDragged(MouseEvent evt)
695 Dimension d = ap.annotationScroller.getPreferredSize();
696 int dif = evt.getY() - oldY;
698 dif /= ap.av.getCharHeight();
699 dif *= ap.av.getCharHeight();
701 if ((d.height - dif) > 20)
703 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
705 d = ap.annotationSpaceFillerHolder.getPreferredSize();
706 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
707 d.width, d.height - dif));
708 ap.paintAlignment(true);
726 public void mouseMoved(MouseEvent evt)
728 resizePanel = evt.getY() < 10;
730 getSelectedRow(evt.getY() - getScrollOffset());
733 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
735 AlignmentAnnotation aa = ap.av.getAlignment()
736 .getAlignmentAnnotation()[selectedRow];
738 StringBuffer desc = new StringBuffer();
739 if (aa.description != null
740 && !aa.description.equals("New description"))
742 // TODO: we could refactor and merge this code with the code in
743 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
745 desc.append(aa.getDescription(true).trim());
746 // check to see if the description is an html fragment.
747 if (desc.length() < 6
748 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
750 // clean the description ready for embedding in html
751 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
752 .replaceAll("<"));
753 desc.insert(0, "<html>");
757 // remove terminating html if any
758 int i = desc.substring(desc.length() - 7).toLowerCase()
759 .lastIndexOf("</html>");
762 desc.setLength(desc.length() - 7 + i);
767 desc.append("<br/>");
769 // if (aa.hasProperties())
771 // desc.append("<table>");
772 // for (String prop : aa.getProperties())
774 // desc.append("<tr><td>" + prop + "</td><td>"
775 // + aa.getProperty(prop) + "</td><tr>");
777 // desc.append("</table>");
782 // begin the tooltip's html fragment
783 desc.append("<html>");
786 // TODO: limit precision of score to avoid noise from imprecise
788 // (64.7 becomes 64.7+/some tiny value).
789 desc.append(" Score: " + aa.score);
792 if (desc.length() > 6)
794 desc.append("</html>");
795 this.setToolTipText(desc.toString());
799 this.setToolTipText(null);
805 public void mouseClicked(MouseEvent evt)
807 final AlignmentAnnotation[] aa = ap.av.getAlignment()
808 .getAlignmentAnnotation();
809 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
811 if (selectedRow > -1 && selectedRow < aa.length)
813 if (aa[selectedRow].groupRef != null)
815 if (evt.getClickCount() >= 2)
817 // todo: make the ap scroll to the selection - not necessary, first
818 // click highlights/scrolls, second selects
819 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
821 SequenceGroup sg = ap.av.getSelectionGroup();
823 || sg == aa[selectedRow].groupRef
824 || !(jalview.util.Platform.isControlDown(evt) || evt
827 if (jalview.util.Platform.isControlDown(evt)
828 || evt.isShiftDown())
830 // clone a new selection group from the associated group
831 ap.av.setSelectionGroup(new SequenceGroup(
832 aa[selectedRow].groupRef));
836 // set selection to the associated group so it can be edited
837 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
842 // modify current selection with associated group
843 int remainToAdd = aa[selectedRow].groupRef.getSize();
844 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
846 if (jalview.util.Platform.isControlDown(evt))
848 sg.addOrRemove(sgs, --remainToAdd == 0);
852 // notionally, we should also add intermediate sequences from
853 // last added sequence ?
854 sg.addSequence(sgs, --remainToAdd == 0);
859 ap.paintAlignment(false);
860 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
861 ap.av.sendSelection();
865 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
866 aa[selectedRow].groupRef.getSequences(null));
870 else if (aa[selectedRow].sequenceRef != null)
872 if (evt.getClickCount() == 1)
876 .highlightSearchResults(
877 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
879 else if (evt.getClickCount() >= 2)
881 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
882 SequenceGroup sg = ap.av.getSelectionGroup();
885 // we make a copy rather than edit the current selection if no
887 // see Enhancement JAL-1557
888 if (!(jalview.util.Platform.isControlDown(evt) || evt
891 sg = new SequenceGroup(sg);
893 sg.addSequence(aa[selectedRow].sequenceRef, false);
897 if (jalview.util.Platform.isControlDown(evt))
899 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
903 // notionally, we should also add intermediate sequences from
904 // last added sequence ?
905 sg.addSequence(aa[selectedRow].sequenceRef, true);
911 sg = new SequenceGroup();
913 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
914 sg.addSequence(aa[selectedRow].sequenceRef, false);
916 ap.av.setSelectionGroup(sg);
917 ap.paintAlignment(false);
918 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
919 ap.av.sendSelection();
929 * do a single sequence copy to jalview and the system clipboard
932 * sequence to be copied to clipboard
934 protected void copy_annotseqtoclipboard(SequenceI sq)
936 SequenceI[] seqs = new SequenceI[] { sq };
937 String[] omitHidden = null;
938 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
939 if (dseqs[0] == null)
941 dseqs[0] = new Sequence(sq);
942 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
943 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
945 sq.setDatasetSequence(dseqs[0]);
947 Alignment ds = new Alignment(dseqs);
948 if (av.hasHiddenColumns())
950 omitHidden = av.getAlignment().getHiddenColumns()
951 .getVisibleSequenceStrings(0,
952 sq.getLength(), seqs);
955 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
956 List<int[]> hiddenCols = av.getAlignment().getHiddenColumns()
958 if (hiddenCols != null)
960 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
963 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
964 seqs, omitHidden, alignmentStartEnd);
966 Toolkit.getDefaultToolkit().getSystemClipboard()
967 .setContents(new StringSelection(output), Desktop.instance);
969 ArrayList<int[]> hiddenColumns = null;
970 if (av.hasHiddenColumns())
972 hiddenColumns = new ArrayList<int[]>();
973 for (int[] region : av.getAlignment().getHiddenColumns()
976 hiddenColumns.add(new int[] { region[0], region[1] });
980 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
982 // sequence ? need to
984 // sequence as special.
995 public void paintComponent(Graphics g)
998 int width = getWidth();
1001 width = ap.calculateIdWidth().width + 4;
1004 Graphics2D g2 = (Graphics2D) g;
1007 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1008 RenderingHints.VALUE_ANTIALIAS_ON);
1011 drawComponent(g2, true, width);
1016 * Draw the full set of annotation Labels for the alignment at the given
1020 * Graphics2D instance (needed for font scaling)
1022 * Width for scaling labels
1025 public void drawComponent(Graphics g, int width)
1027 drawComponent(g, false, width);
1030 private final boolean debugRedraw = false;
1033 * Draw the full set of annotation Labels for the alignment at the given
1037 * Graphics2D instance (needed for font scaling)
1039 * - true indicates that only current visible area needs to be
1042 * Width for scaling labels
1044 public void drawComponent(Graphics g, boolean clip, int width)
1046 if (av.getFont().getSize() < 10)
1052 g.setFont(av.getFont());
1055 FontMetrics fm = g.getFontMetrics(g.getFont());
1056 g.setColor(Color.white);
1057 g.fillRect(0, 0, getWidth(), getHeight());
1059 g.translate(0, getScrollOffset());
1060 g.setColor(Color.black);
1062 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1063 int fontHeight = g.getFont().getSize();
1066 int graphExtras = 0;
1068 Font baseFont = g.getFont();
1069 FontMetrics baseMetrics = fm;
1070 int ofontH = fontHeight;
1073 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1074 .getAnnotationPanel().getVisibleVRange() : null;
1075 if (clip && visr != null)
1078 visHeight = visr[1];
1080 boolean visible = true, before = false, after = false;
1083 hasHiddenRows = false;
1085 for (int i = 0; i < aa.length; i++)
1090 hasHiddenRows = true;
1103 System.out.println("before vis: " + i);
1107 // don't draw what isn't visible
1110 if (olY > visHeight)
1117 System.out.println("Scroll offset: " + sOffset
1118 + " after vis: " + i);
1122 // don't draw what isn't visible
1126 g.setColor(Color.black);
1128 offset = -aa[i].height / 2;
1132 offset += fm.getHeight() / 2;
1133 offset -= fm.getDescent();
1137 offset += fm.getDescent();
1140 x = width - fm.stringWidth(aa[i].label) - 3;
1142 if (aa[i].graphGroup > -1)
1145 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1146 // computed efficiently for all visible labels
1147 for (int gg = 0; gg < aa.length; gg++)
1149 if (aa[gg].graphGroup == aa[i].graphGroup)
1154 if (groupSize * (fontHeight + 8) < aa[i].height)
1156 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1160 // scale font to fit
1161 float h = aa[i].height / (float) groupSize, s;
1168 fontHeight = -8 + (int) h;
1169 s = ((float) fontHeight) / (float) ofontH;
1170 Font f = baseFont.deriveFont(AffineTransform
1171 .getScaleInstance(s, s));
1173 fm = g.getFontMetrics();
1174 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1179 for (int gg = 0; gg < aa.length; gg++)
1181 if (aa[gg].graphGroup == aa[i].graphGroup)
1183 x = width - fm.stringWidth(aa[gg].label) - 3;
1184 g.drawString(aa[gg].label, x, y - graphExtras);
1186 if (aa[gg]._linecolour != null)
1189 g.setColor(aa[gg]._linecolour);
1190 g.drawLine(x, y - graphExtras + 3,
1191 x + fm.stringWidth(aa[gg].label), y - graphExtras
1195 g.setColor(Color.black);
1196 graphExtras += fontHeight + 8;
1200 g.setFont(baseFont);
1202 fontHeight = ofontH;
1206 g.drawString(aa[i].label, x, y + offset);
1213 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1215 else if (dragEvent != null && aa != null)
1217 g.setColor(Color.lightGray);
1218 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1219 dragEvent.getY() - getScrollOffset());
1222 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1224 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1225 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1230 public int getScrollOffset()
1232 return scrollOffset;