@Override public StyleableProperty<Number> getStyleableProperty(JFXAutoCompletePopup.CSSBridge bridge) { return (StyleableProperty<Number>) bridge.popup.cellLimitProperty(); } };
@Override public StyleableProperty<Number> getStyleableProperty(JFXAutoCompletePopup.CSSBridge bridge) { return (StyleableProperty<Number>) bridge.popup.fixedCellSizeProperty(); } };
@Override public Number getInitialValue(JFXAutoCompletePopup.CSSBridge bridge) { return bridge.popup.getCellLimit(); } @Override public boolean isSettable(JFXAutoCompletePopup.CSSBridge bridge) {
public JFXAutoCompletePopup() { super(); bridge = new CSSBridge(); getContent().setAll(bridge); setAutoFix(true); setAutoHide(true); setHideOnEscape(true); getStyleClass().add(DEFAULT_STYLE_CLASS); }
public JFXAutoCompletePopupSkin(JFXAutoCompletePopup<T> control) { this.control = control; suggestionList = new ListView<T>(control.getFilteredSuggestions()){ @Override protected void layoutChildren() { suggestionList.setFixedCellSize(control.getFixedCellSize()); control.fixedCellSizeProperty().addListener(observable -> suggestionList.setFixedCellSize(control.getFixedCellSize())); suggestionList.getItems().addListener((InvalidationListener) observable -> { itemChanged = true; }); suggestionList.getStyleClass().add("autocomplete-list"); control.suggestionsCellFactoryProperty().addListener((o, oldVal, newVal) -> { if (newVal != null) { suggestionList.setCellFactory(newVal); if (control.getSuggestionsCellFactory() != null) { suggestionList.setCellFactory(control.getSuggestionsCellFactory()); suggestionList.prefWidthProperty().bind(control.prefWidthProperty()); suggestionList.maxWidthProperty().bind(control.maxWidthProperty()); suggestionList.minWidthProperty().bind(control.minWidthProperty()); registerEventListener();
public void show(Node node){ if(!isShowing()){ if(node.getScene() == null || node.getScene().getWindow() == null) throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + ((Region)node).getHeight()); ((JFXAutoCompletePopupSkin<T>)getSkin()).animate(); } }
@Override public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() { return getClassCssMetaData(); } }
private void selectItem() { T item = suggestionList.getSelectionModel().getSelectedItem(); if (item == null) { try { suggestionList.getSelectionModel().select(0); item = suggestionList.getSelectionModel().getSelectedItem(); } catch (Exception e) { } } if (item != null) { control.getSelectionHandler().handle(new JFXAutoCompleteEvent<T>(JFXAutoCompleteEvent.SELECTION, item)); } }
public ObservableList<T> getSuggestions() { return autoCompletePopup.getSuggestions(); }
@Override public Double getInitialValue(JFXAutoCompletePopup.CSSBridge bridge) { return bridge.popup.getFixedCellSize(); } @Override public boolean isSettable(JFXAutoCompletePopup.CSSBridge bridge) {
public JFXAutoCompletePopupSkin(JFXAutoCompletePopup<T> control) { this.control = control; suggestionList = new ListView<T>(control.getFilteredSuggestions()){ @Override protected void layoutChildren() { suggestionList.setFixedCellSize(control.getFixedCellSize()); control.fixedCellSizeProperty().addListener(observable -> suggestionList.setFixedCellSize(control.getFixedCellSize())); suggestionList.getItems().addListener((InvalidationListener) observable -> { itemChanged = true; }); suggestionList.getStyleClass().add("autocomplete-list"); control.suggestionsCellFactoryProperty().addListener((o, oldVal, newVal) -> { if (newVal != null) { suggestionList.setCellFactory(newVal); if (control.getSuggestionsCellFactory() != null) { suggestionList.setCellFactory(control.getSuggestionsCellFactory()); suggestionList.prefWidthProperty().bind(control.prefWidthProperty()); suggestionList.maxWidthProperty().bind(control.maxWidthProperty()); suggestionList.minWidthProperty().bind(control.minWidthProperty()); registerEventListener();
public JFXAutoCompletePopup() { super(); bridge = new CSSBridge(); PopupWindowHelper.getContent(this).setAll(new Node[]{this.bridge}); setAutoFix(true); setAutoHide(true); setHideOnEscape(true); getStyleClass().add(DEFAULT_STYLE_CLASS); }
public void show(Node node){ if(!isShowing()){ if(node.getScene() == null || node.getScene().getWindow() == null) throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + ((Region)node).getHeight()); ((JFXAutoCompletePopupSkin<T>)getSkin()).animate(); } }
@Override public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() { return getClassCssMetaData(); } }
private void selectItem() { T item = suggestionList.getSelectionModel().getSelectedItem(); if (item == null) { try { suggestionList.getSelectionModel().select(0); item = suggestionList.getSelectionModel().getSelectedItem(); } catch (Exception e) { } } if (item != null) { control.getSelectionHandler().handle(new JFXAutoCompleteEvent<T>(JFXAutoCompleteEvent.SELECTION, item)); } }
public ObservableList<T> getSuggestions() { return autoCompletePopup.getSuggestions(); }
@Override public Double getInitialValue(JFXAutoCompletePopup.CSSBridge bridge) { return bridge.popup.getFixedCellSize(); } @Override public boolean isSettable(JFXAutoCompletePopup.CSSBridge bridge) {
public final void setFixedCellSize(double value) { fixedCellSizeProperty().set(value); } public final double getFixedCellSize() { return fixedCellSizeProperty().get(); }
public final void setCellLimit(int value) { cellLimitProperty().set(value); } public final int getCellLimit() { return cellLimitProperty().get(); }
private void updateListHeight() { final double height = Math.min(suggestionList.getItems().size(), getSkinnable().getCellLimit()) * suggestionList.getFixedCellSize(); suggestionList.setPrefHeight(height + suggestionList.getFixedCellSize() / 2); }