Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ProjectUtilities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Control System
Libraries
java
ProjectUtilities
Commits
afbfbcb7
Commit
afbfbcb7
authored
10 months ago
by
Raphael GIRARDOT
Browse files
Options
Downloads
Patches
Plain Diff
- NullPointerException avoided (detected during SCAN-968)
- Removed deprecated methods
parent
6cbc4978
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
AwtUtilities/src/main/java/fr/soleil/lib/project/awt/ColorUtils.java
+47
-71
47 additions, 71 deletions
...s/src/main/java/fr/soleil/lib/project/awt/ColorUtils.java
with
47 additions
and
71 deletions
AwtUtilities/src/main/java/fr/soleil/lib/project/awt/ColorUtils.java
+
47
−
71
View file @
afbfbcb7
...
...
@@ -192,19 +192,6 @@ public class ColorUtils {
return
ret
;
}
/**
* Calls {@link #getNextColor()} from default instance.
*
* @return An unused {@link Color}.
* @see #getNextColor()
* @deprecated You should use your own instance of {@link ColorRotationTool}, and call {@link #getNextColor()}
* instead
*/
@Deprecated
public
static
Color
getNewColor
()
{
return
COLOR_ROTATOR
.
getNextColor
();
}
/**
* Generates a new {@link Color} array that can be used for {@link Color} rotation
*
...
...
@@ -264,7 +251,7 @@ public class ColorUtils {
* @see #isTooNear(double, double)
*/
protected
static
double
toGrayBrightnessDistanceTest
(
Color
color
)
{
return
getRealGray
(
color
.
getRGB
());
return
color
==
null
?
Double
.
NaN
:
getRealGray
(
color
.
getRGB
());
}
/**
...
...
@@ -462,6 +449,10 @@ public class ColorUtils {
* @return Blended color.
*/
public
static
Color
blend
(
Color
color1
,
Color
color2
,
double
ratio
)
{
Color
color
;
if
((
color1
==
null
)
||
(
color2
==
null
))
{
color
=
null
;
}
else
{
float
r
=
(
float
)
ratio
;
float
ir
=
(
float
)
1.0
-
r
;
...
...
@@ -471,8 +462,8 @@ public class ColorUtils {
color1
.
getColorComponents
(
rgb1
);
color2
.
getColorComponents
(
rgb2
);
Color
color
=
new
Color
(
rgb1
[
0
]
*
r
+
rgb2
[
0
]
*
ir
,
rgb1
[
1
]
*
r
+
rgb2
[
1
]
*
ir
,
rgb1
[
2
]
*
r
+
rgb2
[
2
]
*
ir
);
color
=
new
Color
(
rgb1
[
0
]
*
r
+
rgb2
[
0
]
*
ir
,
rgb1
[
1
]
*
r
+
rgb2
[
1
]
*
ir
,
rgb1
[
2
]
*
r
+
rgb2
[
2
]
*
ir
);
}
return
color
;
}
...
...
@@ -507,7 +498,7 @@ public class ColorUtils {
* @return Blended color.
*/
public
static
Color
blend
(
Color
color1
,
Color
color2
)
{
return
blend
(
color1
,
color2
,
0.5
);
return
color1
==
null
||
color2
==
null
?
null
:
blend
(
color1
,
color2
,
0.5
);
}
/**
...
...
@@ -529,7 +520,7 @@ public class ColorUtils {
* @return Darker color.
*/
public
static
Color
darker
(
Color
color
,
double
fraction
)
{
return
new
Color
(
darker
(
color
.
getRGB
(),
fraction
),
true
);
return
color
==
null
?
null
:
new
Color
(
darker
(
color
.
getRGB
(),
fraction
),
true
);
}
/**
...
...
@@ -565,32 +556,6 @@ public class ColorUtils {
return
toRGBA
(
red
,
green
,
blue
,
alpha
);
}
/**
* Make a color lighter.
*
* @param color Color to make lighter.
* @param fraction Darkness fraction.
* @return Lighter color.
* @deprecated Use {@link #brighter(Color, double)} instead.
*/
@Deprecated
public
static
Color
lighter
(
Color
color
,
double
fraction
)
{
return
brighter
(
color
,
fraction
);
}
/**
* Make a color lighter.
*
* @param rgba Color to make lighter.
* @param fraction Darkness fraction.
* @return Lighter color's rgb.
* @deprecated Use {@link #brighter(int, double)} instead
*/
@Deprecated
public
static
int
lighter
(
int
rgba
,
double
fraction
)
{
return
brighter
(
rgba
,
fraction
);
}
/**
* Make a color brighter.
*
...
...
@@ -599,7 +564,7 @@ public class ColorUtils {
* @return Brighter color.
*/
public
static
Color
brighter
(
Color
color
,
double
fraction
)
{
return
new
Color
(
brighter
(
color
.
getRGB
(),
fraction
),
true
);
return
color
==
null
?
null
:
new
Color
(
brighter
(
color
.
getRGB
(),
fraction
),
true
);
}
/**
...
...
@@ -620,7 +585,7 @@ public class ColorUtils {
* @return Brighter color.
*/
public
static
Color
brighter
(
Color
base
)
{
return
new
Color
(
brighter
(
base
.
getRGB
()),
true
);
return
base
==
null
?
null
:
new
Color
(
brighter
(
base
.
getRGB
()),
true
);
}
/**
...
...
@@ -673,7 +638,7 @@ public class ColorUtils {
* @return Hex name of color: "rrggbb".
*/
public
static
String
getHexName
(
Color
color
)
{
return
getHexName
(
color
.
getRGB
());
return
color
==
null
?
null
:
getHexName
(
color
.
getRGB
());
}
/**
...
...
@@ -721,7 +686,8 @@ public class ColorUtils {
* @return Distance between colors.
*/
public
static
double
colorDistance
(
double
[]
color1
,
double
[]
color2
)
{
return
colorDistance
(
color1
[
0
],
color1
[
1
],
color1
[
2
],
color2
[
0
],
color2
[
1
],
color2
[
2
]);
return
color1
==
null
||
color2
==
null
||
color1
.
length
<
3
||
color2
.
length
<
3
?
Double
.
NaN
:
colorDistance
(
color1
[
0
],
color1
[
1
],
color1
[
2
],
color2
[
0
],
color2
[
1
],
color2
[
2
]);
}
/**
...
...
@@ -732,13 +698,19 @@ public class ColorUtils {
* @return Distance between colors.
*/
public
static
double
colorDistance
(
Color
color1
,
Color
color2
)
{
double
distance
;
if
(
color1
==
null
||
color2
==
null
)
{
distance
=
Double
.
NaN
;
}
else
{
float
rgb1
[]
=
new
float
[
3
];
float
rgb2
[]
=
new
float
[
3
];
color1
.
getColorComponents
(
rgb1
);
color2
.
getColorComponents
(
rgb2
);
return
colorDistance
(
rgb1
[
0
],
rgb1
[
1
],
rgb1
[
2
],
rgb2
[
0
],
rgb2
[
1
],
rgb2
[
2
]);
distance
=
colorDistance
(
rgb1
[
0
],
rgb1
[
1
],
rgb1
[
2
],
rgb2
[
0
],
rgb2
[
1
],
rgb2
[
2
]);
}
return
distance
;
}
/**
...
...
@@ -776,7 +748,7 @@ public class ColorUtils {
* @return True if this is a "dark" color, false otherwise.
*/
public
static
boolean
isDark
(
Color
color
)
{
return
isDark
(
color
.
getRGB
());
return
color
==
null
?
false
:
isDark
(
color
.
getRGB
());
}
/**
...
...
@@ -802,7 +774,7 @@ public class ColorUtils {
* @return A {@link Color}
*/
public
static
Color
getMediumColor
(
Color
c1
,
Color
c2
)
{
return
new
Color
(
getMediumColor
(
c1
.
getRGB
(),
c2
.
getRGB
()));
return
c1
==
null
||
c2
==
null
?
null
:
new
Color
(
getMediumColor
(
c1
.
getRGB
(),
c2
.
getRGB
()));
}
/**
...
...
@@ -818,6 +790,7 @@ public class ColorUtils {
}
private
static
void
checkLabel
(
Label
colorLabel
,
Color
refColorToAvoid
)
{
if
((
colorLabel
!=
null
)
&&
(
refColorToAvoid
!=
null
))
{
if
(
isTooNear
(
toGrayBrightnessDistanceTest
(
colorLabel
.
getBackground
()),
toGrayBrightnessDistanceTest
(
refColorToAvoid
)))
{
colorLabel
.
setText
(
"skipped"
);
...
...
@@ -825,15 +798,18 @@ public class ColorUtils {
colorLabel
.
setText
(
ObjectUtils
.
EMPTY_STRING
);
}
}
}
private
static
Label
generateLabel
(
Color
bg
,
Color
refColorToAvoid
)
{
Label
colorLabel
=
new
Label
();
if
(
bg
!=
null
)
{
colorLabel
.
setBackground
(
bg
);
Color
fg
=
Math
.
round
(
ColorUtils
.
getRealGray
(
bg
))
<
128
?
Color
.
WHITE
:
Color
.
BLACK
;
colorLabel
.
setForeground
(
fg
);
if
(
isTooNear
(
toGrayBrightnessDistanceTest
(
bg
),
toGrayBrightnessDistanceTest
(
refColorToAvoid
)))
{
colorLabel
.
setText
(
"skipped"
);
}
}
return
colorLabel
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment