001 /*
002 * Created on Oct 21, 2008
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
005 * 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 is distributed on
010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011 * specific language governing permissions and limitations under the License.
012 *
013 * Copyright @2008-2010 the original author or authors.
014 */
015 package org.fest.swing.driver;
016
017 import java.awt.Component;
018
019 import javax.swing.JLabel;
020
021 import org.fest.swing.annotation.RunsInCurrentThread;
022
023 /**
024 * Understands a basic implementation of <code>{@link CellRendererReader}</code>.
025 *
026 * @author Alex Ruiz
027 */
028 public class BasicCellRendererReader implements CellRendererReader {
029
030 /**
031 * Reads the value in the given cell renderer component, or returns <code>null</code> if the renderer belongs to an
032 * unknown component type. Internally, this method will call <code>getText()</code> if the given renderer is an
033 * instance of <code>{@link JLabel}</code></li>.
034 * <p>
035 * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
036 * responsible for calling this method from the EDT.
037 * </p>
038 * @param c the given cell renderer component.
039 * @return the value of the given <code>Component</code>, or <code>null</code> if the renderer belongs to an unknown
040 * component type.
041 */
042 @RunsInCurrentThread
043 public String valueFrom(Component c) {
044 if (c instanceof JLabel) return ((JLabel)c).getText();
045 return null;
046 }
047 }