📄 ngprogressbar.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 org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import com.novocode.naf.app.*;
import com.novocode.naf.data.ModelBinding;
import com.novocode.naf.data.Orientation;
import com.novocode.naf.data.XMLProperty;
import com.novocode.naf.gui.event.*;
import com.novocode.naf.model.*;
import com.novocode.naf.resource.*;
/**
* A progress bar.
*
* @author Stefan Zeiger (szeiger@novocode.com)
* @since Jan 2, 2004
*/
public final class NGProgressBar extends NGWidget
{
private int min, max = 100;
private boolean indeterminate, smooth;
private Orientation orientation = Orientation.HORIZONTAL;
@XMLProperty
public void setOrientation(Orientation o) { this.orientation = o; }
public Orientation getOrientation() { return orientation; }
@XMLProperty
public void setIndeterminate(boolean b) { this.indeterminate = b; }
public boolean isIndeterminate() { return indeterminate; }
@XMLProperty
public void setSmooth(boolean b) { this.smooth = b; }
public boolean isSmooth() { return smooth; }
@XMLProperty
public void setMin(int i) { this.min = i; }
public int getMin() { return min; }
@XMLProperty
public void setMax(int i) { this.max = i; }
public int getMax() { return max; }
public Control createControl(Composite parent, NGComponent parentComp, ShellWindowInstance wi, WidgetData pwd) throws NAFException
{
int style = orientation.style;
if(indeterminate) style |= SWT.INDETERMINATE;
if(smooth) style |= SWT.SMOOTH;
final ProgressBar pb = new ProgressBar(parent, style);
pb.setMinimum(min);
pb.setMaximum(max);
final IProgressReadModel progressModel = getModel("progress", wi.models);
final IIntReadModel valueModel = getModel("value", wi.models);
if(progressModel != null)
{
IChangeListener cl = new IChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int newMin = progressModel.getMin();
int newMax = progressModel.getMax();
int newProgress = progressModel.getProgress();
if(newMin != pb.getMinimum()) pb.setMinimum(newMin);
if(newMax != pb.getMaximum()) pb.setMaximum(newMax);
if(newProgress != pb.getSelection()) pb.setSelection(newProgress);
}
};
SWTUtil.registerModel(pb, progressModel, cl);
cl.stateChanged(null);
}
else if(valueModel != null)
{
IChangeListener cl = new IChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int i = valueModel.getInt();
if(i == pb.getSelection()) return;
pb.setSelection(i);
}
};
SWTUtil.registerModel(pb, valueModel, cl);
cl.stateChanged(null);
}
return pb;
}
protected Object createDefaultModel(ModelBinding mb)
{
if("value".equals(mb.type)) return new DefaultIntModel();
else if("progress".equals(mb.type)) return new DefaultProgressModel(0, 100, 0);
else return super.createDefaultModel(mb);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -