Skip to content

Commit

Permalink
Improve the look & feel of the widgets per operating system apache#2395
Browse files Browse the repository at this point in the history
- Some tweaks for Windows dark mode
- Add some missings setLook
- MetaSelectionLine initializes its own look
- StyledTextComp propagate colors to text widget
- Increase the height of the tab folder for Windows
  • Loading branch information
nadment committed Feb 18, 2023
1 parent 3c30e13 commit c91bd67
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void createControl(Composite parent) {
fdlTestType.right = new FormAttachment(middle, -margin);
wlTestType.setLayoutData(fdlTestType);
wTestType = new Combo(parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
PropsUi.setLook(wTestType);
FormData fdTestType = new FormData();
fdTestType.top = new FormAttachment(wlTestType, 0, SWT.CENTER);
fdTestType.left = new FormAttachment(middle, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,8 @@ private void addInjectTab() {
wInjectComp.setLayout(fileLayout);

// Add a search bar at the top...
ToolBar treeTb = new ToolBar(wInjectComp, SWT.HORIZONTAL | SWT.FLAT);
PropsUi.setLook(treeTb);

ToolBar treeTb = new ToolBar(wInjectComp, SWT.HORIZONTAL | SWT.FLAT);
PropsUi.setLook(treeTb, PropsUi.WIDGET_STYLE_DEFAULT);
ToolItem wFilter = new ToolItem(treeTb, SWT.SEPARATOR);
wSearchText = new Text(treeTb, SWT.SEARCH | SWT.CANCEL | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
wSearchText.setData(BaseDialog.NO_DEFAULT_HANDLER, true);
Expand Down Expand Up @@ -669,7 +668,8 @@ private void addInjectTab() {
fdTree.right = new FormAttachment(100, 0);
fdTree.bottom = new FormAttachment(100, 0);
wTree.setLayoutData(fdTree);

PropsUi.setLook(wTree);

ColumnInfo[] colinf =
new ColumnInfo[] {
new ColumnInfo(
Expand Down
212 changes: 181 additions & 31 deletions ui/src/main/java/org/apache/hop/ui/core/PropsUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;

import java.util.HashMap;
Expand Down Expand Up @@ -153,43 +154,29 @@ public void setDefault() {
}
}

// The user manually selected Dark Mode
// We'll try to change settings to make this possible.
//
// Various tweaks to improve dark theme experience on Windows
if (OsHelper.isWindows() && isDarkMode()) {
display.setData("org.eclipse.swt.internal.win32.useDarkModeExplorerTheme", Boolean.TRUE);
display.setData("org.eclipse.swt.internal.win32.useShellTitleColoring", Boolean.TRUE);
display.setData(
"org.eclipse.swt.internal.win32.menuBarForegroundColor",
display.setData("org.eclipse.swt.internal.win32.useDarkModeExplorerTheme", true);
display.setData("org.eclipse.swt.internal.win32.useShellTitleColoring", true);
display.setData("org.eclipse.swt.internal.win32.menuBarForegroundColor",
new Color(display, 0xD0, 0xD0, 0xD0));
display.setData(
"org.eclipse.swt.internal.win32.menuBarBackgroundColor",
display.setData("org.eclipse.swt.internal.win32.menuBarBackgroundColor",
new Color(display, 0x30, 0x30, 0x30));
display.setData(
"org.eclipse.swt.internal.win32.menuBarBorderColor",
display.setData("org.eclipse.swt.internal.win32.menuBarBorderColor",
new Color(display, 0x50, 0x50, 0x50));
display.setData("org.eclipse.swt.internal.win32.Canvas.use_WS_BORDER", Boolean.TRUE);
display.setData("org.eclipse.swt.internal.win32.List.use_WS_BORDER", Boolean.TRUE);
display.setData("org.eclipse.swt.internal.win32.Table.use_WS_BORDER", Boolean.TRUE);
display.setData("org.eclipse.swt.internal.win32.Combo.use_WS_BORDER", Boolean.TRUE);
display.setData("org.eclipse.swt.internal.win32.Text.use_WS_BORDER", Boolean.TRUE);
display.setData("org.eclipse.swt.internal.win32.Tree.use_WS_BORDER", Boolean.TRUE);
display.setData(
"org.eclipse.swt.internal.win32.Table.headerLineColor",
display.setData("org.eclipse.swt.internal.win32.all.use_WS_BORDER", true);
display.setData("org.eclipse.swt.internal.win32.Table.headerLineColor",
new Color(display, 0x50, 0x50, 0x50));
display.setData(
"org.eclipse.swt.internal.win32.Label.disabledForegroundColor",
display.setData("org.eclipse.swt.internal.win32.Label.disabledForegroundColor",
new Color(display, 0x80, 0x80, 0x80));
display.setData("org.eclipse.swt.internal.win32.Combo.useDarkTheme", Boolean.TRUE);
display.setData(
"org.eclipse.swt.internal.win32.ToolBar.backgroundColor",
display.setData("org.eclipse.swt.internal.win32.Combo.useDarkTheme", true);
display.setData("org.eclipse.swt.internal.win32.ToolBar.backgroundColor",
new Color(display, 0xD0, 0xD0, 0xD0));
display.setData(
"org.eclipse.swt.internal.win32.Combo.backgroundColor",
display.setData("org.eclipse.swt.internal.win32.Combo.backgroundColor",
new Color(display, 0xD0, 0xD0, 0xD0));
display.setData("org.eclipse.swt.internal.win32.ProgressBar.useColors", Boolean.TRUE);
display.setData("org.eclipse.swt.internal.win32.ProgressBar.useColors", true);
}

if (display != null) {
FontData fontData = getDefaultFont();
setProperty(STRING_FONT_DEFAULT_NAME, fontData.getName());
Expand Down Expand Up @@ -481,7 +468,7 @@ public void setShowTableViewToolbar(boolean show) {

public static void setLook(Widget widget) {
int style = WIDGET_STYLE_DEFAULT;
if (widget instanceof Table) {
if (widget instanceof Table || widget instanceof Tree) {
style = WIDGET_STYLE_TABLE;
} else if (widget instanceof ToolBar) {
style = WIDGET_STYLE_TOOLBAR;
Expand All @@ -498,15 +485,107 @@ public static void setLook(Widget widget) {
}

setLook(widget, style);

if (widget instanceof Composite) {
for (Control child : ((Composite) widget).getChildren()) {
Composite composite = (Composite) widget;
for (Control child : composite.getChildren()) {
setLook(child);
}
}
}

public static void setLook(final Widget widget, int style) {
if (OsHelper.isWindows()) {
setLookOnWindows(widget, style);
} else if (OsHelper.isMac()) {
setLookOnMac(widget, style);
} else {
setLookOnLinux(widget, style);
}
}

protected static void setLookOnWindows(final Widget widget, int style) {
final GuiResource gui = GuiResource.getInstance();
Font font = gui.getFontDefault();
Color background = null;
Color foreground = null;

if ( widget instanceof Shell ) {
background = gui.getColorWhite();
foreground = gui.getColorBlack();
Shell shell = (Shell) widget;
shell.setBackgroundMode(SWT.INHERIT_FORCE);
shell.setForeground(gui.getColorBlack());
shell.setBackground(gui.getColorWhite());
return;
}

switch (style) {
case WIDGET_STYLE_DEFAULT:
background = gui.getColorWhite();
foreground = gui.getColorBlack();
break;
case WIDGET_STYLE_FIXED:
font = gui.getFontFixed();
background = gui.getColorWhite();
foreground = gui.getColorBlack();
break;
case WIDGET_STYLE_TABLE:
if (PropsUi.getInstance().isDarkMode()) {
background = gui.getColorWhite();
foreground = gui.getColorBlack();
if (widget instanceof Table) {
Table table = (Table) widget;
table.setHeaderBackground(gui.getColorLightGray());
table.setHeaderForeground(gui.getColorDarkGray());
}
else if (widget instanceof Tree) {
Tree tree = (Tree) widget;
tree.setHeaderBackground(gui.getColorLightGray());
tree.setHeaderForeground(gui.getColorDarkGray());
}
}
break;
case WIDGET_STYLE_TOOLBAR:
if (PropsUi.getInstance().isDarkMode() ) {
background = gui.getColorLightGray();
foreground = gui.getColorBlack();
}
break;
case WIDGET_STYLE_TAB:
CTabFolder tabFolder = (CTabFolder) widget;
tabFolder.setBorderVisible(true);
tabFolder.setTabHeight(28);
if (PropsUi.getInstance().isDarkMode()) {
tabFolder.setBackground(gui.getColorWhite());
tabFolder.setForeground(gui.getColorBlack());
tabFolder.setSelectionBackground(gui.getColorWhite());
tabFolder.setSelectionForeground(gui.getColorBlack());
}
break;
case WIDGET_STYLE_PUSH_BUTTON:
break;
default:
background = gui.getColorGray();
font = null;
break;
}

if (font != null && !font.isDisposed() && (widget instanceof Control)) {
((Control) widget).setFont(font);
}

if (background != null && !background.isDisposed() && (widget instanceof Control)) {
((Control) widget).setBackground(background);
}

if (foreground != null && !foreground.isDisposed() && (widget instanceof Control)) {
((Control) widget).setForeground(foreground);
}
}


protected static void setLookOnMac(final Widget widget, int style) {
final GuiResource gui = GuiResource.getInstance();
Font font = gui.getFontDefault();
Color background = gui.getColorWhite();
Expand Down Expand Up @@ -576,7 +655,78 @@ public static void setLook(final Widget widget, int style) {
((Control) widget).setForeground(foreground);
}
}

protected static void setLookOnLinux(final Widget widget, int style) {
final GuiResource gui = GuiResource.getInstance();
Font font = gui.getFontDefault();
Color background = gui.getColorWhite();
Color foreground = gui.getColorBlack();

switch (style) {
case WIDGET_STYLE_DEFAULT:
break;
case WIDGET_STYLE_OSX_GROUP:
background = gui.getColorWhite();
foreground = gui.getColorBlack();
font = gui.getFontDefault();
Group group = ((Group) widget);
group.addPaintListener(
paintEvent -> {
paintEvent.gc.setForeground(gui.getColorBlack());
paintEvent.gc.setBackground(gui.getColorWhite());
paintEvent.gc.fillRectangle(
2, 0, group.getBounds().width - 8, group.getBounds().height - 20);
});
break;
case WIDGET_STYLE_FIXED:
font = gui.getFontFixed();
break;
case WIDGET_STYLE_TABLE:
background = gui.getColorLightGray();
foreground = gui.getColorDarkGray();

Table table = (Table) widget;
table.setHeaderBackground(gui.getColorLightGray());
table.setHeaderForeground(gui.getColorDarkGray());
break;
case WIDGET_STYLE_TOOLBAR:
if (PropsUi.getInstance().isDarkMode()) {
background = gui.getColorLightGray();
} else {
background = gui.getColorDemoGray();
}
break;
case WIDGET_STYLE_TAB:
CTabFolder tabFolder = (CTabFolder) widget;
tabFolder.setBorderVisible(true);
tabFolder.setBackground(gui.getColorGray());
tabFolder.setForeground(gui.getColorBlack());
tabFolder.setSelectionBackground(gui.getColorWhite());
tabFolder.setSelectionForeground(gui.getColorBlack());
break;
case WIDGET_STYLE_PUSH_BUTTON:
background = null;
foreground = null;
break;
default:
background = gui.getColorBackground();
font = null;
break;
}

if (font != null && !font.isDisposed() && (widget instanceof Control)) {
((Control) widget).setFont(font);
}

if (background != null && !background.isDisposed() && (widget instanceof Control)) {
((Control) widget).setBackground(background);
}

if (foreground != null && !foreground.isDisposed() && (widget instanceof Control)) {
((Control) widget).setForeground(foreground);
}
}

/**
* @return Returns the display.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private void addGeneralTab() {
fdToolBar.right = new FormAttachment(100, 0);
fdToolBar.top = new FormAttachment(0, 0);
wToolBar.setLayoutData(fdToolBar);
PropsUi.setLook(wToolBar);
PropsUi.setLook(wToolBar, PropsUi.WIDGET_STYLE_DEFAULT);

ToolItem item = new ToolItem(wToolBar, SWT.PUSH);
item.setImage(GuiResource.getInstance().getImageHelpWeb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public GuiAction open() {
searchComposite,
SWT.LEFT | SWT.BORDER | SWT.SINGLE | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
wSearch.setLayoutData(new GridData(GridData.FILL_BOTH));
PropsUi.setLook(wSearch, Props.WIDGET_STYLE_TOOLBAR);

// Create a toolbar at the right of the search bar...
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void shellClosed(ShellEvent e) {
wCancel.addListener(SWT.Selection, e -> cancel());

BaseTransformDialog.positionBottomButtons(
shell, new Button[] {wOk, wCancel}, props.getMargin(), null);
shell, new Button[] {wOk, wCancel}, PropsUi.getMargin(), null);

///////////////////////////////////////////////////////////////////////////////////////////////////////
// On top there are the navigation
Expand All @@ -316,9 +316,9 @@ public void shellClosed(ShellEvent e) {

// A toolbar above the browser, below the filename
//
ToolBar navigateToolBar = new ToolBar(navigateComposite, SWT.LEFT | SWT.HORIZONTAL);
ToolBar navigateToolBar = new ToolBar(navigateComposite, SWT.LEFT | SWT.HORIZONTAL);
navigateToolBar.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));
PropsUi.setLook(navigateToolBar);
PropsUi.setLook(navigateToolBar, PropsUi.WIDGET_STYLE_DEFAULT);

navigateToolbarWidgets = new GuiToolbarWidgets();
navigateToolbarWidgets.registerGuiPluginObject(this);
Expand All @@ -344,9 +344,9 @@ public void shellClosed(ShellEvent e) {
SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
FormData fdSashForm = new FormData();
fdSashForm.left = new FormAttachment(0, 0);
fdSashForm.top = new FormAttachment(navigateComposite, props.getMargin());
fdSashForm.top = new FormAttachment(navigateComposite, PropsUi.getMargin());
fdSashForm.right = new FormAttachment(100, 0);
fdSashForm.bottom = new FormAttachment(wOk, (int) (-props.getMargin() * props.getZoomFactor()));
fdSashForm.bottom = new FormAttachment(wOk, (int) (-PropsUi.getMargin() * props.getZoomFactor()));
sashForm.setLayoutData(fdSashForm);

PropsUi.setLook(sashForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,19 @@ public MetaSelectionLine(

// Toolbar for default actions
//
wToolBar = new ToolBar(this, SWT.FLAT | SWT.HORIZONTAL);
wToolBar = new ToolBar(this, SWT.FLAT | SWT.HORIZONTAL);
PropsUi.setLook(wToolBar, PropsUi.WIDGET_STYLE_DEFAULT);
FormData fdToolBar = new FormData();
fdToolBar.right = new FormAttachment(100, 0);
fdToolBar.top = new FormAttachment(0, 0);
wToolBar.setLayoutData(fdToolBar);
//wToolBar.setBackgroundMode(SWT.INHERIT_DEFAULT);
wToolBar.setBackground(GuiResource.getInstance().getColorGreen());
//wToolBar.setForeground(GuiResource.getInstance().getColorBackground());


// Add more toolbar items from plugins.
//
GuiToolbarWidgets toolbarWidgets = new GuiToolbarWidgets();
toolbarWidgets.registerGuiPluginObject(this);
toolbarWidgets.setItemBackgroundColor(GuiResource.getInstance().getColorBackground());
toolbarWidgets.registerGuiPluginObject(this);
// Removed for Windows dark mode
// toolbarWidgets.setItemBackgroundColor(GuiResource.getInstance().getColorBackground());
toolbarWidgets.createToolbarWidgets(wToolBar, GUI_PLUGIN_TOOLBAR_PARENT_ID);

int textFlags = SWT.SINGLE | SWT.LEFT | SWT.BORDER;
Expand Down
12 changes: 12 additions & 0 deletions ui/src/main/java/org/apache/hop/ui/core/widget/StyledTextComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ public void setSelection(int arg0, int arg1) {
textWidget.setSelection(arg0, arg1);
}

@Override
public void setBackground(Color color) {
super.setBackground(color);
textWidget.setBackground(color);
}

@Override
public void setForeground(Color color) {
super.setForeground(color);
textWidget.setForeground(color);
}

@Override
public void setFont(Font fnt) {
textWidget.setFont(fnt);
Expand Down
Loading

0 comments on commit c91bd67

Please sign in to comment.