-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColorPickButton.java
34 lines (30 loc) · 1.05 KB
/
ColorPickButton.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
public class ColorPickButton{
public Button displayButton;
private Color colorValue;
public ColorPickButton(int xPos, int yPos, Color color, RoundColorPicker pickerParent, int colorIndex) {
this.displayButton = new Button();
this.displayButton.setLayoutX(xPos);
this.displayButton.setLayoutY(yPos);
displayButton.getStyleClass().add("color-picker");
colorValue = color;
displayButton.setStyle("-fx-background-color: " + toRGBCode(colorValue));
displayButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
pickerParent.pickColor(colorIndex);
}
});
Effects.addDefaultHoverEffect(this.displayButton);
}
private static String toRGBCode( Color color )
{
return String.format( "#%02X%02X%02X",
(int)( color.getRed() * 255 ),
(int)( color.getGreen() * 255 ),
(int)( color.getBlue() * 255 ) );
}
}