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 ScalePanel
\r
31 protected int offy = 4;
\r
34 protected AlignViewport av;
\r
37 boolean stretchingGroup = false;
\r
39 public ScalePanel(AlignViewport av, AlignmentPanel ap)
\r
45 addMouseListener(new MouseAdapter()
\r
47 public void mousePressed(MouseEvent evt)
\r
49 doMousePressed(evt);
\r
52 public void mouseReleased(MouseEvent evt)
\r
54 doMouseReleased(evt);
\r
58 addMouseMotionListener(new MouseMotionAdapter()
\r
60 public void mouseDragged(MouseEvent evt)
\r
62 doMouseDragged(evt);
\r
68 public void doMousePressed(MouseEvent evt)
\r
71 int res = x / av.getCharWidth() + av.getStartRes();
\r
72 SequenceGroup sg = null;
\r
74 if (av.getColumnSelection().contains(res))
\r
76 av.getColumnSelection().removeElement(res);
\r
80 av.getColumnSelection().addElement(res);
\r
82 sg = new SequenceGroup();
\r
83 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
85 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
88 sg.setStartRes(res);
\r
91 ap.annotationPanel.addEditableColumn(res);
\r
93 av.setSelectionGroup(sg);
\r
97 public void doMouseReleased(MouseEvent evt)
\r
99 if (!stretchingGroup)
\r
104 int x = evt.getX();
\r
105 int res = x / av.getCharWidth() + av.getStartRes();
\r
107 if(res> av.alignment.getWidth())
\r
109 res = av.alignment.getWidth()-1;
\r
112 if (!av.getColumnSelection().contains(res))
\r
114 av.getColumnSelection().addElement(res);
\r
117 SequenceGroup sg = av.getSelectionGroup();
\r
119 if (res > sg.getStartRes())
\r
123 else if (res < sg.getStartRes())
\r
125 sg.setStartRes(res);
\r
128 stretchingGroup = false;
\r
132 public void doMouseDragged(MouseEvent evt)
\r
134 int x = evt.getX();
\r
135 int res = x / av.getCharWidth() + av.getStartRes();
\r
137 if(res> av.alignment.getWidth())
\r
139 res = av.alignment.getWidth()-1;
\r
142 SequenceGroup sg = av.getSelectionGroup();
\r
145 stretchingGroup = true;
\r
146 if (res > sg.getStartRes())
\r
150 else if (res < sg.getStartRes())
\r
152 sg.setStartRes(res);
\r
155 ap.annotationPanel.addEditableColumn(res);
\r
160 public void update(Graphics g)
\r
165 public void paint(Graphics g)
\r
167 drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
\r
171 // scalewidth will normally be screenwidth,
\r
172 public void drawScale(Graphics gg, int startx, int endx, int width,
\r
175 gg.setFont(av.getFont());
\r
177 //Fill in the background
\r
178 gg.setColor(Color.white);
\r
179 gg.fillRect(0, 0, width, height);
\r
180 gg.setColor(Color.black);
\r
182 //Fill the selected columns
\r
183 ColumnSelection cs = av.getColumnSelection();
\r
184 gg.setColor(new Color(220, 0, 0));
\r
185 for (int i = 0; i < cs.size(); i++)
\r
187 int sel = cs.columnAt(i);
\r
188 if (sel >= startx && sel <= endx)
\r
190 gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,
\r
195 // Draw the scale numbers
\r
196 gg.setColor(Color.black);
\r
197 int scalestartx = (startx / 10) * 10;
\r
199 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
200 int y = av.charHeight - fm.getDescent();
\r
202 if (scalestartx % 10 == 0)
\r
210 for (int i = scalestartx; i < endx; i += 5)
\r
214 string = String.valueOf(i);
\r
215 if ( (i - startx - 1) * av.charWidth > maxX)
\r
217 gg.drawString(string,
\r
218 (i - startx - 1) * av.charWidth, y);
\r
219 maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
\r
222 gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
224 (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
225 y + fm.getDescent() * 2);
\r
229 gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
230 y + fm.getDescent(),
\r
231 (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
232 y + fm.getDescent() * 2);
\r