Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / LookAndFeel.java
blob1a67e849735245f53d9184148dafd2f8976681a1
1 /* LookAndFeel.java --
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package javax.swing;
41 import java.awt.Color;
42 import java.awt.Component;
43 import java.awt.Font;
44 import java.awt.Toolkit;
45 import java.net.URL;
47 import javax.swing.border.Border;
48 import javax.swing.plaf.ComponentInputMapUIResource;
49 import javax.swing.plaf.IconUIResource;
50 import javax.swing.plaf.InputMapUIResource;
51 import javax.swing.plaf.UIResource;
52 import javax.swing.text.JTextComponent;
54 public abstract class LookAndFeel
56 /**
57 * This method is called once by UIManager.setLookAndFeel to create
58 * the look and feel specific defaults table.
60 * @return the UI defaults
62 public UIDefaults getDefaults()
64 return null;
67 /**
68 * Returns a description of the look and feel.
70 * @return A description of the look and feel.
72 public abstract String getDescription();
74 public static Object getDesktopPropertyValue(String systemPropertyName,
75 Object fallbackValue)
77 Object value = Toolkit.getDefaultToolkit().getDesktopProperty(systemPropertyName);
78 return value != null ? value : fallbackValue;
81 /**
82 * Returns an identifier for the look and feel.
84 * @return An identifier for the look and feel.
86 public abstract String getID();
88 /**
89 * Returns the name for the look and feel.
91 * @return The name for the look and feel.
93 public abstract String getName();
95 /**
96 * Returns true when the Look and Feel supports window decorations,
97 * false others. This method returns always false and needs to be overwritten
98 * when the derived Look and Feel supports this.
100 * @return false
102 * @since 1.4
104 public boolean getSupportsWindowDecorations()
106 return false;
110 * UIManager.setLookAndFeel calls this method before the first call
111 * (and typically the only call) to getDefaults().
113 public void initialize()
115 // We do nothing here. This method is meant to be overridden by
116 // LookAndFeel implementations.
120 * Convenience method for installing a component's default Border object
121 * on the specified component if either the border is currently null
122 * or already an instance of UIResource.
124 public static void installBorder(JComponent c, String defaultBorderName)
126 Border b = c.getBorder();
127 if (b == null || b instanceof UIResource)
128 c.setBorder(UIManager.getBorder(defaultBorderName));
132 * Convenience method for initializing a component's foreground and
133 * background color properties with values from the current defaults table.
135 public static void installColors(JComponent c, String defaultBgName,
136 String defaultFgName)
138 // Install background.
139 Color bg = c.getBackground();
140 if (bg == null || bg instanceof UIResource)
141 c.setBackground(UIManager.getColor(defaultBgName));
143 // Install foreground.
144 Color fg = c.getForeground();
145 if (fg == null || fg instanceof UIResource)
146 c.setForeground(UIManager.getColor(defaultFgName));
150 * Convenience method for initializing a components foreground background
151 * and font properties with values from the current defaults table.
153 public static void installColorsAndFont(JComponent component,
154 String defaultBgName,
155 String defaultFgName,
156 String defaultFontName)
158 // Install colors.
159 installColors(component, defaultBgName, defaultFgName);
160 // Install font.
161 Font f = component.getFont();
162 if (f == null || f instanceof UIResource)
163 component.setFont(UIManager.getFont(defaultFontName));
167 * Returns <code>true</code> if the look and feel is the "native" look and
168 * feel for the current platform, and <code>false</code> otherwise.
170 * @return A flag indicating whether or not this is the native look and feel
171 * for the current platform.
173 public abstract boolean isNativeLookAndFeel();
176 * Returns <code>true</code> if the look and feel is supported on the
177 * current operating system, and <code>false</code> otherwise. This
178 * mechanism is provided so that it is possible to prevent a look and feel
179 * from being used on some operating systems (usually for legal, not
180 * technical, reasons).
182 * @return A flag indicating whether or not the look and feel is supported
183 * on the current platform.
185 public abstract boolean isSupportedLookAndFeel();
188 * Loads the bindings in keys into retMap. Does not remove existing entries
189 * from retMap. <code>keys</code> describes the InputMap, every even indexed
190 * item is either a KeyStroke or a String representing a KeyStroke and every
191 * odd indexed item is the Object associated with that KeyStroke in an
192 * ActionMap.
194 * @param retMap the InputMap into which we load bindings
195 * @param keys the Object array describing the InputMap as above
197 public static void loadKeyBindings(InputMap retMap, Object[] keys)
199 if (keys == null)
200 return;
201 for (int i = 0; i < keys.length - 1; i+= 2)
203 Object key = keys[i];
204 KeyStroke keyStroke;
205 if (key instanceof KeyStroke)
206 keyStroke = (KeyStroke)key;
207 else
208 keyStroke = KeyStroke.getKeyStroke((String)key);
209 retMap.put(keyStroke, keys[i+1]);
214 * Creates a ComponentInputMap from keys.
215 * <code>keys</code> describes the InputMap, every even indexed
216 * item is either a KeyStroke or a String representing a KeyStroke and every
217 * odd indexed item is the Object associated with that KeyStroke in an
218 * ActionMap.
220 * @param c the JComponent associated with the ComponentInputMap
221 * @param keys the Object array describing the InputMap as above
223 public static ComponentInputMap makeComponentInputMap(JComponent c,
224 Object[] keys)
226 ComponentInputMap retMap = new ComponentInputMapUIResource(c);
227 loadKeyBindings(retMap, keys);
228 return retMap;
232 * Utility method that creates a UIDefaults.LazyValue that creates an
233 * ImageIcon UIResource for the specified gifFile filename.
235 public static Object makeIcon(Class baseClass, String gifFile)
237 final URL file = baseClass.getResource(gifFile);
238 return new UIDefaults.LazyValue()
240 public Object createValue(UIDefaults table)
242 return new IconUIResource(new ImageIcon(file));
248 * Creates a InputMap from keys.
249 * <code>keys</code> describes the InputMap, every even indexed
250 * item is either a KeyStroke or a String representing a KeyStroke and every
251 * odd indexed item is the Object associated with that KeyStroke in an
252 * ActionMap.
254 * @param keys the Object array describing the InputMap as above
256 public static InputMap makeInputMap(Object[] keys)
258 InputMap retMap = new InputMapUIResource();
259 loadKeyBindings(retMap, keys);
260 return retMap;
264 * Convenience method for building lists of KeyBindings.
265 * <code>keyBindingList</code> is an array of KeyStroke-Action pairs where
266 * even indexed elements are KeyStrokes or Strings representing KeyStrokes
267 * and odd indexed elements are the associated Actions.
269 * @param keyBindingList the array of KeyStroke-Action pairs
270 * @return a JTextComponent.KeyBinding array
272 public static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList)
274 JTextComponent.KeyBinding[] retBindings =
275 new JTextComponent.KeyBinding[keyBindingList.length / 2];
276 for (int i = 0; i < keyBindingList.length - 1; i+= 2)
278 KeyStroke stroke;
279 if (keyBindingList[i] instanceof KeyStroke)
280 stroke = (KeyStroke)keyBindingList[i];
281 else
282 stroke = KeyStroke.getKeyStroke((String)keyBindingList[i]);
283 retBindings[i/2] = new JTextComponent.KeyBinding(stroke, (String)keyBindingList[i+1]);
285 return retBindings;
289 * Invoked when the user attempts an invalid operation. The default implement
290 * just beeps. Subclasses that wish to change this need to override this
291 * method.
293 * @param component the component the error occured in
295 public void provideErrorFeedback(Component component)
297 Toolkit.getDefaultToolkit().beep();
301 * Returns a string that displays and identifies this object's properties.
303 * @return the string "LookAndFeel"
305 public String toString()
307 return "LookAndFeel";
311 * UIManager.setLookAndFeel calls this method just before we're replaced by
312 * a new default look and feel.
314 public void uninitialize()
316 // We do nothing here. This method is meant to be overridden by
317 // LookAndFeel implementations.
321 * Convenience method for un-installing a component's default border on the
322 * specified component if the border is currently an instance of UIResource.
324 public static void uninstallBorder(JComponent c)
326 if (c.getBorder() instanceof UIResource)
327 c.setBorder(null);