-
Notifications
You must be signed in to change notification settings - Fork 96
/
DialogArea.java
143 lines (129 loc) · 3.64 KB
/
DialogArea.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
* Copyright (c) 2011-2019 Laurent CARON
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
* Stefan Nöbauer - Bug 550437
*******************************************************************************/
package org.eclipse.nebula.widgets.opal.dialog;
import org.eclipse.nebula.widgets.opal.commons.SWTGraphicUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
/**
* This abstract class if the mother of MessageArea and FooterArea classes
*/
abstract class DialogArea {
private static final String MORE_DETAILS_IMAGE = "moreDetails.png";
private static final String FEWER_DETAILS_IMAGE = "fewerDetails.png";
private static final String WINDOWS_DEFAULT_FONT = "Segoe UI";
private static final String MAC_OS_DEFAULT_FONT = "Lucida Grande";
protected final Dialog parent;
private boolean initialised;
/**
* Constructor
*
* @param parent parent dialog
*/
public DialogArea(final Dialog parent) {
this.parent = parent;
}
/**
* Render the content of an area
*/
abstract void render();
/**
* @return the initialised field
*/
boolean isInitialised() {
return initialised;
}
/**
* @param initialised the initialised value to set
*/
void setInitialised(final boolean initialised) {
this.initialised = initialised;
}
/**
* @return the normal font used by the dialog box
*/
protected Font getNormalFont() {
if (SWTGraphicUtil.isMacOS()) {
return getFont(MAC_OS_DEFAULT_FONT, 11, SWT.NONE);
} else {
return getFont(WINDOWS_DEFAULT_FONT, 9, SWT.NONE);
}
}
/**
* @return the bigger font used by the dialog box
*/
protected Font getBiggerFont() {
if (SWTGraphicUtil.isMacOS()) {
return getFont(MAC_OS_DEFAULT_FONT, 13, SWT.NONE);
} else {
return getFont(WINDOWS_DEFAULT_FONT, 11, SWT.NONE);
}
}
/**
* Build a font
*
* @param name name of the font
* @param size size of the font
* @param style style of the font
* @return the font
*/
private Font getFont(final String name, final int size, final int style) {
final Font font = new Font(Display.getCurrent(), name, size, style);
parent.shell.addDisposeListener(e -> {
SWTGraphicUtil.safeDispose(font);
});
return font;
}
/**
* @return the title's color (blue)
*/
protected Color getTitleColor() {
final Color color = new Color(Display.getCurrent(), 35, 107, 178);
SWTGraphicUtil.addDisposer(parent.shell, color);
return color;
}
/**
* @return the grey color
*/
protected Color getGreyColor() {
final Color color = new Color(Display.getCurrent(), 240, 240, 240);
SWTGraphicUtil.addDisposer(parent.shell, color);
return color;
}
/**
* @return the image "fewer details"
*/
protected Image getFewerDetailsImage() {
return loadImage("images/" + FEWER_DETAILS_IMAGE);
}
/**
* @return the image "more details"
*/
protected Image getMoreDetailsImage() {
return loadImage("images/" + MORE_DETAILS_IMAGE);
}
/**
* Loads an image
*
* @param fileName file name of the image
* @return the image
*/
private Image loadImage(final String fileName) {
final Image image = SWTGraphicUtil.createImageFromFile(fileName);
SWTGraphicUtil.addDisposer(parent.shell, image);
return image;
}
}