private void setSelectedStyle(DecoratedText label, Boolean newValue) { if (newValue) { applyStyle(label, ACTIVE_LABEL_STYLE); removeStyle(label, DEFAULT_LABEL_STYLE); removeStyle(label, DISABLED_LABEL_STYLE); } else { applyStyle(label, DEFAULT_LABEL_STYLE); removeStyle(label, ACTIVE_LABEL_STYLE); removeStyle(label, DISABLED_LABEL_STYLE); } }
public NoticeBoardScrollPaneContent() { getStylesheets().add(getClass().getResource(getClass().getSimpleName()+".css").toExternalForm()); }
public void addMenu(NoticeBoardMenu menu) { if (noticeBoardMenu.contains(menu)) { throw new IllegalArgumentException("The menu may not be added twice."); } noticeBoardMenu.add(menu); if (Platform.isFxApplicationThread()) { nbScrollPane.setContent(Optional.of(menu)); } else { Platform.runLater(() -> nbScrollPane.setContent(Optional.of(menu))); } }
public void setContent(Optional<NoticeBoardMenu> optMenu) { getChildren().clear(); //noinspection OptionalIsPresent if (optMenu.isPresent()) { NoticeBoardMenu menu = optMenu.get(); final Label title = menu.getTitle(); title.getStyleClass().add("scrollPaneContent-title"); getChildren().add(title); for (NoticeBoardMenuEntry menuItem : menu.getMenuEntries()) { final DecoratedText label = menuItem.getLabel(); getChildren().add(label); if (menuItem.getDisabled()) { applyStyle(label, DISABLED_LABEL_STYLE); } else if (menuItem.getSelected()) { applyStyle(label, ACTIVE_LABEL_STYLE); } else { applyStyle(label, DEFAULT_LABEL_STYLE); } menuItem.selectedProperty().addListener((observable, oldValue, newValue) -> setSelectedStyle(label, newValue)); menuItem.disabledProperty().addListener((observable, oldValue, newValue) -> setDisabledStyle(label, newValue)); } } } private void applyStyle(DecoratedText text, String styleClass) {
public NoticeBoard() { setManaged(false); String cssFileName = NoticeBoard.class.getSimpleName()+".css"; URL resource = NoticeBoard.class.getResource(cssFileName); getStylesheets().add(resource.toExternalForm()); getStyleClass().add("noticeBoardText"); ScrollPane scrollPane = new ScrollPane(); scrollPane.setLayoutX(20); scrollPane.setLayoutY(11); scrollPane.setMaxWidth(DEFAULT_WIDTH); scrollPane.setMinWidth(216); scrollPane.setMaxHeight(216); scrollPane.setMinHeight(216); scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER); scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED); nbScrollPane = new NoticeBoardScrollPaneContent(); scrollPane.setContent(nbScrollPane); getChildren().addAll(scrollPane); }
public void closeNoticeBoard() { if (!noticeBoardMenu.isEmpty()) { noticeBoardMenu.removeLast(); } final Optional<NoticeBoardMenu> optMenu; if (noticeBoardMenu.isEmpty()) { optMenu = Optional.empty(); } else { optMenu = Optional.of(noticeBoardMenu.getLast()); } if (Platform.isFxApplicationThread()) { nbScrollPane.setContent(optMenu); } else { Platform.runLater(() -> nbScrollPane.setContent(optMenu)); } }