| 1 |
772 |
jeremybenn |
/* SynthLookAndFeel.java -- A skinnable Swing look and feel
|
| 2 |
|
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
| 3 |
|
|
|
| 4 |
|
|
This file is part of GNU Classpath.
|
| 5 |
|
|
|
| 6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
| 7 |
|
|
it under the terms of the GNU General Public License as published by
|
| 8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
| 9 |
|
|
any later version.
|
| 10 |
|
|
|
| 11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
| 12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
|
|
General Public License for more details.
|
| 15 |
|
|
|
| 16 |
|
|
You should have received a copy of the GNU General Public License
|
| 17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
| 18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
| 19 |
|
|
02110-1301 USA.
|
| 20 |
|
|
|
| 21 |
|
|
Linking this library statically or dynamically with other modules is
|
| 22 |
|
|
making a combined work based on this library. Thus, the terms and
|
| 23 |
|
|
conditions of the GNU General Public License cover the whole
|
| 24 |
|
|
combination.
|
| 25 |
|
|
|
| 26 |
|
|
As a special exception, the copyright holders of this library give you
|
| 27 |
|
|
permission to link this library with independent modules to produce an
|
| 28 |
|
|
executable, regardless of the license terms of these independent
|
| 29 |
|
|
modules, and to copy and distribute the resulting executable under
|
| 30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
| 31 |
|
|
independent module, the terms and conditions of the license of that
|
| 32 |
|
|
module. An independent module is a module which is not derived from
|
| 33 |
|
|
or based on this library. If you modify this library, you may extend
|
| 34 |
|
|
this exception to your version of the library, but you are not
|
| 35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
| 36 |
|
|
exception statement from your version. */
|
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
package javax.swing.plaf.synth;
|
| 40 |
|
|
|
| 41 |
|
|
import gnu.classpath.NotImplementedException;
|
| 42 |
|
|
|
| 43 |
|
|
import java.awt.Component;
|
| 44 |
|
|
import java.io.InputStream;
|
| 45 |
|
|
import java.text.ParseException;
|
| 46 |
|
|
|
| 47 |
|
|
import javax.swing.JComponent;
|
| 48 |
|
|
import javax.swing.UIDefaults;
|
| 49 |
|
|
import javax.swing.plaf.ComponentUI;
|
| 50 |
|
|
import javax.swing.plaf.basic.BasicLookAndFeel;
|
| 51 |
|
|
|
| 52 |
|
|
|
| 53 |
|
|
/**
|
| 54 |
|
|
* A look and feel that can be customized either by providing a file to
|
| 55 |
|
|
* {@link #load} or by setting a {@link SynthStyleFactory} using
|
| 56 |
|
|
* {@link #setStyleFactory}.
|
| 57 |
|
|
*
|
| 58 |
|
|
* @author Roman Kennke (kennke@aicas.com)
|
| 59 |
|
|
*
|
| 60 |
|
|
* @since 1.5
|
| 61 |
|
|
*/
|
| 62 |
|
|
public class SynthLookAndFeel
|
| 63 |
|
|
extends BasicLookAndFeel
|
| 64 |
|
|
{
|
| 65 |
|
|
|
| 66 |
|
|
/**
|
| 67 |
|
|
* The style factory that will be used by the UI classes to load their
|
| 68 |
|
|
* style sets from.
|
| 69 |
|
|
*/
|
| 70 |
|
|
private static SynthStyleFactory styleFactory;
|
| 71 |
|
|
|
| 72 |
|
|
/**
|
| 73 |
|
|
* Creates a new instance of <code>SynthLookAndFeel</code>. In order to use
|
| 74 |
|
|
* the Synth look and feel you either need to call {@link #load} to load a
|
| 75 |
|
|
* set of styles from an XML file, or you need to call
|
| 76 |
|
|
* {@link #setStyleFactory} to provide your own style factory.
|
| 77 |
|
|
*/
|
| 78 |
|
|
public SynthLookAndFeel()
|
| 79 |
|
|
{
|
| 80 |
|
|
// FIXME: What to do here, if anything?
|
| 81 |
|
|
}
|
| 82 |
|
|
|
| 83 |
|
|
/**
|
| 84 |
|
|
* Sets the style factory that the UI classes of Synth will use to load their
|
| 85 |
|
|
* sets of styles.
|
| 86 |
|
|
*
|
| 87 |
|
|
* @param sf the style factory to set
|
| 88 |
|
|
*/
|
| 89 |
|
|
public static void setStyleFactory(SynthStyleFactory sf)
|
| 90 |
|
|
{
|
| 91 |
|
|
styleFactory = sf;
|
| 92 |
|
|
}
|
| 93 |
|
|
|
| 94 |
|
|
/**
|
| 95 |
|
|
* Returns the current style factory that the UI classes of Synth will use to
|
| 96 |
|
|
* load their sets of styles.
|
| 97 |
|
|
*
|
| 98 |
|
|
* @return the current style factory
|
| 99 |
|
|
*/
|
| 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 |
|
|
* "Synth look and feel".
|
| 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 "Synth".
|
| 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 |
|
|
* "Synth look and feel".
|
| 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 |
|
|
}
|