1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.lttng
.scope
.tmf2
.views
.ui
.jfx
;
13 import java
.util
.concurrent
.ConcurrentHashMap
;
15 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.ColorDefinition
;
17 import javafx
.scene
.paint
.Color
;
19 public final class JfxColorFactory
{
21 private JfxColorFactory() {}
23 private static final Map
<ColorDefinition
, Color
> COLOR_MAP
= new ConcurrentHashMap
<>();
24 private static final Map
<ColorDefinition
, Color
> DERIVED_COLOR_MAP
= new ConcurrentHashMap
<>();
27 * Instantiate a {@link Color} from a {@link ColorDefinition} object.
31 * @return The Color object
33 public static synchronized Color
getColorFromDef(ColorDefinition colorDef
) {
34 Color color
= COLOR_MAP
.get(colorDef
);
36 color
= Color
.rgb(colorDef
.fRed
, colorDef
.fGreen
, colorDef
.fBlue
, (double) colorDef
.fAlpha
/ (double) ColorDefinition
.MAX
);
37 COLOR_MAP
.put(colorDef
, color
);
42 public static synchronized Color
getDerivedColorFromDef(ColorDefinition colorDef
) {
43 Color color
= DERIVED_COLOR_MAP
.get(colorDef
);
45 color
= getColorFromDef(colorDef
);
46 color
= color
.desaturate().darker();
47 DERIVED_COLOR_MAP
.put(colorDef
, color
);
53 * Convert a JavaFX {@link Color} to its equivalent {@link ColorDefinition}.
56 * The color to convert
57 * @return A corresponding ColorDefinition
59 public static ColorDefinition
colorToColorDef(Color color
) {
61 * ColorDefintion works with integer values 0 to 255, but JavaFX colors
62 * works with doubles 0.0 to 0.1
64 int red
= (int) Math
.round(color
.getRed() * 255);
65 int green
= (int) Math
.round(color
.getGreen() * 255);
66 int blue
= (int) Math
.round(color
.getBlue() * 255);
67 int opacity
= (int) Math
.round(color
.getOpacity() * 255);
68 return new ColorDefinition(red
, green
, blue
, opacity
);
This page took 0.037798 seconds and 5 git commands to generate.