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
425 || label.indexOf("Information Content") > -1))
427 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
429 // display formatting settings for this row.
431 // av and sequencegroup need to implement same interface for
432 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
433 aa[selectedRow].scaleColLabel);
434 item.addActionListener(this);
438 else if (label.indexOf("Consensus") > -1
439 || label.indexOf("Information Content") > -1)
442 // av and sequencegroup need to implement same interface for
443 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
444 MessageManager.getString("label.ignore_gaps_consensus"),
445 (aa[selectedRow].groupRef != null) ? aa[selectedRow].groupRef
446 .getIgnoreGapsConsensus() : ap.av
447 .isIgnoreGapsConsensus());
448 final AlignmentAnnotation aaa = aa[selectedRow];
449 cbmi.addActionListener(new ActionListener()
452 public void actionPerformed(ActionEvent e)
454 if (aaa.groupRef != null)
456 // TODO: pass on reference to ap so the view can be updated.
457 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
458 ap.getAnnotationPanel().paint(
459 ap.getAnnotationPanel().getGraphics());
463 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
465 ap.alignmentChanged();
469 // av and sequencegroup need to implement same interface for
470 if (aaa.groupRef != null)
472 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
473 MessageManager.getString("label.show_group_histogram"),
474 aa[selectedRow].groupRef.isShowConsensusHistogram());
475 chist.addActionListener(new ActionListener()
478 public void actionPerformed(ActionEvent e)
480 // TODO: pass on reference
486 aaa.groupRef.setShowConsensusHistogram(chist.getState());
488 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
492 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
493 MessageManager.getString("label.show_group_logo"),
494 aa[selectedRow].groupRef.isShowSequenceLogo());
495 cprofl.addActionListener(new ActionListener()
498 public void actionPerformed(ActionEvent e)
500 // TODO: pass on reference
506 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
508 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
512 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
513 MessageManager.getString("label.normalise_group_logo"),
514 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
515 cproflnorm.addActionListener(new ActionListener()
518 public void actionPerformed(ActionEvent e)
521 // TODO: pass on reference
527 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
528 // automatically enable logo display if we're clicked
529 aaa.groupRef.setshowSequenceLogo(true);
531 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
538 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
539 MessageManager.getString("label.show_histogram"),
540 av.isShowConsensusHistogram());
541 chist.addActionListener(new ActionListener()
544 public void actionPerformed(ActionEvent e)
546 // TODO: pass on reference
552 av.setShowConsensusHistogram(chist.getState());
553 ap.alignFrame.setMenusForViewport();
555 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
559 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
560 MessageManager.getString("label.show_logo"),
561 av.isShowSequenceLogo());
562 cprof.addActionListener(new ActionListener()
565 public void actionPerformed(ActionEvent e)
567 // TODO: pass on reference
573 av.setShowSequenceLogo(cprof.getState());
574 ap.alignFrame.setMenusForViewport();
576 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
580 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
581 MessageManager.getString("label.normalise_logo"),
582 av.isNormaliseSequenceLogo());
583 cprofnorm.addActionListener(new ActionListener()
586 public void actionPerformed(ActionEvent e)
588 // TODO: pass on reference
594 av.setShowSequenceLogo(true);
595 av.setNormaliseSequenceLogo(cprofnorm.getState());
596 ap.alignFrame.setMenusForViewport();
598 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
603 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
604 consclipbrd.addActionListener(this);
605 pop.add(consclipbrd);
608 pop.show(this, evt.getX(), evt.getY());
618 public void mouseReleased(MouseEvent evt)
620 if (evt.isPopupTrigger())
626 int start = selectedRow;
627 getSelectedRow(evt.getY() - getScrollOffset());
628 int end = selectedRow;
632 // Swap these annotations
633 AlignmentAnnotation startAA = ap.av.getAlignment()
634 .getAlignmentAnnotation()[start];
637 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
639 AlignmentAnnotation endAA = ap.av.getAlignment()
640 .getAlignmentAnnotation()[end];
642 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
643 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
649 ap.getAnnotationPanel().repaint();
659 public void mouseEntered(MouseEvent evt)
675 public void mouseExited(MouseEvent evt)
677 if (dragEvent == null)
691 public void mouseDragged(MouseEvent evt)
697 Dimension d = ap.annotationScroller.getPreferredSize();
698 int dif = evt.getY() - oldY;
700 dif /= ap.av.getCharHeight();
701 dif *= ap.av.getCharHeight();
703 if ((d.height - dif) > 20)
705 ap.annotationScroller.setPreferredSize(new Dimension(d.width,
707 d = ap.annotationSpaceFillerHolder.getPreferredSize();
708 ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(
709 d.width, d.height - dif));
710 ap.paintAlignment(true);
728 public void mouseMoved(MouseEvent evt)
730 resizePanel = evt.getY() < 10;
732 getSelectedRow(evt.getY() - getScrollOffset());
735 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow)
737 AlignmentAnnotation aa = ap.av.getAlignment()
738 .getAlignmentAnnotation()[selectedRow];
740 StringBuffer desc = new StringBuffer();
741 if (aa.description != null
742 && !aa.description.equals("New description"))
744 // TODO: we could refactor and merge this code with the code in
745 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
747 desc.append(aa.getDescription(true).trim());
748 // check to see if the description is an html fragment.
749 if (desc.length() < 6
750 || (desc.substring(0, 6).toLowerCase().indexOf("<html>") < 0))
752 // clean the description ready for embedding in html
753 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
754 .replaceAll("<"));
755 desc.insert(0, "<html>");
759 // remove terminating html if any
760 int i = desc.substring(desc.length() - 7).toLowerCase()
761 .lastIndexOf("</html>");
764 desc.setLength(desc.length() - 7 + i);
769 desc.append("<br/>");
771 // if (aa.hasProperties())
773 // desc.append("<table>");
774 // for (String prop : aa.getProperties())
776 // desc.append("<tr><td>" + prop + "</td><td>"
777 // + aa.getProperty(prop) + "</td><tr>");
779 // desc.append("</table>");
784 // begin the tooltip's html fragment
785 desc.append("<html>");
788 // TODO: limit precision of score to avoid noise from imprecise
790 // (64.7 becomes 64.7+/some tiny value).
791 desc.append(" Score: " + aa.score);
794 if (desc.length() > 6)
796 desc.append("</html>");
797 this.setToolTipText(desc.toString());
801 this.setToolTipText(null);
807 public void mouseClicked(MouseEvent evt)
809 final AlignmentAnnotation[] aa = ap.av.getAlignment()
810 .getAlignmentAnnotation();
811 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
813 if (selectedRow > -1 && selectedRow < aa.length)
815 if (aa[selectedRow].groupRef != null)
817 if (evt.getClickCount() >= 2)
819 // todo: make the ap scroll to the selection - not necessary, first
820 // click highlights/scrolls, second selects
821 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
823 SequenceGroup sg = ap.av.getSelectionGroup();
825 || sg == aa[selectedRow].groupRef
826 || !(jalview.util.Platform.isControlDown(evt) || evt
829 if (jalview.util.Platform.isControlDown(evt)
830 || evt.isShiftDown())
832 // clone a new selection group from the associated group
833 ap.av.setSelectionGroup(new SequenceGroup(
834 aa[selectedRow].groupRef));
838 // set selection to the associated group so it can be edited
839 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
844 // modify current selection with associated group
845 int remainToAdd = aa[selectedRow].groupRef.getSize();
846 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
848 if (jalview.util.Platform.isControlDown(evt))
850 sg.addOrRemove(sgs, --remainToAdd == 0);
854 // notionally, we should also add intermediate sequences from
855 // last added sequence ?
856 sg.addSequence(sgs, --remainToAdd == 0);
861 ap.paintAlignment(false);
862 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
863 ap.av.sendSelection();
867 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
868 aa[selectedRow].groupRef.getSequences(null));
872 else if (aa[selectedRow].sequenceRef != null)
874 if (evt.getClickCount() == 1)
878 .highlightSearchResults(
879 Arrays.asList(new SequenceI[] { aa[selectedRow].sequenceRef }));
881 else if (evt.getClickCount() >= 2)
883 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
884 SequenceGroup sg = ap.av.getSelectionGroup();
887 // we make a copy rather than edit the current selection if no
889 // see Enhancement JAL-1557
890 if (!(jalview.util.Platform.isControlDown(evt) || evt
893 sg = new SequenceGroup(sg);
895 sg.addSequence(aa[selectedRow].sequenceRef, false);
899 if (jalview.util.Platform.isControlDown(evt))
901 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
905 // notionally, we should also add intermediate sequences from
906 // last added sequence ?
907 sg.addSequence(aa[selectedRow].sequenceRef, true);
913 sg = new SequenceGroup();
915 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
916 sg.addSequence(aa[selectedRow].sequenceRef, false);
918 ap.av.setSelectionGroup(sg);
919 ap.paintAlignment(false);
920 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
921 ap.av.sendSelection();
931 * do a single sequence copy to jalview and the system clipboard
934 * sequence to be copied to clipboard
936 protected void copy_annotseqtoclipboard(SequenceI sq)
938 SequenceI[] seqs = new SequenceI[] { sq };
939 String[] omitHidden = null;
940 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
941 if (dseqs[0] == null)
943 dseqs[0] = new Sequence(sq);
944 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
945 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
947 sq.setDatasetSequence(dseqs[0]);
949 Alignment ds = new Alignment(dseqs);
950 if (av.hasHiddenColumns())
952 omitHidden = av.getAlignment().getHiddenColumns()
953 .getVisibleSequenceStrings(0,
954 sq.getLength(), seqs);
957 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
958 List<int[]> hiddenCols = av.getAlignment().getHiddenColumns()
960 if (hiddenCols != null)
962 alignmentStartEnd = av.getAlignment().getVisibleStartAndEndIndex(
965 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
966 seqs, omitHidden, alignmentStartEnd);
968 Toolkit.getDefaultToolkit().getSystemClipboard()
969 .setContents(new StringSelection(output), Desktop.instance);
971 ArrayList<int[]> hiddenColumns = null;
972 if (av.hasHiddenColumns())
974 hiddenColumns = new ArrayList<>();
975 for (int[] region : av.getAlignment().getHiddenColumns()
978 hiddenColumns.add(new int[] { region[0], region[1] });
982 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
984 // sequence ? need to
986 // sequence as special.
997 public void paintComponent(Graphics g)
1000 int width = getWidth();
1003 width = ap.calculateIdWidth().width + 4;
1006 Graphics2D g2 = (Graphics2D) g;
1009 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1010 RenderingHints.VALUE_ANTIALIAS_ON);
1013 drawComponent(g2, true, width);
1018 * Draw the full set of annotation Labels for the alignment at the given
1022 * Graphics2D instance (needed for font scaling)
1024 * Width for scaling labels
1027 public void drawComponent(Graphics g, int width)
1029 drawComponent(g, false, width);
1032 private final boolean debugRedraw = false;
1035 * Draw the full set of annotation Labels for the alignment at the given
1039 * Graphics2D instance (needed for font scaling)
1041 * - true indicates that only current visible area needs to be
1044 * Width for scaling labels
1046 public void drawComponent(Graphics g, boolean clip, int width)
1048 if (av.getFont().getSize() < 10)
1054 g.setFont(av.getFont());
1057 FontMetrics fm = g.getFontMetrics(g.getFont());
1058 g.setColor(Color.white);
1059 g.fillRect(0, 0, getWidth(), getHeight());
1061 g.translate(0, getScrollOffset());
1062 g.setColor(Color.black);
1064 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1065 int fontHeight = g.getFont().getSize();
1068 int graphExtras = 0;
1070 Font baseFont = g.getFont();
1071 FontMetrics baseMetrics = fm;
1072 int ofontH = fontHeight;
1075 int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap
1076 .getAnnotationPanel().getVisibleVRange() : null;
1077 if (clip && visr != null)
1080 visHeight = visr[1];
1082 boolean visible = true, before = false, after = false;
1085 hasHiddenRows = false;
1087 for (int i = 0; i < aa.length; i++)
1092 hasHiddenRows = true;
1105 System.out.println("before vis: " + i);
1109 // don't draw what isn't visible
1112 if (olY > visHeight)
1119 System.out.println("Scroll offset: " + sOffset
1120 + " after vis: " + i);
1124 // don't draw what isn't visible
1128 g.setColor(Color.black);
1130 offset = -aa[i].height / 2;
1134 offset += fm.getHeight() / 2;
1135 offset -= fm.getDescent();
1139 offset += fm.getDescent();
1142 x = width - fm.stringWidth(aa[i].label) - 3;
1144 if (aa[i].graphGroup > -1)
1147 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1148 // computed efficiently for all visible labels
1149 for (int gg = 0; gg < aa.length; gg++)
1151 if (aa[gg].graphGroup == aa[i].graphGroup)
1156 if (groupSize * (fontHeight + 8) < aa[i].height)
1158 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1162 // scale font to fit
1163 float h = aa[i].height / (float) groupSize, s;
1170 fontHeight = -8 + (int) h;
1171 s = ((float) fontHeight) / (float) ofontH;
1172 Font f = baseFont.deriveFont(AffineTransform
1173 .getScaleInstance(s, s));
1175 fm = g.getFontMetrics();
1176 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8))) / 2;
1181 for (int gg = 0; gg < aa.length; gg++)
1183 if (aa[gg].graphGroup == aa[i].graphGroup)
1185 x = width - fm.stringWidth(aa[gg].label) - 3;
1186 g.drawString(aa[gg].label, x, y - graphExtras);
1188 if (aa[gg]._linecolour != null)
1191 g.setColor(aa[gg]._linecolour);
1192 g.drawLine(x, y - graphExtras + 3,
1193 x + fm.stringWidth(aa[gg].label), y - graphExtras
1197 g.setColor(Color.black);
1198 graphExtras += fontHeight + 8;
1202 g.setFont(baseFont);
1204 fontHeight = ofontH;
1208 g.drawString(aa[i].label, x, y + offset);
1215 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1217 else if (dragEvent != null && aa != null)
1219 g.setColor(Color.lightGray);
1220 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1221 dragEvent.getY() - getScrollOffset());
1224 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1226 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1227 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1232 public int getScrollOffset()
1234 return scrollOffset;