Skip to content

Commit

Permalink
fixes #7 add color coding to user id column with tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Nov 16, 2017
1 parent dc24d47 commit ec3ac2e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
52 changes: 48 additions & 4 deletions src/main/java/com/faforever/moderatorclient/ui/ViewHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import javafx.scene.control.cell.TreeItemPropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.text.TextAlignment;
import org.apache.maven.artifact.versioning.ComparableVersion;

import java.net.URL;
Expand Down Expand Up @@ -236,10 +238,52 @@ static void buildTeamkillTableView(javafx.scene.control.TableView<Teamkill> tabl
}

static void buildUserTableView(TableView<Player> tableView) {
TableColumn<Player, String> idColumn = new TableColumn<>("ID");
idColumn.setCellValueFactory(new PropertyValueFactory<>("id"));
idColumn.setComparator(Comparator.comparingInt(Integer::parseInt));
idColumn.setMinWidth(50);
TableColumn<Player, Player> idColumn = new TableColumn<>("ID");
idColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue()));
idColumn.setCellFactory(param -> new TableCell<Player, Player>() {
Tooltip tooltip = new Tooltip();

{
setTooltip(tooltip);
setTextAlignment(TextAlignment.RIGHT);
}

@Override
protected void updateItem(Player item, boolean empty) {
super.updateItem(item, empty);
setTextFill(Color.BLACK);

if (item == null) {
setText("");
setStyle("");
tooltip.setText("");
} else {
setText(item.getId());

if (item.getBans().isEmpty()) {
setStyle("");
tooltip.setText("No bans");
} else {
setStyle("-fx-font-weight: bold");

if (item.getBans().stream()
.anyMatch(banInfo -> banInfo.getBanStatus() == BanStatus.BANNED && banInfo.getDuration() == BanDurationType.PERMANENT)) {
tooltip.setText("Permanent ban");
setTextFill(Color.valueOf("#ca0000"));
} else if (item.getBans().stream()
.allMatch(banInfo -> banInfo.getBanStatus() == BanStatus.EXPIRED)) {
tooltip.setText("Expired ban");
setTextFill(Color.valueOf("#098700"));
} else {
tooltip.setText("Temporary ban");
setTextFill(Color.valueOf("#ff8800"));
}
}
}
}
});
idColumn.setComparator(Comparator.comparingInt(o -> Integer.parseInt(o.getId())));
idColumn.setMinWidth(70);
tableView.getColumns().add(idColumn);

TableColumn<Player, String> nameColumn = new TableColumn<>("Name");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<content>
<VBox>
<children>
<HBox>
<HBox VBox.vgrow="ALWAYS">
<children>
<VBox minWidth="220.0">
<children>
Expand Down

0 comments on commit ec3ac2e

Please sign in to comment.