📄 ngctabfolder.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.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
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 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 CTabFolder widget.
*
* @author Stefan Zeiger (szeiger@novocode.com)
* @since Nov 14, 2004
*/
public final class NGCTabFolder extends NGWidget
{
private TabPosition tabPosisiton = TabPosition.TOP;
private boolean border, single, flat, close, simple;
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; }
@XMLProperty public void setSingle(boolean b) { this.single = b; }
public boolean getSingle() { return single; }
@XMLProperty public void setFlat(boolean b) { this.flat = b; }
public boolean getFlat() { return flat; }
@XMLProperty public void setClose(boolean b) { this.close = b; }
public boolean getClose() { return close; }
@XMLProperty public void setSimple(boolean b) { this.simple = b; }
public boolean getSimple() { return simple; }
public Control createControl(Composite parent, NGComponent parentComp, ShellWindowInstance wi, WidgetData pwd) throws NAFException
{
int style = tabPosisiton.style | (single ? SWT.SINGLE : SWT.MULTI);
if(border) style |= SWT.BORDER;
if(flat) style |= SWT.FLAT;
if(close) style |= SWT.CLOSE;
final CTabFolder tf = new CTabFolder(parent, style);
tf.setSimple(simple);
// [TODO] Support all CTabFolder / CTabItem features
List<NGWidget> chlist = getChildren(null);
for(NGWidget ch : chlist)
{
Properties props = new Properties();
if(ch.getLayoutDataAttributes() != null) props.putAll(ch.getLayoutDataAttributes());
CTabItem item = new CTabItem(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 + -