Skip to content

Commit a280671

Browse files
committed
[Themes] Refactor and support theme fonts
- Use Eclipse themes font definitions for application fonts rather than hand-rolling our own solution - Allow fonts to refresh when changed when theming is disabled - Allow colors to refresh when changed when theming is disabled - Refactor and add more convenience methods to ThemeUtils
1 parent 888e1fe commit a280671

File tree

21 files changed

+403
-254
lines changed

21 files changed

+403
-254
lines changed

com.archimatetool.editor.themes/plugin.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,11 @@ ACTIVE_NOFOCUS_TAB_BG_START=Active (no focus), selected part background begin
4747
ACTIVE_NOFOCUS_TAB_BG_END=Active (no focus), selected part background end
4848
ACTIVE_NOFOCUS_TAB_SELECTED_TEXT_COLOR=Active (no focus), selected part foreground
4949
LINK_COLOR=Link color
50+
51+
MODEL_TREE_FONT=Model Tree Font
52+
ANALYSIS_TABLE_FONT=Analysis Table Font
53+
MULTI_LINE_TEXT_FONT=Multi Line Text Control Font
54+
NAVIGATOR_TREE_FONT=Navigator Tree Font
55+
PROPERTIES_TABLE_FONT=Properties Table Font
56+
SINGLE_LINE_TEXT_FONT=Single Line Text Control Font
57+

com.archimatetool.editor.themes/plugin.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,36 @@
172172
label="%VISUALISER_BACKGROUND"
173173
value="255,255,255">
174174
</colorDefinition>
175+
<fontDefinition
176+
categoryId="com.archimatetool.editor.themes"
177+
id="com.archimatetool.editor.MODEL_TREE_FONT"
178+
label="%MODEL_TREE_FONT">
179+
</fontDefinition>
180+
<fontDefinition
181+
categoryId="com.archimatetool.editor.themes"
182+
id="com.archimatetool.editor.ANALYSIS_TABLE_FONT"
183+
label="%ANALYSIS_TABLE_FONT">
184+
</fontDefinition>
185+
<fontDefinition
186+
categoryId="com.archimatetool.editor.themes"
187+
id="com.archimatetool.editor.MULTI_LINE_TEXT_FONT"
188+
label="%MULTI_LINE_TEXT_FONT">
189+
</fontDefinition>
190+
<fontDefinition
191+
categoryId="com.archimatetool.editor.themes"
192+
id="com.archimatetool.editor.NAVIGATOR_TREE_FONT"
193+
label="%NAVIGATOR_TREE_FONT">
194+
</fontDefinition>
195+
<fontDefinition
196+
categoryId="com.archimatetool.editor.themes"
197+
id="com.archimatetool.editor.PROPERTIES_TABLE_FONT"
198+
label="%PROPERTIES_TABLE_FONT">
199+
</fontDefinition>
200+
<fontDefinition
201+
categoryId="com.archimatetool.editor.themes"
202+
id="com.archimatetool.editor.SINGLE_LINE_TEXT_FONT"
203+
label="%SINGLE_LINE_TEXT_FONT">
204+
</fontDefinition>
175205
</extension>
176206

177207
</plugin>
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,49 @@
11
/*******************************************************************************
2-
* Styling for Archi that over-rides some Eclipse stylings
2+
* Styling for Archi that over-rides some Eclipse stylings and sets stylings
33
*******************************************************************************/
44

55
/* Draw2d FigureCanvas used in GEF Editor */
6-
FigureCanvas.ArchiFigureCanvas {
6+
#ArchiFigureCanvas {
77
background-color: '#com-archimatetool-editor-VIEW_BACKGROUND';
88
}
99

1010
/* Zest Graph used in Zest graphs */
11-
Graph.ArchiGraph {
11+
#ArchiGraph {
1212
background-color: '#com-archimatetool-editor-VISUALISER_BACKGROUND';
1313
}
1414

15-
/* Set default colors here, so that user-set colors for the default light theme persists */
15+
/* Set default colors here in case a child theme does not declare them (ensures user-set colors for each theme persist) */
1616

1717
ColorDefinition#com-archimatetool-editor-VIEW_BACKGROUND {
1818
color: #FFFFFF;
1919
}
2020

2121
ColorDefinition#com-archimatetool-editor-VISUALISER_BACKGROUND {
2222
color: #FFFFFF;
23-
}
23+
}
24+
25+
/* Controls with user fonts */
26+
27+
#ModelTree {
28+
font-family: '#com-archimatetool-editor-MODEL_TREE_FONT';
29+
}
30+
31+
#AnalysisTable {
32+
font-family: '#com-archimatetool-editor-ANALYSIS_TABLE_FONT';
33+
}
34+
35+
#StyledTextControl {
36+
font-family: '#com-archimatetool-editor-MULTI_LINE_TEXT_FONT';
37+
}
38+
39+
#NavigatorTree {
40+
font-family: '#com-archimatetool-editor-NAVIGATOR_TREE_FONT';
41+
}
42+
43+
#UserPropertiesTable {
44+
font-family: '#com-archimatetool-editor-PROPERTIES_TABLE_FONT';
45+
}
46+
47+
#SingleTextControl {
48+
font-family: '#com-archimatetool-editor-SINGLE_LINE_TEXT_FONT';
49+
}

com.archimatetool.editor/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Require-Bundle: org.eclipse.core.runtime,
1919
com.archimatetool.model;visibility:=reexport,
2020
com.archimatetool.jdom,
2121
com.archimatetool.widgets,
22-
org.eclipse.e4.ui.model.workbench,
22+
org.eclipse.e4.core.services,
2323
org.eclipse.e4.core.contexts,
2424
org.eclipse.e4.ui.css.swt.theme,
2525
org.eclipse.equinox.p2.core,

com.archimatetool.editor/src/com/archimatetool/editor/diagram/AbstractDiagramEditor.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@
7070
import org.eclipse.swt.events.MouseAdapter;
7171
import org.eclipse.swt.events.MouseEvent;
7272
import org.eclipse.swt.events.MouseTrackAdapter;
73-
import org.eclipse.swt.graphics.Color;
7473
import org.eclipse.swt.graphics.Image;
75-
import org.eclipse.swt.graphics.RGB;
7674
import org.eclipse.swt.layout.GridData;
7775
import org.eclipse.swt.layout.GridLayout;
7876
import org.eclipse.swt.widgets.Composite;
@@ -357,14 +355,11 @@ protected void configureGraphicalViewer() {
357355
// Listen to selections
358356
hookSelectionListener();
359357

360-
// Set CSS class name
361-
viewer.getControl().setData("org.eclipse.e4.ui.css.CssClassName", "ArchiFigureCanvas"); //$NON-NLS-1$ //$NON-NLS-2$
358+
// Set CSS ID
359+
ThemeUtils.registerCssId(viewer.getControl(), "ArchiFigureCanvas"); //$NON-NLS-1$
362360

363361
// Set background color in case CSS theming is disabled
364-
RGB rgb = ThemeUtils.getCurrentThemeColor(IPreferenceConstants.VIEW_BACKGROUND_COLOR);
365-
if(rgb != null) {
366-
viewer.getControl().setBackground(new Color(rgb));
367-
}
362+
ThemeUtils.setBackgroundColorIfCssThemingDisabled(viewer.getControl(), IPreferenceConstants.VIEW_BACKGROUND_COLOR);
368363
}
369364

370365
private void hookSelectionListener() {

com.archimatetool.editor/src/com/archimatetool/editor/preferences/AppearancePreferencePage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void setValues() {
154154
}
155155
}
156156

157-
fUseThemes.setSelection(ThemeUtils.getThemeEngine() != null);
157+
fUseThemes.setSelection(themeEngine != null);
158158
fShowStatusLineButton.setSelection(getPreferenceStore().getBoolean(SHOW_STATUS_LINE));
159159
fUseRoundTabsButton.setSelection(ThemeUtils.getSwtRendererPreferences().getBoolean(ThemeUtils.USE_ROUND_TABS, false));
160160

com.archimatetool.editor/src/com/archimatetool/editor/preferences/ColoursPreferencePage.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.eclipse.ui.IWorkbench;
4545
import org.eclipse.ui.IWorkbenchPreferencePage;
4646
import org.eclipse.ui.PlatformUI;
47+
import org.eclipse.ui.internal.util.PrefUtil;
4748

4849
import com.archimatetool.editor.ArchiPlugin;
4950
import com.archimatetool.editor.ui.ArchiLabelProvider;
@@ -65,6 +66,7 @@
6566
*
6667
* @author Phillip Beauvoir
6768
*/
69+
@SuppressWarnings("restriction")
6870
public class ColoursPreferencePage
6971
extends PreferencePage
7072
implements IWorkbenchPreferencePage, IPreferenceConstants {
@@ -710,17 +712,18 @@ private void saveThemeColors() {
710712
// Remove listener so we are not notified
711713
PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(themeChangeListener);
712714

713-
boolean themeResetNeeded = false;
715+
boolean themeColorChanged = false;
714716

715717
for(String colorId : themeColors) {
716718
Color color = fColorsCache.get(colorId);
717719
if(color != null && !color.getRGB().equals(ThemeUtils.getCurrentThemeColor(colorId))) {
718720
ThemeUtils.setCurrentThemeColor(colorId, color.getRGB());
719-
themeResetNeeded = true;
721+
themeColorChanged = true;
720722
}
721723
}
722724

723-
if(themeResetNeeded) {
725+
if(themeColorChanged) {
726+
PrefUtil.savePrefs();
724727
ThemeUtils.resetCurrentTheme();
725728
}
726729
}
@@ -732,7 +735,7 @@ private void saveThemeColors() {
732735

733736
@Override
734737
public void init(IWorkbench workbench) {
735-
// Listen to external theme/color changes to update our theme colors to match current theme.
738+
// Listen to external theme/color changes to update our theme colors to match current theme in case user changed the theme in prefs.
736739
// A side effect is that we trigger this event when setting a theme color so remove our listener when setting theme colors.
737740
themeChangeListener = event -> {
738741
if(themeColors.contains(event.getProperty())) {

0 commit comments

Comments
 (0)