001    /* SynthStyle.java -- A set of style properties
002       Copyright (C) 2006 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package javax.swing.plaf.synth;
040    
041    import gnu.classpath.NotImplementedException;
042    
043    import java.awt.Color;
044    import java.awt.Font;
045    import java.awt.Insets;
046    
047    import javax.swing.Icon;
048    
049    /**
050     * A set of style properties that can be installed on a component.
051     *
052     * @author Roman Kennke (kennke@aicas.com)
053     *
054     * @since 1.5
055     */
056    public abstract class SynthStyle
057    {
058    
059      /**
060       * Creates a new <code>SynthStyle</code> object.
061       */
062      public SynthStyle()
063        throws NotImplementedException
064      {
065        // FIXME: Implement this correctly.
066      }
067    
068      public SynthGraphicsUtils getGraphicsUtils(SynthContext ctx)
069        throws NotImplementedException
070      {
071        // FIXME: Implement this correctly.
072        return null;
073      }
074    
075      public Color getColor(SynthContext ctx, ColorType type)
076        throws NotImplementedException
077      {
078        // FIXME: Implement this correctly.
079        return null;
080      }
081    
082      protected abstract Color getColorForState(SynthContext ctx, ColorType type);
083    
084      public Font getFont(SynthContext ctx)
085        throws NotImplementedException
086      {
087        // FIXME: Implement this correctly.
088        return null;
089      }
090    
091      protected abstract Font getFontForState(SynthContext ctx);
092    
093      public Insets getInsets(SynthContext ctx, Insets result)
094        throws NotImplementedException
095      {
096        // FIXME: Implement this correctly.
097        return null;
098      }
099    
100      public SynthPainter getPainter(SynthContext ctx)
101        throws NotImplementedException
102      {
103        // FIXME: Implement this correctly.
104        return null;
105      }
106    
107      public boolean isOpaque(SynthContext ctx)
108        throws NotImplementedException
109      {
110        // FIXME: Implement this correctly.
111        return true;
112      }
113    
114      public Object get(SynthContext ctx, Object key)
115        throws NotImplementedException
116      {
117        // FIXME: Implement this correctly.
118        return null;
119      }
120    
121      public void installDefaults(SynthContext ctx)
122        throws NotImplementedException
123      {
124        // FIXME: Implement this correctly.
125      }
126    
127      public void uninstallDefaults(SynthContext ctx)
128        throws NotImplementedException
129      {
130        // FIXME: Implement this correctly.
131      }
132    
133      /**
134       * A convenience method to fetch an integer property.
135       * If the property's value is a {@link Number}, then the
136       * integer value is returned.  Otherwise, the default value
137       * is returned.
138       * @param ctx the context
139       * @param key the key to fetch
140       * @param defaultValue the default value
141       * @return the integer value of the property, or the default value
142       */
143      public int getInt(SynthContext ctx, Object key, int defaultValue)
144      {
145        Object obj = get(ctx, key);
146        if (obj instanceof Number)
147          return ((Number) obj).intValue();
148        return defaultValue;
149      }
150    
151      /**
152       * A convenience method to fetch an integer property.
153       * If the property's value is a {@link Boolean}, then the
154       * value is returned.  Otherwise, the default value
155       * is returned.
156       * @param ctx the context
157       * @param key the key to fetch
158       * @param defaultValue the default value
159       * @return the boolean value of the property, or the default value
160       */
161      public boolean getBoolean(SynthContext ctx, Object key,
162                                boolean defaultValue)
163      {
164        Object obj = get(ctx, key);
165        if (obj instanceof Boolean)
166          return ((Boolean) obj).booleanValue();
167        return defaultValue;
168      }
169    
170      /**
171       * A convenience method to fetch an Icon-valued property.
172       * If the property's value is an {@link Icon}, then the
173       * value is returned.  Otherwise, null is returned.
174       * @param ctx the context
175       * @param key the key to fetch
176       * @return the icon, or null
177       */
178      public Icon getIcon(SynthContext ctx, Object key)
179      {
180        Object obj = get(ctx, key);
181        if (key instanceof Icon)
182          return (Icon) obj;
183        return null;
184      }
185    
186      /**
187       * A convenience method to fetch a String property.
188       * If the property's value is a {@link String}, then the
189       * value is returned.  Otherwise, the default value
190       * is returned.
191       * @param ctx the context
192       * @param key the key to fetch
193       * @param defaultValue the default value
194       * @return the String value of the property, or the default value
195       */
196      public String getString(SynthContext ctx, Object key, String defaultValue)
197      {
198        Object obj = get(ctx, key);
199        if (obj instanceof String)
200          return (String) obj;
201        return defaultValue;
202      }
203    }