001    package echopoint.style;
002    
003    import static echopoint.util.ColorKit.makeColor;
004    import static nextapp.echo.app.Component.PROPERTY_FONT;
005    import static nextapp.echo.app.Component.PROPERTY_FOREGROUND;
006    import nextapp.echo.app.MutableStyle;
007    
008    import java.util.logging.Level;
009    import java.util.logging.Logger;
010    
011    /**
012     * Abstract base class from which all style classes are derived.  Primarily
013     * delegates to the {@link #init} method for configuration.
014     *
015     * @author Rakesh 2009-05-12
016     * @version $Id: AbstractStyle.java 208 2009-05-25 02:40:35Z sptrakesh $
017     */
018    public abstract class AbstractStyle extends MutableStyle
019    {
020      /** The logger to use to log messages. */
021      protected static final Logger logger = Logger.getAnonymousLogger();
022    
023      /** The log level to use to log missing style messages. */
024      protected final Level level = Level.FINE;
025    
026      /** Default constructor.  Over-ridden to invoke {@link #init}. */
027      public AbstractStyle()
028      {
029        init();
030      }
031    
032      /**
033       * Mandatory style initialisation method to be implemented by all
034       * sub-classes.  The default implementation sets the default font to use.
035       * Sub-classes should generally invoke {@code super.init()}.
036       *
037       * @see echopoint.style.DefaultFont
038       * @see #setFont
039       */
040      protected void init()
041      {
042        setFont();
043        setForeground();
044      }
045    
046      /** Set the default font to be used for all components. */
047      protected void setFont()
048      {
049        set( PROPERTY_FONT, DefaultFont.getInstance() );
050      }
051    
052      /** Set the default foreground colour for all components. */
053      protected void setForeground()
054      {
055        set( PROPERTY_FOREGROUND, makeColor( "#000000" ) );
056      }
057    
058      /**
059       * Over-ridden to log missing property requests.
060       *
061       * @param name The name of the property to use to retrieve style.
062       * @return Object The appropriate instance of Style.
063       */
064      @Override
065      public Object get( String name )
066      {
067        Object object = super.get( name );
068    
069        if ( object == null )
070        {
071          if ( logger.isLoggable( level ) )
072          {
073            logger.log( level, "No style class defined with name " + name );
074          }
075        }
076    
077        return object;
078      }
079    }