Skip to content

Commit 4d2926c

Browse files
authored
Create new widget for tooltips as regular tooltip does not work in dark mode, fixes #2665 (#6430)
1 parent f5421f7 commit 4d2926c

File tree

4 files changed

+164
-6
lines changed

4 files changed

+164
-6
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hop.ui.core.gui;
19+
20+
import lombok.Setter;
21+
import org.apache.hop.ui.core.ConstUi;
22+
import org.apache.hop.ui.core.PropsUi;
23+
import org.eclipse.swt.SWT;
24+
import org.eclipse.swt.graphics.Point;
25+
import org.eclipse.swt.layout.FillLayout;
26+
import org.eclipse.swt.widgets.Display;
27+
import org.eclipse.swt.widgets.Label;
28+
import org.eclipse.swt.widgets.Shell;
29+
30+
/**
31+
* A custom tooltip implementation using a Shell and Label that supports proper dark mode styling.
32+
* This replaces the SWT ToolTip widget which doesn't support background/foreground color
33+
* customization.
34+
*/
35+
public class HopToolTip {
36+
37+
private final Shell tipShell;
38+
private final Label tipLabel;
39+
@Setter private boolean autoHide = true;
40+
41+
/**
42+
* Creates a new custom tooltip
43+
*
44+
* @param parent The parent shell
45+
*/
46+
public HopToolTip(Shell parent) {
47+
tipShell = new Shell(parent, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
48+
FillLayout layout = new FillLayout();
49+
layout.marginWidth = ConstUi.SMALL_MARGIN;
50+
layout.marginHeight = ConstUi.SMALL_MARGIN;
51+
tipShell.setLayout(layout);
52+
53+
tipLabel = new Label(tipShell, SWT.NONE);
54+
55+
// Apply dark mode styling
56+
GuiResource gui = GuiResource.getInstance();
57+
if (PropsUi.getInstance().isDarkMode()) {
58+
tipShell.setBackground(gui.getColor(32, 31, 27)); // Dark background
59+
tipLabel.setBackground(gui.getColor(32, 31, 27));
60+
tipLabel.setForeground(gui.getColor(224, 224, 224)); // Light text
61+
} else {
62+
tipShell.setBackground(gui.getColorWhite()); // Light background
63+
tipLabel.setBackground(gui.getColorWhite());
64+
tipLabel.setForeground(gui.getColorBlack()); // Dark text
65+
}
66+
67+
// Auto-hide when user clicks anywhere
68+
Display.getCurrent()
69+
.addFilter(
70+
SWT.MouseDown,
71+
event -> {
72+
if (autoHide && !tipShell.isDisposed() && tipShell.isVisible()) {
73+
setVisible(false);
74+
}
75+
});
76+
}
77+
78+
/**
79+
* Sets the tooltip text
80+
*
81+
* @param text The text to display
82+
*/
83+
public void setText(String text) {
84+
if (tipLabel != null && !tipLabel.isDisposed()) {
85+
tipLabel.setText(text != null ? text : "");
86+
tipShell.pack();
87+
}
88+
}
89+
90+
/**
91+
* Gets the tooltip text
92+
*
93+
* @return The current text
94+
*/
95+
public String getText() {
96+
if (tipLabel != null && !tipLabel.isDisposed()) {
97+
return tipLabel.getText();
98+
}
99+
return "";
100+
}
101+
102+
/**
103+
* Sets the tooltip location
104+
*
105+
* @param x The x coordinate
106+
* @param y The y coordinate
107+
*/
108+
public void setLocation(int x, int y) {
109+
if (tipShell != null && !tipShell.isDisposed()) {
110+
tipShell.setLocation(x, y);
111+
}
112+
}
113+
114+
/**
115+
* Sets the tooltip location
116+
*
117+
* @param location The location point
118+
*/
119+
public void setLocation(Point location) {
120+
setLocation(location.x, location.y);
121+
}
122+
123+
/**
124+
* Shows or hides the tooltip
125+
*
126+
* @param visible true to show, false to hide
127+
*/
128+
public void setVisible(boolean visible) {
129+
if (tipShell != null && !tipShell.isDisposed()) {
130+
tipShell.setVisible(visible);
131+
}
132+
}
133+
134+
/**
135+
* Checks if the tooltip is visible
136+
*
137+
* @return true if visible
138+
*/
139+
public boolean isVisible() {
140+
return tipShell != null && !tipShell.isDisposed() && tipShell.isVisible();
141+
}
142+
143+
/** Disposes the tooltip */
144+
public void dispose() {
145+
if (tipShell != null && !tipShell.isDisposed()) {
146+
tipShell.dispose();
147+
}
148+
}
149+
150+
/**
151+
* Checks if the tooltip is disposed
152+
*
153+
* @return true if disposed
154+
*/
155+
public boolean isDisposed() {
156+
return tipShell == null || tipShell.isDisposed();
157+
}
158+
}

ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
import org.apache.hop.ui.core.gui.GuiResource;
146146
import org.apache.hop.ui.core.gui.GuiToolbarWidgets;
147147
import org.apache.hop.ui.core.gui.HopNamespace;
148+
import org.apache.hop.ui.core.gui.HopToolTip;
148149
import org.apache.hop.ui.hopgui.CanvasFacade;
149150
import org.apache.hop.ui.hopgui.CanvasListener;
150151
import org.apache.hop.ui.hopgui.HopGui;
@@ -209,7 +210,6 @@
209210
import org.eclipse.swt.widgets.Shell;
210211
import org.eclipse.swt.widgets.ToolBar;
211212
import org.eclipse.swt.widgets.ToolItem;
212-
import org.eclipse.swt.widgets.ToolTip;
213213

214214
/**
215215
* This class handles the display of the pipelines in a graphical way using icons, arrows, etc. One
@@ -509,7 +509,7 @@ public HopGuiPipelineGraph(
509509

510510
sashForm.setWeights(100);
511511

512-
toolTip = new ToolTip(getShell(), SWT.BALLOON);
512+
toolTip = new HopToolTip(getShell());
513513
toolTip.setAutoHide(true);
514514

515515
iconSize = hopGui.getProps().getIconSize();

ui/src/main/java/org/apache/hop/ui/hopgui/file/shared/HopGuiAbstractGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.hop.ui.core.ConstUi;
3434
import org.apache.hop.ui.core.PropsUi;
3535
import org.apache.hop.ui.core.gui.GuiMenuWidgets;
36+
import org.apache.hop.ui.core.gui.HopToolTip;
3637
import org.apache.hop.ui.hopgui.HopGui;
3738
import org.apache.hop.ui.hopgui.file.IGraphSnapAlignDistribute;
3839
import org.apache.hop.ui.hopgui.file.IHopFileType;
@@ -41,7 +42,6 @@
4142
import org.eclipse.swt.widgets.Composite;
4243
import org.eclipse.swt.widgets.Display;
4344
import org.eclipse.swt.widgets.Shell;
44-
import org.eclipse.swt.widgets.ToolTip;
4545

4646
/**
4747
* The beginnings of a common graph object, used by {@code HopGuiWorkflowGraph} and {@code
@@ -62,7 +62,7 @@ public abstract class HopGuiAbstractGraph extends DragViewZoomBase
6262
protected Point noteOffset;
6363
protected Rectangle resizeArea;
6464
protected Resize resize;
65-
protected ToolTip toolTip;
65+
protected HopToolTip toolTip;
6666
protected String mouseOverName;
6767

6868
/**

ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import org.apache.hop.ui.core.gui.GuiResource;
106106
import org.apache.hop.ui.core.gui.GuiToolbarWidgets;
107107
import org.apache.hop.ui.core.gui.HopNamespace;
108+
import org.apache.hop.ui.core.gui.HopToolTip;
108109
import org.apache.hop.ui.hopgui.CanvasFacade;
109110
import org.apache.hop.ui.hopgui.CanvasListener;
110111
import org.apache.hop.ui.hopgui.HopGui;
@@ -173,7 +174,6 @@
173174
import org.eclipse.swt.widgets.Shell;
174175
import org.eclipse.swt.widgets.ToolBar;
175176
import org.eclipse.swt.widgets.ToolItem;
176-
import org.eclipse.swt.widgets.ToolTip;
177177

178178
/** Handles the display of Workflows in HopGui, in a graphical form. */
179179
@GuiPlugin(name = "i18n::WorkflowGraph.Name", description = "Workflow Graph GUI plugin")
@@ -421,7 +421,7 @@ public HopGuiWorkflowGraph(
421421

422422
sashForm.setWeights(100);
423423

424-
toolTip = new ToolTip(getShell(), SWT.BALLOON);
424+
toolTip = new HopToolTip(getShell());
425425
toolTip.setAutoHide(true);
426426

427427
newProps();

0 commit comments

Comments
 (0)