204 * @param mui the <code>ComponentUI</code> object 205 * that represents the complete UI 206 * for the <code>target</code> component; 207 * this should be an instance 208 * of one of the <code>MultiXxxxUI</code> classes 209 * @param uis a <code>Vector</code>; 210 * generally this is the <code>uis</code> field 211 * of the <code>mui</code> argument 212 * @param target a component whose UI is represented by <code>mui</code> 213 * 214 * @return <code>mui</code> if the component has any auxiliary UI objects; 215 * otherwise, returns the UI object for the default look and feel 216 * or <code>null</code> if the default UI object couldn't be found 217 * 218 * @see javax.swing.UIManager#getAuxiliaryLookAndFeels 219 * @see javax.swing.UIDefaults#getUI 220 * @see MultiButtonUI#uis 221 * @see MultiButtonUI#createUI 222 */ 223 public static ComponentUI createUIs(ComponentUI mui, 224 Vector uis, 225 JComponent target) { 226 ComponentUI ui; 227 228 // Make sure we can at least get the default UI 229 // 230 ui = UIManager.getDefaults().getUI(target); 231 if (ui != null) { 232 uis.addElement(ui); 233 LookAndFeel[] auxiliaryLookAndFeels; 234 auxiliaryLookAndFeels = UIManager.getAuxiliaryLookAndFeels(); 235 if (auxiliaryLookAndFeels != null) { 236 for (int i = 0; i < auxiliaryLookAndFeels.length; i++) { 237 ui = auxiliaryLookAndFeels[i].getDefaults().getUI(target); 238 if (ui != null) { 239 uis.addElement(ui); 240 } 241 } 242 } 243 } else { 244 return null; 245 } 246 247 // Don't bother returning the multiplexing UI if all we did was 248 // get a UI from just the default look and feel. 249 // 250 if (uis.size() == 1) { 251 return (ComponentUI) uis.elementAt(0); 252 } else { 253 return mui; 254 } 255 } 256 257 /** 258 * Creates an array, 259 * populates it with UI objects from the passed-in vector, 260 * and returns the array. 261 * If <code>uis</code> is null, 262 * this method returns an array with zero elements. 263 * If <code>uis</code> is an empty vector, 264 * this method returns <code>null</code>. 265 * A run-time error occurs if any objects in the <code>uis</code> vector 266 * are not of type <code>ComponentUI</code>. 267 * 268 * @param uis a vector containing <code>ComponentUI</code> objects 269 * @return an array equivalent to the passed-in vector 270 * 271 */ 272 protected static ComponentUI[] uisToArray(Vector uis) { 273 if (uis == null) { 274 return new ComponentUI[0]; 275 } else { 276 int count = uis.size(); 277 if (count > 0) { 278 ComponentUI[] u = new ComponentUI[count]; 279 for (int i = 0; i < count; i++) { 280 u[i] = (ComponentUI)uis.elementAt(i); 281 } 282 return u; 283 } else { 284 return null; 285 } 286 } 287 } 288 } 289 290 /** 291 * We want the Multiplexing LookAndFeel to be quiet and fallback 292 * gracefully if it cannot find a UI. This class overrides the 293 * getUIError method of UIDefaults, which is the method that 294 * emits error messages when it cannot find a UI class in the 295 * LAF. 296 */ 297 @SuppressWarnings("serial") // Superclass is not serializable across versions 298 class MultiUIDefaults extends UIDefaults { 299 MultiUIDefaults(int initialCapacity, float loadFactor) { 300 super(initialCapacity, loadFactor); | 204 * @param mui the <code>ComponentUI</code> object 205 * that represents the complete UI 206 * for the <code>target</code> component; 207 * this should be an instance 208 * of one of the <code>MultiXxxxUI</code> classes 209 * @param uis a <code>Vector</code>; 210 * generally this is the <code>uis</code> field 211 * of the <code>mui</code> argument 212 * @param target a component whose UI is represented by <code>mui</code> 213 * 214 * @return <code>mui</code> if the component has any auxiliary UI objects; 215 * otherwise, returns the UI object for the default look and feel 216 * or <code>null</code> if the default UI object couldn't be found 217 * 218 * @see javax.swing.UIManager#getAuxiliaryLookAndFeels 219 * @see javax.swing.UIDefaults#getUI 220 * @see MultiButtonUI#uis 221 * @see MultiButtonUI#createUI 222 */ 223 public static ComponentUI createUIs(ComponentUI mui, 224 Vector<ComponentUI> uis, 225 JComponent target) { 226 ComponentUI ui; 227 228 // Make sure we can at least get the default UI 229 // 230 ui = UIManager.getDefaults().getUI(target); 231 if (ui != null) { 232 uis.addElement(ui); 233 LookAndFeel[] auxiliaryLookAndFeels; 234 auxiliaryLookAndFeels = UIManager.getAuxiliaryLookAndFeels(); 235 if (auxiliaryLookAndFeels != null) { 236 for (int i = 0; i < auxiliaryLookAndFeels.length; i++) { 237 ui = auxiliaryLookAndFeels[i].getDefaults().getUI(target); 238 if (ui != null) { 239 uis.addElement(ui); 240 } 241 } 242 } 243 } else { 244 return null; 245 } 246 247 // Don't bother returning the multiplexing UI if all we did was 248 // get a UI from just the default look and feel. 249 // 250 if (uis.size() == 1) { 251 return uis.elementAt(0); 252 } else { 253 return mui; 254 } 255 } 256 257 /** 258 * Creates an array, 259 * populates it with UI objects from the passed-in vector, 260 * and returns the array. 261 * If <code>uis</code> is null, 262 * this method returns an array with zero elements. 263 * If <code>uis</code> is an empty vector, 264 * this method returns <code>null</code>. 265 * A run-time error occurs if any objects in the <code>uis</code> vector 266 * are not of type <code>ComponentUI</code>. 267 * 268 * @param uis a vector containing <code>ComponentUI</code> objects 269 * @return an array equivalent to the passed-in vector 270 * 271 */ 272 protected static ComponentUI[] uisToArray(Vector<? extends ComponentUI> uis) { 273 if (uis == null) { 274 return new ComponentUI[0]; 275 } else { 276 int count = uis.size(); 277 if (count > 0) { 278 ComponentUI[] u = new ComponentUI[count]; 279 for (int i = 0; i < count; i++) { 280 u[i] = uis.elementAt(i); 281 } 282 return u; 283 } else { 284 return null; 285 } 286 } 287 } 288 } 289 290 /** 291 * We want the Multiplexing LookAndFeel to be quiet and fallback 292 * gracefully if it cannot find a UI. This class overrides the 293 * getUIError method of UIDefaults, which is the method that 294 * emits error messages when it cannot find a UI class in the 295 * LAF. 296 */ 297 @SuppressWarnings("serial") // Superclass is not serializable across versions 298 class MultiUIDefaults extends UIDefaults { 299 MultiUIDefaults(int initialCapacity, float loadFactor) { 300 super(initialCapacity, loadFactor); |