Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
25   93   13   3.57
12   63   0.52   7
7     1.86  
1    
2.2% of code in this file is excluded from these metrics.
 
  JListMatchingItemQuery       Line # 40 25 2.2% 13 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Oct 31, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.driver;
17   
18    import static java.util.Collections.sort;
19    import static org.fest.swing.driver.JListCellBoundsQuery.cellBounds;
20    import static org.fest.swing.driver.JListCellCenterQuery.cellCenter;
21    import static org.fest.swing.edt.GuiActionRunner.execute;
22   
23    import java.awt.Point;
24    import java.util.*;
25   
26    import javax.swing.JList;
27   
28    import org.fest.swing.annotation.RunsInCurrentThread;
29    import org.fest.swing.annotation.RunsInEDT;
30    import org.fest.swing.cell.JListCellReader;
31    import org.fest.swing.edt.GuiQuery;
32    import org.fest.swing.util.StringTextMatcher;
33    import org.fest.swing.util.TextMatcher;
34   
35    /**
36    * Understands lookup of the first item in a <code>{@link JList}</code> whose value matches a given one.
37    *
38    * @author Alex Ruiz
39    */
 
40    final class JListMatchingItemQuery {
41   
 
42  1 toggle @RunsInEDT
43    static Point centerOfMatchingItemCell(final JList list, final String value, final JListCellReader cellReader) {
44  1 return execute(new GuiQuery<Point>() {
 
45  1 toggle protected Point executeInEDT() {
46  1 int itemIndex = matchingItemIndex(list, new StringTextMatcher(value), cellReader);
47  1 return cellCenter(list, cellBounds(list, itemIndex));
48    }
49    });
50    }
51   
 
52  33 toggle @RunsInCurrentThread
53    static int matchingItemIndex(JList list, TextMatcher matcher, JListCellReader cellReader) {
54  33 int size = list.getModel().getSize();
55  100 for (int i = 0; i < size; i++)
56  26 if (matcher.isMatching(cellReader.valueAt(list, i))) return i;
57  7 return -1;
58    }
59   
 
60  16 toggle @RunsInEDT
61    static List<Integer> matchingItemIndices(final JList list, final TextMatcher matcher,
62    final JListCellReader cellReader) {
63  16 return execute(new GuiQuery<List<Integer>>() {
 
64  16 toggle protected List<Integer> executeInEDT() {
65  16 Set<Integer> indices = new HashSet<Integer>();
66  16 int size = list.getModel().getSize();
67  58 for (int i = 0; i < size; i++)
68  23 if (matcher.isMatching(cellReader.valueAt(list, i))) indices.add(i);
69  15 List<Integer> indexList = new ArrayList<Integer>(indices);
70  15 sort(indexList);
71  15 return indexList;
72    }
73    });
74    }
75   
 
76  12 toggle @RunsInEDT
77    static List<String> matchingItemValues(final JList list, final TextMatcher matcher,
78    final JListCellReader cellReader) {
79  12 return execute(new GuiQuery<List<String>>() {
 
80  12 toggle protected List<String> executeInEDT() {
81  12 List<String> values = new ArrayList<String>();
82  12 int size = list.getModel().getSize();
83  46 for (int i = 0; i < size; i++) {
84  34 String value = cellReader.valueAt(list, i);
85  19 if (matcher.isMatching(value)) values.add(value);
86    }
87  12 return values;
88    }
89    });
90    }
91   
 
92    toggle private JListMatchingItemQuery() {}
93    }