Search in sources :

Example 46 with ObservableValue

use of javafx.beans.value.ObservableValue in project Gargoyle by callakrsos.

the class TextSameLineDiffAppController method initialize.

@FXML
public void initialize() {
    /* initControls */
    ivReviced = new ImageView();
    ivpReviced = new ImageViewPane(ivReviced);
    ivpReviced.setPrefWidth(200);
    ivpReviced.setPrefHeight(150);
    ivOrigin = new ImageView();
    ivpOrigin = new ImageViewPane(ivOrigin);
    ivpOrigin.setPrefWidth(200);
    ivpOrigin.setPrefHeight(150);
    gpSnap.add(ivpReviced, 0, 0);
    gpSnap.add(ivpOrigin, 1, 0);
    lvOrinal.setCellFactory(param -> new DefaultTextFieldListCell(ORIGINAL));
    lvRevice.setCellFactory(param -> new DefaultTextFieldListCell(REVICED));
    fileCompareResultProperty.addListener((oba, oldresult, newresult) -> {
        if (newresult == null)
            return;
        List<ChunkWrapper> wrapperedOrigin = extractedWrapperedChunk(DeltaType.ORIGINAL, newresult);
        List<ChunkWrapper> wrapperedReviced = extractedWrapperedChunk(DeltaType.REVICED, newresult);
        lvOrinal.getItems().addAll(wrapperedOrigin);
        lvRevice.getItems().addAll(wrapperedReviced);
        tvChgHis.getItems().addAll(wrapperedOrigin.stream().filter(w -> w.getDelta() != null).collect(Collectors.toList()));
    });
    lvRevice.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            int movePosition = -1;
            ChunkWrapper selectedItem = lvRevice.getSelectionModel().getSelectedItem();
            Delta delta = selectedItem.getDelta();
            if (delta != null && delta.getOriginal() != null) {
                movePosition = selectedItem.getPosition();
                lvOrinal.scrollTo(movePosition - 1);
                lvOrinal.getSelectionModel().select(movePosition);
            }
        }
    });
    lvOrinal.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            int movePosition = -1;
            ChunkWrapper selectedItem = lvOrinal.getSelectionModel().getSelectedItem();
            Delta delta = selectedItem.getDelta();
            if (delta != null && delta.getRevised() != null) {
                movePosition = delta.getRevised().getPosition();
                lvRevice.scrollTo(movePosition - 1);
                lvRevice.getSelectionModel().select(movePosition);
            }
        }
    });
    lvOrinal.addEventFilter(ScrollEvent.SCROLL, event -> {
        snappOriginShot();
    });
    lvRevice.addEventFilter(ScrollEvent.SCROLL, event -> {
        snappReviceShot();
    });
    btnCompare.setOnMouseClicked(event -> {
        String ori = txtOrigin.getText();
        String rev = txtRevice.getText();
        if (!(ori.isEmpty() && rev.isEmpty())) {
            clear();
            try {
                this.compare.setOriginal(ori);
                this.compare.setRevised(rev);
                CompareResult chunkResult = this.compare.getChunkResult();
                this.fileCompareResultProperty.set(chunkResult);
                snappOriginShot();
                snappReviceShot();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    colStatus.setCellValueFactory(new Callback<CellDataFeatures<ChunkWrapper, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<ChunkWrapper, String> param) {
            TYPE type = param.getValue().getType();
            StringProperty prop = new SimpleStringProperty();
            if (type != null)
                prop.set(type.name());
            return prop;
        }
    });
    colPosition.setCellValueFactory(param -> new SimpleIntegerProperty(new Integer(param.getValue().getPosition() + 1)));
    colRevice.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getRevised();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
    colOrigin.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getOriginal();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
}
Also used : CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Chunk(difflib.Chunk) CompareResult(com.kyj.fx.voeditor.visual.diff.CompareResult) IOException(java.io.IOException) Delta(difflib.Delta) ImageView(javafx.scene.image.ImageView) TYPE(difflib.Delta.TYPE) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) FXML(javafx.fxml.FXML)

Example 47 with ObservableValue

