Java Code Examples for javafx.collections.ObservableList

The following examples show how to use javafx.collections.ObservableList. 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
/**
 * Sets the list of conversation which can be displayed in this tab.
 * 
 * @param conversations list of conversations
 */
public static void setConversations(ObservableList<Conversation> conversations) {
	instance.conversation.setItems(conversations);
	if (instance.currentConversation != null && conversations.contains(instance.currentConversation)) {
		instance.displayConversation(instance.currentConversation);
	} else {
		instance.displayConversation();
	}
	instance.npc.textProperty().addListener((observable, oldValue, newValue) -> {
	    if (newValue == null || newValue.isEmpty()) {
	    	instance.npc.setStyle("-fx-background-color: red");
	    } else {
	    	instance.npc.setStyle(null);
	    }
	});
}
 
Example 2
Source Project: constellation   Source File: ColorInputPane.java    License: Apache License 2.0 7 votes vote down vote up
private ComboBox<ConstellationColor> makeNamedCombo() {
    final ObservableList<ConstellationColor> namedColors = FXCollections.observableArrayList();
    for (final ConstellationColor c : ConstellationColor.NAMED_COLOR_LIST) {
        namedColors.add(c);
    }
    final ComboBox<ConstellationColor> namedCombo = new ComboBox<>(namedColors);
    namedCombo.setValue(ConstellationColor.WHITE);
    final Callback<ListView<ConstellationColor>, ListCell<ConstellationColor>> cellFactory = (final ListView<ConstellationColor> p) -> new ListCell<ConstellationColor>() {
        @Override
        protected void updateItem(final ConstellationColor item, boolean empty) {
            super.updateItem(item, empty);
            if (item != null) {
                final Rectangle r = new Rectangle(12, 12, item.getJavaFXColor());
                r.setStroke(Color.BLACK);
                setText(item.getName());
                setGraphic(r);
            }
        }
    };
    namedCombo.setCellFactory(cellFactory);
    namedCombo.setButtonCell(cellFactory.call(null));

    return namedCombo;
}
 
Example 3
Source Project: CPUSim   Source File: DesktopController.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * updates the Save and Load RAM menus so that the the contain a menu item
 * for each RAM in the current machine
 */
private void updateRamMenus() {
    ObservableList<RAM> rams = (ObservableList<RAM>) mediator.getMachine()
            .getModule("rams");
    saveRamMenu.getItems().clear();
    openRamMenu.getItems().clear();

    for (RAM ram : rams) {
        final RAM finalRam = ram;
        MenuItem saveMenuItem = new MenuItem("from " + ram.getName() + "...");
        saveMenuItem.setOnAction(e -> saveRam(finalRam));
        saveRamMenu.getItems().add(saveMenuItem);

        MenuItem openMenuItem = new MenuItem("into " + ram.getName() + "...");
        openMenuItem.setOnAction(e -> openRam(finalRam));
        openRamMenu.getItems().add(openMenuItem);
    }
}
 
Example 4
@Override
public ObservableList<TreeItem<File>> getChildren() {
	if (!childrenInitialized) {
		childrenInitialized = true;

		File f = getValue();
		if (f.isDirectory()) {
			File[] files = f.listFiles(filter);
			if (files != null) {
				Arrays.sort(files, FILE_COMPARATOR);
				ArrayList<TreeItem<File>> children = new ArrayList<>();
				for (File file : files)
					children.add(new FileTreeItem(file, filter));
				super.getChildren().setAll(children);
			}
		}
	}
	return super.getChildren();
}
 
Example 5
Source Project: chart-fx   Source File: GridRenderer.java    License: Apache License 2.0 6 votes vote down vote up
protected void drawHorizontalMajorGridLines(final GraphicsContext gc, final Axis yAxis,
        final double xAxisWidthSnapped, final double yAxisHeight) {
    if (!horMajorGridStyleNode.isVisible() && !horMinorGridStyleNode.isVisible()) {
        return;
    }
    final double zeroSnapped = snap(0);
    applyGraphicsStyleFromLineStyle(gc, horMajorGridStyleNode);
    ObservableList<TickMark> tickMarks = yAxis.getTickMarks();
    for (int i = 0; i < tickMarks.size(); i++) {
        double y = snap(yAxis.getDisplayPosition(tickMarks.get(i).getValue()));
        if (y >= 0 && y < yAxisHeight) {
            // gc.strokeLine(zeroSnapped, y, xAxisWidthSnapped, y);
            DashPatternStyle.strokeDashedLine(gc, zeroSnapped, y, xAxisWidthSnapped, y);
        }
    }
}
 
Example 6
Source Project: phoebus   Source File: SnapshotTable.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets new table entries for this table, but do not change the structure of the table.
 *
 * @param entries the entries to set
 */
public void updateTable(List<TableEntry> entries) {
    final ObservableList<TableEntry> items = getItems();
    final boolean notHide = !controller.isHideEqualItems();
    items.clear();
    entries.forEach(e -> {
        // there is no harm if this is executed more than once, because only one line is allowed for these
        // two properties (see SingleListenerBooleanProperty for more details)
        e.selectedProperty()
            .addListener((a, o, n) -> selectAllCheckBox.setSelected(n ? selectAllCheckBox.isSelected() : false));
        e.liveStoredEqualProperty().addListener((a, o, n) -> {
            if (controller.isHideEqualItems()) {
                if (n) {
                    getItems().remove(e);
                } else {
                    getItems().add(e);
                }
            }
        });
        if (notHide || !e.liveStoredEqualProperty().get()) {
            items.add(e);
        }
    });
}
 
Example 7
Source Project: jmonkeybuilder   Source File: NodeTree.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Select the item.
 */
@FxThread
private void updateSelection(@NotNull final ObservableValue<? extends TreeItem<TreeNode<?>>> observable,
                             @Nullable final TreeItem<TreeNode<?>> oldValue,
                             @Nullable final TreeItem<TreeNode<?>> treeItem) {

    final ObservableList<TreeItem<TreeNode<?>>> selectedItems = getTreeView()
            .getSelectionModel()
            .getSelectedItems();

    final Array<Object> objects = LocalObjects.get().nextObjectArray();
    objects.clear();

    for (final TreeItem<TreeNode<?>> selectedItem : selectedItems) {
        if (selectedItem == null) continue;
        objects.add(selectedItem.getValue());
    }

    selectionHandler.accept(objects);
}
 
Example 8
Source Project: ariADDna   Source File: FileBrowserController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Method for generate file items for fileBrowser and add it into container(temporary realization)
 */
private void showContent() {
    ObservableList<FileItem> list = FXCollections.observableArrayList();
    GridView<FileItem> myGrid = new GridView<>(list);
    myGrid.setCellFactory(gridView -> new GridCell<FileItem>() {
        @Override
        public void updateItem(FileItem item, boolean empty) {
            if (empty || item == null) {
                setText(null);
                setGraphic(null);
            } else {
                //setText(item.getName());
                setGraphic(item);
            }

        }
    });
    list.addAll(new FileItem("icon", "Folder1"),
            new FileItem("icon", "Documents"),
            new FileItem("icon", "WorkFiles"),
            new FileItem("icon", "Projects"));
    container.getChildren().add(myGrid);
}
 
Example 9
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 10
@Override
public ComboBox<ColoringType> createEditingComponent() {
  ObservableList<ColoringType> choicesList = FXCollections.observableArrayList();
  choicesList.add(ColoringType.NOCOLORING);
  choicesList.add(ColoringType.COLORBYFILE);
  for (UserParameter<?, ?> p : MZmineCore.getProjectManager().getCurrentProject()
      .getParameters()) {
    choicesList.add(new ColoringType(p));
  }
  ComboBox<ColoringType> editor = new ComboBox<ColoringType>(choicesList);
  if (value != null)
    editor.getSelectionModel().select(value);
  return editor;
}
 
Example 11
Source Project: chart-fx   Source File: DefaultRenderColorScheme.java    License: Apache License 2.0 5 votes vote down vote up
public static final ObservableList<Paint> getStandardFillStyle() {
    final ObservableList<Paint> values = FXCollections.observableArrayList();
    for (Color colour : fillColorProperty().get()) {
        values.add(FillPatternStyleHelper.getDefaultHatch(colour.brighter(), hatchShiftByIndexProperty().get()));
    }
    return values;
}
 
Example 12
Source Project: classpy   Source File: DirTreeItem.java    License: MIT License 5 votes vote down vote up
@Override
public ObservableList<TreeItem<DirTreeNode>> getChildren() {
    if (isFirstTimeChildren) {
        isFirstTimeChildren = false;
        System.out.println("get children of " + getValue());

        // First getChildren() call, so we actually go off and 
        // determine the children of the File contained in this TreeItem.
        super.getChildren().setAll(buildChildren());
    }
    
    return super.getChildren();
}
 
Example 13
Source Project: LogFX   Source File: FxUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void addIfNotPresent( ObservableList<String> styleClasses,
                                    String... cssClasses ) {
    for ( String cssClass : cssClasses ) {
        if ( !styleClasses.contains( cssClass ) ) {
            styleClasses.add( cssClass );
        }
    }
}
 
Example 14
Source Project: AsciidocFX   Source File: ApplicationController.java    License: Apache License 2.0 5 votes vote down vote up
public void applyCurrentTheme(Stage... stages) {

        ObservableList<EditorConfigBean.Theme> editorTheme = editorConfigBean.getEditorTheme();

        if (editorTheme.isEmpty()) {
            return;
        }

        EditorConfigBean.Theme theme = editorTheme.get(0);
        String themeUri = theme.themeUri();

        if (isNull(themeUri)) {
            return;
        }

        threadService.runActionLater(() -> {
            try {

                String aceTheme = theme.getAceTheme();
//                editorConfigBean.updateAceTheme(aceTheme);

                for (Stage stage : stages) {
                    if (nonNull(stage) && nonNull(stage.getScene())) {
                        ObservableList<String> stylesheets = stage.getScene().getStylesheets();
                        stylesheets.clear();
                        stylesheets.add(themeUri);
                    }
                }

                terminalConfigBean.changeTheme(theme);

            } catch (Exception e) {
                logger.error("Error occured while setting new theme {}", theme);
            }
        });
    }
 
Example 15
Source Project: PeerWasp   Source File: NavigationServiceTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testNavigate() throws IOException {
	ObservableList<Node> pages = getPages();
	assertNotNull(pages);

	/* first page */
	String page_1 = "/testpage1.fxml";
	navigationService.navigate(page_1);
	Mockito.verify(fxmlLoaderProvider, Mockito.times(1)).create(page_1);
	Mockito.verify(fxmlLoader, Mockito.times(1)).load();
	Mockito.verify(controller, Mockito.times(1)).setContent(elements[0]);
	assertTrue(pages.size() == 1);
	assertEquals(pages.get(0), elements[0]);

	/* second page */
	String page_2 = "/testpage2.fxml";
	navigationService.navigate(page_2);
	Mockito.verify(fxmlLoaderProvider, Mockito.times(1)).create(page_2);
	Mockito.verify(fxmlLoader, Mockito.times(2)).load();
	Mockito.verify(controller, Mockito.times(1)).setContent(elements[1]);
	assertTrue(pages.size() == 2);
	assertEquals(pages.get(0), elements[0]);
	assertEquals(pages.get(1), elements[1]);

	/* third page */
	String page_3 = "/testpage3.fxml";
	navigationService.navigate(page_3);
	Mockito.verify(fxmlLoaderProvider, Mockito.times(1)).create(page_3);
	Mockito.verify(fxmlLoader, Mockito.times(3)).load();
	Mockito.verify(controller, Mockito.times(1)).setContent(elements[2]);
	assertTrue(pages.size() == 3);
	assertEquals(pages.get(0), elements[0]);
	assertEquals(pages.get(1), elements[1]);
	assertEquals(pages.get(2), elements[2]);
}
 
Example 16
Source Project: DevToolBox   Source File: MainAction.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
public void deleteRedisKeyAction() {
    ObservableList list = mc.redisValueTable.getSelectionModel().getSelectedItems();
    if (list.isEmpty()) {
        Toast.makeText("请选择要删除的记录").show(mc.pane.getScene().getWindow());
        return;
    }
    StringBuilder key = new StringBuilder();
    int i = 0;
    for (Object object : list) {
        Map mp = (Map) object;
        key.append(mp.get("key"));
        if (i != list.size() - 1) {
            key.append(",");
        }
        i++;
    }
    Alert a = new Alert(Alert.AlertType.CONFIRMATION);
    a.setTitle("确认删除");
    a.setContentText("确认要删除[" + key + "]这些键值吗?");
    a.initOwner(mc.pane.getScene().getWindow());
    Optional<ButtonType> o = a.showAndWait();
    if (o.get().getButtonData().equals(ButtonBar.ButtonData.OK_DONE)) {
        String[] keys = key.toString().split(",");
        String name = (String) mc.redisDatabaseList.getSelectionModel().getSelectedItem();
        RedisUtil.deleteKeys(name, keys);
        Toast.makeText("删除成功", Duration.seconds(1)).show(mc.pane.getScene().getWindow());
        mc.paginationForValue.getPageFactory().call(0);
    }
}
 
Example 17
Source Project: HealthPlus   Source File: AddNewDrugController.java    License: Apache License 2.0 5 votes vote down vote up
@FXML private void showDrugUnit()
{
    drugUnit.setDisable(false);
    
    ObservableList<String> units = FXCollections.observableArrayList();
    units.add("mg");
    units.add("g");
    units.add("ml");
    drugUnit.getItems().clear();
    drugUnit.getItems().addAll(units);
}
 
Example 18
Source Project: ShootOFF   Source File: PolygonRegion.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void changeHeight(final double heightDelta) {
	final ObservableList<Double> points = getPoints();
	final List<Double> pointsY = new ArrayList<>();

	for (int i = 1; i < points.size(); i += 2) {
		pointsY.add(points.get(i));
	}

	final double height = Collections.max(pointsY);
	final double scaleFactor = (height + heightDelta) / height;

	setScaleY(getScaleY() * scaleFactor);
}
 
Example 19
public static void setCompassTarget(ObservableList<CompassTarget> targets) {
	instance.compassList.setItems(null);
	instance.compassList.setItems(targets);
	instance.compassList.setOnMouseClicked(event -> {
		if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
			instance.editCompassTarget();
		}
	});
}
 
Example 20
/**
 * @return all NpcOptions from loaded conversations in this package, the ones from current conversation first
 */
public ObservableList<NpcOption> getAllNpcOptions() {
	ObservableList<NpcOption> list = FXCollections.observableArrayList();
	list.addAll(ConversationController.getDisplayedConversation().getNpcOptions());
	conversations.forEach(conv -> {
		if (!conv.equals(ConversationController.getDisplayedConversation())) {
			list.addAll(conv.getNpcOptions());
		}
	});
	return list;
}
 
Example 21
Source Project: Corendon-LostLuggage   Source File: OverviewUserController.java    License: MIT License 5 votes vote down vote up
public ObservableList<User> getUsers() {

        ObservableList<User> users = FXCollections.observableArrayList();

        try {
            ResultSet resultSet;

            resultSet = DB.executeResultSetQuery("SELECT employeeId, firstname, lastname, location, status, role FROM employee");

            while (resultSet.next()) {
                String id = resultSet.getString("employeeId");
                String firstName = resultSet.getString("firstname");
                String lastName = resultSet.getString("lastname");
                String location = resultSet.getString("location");
                String status = resultSet.getString("status");
                String role = resultSet.getString("role");

                System.out.println("ID: " + id + "  Firstname: " + firstName + " Lastname: " + lastName + " Location: " + location + " Status: " + status + " Role: " + role);
                users.add(new User(id, lastName, firstName, location, role, status));

            }

        } catch (SQLException ex) {
            Logger.getLogger(OverviewUserController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return users;
    }
 
Example 22
Source Project: AsciidocFX   Source File: ApplicationController.java    License: Apache License 2.0 5 votes vote down vote up
public void closeOtherTerminals(ActionEvent actionEvent) {
    ObservableList<Tab> tabs = FXCollections.observableArrayList(terminalTabPane.getTabs());
    tabs.remove(terminalTabPane.getSelectionModel().getSelectedItem());

    for (Tab tab : tabs) {
        ((TerminalTab) tab).closeTerminal();
    }
}
 
Example 23
Source Project: Flowless   Source File: VirtualFlowTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void idempotentSetLengthOffsetTest() {
    // create VirtualFlow with 1 big cell
    Rectangle rect = new Rectangle(500, 500);
    ObservableList<Rectangle> items = FXCollections.singletonObservableList(rect);
    VirtualFlow<Rectangle, Cell<Rectangle, Rectangle>> vf = VirtualFlow.createVertical(items, Cell::wrapNode);
    vf.resize(100, 100); // size of VirtualFlow less than that of the cell
    vf.layout();

    vf.setLengthOffset(10.0);
    vf.setLengthOffset(10.0);
    vf.layout();
    assertEquals(-10.0, rect.getBoundsInParent().getMinY(), 0.01);
}
 
Example 24
Source Project: marathonv5   Source File: SplitDockingContainer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void replace(Node base, INewDockingContainer indc) {
    double[] dividerPositions = getDividerPositions();
    ObservableList<Node> items = getItems();
    int indexOf = items.indexOf(base);
    items.remove(indexOf);
    items.add(indexOf, indc.get());
    setDividerPositions(dividerPositions);
}
 
Example 25
Source Project: constellation   Source File: TableViewPane.java    License: Apache License 2.0 5 votes vote down vote up
private void updateVisibleColumns(final Graph graph, final TableViewState state,
        final List<ThreeTuple<String, Attribute, TableColumn<ObservableList<String>, String>>> columns, final UpdateMethod updateState) {
    if (graph != null && state != null) {
        final TableViewState newState = new TableViewState(state);

        final List<Tuple<String, Attribute>> columnAttributes = new ArrayList<>();
        switch (updateState) {
            case ADD:
                if (newState.getColumnAttributes() != null) {
                    columnAttributes.addAll(newState.getColumnAttributes());
                }
                columnAttributes.addAll(columns.stream()
                        .map(columnTuple -> Tuple.create(columnTuple.getFirst(), columnTuple.getSecond()))
                        .collect(Collectors.toList()));
                break;
            case REMOVE:
                if (newState.getColumnAttributes() != null) {
                    columnAttributes.addAll(newState.getColumnAttributes());
                }
                columnAttributes.removeAll(columns.stream()
                        .map(columnTuple -> Tuple.create(columnTuple.getFirst(), columnTuple.getSecond()))
                        .collect(Collectors.toList()));
                break;
            case REPLACE:
                columnAttributes.addAll(columns.stream()
                        .map(columnTuple -> Tuple.create(columnTuple.getFirst(), columnTuple.getSecond()))
                        .collect(Collectors.toList()));
                break;
        }

        newState.setColumnAttributes(columnAttributes);
        PluginExecution.withPlugin(new TableViewUtilities.UpdateStatePlugin(newState)).executeLater(graph);
    }
}
 
Example 26
Source Project: qiniu   Source File: MainController.java    License: MIT License 5 votes vote down vote up
/**
 * 复制链接
 */
public void copyLink() {
    ObservableList<FileBean> fileBeans = resTV.getSelectionModel().getSelectedItems();
    if (Checker.isNotEmpty(fileBeans)) {
        // 只复制选中的第一个文件的链接
        Utils.copyToClipboard(QiniuUtils.buildUrl(fileBeans.get(0).getName(), domainTF.getText()));
    }
}
 
Example 27
Source Project: DashboardFx   Source File: PieChart.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(URL location, ResourceBundle resources) {
    ObservableList<javafx.scene.chart.PieChart.Data> pieChartData = FXCollections.observableArrayList(
            new javafx.scene.chart.PieChart.Data("Sun", 20),
            new javafx.scene.chart.PieChart.Data("IBM", 12),
            new javafx.scene.chart.PieChart.Data("HP", 25),
            new javafx.scene.chart.PieChart.Data("Dell", 22),
            new javafx.scene.chart.PieChart.Data("Apple", 30)
    );
    pieChart.setData(pieChartData);
    pieChart.setClockwise(false);
}
 
Example 28
Source Project: CPUSim   Source File: IOTableController.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the clones to the new array passed as a parameter.
 * Does not check for validity.
 *
 * @param newClones Object array containing new set of clones
 */
public void setClones(ObservableList newClones)
{
    IO[] ios = new IO[newClones.size()];
    for (int i = 0; i < newClones.size(); i++) {
        ios[i] = (IO) newClones.get(i);
    }
    clones = ios;
}
 
Example 29
Source Project: sis   Source File: ResourceView.java    License: Apache License 2.0 5 votes vote down vote up
private void setContent(final Node content) {
    final ObservableList<Node> items = pane.getItems();
    if (items.size() >= 2) {
        items.set(1, content);
    } else {
        items.add(content);
    }
}
 
Example 30
Source Project: marathonv5   Source File: UnSavedHistoryStage.java    License: Apache License 2.0 5 votes vote down vote up
private void onManageFavourites() {
    FavouriteHistoryStage favouriteHistoryStage = new FavouriteHistoryStage(new RunHistoryInfo("favourites"));
    favouriteHistoryStage.getStage().showAndWait();
    ObservableList<JSONObject> items = historyView.getItems();
    items.clear();
    items.addAll(runHistoryInfo.getTests());
}