2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 package jalview.appletgui;
23 import java.awt.event.*;
24 import java.util.Vector;
26 import jalview.datamodel.*;
28 public class AnnotationLabels
29 extends Panel implements ActionListener
31 boolean active = false;
34 boolean resizing = false;
36 static String ADDNEW = "Add new row";
37 static String HIDE = "Hide this row";
38 static String DELETE = "Delete this row";
39 static String SHOWALL = "Show all hidden rows";
40 static String OUTPUT_TEXT = "Show Values In Textbox";
41 static String COPYCONS_SEQ = "Copy Consensus Sequence";
46 public AnnotationLabels(AlignmentPanel ap)
51 addMouseListener(new MouseAdapter()
53 public void mousePressed(MouseEvent evt)
60 public AnnotationLabels(AlignViewport av)
66 public void setScrollOffset(int y)
72 public void actionPerformed(ActionEvent evt)
74 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
76 if (evt.getActionCommand().equals(HIDE))
78 aa[selectedRow].visible = false;
80 else if (evt.getActionCommand().equals(SHOWALL))
82 for (int i = 0; i < aa.length; i++)
87 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
89 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
90 Frame frame = new Frame();
92 jalview.bin.JalviewLite.addFrame(frame,
93 ap.alignFrame.getTitle() + " - " +
94 aa[selectedRow].label, 500, 100);
95 cap.setText(aa[selectedRow].toString());
97 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
99 SequenceI cons=av.getConsensusSeq();
101 copy_annotseqtoclipboard(cons);
104 ap.annotationPanel.adjustPanelHeight();
105 setSize(getSize().width, ap.annotationPanel.getSize().height);
110 public void doMousePressed(MouseEvent evt)
112 int y = evt.getY() - scrollOffset;
113 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
115 for (int i = 0; i < aa.length; i++)
122 height += aa[i].height;
130 PopupMenu pop = new PopupMenu("Annotations");
131 MenuItem item = new MenuItem(HIDE);
132 item.addActionListener(this);
134 item = new MenuItem(SHOWALL);
135 item.addActionListener(this);
138 item = new MenuItem(OUTPUT_TEXT);
139 item.addActionListener(this);
142 if (aa[selectedRow].label.equals("Consensus"))
145 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
146 "Ignore Gaps In Consensus",
147 ap.av.getIgnoreGapsConsensus());
149 cbmi.addItemListener(new ItemListener()
151 public void itemStateChanged(ItemEvent e)
153 ap.av.setIgnoreGapsConsensus(cbmi.getState());
158 final MenuItem cpcons=new MenuItem(COPYCONS_SEQ);
159 cpcons.addActionListener(this);
163 pop.show(this, evt.getX(), evt.getY());
169 * @param e DOCUMENT ME!
171 protected void copy_annotseqtoclipboard(SequenceI sq)
173 if (sq==null || sq.getLength()<1)
175 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
176 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
177 sq.getStart() + "\t" +
179 sq.getSequence() + "\n");
180 if (av.hasHiddenColumns)
182 jalview.appletgui.AlignFrame.copiedHiddenColumns=new Vector();
183 for(int i=0; i<av.getColumnSelection().getHiddenColumns().size(); i++)
185 int[] region = (int[])
186 av.getColumnSelection().getHiddenColumns().elementAt(i);
188 jalview.appletgui.AlignFrame.copiedHiddenColumns.addElement(new int[]{region[0],
194 public void paint(Graphics g)
196 drawComponent(g, getSize().width);
199 public void drawComponent(Graphics g, int width)
201 g.setFont(av.getFont());
202 FontMetrics fm = g.getFontMetrics(av.getFont());
203 g.setColor(Color.white);
204 g.fillRect(0, 0, getSize().width, getSize().height);
206 g.translate(0, scrollOffset);
207 g.setColor(Color.black);
209 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
210 int y = g.getFont().getSize();
215 for (int i = 0; i < aa.length; i++)
222 x = width - fm.stringWidth(aa[i].label) - 3;
226 y += (aa[i].height / 3);
229 g.drawString(aa[i].label, x, y);
233 y += (2 * aa[i].height / 3);