JAL-1432 updated copyright notices
[jalview.git] / src / jalview / appletgui / IdwidthAdjuster.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.appletgui;
20
21 import java.awt.*;
22 import java.awt.event.*;
23
24 public class IdwidthAdjuster extends Panel implements MouseListener,
25         MouseMotionListener
26 {
27   boolean active = false;
28
29   int oldX = 0;
30
31   Image image;
32
33   AlignmentPanel ap;
34
35   public IdwidthAdjuster(AlignmentPanel ap)
36   {
37     setLayout(null);
38     this.ap = ap;
39     java.net.URL url = getClass().getResource("/images/idwidth.gif");
40     if (url != null)
41     {
42       image = java.awt.Toolkit.getDefaultToolkit().getImage(url);
43     }
44
45     addMouseListener(this);
46     addMouseMotionListener(this);
47   }
48
49   public void mousePressed(MouseEvent evt)
50   {
51     oldX = evt.getX();
52   }
53
54   public void mouseReleased(MouseEvent evt)
55   {
56     active = false;
57     repaint();
58   }
59
60   public void mouseEntered(MouseEvent evt)
61   {
62     active = true;
63     repaint();
64   }
65
66   public void mouseExited(MouseEvent evt)
67   {
68     active = false;
69     repaint();
70   }
71
72   public void mouseDragged(MouseEvent evt)
73   {
74     active = true;
75     Dimension d = ap.idPanel.idCanvas.getSize();
76     int dif = evt.getX() - oldX;
77
78     if (d.width + dif > 20 || dif > 0)
79     {
80       ap.setIdWidth(d.width + dif, d.height);
81       this.setSize(d.width + dif, getSize().height);
82       oldX = evt.getX();
83     }
84
85   }
86
87   public void mouseMoved(MouseEvent evt)
88   {
89   }
90
91   public void mouseClicked(MouseEvent evt)
92   {
93   }
94
95   public void paint(Graphics g)
96   {
97     g.setColor(Color.white);
98     g.fillRect(0, 0, getSize().width, getSize().height);
99     if (active)
100     {
101       if (image != null)
102       {
103         g.drawImage(image, getSize().width - 20, 2, this);
104       }
105     }
106   }
107
108 }