📄 blind.java
字号:
}
/**
* 在slat上闪烁一个图标
*
* @param index
* 序号
* @param image
* 要闪烁的图标
*/
public void startBlink(int index, Image image) {
checkWidget();
if(!checkIndex(index))
return;
((Slat)children.get(index << 1)).startBlinkImage(image);
}
/**
* 停止闪烁一个slat
*
* @param index
* 序号
*/
public void stopBlink(int index) {
checkWidget();
if(!checkIndex(index))
return;
((Slat)children.get(index << 1)).stopBlinkImage();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Composite#getChildren()
*/
@Override
public Control[] getChildren() {
checkWidget();
return children.toArray(new Control[children.size()]);
}
/**
* 添加一个slat
*
* @param slatControl
* slat所绑定的控件
* @return
* 新建的slat
*/
public Slat addSlat(Control slatControl) {
return internalAddSlat(children.size() >>> 1, slatControl);
}
/**
* 添加一个slat到指定位置
*
* @param index
* slat的索引,不包括slat的控件
* @param slatControl
* slat所绑定的控件
* @return
* 新建的slat
*/
public Slat addSlat(int index, Control slatControl) {
return internalAddSlat(index, slatControl);
}
/**
* 添加一个slat到指定位置
*
* @param index
* slat的索引,相对于所有控件来说
* @param slatControl
* slat所绑定的控件
* @return
* 新建的slat
*/
private Slat internalAddSlat(int index, Control slatControl) {
checkWidget();
if(labelProvider == null)
return null;
if(index < 0 || index > getSlatCount())
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
int temp = index << 1;
// 添加slat控件
Slat slat = new Slat(this, SWT.CENTER, labelProvider.getText(slatControl), null);
slat.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
slat.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
children.add(temp, slat);
// 添加slat绑定控件
GridData gd = new GridData(GridData.FILL_BOTH);
gd.exclude = true;
slatControl.setVisible(false);
slatControl.setLayoutData(gd);
slatControl.setBackground(contentBackground);
children.add(temp + 1, slatControl);
visibleSlatCount++;
slat.addMouseListener(slatMouseListener);
if(currentSlat == -1)
setCurrentSlat(0);
else if(index <= currentSlat) {
currentSlat++;
layout();
} else
layout();
return slat;
}
/**
* 检查索引范围
*
* @param index
* 索引
* @return
* true表示索引范围正确
*/
private boolean checkIndex(int index) {
return index >= 0 && index < getSlatCount();
}
/**
* 检查样式是否合法
*
* @param style
* 样式常量
*/
private void checkStyle(int style) {
style &= SWT.BORDER;
}
/**
* @return Returns the labelProvider.
*/
public ISlatLabelProvider getLabelProvider() {
return labelProvider;
}
/**
* @param labelProvider The labelProvider to set.
*/
public void setLabelProvider(ISlatLabelProvider labelProvider) {
this.labelProvider = labelProvider;
}
/**
* @return Returns the currentSlat.
*/
public int getCurrentSlatIndex() {
return currentSlat;
}
/**
* 得到这个控件所在的slat索引
*
* @param slatControl
* @return
*/
public int indexOf(Control slatControl) {
int index = children.indexOf(slatControl);
return index >>> 1;
}
/**
* 得到slat绑定控件
*
* @param index
* slat索引
* @return
* Control对象
*/
public Control getSlatControl(int index) {
checkWidget();
if(!checkIndex(index))
return null;
return children.get((index << 1) + 1);
}
/**
* @return
* slat总数
*/
public int getSlatCount() {
return children.size() >>> 1;
}
/**
* 为Slat添加拖动支持
*
* @param index
* slat序号
* @param operations
* a bitwise OR of the supported drag and drop operation types (
* <code>DROP_COPY</code>,<code>DROP_LINK</code>, and
* <code>DROP_MOVE</code>)
* @param transferTypes
* the transfer types that are supported by the drag operation
* @param listener
* the callback that will be invoked to set the drag data and to
* cleanup after the drag and drop operation finishes
* @see org.eclipse.swt.dnd.DND
*/
public void addSlatDragSupport(int index, int operations, Transfer[] transferTypes, DragSourceListener listener) {
checkWidget();
if(!checkIndex(index))
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
DragSource dragSource = new DragSource(children.get(index << 1), operations);
dragSource.setTransfer(transferTypes);
dragSource.addDragListener(listener);
}
/**
* 为Slat添加拖放支持
*
* @param index
* slat序号
* @param operations
* a bitwise OR of the supported drag and drop operation types (
* <code>DROP_COPY</code>,<code>DROP_LINK</code>, and
* <code>DROP_MOVE</code>)
* @param transferTypes
* the transfer types that are supported by the drop operation
* @param listener
* the callback that will be invoked after the drag and drop
* operation finishes
* @see org.eclipse.swt.dnd.DND
*/
public void addSlatDropSupport(int index, int operations, Transfer[] transferTypes, DropTargetListener listener) {
checkWidget();
if(!checkIndex(index))
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
DropTarget dropTarget = new DropTarget(children.get(index << 1), operations);
dropTarget.setTransfer(transferTypes);
dropTarget.addDropListener(listener);
}
/**
* 为Slat添加一个拖放支持,使用slat或者slat绑定控件定位
*
* @param c
* @param operations
* @param transferTypes
* @param listener
*/
public void addSlatDropSupport(Control c, int operations, Transfer[] transferTypes, DropTargetListener listener) {
int index = indexOf(c);
addSlatDropSupport(index, operations, transferTypes, listener);
}
/**
* 为Slat绑定控件添加拖动支持
*
* @param index
* slat序号
* @param operations
* a bitwise OR of the supported drag and drop operation types (
* <code>DROP_COPY</code>,<code>DROP_LINK</code>, and
* <code>DROP_MOVE</code>)
* @param transferTypes
* the transfer types that are supported by the drag operation
* @param listener
* the callback that will be invoked to set the drag data and to
* cleanup after the drag and drop operation finishes
* @see org.eclipse.swt.dnd.DND
*/
public void addSlatControlDragSupport(int index, int operations, Transfer[] transferTypes, DragSourceListener listener) {
checkWidget();
if(!checkIndex(index))
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
DragSource dragSource = new DragSource(children.get((index << 1) + 1), operations);
dragSource.setTransfer(transferTypes);
dragSource.addDragListener(listener);
}
/**
* 为Slat绑定控件添加拖放支持
*
* @param index
* slat序号
* @param operations
* a bitwise OR of the supported drag and drop operation types (
* <code>DROP_COPY</code>,<code>DROP_LINK</code>, and
* <code>DROP_MOVE</code>)
* @param transferTypes
* the transfer types that are supported by the drop operation
* @param listener
* the callback that will be invoked after the drag and drop
* operation finishes
* @see org.eclipse.swt.dnd.DND
*/
public void addSlatControlDropSupport(int index, int operations, Transfer[] transferTypes, DropTargetListener listener) {
checkWidget();
if(!checkIndex(index))
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
DropTarget dropTarget = new DropTarget(children.get((index << 1) + 1), operations);
dropTarget.setTransfer(transferTypes);
dropTarget.addDropListener(listener);
}
/**
* 得到指定位置的slat
*
* @param index
* slat索引
* @return
* Slat对象
*/
public Slat getSlat(int index) {
checkWidget();
if(!checkIndex(index))
return null;
return (Slat)children.get(index << 1);
}
/**
* 设置slat绑定控件背景色
*
* @param bg
* 背景色
*/
public void setContentBackground(Color bg) {
checkWidget();
contentBackground = bg;
int size = children.size();
for(int i = 1; i < size; i += 2)
children.get(i).setBackground(bg);
setBackground(contentBackground);
}
/**
* @return
* 当前slat控件
*/
public Slat getCurrentSlat() {
return getSlat(getCurrentSlatIndex());
}
/**
* @return
* 当前slat绑定控件
*/
public Control getCurrentSlatControl() {
return getSlatControl(getCurrentSlatIndex());
}
/**
* 停止所有Slat上的动画
*/
public void stopAllAnimation() {
int size = children.size();
for(int i = 0; i < size; i += 2) {
Slat slat = (Slat)children.get(i);
slat.stopAnimate();
slat.stopBlinkImage();
slat.stopBounceImage();
}
}
/**
* @param index
* @return
* true表示slat上有一个动画
*/
public boolean hasSlatAnimation(int index) {
checkWidget();
if(!checkIndex(index))
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Slat slat = getSlat(index);
return slat.isAnimating() || slat.isBlinking() || slat.isBouncing();
}
/**
* @return Returns the previousSlat.
*/
public int getPreviousSlat() {
return previousSlat;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -