Java Code Examples for javafx.collections.FXCollections

The following examples show how to use javafx.collections.FXCollections. These examples are extracted from open source projects. 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 Project: quantumjava   Author: johanvos   File: Main.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Chart plotFunction(List<Function<Double, Double>> functions, Number xStart, Number xEnd) {
    int div = 500;
    double x0 = xStart.doubleValue();
    double x1 = xEnd.doubleValue();
    double step = 1./div* (x1-x0);
    Axis<Number> xAxis = new NumberAxis(x0, x1, .1* (x1-x0));
    Axis<Number> yAxis = new NumberAxis();
    ObservableList<XYChart.Series<Number, Number>> series = FXCollections.observableArrayList();
    LineChart<Number,Number> chart = new LineChart(xAxis, yAxis, series);
    chart.setCreateSymbols(false);
    for (Function<Double, Double> f: functions) {
        XYChart.Series<Number, Number> mainSeries = new XYChart.Series();
        series.add(mainSeries);
        ObservableList<XYChart.Data<Number, Number>> data = FXCollections.observableArrayList();
        mainSeries.setData(data);
        for (double x = x0; x < x1; x= x +step) {
            final Number y = f.apply(x);
            data.add(new XYChart.Data<>(x,y));
        }
    }
    return chart;

}
 
Example #2
Source Project: tutorials   Author: eugenp   File: SearchController.java    License: MIT License 6 votes vote down vote up
private void loadData() {

        String searchText = searchField.getText();

        Task<ObservableList<Person>> task = new Task<ObservableList<Person>>() {
            @Override
            protected ObservableList<Person> call() throws Exception {
                updateMessage("Loading data");
                return FXCollections.observableArrayList(masterData
                        .stream()
                        .filter(value -> value.getName().toLowerCase().contains(searchText))
                        .collect(Collectors.toList()));
            }
        };

        task.setOnSucceeded(event -> {
            masterData = task.getValue();
            pagination.setVisible(true);
            pagination.setPageCount(masterData.size() / PAGE_ITEMS_COUNT);
        });

        Thread th = new Thread(task);
        th.setDaemon(true);
        th.start();
    }
 
Example #3
Source Project: phoenicis   Author: PhoenicisOrg   File: ApplicationSidebarSkin.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private SidebarGroup<CheckBox> createFilterGroup() {
    final CheckBox testingCheck = createCheckBox(tr("Testing"));
    getControl().containTestingApplicationsProperty().bind(testingCheck.selectedProperty());

    final CheckBox requiresPatchCheck = createCheckBox(tr("Patch required"));
    getControl().containRequiresPatchApplicationsProperty().bind(requiresPatchCheck.selectedProperty());

    final CheckBox commercialCheck = createCheckBox(tr("Commercial"));
    commercialCheck.setSelected(true);
    getControl().containCommercialApplicationsProperty().bind(commercialCheck.selectedProperty());

    final CheckBox operatingSystemCheck = createCheckBox(tr("All Operating Systems"));
    getControl().containAllOSCompatibleApplicationsProperty().bind(operatingSystemCheck.selectedProperty());

    return new SidebarGroup<>(tr("Filters"), FXCollections.observableArrayList(
            testingCheck, requiresPatchCheck, commercialCheck, operatingSystemCheck));
}
 
Example #4
Source Project: Spring-generator   Author: EliMirren   File: SetSqlController.java    License: MIT License 6 votes vote down vote up
@Override
public void initialize(URL location, ResourceBundle resources) {
	tblProperty.setEditable(true);
	tblProperty.setStyle("-fx-font-size:14px");
	StringProperty property = Main.LANGUAGE.get(LanguageKey.SET_TBL_TIPS);
	String title = property == null ? "可以在右边自定义添加属性..." : property.get();
	tblProperty.setPlaceholder(new Label(title));
	tblPropertyValues = FXCollections.observableArrayList();
	// 设置列的大小自适应
	tblProperty.setColumnResizePolicy(resize -> {
		double width = resize.getTable().getWidth();
		tdKey.setPrefWidth(width / 3);
		tdValue.setPrefWidth(width / 3);
		tdDescribe.setPrefWidth(width / 3);
		return true;
	});
	btnConfirm.widthProperty().addListener(w -> {
		double x = btnConfirm.getLayoutX() + btnConfirm.getWidth() + 10;
		btnCancel.setLayoutX(x);
	});
}
 
Example #5
Source Project: Quelea   Author: quelea-projection   File: ThemeUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get a list of themes currently in use on this window.
 * <p/>
 * @return the list of themes displayed.
 */
public static ObservableList<ThemeDTO> getThemes() {
    List<ThemeDTO> themesList = new ArrayList<>();
    File themeDir = new File(QueleaProperties.get().getQueleaUserHome(), "themes");
    if (!themeDir.exists()) {
        themeDir.mkdir();
    }
    for (File file : themeDir.listFiles()) {
        if (file.getName().endsWith(".th")) {
            String fileText = Utils.getTextFromFile(file.getAbsolutePath(), "");
            if (fileText.trim().isEmpty()) {
                continue;
            }
            final ThemeDTO theme = ThemeDTO.fromString(fileText);
            if (theme == ThemeDTO.DEFAULT_THEME) {
                LOGGER.log(Level.WARNING, "Error parsing theme file: {0}", fileText);
                continue;  //error
            }
            theme.setFile(file);
            themesList.add(theme);
        }
    }
    return FXCollections.observableArrayList(themesList);
}
 
Example #6
Source Project: JetUML   Author: prmr   File: PropertySheet.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Control createEnumEditor(Property pProperty)
{
	Enum<?> value = (Enum<?>)pProperty.get();
	try 
	{
		Enum<?>[] enumValues = (Enum<?>[])value.getClass().getMethod("values").invoke(null);
		final ComboBox<Enum<?>> comboBox = new ComboBox<>(FXCollections.observableArrayList(enumValues));
		
		comboBox.getSelectionModel().select(value);
		comboBox.valueProperty().addListener((pObservable, pOldValue, pNewValue) -> 
		{
			pProperty.set(pNewValue.toString());
			aListener.propertyChanged();
		});
	
		return comboBox;
	}
	catch(NoSuchMethodException | InvocationTargetException | IllegalAccessException e) 
	{ 
		return null; 
	}
}
 
Example #7
Source Project: WorkbenchFX   Author: dlsc-software-consulting-gmbh   File: DialogTestModule.java    License: Apache License 2.0 6 votes vote down vote up
private void initDialogParts() {
  // create the data to show in the CheckListView
  final ObservableList<String> libraries = FXCollections.observableArrayList();
  libraries.addAll("WorkbenchFX", "PreferencesFX", "CalendarFX", "FlexGanttFX", "FormsFX");

  // Create the CheckListView with the data
  checkListView = new CheckListView<>(libraries);

  // initialize map for dialog
  mapView = new GoogleMapView();
  mapView.addMapInializedListener(this);

  // initialize favorites dialog separately
  favoriteLibrariesDialog =
      WorkbenchDialog.builder("Select your favorite libraries", checkListView, Type.INPUT)
          .onResult(buttonType -> {
            if (ButtonType.CANCEL.equals(buttonType)) {
              System.err.println("Dialog was cancelled!");
            } else {
              System.err.println("Chosen favorite libraries: " +
                  checkListView.getCheckModel().getCheckedItems().stream().collect(
                      Collectors.joining(", ")));
            }
          }).build();
}
 
Example #8
Source Project: ReactFX   Author: TomasMikula   File: ListReductionTest.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testWhenBound() {
    ObservableList<Integer> list = FXCollections.observableArrayList(1, 1, 1, 1, 1);
    Val<Integer> sum = LiveList.reduce(list, (a, b) -> a + b);
    Var<Integer> lastObserved = Var.newSimpleVar(sum.getValue());

    assertEquals(5, lastObserved.getValue().intValue());

    sum.addListener((obs, oldVal, newVal) -> {
        assertEquals(lastObserved.getValue(), oldVal);
        lastObserved.setValue(newVal);
    });

    list.addAll(2, Arrays.asList(2, 2));
    assertEquals(9, lastObserved.getValue().intValue());

    list.subList(3, 6).clear();
    assertEquals(5, lastObserved.getValue().intValue());
}
 
Example #9
Source Project: marathonv5   Author: jalian-systems   File: ListViewCellFactorySample.java    License: 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 #10
Source Project: phoenicis   Author: PhoenicisOrg   File: ShortcutInformationPanelSkin.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param control The control belonging to the skin
 */
public ShortcutInformationPanelSkin(ShortcutInformationPanel control) {
    super(control);

    this.description = StringBindings.map(getControl().shortcutProperty(),
            shortcut -> shortcut.getInfo().getDescription());

    this.shortcutProperties = CollectionBindings.mapToMap(getControl().shortcutProperty(), shortcut -> {
        try {
            return getControl().getObjectMapper()
                    .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() {
                        // nothing
                    });
        } catch (IOException e) {
            LOGGER.error("An error occurred during a shortcut update", e);

            return Map.of();
        }
    });

    this.environmentAttributes = FXCollections.observableHashMap();
}
 
Example #11
Source Project: Automekanik   Author: urankajtazaj   File: ShikoPunetPunetoret.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void mbushNgaStatusi(String emri){
    try {
        String sql = "select * from Punet where punetori = '" + emri + "' order by id asc";
        Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        ObservableList<TabelaTeDhenatPunetore> data = FXCollections.observableArrayList();
        Format format = new SimpleDateFormat("dd/MM/yyyy");
        String s = "";
        while (rs.next()) {
            s = format.format(rs.getDate("data"));
            data.add(new TabelaTeDhenatPunetore(rs.getInt("id"), rs.getString("lloji"), s,
                    rs.getFloat("qmimi"), rs.getString("konsumatori"), rs.getString("pershkrimi"), rs.getString("kryer"), rs.getString("makina")));
        }

        rs.close();
        stmt.close();
        conn.close();
        table.setItems(data);
    }catch (Exception ex){ex.printStackTrace();}
}
 
Example #12
Source Project: WorkbenchFX   Author: dlsc-software-consulting-gmbh   File: SingleModuleWorkbenchTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void tabBarVisibilityChanges(){
  HBox bottomBox = robot.lookup("#bottom-box").queryAs(HBox.class);

  WorkbenchModule anotherModule = createMockModule(
          new Label(), null, true, "Module 2", workbench,
          FXCollections.observableArrayList(), FXCollections.observableArrayList());


  robot.interact(() -> {
    // add a second module to the workbench, the bottom-box should be visible now
    workbench.getModules().add(anotherModule);
    assertTrue(bottomBox.isVisible());

    workbench.getModules().remove(anotherModule);
    assertFalse(bottomBox.isVisible());
  });
}
 
Example #13
Source Project: archivo   Author: fflewddur   File: RecordingListController.java    License: GNU General Public License v3.0 6 votes vote down vote up
public RecordingListController(Archivo mainApp) {
    recordingSelection = new RecordingSelection();
    tivoIsBusy = new SimpleBooleanProperty(false);
    alreadyDefaultSorted = false;
    fadeTransition = new FadeTransition(javafx.util.Duration.millis(FADE_DURATION));
    this.mainApp = mainApp;
    tivos = FXCollections.synchronizedObservableList(FXCollections.observableArrayList());
    tablePlaceholderMessage = new Label("No recordings are available");
    tivoSelectedListener = (tivoList, oldTivo, curTivo) -> {
        logger.info("New TiVo selected: {}", curTivo);
        if (curTivo != null) {
            mainApp.setLastDevice(curTivo);
            fetchRecordingsFrom(curTivo);
        }
    };
}
 
Example #14
Source Project: marathonv5   Author: jalian-systems   File: TableScrollSample.java    License: Apache License 2.0 6 votes vote down vote up
public TableScrollSample() {
    final ObservableList<Person> data = FXCollections.observableArrayList(
            new Person("Jacob", "Smith", "[email protected]"),
            new Person("Isabella", "Johnson", "[email protected]"),
            new Person("Ethan", "Williams", "[email protected]"),
            new Person("Emma", "Jones", "[email protected]"), new Person("Michael", "Brown", "[email protected]"));
    TableColumn firstNameCol = new TableColumn();
    firstNameCol.setText("First");
    firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
    TableColumn lastNameCol = new TableColumn();
    lastNameCol.setText("Last");
    lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
    TableColumn emailCol = new TableColumn();
    emailCol.setText("Email");
    emailCol.setMinWidth(200);
    emailCol.setCellValueFactory(new PropertyValueFactory("email"));
    TableView tableView = new TableView();
    tableView.setItems(data);
    ObservableList items = tableView.getItems();
    for (int i = 0; i < 10; i++)
        items.add(new Person("Name" + i, "Last" + i, "Email " + i));
    tableView.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
    getChildren().add(tableView);
}
 
Example #15
Source Project: marathonv5   Author: jalian-systems   File: ListViewCellFactorySample.java    License: 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 #16
Source Project: Automekanik   Author: urankajtazaj   File: ShikoPunetoret.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void mbushPunetoret(){
    try {
        String sql = "select * from Punetoret";
        Connection conn = DriverManager.getConnection(CON_STR, "test", "test");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        ObservableList<TabelaPunetoret> data = FXCollections.observableArrayList();
        Format format = new SimpleDateFormat("dd/MM/yyyy");
        while (rs.next()){
            String s = format.format(rs.getDate("regjistrimi"));
            data.add(new TabelaPunetoret(rs.getInt("id"), rs.getString("emri"),
                    rs.getString("mbiemri"), rs.getString("komuna"), rs.getString("pozita"),
                    s, rs.getFloat("paga")));
        }

        table.setItems(data);
        conn.close();
    }catch (Exception ex){ex.printStackTrace();}
}
 
Example #17
Source Project: triplea   Author: triplea-game   File: RoleSelectionTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@ParameterizedTest
@ValueSource(booleans = {true, false})
void canToggleResourceModifiers(final boolean checked) {
  final CheckBox checkBox = mock(CheckBox.class);
  when(checkBox.isSelected()).thenReturn(checked);

  final Node node1 = mock(Node.class);
  final Node node2 = mockNodeInGridPane(0, 2);
  final Node node3 = mockNodeInGridPane(0, 3);
  final Node node4 = mockNodeInGridPane(1, 2);
  final Node node5 = mockNodeInGridPane(1, 3);

  final GridPane factionGrid = mock(GridPane.class);
  when(factionGrid.getChildren())
      .thenReturn(FXCollections.observableArrayList(node1, node2, node3, node4, node5));
  roleSelection.setFactionGrid(factionGrid);
  roleSelection.setResourceModifierCheckbox(checkBox);

  roleSelection.toggleResourceModifiers();

  verify(node1, never()).setDisable(anyBoolean());
  verify(node2, never()).setDisable(anyBoolean());
  verify(node3, never()).setDisable(anyBoolean());
  verify(node4, never()).setDisable(anyBoolean());
  verify(node5).setDisable(!checked);
}
 
Example #18
Source Project: phoenicis   Author: PhoenicisOrg   File: SettingsView.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private RepositoriesPanel createRepositoriesPanel() {
    ObservableList<RepositoryLocation<? extends Repository>> repositoryLocations = FXCollections
            .observableArrayList(settingsManager.loadRepositoryLocations());

    final RepositoriesPanel repositoriesPanel = new RepositoriesPanel(repositoryLocations);

    // set the initial values
    repositoriesPanel.setOnRepositoryRefresh(repositoryManager::triggerRepositoryChange);

    repositoriesPanel.setRepositoryLocationLoader(repositoryLocationLoader);

    // react to changes
    repositoriesPanel.getRepositoryLocations()
            .addListener((ListChangeListener.Change<? extends RepositoryLocation<? extends Repository>> change) -> {
                repositoryManager.updateRepositories(repositoryLocations);

                settingsManager.saveRepositories(repositoryLocations);
            });

    return repositoriesPanel;
}
 
Example #19
Source Project: marathonv5   Author: jalian-systems   File: DrilldownPieChartSample.java    License: Apache License 2.0 6 votes vote down vote up
public DrilldownPieChartSample() {
    String drilldownCss = DrilldownPieChartSample.class.getResource("DrilldownChart.css").toExternalForm();

    PieChart pie = new PieChart(
            FXCollections.observableArrayList(
            A = new PieChart.Data("A", 20),
            B = new PieChart.Data("B", 30),
            C = new PieChart.Data("C", 10),
            D = new PieChart.Data("D", 40)));
    ((Parent) pie).getStylesheets().add(drilldownCss);

    setDrilldownData(pie, A, "a");
    setDrilldownData(pie, B, "b");
    setDrilldownData(pie, C, "c");
    setDrilldownData(pie, D, "d");
    getChildren().add(pie);
}
 
Example #20
Source Project: dolphin-platform   Author: canoo   File: BidirectionalListBinderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRemoveSingleElementAtBeginningOfDolphinList() {
    // given:
    final javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
    final ObservableList<Integer> dolphinList = new ObservableArrayList<>();
    FXBinder.bind(javaFXList).bidirectionalTo(dolphinList, Object::toString, Integer::parseInt);
    dolphinList.addAll(1, 2, 3);

    // when:
    javaFXList.remove("1");

    // then:
    assertThat(dolphinList, contains(2, 3));
}
 
Example #21
Source Project: gef   Author: eclipse   File: AbstractAnchor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ObservableMap<AnchorKey, Point> getPositionsUnmodifiable() {
	if (positionsUnmodifiable == null) {
		positionsUnmodifiable = FXCollections
				.unmodifiableObservableMap(positions);
	}
	return positionsUnmodifiable;
}
 
Example #22
Source Project: NSMenuFX   Author: codecentric   File: WindowMenuUpdateListener.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public WindowMenuUpdateListener(Menu windowMenu) {
	this.windowMenu = new WeakReference<>(windowMenu);
	createdMenuItems = new HashMap<>();

	addItemsToMenu(StageUtils.getStages());

	stages = FXCollections.observableArrayList(stage -> new Observable[] {stage.focusedProperty()});
	Bindings.bindContent(stages, StageUtils.getStages());

	stages.addListener((Change <? extends Stage> c) -> checkFocusedStage());
}
 
Example #23
Source Project: bisq   Author: bisq-network   File: SpreadViewModelTest.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testMaxCharactersForAmountWithNoOffers() {
    OfferBook offerBook = mock(OfferBook.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();

    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

    SpreadViewModel model = new SpreadViewModel(offerBook, null, coinFormatter);
    assertEquals(0, model.maxPlacesForAmount.intValue());
}
 
Example #24
Source Project: OpenLabeler   Author: kinhong   File: Settings.java    License: Apache License 2.0 5 votes vote down vote up
public RecentList(int maxLength, String baseKey, Class<T> type) {
    super(FXCollections.observableArrayList());
    this.maxLength = maxLength;
    this.baseKey = baseKey;
    this.type = type;
    load();
}
 
Example #25
Source Project: dolphin-platform   Author: canoo   File: BidirectionalListBinderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRemoveSingleElementInMiddleOfDolphinList() {
    // given:
    final javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
    final ObservableList<Integer> dolphinList = new ObservableArrayList<>();
    FXBinder.bind(javaFXList).bidirectionalTo(dolphinList, Object::toString, Integer::parseInt);
    dolphinList.addAll(1, 2, 3);

    // when:
    javaFXList.remove("2");

    // then:
    assertThat(dolphinList, contains(1, 3));
}
 
Example #26
Source Project: dctb-utfpr-2018-1   Author: diogocezar   File: ListAllController.java    License: Apache License 2.0 5 votes vote down vote up
private void loadList() {
    pokemonsList = FXCollections.observableArrayList();
    try {
        for (Pokemon el : ControllerMaster.getInstance().getPokeDAO().getALlPokemons()) {
            pokemonsList.add(el);
        }
    } catch (Exception e) {
        ControllerMaster.getInstance().displayErrorAlert("Falha ao conectar com o banco!");
    }
}
 
Example #27
Source Project: constellation   Author: constellation-app   File: JsonIODialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * *
 * Present a dialog allowing user to select an entry from a list of
 * available files.
 *
 * @param names list of filenames to choose from
 * @return the selected element text or null if nothing was selected
 */
public static String getSelection(final String[] names) {
    final Alert dialog = new Alert(Alert.AlertType.CONFIRMATION);
    final ObservableList<String> q = FXCollections.observableArrayList(names);
    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);
        }
    });
    ButtonType removeButton = new ButtonType("Remove");
    dialog.getDialogPane().setContent(nameList);
    dialog.getButtonTypes().add(removeButton);
    dialog.setResizable(false);
    dialog.setTitle("Preferences");
    dialog.setHeaderText("Select a preference to load.");

    // The remove button has been wrapped inside the btOk, this has been done because any ButtonTypes added
    // to an alert window will automatically close the window when pressed. 
    // Wrapping it in another button can allow us to consume the closing event and keep the window open.
    final Button btOk = (Button) dialog.getDialogPane().lookupButton(removeButton);
    btOk.addEventFilter(ActionEvent.ACTION, event -> {
        JsonIO.deleteJsonPreference(nameList.getSelectionModel().getSelectedItem());
        q.remove(nameList.getSelectionModel().getSelectedItem());
        nameList.setCellFactory(p -> new DraggableCell<>());
        dialog.getDialogPane().setContent(nameList);
        event.consume();
    });
    final Optional<ButtonType> option = dialog.showAndWait();
    if (option.isPresent() && option.get() == ButtonType.OK) {
        return nameList.getSelectionModel().getSelectedItem();
    }

    return null;
}
 
Example #28
Source Project: MusicPlayer   Author: Mpmart08   File: RecentlyPlayedPlaylist.java    License: MIT License 5 votes vote down vote up
@Override
public ObservableList<Song> getSongs() {

    List<Song> songs = new ArrayList<>(Library.getSongs());
    songs = songs.stream()
            .filter(x -> x.getPlayCount() > 0)
            .sorted((x, y) -> y.getPlayDate().compareTo(x.getPlayDate()))
            .collect(Collectors.toList());

    if (songs.size() > 100) {
        songs = songs.subList(0, 100);
    }

    return FXCollections.observableArrayList(songs);
}
 
Example #29
Source Project: marathonv5   Author: jalian-systems   File: AdvancedBarChartSample.java    License: Apache License 2.0 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final String[] years = {"2007", "2008", "2009"};
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    // setup chart
    bc.setTitle("Advanced Bar Chart");
    xAxis.setLabel("Year");
    xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
    yAxis.setLabel("Price");
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    XYChart.Series<String,Number> series2 = new XYChart.Series<String,Number>();
    series2.setName("Data Series 2");
    XYChart.Series<String,Number> series3 = new XYChart.Series<String,Number>();
    series3.setName("Data Series 3");
    // create sample data
    series1.getData().add(new XYChart.Data<String,Number>(years[0], 567));
    series1.getData().add(new XYChart.Data<String,Number>(years[1], 1292));
    series1.getData().add(new XYChart.Data<String,Number>(years[2], 2180));
    series2.getData().add(new XYChart.Data<String,Number>(years[0], 956));
    series2.getData().add(new XYChart.Data<String,Number>(years[1], 1665));
    series2.getData().add(new XYChart.Data<String,Number>(years[2], 2450));
    series3.getData().add(new XYChart.Data<String,Number>(years[0], 800));
    series3.getData().add(new XYChart.Data<String,Number>(years[1], 1000));
    series3.getData().add(new XYChart.Data<String,Number>(years[2], 2800));
    bc.getData().add(series1);
    bc.getData().add(series2);
    bc.getData().add(series3);
    return bc;
}
 
Example #30
Source Project: marathonv5   Author: jalian-systems   File: ProductFetcherTask.java    License: Apache License 2.0 5 votes vote down vote up
@Override protected ObservableList<FullProductListing> call() throws Exception {
    FullProductListingClient client = new FullProductListingClient();
    FullProductListing[] fpl = client.findAll_JSON(FullProductListing[].class);
    ObservableList<FullProductListing> results = FXCollections.observableArrayList(fpl);
    client.close();
    return results;
}