Module Client : utilisation des pseudo classes pour les variations de style css des cellules de tableview et de listview

This commit is contained in:
Notmoo 2017-08-19 19:18:10 +02:00
parent 312a5ce293
commit 41c59d31fe
3 changed files with 55 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.css.PseudoClass;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
@ -68,10 +69,24 @@ class StockScreenView implements IFXComponent {
HBox.setHgrow(separator, Priority.ALWAYS); HBox.setHgrow(separator, Priority.ALWAYS);
mainPaneContent.setTop(mainPaneTopContent); mainPaneContent.setTop(mainPaneTopContent);
PseudoClass outOfStockPseudoClass = PseudoClass.getPseudoClass("stock-out");
PseudoClass lowStockPseudoClass = PseudoClass.getPseudoClass("stock-low");
PseudoClass highStockPseudoClass = PseudoClass.getPseudoClass("stock-high");
stockTableView = new TableView<>(); stockTableView = new TableView<>();
stockTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); stockTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
stockTableView.setRowFactory(tableView->{ stockTableView.setRowFactory(tableView->{
TableRow<Product> row = new TableRow<>(); TableRow<Product> row = new TableRow<>();
row.itemProperty().addListener((obs, oldVal, newVal)->{
if(newVal!=null){
row.pseudoClassStateChanged(outOfStockPseudoClass, newVal.getAmountRemaining()<=0);
row.pseudoClassStateChanged(lowStockPseudoClass, newVal.getAmountRemaining()>0 && newVal.getAmountRemaining()<30);
row.pseudoClassStateChanged(highStockPseudoClass, newVal.getAmountRemaining()>=30);
}else{
row.pseudoClassStateChanged(outOfStockPseudoClass, false);
row.pseudoClassStateChanged(lowStockPseudoClass, false);
row.pseudoClassStateChanged(highStockPseudoClass, false);
}
});
row.setOnMouseClicked(event -> { row.setOnMouseClicked(event -> {
if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2) if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2)
ctrl.getProductActivationListener().onProductActivated(row.getItem()); ctrl.getProductActivationListener().onProductActivated(row.getItem());

View File

@ -1,18 +1,25 @@
package com.pqt.client.gui.ressources.components.generics.javafx_override; package com.pqt.client.gui.ressources.components.generics.javafx_override;
import javafx.css.PseudoClass;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
public class HighlightListCell<T> extends ListCell<T> { public class HighlightListCell<T> extends ListCell<T> {
private PseudoClass highlightPC;
private boolean highlighted;
public HighlightListCell() {
super();
highlighted = false;
highlightPC = PseudoClass.getPseudoClass("highlighted");
}
public void setHighLight(boolean highLight){ public void setHighLight(boolean highLight){
if(highLight){ highlighted = highLight;
if(!getStyleClass().contains("list-cell-highlighted")) this.pseudoClassStateChanged(highlightPC, highLight);
getStyleClass().add("list-cell-highlighted");
}
else
getStyleClass().remove("list-cell-highlighted");
} }
public boolean isHightlighted(){ public boolean isHightlighted(){
return getStyleClass().contains("list-cell-highlighted"); return highlighted;
} }
} }

View File

@ -51,6 +51,7 @@
.list-view { .list-view {
-fx-base: #1d1d1d; -fx-base: #1d1d1d;
-fx-control-inner-background: #1d1d1d; -fx-control-inner-background: #1d1d1d;
-fx-control-inner-background-alt: #333333;
-fx-background-color: #1d1d1d; -fx-background-color: #1d1d1d;
-fx-table-cell-border-color: transparent; -fx-table-cell-border-color: transparent;
-fx-table-header-border-color: transparent; -fx-table-header-border-color: transparent;
@ -71,8 +72,10 @@
.list-view:focused .list-cell:filled:focused:selected { .list-view:focused .list-cell:filled:focused:selected {
-fx-background-color: -fx-focus-color; -fx-background-color: -fx-focus-color;
} }
.list-cell-highlighted{ .list-cell:highlighted{
-fx-background-color: #4d4d4d; -fx-text-fill: #cc7a00;
-fx-border-width: 1px;
-fx-border-color: white;
} }
.table-view { .table-view {
@ -108,6 +111,26 @@
-fx-opacity: 1; -fx-opacity: 1;
} }
.table-view .table-row-cell {
-fx-control-inner-background: #1d1d1d;
-fx-control-inner-background-alt: #333333;
}
.table-view .table-row-cell:stock-out {
-fx-control-inner-background: #4d0000;
-fx-control-inner-background-alt: #4d0000;
}
.table-view .table-row-cell:stock-low {
-fx-control-inner-background: #4d2e00;
-fx-control-inner-background-alt: #4d2e00;
}
.table-view .table-row-cell:stock-high {
-fx-control-inner-background: #1a3300;
-fx-control-inner-background-alt: #1a3300;
}
.table-view:focused .table-row-cell:filled:focused:selected { .table-view:focused .table-row-cell:filled:focused:selected {
-fx-background-color: -fx-focus-color; -fx-background-color: -fx-focus-color;
} }
@ -247,7 +270,7 @@
.validator .button{ .validator .button{
-fx-pref-width: 150; -fx-pref-width: 150;
-fx-pref-height: 50; -fx-pref-height: 50;
} }
.sidebar { .sidebar {
-fx-background-color: #2e2e2e; -fx-background-color: #2e2e2e;