1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertTrue; |
25 |
|
|
26 |
|
import jalview.bin.Cache; |
27 |
|
import jalview.bin.Jalview; |
28 |
|
import jalview.datamodel.Alignment; |
29 |
|
import jalview.datamodel.AlignmentI; |
30 |
|
import jalview.datamodel.Sequence; |
31 |
|
import jalview.datamodel.SequenceGroup; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.io.DataSourceType; |
34 |
|
import jalview.io.FileLoader; |
35 |
|
import jalview.util.MessageManager; |
36 |
|
import jalview.viewmodel.ViewportRanges; |
37 |
|
|
38 |
|
import java.awt.event.MouseEvent; |
39 |
|
|
40 |
|
import javax.swing.JMenuItem; |
41 |
|
import javax.swing.JPopupMenu; |
42 |
|
|
43 |
|
import org.testng.annotations.BeforeClass; |
44 |
|
import org.testng.annotations.Test; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (119) |
Complexity: 5 |
Complexity Density: 0.04 |
|
46 |
|
public class ScalePanelTest |
47 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
1 |
@BeforeClass(alwaysRun = true)... |
49 |
|
public void setUpJvOptionPane() |
50 |
|
{ |
51 |
1 |
JvOptionPane.setInteractiveMode(false); |
52 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
55 |
1 |
@Test(groups = "Functional")... |
56 |
|
public void testPreventNegativeStartColumn() |
57 |
|
{ |
58 |
1 |
SequenceI seq1 = new Sequence("Seq1", "MATRESS"); |
59 |
1 |
SequenceI seq2 = new Sequence("Seq2", "MADNESS"); |
60 |
1 |
AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); |
61 |
|
|
62 |
1 |
AlignFrame alignFrame = new AlignFrame(al, al.getWidth(), |
63 |
|
al.getHeight()); |
64 |
1 |
ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel(); |
65 |
|
|
66 |
1 |
MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, 4, 0, 1, false); |
67 |
|
|
68 |
|
|
69 |
1 |
assertEquals( |
70 |
|
alignFrame.alignPanel.getSeqPanel().findAlignmentColumn(mouse), |
71 |
|
0); |
72 |
|
|
73 |
1 |
scalePanel.mousePressed(mouse); |
74 |
1 |
scalePanel.mouseDragged(mouse); |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, -30, 0, 1, false); |
79 |
|
|
80 |
1 |
scalePanel.mouseReleased(mouse); |
81 |
|
|
82 |
1 |
SequenceGroup sg = scalePanel.av.getSelectionGroup(); |
83 |
1 |
int startCol = sg.getStartRes(); |
84 |
|
|
85 |
1 |
assertTrue(startCol >= 0); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
91 |
1 |
@Test(groups = "Functional")... |
92 |
|
public void testSelectColumns_withHidden() |
93 |
|
{ |
94 |
1 |
String seq1 = ">Seq1\nANTOFAGASTAVALPARAISOMONTEVIDEOANTANANARIVO"; |
95 |
1 |
AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seq1, |
96 |
|
DataSourceType.PASTE); |
97 |
1 |
ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel(); |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
1 |
AlignViewport viewport = alignFrame.getViewport(); |
105 |
1 |
ViewportRanges ranges = viewport.getRanges(); |
106 |
1 |
assertEquals(ranges.getStartRes(), 0); |
107 |
1 |
assertEquals(ranges.getEndRes(), 42); |
108 |
1 |
viewport.hideColumns(0, 19); |
109 |
1 |
alignFrame.alignPanel.updateLayout(); |
110 |
1 |
assertEquals(ranges.getStartRes(), 0); |
111 |
1 |
assertEquals(ranges.getEndRes(), 22); |
112 |
|
|
113 |
1 |
int cw = viewport.getCharWidth(); |
114 |
1 |
int xPos = 9 * cw + 2; |
115 |
1 |
MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, |
116 |
|
false); |
117 |
1 |
scalePanel.mousePressed(mouse); |
118 |
1 |
scalePanel.mouseDragged(mouse); |
119 |
1 |
xPos += cw; |
120 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
121 |
1 |
scalePanel.mouseReleased(mouse); |
122 |
|
|
123 |
1 |
SequenceGroup sg = scalePanel.av.getSelectionGroup(); |
124 |
1 |
assertEquals(sg.getStartRes(), 29); |
125 |
1 |
assertEquals(sg.getEndRes(), 30); |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (74) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
128 |
1 |
@Test(groups = "Functional")... |
129 |
|
public void testBuildPopupMenu() |
130 |
|
{ |
131 |
1 |
final String hide = MessageManager.getString("label.hide_columns"); |
132 |
1 |
final String reveal = MessageManager.getString("label.reveal"); |
133 |
1 |
final String revealAll = MessageManager.getString("action.reveal_all"); |
134 |
|
|
135 |
1 |
String seq1 = ">Seq1\nANTOFAGASTA"; |
136 |
1 |
AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seq1, |
137 |
|
DataSourceType.PASTE); |
138 |
1 |
ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel(); |
139 |
1 |
AlignViewport viewport = alignFrame.getViewport(); |
140 |
1 |
int cw = viewport.getCharWidth(); |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
1 |
viewport.hideColumns(3, 4); |
146 |
1 |
alignFrame.alignPanel.updateLayout(); |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
1 |
int xPos = 1 * cw + 2; |
153 |
1 |
MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, |
154 |
|
false); |
155 |
1 |
scalePanel.mouseMoved(mouse); |
156 |
1 |
JPopupMenu popup = scalePanel.buildPopupMenu(1); |
157 |
1 |
assertEquals(popup.getSubElements().length, 0); |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
1 |
xPos = 2 * cw + 2; |
163 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
164 |
1 |
scalePanel.mouseMoved(mouse); |
165 |
1 |
popup = scalePanel.buildPopupMenu(2); |
166 |
1 |
assertEquals(popup.getSubElements().length, 1); |
167 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal); |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
1 |
xPos = 3 * cw + 2; |
173 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
174 |
1 |
scalePanel.mouseMoved(mouse); |
175 |
1 |
popup = scalePanel.buildPopupMenu(5); |
176 |
1 |
assertEquals(popup.getSubElements().length, 1); |
177 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal); |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
1 |
xPos = 4 * cw + 2; |
183 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
184 |
1 |
scalePanel.mouseMoved(mouse); |
185 |
1 |
popup = scalePanel.buildPopupMenu(6); |
186 |
1 |
assertEquals(popup.getSubElements().length, 0); |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
1 |
xPos = 1 * cw + 2; |
192 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
193 |
1 |
scalePanel.mousePressed(mouse); |
194 |
1 |
scalePanel.mouseDragged(mouse); |
195 |
1 |
xPos = 5 * cw + 2; |
196 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
197 |
1 |
scalePanel.mouseReleased(mouse); |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
1 |
xPos = 1 * cw + 2; |
203 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
204 |
1 |
scalePanel.mouseMoved(mouse); |
205 |
1 |
popup = scalePanel.buildPopupMenu(1); |
206 |
1 |
assertEquals(popup.getSubElements().length, 1); |
207 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), hide); |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
1 |
xPos = 2 * cw + 2; |
213 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
214 |
1 |
scalePanel.mouseMoved(mouse); |
215 |
1 |
popup = scalePanel.buildPopupMenu(1); |
216 |
1 |
assertEquals(popup.getSubElements().length, 2); |
217 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal); |
218 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), hide); |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
1 |
xPos = 3 * cw + 2; |
224 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
225 |
1 |
scalePanel.mouseMoved(mouse); |
226 |
1 |
popup = scalePanel.buildPopupMenu(5); |
227 |
1 |
assertEquals(popup.getSubElements().length, 2); |
228 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal); |
229 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), hide); |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
1 |
viewport.hideColumns(6, 7); |
235 |
1 |
alignFrame.alignPanel.updateLayout(); |
236 |
1 |
xPos = 3 * cw + 2; |
237 |
1 |
mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false); |
238 |
1 |
scalePanel.mouseMoved(mouse); |
239 |
1 |
popup = scalePanel.buildPopupMenu(5); |
240 |
1 |
assertEquals(popup.getSubElements().length, 3); |
241 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal); |
242 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), |
243 |
|
revealAll); |
244 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[2]).getText(), hide); |
245 |
|
|
246 |
1 |
alignFrame.deselectAllSequenceMenuItem_actionPerformed(null); |
247 |
1 |
popup = scalePanel.buildPopupMenu(5); |
248 |
1 |
assertEquals(popup.getSubElements().length, 2); |
249 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal); |
250 |
1 |
assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), |
251 |
|
revealAll); |
252 |
|
} |
253 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
254 |
1 |
@BeforeClass(alwaysRun = true)... |
255 |
|
public static void setUpBeforeClass() throws Exception |
256 |
|
{ |
257 |
|
|
258 |
|
|
259 |
|
|
260 |
1 |
Cache.loadProperties("test/jalview/io/testProps.jvprops"); |
261 |
1 |
Jalview.main(new String[] { "--nonews" }); |
262 |
|
} |
263 |
|
|
264 |
|
} |