2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
28 extends Panel implements MouseMotionListener, MouseListener
\r
31 protected int offy = 4;
\r
34 protected AlignViewport av;
\r
37 boolean stretchingGroup = false;
\r
38 int min; //used by mouseDragged to see if user
\r
39 int max; //used by mouseDragged to see if user
\r
40 boolean mouseDragging = false;
\r
43 public ScalePanel(AlignViewport av, AlignmentPanel ap)
\r
49 addMouseListener(this);
\r
50 addMouseMotionListener(this);
\r
54 public void mousePressed(MouseEvent evt)
\r
56 int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
59 if (av.hasHiddenColumns)
\r
61 res = av.getColumnSelection().adjustForHiddenColumns(x);
\r
70 if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK)
\r
71 == InputEvent.BUTTON3_MASK)
\r
73 PopupMenu pop = new PopupMenu();
\r
76 MenuItem item = new MenuItem("Reveal");
\r
77 item.addActionListener(new ActionListener()
\r
79 public void actionPerformed(ActionEvent e)
\r
81 av.showColumn(reveal[0]);
\r
83 ap.paintAlignment(true);
\r
84 if (ap.overviewPanel != null)
\r
86 ap.overviewPanel.updateOverviewImage();
\r
92 if (av.getColumnSelection().getHiddenColumns().size() > 1)
\r
94 item = new MenuItem("Reveal All");
\r
95 item.addActionListener(new ActionListener()
\r
97 public void actionPerformed(ActionEvent e)
\r
99 av.showAllHiddenColumns();
\r
101 ap.paintAlignment(true);
\r
102 if (ap.overviewPanel != null)
\r
104 ap.overviewPanel.updateOverviewImage();
\r
111 pop.show(this, evt.getX(), evt.getY());
\r
113 else if (av.getColumnSelection().contains(res))
\r
115 MenuItem item = new MenuItem("Hide Columns");
\r
116 item.addActionListener(new ActionListener()
\r
118 public void actionPerformed(ActionEvent e)
\r
120 av.hideColumns(res, res);
\r
121 if (av.getSelectionGroup() != null
\r
123 av.getSelectionGroup().getSize() == av.alignment.getHeight())
\r
125 av.setSelectionGroup(null);
\r
128 ap.paintAlignment(true);
\r
129 if (ap.overviewPanel != null)
\r
131 ap.overviewPanel.updateOverviewImage();
\r
137 pop.show(this, evt.getX(), evt.getY());
\r
140 else // LEFT MOUSE TO SELECT
\r
142 if (!evt.isControlDown() && !evt.isShiftDown())
\r
144 av.getColumnSelection().clear();
\r
147 av.getColumnSelection().addElement(res);
\r
148 SequenceGroup sg = new SequenceGroup();
\r
149 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
151 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
154 sg.setStartRes(res);
\r
156 av.setSelectionGroup(sg);
\r
158 if (evt.isShiftDown())
\r
160 int min = Math.min(av.getColumnSelection().getMin(), res);
\r
161 int max = Math.max(av.getColumnSelection().getMax(), res);
\r
162 for (int i = min; i < max; i++)
\r
164 av.getColumnSelection().addElement(i);
\r
166 sg.setStartRes(min);
\r
171 ap.paintAlignment(true);
\r
174 public void mouseReleased(MouseEvent evt)
\r
176 mouseDragging = false;
\r
178 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
180 if (res > av.alignment.getWidth())
\r
182 res = av.alignment.getWidth() - 1;
\r
185 if (av.hasHiddenColumns)
\r
187 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
190 if (!stretchingGroup)
\r
192 ap.paintAlignment(false);
\r
197 SequenceGroup sg = av.getSelectionGroup();
\r
199 if (res > sg.getStartRes())
\r
203 else if (res < sg.getStartRes())
\r
205 sg.setStartRes(res);
\r
208 stretchingGroup = false;
\r
209 ap.paintAlignment(false);
\r
212 public void mouseDragged(MouseEvent evt)
\r
214 mouseDragging = true;
\r
216 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
222 if (av.hasHiddenColumns)
\r
224 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
227 if (res > av.alignment.getWidth())
\r
229 res = av.alignment.getWidth() - 1;
\r
242 SequenceGroup sg = av.getSelectionGroup();
\r
246 stretchingGroup = true;
\r
248 if (!av.getColumnSelection().contains(res))
\r
250 av.getColumnSelection().addElement(res);
\r
253 if (res > sg.getStartRes())
\r
257 if (res < sg.getStartRes())
\r
259 sg.setStartRes(res);
\r
263 for (int i = min; i <= max; i++)
\r
265 col = av.getColumnSelection().adjustForHiddenColumns(i);
\r
267 if ( (col < sg.getStartRes()) || (col > sg.getEndRes()))
\r
269 av.getColumnSelection().removeElement(col);
\r
273 av.getColumnSelection().addElement(col);
\r
277 ap.paintAlignment(false);
\r
281 public void mouseEntered(MouseEvent evt)
\r
285 ap.seqPanel.scrollCanvas(null);
\r
289 public void mouseExited(MouseEvent evt)
\r
293 ap.seqPanel.scrollCanvas(evt);
\r
297 public void mouseClicked(MouseEvent evt)
\r
302 public void mouseMoved(MouseEvent evt)
\r
304 if (!av.hasHiddenColumns)
\r
309 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
311 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
314 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
\r
316 int[] region = (int[]) av.getColumnSelection().getHiddenColumns().
\r
318 if (res + 1 == region[0] || res - 1 == region[1])
\r
328 public void update(Graphics g)
\r
333 public void paint(Graphics g)
\r
335 drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
\r
339 // scalewidth will normally be screenwidth,
\r
340 public void drawScale(Graphics gg, int startx, int endx, int width,
\r
343 gg.setFont(av.getFont());
\r
345 //Fill in the background
\r
346 gg.setColor(Color.white);
\r
347 gg.fillRect(0, 0, width, height);
\r
348 gg.setColor(Color.black);
\r
350 //Fill the selected columns
\r
351 ColumnSelection cs = av.getColumnSelection();
\r
352 gg.setColor(new Color(220, 0, 0));
\r
354 for (int i = 0; i < cs.size(); i++)
\r
356 int sel = cs.columnAt(i);
\r
357 if (av.hasHiddenColumns)
\r
359 sel = av.getColumnSelection().findColumnPosition(sel);
\r
362 if ( (sel >= startx) && (sel <= endx))
\r
364 gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,
\r
369 // Draw the scale numbers
\r
370 gg.setColor(Color.black);
\r
372 int scalestartx = (startx / 10) * 10;
\r
374 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
375 int y = av.charHeight - fm.getDescent();
\r
377 if ( (scalestartx % 10) == 0)
\r
385 for (int i = scalestartx; i < endx; i += 5)
\r
387 if ( (i % 10) == 0)
\r
389 string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(
\r
391 if ( (i - startx - 1) * av.charWidth > maxX)
\r
393 gg.drawString(string,
\r
394 (i - startx - 1) * av.charWidth, y);
\r
395 maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
\r
398 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
399 (av.charWidth / 2)), y + 2,
\r
400 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
401 (av.charWidth / 2)),
\r
402 y + (fm.getDescent() * 2));
\r
407 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
408 (av.charWidth / 2)), y + fm.getDescent(),
\r
409 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
410 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r
414 if (av.hasHiddenColumns)
\r
416 gg.setColor(Color.blue);
\r
418 if (av.getShowHiddenMarkers())
\r
420 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size();
\r
424 res = av.getColumnSelection().findHiddenRegionPosition(i) -
\r
427 if (res < 0 || res > endx - scalestartx)
\r
432 gg.fillPolygon(new int[]
\r
433 {res * av.charWidth - av.charHeight / 4,
\r
434 res * av.charWidth + av.charHeight / 4,
\r
435 res * av.charWidth},
\r
438 y - av.charHeight / 2, y - av.charHeight / 2,
\r
445 if (reveal != null && reveal[0] > startx && reveal[0] < endx)
\r
447 gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0);
\r