tool window combo - show content action
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / wm / impl / content / ComboContentLayout.java
blobe36231e0c7f939a55f732523c6141ee99747e9c2
1 /*
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;
22 import java.awt.*;
23 import java.awt.geom.GeneralPath;
25 class ComboContentLayout extends ContentLayout {
27 BaseLabel myIdLabel;
28 ContentComboLabel myComboLabel;
30 ComboContentLayout(ToolWindowContentUi ui) {
31 super(ui);
34 @Override
35 public void init() {
36 reset();
38 myIdLabel = new BaseLabel(myUi, false);
39 myComboLabel = new ContentComboLabel(this);
42 @Override
43 public void reset() {
44 myIdLabel = null;
45 myComboLabel = null;
48 @Override
49 public void layout() {
50 Rectangle bounds = myUi.getBounds();
51 Dimension idSize = myIdLabel.getPreferredSize();
53 int eachX = 0;
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) {
64 width = spaceLeft;
67 myComboLabel.setBounds(eachX, eachY, width, bounds.height);
70 @Override
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);
81 c.restore();
84 @Override
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;
94 g2d.setColor(edges);
96 Shape shape = getShapeFor(myComboLabel);
97 g2d.draw(shape);
99 c.restore();
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;
110 bounds.width += 1;
112 int arc = TAB_ARC;
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);
124 path.closePath();
126 return path;
130 @Override
131 public void update() {
132 updateIdLabel(myIdLabel);
133 myComboLabel.update();
136 @Override
137 public void rebuild() {
138 myUi.removeAll();
140 myUi.add(myIdLabel);
141 myUi.initMouseListeners(myIdLabel, myUi);
143 myUi.add(myComboLabel);
144 myUi.initMouseListeners(myComboLabel, myUi);
147 boolean isToDrawCombo() {
148 return myUi.myManager.getContentCount() > 1;
151 @Override
152 public void contentAdded(ContentManagerEvent event) {
155 @Override
156 public void contentRemoved(ContentManagerEvent event) {
159 @Override
160 public void showContentPopup(ListPopup listPopup) {
161 listPopup.setMinimumSize(new Dimension(myComboLabel.getPreferredSize().width, 0));
162 listPopup.showUnderneathOf(myComboLabel);