forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto group colour assignment (JabRef#10521)
* Add auto group colour assignment * Add clickable option for auto colour assignment * Change button to checkbox * Start working on using the context of the current group for coloring Co-authored-by: Carl Christian Snethlage <[email protected]> * First short for colorful subgroups * When creating a new group, it inhertics the icon of the parent group * Add checkbox for coloring of groups Co-authored-by: Carl Christian Snethlage <[email protected]> * Help button leaves dialog opened Co-authored-by: Carl Christian Snethlage <[email protected]> * Fix missing "Collect by" header Co-authored-by: Carl Christian Snethlage <[email protected]> --------- Co-authored-by: Oliver Kopp <[email protected]> Co-authored-by: Carl Christian Snethlage <[email protected]>
- Loading branch information
1 parent
82f1749
commit 31467be
Showing
13 changed files
with
258 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.jabref.gui.groups; | ||
|
||
import java.util.List; | ||
|
||
import javafx.scene.paint.Color; | ||
|
||
import org.jspecify.annotations.NullMarked; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
@NullMarked | ||
public class GroupColorPicker { | ||
|
||
// Generate color for top groups | ||
public static Color generateColor(List<Color> siblingColors) { | ||
return generateColor(siblingColors, null); | ||
} | ||
|
||
/** | ||
* Algorithm optimized for colors, not for gray-scale (where it does not work) | ||
*/ | ||
public static Color generateColor(List<Color> siblingColors, @Nullable Color parentColor) { | ||
if (siblingColors.isEmpty()) { | ||
if (parentColor == null) { | ||
// We need something colorful to derive other colors based on the color | ||
return Color.hsb(Math.random() * 360.0, .50, .75); | ||
} | ||
return generateSubGroupColor(parentColor); | ||
} | ||
|
||
double sumSin = 0; | ||
double sumCos = 0; | ||
|
||
// Calculate the mean angle | ||
for (Color color : siblingColors) { | ||
double hue = color.getHue(); | ||
sumSin += Math.sin(Math.toRadians(hue)); | ||
sumCos += Math.cos(Math.toRadians(hue)); | ||
} | ||
|
||
double meanAngle = Math.toDegrees(Math.atan2(sumSin, sumCos)); | ||
meanAngle = (meanAngle + 360) % 360; | ||
|
||
// The opposite angle is potentially the point of maximum average distance | ||
double newHue = (meanAngle + 180) % 360; | ||
|
||
double sumSaturation = 0; | ||
double sumBrightness = 0; | ||
for (Color color : siblingColors) { | ||
sumSaturation += color.getSaturation(); | ||
sumBrightness += color.getBrightness(); | ||
} | ||
|
||
double averageSaturation = sumSaturation / siblingColors.size(); | ||
double averageBrightness = sumBrightness / siblingColors.size(); | ||
|
||
return Color.hsb(newHue, averageSaturation, averageBrightness); | ||
} | ||
|
||
private static Color generateSubGroupColor(Color baseColor) { | ||
return baseColor.deriveColor(0.0, 1.0, .9, 1.0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.