Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File IdwidthAdjuster.java

 

Coverage histogram

../../img/srcFileCovDistChart3.png
47% of files have more coverage

Code metrics

6
29
9
1
193
87
14
0.48
3.22
9
1.56

Classes

Class Line # Actions
IdwidthAdjuster 40 29 14 34
0.2272727322.7%
 

Contributing tests

This file is covered by 78 tests. .

Source view

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.gui;
22   
23    import jalview.api.AlignViewportI;
24   
25    import java.awt.Color;
26    import java.awt.Cursor;
27    import java.awt.Graphics;
28    import java.awt.event.MouseEvent;
29    import java.awt.event.MouseListener;
30    import java.awt.event.MouseMotionListener;
31   
32    import javax.swing.JPanel;
33   
34    /**
35    * DOCUMENT ME!
36    *
37    * @author $author$
38    * @version $Revision$
39    */
 
40    public class IdwidthAdjuster extends JPanel
41    implements MouseListener, MouseMotionListener
42    {
43    boolean active = false;
44   
45    int oldX = 0;
46   
47    AlignmentPanel ap;
48   
49    /**
50    * Creates a new IdwidthAdjuster object.
51    *
52    * @param ap
53    * DOCUMENT ME!
54    */
 
55  217 toggle public IdwidthAdjuster(AlignmentPanel ap)
56    {
57  217 this.ap = ap;
58  217 setBackground(Color.white);
59  217 addMouseListener(this);
60  217 addMouseMotionListener(this);
61    }
62   
63    /**
64    * DOCUMENT ME!
65    *
66    * @param evt
67    * DOCUMENT ME!
68    */
 
69  0 toggle @Override
70    public void mousePressed(MouseEvent evt)
71    {
72  0 oldX = evt.getX();
73    }
74   
75    /**
76    * DOCUMENT ME!
77    *
78    * @param evt
79    * DOCUMENT ME!
80    */
 
81  0 toggle @Override
82    public void mouseReleased(MouseEvent evt)
83    {
84  0 active = false;
85  0 repaint();
86   
87    /*
88    * If in a SplitFrame with co-scaled alignments, set the other's id width to
89    * match
90    */
91  0 final AlignViewportI viewport = ap.getAlignViewport();
92  0 if (viewport.getCodingComplement() != null
93    && viewport.isScaleProteinAsCdna())
94    {
95  0 viewport.getCodingComplement().setIdWidth(viewport.getIdWidth());
96  0 SplitFrame sf = (SplitFrame) ap.alignFrame.getSplitViewContainer();
97  0 sf.repaint();
98    }
99   
100    }
101   
102    /**
103    * DOCUMENT ME!
104    *
105    * @param evt
106    * DOCUMENT ME!
107    */
 
108  0 toggle @Override
109    public void mouseEntered(MouseEvent evt)
110    {
111  0 active = true;
112  0 repaint();
113    }
114   
115    /**
116    * DOCUMENT ME!
117    *
118    * @param evt
119    * DOCUMENT ME!
120    */
 
121  0 toggle @Override
122    public void mouseExited(MouseEvent evt)
123    {
124  0 active = false;
125  0 repaint();
126    }
127   
128    /**
129    * DOCUMENT ME!
130    *
131    * @param evt
132    * DOCUMENT ME!
133    */
 
134  0 toggle @Override
135    public void mouseDragged(MouseEvent evt)
136    {
137  0 active = true;
138   
139  0 final AlignViewportI viewport = ap.getAlignViewport();
140  0 int curwidth = viewport.getIdWidth();
141  0 int dif = evt.getX() - oldX;
142   
143  0 final int newWidth = curwidth + dif;
144  0 if ((newWidth > 20) || (dif > 0))
145    {
146  0 viewport.setIdWidth(newWidth);
147   
148  0 ap.paintAlignment(true, false);
149    }
150   
151  0 oldX = evt.getX();
152    }
153   
154    /**
155    * DOCUMENT ME!
156    *
157    * @param evt
158    * DOCUMENT ME!
159    */
 
160  0 toggle @Override
161    public void mouseMoved(MouseEvent evt)
162    {
163    }
164   
165    /**
166    * DOCUMENT ME!
167    *
168    * @param evt
169    * DOCUMENT ME!
170    */
 
171  0 toggle @Override
172    public void mouseClicked(MouseEvent evt)
173    {
174    }
175   
176    /**
177    * DOCUMENT ME!
178    *
179    * @param g
180    * DOCUMENT ME!
181    */
 
182  711 toggle @Override
183    public void paintComponent(Graphics g)
184    {
185  711 g.setColor(Color.white);
186  711 g.fillRect(0, 0, getWidth(), getHeight());
187   
188  711 if (active)
189    {
190  0 setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
191    }
192    }
193    }