Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File IdwidthAdjuster.java

 

Coverage histogram

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

Code metrics

6
27
9
1
174
84
13
0.48
3
9
1.44

Classes

Class Line # Actions
IdwidthAdjuster 40 27 13
0.2142857221.4%
 

Contributing tests

This file is covered by 96 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    public static final int MIN_ID_WIDTH = 20;
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  267 toggle public IdwidthAdjuster(AlignmentPanel ap)
56    {
57  267 this.ap = ap;
58  267 setBackground(Color.white);
59  267 addMouseListener(this);
60  267 addMouseMotionListener(this);
61    }
62   
63    /**
64    * Action on mouse pressed is to save the start position for any drag
65    *
66    * @param evt
67    */
 
68  0 toggle @Override
69    public void mousePressed(MouseEvent evt)
70    {
71  0 oldX = evt.getX();
72    }
73   
74    /**
75    * On release of mouse drag to resize the width, if there is a complementary
76    * alignment in a split frame, sets the complement to the same id width and
77    * repaints the split frame. Note this is done whether or not the protein
78    * characters are scaled to codon width.
79    *
80    * @param evt
81    */
 
82  0 toggle @Override
83    public void mouseReleased(MouseEvent evt)
84    {
85  0 repaint();
86   
87    /*
88    * If in a SplitFrame, set the other's id width to match
89    */
90  0 final AlignViewportI viewport = ap.getAlignViewport();
91  0 if (viewport.getCodingComplement() != null)
92    {
93  0 viewport.getCodingComplement().setIdWidth(viewport.getIdWidth());
94  0 SplitFrame sf = (SplitFrame) ap.alignFrame.getSplitViewContainer();
95  0 sf.repaint();
96    }
97    }
98   
99    /**
100    * When this region is entered, repaints to show a left-right move cursor
101    *
102    * @param evt
103    */
 
104  0 toggle @Override
105    public void mouseEntered(MouseEvent evt)
106    {
107  0 repaint();
108    }
109   
 
110  0 toggle @Override
111    public void mouseExited(MouseEvent evt)
112    {
113    }
114   
115    /**
116    * Adjusts the id panel width for a mouse drag left or right (subject to a
117    * minimum of 20 pixels) and repaints the alignment
118    *
119    * @param evt
120    */
 
121  0 toggle @Override
122    public void mouseDragged(MouseEvent evt)
123    {
124  0 int mouseX = evt.getX();
125  0 final AlignViewportI viewport = ap.getAlignViewport();
126  0 int curwidth = viewport.getIdWidth();
127  0 int dif = mouseX - oldX;
128   
129  0 final int newWidth = curwidth + dif;
130   
131    /*
132    * don't drag below minimum width
133    */
134  0 if (newWidth < MIN_ID_WIDTH)
135    {
136  0 return;
137    }
138   
139  0 oldX = evt.getX();
140   
141    /*
142    * don't drag right if mouse is to the left of the region
143    */
144  0 if (dif > 0 && mouseX < 0)
145    {
146  0 return;
147    }
148  0 viewport.setIdWidth(newWidth);
149  0 ap.paintAlignment(true, false);
150    }
151   
 
152  0 toggle @Override
153    public void mouseMoved(MouseEvent evt)
154    {
155    }
156   
 
157  0 toggle @Override
158    public void mouseClicked(MouseEvent evt)
159    {
160    }
161   
162    /**
163    * Paints this region, showing a left-right move cursor if currently 'active'
164    *
165    * @param g
166    */
 
167  725 toggle @Override
168    public void paintComponent(Graphics g)
169    {
170  725 g.setColor(Color.white);
171  725 g.fillRect(0, 0, getWidth(), getHeight());
172  725 setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
173    }
174    }