Skip to content

Commit 2a496db

Browse files
committed
#178: use random color when importing projects
1 parent 5e2e79a commit 2a496db

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/de/doubleslash/keeptime/common/ColorHelper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@
1818

1919
import javafx.scene.paint.Color;
2020

21+
import java.util.Random;
22+
2123
public class ColorHelper {
2224

25+
private static final Random random = new Random();
26+
2327
private ColorHelper() {
2428
throw new IllegalStateException("Utility class: ColorHelper");
2529
}
2630

2731
public static Color randomColor() {
28-
return Color.BLACK;
32+
double hue = random.nextDouble() * 360;
33+
double saturation = 0.7 + random.nextDouble() * 0.3; // High saturation
34+
double brightness = 0.8 + random.nextDouble() * 0.2; // High brightness
35+
return Color.hsb(hue, saturation, brightness);
2936
}
3037

3138
public static String colorToCssRgba(final Color color) {

src/main/java/de/doubleslash/keeptime/view/MapExternalProjectsController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package de.doubleslash.keeptime.view;
1818

19+
import de.doubleslash.keeptime.common.ColorHelper;
1920
import de.doubleslash.keeptime.controller.Controller;
2021
import de.doubleslash.keeptime.controller.HeimatController;
2122
import de.doubleslash.keeptime.model.Model;
@@ -194,7 +195,7 @@ protected void updateItem(HeimatTask item, boolean empty) {
194195
final HeimatTask task = addNewProjectComboBox.getValue();
195196
final int sortIndex = model.getAvailableProjects().size();
196197
final Project project = controller.addNewProject(
197-
new Project(task.taskHolderName() + " - " + task.name(), task.bookingHint(), Color.BLACK, true,
198+
new Project(task.taskHolderName() + " - " + task.name(), task.bookingHint(), ColorHelper.randomColor(), true,
198199
sortIndex));
199200
newProjectMappings.add(new HeimatController.ProjectMapping(project, task));
200201
addNewProjectComboBox.getSelectionModel().clearSelection();

0 commit comments

Comments
 (0)