use of javafx.beans.value.ObservableValue in project Gargoyle by callakrsos.

the class HtmlBaseDiffAppController method initialize.

@FXML
public void initialize() {
    /* initControls */
    ivReviced = new ImageView();
    ivpReviced = new ImageViewPane(ivReviced);
    ivpReviced.setPrefWidth(200);
    ivpReviced.setPrefHeight(150);
    ivOrigin = new ImageView();
    ivpOrigin = new ImageViewPane(ivOrigin);
    ivpOrigin.setPrefWidth(200);
    ivpOrigin.setPrefHeight(150);
    gpSnap.add(ivpReviced, 0, 0);
    gpSnap.add(ivpOrigin, 1, 0);
    // lvOrinal.setCellFactory(param -> new
    // DefaultTextFieldListCell(ORIGINAL));
    // lvRevice.setCellFactory(param -> new
    // DefaultTextFieldListCell(REVICED));
    fileCompareResultProperty.addListener((oba, oldresult, newresult) -> {
        if (newresult == null)
            return;
    // List<ChunkWrapper> wrapperedOrigin =
    // extractedWrapperedChunk(DeltaType.ORIGINAL, newresult);
    // List<ChunkWrapper> wrapperedReviced =
    // extractedWrapperedChunk(DeltaType.REVICED, newresult);
    // lvOrinal.getItems().addAll(wrapperedOrigin);
    // lvRevice.getItems().addAll(wrapperedReviced);
    // tvChgHis.getItems().addAll(wrapperedOrigin.stream().filter(w
    // -> w.getDelta() != null).collect(Collectors.toList()));
    });
    // lvRevice.setOnMouseClicked(event -> {
    // if (event.getClickCount() == 2) {
    // int movePosition = -1;
    // ChunkWrapper selectedItem =
    // lvRevice.getSelectionModel().getSelectedItem();
    // Delta delta = selectedItem.getDelta();
    // if (delta != null && delta.getOriginal() != null) {
    // movePosition = selectedItem.getPosition();
    // lvOrinal.scrollTo(movePosition - 1);
    // lvOrinal.getSelectionModel().select(movePosition);
    // }
    //
    // }
    // });
    // lvOrinal.setOnMouseClicked(event -> {
    // if (event.getClickCount() == 2) {
    // int movePosition = -1;
    // ChunkWrapper selectedItem =
    // lvOrinal.getSelectionModel().getSelectedItem();
    // Delta delta = selectedItem.getDelta();
    // if (delta != null && delta.getRevised() != null) {
    // movePosition = delta.getRevised().getPosition();
    // lvRevice.scrollTo(movePosition - 1);
    // lvRevice.getSelectionModel().select(movePosition);
    // }
    // }
    //
    // });
    // lvOrinal.addEventFilter(ScrollEvent.SCROLL, event -> {
    // snappOriginShot();
    // });
    //
    // lvRevice.addEventFilter(ScrollEvent.SCROLL, event -> {
    // snappReviceShot();
    // });
    btnCompare.setOnMouseClicked(event -> {
        String ori = txtOrigin.getText();
        String rev = txtRevice.getText();
        if (!(ori.isEmpty() && rev.isEmpty())) {
            clear();
            try {
                this.compare.setOriginal(ori);
                this.compare.setRevised(rev);
                CompareResult chunkResult = this.compare.getChunkResult();
                this.fileCompareResultProperty.set(chunkResult);
                snappOriginShot();
                snappReviceShot();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    colStatus.setCellValueFactory(new Callback<CellDataFeatures<ChunkWrapper, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<ChunkWrapper, String> param) {
            TYPE type = param.getValue().getType();
            StringProperty prop = new SimpleStringProperty();
            if (type != null)
                prop.set(type.name());
            return prop;
        }
    });
    colPosition.setCellValueFactory(param -> new SimpleIntegerProperty(new Integer(param.getValue().getPosition() + 1)));
    colRevice.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getRevised();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
    colOrigin.setCellValueFactory(param -> {
        Delta delta = param.getValue().getDelta();
        SimpleStringProperty prop = new SimpleStringProperty();
        if (delta != null) {
            Chunk c = delta.getOriginal();
            prop.setValue(c.getLines().toString());
        }
        return prop;
    });
}
Also used : CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) ObservableValue(javafx.beans.value.ObservableValue) ChunkWrapper(com.kyj.fx.voeditor.visual.diff.ChunkWrapper) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Chunk(difflib.Chunk) CompareResult(com.kyj.fx.voeditor.visual.diff.CompareResult) IOException(java.io.IOException) Delta(difflib.Delta) ImageView(javafx.scene.image.ImageView) TYPE(difflib.Delta.TYPE) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) FXML(javafx.fxml.FXML)

