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
71 implements MouseListener, 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(ap).exportAnnotation(aa[selectedRow]);
271 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
273 SequenceI cons = null;
274 if (aa[selectedRow].groupRef != null)
276 cons = aa[selectedRow].groupRef.getConsensusSeq();
280 cons = av.getConsensusSeq();
284 copy_annotseqtoclipboard(cons);
288 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
290 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
293 ap.refresh(fullRepaint);
303 boolean editLabelDescription(AlignmentAnnotation annotation)
306 EditNameDialog dialog = new EditNameDialog(annotation.label,
307 annotation.description, " Annotation Name ",
308 "Annotation Description ", "Edit Annotation Name/Description",
316 annotation.label = dialog.getName();
318 String text = dialog.getDescription();
319 if (text != null && text.length() == 0)
323 annotation.description = text;
329 public void mousePressed(MouseEvent evt)
331 getSelectedRow(evt.getY() - getScrollOffset());
333 if (evt.isPopupTrigger())
340 * Build and show the Pop-up menu at the right-click mouse position
344 void showPopupMenu(MouseEvent evt)
347 final AlignmentAnnotation[] aa = ap.av.getAlignment()
348 .getAlignmentAnnotation();
350 JPopupMenu pop = new JPopupMenu(
351 MessageManager.getString("label.annotations"));
352 JMenuItem item = new JMenuItem(ADDNEW);
353 item.addActionListener(this);
358 { // let the user make everything visible again
359 item = new JMenuItem(SHOWALL);
360 item.addActionListener(this);
363 pop.show(this, evt.getX(), evt.getY());
366 item = new JMenuItem(EDITNAME);
367 item.addActionListener(this);
369 item = new JMenuItem(HIDE);
370 item.addActionListener(this);
372 // JAL-1264 hide all sequence-specific annotations of this type
373 if (selectedRow < aa.length)
375 if (aa[selectedRow].sequenceRef != null)
377 final String label = aa[selectedRow].label;
378 JMenuItem hideType = new JMenuItem();
379 String text = MessageManager.getString("label.hide_all") + " "
381 hideType.setText(text);
382 hideType.addActionListener(new ActionListener()
385 public void actionPerformed(ActionEvent e)
387 AlignmentUtils.showOrHideSequenceAnnotations(
388 ap.av.getAlignment(), Collections.singleton(label),
390 // for (AlignmentAnnotation ann : ap.av.getAlignment()
391 // .getAlignmentAnnotation())
393 // if (ann.sequenceRef != null && ann.label != null
394 // && ann.label.equals(label))
396 // ann.visible = false;
405 item = new JMenuItem(DELETE);
406 item.addActionListener(this);
410 item = new JMenuItem(SHOWALL);
411 item.addActionListener(this);
414 item = new JMenuItem(OUTPUT_TEXT);
415 item.addActionListener(this);
417 // TODO: annotation object should be typed for autocalculated/derived
419 if (selectedRow < aa.length)
421 final String label = aa[selectedRow].label;
422 if (!aa[selectedRow].autoCalculated)
424 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
426 // display formatting settings for this row.
428 // av and sequencegroup need to implement same interface for
429 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
430 aa[selectedRow].scaleColLabel);
431 item.addActionListener(this);
435 else if (label.indexOf("Consensus") > -1)
438 // av and sequencegroup need to implement same interface for
439 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
440 MessageManager.getString("label.ignore_gaps_consensus"),
441 (aa[selectedRow].groupRef != null)
442 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
443 : ap.av.isIgnoreGapsConsensus());
444 final AlignmentAnnotation aaa = aa[selectedRow];
445 cbmi.addActionListener(new ActionListener()
448 public void actionPerformed(ActionEvent e)
450 if (aaa.groupRef != null)
452 // TODO: pass on reference to ap so the view can be updated.
453 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
454 ap.getAnnotationPanel()
455 .paint(ap.getAnnotationPanel().getGraphics());
459 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
461 ap.alignmentChanged();
465 // av and sequencegroup need to implement same interface for
466 if (aaa.groupRef != null)
468 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
469 MessageManager.getString("label.show_group_histogram"),
470 aa[selectedRow].groupRef.isShowConsensusHistogram());
471 chist.addActionListener(new ActionListener()
474 public void actionPerformed(ActionEvent e)
476 // TODO: pass on reference
482 aaa.groupRef.setShowConsensusHistogram(chist.getState());
484 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
488 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
489 MessageManager.getString("label.show_group_logo"),
490 aa[selectedRow].groupRef.isShowSequenceLogo());
491 cprofl.addActionListener(new ActionListener()
494 public void actionPerformed(ActionEvent e)
496 // TODO: pass on reference
502 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
504 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
508 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
509 MessageManager.getString("label.normalise_group_logo"),
510 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
511 cproflnorm.addActionListener(new ActionListener()
514 public void actionPerformed(ActionEvent e)
517 // TODO: pass on reference
523 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
524 // automatically enable logo display if we're clicked
525 aaa.groupRef.setshowSequenceLogo(true);
527 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
534 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
535 MessageManager.getString("label.show_histogram"),
536 av.isShowConsensusHistogram());
537 chist.addActionListener(new ActionListener()
540 public void actionPerformed(ActionEvent e)
542 // TODO: pass on reference
548 av.setShowConsensusHistogram(chist.getState());
549 ap.alignFrame.setMenusForViewport();
551 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
555 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
556 MessageManager.getString("label.show_logo"),
557 av.isShowSequenceLogo());
558 cprof.addActionListener(new ActionListener()
561 public void actionPerformed(ActionEvent e)
563 // TODO: pass on reference
569 av.setShowSequenceLogo(cprof.getState());
570 ap.alignFrame.setMenusForViewport();
572 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
576 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
577 MessageManager.getString("label.normalise_logo"),
578 av.isNormaliseSequenceLogo());
579 cprofnorm.addActionListener(new ActionListener()
582 public void actionPerformed(ActionEvent e)
584 // TODO: pass on reference
590 av.setShowSequenceLogo(true);
591 av.setNormaliseSequenceLogo(cprofnorm.getState());
592 ap.alignFrame.setMenusForViewport();
594 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
599 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
600 consclipbrd.addActionListener(this);
601 pop.add(consclipbrd);
604 pop.show(this, evt.getX(), evt.getY());
614 public void mouseReleased(MouseEvent evt)
616 if (evt.isPopupTrigger())
622 int start = selectedRow;
623 getSelectedRow(evt.getY() - getScrollOffset());
624 int end = selectedRow;
628 // Swap these annotations
629 AlignmentAnnotation startAA = ap.av.getAlignment()
630 .getAlignmentAnnotation()[start];
633 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
635 AlignmentAnnotation endAA = ap.av.getAlignment()
636 .getAlignmentAnnotation()[end];
638 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
639 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
645 ap.getAnnotationPanel().repaint();
655 public void mouseEntered(MouseEvent evt)
671 public void mouseExited(MouseEvent evt)
673 if (dragEvent == null)
687 public void mouseDragged(MouseEvent evt)
693 Dimension d = ap.annotationScroller.getPreferredSize();
694 int dif = evt.getY() - oldY;
696 dif /= ap.av.getCharHeight();
697 dif *= ap.av.getCharHeight();
699 if ((d.height - dif) > 20)
701 ap.annotationScroller
702 .setPreferredSize(new Dimension(d.width, d.height - dif));
703 d = ap.annotationSpaceFillerHolder.getPreferredSize();
704 ap.annotationSpaceFillerHolder
705 .setPreferredSize(new Dimension(d.width, d.height - dif));
706 ap.paintAlignment(true, false);
724 public void mouseMoved(MouseEvent evt)
726 resizePanel = evt.getY() < 10;
728 getSelectedRow(evt.getY() - getScrollOffset());
730 if (selectedRow > -1 && ap.av.getAlignment()
731 .getAlignmentAnnotation().length > selectedRow)
733 AlignmentAnnotation aa = ap.av.getAlignment()
734 .getAlignmentAnnotation()[selectedRow];
736 StringBuffer desc = new StringBuffer();
737 if (aa.description != null
738 && !aa.description.equals("New description"))
740 // TODO: we could refactor and merge this code with the code in
741 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
743 desc.append(aa.getDescription(true).trim());
744 // check to see if the description is an html fragment.
745 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
746 .indexOf("<html>") < 0))
748 // clean the description ready for embedding in html
749 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
750 .replaceAll("<"));
751 desc.insert(0, "<html>");
755 // remove terminating html if any
756 int i = desc.substring(desc.length() - 7).toLowerCase()
757 .lastIndexOf("</html>");
760 desc.setLength(desc.length() - 7 + i);
765 desc.append("<br/>");
767 // if (aa.hasProperties())
769 // desc.append("<table>");
770 // for (String prop : aa.getProperties())
772 // desc.append("<tr><td>" + prop + "</td><td>"
773 // + aa.getProperty(prop) + "</td><tr>");
775 // desc.append("</table>");
780 // begin the tooltip's html fragment
781 desc.append("<html>");
784 // TODO: limit precision of score to avoid noise from imprecise
786 // (64.7 becomes 64.7+/some tiny value).
787 desc.append(" Score: " + aa.score);
790 if (desc.length() > 6)
792 desc.append("</html>");
793 this.setToolTipText(desc.toString());
797 this.setToolTipText(null);
803 public void mouseClicked(MouseEvent evt)
805 final AlignmentAnnotation[] aa = ap.av.getAlignment()
806 .getAlignmentAnnotation();
807 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
809 if (selectedRow > -1 && selectedRow < aa.length)
811 if (aa[selectedRow].groupRef != null)
813 if (evt.getClickCount() >= 2)
815 // todo: make the ap scroll to the selection - not necessary, first
816 // click highlights/scrolls, second selects
817 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
819 SequenceGroup sg = ap.av.getSelectionGroup();
820 if (sg == null || sg == aa[selectedRow].groupRef
821 || !(jalview.util.Platform.isControlDown(evt)
822 || evt.isShiftDown()))
824 if (jalview.util.Platform.isControlDown(evt)
825 || evt.isShiftDown())
827 // clone a new selection group from the associated group
828 ap.av.setSelectionGroup(
829 new SequenceGroup(aa[selectedRow].groupRef));
833 // set selection to the associated group so it can be edited
834 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
839 // modify current selection with associated group
840 int remainToAdd = aa[selectedRow].groupRef.getSize();
841 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
843 if (jalview.util.Platform.isControlDown(evt))
845 sg.addOrRemove(sgs, --remainToAdd == 0);
849 // notionally, we should also add intermediate sequences from
850 // last added sequence ?
851 sg.addSequence(sgs, --remainToAdd == 0);
856 ap.paintAlignment(false, false);
857 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
858 ap.av.sendSelection();
862 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
863 aa[selectedRow].groupRef.getSequences(null));
867 else if (aa[selectedRow].sequenceRef != null)
869 if (evt.getClickCount() == 1)
871 ap.getSeqPanel().ap.getIdPanel()
872 .highlightSearchResults(Arrays.asList(new SequenceI[]
873 { aa[selectedRow].sequenceRef }));
875 else if (evt.getClickCount() >= 2)
877 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
878 SequenceGroup sg = ap.av.getSelectionGroup();
881 // we make a copy rather than edit the current selection if no
883 // see Enhancement JAL-1557
884 if (!(jalview.util.Platform.isControlDown(evt)
885 || evt.isShiftDown()))
887 sg = new SequenceGroup(sg);
889 sg.addSequence(aa[selectedRow].sequenceRef, false);
893 if (jalview.util.Platform.isControlDown(evt))
895 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
899 // notionally, we should also add intermediate sequences from
900 // last added sequence ?
901 sg.addSequence(aa[selectedRow].sequenceRef, true);
907 sg = new SequenceGroup();
909 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
910 sg.addSequence(aa[selectedRow].sequenceRef, false);
912 ap.av.setSelectionGroup(sg);
913 ap.paintAlignment(false, false);
914 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
915 ap.av.sendSelection();
925 * do a single sequence copy to jalview and the system clipboard
928 * sequence to be copied to clipboard
930 protected void copy_annotseqtoclipboard(SequenceI sq)
932 SequenceI[] seqs = new SequenceI[] { sq };
933 String[] omitHidden = null;
934 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
935 if (dseqs[0] == null)
937 dseqs[0] = new Sequence(sq);
938 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
939 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
941 sq.setDatasetSequence(dseqs[0]);
943 Alignment ds = new Alignment(dseqs);
944 if (av.hasHiddenColumns())
946 omitHidden = av.getAlignment().getHiddenColumns()
947 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
950 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
951 if (av.hasHiddenColumns())
953 alignmentStartEnd = av.getAlignment().getHiddenColumns()
954 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
957 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
958 seqs, omitHidden, alignmentStartEnd);
960 Toolkit.getDefaultToolkit().getSystemClipboard()
961 .setContents(new StringSelection(output), Desktop.instance);
963 ArrayList<int[]> hiddenColumns = null;
965 if (av.hasHiddenColumns())
967 hiddenColumns = av.getAlignment().getHiddenColumns()
968 .getHiddenColumnsCopy();
971 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
973 // sequence ? need to
975 // sequence as special.
986 public void paintComponent(Graphics g)
989 int width = getWidth();
992 width = ap.calculateIdWidth().width + 4;
995 Graphics2D g2 = (Graphics2D) g;
998 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
999 RenderingHints.VALUE_ANTIALIAS_ON);
1002 drawComponent(g2, true, width);
1007 * Draw the full set of annotation Labels for the alignment at the given
1011 * Graphics2D instance (needed for font scaling)
1013 * Width for scaling labels
1016 public void drawComponent(Graphics g, int width)
1018 drawComponent(g, false, width);
1021 private final boolean debugRedraw = false;
1024 * Draw the full set of annotation Labels for the alignment at the given
1028 * Graphics2D instance (needed for font scaling)
1030 * - true indicates that only current visible area needs to be
1033 * Width for scaling labels
1035 public void drawComponent(Graphics g, boolean clip, int width)
1037 if (av.getFont().getSize() < 10)
1043 g.setFont(av.getFont());
1046 FontMetrics fm = g.getFontMetrics(g.getFont());
1047 g.setColor(Color.white);
1048 g.fillRect(0, 0, getWidth(), getHeight());
1050 g.translate(0, getScrollOffset());
1051 g.setColor(Color.black);
1053 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1054 int fontHeight = g.getFont().getSize();
1057 int graphExtras = 0;
1059 Font baseFont = g.getFont();
1060 FontMetrics baseMetrics = fm;
1061 int ofontH = fontHeight;
1064 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1065 ? ap.getAnnotationPanel().getVisibleVRange()
1067 if (clip && visr != null)
1070 visHeight = visr[1];
1072 boolean visible = true, before = false, after = false;
1075 hasHiddenRows = false;
1077 for (int i = 0; i < aa.length; i++)
1082 hasHiddenRows = true;
1095 System.out.println("before vis: " + i);
1099 // don't draw what isn't visible
1102 if (olY > visHeight)
1110 "Scroll offset: " + sOffset + " after vis: " + i);
1114 // don't draw what isn't visible
1118 g.setColor(Color.black);
1120 offset = -aa[i].height / 2;
1124 offset += fm.getHeight() / 2;
1125 offset -= fm.getDescent();
1129 offset += fm.getDescent();
1132 x = width - fm.stringWidth(aa[i].label) - 3;
1134 if (aa[i].graphGroup > -1)
1137 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1138 // computed efficiently for all visible labels
1139 for (int gg = 0; gg < aa.length; gg++)
1141 if (aa[gg].graphGroup == aa[i].graphGroup)
1146 if (groupSize * (fontHeight + 8) < aa[i].height)
1148 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1153 // scale font to fit
1154 float h = aa[i].height / (float) groupSize, s;
1161 fontHeight = -8 + (int) h;
1162 s = ((float) fontHeight) / (float) ofontH;
1164 .deriveFont(AffineTransform.getScaleInstance(s, s));
1166 fm = g.getFontMetrics();
1167 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1173 for (int gg = 0; gg < aa.length; gg++)
1175 if (aa[gg].graphGroup == aa[i].graphGroup)
1177 x = width - fm.stringWidth(aa[gg].label) - 3;
1178 g.drawString(aa[gg].label, x, y - graphExtras);
1180 if (aa[gg]._linecolour != null)
1183 g.setColor(aa[gg]._linecolour);
1184 g.drawLine(x, y - graphExtras + 3,
1185 x + fm.stringWidth(aa[gg].label),
1186 y - graphExtras + 3);
1189 g.setColor(Color.black);
1190 graphExtras += fontHeight + 8;
1194 g.setFont(baseFont);
1196 fontHeight = ofontH;
1200 g.drawString(aa[i].label, x, y + offset);
1207 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1209 else if (dragEvent != null && aa != null)
1211 g.setColor(Color.lightGray);
1212 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1213 dragEvent.getY() - getScrollOffset());
1216 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1218 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1219 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1224 public int getScrollOffset()
1226 return scrollOffset;