001/* SynthLookAndFeel.java -- A skinnable Swing look and feel
002   Copyright (C) 2006 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.swing.plaf.synth;
040
041import gnu.classpath.NotImplementedException;
042
043import java.awt.Component;
044import java.io.InputStream;
045import java.text.ParseException;
046
047import javax.swing.JComponent;
048import javax.swing.UIDefaults;
049import javax.swing.plaf.ComponentUI;
050import javax.swing.plaf.basic.BasicLookAndFeel;
051
052
053/**
054 * A look and feel that can be customized either by providing a file to
055 * {@link #load} or by setting a {@link SynthStyleFactory} using
056 * {@link #setStyleFactory}.
057 *
058 * @author Roman Kennke (kennke@aicas.com)
059 *
060 * @since 1.5
061 */
062public class SynthLookAndFeel
063  extends BasicLookAndFeel
064{
065
066  /**
067   * The style factory that will be used by the UI classes to load their
068   * style sets from.
069   */
070  private static SynthStyleFactory styleFactory;
071
072  /**
073   * Creates a new instance of <code>SynthLookAndFeel</code>. In order to use
074   * the Synth look and feel you either need to call {@link #load} to load a
075   * set of styles from an XML file, or you need to call
076   * {@link #setStyleFactory} to provide your own style factory.
077   */
078  public SynthLookAndFeel()
079  {
080    // FIXME: What to do here, if anything?
081  }
082
083  /**
084   * Sets the style factory that the UI classes of Synth will use to load their
085   * sets of styles.
086   *
087   * @param sf the style factory to set
088   */
089  public static void setStyleFactory(SynthStyleFactory sf)
090  {
091    styleFactory = sf;
092  }
093
094  /**
095   * Returns the current style factory that the UI classes of Synth will use to
096   * load their sets of styles.
097   *
098   * @return the current style factory
099   */
100  public static SynthStyleFactory getStyleFactory()
101  {
102    return styleFactory;
103  }
104
105  /**
106   * Returns the style for the specified component and region.
107   *
108   * @param c the component for which to return the style
109   * @param r the region of the component for which to return the style
110   *
111   * @return the style for the specified component and region
112   */
113  public static SynthStyle getStyle(JComponent c, Region r)
114  {
115    return getStyleFactory().getStyle(c, r);
116  }
117
118  /**
119   * Updates all style information of the component and it's children.
120   *
121   * @param c the componenent for which to update the style
122   */
123  public static void updateStyles(Component c)
124    throws NotImplementedException
125  {
126    // FIXME: Implement this properly.
127  }
128
129  /**
130   * Returns the region for a given Swing component.
131   *
132   * @param c the Swing component for which to fetch the region
133   *
134   * @return the region for a given Swing component
135   */
136  public static Region getRegion(JComponent c)
137    throws NotImplementedException
138  {
139    // FIXME: This can be implemented as soon as we have the component UI
140    // classes in place, since this region will be matched via the UI classes.
141    return null;
142  }
143
144  /**
145   * Creates the Synth look and feel component UI instance for the given
146   * component.
147   *
148   * @param c the component for which to create a UI instance
149   *
150   * @return the Synth look and feel component UI instance for the given
151   *         component
152   */
153  public static ComponentUI createUI(JComponent c)
154    throws NotImplementedException
155  {
156    // FIXME: This can be implemented as soon as we have the component UI
157    // classes in place.
158    return null;
159  }
160
161  /**
162   * Initializes this look and feel.
163   */
164  public void initialize()
165    throws NotImplementedException
166  {
167    super.initialize();
168    // TODO: Implement at least the following here:
169    // if (styleFactory != null)
170    //   styleFactory = new DefaultStyleFactory();
171  }
172
173  /**
174   * Uninitializes the look and feel.
175   */
176  public void uninitialize()
177    throws NotImplementedException
178  {
179    super.uninitialize();
180    // TODO: What to do here?
181  }
182
183  /**
184   * Returns the UI defaults of this look and feel.
185   *
186   * @return the UI defaults of this look and feel
187   */
188  public UIDefaults getDefaults()
189    throws NotImplementedException
190  {
191    // FIXME: This is certainly wrong. The defaults should be fetched/merged
192    // from the file from which the l&f is loaded.
193    return super.getDefaults();
194  }
195
196  /**
197   * FIXME: DOCUMENT ME!
198   *
199   * @return FIXME
200   */
201  public boolean shouldUpdateStyleOnAncestorChanged()
202    throws NotImplementedException
203  {
204    return false;
205  }
206
207  /**
208   * Loads a set of {@link SynthStyle}s that are used for the look and feel of
209   * the components. The <code>resourceBase</code> parameter is used to resolve
210   * references against, like icons and other files.
211   *
212   * @param in the input stream from where to load the styles
213   * @param resourceBase the base against which references are resolved.
214   *
215   * @throws ParseException if the input stream cannot be parsed
216   * @throws IllegalArgumentException if one of the parameters is
217   *         <code>null</code>
218   */
219  public void load(InputStream in, Class<?> resourceBase)
220    throws ParseException, IllegalArgumentException, NotImplementedException
221  {
222    // FIXME: Implement this correctly.
223  }
224
225  /**
226   * Returns a textual description of the Synth look and feel. This returns
227   * &quot;Synth look and feel&quot;.
228   *
229   * @return a textual description of the Synth look and feel
230   */
231  public String getDescription()
232  {
233    return "Synth look and feel";
234  }
235
236  /**
237   * Returns the ID of the Synth look and feel. This returns &quot;Synth&quot;.
238   *
239   * @return the ID of the Synth look and feel
240   */
241  public String getID()
242  {
243    return "Synth";
244  }
245
246  /**
247   * Returns the name of the Synth look and feel. This returns
248   * &quot;Synth look and feel&quot;.
249   *
250   * @return the name of the Synth look and feel
251   */
252  public String getName()
253  {
254    return "Synth look and feel";
255  }
256
257  /**
258   * Returns <code>false</code> since the Synth look and feel is not a native
259   * look and feel.
260   *
261   * @return <code>false</code>
262   */
263  public boolean isNativeLookAndFeel()
264  {
265    return false;
266  }
267
268  /**
269   * Returns <code>true</code> since the Synth look and feel is always a
270   * supported look and feel.
271   *
272   * @return <code>true</code>
273   */
274  public boolean isSupportedLookAndFeel()
275  {
276    return true;
277  }
278
279}