MutableDisplayable.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * TheseFoolishThings: Miscellaneous utilities
  5.  * http://tidalwave.it/projects/thesefoolishthings
  6.  *
  7.  * Copyright (C) 2009 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *********************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  12.  * the License. You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
  23.  * git clone https://github.com/tidalwave-it/thesefoolishthings-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.role.ui;

  28. import javax.annotation.Nonnull;
  29. import java.beans.PropertyChangeListener;
  30. import java.util.Locale;
  31. import java.util.Map;
  32. import it.tidalwave.role.ui.impl.DefaultMutableDisplayable;

  33. /***********************************************************************************************************************
  34.  *
  35.  * A specialized {@link it.tidalwave.role.ui.Displayable} which is mutable (that is, its display name can be changed)
  36.  * and fires {@code PropertyChangeEvent}s.
  37.  *
  38.  * @stereotype Role
  39.  *
  40.  * @author  Fabrizio Giudici
  41.  * @it.tidalwave.javadoc.stable
  42.  *
  43.  **********************************************************************************************************************/
  44. public interface MutableDisplayable extends Displayable
  45.   {
  46.     public static final Class<MutableDisplayable> _MutableDisplayable_ = MutableDisplayable.class;

  47.     /** The property name for displayName */
  48.     public static final String PROP_DISPLAY_NAME = "displayName";

  49.     /** The property name for displayNames */
  50.     public static final String PROP_DISPLAY_NAMES = "displayNames";

  51.     /*******************************************************************************************************************
  52.      *
  53.      * Sets the display name in {@code Locale.ENGLISH}.
  54.      *
  55.      * @param  displayName  the display name
  56.      *
  57.      ******************************************************************************************************************/
  58.     public void setDisplayName (@Nonnull String displayName);

  59.     /*******************************************************************************************************************
  60.      *
  61.      * Sets the display name in the given {@code Locale}.
  62.      *
  63.      * @param  displayName  the display name
  64.      * @param  locale       the locale
  65.      *
  66.      ******************************************************************************************************************/
  67.     public void setDisplayName (@Nonnull String displayName, @Nonnull Locale locale);

  68.     /*******************************************************************************************************************
  69.      *
  70.      * Sets a bag of display names for a number of {@code Locale}s.
  71.      *
  72.      * @param  displayNames  the display names
  73.      *
  74.      ******************************************************************************************************************/
  75.     public void setDisplayNames (@Nonnull Map<Locale, String> displayNames);

  76.     /*******************************************************************************************************************
  77.      *
  78.      * Registers a {@link PropertyChangeListener}.
  79.      *
  80.      * @param  listener   the listener
  81.      *
  82.      ******************************************************************************************************************/
  83.     public void addPropertyChangeListener (@Nonnull PropertyChangeListener listener);

  84.     /*******************************************************************************************************************
  85.      *
  86.      * Unregisters a {@link PropertyChangeListener}.
  87.      *
  88.      * @param  listener   the listener
  89.      *
  90.      ******************************************************************************************************************/
  91.     public void removePropertyChangeListener (@Nonnull PropertyChangeListener listener);

  92.     /*******************************************************************************************************************
  93.      *
  94.      * Creates an instance with an initial given display name in {@code Locale.ENGLISH}.
  95.      *
  96.      * @param  displayName    the display name
  97.      * @return                the new instance
  98.      * @since                 3.2-ALPHA-1
  99.      *
  100.      ******************************************************************************************************************/
  101.     @Nonnull
  102.     public static MutableDisplayable of (@Nonnull final String displayName)
  103.       {
  104.         return of(displayName, "???");
  105.       }

  106.     /*******************************************************************************************************************
  107.      *
  108.      * Creates an instance with an initial given display name in {@code Locale.ENGLISH} and an explicit identifier for
  109.      * {@code toString()}.
  110.      *
  111.      * @param  displayName    the display name
  112.      * @param  toStringName   the name to be rendered when {@code toString()} is called
  113.      * @return                the new instance
  114.      * @since                 3.2-ALPHA-1
  115.      *
  116.      ******************************************************************************************************************/
  117.     @Nonnull
  118.     public static MutableDisplayable of (@Nonnull final String displayName, @Nonnull final String toStringName)
  119.       {
  120.         return new DefaultMutableDisplayable(displayName, toStringName);
  121.       }
  122.   }