Skip to content

Commit 98b0779

Browse files
committed
Add possibility to set the Shell titlebar color
Change-Id: I1404194a2552ea240a106bdde6c9f872c9c57244
1 parent 70599a0 commit 98b0779

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

com.eclipsesource.tabris.test/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecoratorTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2013 EclipseSource and others.
2+
* Copyright (c) 2013, 2021 EclipseSource and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -69,4 +69,32 @@ public void testSetsOverlay() {
6969
verify( shell ).setData( WhiteListEntry.OVERLAY_COLOR.getKey(), expectedColor );
7070
}
7171

72+
@Test( expected = IllegalArgumentException.class )
73+
public void testSetTitlebarColor_FailsWithNegativeAlpha() {
74+
Color color = new Color( display, 233, 244, 255 );
75+
76+
decorator.setTitlebarColor( color, -34 );
77+
}
78+
79+
@Test( expected = IllegalArgumentException.class )
80+
public void testSetTitlebarColor_FailsWithToBigAlpha() {
81+
Color color = new Color( display, 233, 244, 255 );
82+
83+
decorator.setTitlebarColor( color, 256 );
84+
}
85+
86+
@Test( expected = IllegalArgumentException.class )
87+
public void testSetTitlebarColor_FailsWithNullColor() {
88+
decorator.setTitlebarColor( null, 254 );
89+
}
90+
91+
@Test
92+
public void testSetTitlebarColor() {
93+
Color color = new Color( display, 233, 244, 255 );
94+
decorator.setTitlebarColor( color, 34 );
95+
96+
JsonArray expectedColor = new JsonArray().add( 233 ).add( 244 ).add( 255 ).add( 34 );
97+
verify( shell ).setData( WhiteListEntry.TITLEBAR_COLOR.getKey(), expectedColor );
98+
}
99+
72100
}

com.eclipsesource.tabris/src/com/eclipsesource/tabris/internal/DataWhitelist.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2013, 2020 EclipseSource and others.
2+
* Copyright (c) 2013, 2021 EclipseSource and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -33,6 +33,7 @@ public enum WhiteListEntry {
3333
SHOW_TOUCH( "showTouch" ),
3434
BADGE_VALUE( "badgeValue" ),
3535
OVERLAY_COLOR( "overlayColor" ),
36+
TITLEBAR_COLOR( "titlebarColor" ),
3637
TEXT_REPLACEMENT( "textReplacement" ),
3738
AUTO_CAPITALIZE( "autoCapitalize" ),
3839
KEYBOARD_APPEARANCE_MODE( "keyboardAppearanceMode" ),

com.eclipsesource.tabris/src/com/eclipsesource/tabris/widgets/enhancement/ShellDecorator.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2013 EclipseSource and others.
2+
* Copyright (c) 2013, 2021 EclipseSource and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@
1313
import static com.eclipsesource.tabris.internal.Clauses.when;
1414
import static com.eclipsesource.tabris.internal.Clauses.whenNull;
1515
import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.OVERLAY_COLOR;
16+
import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.TITLEBAR_COLOR;
1617
import static com.eclipsesource.tabris.internal.WidgetsUtil.setData;
1718

1819
import org.eclipse.rap.json.JsonArray;
@@ -51,4 +52,23 @@ public ShellDecorator setOverlayColor( Color color, int alpha ) {
5152
setData( shell, OVERLAY_COLOR, overlay );
5253
return this;
5354
}
55+
56+
/**
57+
* <p>
58+
* Specifies the titlebar color of modal shells.
59+
* </p>
60+
*
61+
* @param color the color to use for shell titlebar. Must not be <code>null</code>.
62+
* @param alpha the alpha value of the color.
63+
*
64+
* @since 3.17
65+
*/
66+
public ShellDecorator setTitlebarColor( Color color, int alpha ) {
67+
whenNull( color ).throwIllegalArgument( "Color must not be null" );
68+
when( alpha < 0 || alpha > 255 ).throwIllegalArgument( "Alpha must be >= 0 and <= 255 but was " + alpha );
69+
RGB rgb = color.getRGB();
70+
JsonArray overlay = new JsonArray().add( rgb.red ).add( rgb.green ).add( rgb.blue ).add( alpha );
71+
setData( shell, TITLEBAR_COLOR, overlay );
72+
return this;
73+
}
5474
}

0 commit comments

Comments
 (0)