⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabcontainer.java

📁 eclise rcp 项目,是非常好的学习源码
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2007 Siemens AG
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Kai T鰀ter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.presentation;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;

public class TabContainer extends Composite {

    protected List<Tab> tabItems = new ArrayList<Tab>();

    protected IPresentablePart part;

    protected int style;

    public TabContainer(Composite parent, int style) {
        super(parent, style);
        this.style = style;
    }

    public void addPart(IPresentablePart part, Presentation presentation,
            IStackPresentationSite site) {
        Tab tab = new Tab(this, style, presentation, site);
        tab.setPresentablePart(part);
        tabItems.add(tab);
        redraw();
    }

    public void setPresentablePart(IPresentablePart part) {
        this.part = part;
        for (Tab b : tabItems) {
            b.setSected(b.checkPart(part));
        }
        redraw();
    }

    public int getHeight() {
        if (tabItems.size() < 2) {
            return 0;
        }
        return tabItems.size() * tabItems.get(0).getHeight() - tabItems.size() + 1;
    }

    @Override
    public void setBounds(int x, int y, int width, int height) {
        int y2 = 0;
        int h = 21;
        for (Tab b : tabItems) {
            b.setBounds(x, y2, width, h);
            y2 += 20;
        }
        super.setBounds(x, y, width, height);
    }

    public void redraw() {
        if (tabItems.size() < 2) {
            return;
        }
        for (Tab b : tabItems) {
            b.redraw();
        }
    }

    public void removePart(IPresentablePart oldPart) {
        Tab foundTab = null;
        for (Tab b : tabItems) {
            if (b.getPart() == oldPart) {
                foundTab = b;
                break;
            }
        }
        if (foundTab != null) {
            tabItems.remove(foundTab);
            foundTab.dispose();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -