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
8   72   4   2.67
2   34   0.5   3
3     1.33  
1    
 
  JComboBoxFormatter       Line # 35 8 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.util.Strings.concat;
20    import static org.fest.util.Strings.quote;
21   
22    import java.awt.Component;
23    import java.util.ArrayList;
24    import java.util.List;
25   
26    import javax.swing.JComboBox;
27   
28    import org.fest.util.Arrays;
29   
30    /**
31    * Understands a formatter for <code>{@link JComboBox}</code>es.
32    *
33    * @author Yvonne Wang
34    */
 
35    public class JComboBoxFormatter extends ComponentFormatterTemplate {
36   
37    /**
38    * Returns the <code>String</code> representation of the given <code>{@link Component}</code>, which should be a
39    * <code>{@link JComboBox}</code> (or subclass.)
40    * @param c the given <code>Component</code>.
41    * @return the <code>String</code> representation of the given <code>JComboBox</code>.
42    */
 
43  41 toggle protected String doFormat(Component c) {
44  41 JComboBox comboBox = (JComboBox)c;
45  41 return concat(
46    comboBox.getClass().getName(), "[",
47    "name=", quote(comboBox.getName()), ", ",
48    "selectedItem=", quote(comboBox.getSelectedItem()), ", ",
49    "contents=", Arrays.format(contentsOf(comboBox)), ", ",
50    "editable=", valueOf(comboBox.isEditable()), ", ",
51    "enabled=", valueOf(comboBox.isEnabled()), ", ",
52    "visible=", valueOf(comboBox.isVisible()), ", ",
53    "showing=", valueOf(comboBox.isShowing()),
54    "]"
55    );
56    }
57   
 
58  41 toggle private Object[] contentsOf(final JComboBox comboBox) {
59  41 List<Object> contents = new ArrayList<Object>();
60  41 int count = comboBox.getItemCount();
61  167 for (int i = 0; i < count; i++) contents.add(comboBox.getItemAt(i));
62  41 return contents.toArray();
63    }
64   
65    /**
66    * Indicates that this formatter supports <code>{@link JComboBox}</code> only.
67    * @return <code>JComboBox.class</code>.
68    */
 
69  366 toggle public Class<? extends Component> targetType() {
70  366 return JComboBox.class;
71    }
72    }