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
.content
;
18 import com
.intellij
.openapi
.ui
.popup
.ListPopup
;
19 import com
.intellij
.openapi
.wm
.impl
.TitlePanel
;
20 import com
.intellij
.ui
.content
.ContentManagerEvent
;
23 import java
.awt
.geom
.GeneralPath
;
25 class ComboContentLayout
extends ContentLayout
{
28 ContentComboLabel myComboLabel
;
30 ComboContentLayout(ToolWindowContentUi ui
) {
38 myIdLabel
= new BaseLabel(myUi
, false);
39 myComboLabel
= new ContentComboLabel(this);
49 public void layout() {
50 Rectangle bounds
= myUi
.getBounds();
51 Dimension idSize
= myIdLabel
.getPreferredSize();
54 int eachY
= TitlePanel
.STRUT
;
56 myIdLabel
.setBounds(eachX
, eachY
, idSize
.width
, bounds
.height
);
57 eachX
+= idSize
.width
;
59 Dimension comboSize
= myComboLabel
.getPreferredSize();
60 int spaceLeft
= bounds
.width
- eachX
- (isToDrawCombo() ?
3 : 0);
62 int width
= comboSize
.width
;
63 if (width
> spaceLeft
) {
67 myComboLabel
.setBounds(eachX
, eachY
, width
, bounds
.height
);
71 public void paintComponent(Graphics g
) {
72 if (!isToDrawCombo()) return;
74 final Graphics2D g2d
= (Graphics2D
)g
;
76 final GraphicsConfig c
= new GraphicsConfig(g
);
77 c
.setAntialiasing(true);
79 fillTabShape(g2d
, myComboLabel
, getShapeFor(myComboLabel
), true);
85 public void paintChildren(Graphics g
) {
86 if (!isToDrawCombo()) return;
88 final GraphicsConfig c
= new GraphicsConfig(g
);
89 c
.setAntialiasing(true);
91 final Graphics2D g2d
= (Graphics2D
)g
;
93 final Color edges
= myUi
.myWindow
.isActive() ? TAB_BORDER_ACTIVE_WINDOW
: TAB_BORDER_PASSIVE_WINDOW
;
96 Shape shape
= getShapeFor(myComboLabel
);
102 private Shape
getShapeFor(ContentComboLabel label
) {
103 final Rectangle bounds
= label
.getBounds();
105 if (bounds
.width
<= 0 || bounds
.height
<= 0) return new GeneralPath();
107 bounds
.y
= bounds
.y
- TitlePanel
.STRUT
;
108 int height
= bounds
.height
- 1;
114 final GeneralPath path
= new GeneralPath();
115 path
.moveTo(bounds
.x
, bounds
.y
+ height
- arc
);
116 path
.lineTo(bounds
.x
, bounds
.y
+ arc
);
117 path
.quadTo(bounds
.x
, bounds
.y
, bounds
.x
+ arc
, bounds
.y
);
118 path
.lineTo(bounds
.x
+ bounds
.width
- arc
, bounds
.y
);
119 path
.quadTo(bounds
.x
+ bounds
.width
, bounds
.y
, bounds
.x
+ bounds
.width
, bounds
.y
+ arc
);
120 path
.lineTo(bounds
.x
+ bounds
.width
, bounds
.y
+ height
- arc
);
121 path
.quadTo(bounds
.x
+ bounds
.width
, bounds
.y
+ height
, bounds
.x
+ bounds
.width
- arc
, bounds
.y
+ height
);
122 path
.lineTo(bounds
.x
+ arc
, bounds
.y
+ height
);
123 path
.quadTo(bounds
.x
, bounds
.y
+ height
, bounds
.x
, bounds
.y
+ height
- arc
);
131 public void update() {
132 updateIdLabel(myIdLabel
);
133 myComboLabel
.update();
137 public void rebuild() {
141 myUi
.initMouseListeners(myIdLabel
, myUi
);
143 myUi
.add(myComboLabel
);
144 myUi
.initMouseListeners(myComboLabel
, myUi
);
147 boolean isToDrawCombo() {
148 return myUi
.myManager
.getContentCount() > 1;
152 public void contentAdded(ContentManagerEvent event
) {
156 public void contentRemoved(ContentManagerEvent event
) {
160 public void showContentPopup(ListPopup listPopup
) {
161 listPopup
.setMinimumSize(new Dimension(myComboLabel
.getPreferredSize().width
, 0));
162 listPopup
.showUnderneathOf(myComboLabel
);