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
9   75   4   3
2   37   0.44   3
3     1.33  
1    
 
  JListFormatter       Line # 37 9 0% 4 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Dec 23, 2007
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 @2007-2010 the original author or authors.
15    */
16    package org.fest.swing.format;
17   
18    import static java.lang.String.valueOf;
19    import static org.fest.swing.format.SwingIntEnums.SELECTION_MODES;
20    import static org.fest.util.Strings.concat;
21    import static org.fest.util.Strings.quote;
22   
23    import java.awt.Component;
24    import java.util.ArrayList;
25    import java.util.List;
26   
27    import javax.swing.JList;
28    import javax.swing.ListModel;
29   
30    import org.fest.util.Arrays;
31   
32    /**
33    * Understands a formatter for <code>{@link JList}</code>s.
34    *
35    * @author Yvonne Wang
36    */
 
37    public class JListFormatter extends ComponentFormatterTemplate {
38   
39    /**
40    * Returns the <code>String</code> representation of the given <code>{@link Component}</code>, which should be a
41    * <code>{@link JList}</code> (or subclass.)
42    * @param c the given <code>Component</code>.
43    * @return the <code>String</code> representation of the given <code>JList</code>.
44    */
 
45  71 toggle protected String doFormat(Component c) {
46  71 JList list = (JList)c;
47  71 return concat(
48    list.getClass().getName(), "[",
49    "name=", quote(list.getName()), ", ",
50    "selectedValues=", Arrays.format(list.getSelectedValues()), ", ",
51    "contents=", Arrays.format(contentsOf(list)), ", ",
52    "selectionMode=", SELECTION_MODES.get(list.getSelectionMode()), ", ",
53    "enabled=", valueOf(list.isEnabled()), ", ",
54    "visible=", valueOf(list.isVisible()), ", ",
55    "showing=", valueOf(list.isShowing()),
56    "]"
57    );
58    }
59   
 
60  71 toggle private Object[] contentsOf(JList list) {
61  71 List<Object> contents = new ArrayList<Object>();
62  71 ListModel model = list.getModel();
63  71 int size = model.getSize();
64  337 for (int i = 0; i < size; i++) contents.add(model.getElementAt(i));
65  71 return contents.toArray();
66    }
67   
68    /**
69    * Indicates that this formatter supports <code>{@link JList}</code> only.
70    * @return <code>JList.class</code>.
71    */
 
72  395 toggle public Class<? extends Component> targetType() {
73  395 return JList.class;
74    }
75    }