/** * Create a new control * * @param s * the styled string */ public StyledLabel(@NonNull StyledString s) { this.styledString.set(s); getStyleClass().add("styled-label"); //$NON-NLS-1$ setMouseTransparent(true); }
@Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (!empty) { CharSequence t = this.labelExtractor.apply(item); if (t == null) { setGraphic(null); } else if (t instanceof StyledString) { StyledLabel l = new StyledLabel((StyledString) t); l.getStyleClass().addAll(this.cssClassProvider.apply(item)); Node g = this.graphicExtractor.apply(item); if( g != null ) { l.setGraphic(g); } setGraphic(l); } else { Label l = new Label(t.toString()); l.getStyleClass().addAll(this.cssClassProvider.apply(item)); Node g = this.graphicExtractor.apply(item); if( g != null ) { l.setGraphic(g); } setGraphic(l); } } else { setGraphic(null); } } }
/** * Create a new skin * * @param control * the control */ public StyledLabelSkin(StyledLabel control) { super(control); this.b = new HBox(); this.l = new Label(); this.l.getStyleClass().clear(); Bindings.bindContent(this.l.getStyleClass(), control.getStyleClass()); this.b.getChildren().add(this.l); control.styledStringProperty().addListener(this::styleStringChanged); control.graphicProperty().addListener(this::graphicChanged); if( control.getGraphic() != null ) { this.l.setGraphic(control.getGraphic()); } getChildren().add(this.b); rebuildControl(); }
@Override public void dispose() { getSkinnable().getStyleString().getSegmentList() .removeListener(this::segmentsChanged); getSkinnable().styledStringProperty().removeListener( this::styleStringChanged); Bindings.unbindContent(this.l.getStyleClass(), getSkinnable().getStyleClass()); super.dispose(); }
private void rebuildControl() { if( this.b.getChildren().size() > 1 ) { this.b.getChildren().set(1, Util.toNode(getSkinnable().getStyleString())); } else { this.b.getChildren().add( Util.toNode(getSkinnable().getStyleString())); } }
@Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (!empty && item != null) { CharSequence t = this.labelExtractor.apply(item); if (t == null) { setGraphic(null); } else if (t instanceof StyledString) { StyledLabel l = new StyledLabel((StyledString) t); l.getStyleClass().addAll(this.cssClassProvider.apply(item)); Node g = this.graphicExtractor.apply(item); if( g != null ) { l.setGraphic(g); } setGraphic(l); } else { Label l = new Label(t.toString()); l.getStyleClass().addAll(this.cssClassProvider.apply(item)); Node g = this.graphicExtractor.apply(item); if( g != null ) { l.setGraphic(g); } setGraphic(l); } } else { setGraphic(null); } } }
/** * Create a new skin * * @param control * the control */ public StyledLabelSkin(StyledLabel control) { super(control); this.b = new HBox(10); this.l = new Label(); this.l.getStyleClass().clear(); Bindings.bindContent(this.l.getStyleClass(), control.getStyleClass()); this.b.getChildren().add(this.l); control.styledStringProperty().addListener(this::styleStringChanged); control.graphicProperty().addListener(this::graphicChanged); if( control.getGraphic() != null ) { this.l.setGraphic(control.getGraphic()); } getChildren().add(this.b); rebuildControl(); }
@Override public void dispose() { getSkinnable().getStyleString().getSegmentList() .removeListener(this::segmentsChanged); getSkinnable().styledStringProperty().removeListener( this::styleStringChanged); Bindings.unbindContent(this.l.getStyleClass(), getSkinnable().getStyleClass()); super.dispose(); }
private void rebuildControl() { if( this.b.getChildren().size() > 1 ) { this.b.getChildren().set(1, Util.toNode(getSkinnable().getStyleString())); } else { this.b.getChildren().add( Util.toNode(getSkinnable().getStyleString())); } }
@Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); if (!empty) { CharSequence t = this.labelExtractor.apply(item); if (t == null) { setGraphic(null); } else if (t instanceof StyledString) { StyledLabel l = new StyledLabel((StyledString) t); l.getStyleClass().addAll(this.cssClassProvider.apply(item)); Node g = this.graphicExtractor.apply(item); if( g != null ) { l.setGraphic(g); } setGraphic(l); } else { Label l = new Label(t.toString()); l.getStyleClass().addAll(this.cssClassProvider.apply(item)); Node g = this.graphicExtractor.apply(item); if( g != null ) { l.setGraphic(g); } setGraphic(l); } } else { setGraphic(null); } } }
/** * Create a new control * * @param s * the styled string */ public StyledLabel(@NonNull StyledString s) { this.styledString.set(s); getStyleClass().add("styled-label"); //$NON-NLS-1$ setMouseTransparent(true); }
if (t instanceof StyledString) { setText(""); //$NON-NLS-1$ StyledLabel l = new StyledLabel((StyledString) t); l.getStyleClass().addAll(this.cssClassProvider.apply(item)); Node g = this.graphicExtractor.apply(item); if (g != null) { l.setGraphic(g);