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 implements MouseMotionListener, MouseListener
\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
46 boolean mouseDragging = false;
\r
48 // wants to delete columns
\r
49 public ScalePanel(AlignViewport av, AlignmentPanel ap)
\r
54 addMouseListener(this);
\r
55 addMouseMotionListener(this);
\r
61 * @param evt DOCUMENT ME!
\r
63 public void mousePressed(MouseEvent evt)
\r
65 int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
68 if(av.hasHiddenColumns)
\r
69 res = av.getColumnSelection().adjustForHiddenColumns(x);
\r
76 if(reveal != null && SwingUtilities.isRightMouseButton(evt))
\r
78 JPopupMenu pop = new JPopupMenu();
\r
79 JMenuItem item = new JMenuItem("Reveal");
\r
80 item.addActionListener(new ActionListener()
\r
82 public void actionPerformed(ActionEvent e)
\r
84 av.showColumn(reveal[0]);
\r
87 if(ap.overviewPanel != null)
\r
88 ap.overviewPanel.updateOverviewImage();
\r
93 if(av.getColumnSelection().size()>1)
\r
95 item = new JMenuItem("Reveal All");
\r
96 item.addActionListener(new ActionListener()
\r
98 public void actionPerformed(ActionEvent e)
\r
100 av.showAllHiddenColumns();
\r
103 if(ap.overviewPanel != null)
\r
104 ap.overviewPanel.updateOverviewImage();
\r
110 pop.show(this, evt.getX(), evt.getY());
\r
114 if (av.getColumnSelection().contains(res))
\r
116 if( SwingUtilities.isRightMouseButton(evt))
\r
118 JPopupMenu pop = new JPopupMenu();
\r
119 JMenuItem item = new JMenuItem("Hide Columns");
\r
120 item.addActionListener(new ActionListener()
\r
122 public void actionPerformed(ActionEvent e)
\r
124 av.hideColumns(res, res);
\r
126 if(ap.overviewPanel != null)
\r
127 ap.overviewPanel.updateOverviewImage();
\r
131 pop.show(this, evt.getX(), evt.getY());
\r
136 av.getColumnSelection().removeElement(res);
\r
137 av.setSelectionGroup(null);
\r
142 av.getColumnSelection().addElement(res);
\r
143 SequenceGroup sg = new SequenceGroup();
\r
145 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
147 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
150 sg.setStartRes(res);
\r
152 av.setSelectionGroup(sg);
\r
162 * @param evt DOCUMENT ME!
\r
164 public void mouseReleased(MouseEvent evt)
\r
166 mouseDragging = false;
\r
168 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
170 if(res> av.alignment.getWidth())
\r
172 res = av.alignment.getWidth()-1;
\r
175 if(av.hasHiddenColumns)
\r
176 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
178 if (!stretchingGroup)
\r
185 SequenceGroup sg = av.getSelectionGroup();
\r
187 if (res > sg.getStartRes())
\r
191 else if (res < sg.getStartRes())
\r
193 sg.setStartRes(res);
\r
196 stretchingGroup = false;
\r
203 * @param evt DOCUMENT ME!
\r
205 public void mouseDragged(MouseEvent evt)
\r
207 mouseDragging = true;
\r
209 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
211 if(av.hasHiddenColumns)
\r
212 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
215 if(res> av.alignment.getWidth())
\r
217 res = av.alignment.getWidth()-1;
\r
233 SequenceGroup sg = av.getSelectionGroup();
\r
237 stretchingGroup = true;
\r
239 if (!av.getColumnSelection().contains(res))
\r
241 av.getColumnSelection().addElement(res);
\r
244 if (res > sg.getStartRes())
\r
248 if (res < sg.getStartRes())
\r
250 sg.setStartRes(res);
\r
253 for (int i = min; i <= max; i++)
\r
255 if ((i < sg.getStartRes()) || (i > sg.getEndRes()))
\r
257 av.getColumnSelection().removeElement(i);
\r
261 av.getColumnSelection().addElement(i);
\r
269 public void mouseEntered(MouseEvent evt)
\r
272 ap.seqPanel.scrollCanvas(null);
\r
275 public void mouseExited(MouseEvent evt)
\r
278 ap.seqPanel.scrollCanvas(evt);
\r
281 public void mouseClicked(MouseEvent evt){}
\r
283 public void mouseMoved(MouseEvent evt)
\r
285 if(!av.hasHiddenColumns)
\r
288 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
290 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
293 for(int i=0; i<av.getColumnSelection().getHiddenColumns().size(); i++)
\r
295 int [] region = (int[])av.getColumnSelection().getHiddenColumns().elementAt(i);
\r
296 if(res+1==region[0] || res-1==region[1])
\r
299 ToolTipManager.sharedInstance().registerComponent(this);
\r
300 this.setToolTipText("Reveal Hidden Columns with Right Mouse Button");
\r
304 this.setToolTipText(null);
\r
316 * @param g DOCUMENT ME!
\r
318 public void paintComponent(Graphics g)
\r
320 drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight());
\r
323 // scalewidth will normally be screenwidth,
\r
324 public void drawScale(Graphics g, int startx, int endx, int width,
\r
327 Graphics2D gg = (Graphics2D) g;
\r
328 gg.setFont(av.getFont());
\r
331 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
332 RenderingHints.VALUE_ANTIALIAS_ON);
\r
334 //Fill in the background
\r
335 gg.setColor(Color.white);
\r
336 gg.fillRect(0, 0, width, height);
\r
337 gg.setColor(Color.black);
\r
339 //Fill the selected columns
\r
340 ColumnSelection cs = av.getColumnSelection();
\r
341 gg.setColor(new Color(220, 0, 0));
\r
343 for (int i = 0; i < cs.size(); i++)
\r
345 int sel = cs.columnAt(i);
\r
346 if(av.hasHiddenColumns)
\r
347 sel = av.getColumnSelection().findColumnPosition(sel);
\r
349 if ((sel >= startx) && (sel <= endx))
\r
351 gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
\r
356 // Draw the scale numbers
\r
357 gg.setColor(Color.black);
\r
359 int scalestartx = (startx / 10) * 10;
\r
361 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
362 int y = av.charHeight - fm.getDescent();
\r
364 if ((scalestartx % 10) == 0)
\r
372 for (int i = scalestartx; i < endx; i += 5)
\r
376 string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i));
\r
377 if ( (i - startx - 1) * av.charWidth > maxX)
\r
379 gg.drawString(string,
\r
380 (i - startx - 1) * av.charWidth, y);
\r
381 maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
\r
384 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
385 (av.charWidth / 2)), y + 2,
\r
386 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
387 (av.charWidth / 2)),
\r
388 y + (fm.getDescent() * 2));
\r
393 gg.drawLine((int) (((i - startx - 1) * av.charWidth) +
\r
394 (av.charWidth / 2)), y + fm.getDescent(),
\r
395 (int) (((i - startx - 1) * av.charWidth) +
\r
396 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r
400 if (av.hasHiddenColumns)
\r
402 gg.setColor(Color.blue);
\r
404 if(av.getShowHiddenMarkers())
\r
406 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size();
\r
410 res = av.getColumnSelection().findHiddenRegionPosition(i) -
\r
413 if(res < 0 || res > endx-scalestartx)
\r
416 gg.fillPolygon(new int[]
\r
417 {res * av.charWidth - av.charHeight / 4,
\r
418 res * av.charWidth + av.charHeight / 4,
\r
419 res * av.charWidth},
\r
422 y - av.charHeight / 2, y - av.charHeight / 2,
\r
429 if (reveal != null && reveal[0] > startx && reveal[0] < endx)
\r
431 gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0);
\r