01: package net.sourceforge.tracelog.ui;
02:
03: import org.eclipse.swt.SWT;
04: import org.eclipse.swt.graphics.Color;
05: import org.eclipse.swt.graphics.Cursor;
06: import org.eclipse.swt.graphics.Font;
07: import org.eclipse.swt.graphics.Rectangle;
08: import org.eclipse.swt.layout.GridData;
09: import org.eclipse.swt.layout.GridLayout;
10: import org.eclipse.swt.widgets.Composite;
11: import org.eclipse.swt.widgets.Display;
12: import org.eclipse.swt.widgets.Label;
13: import org.eclipse.swt.widgets.Shell;
14:
15: public class UIUtil {
16: private static final Display DISPLAY = new Display();
17: private static final Color COLOR_GRAY = DISPLAY
18: .getSystemColor(SWT.COLOR_GRAY);
19: private static final Color COLOR_WHITE = DISPLAY
20: .getSystemColor(SWT.COLOR_WHITE);
21:
22: private static final Font FONT_TITLE = new Font(null, "Arial", 12,
23: SWT.BOLD);
24:
25: /**
26: * Center aligned shell in relative to parent shell.
27: *
28: * @param parentShell
29: * Parent shell
30: * @param shell
31: * Shell to be aligned
32: */
33: public static void centerAlignedShell(Shell parentShell, Shell shell) {
34: Rectangle shellRect = shell.getBounds();
35: Rectangle parentShellRect = parentShell.getBounds();
36:
37: int x = (parentShellRect.width - shellRect.width) / 2;
38: int y = (parentShellRect.height - shellRect.height) / 2;
39:
40: shell.setLocation(parentShellRect.x + x, parentShellRect.y + y);
41: }
42:
43: public static void createTitle(Composite composite, String text) {
44: Label title = new Label(composite, SWT.NONE);
45: title.setFont(FONT_TITLE);
46: title.setText(text);
47: title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
48: Label separator = new Label(composite, SWT.SEPARATOR
49: | SWT.HORIZONTAL);
50: separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
51: }
52:
53: public static Color getColor(int color) {
54: return DISPLAY.getSystemColor(color);
55: }
56:
57: public static Color getColorGray() {
58: return COLOR_GRAY;
59: }
60:
61: public static Color getColorWhite() {
62: return COLOR_WHITE;
63: }
64:
65: public static Cursor getCursorHand() {
66: return new Cursor(DISPLAY, SWT.CURSOR_HAND);
67: }
68:
69: public static GridLayout getDefaultGridLayout() {
70: return new GridLayout();
71: }
72:
73: /**
74: * Returns the display.
75: *
76: * @return Display.
77: */
78: public static Display getDisplay() {
79: return DISPLAY;
80: }
81:
82: public static GridData getGridDataFillBoth() {
83: return new GridData(GridData.FILL_BOTH);
84: }
85:
86: public static GridData getGridDataFillHorizontal() {
87: return new GridData(GridData.FILL_HORIZONTAL);
88: }
89:
90: public static GridData getGridDataFillHorizontalSpan(int spanSize) {
91: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
92: gridData.horizontalSpan = spanSize;
93: return gridData;
94: }
95:
96: public static GridData getGridDataFillVertical() {
97: return new GridData(GridData.FILL_VERTICAL);
98: }
99: }
|