Example 48 with ObservableValue

use of javafx.beans.value.ObservableValue in project uPMT by coco35700.

the class TypeTreeViewControllerClass method rename.

@Override
public void rename() {
    super.rename();
    ChangeListener<Boolean> listener = new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
            if (!newPropertyValue) {
                if (type.getType().isCategory()) {
                    String oldName = new String(type.getType().getName());
                    if (!oldName.equals(textField.getText())) {
                        boolean hasName = false;
                        // System.out.println("Parent: "+type.getParent().getName());
                        for (Type classe : type.getParent().getTypes()) {
                            // System.out.println("Classes: "+classe.getName());
                            if (classe.getName().equals(textField.getText())) {
                                hasName = true;
                                break;
                            }
                        }
                        if (!hasName) {
                            RenameClassSchemeCommand cmd = new RenameClassSchemeCommand(type.getClassNameController(), oldName, textField.getText(), main);
                            cmd.execute();
                            UndoCollector.INSTANCE.add(cmd);
                        } else {
                            Alert alert = new Alert(AlertType.INFORMATION);
                            alert.setTitle(main._langBundle.getString("invalid_name"));
                            alert.setHeaderText(null);
                            alert.setContentText(main._langBundle.getString("class_name_invalid"));
                            alert.show();
                        }
                    }
                }
                typePane.setLeft(nomType);
                rename.setDisable(false);
                textField.focusedProperty().removeListener(this);
            }
        }
    };
    textField.setOnKeyPressed(new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.ENTER) {
                if (type.getType().isProperty()) {
                    textField.setText(textField.getText());
                }
                typePane.setLeft(nomType);
                rename.setDisable(false);
            }
            if (event.getCode() == KeyCode.ESCAPE) {
                typePane.setLeft(nomType);
                rename.setDisable(true);
            }
        }
    });
    textField.focusedProperty().addListener(listener);
    typePane.setLeft(textField);
    Platform.runLater(() -> textField.requestFocus());
    Platform.runLater(() -> textField.selectAll());
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) Type(model.Type) AlertType(javafx.scene.control.Alert.AlertType) ObservableValue(javafx.beans.value.ObservableValue) RenameClassSchemeCommand(controller.command.RenameClassSchemeCommand) ChangeListener(javafx.beans.value.ChangeListener) Alert(javafx.scene.control.Alert)

Example 49 with ObservableValue

use of javafx.beans.value.ObservableValue in project Board-Instrumentation-Framework by intel.

the class Marvin method testAppSize.

/*
    private void LoadApplication(Stage stage)
    {
        stage.setIconified(true);
        _Config = new ConfigurationReader();
        if (null == _Config)
        {
            return;
        }

        Configuration config = _Config.ReadStartupInfo(ConfigFilename);
        if (null == config)
        {
            return;
        }
        _objTabPane = new TabPane();
        _objTabPane.setSide(config.getSide());

        GridPane sceneGrid = new GridPane();

        GridPane.setHalignment(_Config.getConfiguration().getMenuBar(), HPos.LEFT);
        GridPane.setValignment(_Config.getConfiguration().getMenuBar(), VPos.TOP);

        sceneGrid.add(_Config.getConfiguration().getMenuBar(), 0, 0);
        sceneGrid.add(_objTabPane, 0, 1);

        Scene scene = null;
        Rectangle2D visualBounds = _Config.getConfiguration().getPrimaryScreen().getVisualBounds();
        int appWidth = (int) visualBounds.getWidth();
        int appHeight = (int) visualBounds.getHeight();

        if (config.getWidth() > 0)
        {
            appWidth = config.getWidth();
        }
        else
        {
            config.setWidth(appWidth);
        }
        if (config.getHeight() > 0)
        {
            appHeight = config.getHeight();
        }
        else
        {
            config.setHeight(appHeight);
        }

        scene = new Scene(sceneGrid);
        SetAppStyle(scene.getStylesheets());
        stage.setScene(scene);
        stage.setIconified(true);

        stage.setX(_Config.getConfiguration().getPrimaryScreen().getVisualBounds().getMinX());
        stage.setY(_Config.getConfiguration().getPrimaryScreen().getVisualBounds().getMinY());

        stage.setMaximized(true);

        stage.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>()
                      {
                          @Override
                          public void handle(WindowEvent window)
                          {
                              FinishLoad(stage);
                          }
                      });

        while (false && !_SizeCheckWindowShowing)
        {
            try
            {
                Thread.sleep(100);
            }
            catch (InterruptedException ex)
            {
                Logger.getLogger(Marvin.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        FinishLoad(stage);

    }
     */
// / pop up quick simple tab,menu and style it, then grab the size of the window
// / so we know the canvas dimenstions
private void testAppSize(Stage stage) {
    final GridPane stagePane = new GridPane();
    final GridPane canvasPane = new GridPane();
    canvasPane.setAlignment(Pos.TOP_LEFT);
    _Config = new ConfigurationReader();
    final Configuration basicConfig = _Config.ReadStartupInfo(ConfigFilename);
    stage.setX(basicConfig.getPrimaryScreen().getVisualBounds().getMinX());
    stage.setY(basicConfig.getPrimaryScreen().getVisualBounds().getMinY());
    TabPane tabPane = new TabPane();
    Tab objTab = new Tab();
    final Side tabSide = basicConfig.getSide();
    if (tabSide == Side.TOP || tabSide == Side.BOTTOM) {
        tabPane.setSide(Side.TOP);
    } else {
        tabPane.setSide(Side.LEFT);
    }
    objTab.setText("");
    tabPane.getTabs().add(objTab);
    stagePane.add(tabPane, 0, 1);
    MenuBar objMenuBar = new MenuBar();
    if (basicConfig.getShowMenuBar()) {
        Menu objMenu = new Menu("About");
        MenuItem objItem = new MenuItem("Dummy");
        objMenu.getItems().add(objItem);
        objMenuBar.getMenus().add(objMenu);
        stagePane.add(objMenuBar, 0, 0);
    }
    if (basicConfig.getEnableScrollBars()) {
        ScrollPane testScrollPane = new ScrollPane();
        testScrollPane.setPannable(true);
        testScrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        testScrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        testScrollPane.setContent(canvasPane);
        objTab.setContent(testScrollPane);
    } else {
        objTab.setContent(canvasPane);
    }
    stage.setTitle(basicConfig.getAppTitle());
    Scene scene = new Scene(stagePane);
    stage.setScene(scene);
    SetAppStyle(scene.getStylesheets());
    stage.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent window) {
            scene.heightProperty().addListener(new ChangeListener<Number>() {

                @Override
                public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
                    scene.heightProperty().removeListener(this);
                    Point2D canvasInScene = canvasPane.localToScene(0.0, 0.0);
                    int cvHeight;
                    int cvWidth;
                    if (tabSide == Side.TOP || tabSide == Side.BOTTOM) {
                        cvHeight = (int) (scene.getHeight() - canvasInScene.getY());
                        cvWidth = (int) scene.getWidth();
                    } else {
                        cvHeight = (int) (scene.getHeight() - canvasInScene.getY());
                        cvWidth = (int) (scene.getWidth() - canvasInScene.getX());
                    }
                    basicConfig.setCanvasWidth(cvWidth);
                    basicConfig.setCanvasHeight(cvHeight);
                    stage.setIconified(true);
                    Platform.runLater(new Runnable() {

                        @Override
                        public void run() {
                            FinishLoad(stage);
                        }
                    });
                }
            });
        }
    });
    stage.show();
    if (basicConfig.getWidth() > 0) {
        stage.setWidth(basicConfig.getWidth());
        stage.setHeight(basicConfig.getHeight());
    } else {
        stage.setMaximized(true);
    }
}
Also used : TabPane(javafx.scene.control.TabPane) GridPane(javafx.scene.layout.GridPane) Configuration(kutch.biff.marvin.configuration.Configuration) ObservableValue(javafx.beans.value.ObservableValue) MenuBar(javafx.scene.control.MenuBar) MenuItem(javafx.scene.control.MenuItem) Scene(javafx.scene.Scene) Side(javafx.geometry.Side) Tab(javafx.scene.control.Tab) Point2D(javafx.geometry.Point2D) ScrollPane(javafx.scene.control.ScrollPane) WindowEvent(javafx.stage.WindowEvent) ChangeListener(javafx.beans.value.ChangeListener) Menu(javafx.scene.control.Menu) ConfigurationReader(kutch.biff.marvin.configuration.ConfigurationReader)

Example 50 with ObservableValue

use of javafx.beans.value.ObservableValue in project Board-Instrumentation-Framework by intel.

the class DoubleBarGaugeWidget method Create.

public boolean Create(GridPane pane, DataManager dataMgr) {
    SetParent(pane);
    if (false == SetupGauge()) {
        return false;
    }
    _Gauge.setInnerValue(_InitialValue);
    _Gauge.setOuterValue(_InitialValue);
    ConfigureAlignment();
    SetupPeekaboo(dataMgr);
    ConfigureDimentions();
    pane.add(_Gauge, getColumn(), getRow(), getColumnSpan(), getRowSpan());
    dataMgr.AddListener(getMinionID(), getNamespace(), new ChangeListener() {

        @Override
        public void changed(ObservableValue o, Object oldVal, Object newVal) {
            if (IsPaused()) {
                return;
            }
            double newDialValue = 0;
            String strVal = newVal.toString();
            try {
                newDialValue = Double.parseDouble(strVal);
            } catch (NumberFormatException ex) {
                LOGGER.severe("Invalid data for BarGauge received: " + strVal);
                return;
            }
            _Gauge.setInnerValue(newDialValue);
        }
    });
    if (null == _OuterID || null == _OuterNamespace) {
        LOGGER.severe("No Outter Data source defined for BarGauge");
        return false;
    }
    dataMgr.AddListener(_OuterID, _OuterNamespace, new ChangeListener() {

        @Override
        public void changed(ObservableValue o, Object oldVal, Object newVal) {
            if (IsPaused()) {
                return;
            }
            double newDialValue = 0;
            String strVal = newVal.toString();
            try {
                newDialValue = Double.parseDouble(strVal);
            } catch (NumberFormatException ex) {
                LOGGER.severe("Invalid data for BarGauge received: " + strVal);
                return;
            }
            _Gauge.setOuterValue(newDialValue);
        }
    });
    return true;
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener)

Aggregations

ObservableValue (javafx.beans.value.ObservableValue)85 ChangeListener (javafx.beans.value.ChangeListener)53 FXML (javafx.fxml.FXML)13 Scene (javafx.scene.Scene)13 ImageView (javafx.scene.image.ImageView)13 KeyEvent (javafx.scene.input.KeyEvent)11 ArrayList (java.util.ArrayList)10 Label (javafx.scene.control.Label)10 TableColumn (javafx.scene.control.TableColumn)10 TableView (javafx.scene.control.TableView)10 ActionEvent (javafx.event.ActionEvent)9 MouseEvent (javafx.scene.input.MouseEvent)9 TextField (javafx.scene.control.TextField)8 Color (javafx.scene.paint.Color)8 ObservableList (javafx.collections.ObservableList)7 MenuItem (javafx.scene.control.MenuItem)7 CellDataFeatures (javafx.scene.control.TableColumn.CellDataFeatures)7 List (java.util.List)6 Set (java.util.Set)6 Platform (javafx.application.Platform)6