Example usage for javafx.scene.shape Rectangle getX

List of usage examples for javafx.scene.shape Rectangle getX

Introduction

In this page you can find the example usage for javafx.scene.shape Rectangle getX.

Prototype

public final double getX() 

Source Link

Usage

From source file:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iNumZone numero de la zone// w  ww.j  av a2s. c  om
 * @param rect rectangle concern
 * @return ancres rectangle
 */
private static ObservableList<AncreForme> olCreeAncresPourRectangle(int iNumZone, Rectangle rect) {
    ObservableList<AncreForme> olAnchors = FXCollections.observableArrayList();

    DoubleProperty xProperty1 = new SimpleDoubleProperty(rect.getX());
    DoubleProperty yProperty1 = new SimpleDoubleProperty(rect.getY());
    DoubleProperty xProperty2 = new SimpleDoubleProperty(rect.getWidth() + rect.getX());
    DoubleProperty yProperty2 = new SimpleDoubleProperty(rect.getHeight() + rect.getY());
    olAnchors.add(new AncreForme(Color.GOLD, xProperty1, yProperty1));
    AncreForme ancrePoint2 = new AncreForme(Color.BLUEVIOLET, xProperty2, yProperty2);
    olAnchors.add(ancrePoint2);
    xProperty1.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> {
        double dX = -rect.getX() + (double) x;
        rect.setX((double) x);
        ancrePoint2.setCenterX(ancrePoint2.getCenterX() + dX);
        String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + ","
                + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + ","
                + Math.round((rect.getY() + rect.getHeight()) * 10) / 10;
        zones[iNumZone].setStrCoordonneesZone(chaine);
    });

    yProperty1.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> {
        double dY = -rect.getY() + (double) y;
        rect.setY((double) y);
        ancrePoint2.setCenterY(ancrePoint2.getCenterY() + dY);
        String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + ","
                + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + ","
                + Math.round((rect.getY() + rect.getHeight()) * 10) / 10;
        zones[iNumZone].setStrCoordonneesZone(chaine);
    });
    xProperty2.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> {
        rect.setWidth((double) x - rect.getX());
        String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + ","
                + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + ","
                + Math.round((rect.getY() + rect.getHeight()) * 10) / 10;
        zones[iNumZone].setStrCoordonneesZone(chaine);
    });

    yProperty2.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> {
        rect.setHeight((double) y - rect.getY());
        String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + ","
                + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + ","
                + Math.round((rect.getY() + rect.getHeight()) * 10) / 10;
        zones[iNumZone].setStrCoordonneesZone(chaine);
    });

    return olAnchors;
}

From source file:org.nmrfx.processor.gui.spectra.PeakListAttributes.java

private boolean pick2DPeak(Peak peak, double x, double y) {
    double[] ctr = { 0.0, 0.0 };
    double[] bou = { 0.0, 0.0 };
    int[] peakDim = getPeakDim();

    bou[0] = peak.peakDim[peakDim[0]].getBoundsValue();
    bou[1] = peak.peakDim[peakDim[1]].getBoundsValue();
    ctr[0] = peak.peakDim[peakDim[0]].getChemShiftValue();
    ctr[1] = peak.peakDim[peakDim[1]].getChemShiftValue();
    Rectangle box = getBox(ctr, bou);
    boolean result = box.contains(x, y);
    //        System.out.println(box.toString() + " " + x + " " + y + " " + result);

    if (!result) {
        int growWidth = 0;
        int growHeight = 0;
        int width = (int) box.getWidth();
        if (width < minHitSize) {
            growWidth = minHitSize - width;
        }/*w w  w . jav a 2 s. co m*/
        int height = (int) box.getHeight();
        if (height < minHitSize) {
            growHeight = minHitSize - height;
        }
        // fixme why are we doing this (from old code) and should it grow symmetrically
        // gues we try to hit small rect for selectivity, then expand if no hit
        if ((growWidth > 0) || (growHeight > 0)) {
            box.setWidth(growWidth);
            box.setX(box.getX() - growWidth / 2);
            box.setHeight(growHeight);
            box.setY(box.getY() - growHeight / 2);

            result = box.contains(x, y);
        }
    }
    return result;
}

From source file:snpviewer.SnpViewer.java

private void zoomRegion(Rectangle rectangle) {
    try {//w ww . j a  v  a 2 s.co  m
        FXMLLoader loader = new FXMLLoader(getClass().getResource("ZoomRegionView.fxml"));
        ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
        String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                .getSelectedIndex()];
        double startCoordinate = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                * rectangle.getX();
        double selectionWidth = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                * rectangle.getWidth();
        if (rectangle.getX() == 0) {
            startCoordinate = 1;
        }

        Pane page = (Pane) loader.load();
        Scene scene = new Scene(page);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.setTitle("chr" + currentChrom + ":" + nf.format(startCoordinate) + "-"
                + nf.format(startCoordinate + selectionWidth));
        scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm());
        String subPath = "zoom";
        stage.initModality(Modality.NONE);
        stage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
        stage.show();
        ZoomRegionViewController zoomController = (ZoomRegionViewController) loader.getController();
        ArrayList<SnpFile> bothFiles = new ArrayList<>();
        bothFiles.addAll(affFiles);
        bothFiles.addAll(unFiles);
        ArrayList<Pane> zoomPanes = zoomController.setPanes(bothFiles);
        zoomController.setParentController(this);
        zoomController.setLoadingRectangle(rectangle);
        zoomController.setRegionLength(selectionWidth);
        zoomController.setRegionStart(startCoordinate);
        zoomController.setChromosome(currentChrom);
        SplitPane zoomSplit = zoomController.getSplitPane();
        Iterator<SnpFile> sIter = bothFiles.iterator();
        Iterator<Pane> pIter = zoomPanes.iterator();
        if (!sIter.hasNext() || !pIter.hasNext()) {
            return;
        }
        SnpFile firstFile = sIter.next();
        Pane firstPane = pIter.next();
        drawCoordinatesWithIterator(firstFile, firstPane, subPath, sIter, pIter, 1, bothFiles.size(),
                currentChrom, startCoordinate, startCoordinate + selectionWidth, true, zoomSplit);
        zoomController.tidyPanes();

    } catch (ChromosomeLength.ChromosomeLengthException | IOException ex) {
        Dialogs.showErrorDialog(null, "Please see details for stack trace.", "Error displaying zoomed region",
                "SnpViewer", ex);
    }
}

From source file:snpviewer.SnpViewer.java

private void displayFlankingSnpIDs(final Rectangle rectangle) {
    /* get coordinates of selection and report back
     * flanking snp ids and coordinates//from w  w  w  . j  a v a  2  s . c  o m
     */
    try {
        if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1
                && rectangle.getWidth() > 0) {

            //work out coordinates based on chromosome and pane sizes
            ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
            String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                    .getSelectedIndex()];
            double startCoordinate = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                    * rectangle.getX();
            double selectionWidth = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                    * rectangle.getWidth();
            if (rectangle.getX() == 0) {
                startCoordinate = 1;
            }
            displayFlankingSnpIDs(currentChrom, startCoordinate, startCoordinate + selectionWidth);
        }
    } catch (Exception ex) {
        Dialogs.showErrorDialog(null, "Couldn't display flanking SNP IDs - " + "build error?",
                "Error Displaying flanking SNPs", "SnpViewer", ex);
    }
}

From source file:snpviewer.SnpViewer.java

public void writeRegionToFile(final Rectangle rectangle) {
    try {// www .  ja  v  a 2s  .  com
        ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
        String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                .getSelectedIndex()];
        double startCoordinate = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                * rectangle.getX();
        double selectionWidth = chromLength.getLength(currentChrom) / selectionOverlayPane.getWidth()
                * rectangle.getWidth();
        if (rectangle.getX() == 0) {
            startCoordinate = 1;
        }
        writeRegionToFile(currentChrom, startCoordinate, startCoordinate + selectionWidth);
    } catch (Exception ex) {
        Dialogs.showErrorDialog(null, "Region write failed while assessing " + "region properties.",
                "Write Failed", "SNP Viewer", ex);
    }
}