it.tidalwave.metadata.basic.provider.BasicFormatProvider Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueMarine Metadata - open source media workflow
* Copyright (C) 2007-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://bluemarine.tidalwave.it
* SCM: https://kenai.com/hg/bluemarine~metadata-src
*
**********************************************************************************************************************/
package it.tidalwave.metadata.basic.provider;
import java.util.HashMap;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Map;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import org.openide.util.NbBundle;
import it.tidalwave.metadata.text.ApertureFormat;
import it.tidalwave.metadata.text.EVFormat;
import it.tidalwave.metadata.text.FocalFormat;
import it.tidalwave.metadata.text.ISOFormat;
import it.tidalwave.metadata.text.ShutterFormat;
import it.tidalwave.metadata.basic.Basic;
import it.tidalwave.metadata.spi.MetadataItemFormatProvider;
import it.tidalwave.metadata.text.DimensionFormat;
import it.tidalwave.metadata.text.PixelCountFormat;
import javax.annotation.Nonnull;
/*******************************************************************************
*
* This class provides formatting capabilities for the {@link Basic} metadata
* item.
*
* @author Fabrizio Giudici
* @version $Id$
*
******************************************************************************/
public class BasicFormatProvider implements MetadataItemFormatProvider
{
private static final String DISPLAY_NAME = "Basic";
private final Map formatMap = new HashMap();
private final Class itemClass = Basic.class;
// FIXME: merge with MetadataItemFormatImpl
protected final static Format DEFAULT_FORMAT = new Format()
{
@Override
public StringBuffer format (final Object object, final StringBuffer toAppendTo, final FieldPosition pos)
{
toAppendTo.append((object != null) ? object.toString() : "");
return toAppendTo;
}
@Override
public Object parseObject (final String source, final ParsePosition pos)
{
pos.setIndex(pos.getIndex() + source.length() + 1);
return source;
}
};
public BasicFormatProvider()
{
// TODO: move to a configuration file? layer.xml or Bundle.properties?
}
@Nonnull
public Class getItemClass()
{
return itemClass;
}
@Nonnull
public final String getItemDisplayName()
{
return DISPLAY_NAME;
}
@Nonnull
public Format getFormat (@Nonnull final String propertyName)
{
Format format = formatMap.get(propertyName);
if (format == null)
{
format = DEFAULT_FORMAT;
}
return format;
}
@Nonnull
public String getDisplayName (@Nonnull final String propertyName)
{
try
{
return NbBundle.getMessage(BasicFormatProvider.class, capitalized(propertyName));
}
catch (MissingResourceException e)
{
return propertyName;
}
}
@Nonnull
private static String capitalized (@Nonnull final String string)
{
return string.substring(0, 1).toUpperCase(Locale.getDefault()) + string.substring(1);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy