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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
24 import java.awt.event.*;
\r
26 import javax.swing.*;
\r
33 * @version $Revision$
\r
35 public class ScalePanel extends JPanel
\r
37 protected int offy = 4;
\r
39 /** DOCUMENT ME!! */
\r
41 protected AlignViewport av;
\r
43 boolean stretchingGroup = false;
\r
44 int min; //used by mouseDragged to see if user
\r
45 int max; //used by mouseDragged to see if user
\r
47 // wants to delete columns
\r
48 public ScalePanel(AlignViewport av, AlignmentPanel ap)
\r
53 addMouseListener(new MouseAdapter()
\r
55 public void mousePressed(MouseEvent evt)
\r
57 doMousePressed(evt);
\r
60 public void mouseReleased(MouseEvent evt)
\r
62 doMouseReleased(evt);
\r
65 addMouseMotionListener(new MouseMotionAdapter()
\r
67 public void mouseDragged(MouseEvent evt)
\r
69 doMouseDragged(evt);
\r
77 * @param evt DOCUMENT ME!
\r
79 public void doMousePressed(MouseEvent evt)
\r
82 int res = (x / av.getCharWidth()) + av.getStartRes();
\r
83 SequenceGroup sg = null;
\r
88 if (av.getColumnSelection().contains(res))
\r
90 av.getColumnSelection().removeElement(res);
\r
91 ap.annotationPanel.removeEditableColumn(res);
\r
95 av.getColumnSelection().addElement(res);
\r
96 sg = new SequenceGroup();
\r
98 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
100 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
103 sg.setStartRes(res);
\r
107 av.setSelectionGroup(sg);
\r
114 * @param evt DOCUMENT ME!
\r
116 public void doMouseReleased(MouseEvent evt)
\r
118 int x = evt.getX();
\r
119 int res = (x / av.getCharWidth()) + av.getStartRes();
\r
121 if (av.getColumnSelection() != null)
\r
123 for (int i = 0; i < av.getColumnSelection().size(); i++)
\r
125 ap.annotationPanel.addEditableColumn(av.getColumnSelection()
\r
130 if (!stretchingGroup)
\r
137 SequenceGroup sg = av.getSelectionGroup();
\r
139 if (res > sg.getStartRes())
\r
143 else if (res < sg.getStartRes())
\r
145 sg.setStartRes(res);
\r
148 stretchingGroup = false;
\r
155 * @param evt DOCUMENT ME!
\r
157 public void doMouseDragged(MouseEvent evt)
\r
159 int x = evt.getX();
\r
160 int res = (x / av.getCharWidth()) + av.getStartRes();
\r
172 SequenceGroup sg = av.getSelectionGroup();
\r
176 stretchingGroup = true;
\r
178 if (!av.getColumnSelection().contains(res))
\r
180 av.getColumnSelection().addElement(res);
\r
183 if (res > sg.getStartRes())
\r
187 else if (res < sg.getStartRes())
\r
189 sg.setStartRes(res);
\r
192 for (int i = min; i <= max; i++)
\r
194 if ((i < sg.getStartRes()) || (i > sg.getEndRes()))
\r
196 av.getColumnSelection().removeElement(i);
\r
197 ap.annotationPanel.removeEditableColumn(res);
\r
201 av.getColumnSelection().addElement(i);
\r
212 * @param g DOCUMENT ME!
\r
214 public void paintComponent(Graphics g)
\r
216 drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight());
\r
219 // scalewidth will normally be screenwidth,
\r
220 public void drawScale(Graphics g, int startx, int endx, int width,
\r
223 Graphics2D gg = (Graphics2D) g;
\r
224 gg.setFont(av.getFont());
\r
225 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
226 RenderingHints.VALUE_ANTIALIAS_ON);
\r
228 //Fill in the background
\r
229 gg.setColor(Color.white);
\r
230 gg.fillRect(0, 0, width, height);
\r
231 gg.setColor(Color.black);
\r
233 //Fill the selected columns
\r
234 ColumnSelection cs = av.getColumnSelection();
\r
235 gg.setColor(new Color(220, 0, 0));
\r
237 for (int i = 0; i < cs.size(); i++)
\r
239 int sel = cs.columnAt(i);
\r
241 if ((sel >= startx) && (sel <= endx))
\r
243 gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
\r
248 // Draw the scale numbers
\r
249 gg.setColor(Color.black);
\r
251 int scalestartx = (startx / 10) * 10;
\r
253 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
254 int y = av.charHeight - fm.getDescent();
\r
256 if ((scalestartx % 10) == 0)
\r
261 for (int i = scalestartx; i < endx; i += 5)
\r
265 gg.drawString(String.valueOf(i),
\r
266 (i - startx - 1) * av.charWidth, y);
\r
267 gg.drawLine((int) (((i - startx - 1) * av.charWidth) +
\r
268 (av.charWidth / 2)), y + 2,
\r
269 (int) (((i - startx - 1) * av.charWidth) +
\r
270 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r
274 gg.drawLine((int) (((i - startx - 1) * av.charWidth) +
\r
275 (av.charWidth / 2)), y + fm.getDescent(),
\r
276 (int) (((i - startx - 1) * av.charWidth) +
\r
277 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r