JAL-1807 update
[jalviewjs.git] / unused / 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.Color;
24 import java.awt.Dimension;
25 import java.awt.Graphics;
26 import java.awt.Image;
27 import java.awt.event.MouseEvent;
28 import java.awt.event.MouseListener;
29 import java.awt.event.MouseMotionListener;
30
31 import javax.swing.JPanel;
32
33 public class IdwidthAdjuster extends JPanel implements MouseListener,
34         MouseMotionListener
35 {
36   boolean active = false;
37
38   int oldX = 0;
39
40   Image image;
41
42   AlignmentPanel ap;
43
44   public IdwidthAdjuster(AlignmentPanel ap)
45   {
46     setLayout(null);
47     this.ap = ap;
48     java.net.URL url = getClass().getResource("/images/idwidth.gif");
49     if (url != null)
50     {
51       image = java.awt.Toolkit.getDefaultToolkit().getImage(url);
52     }
53
54     addMouseListener(this);
55     addMouseMotionListener(this);
56   }
57
58   public void mousePressed(MouseEvent evt)
59   {
60     oldX = evt.getX();
61   }
62
63   public void mouseReleased(MouseEvent evt)
64   {
65     active = false;
66     repaint();
67
68     /*
69      * If in a SplitFrame with co-scaled alignments, set the other's id width to
70      * match; note applet does not (yet) store this in ViewStyle
71      */
72     /*
73      * Code disabled for now as it doesn't work, don't know why; idCanvas width
74      * keeps resetting to a previous value (actually two alternating values!)
75      */
76     // final AlignViewportI viewport = ap.getAlignViewport();
77     // if (viewport.getCodingComplement() != null
78     // && viewport.isScaleProteinAsCdna())
79     // {
80     // Dimension d = ap.idPanel.idCanvas.getSize();
81     // SplitFrame sf = ap.alignFrame.getSplitFrame();
82     // final AlignmentPanel otherPanel =
83     // sf.getComplement(ap.alignFrame).alignPanel;
84     // otherPanel.setIdWidth(d.width, d.height);
85     // otherPanel.repaint();
86     // }
87   }
88
89   public void mouseEntered(MouseEvent evt)
90   {
91     active = true;
92     repaint();
93   }
94
95   public void mouseExited(MouseEvent evt)
96   {
97     active = false;
98     repaint();
99   }
100
101   public void mouseDragged(MouseEvent evt)
102   {
103     active = true;
104     Dimension d = ap.idPanel.idCanvas.getSize();
105     int dif = evt.getX() - oldX;
106
107     final int newWidth = d.width + dif;
108     if (newWidth > 20 || dif > 0)
109     {
110       ap.setIdWidth(newWidth, d.height);
111       this.setSize(newWidth, getSize().height);
112       oldX = evt.getX();
113     }
114   }
115
116   public void mouseMoved(MouseEvent evt)
117   {
118   }
119
120   public void mouseClicked(MouseEvent evt)
121   {
122   }
123
124   public void paint(Graphics g)
125   {
126     g.setColor(Color.white);
127     g.fillRect(0, 0, getSize().width, getSize().height);
128     if (active)
129     {
130       if (image != null)
131       {
132         g.drawImage(image, getSize().width - 20, 2, this);
133       }
134     }
135   }
136
137 }