2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
27 public class AnnotationLabels
\r
28 extends Panel implements ActionListener
\r
30 boolean active = false;
\r
33 boolean resizing = false;
\r
35 static String ADDNEW = "Add new row";
\r
36 static String HIDE = "Hide this row";
\r
37 static String DELETE = "Delete this row";
\r
38 static String SHOWALL = "Show all hidden rows";
\r
39 static String OUTPUT_TEXT = "Show Values In Textbox";
\r
40 int selectedRow = 0;
\r
41 int scrollOffset = 0;
\r
43 public AnnotationLabels(AlignmentPanel ap)
\r
48 addMouseListener(new MouseAdapter()
\r
50 public void mousePressed(MouseEvent evt)
\r
52 doMousePressed(evt);
\r
57 public AnnotationLabels(AlignViewport av)
\r
63 public void setScrollOffset(int y)
\r
69 public void actionPerformed(ActionEvent evt)
\r
71 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
73 if (evt.getActionCommand().equals(HIDE))
\r
75 aa[selectedRow].visible = false;
\r
77 else if (evt.getActionCommand().equals(SHOWALL))
\r
79 for (int i = 0; i < aa.length; i++)
\r
81 aa[i].visible = true;
\r
84 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
\r
86 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
\r
87 Frame frame = new Frame();
\r
89 jalview.bin.JalviewLite.addFrame(frame,
\r
90 ap.alignFrame.getTitle() + " - " +
\r
91 aa[selectedRow].label, 500, 100);
\r
92 cap.setText(aa[selectedRow].toString());
\r
95 ap.annotationPanel.adjustPanelHeight();
\r
96 setSize(getSize().width, ap.annotationPanel.getSize().height);
\r
101 public void doMousePressed(MouseEvent evt)
\r
103 int y = evt.getY() - scrollOffset;
\r
104 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
106 for (int i = 0; i < aa.length; i++)
\r
108 if (!aa[i].visible)
\r
113 height += aa[i].height;
\r
121 PopupMenu pop = new PopupMenu("Annotations");
\r
122 MenuItem item = new MenuItem(HIDE);
\r
123 item.addActionListener(this);
\r
125 item = new MenuItem(SHOWALL);
\r
126 item.addActionListener(this);
\r
129 item = new MenuItem(OUTPUT_TEXT);
\r
130 item.addActionListener(this);
\r
133 if (aa[selectedRow].label.equals("Consensus"))
\r
135 pop.addSeparator();
\r
136 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
\r
137 "Ignore Gaps In Consensus",
\r
138 ap.av.getIgnoreGapsConsensus());
\r
140 cbmi.addItemListener(new ItemListener()
\r
142 public void itemStateChanged(ItemEvent e)
\r
144 ap.av.setIgnoreGapsConsensus(cbmi.getState());
\r
151 pop.show(this, evt.getX(), evt.getY());
\r
155 public void paint(Graphics g)
\r
157 drawComponent(g, getSize().width);
\r
160 public void drawComponent(Graphics g, int width)
\r
162 FontMetrics fm = g.getFontMetrics(g.getFont());
\r
163 g.setColor(Color.white);
\r
164 g.fillRect(0, 0, getSize().width, getSize().height);
\r
166 g.translate(0, scrollOffset);
\r
167 g.setColor(Color.black);
\r
169 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
170 int y = g.getFont().getSize();
\r
175 for (int i = 0; i < aa.length; i++)
\r
177 if (!aa[i].visible)
\r
182 x = width - fm.stringWidth(aa[i].label) - 3;
\r
186 y += (aa[i].height / 3);
\r
189 g.drawString(aa[i].label, x, y);
\r
193 y += (2 * aa[i].height / 3);
\r