private static void fixPopupSize(final Popup popup, final Component contents) { if (!UIUtil.isUnderGTKLookAndFeel() || !(contents instanceof JPopupMenu)) return; for (Class<?> aClass = popup.getClass(); aClass != null && Popup.class.isAssignableFrom(aClass); aClass = aClass.getSuperclass()) { try { final Method getComponent = aClass.getDeclaredMethod("getComponent"); getComponent.setAccessible(true); final Object component = getComponent.invoke(popup); if (component instanceof JWindow) { ((JWindow) component).setSize(new Dimension(0, 0)); } break; } catch (Exception ignored) { } } }
/** Sets current LAF. The method doesn't update component hierarchy. */ @Override public void setCurrentLookAndFeel(UIManager.LookAndFeelInfo lookAndFeelInfo) { if (findLaf(lookAndFeelInfo.getClassName()) == null) { LOG.error("unknown LookAndFeel : " + lookAndFeelInfo); return; } // Set L&F if (IdeaLookAndFeelInfo.CLASS_NAME.equals( lookAndFeelInfo.getClassName())) { // that is IDEA default LAF IdeaLaf laf = new IdeaLaf(); MetalLookAndFeel.setCurrentTheme(new IdeaBlueMetalTheme()); try { UIManager.setLookAndFeel(laf); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } else if (DarculaLookAndFeelInfo.CLASS_NAME.equals(lookAndFeelInfo.getClassName())) { DarculaLaf laf = new DarculaLaf(); try { UIManager.setLookAndFeel(laf); JBColor.setDark(true); IconLoader.setUseDarkIcons(true); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } else { // non default LAF try { LookAndFeel laf = ((LookAndFeel) Class.forName(lookAndFeelInfo.getClassName()).newInstance()); if (laf instanceof MetalLookAndFeel) { MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); } UIManager.setLookAndFeel(laf); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } myCurrentLaf = ObjectUtils.chooseNotNull(findLaf(lookAndFeelInfo.getClassName()), lookAndFeelInfo); checkLookAndFeel(lookAndFeelInfo, false); }
public static <Key, Psi extends PsiElement> Collection<Psi> safeGet( @NotNull StubIndexKey<Key, Psi> indexKey, @NotNull Key key, final Project project, final GlobalSearchScope scope, Class<Psi> requiredClass) { Collection<Psi> collection = getInstance().get(indexKey, key, project, scope); for (Iterator<Psi> iterator = collection.iterator(); iterator.hasNext(); ) { Psi psi = iterator.next(); if (!requiredClass.isInstance(psi)) { iterator.remove(); VirtualFile faultyContainer = PsiUtilCore.getVirtualFile(psi); LOG.error("Invalid stub element type in index: " + faultyContainer + ". found: " + psi); if (faultyContainer != null && faultyContainer.isValid()) { FileBasedIndex.getInstance().requestReindex(faultyContainer); } } } return collection; }