Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
// Not public API - this is (presently) an implementation detail only
class ColorPalette extends Region {

private static final int SQUARE_SIZE = 15;
private double squareSize = 15.0;

// package protected for testing purposes
ColorPickerGrid colorPickerGrid;
Expand All @@ -98,6 +98,51 @@ class ColorPalette extends Region {

private final ColorSquare hoverSquare = new ColorSquare();

private VBox paletteBox;

public double getSquareSize(){
return squareSize;
}

public void setSquareSize(double size){
if(size <= 0 ){
throw new IllegalArgumentException("Square size must be positive");
}

if (getSquareSize() != size) {
this.squareSize = size;
rebuildSquares();
}
}

private void rebuildSquares() {
buildStandardColors();
buildCustomColors();
colorPickerGrid = new ColorPickerGrid();

paletteBox.getChildren().setAll(
standardColorGrid, colorPickerGrid,
customColorLabel, customColorGrid,
separator, customColorLink
);

customColorLabel.prefWidthProperty().unbind();
customColorLink.prefWidthProperty().unbind();
standardColorGrid.prefWidthProperty().unbind();
customColorGrid.prefWidthProperty().unbind();

customColorLabel.prefWidthProperty().bind(colorPickerGrid.widthProperty());
customColorLink.prefWidthProperty().bind(colorPickerGrid.widthProperty());
standardColorGrid.prefWidthProperty().bind(colorPickerGrid.widthProperty());
customColorGrid.prefWidthProperty().bind(colorPickerGrid.widthProperty());

hoverSquare.setMouseTransparent(true);
hoverSquare.getStyleClass().addAll("hover-square");
setFocusedSquare(null);

requestLayout();
}

public ColorPalette(final ColorPicker colorPicker) {
getStyleClass().add("color-palette-region");
this.colorPicker = colorPicker;
Expand Down Expand Up @@ -151,9 +196,14 @@ public ColorPalette(final ColorPicker colorPicker) {
}
});

VBox paletteBox = new VBox();
paletteBox = new VBox();
paletteBox.getStyleClass().add("color-palette");
paletteBox.getChildren().addAll(standardColorGrid, colorPickerGrid, customColorLabel, customColorGrid, separator, customColorLink);
paletteBox.setFillWidth(true);
paletteBox.getChildren().addAll(
standardColorGrid, colorPickerGrid,
customColorLabel, customColorGrid,
separator, customColorLink
);

hoverSquare.setMouseTransparent(true);
hoverSquare.getStyleClass().addAll("hover-square");
Expand Down Expand Up @@ -501,7 +551,7 @@ public ColorSquare(Color color, int index, ColorType type) {
}
this.index = index;
this.colorType = type;
rectangle = new Rectangle(SQUARE_SIZE, SQUARE_SIZE);
rectangle = new Rectangle(squareSize, squareSize);
if (color == null) {
rectangle.setFill(Color.WHITE);
isEmpty = true;
Expand Down Expand Up @@ -593,9 +643,9 @@ public ColorPickerGrid() {
mouseDragColor = colorPicker.getValue();
}
int xIndex = com.sun.javafx.util.Utils.clamp(0,
(int)t.getX()/(SQUARE_SIZE + 1), NUM_OF_COLUMNS - 1);
(int)Math.floor(t.getX()/(squareSize + 1)), NUM_OF_COLUMNS - 1);
int yIndex = com.sun.javafx.util.Utils.clamp(0,
(int)t.getY()/(SQUARE_SIZE + 1), NUM_OF_ROWS - 1);
(int)Math.floor(t.getY()/(squareSize + 1)), NUM_OF_ROWS - 1);
int index = xIndex + yIndex*NUM_OF_COLUMNS;
colorPicker.setValue((Color) squares.get(index).rectangle.getFill());
updateSelection(colorPicker.getValue());
Expand All @@ -621,11 +671,11 @@ public List<ColorSquare> getSquares() {
}

@Override protected double computePrefWidth(double height) {
return (SQUARE_SIZE + 1)*NUM_OF_COLUMNS;
return (squareSize + 1)*NUM_OF_COLUMNS;
}

@Override protected double computePrefHeight(double width) {
return (SQUARE_SIZE + 1)*NUM_OF_ROWS;
return (squareSize + 1)*NUM_OF_ROWS;
}
}

Expand Down