📄 uitool.java
字号:
* 创建一个标签控件
*
* @param parent
* 父容器
* @param text
* 文本
* @param layoutData
* 布局数据
* @param style
* 样式
* @return
* Label对象
*/
public static Label createLabel(Composite parent, String text, Object layoutData, int style) {
Label label = new Label(parent, style);
label.setText(text);
label.setBackground(getDefaultBackground());
label.setLayoutData(layoutData);
return label;
}
/**
* 创建一个CCombo控件
*
* @param parent
* 父容器
* @return
* CCombo
*/
public static CCombo createCCombo(Composite parent) {
return createCCombo(parent, new GridData(), SWT.FLAT | SWT.READ_ONLY);
}
/**
* 创建一个CCombo控件
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @return
* CCombo
*/
public static CCombo createCCombo(Composite parent, Object layoutData) {
return createCCombo(parent, layoutData, SWT.FLAT | SWT.READ_ONLY);
}
/**
* 创建一个CCombo控件
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @param style
* 样式
* @return
* CCombo
*/
public static CCombo createCCombo(Composite parent, Object layoutData, int style) {
CCombo combo = new CCombo(parent, style);
combo.setBackground(getDefaultBackground());
combo.setLayoutData(layoutData);
return combo;
}
/**
* 创建一个单行文本框
*
* @param parent
* 父容器
* @return
* Text
*/
public static Text createSingleText(Composite parent) {
return createSingleText(parent, new GridData(), SWT.SINGLE);
}
/**
* 创建一个单行文本框
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @return
* Text
*/
public static Text createSingleText(Composite parent, Object layoutData) {
return createSingleText(parent, layoutData, SWT.SINGLE);
}
/**
* 创建一个单行文本框
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @param style
* 样式
* @return
* Text
*/
public static Text createSingleText(Composite parent, Object layoutData, int style) {
Text text = new Text(parent, style);
text.setBackground(getDefaultBackground());
text.setLayoutData(layoutData);
return text;
}
/**
* 创建一个多行文本框
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @return
* Text
*/
public static Text createMultiText(Composite parent, Object layoutData) {
return createMultiText(parent, layoutData, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
}
/**
* 创建一个多行文本框
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @param style
* 样式
* @return
* Text
*/
public static Text createMultiText(Composite parent, Object layoutData, int style) {
Text text = new Text(parent, style);
text.setBackground(getDefaultBackground());
text.setLayoutData(layoutData);
return text;
}
/**
* 创建一个容器
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @param layout
* 布局
* @return
* Composite
*/
public static Composite createContainer(Composite parent, Object layoutData, Layout layout) {
Composite c = new Composite(parent, SWT.NONE);
c.setBackground(getDefaultBackground());
c.setLayoutData(layoutData);
c.setLayout(layout);
return c;
}
/**
* 创建一个只支持文字的link
*
* @param parent
* @param text
* @return
*/
public static Label createSimpleLink(Composite parent, String text) {
return createSimpleLink(parent, text, new GridData());
}
/**
* 创建一个只支持文字的link
*
* @param parent
* @param text
* @param layoutData
* @return
*/
public static Label createSimpleLink(Composite parent, String text, Object layoutData) {
return createSimpleLink(parent, text, Colors.BLUE, Colors.RED);
}
/**
* 创建一个只支持文字的link
*
* @param parent
* @param text
* @param fg
* @param hg
* @return
*/
public static Label createSimpleLink(Composite parent, String text, Color fg, Color hg) {
return createSimpleLink(parent, text, fg, hg, new GridData());
}
/**
* 创建一个只支持文字的link
*
* @param parent
* @param text
* @param fg
* @param hg
* @param layoutData
* @return
*/
public static Label createSimpleLink(Composite parent, String text, Color fg, Color hg, Object layoutData) {
Label link = new Label(parent, SWT.LEFT);
link.setBackground(getDefaultBackground());
link.setText(text);
link.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
link.addMouseTrackListener(new LinkMouseTrackListener(fg, hg));
link.setForeground(fg);
return link;
}
/**
* 创建一个link样式的label
*
* @param parent
* 父容器
* @param text
* 文本
* @param image
* 图标
* @return
* CLabel
*/
public static CLabel createLink(Composite parent, String text, Image image) {
return createLink(parent, text, image, new GridData());
}
/**
* 创建一个link样式的label
*
* @param parent
* 父容器
* @param text
* 文本
* @param image
* 图标
* @param layoutData
* 布局数据
* @return
* CLabel
*/
public static CLabel createLink(Composite parent, String text, Image image, Object layoutData) {
return createLink(parent, text, image, Colors.BLUE, Colors.RED);
}
/**
* 创建一个link样式的label
*
* @param parent
* @param text
* @param image
* @param fg
* @param hg
* @return
*/
public static CLabel createLink(Composite parent, String text, Image image, Color fg, Color hg) {
return createLink(parent, text, image, fg, hg, new GridData());
}
/**
* @param parent
* @param text
* @param image
* @param fg
* @param hg
* @param layoutData
* @return
*/
public static CLabel createLink(Composite parent, String text, Image image, Color fg, Color hg, Object layoutData) {
CLabel link = new CLabel(parent, SWT.LEFT);
link.setLayoutData(layoutData);
link.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
link.setImage(image);
link.setText(text);
link.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
link.setBackground(getDefaultBackground());
link.addMouseTrackListener(new LinkMouseTrackListener(fg, hg));
return link;
}
public static QButton createQButton(Composite parent, String text) {
return createQButton(parent, text, new GridData());
}
public static QButton createQButton(Composite parent, String text, GridData gd) {
return createQButton(parent, text, gd, SWT.NONE);
}
public static QButton createQButton(Composite parent, String text, int style) {
return createQButton(parent, text, new GridData(), SWT.NONE);
}
public static QButton createQButton(Composite parent, String text, GridData gd, int style) {
QButton button = new QButton(parent, style);
button.setText(text);
button.setLayoutData(gd);
return button;
}
/**
* 设置缺省背景色
*
* @param c
*/
public static void setDefaultBackground(Color c) {
DEFAULT_BACKGROUND = c;
}
/**
* @return
* 缺省背景色
*/
public static Color getDefaultBackground() {
if(DEFAULT_BACKGROUND == null)
return Colors.PAGE_BACKGROUND;
else
return DEFAULT_BACKGROUND;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -