Java Code Examples for javafx.scene.control.ListView#setCellFactory()

The following examples show how to use javafx.scene.control.ListView#setCellFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryListDialog.java    From constellation with Apache License 2.0 7 votes vote down vote up
static String getQueryName(final Object owner, final String[] queryNames) {
    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);

    final ObservableList<String> q = FXCollections.observableArrayList(queryNames);
    final ListView<String> nameList = new ListView<>(q);
    nameList.setCellFactory(p -> new DraggableCell<>());
    nameList.setEditable(false);
    nameList.setOnMouseClicked(event -> {
        if (event.getClickCount() > 1) {
            dialog.setResult(ButtonType.OK);
        }
    });

    dialog.setResizable(false);
    dialog.setTitle("Query names");
    dialog.setHeaderText("Select a query to load.");
    dialog.getDialogPane().setContent(nameList);
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        return nameList.getSelectionModel().getSelectedItem();
    }

    return null;
}
 
Example 2
Source File: ListViewCellFactorySample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ListViewCellFactorySample() {
    final ListView<Number> listView = new ListView<Number>();
    listView.setItems(FXCollections.<Number>observableArrayList(
            100.00, -12.34, 33.01, 71.00, 23000.00, -6.00, 0, 42223.00, -12.05, 500.00,
            430000.00, 1.00, -4.00, 1922.01, -90.00, 11111.00, 3901349.00, 12.00, -1.00, -2.00,
            15.00, 47.50, 12.11

    ));
    
    listView.setCellFactory(new Callback<ListView<java.lang.Number>, ListCell<java.lang.Number>>() {
        @Override public ListCell<Number> call(ListView<java.lang.Number> list) {
            return new MoneyFormatCell();
        }
    });        
    
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    getChildren().add(listView);
}
 
Example 3
Source File: ListViewCellFactorySample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ListViewCellFactorySample() {
    final ListView<Number> listView = new ListView<Number>();
    listView.setItems(FXCollections.<Number>observableArrayList(
            100.00, -12.34, 33.01, 71.00, 23000.00, -6.00, 0, 42223.00, -12.05, 500.00,
            430000.00, 1.00, -4.00, 1922.01, -90.00, 11111.00, 3901349.00, 12.00, -1.00, -2.00,
            15.00, 47.50, 12.11

    ));
    
    listView.setCellFactory(new Callback<ListView<java.lang.Number>, ListCell<java.lang.Number>>() {
        @Override public ListCell<Number> call(ListView<java.lang.Number> list) {
            return new MoneyFormatCell();
        }
    });        
    
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    getChildren().add(listView);
}
 
Example 4
Source File: ListCellTextFieldTest.java    From oim-fx with MIT License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    StackPane pane = new StackPane();
    Scene scene = new Scene(pane, 300, 150);
    primaryStage.setScene(scene);
    ObservableList<String> list = FXCollections.observableArrayList(
            "Item 1", "Item 2", "Item 3", "Item 4");
    ListView<String> lv = new ListView<>(list);
    lv.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override
        public ListCell<String> call(ListView<String> param) {
            return new XCell();
        }
    });
    pane.getChildren().add(lv);
    primaryStage.show();
}
 
Example 5
Source File: ListCellLabelTest.java    From oim-fx with MIT License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    StackPane pane = new StackPane();
    Scene scene = new Scene(pane, 300, 150);
    primaryStage.setScene(scene);
    ObservableList<String> list = FXCollections.observableArrayList(
            "Item 1", "Item 2", "Item 3", "Item 4");
    ListView<String> lv = new ListView<>(list);
    lv.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override
        public ListCell<String> call(ListView<String> param) {
            return new XCell();
        }
    });
    pane.getChildren().add(lv);
    primaryStage.show();
}
 
Example 6
Source File: ListCellTextFieldTest2.java    From oim-fx with MIT License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    StackPane pane = new StackPane();
    Scene scene = new Scene(pane, 300, 150);
    primaryStage.setScene(scene);
    ObservableList<String> list = FXCollections.observableArrayList(
            "Item 1", "Item 2", "Item 3", "Item 4");
    ListView<String> lv = new ListView<>(list);
    lv.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override
        public ListCell<String> call(ListView<String> param) {
            return new XCell();
        }
    });
    pane.getChildren().add(lv);
    primaryStage.show();
}
 
Example 7
Source File: ViolationCollectionView.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initListView(ListView<LiveViolationRecord> view) {

        ControlUtil.makeListViewFitToChildren(view, LIST_CELL_HEIGHT);

        view.setEditable(true);

        DragAndDropUtil.registerAsNodeDragTarget(view, textRange -> {
            LiveViolationRecord record = new LiveViolationRecord();
            record.setRange(textRange);
            record.setExactRange(true);
            getItems().add(record);
        }, getDesignerRoot());

        ControlUtil.makeListViewNeverScrollHorizontal(view);

        // go into normal state on window hide
        ControlUtil.subscribeOnWindow(
            this,
            w -> ReactfxUtil.addEventHandler(w.onHiddenProperty(), evt -> view.edit(-1))
        );

        Label placeholder = new Label("No violations expected in this code");
        placeholder.getStyleClass().addAll("placeholder");
        view.setPlaceholder(placeholder);
        view.setCellFactory(lv -> new ViolationCell());
    }
 
Example 8
Source File: AttributeEditorPanel.java    From constellation with Apache License 2.0 6 votes vote down vote up
private ListView<Object> createListView(final AttributeData attribute, final ObservableList<Object> listData) {

        final ListView<Object> newList = new ListView<>(listData);
        newList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        newList.setCellFactory((ListView<Object> p) -> new AttributeValueCell(attribute.getDataType()));

        addCopyHandlersToListView(newList, attribute);
        newList.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
            if (event.isShortcutDown() && (event.getCode() == KeyCode.C)) {
                copySelectedItems(newList, attribute.getDataType());
                event.consume();
            } else if (event.isShortcutDown() && (event.getCode() == KeyCode.A)) {
                event.consume();
            }
        });
        return newList;
    }
 
Example 9
Source File: LazyListFactory.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Parent createProjection(Projector projector, ClientContext clientContext, ControllerProxy controllerProxy, MediaLazyListBean projectable) {
    ListView<LazyMediaBean> listView = new ListView<>();
    listView.setCellFactory(SimpleMediaListCell.createDefaultCallback());
    LazyLoadingBehavior<LazyMediaBean> lazyLoadingBehavior = new LazyLoadingBehavior<>(listView);
    lazyLoadingBehavior.setModel(projectable);
    return listView;
}
 
Example 10
Source File: ComboBoxListViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ComboBoxListViewSample() {
    ListView<Object> listView = new ListView<>();
    listView.getItems().addAll(items);
    listView.setEditable(true);
    listView.setCellFactory(ComboBoxListCell.forListView(items));
    getChildren().add(listView);
}
 
Example 11
Source File: TextFieldListViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TextFieldListViewSample() {
    final ListView<String> listView = new ListView<String>();
    listView.setItems(FXCollections.observableArrayList("Row 1", "Row 2", "Long Row 3", "Row 4", "Row 5", "Row 6", "Row 7",
            "Row 8", "Row 9", "Row 10", "Row 11", "Row 12", "Row 13", "Row 14", "Row 15", "Row 16", "Row 17", "Row 18",
            "Row 19", "Row 20"));
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    listView.setEditable(true);
    listView.setCellFactory(TextFieldListCell.forListView());
    getChildren().add(listView);
}
 
Example 12
Source File: ChoiceBoxListViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ChoiceBoxListViewSample() {
    ListView<Object> listView = new ListView<>();
    listView.getItems().addAll(items);
    listView.setEditable(true);
    listView.setCellFactory(ChoiceBoxListCell.forListView(items));
    getChildren().addAll(listView, new Button("Click me"));
}
 
Example 13
Source File: BasicListView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BasicListView() {

        // create a DataSource that loads data from a classpath resource
        InputDataSource dataSource = new BasicInputDataSource(Main.class.getResourceAsStream("/languages.json"));

        // create a Converter that converts a json array into a list
        InputStreamIterableInputConverter<Language> converter = new JsonIterableInputConverter<>(Language.class);

        // create a ListDataReader that will read the data from the DataSource and converts
        // it from json into a list of objects
        ListDataReader<Language> listDataReader = new InputStreamListDataReader<>(dataSource, converter);

        // retrieve a list from the DataProvider
        GluonObservableList<Language> programmingLanguages = DataProvider.retrieveList(listDataReader);

        // create a JavaFX ListView and populate it with the retrieved list
        ListView<Language> lvProgrammingLanguages = new ListView<>(programmingLanguages);
        lvProgrammingLanguages.setCellFactory(lv -> new ListCell<Language>() {
            @Override
            protected void updateItem(Language item, boolean empty) {
                super.updateItem(item, empty);

                if (!empty) {
                    setText(item.getName() + ": " + item.getRatings() + "%");
                } else {
                    setText(null);
                }
            }
        });

        setCenter(lvProgrammingLanguages);
    }
 
Example 14
Source File: FileListView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public FileListView() throws IOException {

        File languagesFile = new File(ROOT_DIR, "languages.json");

        // create a FileClient to the specified file
        FileClient fileClient = FileClient.create(languagesFile);

        // create a JSON converter that converts the nodes from a JSON array into language objects
        InputStreamIterableInputConverter<Language> converter = new JsonIterableInputConverter<>(Language.class);

        // retrieve a list from a ListDataReader created from the FileClient
        GluonObservableList<Language> languages = DataProvider.retrieveList(fileClient.createListDataReader(converter));

        // create a JavaFX ListView and populate it with the retrieved list
        ListView<Language> lvLanguages = new ListView<>(languages);
        lvLanguages.setCellFactory(lv -> new ListCell<Language>() {
            @Override
            protected void updateItem(Language item, boolean empty) {
                super.updateItem(item, empty);

                if (!empty) {
                    setText(item.getName() + " - " + item.getRatings());
                } else {
                    setText(null);
                }
            }
        });

        setCenter(lvLanguages);
    }
 
Example 15
Source File: RestListView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public RestListView() {

        // create a RestClient to the specific URL
        RestClient restClient = RestClient.create()
                .method("GET")
                .host("https://api.stackexchange.com")
                .path("/2.2/errors");

        // create a custom Converter that is able to parse the response into a list of objects
        InputStreamIterableInputConverter<Error> converter = new ItemsIterableInputConverter<>(Error.class);

        // retrieve a list from the DataProvider
        GluonObservableList<Error> errors = DataProvider.retrieveList(restClient.createListDataReader(converter));

        // create a JavaFX ListView and populate it with the retrieved list
        ListView<Error> lvErrors = new ListView<>(errors);
        lvErrors.setCellFactory(lv -> new ListCell<Error>() {
            @Override
            protected void updateItem(Error item, boolean empty) {
                super.updateItem(item, empty);

                if (!empty) {
                    setText(item.getErrorId() + " - " + item.getErrorName());
                } else {
                    setText(null);
                }
            }
        });

        setCenter(lvErrors);
    }
 
Example 16
Source File: ReadSymbolsFromMobileStyleFileController.java    From arcgis-runtime-samples-java with Apache License 2.0 5 votes vote down vote up
@FXML
public void initialize() {

  // create a map
  ArcGISMap map = new ArcGISMap(Basemap.createTopographic());
  // add the map to the map view
  mapView.setMap(map);

  // create a graphics overlay and add it to the map
  graphicsOverlay = new GraphicsOverlay();
  mapView.getGraphicsOverlays().add(graphicsOverlay);

  // load the available symbols from the style file
  loadSymbolsFromStyleFile();

  // create a listener that builds the composite symbol when an item from the list view is selected
  ChangeListener<Object> changeListener = (obs, oldValue, newValue) -> buildCompositeSymbol();

  // create a list of the ListView objects and iterate over it
  List<ListView<SymbolStyleSearchResult>> listViews = Arrays.asList(hatSelectionListView, eyesSelectionListView, mouthSelectionListView);
  for (ListView<SymbolStyleSearchResult> listView : listViews) {
    // add the cell factory to show the symbol within the list view
    listView.setCellFactory(c -> new SymbolLayerInfoListCell());
    // add the change listener to rebuild the preview when a selection is made
    listView.getSelectionModel().selectedItemProperty().addListener(changeListener);
    // add an empty entry to the list view to allow selecting 'nothing', and make it selected by default
    listView.getItems().add(null);
    listView.getSelectionModel().select(0);
  }
}
 
Example 17
Source File: DetailsListWidgetSkin.java    From phoenicis with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final ListView<DetailsListElement<E>> container = new ListView<>();
    container.getStyleClass().addAll("listWidget", "detailsListWidget");

    container.setPrefWidth(0);
    container.setPrefHeight(0);

    // ensure that empty rows have the same height as non-empty ones
    container.setCellFactory(param -> {
        final ListCell<DetailsListElement<E>> listCell = new ListCell<DetailsListElement<E>>() {
            @Override
            public void updateItem(DetailsListElement<E> item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty && item != null) {
                    setGraphic(item);
                } else {
                    setGraphic(null);
                }
            }
        };

        listCell.getStyleClass().addAll("detailsListElement");

        return listCell;
    });

    Bindings.bindContent(container.getItems(), mappedElements);

    // ensure that updates to the selected element property are automatically reflected in the view
    getControl().selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        // deselect the old element
        updateOldSelection(container, oldValue);

        // select the new element
        updateNewSelection(container, newValue);
    });

    // initialise selection at startup
    updateNewSelection(container, getControl().getSelectedElement());

    getChildren().addAll(container);
}
 
Example 18
Source File: BrowseWfsLayersSample.java    From arcgis-runtime-samples-java with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {

  // create stack pane and JavaFX app scene
  StackPane stackPane = new StackPane();
  Scene scene = new Scene(stackPane);
  scene.getStylesheets().add(getClass().getResource("/browse_wfs_layers/style.css").toExternalForm());

  // set title, size, and add JavaFX scene to stage
  stage.setTitle("Browse WFS Layers");
  stage.setWidth(800);
  stage.setHeight(700);
  stage.setScene(scene);
  stage.show();

  // create a list view to show all of the layers in a WFS service
  ListView<WfsLayerInfo> wfsLayerNamesListView = new ListView<>();
  wfsLayerNamesListView.setMaxSize(200, 160);

  // create a progress indicator
  progressIndicator = new ProgressIndicator();
  progressIndicator.setVisible(true);

  // create an ArcGISMap with topographic basemap and set it to the map view
  map = new ArcGISMap(Basemap.createImagery());
  mapView = new MapView();
  mapView.setMap(map);

  // create a WFS service with a URL and load it
  wfsService = new WfsService("https://dservices2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/services/Seattle_Downtown_Features/WFSServer?service=wfs&request=getcapabilities");
  wfsService.loadAsync();

  // when the WFS service has loaded, add its layer information to the list view for browsing
  wfsService.addDoneLoadingListener(() -> {
    progressIndicator.setVisible(false);
    if (wfsService.getLoadStatus() == LoadStatus.LOADED) {
      // add the list of WFS layers to the list view
      List<WfsLayerInfo> wfsLayerInfos = wfsService.getServiceInfo().getLayerInfos();
      wfsLayerNamesListView.getItems().addAll(wfsLayerInfos);
    } else {
      Alert alert = new Alert(Alert.AlertType.ERROR, "WFS Service Failed to Load!");
      alert.show();
    }
  });

  // populate the list view with layer names
  wfsLayerNamesListView.setCellFactory(list -> new ListCell<>() {

    @Override
    protected void updateItem(WfsLayerInfo wfsLayerInfo, boolean bln) {
      super.updateItem(wfsLayerInfo, bln);
      if (wfsLayerInfo != null) {
        String fullNameOfWfsLayer = wfsLayerInfo.getName();
        String[] split = fullNameOfWfsLayer.split(":");
        String smallName = split[1];
        setText(smallName);
      }
    }
  });

  // load the selected layer from the list view when the layer is selected
  wfsLayerNamesListView.getSelectionModel().selectedItemProperty().addListener(observable ->
    updateMap(wfsLayerNamesListView.getSelectionModel().getSelectedItem())
  );

  // add the controls to the stack pane
  stackPane.getChildren().addAll(mapView, wfsLayerNamesListView, progressIndicator);
  StackPane.setAlignment(wfsLayerNamesListView, Pos.TOP_LEFT);
  StackPane.setMargin(wfsLayerNamesListView, new Insets(10));
}
 
Example 19
Source File: CompactListWidgetSkin.java    From phoenicis with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final ListView<CompactListElement<E>> container = new ListView<>();
    container.getStyleClass().addAll("listWidget", "compactListWidget");

    container.setPrefWidth(0);
    container.setPrefHeight(0);

    // ensure that empty rows have the same height as non-empty ones
    container.setCellFactory(param -> {
        final ListCell<CompactListElement<E>> listCell = new ListCell<CompactListElement<E>>() {
            @Override
            public void updateItem(CompactListElement<E> item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty && item != null) {
                    setGraphic(item);
                } else {
                    setGraphic(null);
                }
            }
        };

        listCell.getStyleClass().addAll("compactListElement");

        return listCell;
    });

    Bindings.bindContent(container.getItems(), mappedElements);

    // ensure that updates to the selected element property are automatically reflected in the view
    getControl().selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        // deselect the old element
        updateOldSelection(container, oldValue);

        // select the new element
        updateNewSelection(container, newValue);
    });

    // initialise selection at startup
    updateNewSelection(container, getControl().getSelectedElement());

    getChildren().addAll(container);
}
 
Example 20
Source File: ControlUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 3 votes vote down vote up
public static <T> void decorateCellFactory(ListView<T> lv, Function<ListCell<T>, ListCell<T>> f) {

        Callback<ListView<T>, ListCell<T>> originalCellF = lv.getCellFactory();

        lv.setCellFactory(l -> f.apply(originalCellF.call(l)));

    }