/
evernotenkai
/
DataBaseXJavaProject
Обзор
Документация
Войти
/
evernotenkai
/
DataBaseXJavaProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/app/ui/components/UiKit.java
191 строка
6 KB
Makson4ik
Весь проект с src db и прочим делом
12 май 2026, 22:43
12 май 2026, 22:43
431f4aa
Код
Авторство
О чём код?
package app.ui.components; import java.util.List; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TableView; import javafx.scene.control.Tooltip; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; public final class UiKit { private UiKit() {} public static Label title(String text) { return labeled(text, "page-title"); } public static Label subtitle(String text) { return labeled(text, "page-subtitle"); } public static Label section(String text) { return labeled(text, "section-title"); } public static Label muted(String text) { return labeled(text, "muted-text"); } public static Label labeled(String text, String styleClass) { String value = text == null ? "" : text; Label label = new Label(value); label.getStyleClass().add(styleClass); if (!value.isEmpty()) { label.setTooltip(new Tooltip(value)); } return label; } public static Button navButton(String text) { Button b = new Button(text); b.getStyleClass().add("nav-button"); b.setMaxWidth(Double.MAX_VALUE); b.setMinHeight(40); if (text != null && !text.trim().isEmpty()) { b.setTooltip(new Tooltip(text)); } return b; } public static Button primaryButton(String text) { Button b = new Button(text); b.getStyleClass().add("primary-button"); return b; } public static Button secondaryButton(String text) { Button b = new Button(text); b.getStyleClass().add("secondary-button"); return b; } public static Button dangerButton(String text) { Button b = new Button(text); b.getStyleClass().add("danger-button"); return b; } public static Button ghostButton(String text) { Button b = new Button(text); b.getStyleClass().add("ghost-button"); return b; } public static VBox card(Node... nodes) { VBox box = new VBox(12); box.getStyleClass().addAll("card", "surface"); box.setPadding(new Insets(18)); box.setFillWidth(true); box.setMinWidth(0); box.setMaxWidth(Double.MAX_VALUE); box.getChildren().addAll(nodes); return box; } public static VBox pageSection(String title, String subtitleText, Node body) { VBox box = new VBox(10); box.getStyleClass().add("card"); box.setPadding(new Insets(18)); box.setFillWidth(true); box.setMinWidth(0); box.setMaxWidth(Double.MAX_VALUE); box.getChildren().add(title(title)); if (subtitleText != null && !subtitleText.trim().isEmpty()) { box.getChildren().add(subtitle(subtitleText)); } if (body != null) { box.getChildren().add(body); } return box; } public static Region spacer() { Region r = new Region(); VBox.setVgrow(r, Priority.ALWAYS); return r; } public static HBox chip(String text, String styleClass) { Label label = new Label(text == null ? "" : text); label.getStyleClass().addAll("chip", styleClass == null ? "chip-gray" : styleClass); HBox box = new HBox(label); box.setAlignment(Pos.CENTER_LEFT); return box; } public static String statusClass(String status) { if (status == null) { return "chip-gray"; } String s = status.trim().toLowerCase(); if (s.contains("checked") || s.contains("провер")) return "chip-green"; if (s.contains("returned") || s.contains("дораб")) return "chip-orange"; if (s.contains("submitted") || s.contains("отправ")) return "chip-blue"; if (s.contains("admin")) return "chip-violet"; if (s.contains("reject")) return "chip-red"; return "chip-gray"; } public static <T> void configureTable(TableView<T> table) { table.getStyleClass().add("modern-table"); table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); table.setFixedCellSize(40); table.setMinWidth(0); table.setMaxWidth(Double.MAX_VALUE); table.setPlaceholder(new Label("Нет данных")); } public static Integer requireInt(String rawValue, int min, int max, String fieldName) { if (rawValue == null || rawValue.trim().isEmpty()) { throw new IllegalArgumentException(fieldName + " не заполнено."); } String trimmed = rawValue.trim(); if (!trimmed.matches("\\d+")) { throw new IllegalArgumentException(fieldName + " должно содержать только цифры."); } int value = Integer.parseInt(trimmed); if (value < min || value > max) { throw new IllegalArgumentException(fieldName + " должно быть в диапазоне от " + min + " до " + max + "."); } return Integer.valueOf(value); } public static VBox fieldBox(String title, Node field, String hint) { VBox box = new VBox(6); Label label = labeled(title, "field-title"); box.getChildren().add(label); if (field != null) { field.getStyleClass().add("search-field"); if (field instanceof javafx.scene.layout.Region) { ((javafx.scene.layout.Region) field).setMaxWidth(Double.MAX_VALUE); ((javafx.scene.layout.Region) field).setMinWidth(0); } } box.getChildren().add(field); if (hint != null && !hint.trim().isEmpty()) { Label h = labeled(hint, "field-hint"); box.getChildren().add(h); } return box; } public static HBox row(Node left, Node right) { HBox row = new HBox(12, left, right); row.setFillHeight(true); HBox.setHgrow(left, Priority.ALWAYS); HBox.setHgrow(right, Priority.ALWAYS); return row; } public static void fillHBox(HBox box, List<? extends Node> nodes) { box.getChildren().addAll(nodes); } }