/** * Call the LookAndFeelFactory.installJideExtension using a specific class loader. This is used for GUI context * switch when going between two class loaders. * * @param newLoader ClassLoader */ public static void installJideExtension(ClassLoader newLoader) { installJideExtension(newLoader, false); }
/** * Install itself as UIManager.getLAFState().multiLookAndFeel to that calls to getUI() can be trapped */ public static void install() { try { // lafState = UIManager.getLAFState() method Method method = UIManager.class.getDeclaredMethod("getLAFState", new Class[]{null}); method.setAccessible(true); // turn off checking for private method Object lafState = method.invoke(null, new Object[]{null}); // lafState.multiLookAndFeel = new CacheCleanerLookAndFeel() Field field = lafState.getClass().getDeclaredField("multiLookAndFeel"); field.setAccessible(true); // turn off security checking CachedLookAndFeel laf = new CachedLookAndFeel(); field.set(lafState, laf); } catch (Exception e) { e.printStackTrace(); } }
public static void reinstallJideExtension() { installJideExtension(currentLoader, true); }
@Override public ComponentUI getUI(JComponent target) { UIDefaults defaults = UIManager.getDefaults(); // to increase the performance, UIManager is caching the // className <--> class definition object // It does not differentiate between classNames from different class loaders // This means that the cached class definition may not match the current // classloader and will cause ClassCastException later on. // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4675772 String className = (String) defaults.get(target.getUIClassID()); Class componentUIClass = className != null ? (Class) defaults.get(className) : null; ClassLoader componentUIClassLoader = componentUIClass != null ? componentUIClass.getClassLoader() : null; ClassLoader targetClassLoader = target.getClass().getClassLoader(); ClassLoader uiClassLoader = (ClassLoader) UIManager.get("ClassLoader"); if (targetClassLoader == null) { // for JMenuItem and JPopupMenu.Separator if (componentUIClassLoader != null && componentUIClassLoader != uiClassLoader) { removeCachedClass(defaults, componentUIClass); } return null; } if (targetClassLoader != componentUIClassLoader || targetClassLoader != uiClassLoader) { if (componentUIClassLoader != null) { removeCachedClass(defaults, componentUIClass); } installJideExtension(targetClassLoader); } return null; } }