All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.taxonomy.birds.impl.PatchedDefaultMutableDisplayable Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * blueBill Resources - open source birding
 * Copyright (C) 2009-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://bluebill.tidalwave.it
 * SCM: https://java.net/hg/bluebill~resources-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.taxonomy.birds.impl;

import it.tidalwave.role.MutableLocalizedDisplayable;
import javax.annotation.Nonnull;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;

/***********************************************************************************************************************
 *
 * @author Fabrizio Giudici
 * @version $Id$
 * @stable
 *
 **********************************************************************************************************************/
public class PatchedDefaultMutableDisplayable implements MutableLocalizedDisplayable
  {
    private static final long serialVersionUID = 45345436345634734L;

    @Nonnull
    private final String toStringName;

    @Nonnull
    private  final Map displayNameMap = new HashMap();

    private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

    private final Locale defaultLocale = Locale.ENGLISH;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public PatchedDefaultMutableDisplayable()
      {
        this.toStringName = "";
//        displayNameMap.put( defaultLocale, displayName);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    @Nonnull
    public String getDisplayName()
      {
        return getDisplayName(defaultLocale);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    @Nonnull
    public String getDisplayName (final @Nonnull Locale locale)
      {
        return displayNameMap.get(locale);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    @Nonnull
    public SortedSet getLocales()
      {
        return new TreeSet(displayNameMap.keySet());
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    @Nonnull
    public Map getDisplayNames()
      {
        return Collections.unmodifiableMap(displayNameMap);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    public void setDisplayName (final @Nonnull String displayName)
      {
        final String oldDisplayName = getDisplayName(defaultLocale);
        setDisplayName(displayName, defaultLocale);
        pcs.firePropertyChange(PROP_DISPLAY_NAME, oldDisplayName, displayName);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    public void setDisplayName (final @Nonnull String displayName, final @Nonnull Locale locale)
      {
        final Map oldDisplayNameMap = new HashMap(displayNameMap);
        displayNameMap.put(locale, displayName);
        pcs.firePropertyChange(PROP_DISPLAY_NAMES, oldDisplayNameMap, displayNameMap);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    public void setDisplayNames (final @Nonnull Map displayNames)
      {
        final Map oldDisplayNameMap = new HashMap(displayNameMap);
        displayNameMap.putAll(displayNames);
        pcs.firePropertyChange(PROP_DISPLAY_NAMES, oldDisplayNameMap, displayNameMap);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    public void addPropertyChangeListener (final @Nonnull PropertyChangeListener listener)
      {
        pcs.addPropertyChangeListener(listener);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    public void removePropertyChangeListener (final @Nonnull PropertyChangeListener listener)
      {
        pcs.removePropertyChangeListener(listener);
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
//    @Override
    @Nonnull
    public String toString()
      {
        return String.format("%s@%x$MutableDisplayable[]", toStringName, System.identityHashCode(this));
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy