📄 ngcoolbar.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.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import com.novocode.naf.app.*;
import com.novocode.naf.data.DataDecoder;
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.DefaultBooleanModel;
import com.novocode.naf.model.IBooleanReadModel;
import com.novocode.naf.resource.*;
/**
* A CoolBar widget.
*
* @author Stefan Zeiger (szeiger@novocode.com)
* @since Feb 16, 2004
*/
public final class NGCoolBar extends NGWidget
{
private boolean resizable, border, flat, recursivePopup;
@XMLProperty public void setResizable(boolean b) { this.resizable = b; }
public boolean isResizable() { return resizable; }
@XMLProperty public void setBorder(boolean b) { this.border = b; }
public boolean getBorder() { return border; }
@XMLProperty public void setFlat(boolean b) { this.flat = b; }
public boolean isFlat() { return flat; }
@XMLProperty public void setRecursivePopup(boolean b) { this.recursivePopup = b; }
public boolean getRecursivePopup() { return recursivePopup; }
public Control createControl(Composite parent, NGComponent parentComp, ShellWindowInstance wi, WidgetData pwd) throws NAFException
{
int style = SWT.NONE;
if(border) style |= SWT.BORDER;
if(flat) style |= SWT.FLAT;
final CoolBar bar = new CoolBar(parent, style);
return bar;
}
protected void configureControl(final Control control, final ShellWindowInstance wi, WidgetData wd, WidgetData pwd)
{
super.configureControl(control, wi, wd, pwd);
final CoolBar bar = (CoolBar)control;
/* [TODO] Implement chevron dropdown for resizable=true
* as shown in http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-swt-home/snippits/snippet140.html */
List<NGWidget> chlist = getChildren(null);
for(NGWidget ch : chlist)
{
CoolItem item = new CoolItem(bar, resizable ? SWT.DROP_DOWN : SWT.NONE);
wd.attachTo(item);
Control itemControl = ch.createAndConfigureControl(bar, this, wi);
item.setControl(itemControl);
itemControl.pack();
Point size = itemControl.getSize();
Point itemSize = item.computeSize(size.x, size.y);
item.setSize(itemSize);
if(!resizable) item.setMinimumSize(size);
}
bar.pack();
final Point oldSize = bar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
bar.addListener(SWT.Resize, new Listener()
{
public void handleEvent(Event event)
{
Point newSize = bar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
if(newSize.y != oldSize.y)
{
//System.out.println("Preferred size: "+newSize);
//System.out.println("Actual size: "+bar.getSize());
bar.getParent().layout(true);
}
//oldSize.x = newSize.x;
oldSize.y = newSize.y;
}
});
final IBooleanReadModel lockedModel = getModel("locked", wi.models);
if(lockedModel != null)
{
IChangeListener cl = new IChangeListener()
{
public void stateChanged(ChangeEvent e)
{
boolean b = lockedModel.getBoolean();
if(bar.getLocked() != b) bar.setLocked(b);
}
};
SWTUtil.registerModel(bar, lockedModel, cl);
cl.stateChanged(null);
}
}
protected Object createDefaultModel(ModelBinding mb)
{
if("locked".equals(mb.type))
return new DefaultBooleanModel(DataDecoder.decodeBoolean(mb.getAttribute("initial"), false));
else return super.createDefaultModel(mb);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -