Search in sources :

Example 16 with ReadOnlyStringWrapper

use of javafx.beans.property.ReadOnlyStringWrapper in project Smartcity-Smarthouse by TechnionYP5777.

the class MainSystemGuiController method setupFSTreeView.

private void setupFSTreeView(SystemCore model) {
    TreeItem<String> rootElement = new TreeItem<>("File System View");
    rootElement.setExpanded(true);
    createTree(model.getFileSystem().getReadOnlyFileSystem(), rootElement);
    TreeTableColumn<String, String> fsViewCol = new TreeTableColumn<>();
    fsViewCol.prefWidthProperty().bind(fsTreeView.widthProperty());
    fsViewCol.setCellValueFactory((CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(p.getValue().getValue()));
    fsTreeView.setRoot(rootElement);
    fsTreeView.getColumns().add(fsViewCol);
    mainSplitPane.getItems().add(fsTreeView);
    mainSplitPane.getDividers().get(0).setPosition(0.7);
}
Also used : CellDataFeatures(javafx.scene.control.TreeTableColumn.CellDataFeatures) TreeItem(javafx.scene.control.TreeItem) TreeTableColumn(javafx.scene.control.TreeTableColumn) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper)

Example 17 with ReadOnlyStringWrapper

use of javafx.beans.property.ReadOnlyStringWrapper in project Smartcity-Smarthouse by TechnionYP5777.

the class ConfigurationWindowController method initialize.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.gui_controller.GuiController#initialize(java
     * .lang.Object, il.ac.technion.cs.smarthouse.gui_controller.GuiController,
     * java.net.URL, java.util.ResourceBundle)
     */
@Override
protected <T extends GuiController<SensorsSimulator>> void initialize(SensorsSimulator model1, T parent1, URL location, ResourceBundle b) {
    backButton.setOnAction(__1 -> ((DeveloperSimulatorController) this.getParentController()).moveToSensorsList());
    nameColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getKey()));
    typeColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getValue().getName()));
    deleteColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    deleteColumn.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAlignment(Pos.CENTER);
        return $;
    });
    addTypeField.setPromptText("Field Type");
    addTypeField.getItems().addAll(Types.values());
    addNameField.focusedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> b, Boolean oldValue, Boolean newValue) {
            if (// Focusing out
            !newValue)
                addNameField.setStyle("-fx-border-color: " + (addNameField.getText().isEmpty() ? "red" : "green"));
        }
    });
    alias.focusedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> b, Boolean oldValue, Boolean newValue) {
            if (// Focusing out
            !newValue)
                alias.setStyle("-fx-border-color: " + (alias.getText().isEmpty() ? "red" : "green"));
        }
    });
    commName.focusedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> b, Boolean oldValue, Boolean newValue) {
            if (// Focusing out
            !newValue)
                commName.setStyle("-fx-border-color: " + (commName.getText().isEmpty() ? "red" : "green"));
        }
    });
    final int btnCount = buttonBox.getChildren().size();
    addNameField.prefWidthProperty().bind(buttonBox.widthProperty().divide(btnCount));
    addTypeField.prefWidthProperty().bind(buttonBox.widthProperty().divide(btnCount));
    addButton.prefWidthProperty().bind(buttonBox.widthProperty().divide(btnCount));
    addButton.setOnAction(__1 -> addField());
    saveButton.setOnAction(__1 -> saveNewSensor());
    fieldsTable.setItems(typesList);
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper)

Example 18 with ReadOnlyStringWrapper

use of javafx.beans.property.ReadOnlyStringWrapper in project Smartcity-Smarthouse by TechnionYP5777.

the class MainSensorListController method initialize.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.gui_controller.GuiController#initialize(java
     * .lang.Object, il.ac.technion.cs.smarthouse.gui_controller.GuiController,
     * java.net.URL, java.util.ResourceBundle)
     */
@Override
protected <T extends GuiController<SensorsSimulator>> void initialize(SensorsSimulator model1, T parent1, URL location, ResourceBundle b) {
    Consumer<GenericSensor> addConsumer = x -> {
        this.sensors.add(new Pair<String, String>(model1.getSensorId(x), x.getCommname() + "(" + x.getAlias() + ")"));
        sensors.sort(new Comparator<Pair<String, String>>() {

            @Override
            public int compare(Pair<String, String> o1, Pair<String, String> o2) {
                return o1.getValue().compareTo(o2.getValue());
            }
        });
    };
    model1.addListenerWhen(SensorsSimulator.Action.ADD, addConsumer);
    sensorTable.setItems(sensors);
    nameColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.7));
    nameColumn.setResizable(false);
    nameColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getValue()));
    configColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.1));
    configColumn.setResizable(false);
    configColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    configColumn.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                final TextInputDialog dialog = new TextInputDialog();
                dialog.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/Homeicon.png"))));
                dialog.setTitle("Sensor simulator");
                dialog.setHeaderText("Clone Sensor");
                dialog.setContentText("Please enter the cloned sensor alias:");
                final Optional<String> result = dialog.showAndWait();
                if (!result.isPresent())
                    return;
                final String name = result.get();
                MainSensorListController.this.getModel().cloneSensor($.getTableView().getItems().get($.getIndex()).getKey(), name);
            }
        });
        $.setImage(new ImageView(new Image(getClass().getResourceAsStream("/Copy.png"))));
        $.setAlignment(Pos.CENTER);
        return $;
    });
    messageColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.1));
    messageColumn.setResizable(false);
    messageColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    messageColumn.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                setSelectedSensor($.getTableView().getItems().get($.getIndex()).getKey());
                ((DeveloperSimulatorController) MainSensorListController.this.getParentController()).openMessageWindow();
            }
        });
        $.setImage(new ImageView(new Image(getClass().getResourceAsStream("/Message.png"))));
        $.setAlignment(Pos.CENTER);
        return $;
    });
    deleteColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.1));
    deleteColumn.setResizable(false);
    deleteColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    deleteColumn.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                Alert alert = new Alert(AlertType.CONFIRMATION);
                alert.setTitle("Confirmation Dialog");
                alert.setHeaderText("Are you sure?");
                alert.setContentText("The sensor will be deleted forever!");
                Optional<ButtonType> result = alert.showAndWait();
                if (result.get() != ButtonType.OK)
                    return;
                final Pair<String, String> currentSensor = $.getTableView().getItems().get($.getIndex());
                model1.removeSensor(currentSensor.getKey());
                MainSensorListController.this.sensors.remove(currentSensor);
            }
        });
        $.setImage(new ImageView(new Image(getClass().getResourceAsStream("/Delete.png"))));
        $.setAlignment(Pos.CENTER);
        return $;
    });
    addButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            ((DeveloperSimulatorController) MainSensorListController.this.getParentController()).moveToConfiguration();
        }
    });
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) URL(java.net.URL) GuiController(il.ac.technion.cs.smarthouse.gui_controller.GuiController) ButtonType(javafx.scene.control.ButtonType) FXCollections(javafx.collections.FXCollections) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) ResourceBundle(java.util.ResourceBundle) AlertType(javafx.scene.control.Alert.AlertType) TableView(javafx.scene.control.TableView) Alert(javafx.scene.control.Alert) Pair(javafx.util.Pair) SensorsSimulator(il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) Consumer(java.util.function.Consumer) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) GenericSensor(il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor) ImageView(javafx.scene.image.ImageView) TextInputDialog(javafx.scene.control.TextInputDialog) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) Comparator(java.util.Comparator) Image(javafx.scene.image.Image) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Optional(java.util.Optional) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) ActionEvent(javafx.event.ActionEvent) Image(javafx.scene.image.Image) Comparator(java.util.Comparator) Alert(javafx.scene.control.Alert) ImageView(javafx.scene.image.ImageView) GenericSensor(il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor) Pair(javafx.util.Pair) TextInputDialog(javafx.scene.control.TextInputDialog)

Example 19 with ReadOnlyStringWrapper

use of javafx.beans.property.ReadOnlyStringWrapper in project Smartcity-Smarthouse by TechnionYP5777.

the class SendMessageController method addStringField.

private void addStringField(String fieldName) {
    ObservableList<String> s = FXCollections.observableArrayList();
    Label label = new Label(fieldName + ":");
    TableView<String> table = new TableView<>(s);
    TableColumn<String, String> valueCol = new TableColumn<String, String>("Value");
    valueCol.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue()));
    TableColumn<String, Boolean> deleteCol = new TableColumn<String, Boolean>();
    deleteCol.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    deleteCol.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAction(__1 -> s.remove($.getTableView().getItems().get($.getIndex())));
        $.setAlignment(Pos.CENTER);
        return $;
    });
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.setPrefSize(100, 100);
    table.getColumns().setAll(Arrays.asList(valueCol, deleteCol));
    Group group = new Group(table);
    VBox.setVgrow(group, Priority.NEVER);
    TextField addValue = new TextField();
    Button addButton = new Button("Add");
    addButton.setOnAction(__1 -> {
        s.add(addValue.getText());
        addValue.clear();
    });
    HBox hb = new HBox(addValue, addButton);
    hb.setSpacing(3);
    VBox vbox = new VBox(label, table, hb);
    vbox.setSpacing(5);
    vbox.setPadding(new Insets(10, 0, 0, 10));
    mainPane.getChildren().add(vbox);
    consumers.add(l -> {
        if (!s.isEmpty())
            l.put(fieldName, s);
        else {
            this.encounterdIssue = true;
            issues.add("in " + fieldName + " must contain at least one String");
        }
    });
}
Also used : Group(javafx.scene.Group) ToggleGroup(javafx.scene.control.ToggleGroup) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) Label(javafx.scene.control.Label) TableColumn(javafx.scene.control.TableColumn) Button(javafx.scene.control.Button) RadioButton(javafx.scene.control.RadioButton) TextField(javafx.scene.control.TextField) VBox(javafx.scene.layout.VBox) TableView(javafx.scene.control.TableView)

Example 20 with ReadOnlyStringWrapper

use of javafx.beans.property.ReadOnlyStringWrapper in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketHex method buildPacketView.

/**
 * Build packet view
 *
 * @param packet
 * @return
 */
private VBox buildPacketView() {
    VBox insidePane = new VBox();
    TreeTableColumn<HexData, String> c0 = new TreeTableColumn<>("offst");
    c0.setCellValueFactory((TreeTableColumn.CellDataFeatures<HexData, String> param) -> new ReadOnlyStringWrapper(param.getValue().getValue().getOffset()));
    c0.setSortable(false);
    c0.setPrefWidth(120);
    TreeTableColumn<HexData, String> c1 = new TreeTableColumn<>("Hex");
    c1.setCellValueFactory((TreeTableColumn.CellDataFeatures<HexData, String> param) -> new ReadOnlyStringWrapper(param.getValue().getValue().getHex()));
    c1.setSortable(false);
    c1.setPrefWidth(375);
    c1.setCellFactory(new TextFieldCellFactory());
    TreeTableColumn<HexData, String> c2 = new TreeTableColumn<>("Payload");
    c2.setCellValueFactory((TreeTableColumn.CellDataFeatures<HexData, String> param) -> new ReadOnlyStringWrapper(param.getValue().getValue().getPayLoad()));
    c2.setSortable(false);
    c2.setPrefWidth(130);
    hexTable = new TreeTableView<>();
    hexTable.getStyleClass().add("treeTable");
    hexTable.getColumns().addAll(c0, c1, c2);
    hexTable.setPrefSize(630, 510);
    insidePane.getChildren().add(hexTable);
    return insidePane;
}
Also used : TreeTableColumn(javafx.scene.control.TreeTableColumn) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) VBox(javafx.scene.layout.VBox)

Aggregations

ReadOnlyStringWrapper (javafx.beans.property.ReadOnlyStringWrapper)20 TableColumn (javafx.scene.control.TableColumn)7 TableView (javafx.scene.control.TableView)5 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)4 ObservableList (javafx.collections.ObservableList)3 Tab (javafx.scene.control.Tab)3 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 FXCollections (javafx.collections.FXCollections)2 ActionEvent (javafx.event.ActionEvent)2 FXML (javafx.fxml.FXML)2 Pos (javafx.geometry.Pos)2 Button (javafx.scene.control.Button)2 TreeItem (javafx.scene.control.TreeItem)2 TreeTableColumn (javafx.scene.control.TreeTableColumn)2 CellDataFeatures (javafx.scene.control.TreeTableColumn.CellDataFeatures)2 VBox (javafx.scene.layout.VBox)2 DiffEntry (com.insightfullogic.honest_profiler.core.aggregation.result.diff.DiffEntry)1 GuiController (il.ac.technion.cs.smarthouse.gui_controller.GuiController)1 GenericSensor (il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor)1 SensorsSimulator (il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator)1