Ejemplo n.º 1
0
 void updateToolbar() {
   if (myToolbar != null) {
     myNorthPanel.remove(myToolbar);
   }
   myToolbar = createToolbar();
   myNorthPanel.add(myToolbar);
   updateToolbarVisibility();
   myContentPane.revalidate();
 }
Ejemplo n.º 2
0
 public void deinstallNorthComponents() {
   for (IdeRootPaneNorthExtension northComponent : myNorthComponents) {
     myNorthPanel.remove(northComponent.getComponent());
     Disposer.dispose(northComponent);
   }
   myNorthComponents.clear();
 }
Ejemplo n.º 3
0
 public void installNorthComponents(final Project project) {
   ContainerUtil.addAll(
       myNorthComponents, Extensions.getExtensions(IdeRootPaneNorthExtension.EP_NAME, project));
   for (IdeRootPaneNorthExtension northComponent : myNorthComponents) {
     myNorthPanel.add(northComponent.getComponent());
     northComponent.uiSettingsChanged(myUISettings);
   }
 }
Ejemplo n.º 4
0
// Made public and non-final for Fabrique
public class IdeRootPane extends JRootPane implements UISettingsListener {
  private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.wm.impl.IdeRootPane");

  /** Toolbar and status bar. */
  private JComponent myToolbar;

  private IdeStatusBarImpl myStatusBar;

  private final Box myNorthPanel = Box.createVerticalBox();
  private final List<IdeRootPaneNorthExtension> myNorthComponents =
      new ArrayList<IdeRootPaneNorthExtension>();

  /** Current <code>ToolWindowsPane</code>. If there is no such pane then this field is null. */
  private ToolWindowsPane myToolWindowsPane;

  private final MyUISettingsListenerImpl myUISettingsListener;
  private JPanel myContentPane;
  private final ActionManager myActionManager;
  private final UISettings myUISettings;

  private static WelcomeScreen myWelcomeScreen;
  private static Component myWelcomePane;
  private final boolean myGlassPaneInitialized;
  private final IdeGlassPaneImpl myGlassPane;

  private final Application myApplication;
  private MemoryUsagePanel myMemoryWidget;
  private final StatusBarCustomComponentFactory[] myStatusBarCustomComponentFactories;
  private final Disposable myDisposable = Disposer.newDisposable();

  IdeRootPane(
      ActionManagerEx actionManager,
      UISettings uiSettings,
      DataManager dataManager,
      final Application application,
      final String[] commandLineArgs,
      IdeFrame frame) {
    myActionManager = actionManager;
    myUISettings = uiSettings;

    updateToolbar();
    myContentPane.add(myNorthPanel, BorderLayout.NORTH);

    myStatusBarCustomComponentFactories =
        application.getExtensions(StatusBarCustomComponentFactory.EP_NAME);
    myApplication = application;

    createStatusBar(frame);

    updateStatusBarVisibility();

    myContentPane.add(myStatusBar, BorderLayout.SOUTH);

    myUISettingsListener = new MyUISettingsListenerImpl();
    setJMenuBar(new IdeMenuBar(actionManager, dataManager));

    final Ref<Boolean> willOpenProject = new Ref<Boolean>(Boolean.FALSE);
    final AppLifecycleListener lifecyclePublisher =
        application.getMessageBus().syncPublisher(AppLifecycleListener.TOPIC);
    lifecyclePublisher.appFrameCreated(commandLineArgs, willOpenProject);
    LOG.info(
        "App initialization took "
            + (System.nanoTime() - PluginManager.startupStart) / 1000000
            + " ms");
    PluginManager.dumpPluginClassStatistics();
    if (!willOpenProject.get()) {
      showWelcomeScreen();
      lifecyclePublisher.welcomeScreenDisplayed();
    }

    myGlassPane = new IdeGlassPaneImpl(this);
    setGlassPane(myGlassPane);
    myGlassPaneInitialized = true;

    myGlassPane.setVisible(false);
    Disposer.register(application, myDisposable);
  }

  private void showWelcomeScreen() {
    myWelcomeScreen = new WelcomeScreen(this);
    Disposer.register(myDisposable, myWelcomeScreen);
    myWelcomePane = myWelcomeScreen.getWelcomePanel();
    myContentPane.add(myWelcomePane);
    updateToolbarVisibility();
  }

  public void setGlassPane(final Component glass) {
    if (myGlassPaneInitialized)
      throw new IllegalStateException("Setting of glass pane for IdeFrame is prohibited");
    super.setGlassPane(glass);
  }

  /** Invoked when enclosed frame is being shown. */
  public final void addNotify() {
    super.addNotify();
    myUISettings.addUISettingsListener(myUISettingsListener, myDisposable);
  }

  /** Invoked when enclosed frame is being disposed. */
  public final void removeNotify() {
    Disposer.dispose(myDisposable);
    super.removeNotify();
  }

  /**
   * Sets current tool windows pane (panel where all tool windows are located). If <code>
   * toolWindowsPane</code> is <code>null</code> then the method just removes the current tool
   * windows pane.
   */
  final void setToolWindowsPane(@Nullable final ToolWindowsPane toolWindowsPane) {
    final JComponent contentPane = (JComponent) getContentPane();
    if (myToolWindowsPane != null) {
      contentPane.remove(myToolWindowsPane);
    }

    hideWelcomeScreen(contentPane);

    myToolWindowsPane = toolWindowsPane;
    if (myToolWindowsPane != null) {
      contentPane.add(myToolWindowsPane, BorderLayout.CENTER);
    } else if (!myApplication.isDisposeInProgress()) {
      showWelcomeScreen();
    }

    contentPane.revalidate();
  }

