📄 uitool.java
字号:
* 父容器
* @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 style
* 样式
* @return
* Text
*/
public static Text createSingleText(Composite parent, int style) {
return createSingleText(parent, new GridData(), style);
}
/**
* 创建一个单行文本框
*
* @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) {
return createContainer(parent, layoutData, layout, SWT.NONE);
}
/**
* 创建一个容器
*
* @param parent
* 父容器
* @param layoutData
* 布局数据
* @param layout
* 布局
* @param style
* 样式
* @return
* Composite
*/
public static Composite createContainer(Composite parent, Object layoutData, Layout layout, int style) {
Composite c = new Composite(parent, style);
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, layoutData);
}
/**
* 创建一个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 Slat createSlat(Composite parent, String text) {
return createSlat(parent, text, new GridData());
}
public static Slat createSlat(Composite parent, String text, GridData gd) {
return createSlat(parent, text, gd, SWT.CENTER);
}
public static Slat createSlat(Composite parent, String text, GridData gd, int style) {
Slat button = new Slat(parent, SWT.CENTER);
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;
}
/**
* 计算字体高度
*
* @return
* 字体高度象素
*/
public static int calculateDefaultFontHeight(GC gc) {
Font originalFont = gc.getFont();
FontData[] fontDatas = originalFont.getFontData();
FontMetrics metrics = gc.getFontMetrics();
int ascent = metrics.getAscent() + metrics.getLeading();
int descent = metrics.getDescent();
getFontData(fontDatas, SWT.BOLD);
Font boldFont = new Font(getDisplay(), fontDatas);
gc.setFont(boldFont);
metrics = gc.getFontMetrics();
ascent = max(ascent, metrics.getAscent() + metrics.getLeading());
descent = max(descent, metrics.getDescent());
boldFont.dispose();
getFontData(fontDatas, SWT.ITALIC);
Font italicFont = new Font(getDisplay(), fontDatas);
gc.setFont(italicFont);
metrics = gc.getFontMetrics();
ascent = max(ascent, metrics.getAscent() + metrics.getLeading());
descent = max(descent, metrics.getDescent());
italicFont.dispose();
getFontData(fontDatas, SWT.BOLD | SWT.ITALIC);
Font boldItalicFont = new Font(getDisplay(), fontDatas);
gc.setFont(boldItalicFont);
metrics = gc.getFontMetrics();
ascent = max(ascent, metrics.getAscent() + metrics.getLeading());
descent = max(descent, metrics.getDescent());
boldItalicFont.dispose();
gc.setFont(originalFont);
return ascent + descent;
}
private static Display getDisplay() {
return Display.getCurrent();
}
/**
* 设置font data为某种样式
*
* @param fontDatas
* FontData数组
* @param style
* 样式
*/
private static void getFontData(FontData[] fontDatas, int style) {
for(FontData fd : fontDatas)
fd.setStyle(style);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -