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
16   81   8   4
8   41   0.5   4
4     2  
1    
 
  JTabbedPaneFormatter       Line # 33 16 0% 8 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Dec 24, 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   
24    import javax.swing.JTabbedPane;
25   
26    import org.fest.util.Arrays;
27   
28    /**
29    * Understands a formatter for <code>{@link JTabbedPane}</code>s.
30    *
31    * @author Alex Ruiz
32    */
 
33    public class JTabbedPaneFormatter extends ComponentFormatterTemplate {
34   
35    private static final String NO_SELECTION = "<No selection>";
36   
37    /**
38    * Returns the <code>String</code> representation of the given <code>{@link Component}</code>, which should be a
39    * <code>{@link JTabbedPane}</code> (or subclass.)
40    * @param c the given <code>Component</code>.
41    * @return the <code>String</code> representation of the given <code>JTabbedPane</code>.
42    */
 
43  16 toggle protected String doFormat(Component c) {
44  16 JTabbedPane tabbedPane = (JTabbedPane)c;
45  16 return concat(
46    tabbedPane.getClass().getName(), "[",
47    "name=", quote(tabbedPane.getName()), ", ",
48    "selectedTabIndex=", valueOf(tabbedPane.getSelectedIndex()), ", ",
49    "selectedTabTitle=", selectedTab(tabbedPane), ", ",
50    "tabCount=", valueOf(tabbedPane.getTabCount()), ", ",
51    "tabTitles=", Arrays.format(tabTitles(tabbedPane)), ", ",
52    "enabled=", valueOf(tabbedPane.isEnabled()), ", ",
53    "visible=", valueOf(tabbedPane.isVisible()), ", ",
54    "showing=", valueOf(tabbedPane.isShowing()),
55    "]"
56    );
57    }
58   
 
59  16 toggle private String selectedTab(JTabbedPane tabbedPane) {
60  1 if (tabbedPane.getTabCount() == 0) return NO_SELECTION;
61  15 int index = tabbedPane.getSelectedIndex();
62  1 if (index == -1) return NO_SELECTION;
63  14 return quote(tabbedPane.getTitleAt(index));
64    }
65   
 
66  16 toggle private String[] tabTitles(JTabbedPane tabbedPane) {
67  16 int count = tabbedPane.getTabCount();
68  1 if (count == 0) return new String[0];
69  15 String[] titles = new String[count];
70  26 for (int i = 0; i < count; i++) titles[i] = tabbedPane.getTitleAt(i);
71  15 return titles;
72    }
73   
74    /**
75    * Indicates that this formatter supports <code>{@link JTabbedPane}</code> only.
76    * @return <code>JTabbedPane.class</code>.
77    */
 
78  340 toggle public Class<? extends Component> targetType() {
79  340 return JTabbedPane.class;
80    }
81    }