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