mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 21:48:22 +02:00
added a status color block and changed the error color
This commit is contained in:
@@ -36,6 +36,7 @@ import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||
import ninja.javafx.smartcsv.fx.util.ColorConstants;
|
||||
import ninja.javafx.smartcsv.validation.ValidationError;
|
||||
import org.controlsfx.control.PopOver;
|
||||
|
||||
@@ -44,6 +45,8 @@ import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static javafx.geometry.Pos.CENTER;
|
||||
import static ninja.javafx.smartcsv.fx.util.ColorConstants.ERROR_COLOR;
|
||||
import static ninja.javafx.smartcsv.fx.util.ColorConstants.OK_COLOR;
|
||||
import static ninja.javafx.smartcsv.fx.util.I18nValidationUtil.getI18nValidatioMessage;
|
||||
|
||||
/**
|
||||
@@ -52,6 +55,10 @@ import static ninja.javafx.smartcsv.fx.util.I18nValidationUtil.getI18nValidatioM
|
||||
public class ErrorSideBar extends Region {
|
||||
|
||||
private static final double WIDTH = 20.0;
|
||||
private static final int BORDER = 8;
|
||||
private static final double STATUS_BLOCK_HEIGHT = WIDTH - BORDER;
|
||||
private static final double STATUS_BLOCK_WIDTH = WIDTH - BORDER;
|
||||
private static final double STATUS_BLOCK_OFFSET = WIDTH + BORDER / 2;
|
||||
|
||||
private ListChangeListener<ValidationError> errorListListener = c -> setErrorMarker();
|
||||
private WeakListChangeListener<ValidationError> weakErrorListListener = new WeakListChangeListener<>(errorListListener);
|
||||
@@ -59,12 +66,18 @@ public class ErrorSideBar extends Region {
|
||||
private ObjectProperty<ValidationError> selectedValidationError = new SimpleObjectProperty<>();
|
||||
private PopOver popOver = new PopOver();
|
||||
private ResourceBundle resourceBundle;
|
||||
private Region statusBlock;
|
||||
|
||||
public ErrorSideBar(ResourceBundle resourceBundle) {
|
||||
this.resourceBundle = resourceBundle;
|
||||
initPopOver();
|
||||
setFixWidth();
|
||||
addModelListener();
|
||||
|
||||
statusBlock = new Region();
|
||||
statusBlock.setPrefSize(STATUS_BLOCK_WIDTH, STATUS_BLOCK_HEIGHT);
|
||||
statusBlock.setLayoutY(BORDER / 2);
|
||||
statusBlock.setLayoutX(BORDER / 2);
|
||||
}
|
||||
|
||||
private void initPopOver() {
|
||||
@@ -111,11 +124,16 @@ public class ErrorSideBar extends Region {
|
||||
|
||||
private void setErrorMarker() {
|
||||
List<Region> errorMarkerList = new ArrayList<>();
|
||||
errorMarkerList.add(statusBlock);
|
||||
statusBlock.setStyle("-fx-background-color: " + OK_COLOR);
|
||||
if (model.get() != null) {
|
||||
List<ValidationError> errorList = model.get().getValidationError();
|
||||
if (errorList != null && !errorList.isEmpty()) {
|
||||
|
||||
statusBlock.setStyle("-fx-background-color: " + ERROR_COLOR);
|
||||
|
||||
int rows = model.get().getRows().size();
|
||||
double space = ((int)getHeight()) / rows;
|
||||
double space = heightWithoutStatusBlock() / rows;
|
||||
for (ValidationError error : errorList) {
|
||||
errorMarkerList.add(generateErrorMarker(space, error));
|
||||
}
|
||||
@@ -124,11 +142,15 @@ public class ErrorSideBar extends Region {
|
||||
getChildren().setAll(errorMarkerList);
|
||||
}
|
||||
|
||||
private int heightWithoutStatusBlock() {
|
||||
return (int)(getHeight() - STATUS_BLOCK_OFFSET);
|
||||
}
|
||||
|
||||
private Region generateErrorMarker(double space, ValidationError error) {
|
||||
Region errorMarker = new Region();
|
||||
errorMarker.setLayoutY(space * error.getLineNumber());
|
||||
errorMarker.setLayoutY(space * error.getLineNumber() + STATUS_BLOCK_OFFSET);
|
||||
errorMarker.setPrefSize(WIDTH, 2);
|
||||
errorMarker.setStyle("-fx-background-color: #ff8888");
|
||||
errorMarker.setStyle("-fx-background-color: " + ERROR_COLOR);
|
||||
errorMarker.setOnMouseClicked(event -> selectedValidationError.setValue(error));
|
||||
errorMarker.setOnMouseEntered(event -> {
|
||||
popOver.setContentNode(popupContent(getI18nValidatioMessage(resourceBundle, error)));
|
||||
|
||||
@@ -33,10 +33,12 @@ import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
||||
import ninja.javafx.smartcsv.fx.table.model.CSVValue;
|
||||
import ninja.javafx.smartcsv.fx.util.ColorConstants;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import static javafx.application.Platform.runLater;
|
||||
import static ninja.javafx.smartcsv.fx.util.ColorConstants.ERROR_COLOR;
|
||||
import static ninja.javafx.smartcsv.fx.util.I18nValidationUtil.getI18nValidatioMessage;
|
||||
|
||||
/**
|
||||
@@ -77,7 +79,7 @@ public class EditableValidationCell extends TableCell<CSVRow, CSVValue> {
|
||||
setStyle("");
|
||||
setTooltip(null);
|
||||
} else if (item.getValidationError() != null) {
|
||||
setStyle("-fx-background-color: #ff8888");
|
||||
setStyle("-fx-background-color: derive("+ ERROR_COLOR +", 30%)");
|
||||
setTooltip(new Tooltip(getI18nValidatioMessage(resourceBundle, item.getValidationError())));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
package ninja.javafx.smartcsv.fx.util;
|
||||
|
||||
/**
|
||||
* Collection of all the important colors
|
||||
*/
|
||||
public class ColorConstants {
|
||||
public static final String OK_COLOR = "#22aa22";
|
||||
public static final String ERROR_COLOR = "#ff6622";
|
||||
}
|
||||
Reference in New Issue
Block a user