001    /*
002     * Created on Dec 23, 2007
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005     * in compliance with the License. You may obtain a copy of the License at
006     *
007     * http://www.apache.org/licenses/LICENSE-2.0
008     *
009     * Unless required by applicable law or agreed to in writing, software distributed under the License
010     * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011     * or implied. See the License for the specific language governing permissions and limitations under
012     * the License.
013     *
014     * Copyright @2007-2010 the original author or authors.
015     */
016    package org.fest.swing.format;
017    
018    import static java.lang.String.valueOf;
019    import static org.fest.util.Strings.concat;
020    import static org.fest.util.Strings.quote;
021    
022    import java.awt.Component;
023    
024    import javax.swing.JTable;
025    
026    /**
027     * Understands a formatter for <code>{@link JTable}</code>s.
028     *
029     * @author Alex Ruiz
030     * @author Yvonne Wang
031     */
032    public class JTableFormatter extends ComponentFormatterTemplate {
033    
034      /**
035       * Returns the <code>String</code> representation of the given <code>{@link Component}</code>, which should be a
036       * <code>{@link JTable}</code> (or subclass.)
037       * @param c the given <code>Component</code>.
038       * @return the <code>String</code> representation of the given <code>JTable</code>.
039       */
040      protected String doFormat(Component c) {
041        JTable table = (JTable)c;
042        return concat(
043            table.getClass().getName(), "[",
044            "name=",        quote(table.getName()),          ", ",
045            "rowCount=",    valueOf(table.getRowCount()),    ", ",
046            "columnCount=", valueOf(table.getColumnCount()), ", ",
047            "enabled=",     valueOf(table.isEnabled()),      ", ",
048            "visible=",     valueOf(table.isVisible()),      ", ",
049            "showing=",     valueOf(table.isShowing()),
050            "]"
051        );
052      }
053    
054      /**
055       * Indicates that this formatter supports <code>{@link JTable}</code> only.
056       * @return <code>JTable.class</code>.
057       */
058      public Class<? extends Component> targetType() {
059        return JTable.class;
060      }
061    }