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 javax.swing.JFileChooser.*;
020 import static org.fest.util.Strings.concat;
021 import static org.fest.util.Strings.quote;
022
023 import java.awt.Component;
024
025 import javax.swing.JFileChooser;
026
027 /**
028 * Understands a formatter for <code>{@link JFileChooser}</code>s.
029 *
030 * @author Yvonne Wang
031 */
032 public class JFileChooserFormatter extends ComponentFormatterTemplate {
033
034 private static final IntEnum DIALOG_TYPES = new IntEnum();
035 static {
036 DIALOG_TYPES.put(OPEN_DIALOG, "OPEN_DIALOG")
037 .put(SAVE_DIALOG, "SAVE_DIALOG")
038 .put(CUSTOM_DIALOG, "CUSTOM_DIALOG");
039 }
040
041 /**
042 * Returns the <code>String</code> representation of the given <code>{@link Component}</code>, which should be a
043 * <code>{@link JFileChooser}</code> (or subclass.)
044 * @param c the given <code>Component</code>.
045 * @return the <code>String</code> representation of the given <code>JFileChooser</code>.
046 */
047 protected String doFormat(Component c) {
048 JFileChooser fileChooser = (JFileChooser)c;
049 return concat(
050 fileChooser.getClass().getName(), "[",
051 "name=", quote(fileChooser.getName()), ", ",
052 "dialogTitle=", quote(fileChooser.getDialogTitle()), ", ",
053 "dialogType=", DIALOG_TYPES.get(fileChooser.getDialogType()), ", ",
054 "currentDirectory=", fileChooser.getCurrentDirectory(), ", ",
055 "enabled=", valueOf(fileChooser.isEnabled()), ", ",
056 "visible=", valueOf(fileChooser.isVisible()), ", ",
057 "showing=", valueOf(fileChooser.isShowing()),
058 "]"
059 );
060 }
061
062 /**
063 * Indicates that this formatter supports <code>{@link JFileChooser}</code> only.
064 * @return <code>JFileChooser.class</code>.
065 */
066 public Class<? extends Component> targetType() {
067 return JFileChooser.class;
068 }
069 }