/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentTabLabel.java
https://bitbucket.org/nbargnesi/idea · Java · 112 lines · 80 code · 17 blank · 15 comment · 10 complexity · 7cbfe14c3129babe9fb6f5879f4d74d3 MD5 · raw file
- /*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.intellij.openapi.wm.impl.content;
- import com.intellij.ui.EngravedTextGraphics;
- import com.intellij.ui.Gray;
- import com.intellij.ui.content.Content;
- import com.intellij.ui.content.ContentManager;
- import com.intellij.util.ui.BaseButtonBehavior;
- import com.intellij.util.ui.TimedDeadzone;
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- import java.awt.*;
- import java.awt.event.MouseEvent;
- class ContentTabLabel extends BaseLabel {
- Content myContent;
- private final BaseButtonBehavior myBehavior;
- private final TabContentLayout myLayout;
- public ContentTabLabel(final Content content, TabContentLayout layout) {
- super(layout.myUi, true);
- myLayout = layout;
- myContent = content;
- update();
- myBehavior = new BaseButtonBehavior(this) {
- protected void execute(final MouseEvent e) {
- final ContentManager mgr = contentManager();
- if (mgr.getIndexOfContent(myContent) >= 0) {
- mgr.setSelectedContent(myContent, true);
- }
- }
- };
- myBehavior.setActionTrigger(MouseEvent.MOUSE_PRESSED);
- myBehavior.setMouseDeadzone(TimedDeadzone.NULL);
- }
- public void update() {
- if (!myLayout.isToDrawTabs()) {
- setHorizontalAlignment(JLabel.LEFT);
- setBorder(null);
- } else {
- setHorizontalAlignment(JLabel.CENTER);
- setBorder(new EmptyBorder(0, 8, 0, 8));
- }
- updateTextAndIcon(myContent, isSelected());
- }
- @Override
- protected boolean allowEngravement() {
- return isSelected() || (myUi != null && myUi.myWindow.isActive());
- }
- @Override
- protected Color getActiveFg(boolean selected) {
- if (contentManager().getContentCount() > 1) {
- return selected ? Color.white : super.getActiveFg(selected);
- }
- return super.getActiveFg(selected);
- }
- @Override
- protected Color getPassiveFg(boolean selected) {
- if (contentManager().getContentCount() > 1) {
- return selected ? Gray._255 : super.getPassiveFg(selected);
- }
- return super.getPassiveFg(selected);
- }
- protected void paintComponent(final Graphics g) {
- super.paintComponent(g);
- }
- public boolean isSelected() {
- return contentManager().isSelected(myContent);
- }
- @Override
- protected Graphics _getGraphics(Graphics2D g) {
- if (isSelected() && contentManager().getContentCount() > 1) {
- return new EngravedTextGraphics(g, 1, 1, myUi.myWindow.isActive() ? new Color(0, 0, 0, 120) : new Color(0, 0, 0, 130));
- }
-
- return super._getGraphics(g);
- }
- private ContentManager contentManager() {
- return myUi.myWindow.getContentManager();
- }
- @Override
- public Content getContent() {
- return myContent;
- }
- }