JAL-984 remove all references to idwidth.gif and use int constants in place of width...
[jalview.git] / src / jalview / appletgui / IdwidthAdjuster.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.appletgui;
22
23 import java.awt.Cursor;
24 import java.awt.Dimension;
25 import java.awt.Panel;
26 import java.awt.event.MouseEvent;
27 import java.awt.event.MouseListener;
28 import java.awt.event.MouseMotionListener;
29
30 public class IdwidthAdjuster extends Panel
31         implements MouseListener, MouseMotionListener
32 {
33   boolean active = false;
34
35   int oldX = 0;
36
37   AlignmentPanel ap;
38
39   public IdwidthAdjuster(AlignmentPanel ap)
40   {
41     setLayout(null);
42     this.ap = ap;
43
44     addMouseListener(this);
45     addMouseMotionListener(this);
46   }
47
48   @Override
49   public void mousePressed(MouseEvent evt)
50   {
51     oldX = evt.getX();
52   }
53
54   @Override
55   public void mouseReleased(MouseEvent evt)
56   {
57     active = false;
58     repaint();
59
60     /*
61      * If in a SplitFrame with co-scaled alignments, set the other's id width to
62      * match; note applet does not (yet) store this in ViewStyle
63      */
64     /*
65      * Code disabled for now as it doesn't work, don't know why; idCanvas width
66      * keeps resetting to a previous value (actually two alternating values!)
67      */
68     // final AlignViewportI viewport = ap.getAlignViewport();
69     // if (viewport.getCodingComplement() != null
70     // && viewport.isScaleProteinAsCdna())
71     // {
72     // Dimension d = ap.idPanel.idCanvas.getSize();
73     // SplitFrame sf = ap.alignFrame.getSplitFrame();
74     // final AlignmentPanel otherPanel =
75     // sf.getComplement(ap.alignFrame).alignPanel;
76     // otherPanel.setIdWidth(d.width, d.height);
77     // otherPanel.repaint();
78     // }
79   }
80
81   @Override
82   public void mouseEntered(MouseEvent evt)
83   {
84     active = true;
85     setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
86
87     repaint();
88   }
89
90   @Override
91   public void mouseExited(MouseEvent evt)
92   {
93     active = false;
94     setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
95     repaint();
96   }
97
98   @Override
99   public void mouseDragged(MouseEvent evt)
100   {
101     active = true;
102     Dimension d = ap.idPanel.idCanvas.getSize();
103     int dif = evt.getX() - oldX;
104
105     final int newWidth = d.width + dif;
106     if (newWidth > 20 || dif > 0)
107     {
108       ap.setIdWidth(newWidth, d.height);
109       this.setSize(newWidth, getSize().height);
110       oldX = evt.getX();
111     }
112   }
113
114   @Override
115   public void mouseMoved(MouseEvent evt)
116   {
117   }
118
119   @Override
120   public void mouseClicked(MouseEvent evt)
121   {
122   }
123 }