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

📄 ngtabfolder.java

📁 Novocode的 SWT 控件框架 丰富了MDI功能
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2004 Stefan Zeiger and others.
 * 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.novocode.com/legal/epl-v10.html
 * 
 * Contributors:
 *     Stefan Zeiger (szeiger@novocode.com) - initial API and implementation
 *******************************************************************************/

package com.novocode.naf.gui;

import java.util.*;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

import com.novocode.naf.app.*;
import com.novocode.naf.data.ModelBinding;
import com.novocode.naf.data.XMLProperty;
import com.novocode.naf.gui.event.ChangeEvent;
import com.novocode.naf.gui.event.IChangeListener;
import com.novocode.naf.model.DefaultIntModel;
import com.novocode.naf.model.IIntModel;
import com.novocode.naf.resource.*;


/**
 * A TabFolder widget.
 * 
 * @author Stefan Zeiger (szeiger@novocode.com)
 * @since Feb 28, 2004
 */

public final class NGTabFolder extends NGWidget
{
  private TabPosition tabPosisiton = TabPosition.TOP;
  private boolean border;

  public enum TabPosition
  {
    TOP (SWT.TOP), BOTTOM (SWT.BOTTOM);
    public final int style;
    TabPosition(int style) { this.style = style; }
  };
  

  @XMLProperty
  public void setTabPosition(TabPosition t) { this.tabPosisiton = t; }
  public TabPosition getTabPosition() { return tabPosisiton; }
  
  
  @XMLProperty
  public void setBorder(boolean b) { this.border = b; }
  public boolean getBorder() { return border; }

  
  public Control createControl(Composite parent, NGComponent parentComp, ShellWindowInstance wi, WidgetData pwd) throws NAFException
  {
    int style = tabPosisiton.style;
    if(border) style |= SWT.BORDER;
    final TabFolder tf = new TabFolder(parent, style);

    List<NGWidget> chlist = getChildren(null);
    for(NGWidget ch : chlist)
    {
      Properties props = new Properties();
      if(ch.getLayoutDataAttributes() != null) props.putAll(ch.getLayoutDataAttributes());
      TabItem item = new TabItem(tf, SWT.NONE);
      Control control = ch.createAndConfigureControl(tf, this, wi);
      item.setControl(control);
      control.pack();
      String text = props.getProperty("text");
      String tooltip = props.getProperty("tooltip");
      String imageRes = props.getProperty("image");
      if(text != null) item.setText(text);
      if(tooltip != null) item.setToolTipText(tooltip);
      if(imageRes != null) SWTUtil.setRegisteredImage(imageRes, getResourceURL(), item, wi.imageManager, true);
    }
    tf.pack();

    final IIntModel pageModel = getModel("page", wi.models);
    if(pageModel != null)
    {
      final boolean[] lock = new boolean[1];
      IChangeListener cl = new IChangeListener()
      {
        public void stateChanged(ChangeEvent e)
        {
          int i = pageModel.getInt();
          if(i == tf.getSelectionIndex()) return;
          try
          {
            lock[0] = true;
            tf.setSelection(i);
          }
          finally { lock[0] = false; }
        }
      };
      SWTUtil.registerModel(tf, pageModel, cl);
      cl.stateChanged(null);

      tf.addSelectionListener(new SelectionAdapter()
      {
        public void widgetSelected(SelectionEvent e)
        {
          if(!lock[0]) pageModel.setInt(tf.getSelectionIndex());
        }
      });
    }

    return tf;
  }


  protected Object createDefaultModel(ModelBinding mb)
  {
    if("page".equals(mb.type)) return new DefaultIntModel();
    else return super.createDefaultModel(mb);
  }
}

⌨️ 快捷键说明

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