  private void hideWelcomeScreen(JComponent contentPane) {
    if (myWelcomePane != null) {
      Disposer.dispose(myWelcomeScreen);
      contentPane.remove(myWelcomePane);
      myWelcomeScreen = null;
      myWelcomePane = null;
      updateToolbarVisibility();
    }
  }

  protected final Container createContentPane() {
    myContentPane = new JPanel(new BorderLayout());
    myContentPane.setBackground(Color.GRAY);

    return myContentPane;
  }

  void updateToolbar() {
    if (myToolbar != null) {
      myNorthPanel.remove(myToolbar);
    }
    myToolbar = createToolbar();
    myNorthPanel.add(myToolbar);
    updateToolbarVisibility();
    myContentPane.revalidate();
  }

  void updateMainMenuActions() {
    ((IdeMenuBar) menuBar).updateMenuActions();
    menuBar.repaint();
  }

  private JComponent createToolbar() {
    ActionGroup group =
        (ActionGroup)
            CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
    final ActionToolbar toolBar =
        myActionManager.createActionToolbar(ActionPlaces.MAIN_TOOLBAR, group, true);
    toolBar.setLayoutPolicy(ActionToolbar.WRAP_LAYOUT_POLICY);

    DefaultActionGroup menuGroup = new DefaultActionGroup();
    menuGroup.add(new ViewToolbarAction());
    menuGroup.add(new CustomizeUIAction());
    PopupHandler.installUnknownPopupHandler(toolBar.getComponent(), menuGroup, myActionManager);

    return toolBar.getComponent();
  }

  private void createStatusBar(IdeFrame frame) {
    myUISettings.addUISettingsListener(this, myApplication);

    myStatusBar = new IdeStatusBarImpl();
    myStatusBar.install(frame);

    myMemoryWidget = new MemoryUsagePanel();

    if (myStatusBarCustomComponentFactories != null) {
      for (final StatusBarCustomComponentFactory<JComponent> componentFactory :
          myStatusBarCustomComponentFactories) {
        final JComponent c = componentFactory.createComponent(myStatusBar);
        myStatusBar.addWidget(
            new CustomStatusBarWidget() {
              public JComponent getComponent() {
                return c;
              }

              @NotNull
              public String ID() {
                return c.getClass().getSimpleName();
              }

              public WidgetPresentation getPresentation(@NotNull PlatformType type) {
                return null;
              }

              public void install(@NotNull StatusBar statusBar) {}

              public void dispose() {
                componentFactory.disposeComponent(myStatusBar, c);
              }
            },
            "before " + MemoryUsagePanel.WIDGET_ID);
      }
    }

    myStatusBar.addWidget(myMemoryWidget);
    myStatusBar.addWidget(
        new IdeMessagePanel(MessagePool.getInstance()), "before " + MemoryUsagePanel.WIDGET_ID);

    setMemoryIndicatorVisible(myUISettings.SHOW_MEMORY_INDICATOR);
  }

  void setMemoryIndicatorVisible(final boolean visible) {
    if (myMemoryWidget != null) {
      myMemoryWidget.setShowing(visible);
      if (!SystemInfo.isMac) {
        myStatusBar.setBorder(BorderFactory.createEmptyBorder(1, 4, 0, visible ? 0 : 2));
      }
    }
  }

  @Nullable
  final StatusBar getStatusBar() {
    return myStatusBar;
  }

  private void updateToolbarVisibility() {
    myToolbar.setVisible(myUISettings.SHOW_MAIN_TOOLBAR && myWelcomeScreen == null);
  }

  private void updateStatusBarVisibility() {
    myStatusBar.setVisible(myUISettings.SHOW_STATUS_BAR);
  }

  public void installNorthComponents(final Project project) {
    ContainerUtil.addAll(
        myNorthComponents, Extensions.getExtensions(IdeRootPaneNorthExtension.EP_NAME, project));
    for (IdeRootPaneNorthExtension northComponent : myNorthComponents) {
      myNorthPanel.add(northComponent.getComponent());
      northComponent.uiSettingsChanged(myUISettings);
    }
  }

  public void deinstallNorthComponents() {
    for (IdeRootPaneNorthExtension northComponent : myNorthComponents) {
      myNorthPanel.remove(northComponent.getComponent());
      Disposer.dispose(northComponent);
    }
    myNorthComponents.clear();
  }

  public IdeRootPaneNorthExtension findByName(String name) {
    for (IdeRootPaneNorthExtension northComponent : myNorthComponents) {
      if (Comparing.strEqual(name, northComponent.getKey())) {
        return northComponent;
      }
    }
    return null;
  }

  public void uiSettingsChanged(UISettings source) {
    setMemoryIndicatorVisible(source.SHOW_MEMORY_INDICATOR);
  }

  private final class MyUISettingsListenerImpl implements UISettingsListener {
    public final void uiSettingsChanged(final UISettings source) {
      updateToolbarVisibility();
      updateStatusBarVisibility();
      for (IdeRootPaneNorthExtension component : myNorthComponents) {
        component.uiSettingsChanged(source);
      }
    }
  }

  public boolean isOptimizedDrawingEnabled() {
    return !myGlassPane.hasPainters() && myGlassPane.getComponentCount() == 0;
  }
}