2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.wm
.impl
;
18 import com
.intellij
.ide
.AppLifecycleListener
;
19 import com
.intellij
.ide
.DataManager
;
20 import com
.intellij
.ide
.actions
.CustomizeUIAction
;
21 import com
.intellij
.ide
.actions
.ViewToolbarAction
;
22 import com
.intellij
.ide
.plugins
.PluginManager
;
23 import com
.intellij
.ide
.ui
.UISettings
;
24 import com
.intellij
.ide
.ui
.UISettingsListener
;
25 import com
.intellij
.ide
.ui
.customization
.CustomActionsSchema
;
26 import com
.intellij
.openapi
.actionSystem
.*;
27 import com
.intellij
.openapi
.application
.Application
;
28 import com
.intellij
.openapi
.diagnostic
.Logger
;
29 import com
.intellij
.openapi
.extensions
.Extensions
;
30 import com
.intellij
.openapi
.keymap
.KeymapManager
;
31 import com
.intellij
.openapi
.project
.Project
;
32 import com
.intellij
.openapi
.util
.Comparing
;
33 import com
.intellij
.openapi
.util
.Disposer
;
34 import com
.intellij
.openapi
.util
.Ref
;
35 import com
.intellij
.openapi
.wm
.StatusBarCustomComponentFactory
;
36 import com
.intellij
.openapi
.wm
.ex
.StatusBarEx
;
37 import com
.intellij
.openapi
.wm
.impl
.status
.StatusBarImpl
;
38 import com
.intellij
.openapi
.wm
.impl
.welcomeScreen
.WelcomeScreen
;
39 import com
.intellij
.ui
.PopupHandler
;
40 import org
.jetbrains
.annotations
.Nullable
;
44 import java
.util
.ArrayList
;
45 import java
.util
.Arrays
;
46 import java
.util
.List
;
49 * @author Anton Katilin
50 * @author Vladimir Kondratyev
53 // Made public and non-final for Fabrique
54 public class IdeRootPane
extends JRootPane
{
55 private static final Logger LOG
= Logger
.getInstance("#com.intellij.openapi.wm.impl.IdeRootPane");
58 * Toolbar and status bar.
60 private JComponent myToolbar
;
61 private StatusBarImpl myStatusBar
;
63 private final Box myNorthPanel
= Box
.createVerticalBox();
64 private final List
<IdeRootPaneNorthExtension
> myNorthComponents
= new ArrayList
<IdeRootPaneNorthExtension
>();
67 * Current <code>ToolWindowsPane</code>. If there is no such pane then this field is null.
69 private ToolWindowsPane myToolWindowsPane
;
70 private final MyUISettingsListenerImpl myUISettingsListener
;
71 private JPanel myContentPane
;
72 private final ActionManager myActionManager
;
73 private final UISettings myUISettings
;
75 private static Component myWelcomePane
;
76 private final boolean myGlassPaneInitialized
;
77 private final IdeGlassPaneImpl myGlassPane
;
79 private final Application myApplication
;
81 IdeRootPane(ActionManager actionManager
, UISettings uiSettings
, DataManager dataManager
, KeymapManager keymapManager
,
82 final Application application
, final String
[] commandLineArgs
){
83 myActionManager
= actionManager
;
84 myUISettings
= uiSettings
;
87 myContentPane
.add(myNorthPanel
, BorderLayout
.NORTH
);
90 updateStatusBarVisibility();
92 myContentPane
.add(myStatusBar
, BorderLayout
.SOUTH
);
94 myUISettingsListener
=new MyUISettingsListenerImpl();
95 setJMenuBar(new IdeMenuBar(myActionManager
, dataManager
, keymapManager
));
97 final Ref
<Boolean
> willOpenProject
= new Ref
<Boolean
>(Boolean
.FALSE
);
98 final AppLifecycleListener lifecyclePublisher
= application
.getMessageBus().syncPublisher(AppLifecycleListener
.TOPIC
);
99 lifecyclePublisher
.appFrameCreated(commandLineArgs
, willOpenProject
);
100 LOG
.info("App initialization took " + (System
.nanoTime() - PluginManager
.startupStart
) / 1000000 + " ms");
101 PluginManager
.dumpPluginClassStatistics();
102 if (!willOpenProject
.get()) {
103 myWelcomePane
= WelcomeScreen
.createWelcomePanel();
104 myContentPane
.add(myWelcomePane
);
105 lifecyclePublisher
.welcomeScreenDisplayed();
108 myGlassPane
= new IdeGlassPaneImpl(this);
109 setGlassPane(myGlassPane
);
110 myGlassPaneInitialized
= true;
112 myGlassPane
.setVisible(false);
113 myApplication
= application
;
115 myStatusBar
.setCustomComponentsFactory(Arrays
.asList(StatusBarCustomComponentFactory
.EP_NAME
.getExtensions()));
120 public void setGlassPane(final Component glass
) {
121 if (myGlassPaneInitialized
) throw new IllegalStateException("Setting of glass pane for IdeFrame is prohibited");
122 super.setGlassPane(glass
);
126 * Invoked when enclosed frame is being shown.
128 public final void addNotify(){
130 myUISettings
.addUISettingsListener(myUISettingsListener
);
134 * Invoked when enclosed frame is being disposed.
136 public final void removeNotify(){
137 myUISettings
.removeUISettingsListener(myUISettingsListener
);
138 super.removeNotify();
142 * Sets current tool windows pane (panel where all tool windows are located).
143 * If <code>toolWindowsPane</code> is <code>null</code> then the method just removes
144 * the current tool windows pane.
146 final void setToolWindowsPane(final ToolWindowsPane toolWindowsPane
) {
147 final JComponent contentPane
= (JComponent
)getContentPane();
148 if(myToolWindowsPane
!= null){
149 contentPane
.remove(myToolWindowsPane
);
152 if (myWelcomePane
!= null) {
153 contentPane
.remove(myWelcomePane
);
154 myWelcomePane
= null;
157 myToolWindowsPane
= toolWindowsPane
;
158 if(myToolWindowsPane
!= null) {
159 contentPane
.add(myToolWindowsPane
,BorderLayout
.CENTER
);
161 else if (!myApplication
.isDisposeInProgress()) {
162 myWelcomePane
= WelcomeScreen
.createWelcomePanel();
163 contentPane
.add(myWelcomePane
);
166 contentPane
.revalidate();
169 protected final Container
createContentPane(){
170 myContentPane
= new JPanel(new BorderLayout());
171 myContentPane
.setBackground(Color
.GRAY
);
173 return myContentPane
;
176 void updateToolbar() {
177 if (myToolbar
!= null) {
178 myNorthPanel
.remove(myToolbar
);
180 myToolbar
= createToolbar();
181 myNorthPanel
.add(myToolbar
);
182 updateToolbarVisibility();
183 myContentPane
.revalidate();
186 void updateMainMenuActions(){
187 ((IdeMenuBar
)menuBar
).updateMenuActions();
191 private JComponent
createToolbar() {
192 ActionGroup group
= (ActionGroup
)CustomActionsSchema
.getInstance().getCorrectedAction(IdeActions
.GROUP_MAIN_TOOLBAR
);
193 final ActionToolbar toolBar
= myActionManager
.createActionToolbar(
194 ActionPlaces
.MAIN_TOOLBAR
,
198 toolBar
.setLayoutPolicy(ActionToolbar
.WRAP_LAYOUT_POLICY
);
200 DefaultActionGroup menuGroup
= new DefaultActionGroup();
201 menuGroup
.add(new ViewToolbarAction());
202 menuGroup
.add(new CustomizeUIAction());
203 PopupHandler
.installUnknownPopupHandler(toolBar
.getComponent(), menuGroup
, myActionManager
);
205 return toolBar
.getComponent();
208 private void createStatusBar() {
209 myStatusBar
= new StatusBarImpl(myUISettings
);
213 final StatusBarEx
getStatusBar() {
217 private void updateToolbarVisibility(){
218 myToolbar
.setVisible(myUISettings
.SHOW_MAIN_TOOLBAR
);
221 private void updateStatusBarVisibility(){
222 myStatusBar
.setVisible(myUISettings
.SHOW_STATUS_BAR
);
225 public void installNorthComponents(final Project project
) {
226 myNorthComponents
.addAll(Arrays
.asList(Extensions
.getExtensions(IdeRootPaneNorthExtension
.EP_NAME
, project
)));
227 for (IdeRootPaneNorthExtension northComponent
: myNorthComponents
) {
228 myNorthPanel
.add(northComponent
.getComponent());
229 northComponent
.uiSettingsChanged(myUISettings
);
233 public void deinstallNorthComponents(){
234 for (IdeRootPaneNorthExtension northComponent
: myNorthComponents
) {
235 myNorthPanel
.remove(northComponent
.getComponent());
236 Disposer
.dispose(northComponent
);
238 myNorthComponents
.clear();
241 public IdeRootPaneNorthExtension
findByName(String name
) {
242 for (IdeRootPaneNorthExtension northComponent
: myNorthComponents
) {
243 if (Comparing
.strEqual(name
, northComponent
.getKey())) {
244 return northComponent
;
250 private final class MyUISettingsListenerImpl
implements UISettingsListener
{
251 public final void uiSettingsChanged(final UISettings source
){
252 updateToolbarVisibility();
253 updateStatusBarVisibility();
254 for (IdeRootPaneNorthExtension component
: myNorthComponents
) {
255 component
.uiSettingsChanged(source
);
260 public boolean isOptimizedDrawingEnabled() {
261 return !myGlassPane
.hasPainters() && myGlassPane
.getComponentCount() == 0;