Skip to content

Commit

Permalink
Add possibility to set the Shell titlebar color
Browse files Browse the repository at this point in the history
Change-Id: I1404194a2552ea240a106bdde6c9f872c9c57244
  • Loading branch information
ifurnadjiev committed Sep 6, 2021
1 parent 70599a0 commit 98b0779
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013 EclipseSource and others.
* Copyright (c) 2013, 2021 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -69,4 +69,32 @@ public void testSetsOverlay() {
verify( shell ).setData( WhiteListEntry.OVERLAY_COLOR.getKey(), expectedColor );
}

@Test( expected = IllegalArgumentException.class )
public void testSetTitlebarColor_FailsWithNegativeAlpha() {
Color color = new Color( display, 233, 244, 255 );

decorator.setTitlebarColor( color, -34 );
}

@Test( expected = IllegalArgumentException.class )
public void testSetTitlebarColor_FailsWithToBigAlpha() {
Color color = new Color( display, 233, 244, 255 );

decorator.setTitlebarColor( color, 256 );
}

@Test( expected = IllegalArgumentException.class )
public void testSetTitlebarColor_FailsWithNullColor() {
decorator.setTitlebarColor( null, 254 );
}

@Test
public void testSetTitlebarColor() {
Color color = new Color( display, 233, 244, 255 );
decorator.setTitlebarColor( color, 34 );

JsonArray expectedColor = new JsonArray().add( 233 ).add( 244 ).add( 255 ).add( 34 );
verify( shell ).setData( WhiteListEntry.TITLEBAR_COLOR.getKey(), expectedColor );
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2020 EclipseSource and others.
* Copyright (c) 2013, 2021 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -33,6 +33,7 @@ public enum WhiteListEntry {
SHOW_TOUCH( "showTouch" ),
BADGE_VALUE( "badgeValue" ),
OVERLAY_COLOR( "overlayColor" ),
TITLEBAR_COLOR( "titlebarColor" ),
TEXT_REPLACEMENT( "textReplacement" ),
AUTO_CAPITALIZE( "autoCapitalize" ),
KEYBOARD_APPEARANCE_MODE( "keyboardAppearanceMode" ),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013 EclipseSource and others.
* Copyright (c) 2013, 2021 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@
import static com.eclipsesource.tabris.internal.Clauses.when;
import static com.eclipsesource.tabris.internal.Clauses.whenNull;
import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.OVERLAY_COLOR;
import static com.eclipsesource.tabris.internal.DataWhitelist.WhiteListEntry.TITLEBAR_COLOR;
import static com.eclipsesource.tabris.internal.WidgetsUtil.setData;

import org.eclipse.rap.json.JsonArray;
Expand Down Expand Up @@ -51,4 +52,23 @@ public ShellDecorator setOverlayColor( Color color, int alpha ) {
setData( shell, OVERLAY_COLOR, overlay );
return this;
}

/**
* <p>
* Specifies the titlebar color of modal shells.
* </p>
*
* @param color the color to use for shell titlebar. Must not be <code>null</code>.
* @param alpha the alpha value of the color.
*
* @since 3.17
*/
public ShellDecorator setTitlebarColor( Color color, int alpha ) {
whenNull( color ).throwIllegalArgument( "Color must not be null" );
when( alpha < 0 || alpha > 255 ).throwIllegalArgument( "Alpha must be >= 0 and <= 255 but was " + alpha );
RGB rgb = color.getRGB();
JsonArray overlay = new JsonArray().add( rgb.red ).add( rgb.green ).add( rgb.blue ).add( alpha );
setData( shell, TITLEBAR_COLOR, overlay );
return this;
}
}

0 comments on commit 98b0779

Please sign in to comment.