Package com.peterhi.ui

Source Code of com.peterhi.ui.TabPane

package com.peterhi.ui;

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

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

final class TabPane extends CTabFolder {

  static final class Item extends CTabItem {

    public Item(TabPane parent, int style) {
      super(parent, style | SWT.CLOSE);
    }
   
    public Item(TabPane parent, int style, int index) {
      super(parent, style | SWT.CLOSE, index);
    }
   
    @Override
    public TabPane getParent() {
      CTabFolder parent = super.getParent();
     
      if (parent instanceof TabPane) {
        TabPane panel = (TabPane )parent;
        return panel;
      }
     
      throw new ClassCastException();
    }

    @Override
    public View getControl() {
      Control control = super.getControl();
     
      if (control == null) {
        return null;
      }
     
      if (control instanceof View) {
        View view = (View )control;
        return view;
      }
     
      throw new ClassCastException();
    }
   
  }
 
  public TabPane(Composite parent, int style) {
    super(parent, style | SWT.BORDER);
  }
 
  public View[] getViews() {
    List<View> viewList = new ArrayList<View>();
    int count = getItemCount();
   
    for (int i = 0; i < count; i++) {
      Item item = getItem(i);
      View view = item.getControl();
     
      if (view != null) {
        viewList.add(view);
      }
    }
   
    View[] views = viewList.toArray(new View[viewList.size()]);
    return views;
  }
 
  @Override
  public Item getItem(int index) {
    if (index < 0) {
      throw new IllegalArgumentException();
    }
   
    if (index >= getItemCount()) {
      throw new IllegalArgumentException();
    }
   
    CTabItem tab = super.getItem(index);
   
    if (tab instanceof Item) {
      Item item = (Item )tab;
      return item;
    }
   
    throw new ClassCastException();
  }

  @Override
  public Item getItem(Point location) {
    if (location == null) {
      throw new NullPointerException();
    }
   
    CTabItem tab = super.getItem(location);
   
    if (tab == null) {
      return null;
    }
   
    if (tab instanceof Item) {
      Item item = (Item )tab;
      return item;
    }
   
    throw new ClassCastException();
  }

  @Override
  public Item[] getItems() {
    CTabItem[] tabs = super.getItems();
    Item[] items = new Item[tabs.length];
    System.arraycopy(tabs, 0, items, 0, tabs.length);
    return items;
  }
 
  /*public Rect bounds() {
    return Rect.fromSWT(getBounds());
  }
 
  public Rect clientArea() {
    return Rect.fromSWT(getClientArea());
  }*/
}
 
TOP

Related Classes of com.peterhi.ui.TabPane

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.