📄 ngstacklayout.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.layout;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.widgets.*;
import org.w3c.dom.Element;
import com.novocode.naf.app.NAFException;
import com.novocode.naf.data.ModelBinding;
import com.novocode.naf.data.SizeMeasure;
import com.novocode.naf.data.SizeMeasurePair;
import com.novocode.naf.data.XMLProperty;
import com.novocode.naf.gui.SWTUtil;
import com.novocode.naf.gui.ShellWindowInstance;
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;
/**
* Layout creator for SWT StackLayout.
*
* @author Stefan Zeiger (szeiger@novocode.com)
* @since Apr 24, 2004
*/
public class NGStackLayout extends NGLayout
{
private SizeMeasurePair margin = new SizeMeasurePair(new SizeMeasure(0));
private ModelBinding topModelBinding;
@XMLProperty
public void setMargin(SizeMeasurePair a) { this.margin = new SizeMeasurePair(a); }
@XMLProperty("hmargin")
public void setHorizontalMargin(SizeMeasure s) { this.margin.setHorizonal(s); }
public SizeMeasure getHorizontalMargin() { return margin.getHorizonal(); }
@XMLProperty("vmargin")
public void setVerticalMargin(SizeMeasure s) { this.margin.setVertical(s); }
public SizeMeasure getVerticalMargin() { return margin.getVertical(); }
protected void parseNAFChildElement(Element e) throws NAFException
{
if("model".equals(e.getLocalName()))
{
ModelBinding mb = new ModelBinding(e, 0);
if("top".equals(mb.type)) topModelBinding = mb;
}
else super.parseNAFChildElement(e);
}
public void assignLayout(final Composite comp, ShellWindowInstance wi) throws NAFException
{
int embase = SWTUtil.computeEMBase(comp);
final StackLayout l = new StackLayout();
l.marginWidth = margin.getHorizonal().compute(embase);
l.marginHeight = margin.getVertical().compute(embase);
comp.setLayout(l);
if(topModelBinding != null)
{
IIntModel model = wi.models.get(topModelBinding.id);
if(model == null && (topModelBinding.create != ModelBinding.Create.NO))
model = new DefaultIntModel();
if(model != null)
{
final IIntModel finalModel = model;
final Control[] ch = comp.getChildren();
IChangeListener cl = new IChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int i = finalModel.getInt();
if(i < 0) i = 0;
else if(i >= ch.length) i = ch.length-1;
Control c = ch[i];
if(l.topControl != c)
{
l.topControl = c;
comp.layout();
}
}
};
SWTUtil.registerModel(comp, finalModel, cl);
cl.stateChanged(null);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -