Example usage for javafx.scene.text Text getText

List of usage examples for javafx.scene.text Text getText

Introduction

In this page you can find the example usage for javafx.scene.text Text getText.

Prototype

public final String getText() 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Hello Drag And Drop");

    Group root = new Group();
    Scene scene = new Scene(root, 400, 200);
    scene.setFill(Color.LIGHTGREEN);

    final Text source = new Text(50, 100, "DRAG ME");
    source.setScaleX(2.0);//w  w w .j  av  a  2s .com
    source.setScaleY(2.0);

    final Text target = new Text(250, 100, "DROP HERE");
    target.setScaleX(2.0);
    target.setScaleY(2.0);

    source.setOnDragDetected(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent event) {
            /* drag was detected, start drag-and-drop gesture*/
            System.out.println("onDragDetected");

            /* allow any transfer mode */
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);

            /* put a string on dragboard */
            ClipboardContent content = new ClipboardContent();
            content.putString(source.getText());
            db.setContent(content);

            event.consume();
        }
    });

    target.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data is dragged over the target */
            System.out.println("onDragOver");

            /* accept it only if it is  not dragged from the same node 
             * and if it has a string data */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            }

            event.consume();
        }
    });

    target.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            System.out.println("onDragEntered");
            /* show to the user that it is an actual gesture target */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                target.setFill(Color.GREEN);
            }

            event.consume();
        }
    });

    target.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            target.setFill(Color.BLACK);

            event.consume();
        }
    });

    target.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data dropped */
            System.out.println("onDragDropped");
            /* if there is a string data on dragboard, read it and use it */
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasString()) {
                target.setText(db.getString());
                success = true;
            }
            /* let the source know whether the string was successfully 
             * transferred and used */
            event.setDropCompleted(success);

            event.consume();
        }
    });

    source.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture ended */
            System.out.println("onDragDone");
            /* if the data was successfully moved, clear it */
            if (event.getTransferMode() == TransferMode.MOVE) {
                source.setText("");
            }

            event.consume();
        }
    });

    root.getChildren().add(source);
    root.getChildren().add(target);
    stage.setScene(scene);
    stage.show();
}

From source file:com.virus.removal.javafxapplication.FXMLDocumentController.java

/**
 * //from w ww . ja  v  a 2 s  . co  m
 */
private void processHistoryData() {

    if (handler.getVirusScanStatus() == VirusScanStatus.VIRUS_JOB_COMPLETED
            || handler.getVirusScanStatus() == VirusScanStatus.VIRUS_SCAN_STOPPED) {

        textAreaForHistory.setStyle("-fx-text-fill: #00AEEF;");

        /* Enable the button */
        if (clearHistory.isDisabled()
                && (textAreaForHistory.getText().contains(HISTORY_UNAVAILABLE)
                        || textAreaForHistory.getText().contains(HISTORY_UNAVAILABLE_IN_SPANISH)
                        || textAreaForHistory.getText().contains(HISTORY_UNAVAILABLE_IN_FRENCH)
                        || textAreaForHistory.getText().contains(HISTORY_UNAVAILABLE_IN_PORTUGUESE))
                && virusScanHistoryList.size() > 0) {
            clearHistory.setDisable(false);
            textAreaForHistory.clear();
        }

        textAreaForHistory.setFont(Font.font("Verdana", FontWeight.EXTRA_BOLD, 11));

        for (final VirusScanHistory virusScanHistory : virusScanHistoryList) {

            /* Scanned Date */
            final Text scannedText = new Text("Scanned: " + virusScanHistory.getScanDate());
            scannedText.setLayoutX(50.0);
            scannedText.setLayoutY(150.0);

            if (virusScanHistoryCount != 0) {
                textAreaForHistory.appendText("\n\n\n\n");
            }

            textAreaForHistory.appendText(scannedText.getText());
            textAreaForHistory.appendText("                                                         ");

            /* Status */
            final String jobStatus = virusScanHistory.getScanStatus();
            final Text jobStatusText = new Text(jobStatus);

            final Text statusText = new Text("Status: " + jobStatusText.getText());
            statusText.setLayoutX(450.0);
            statusText.setLayoutY(150.0);

            textAreaForHistory.appendText(statusText.getText());

            textAreaForHistory.appendText("\n\n");

            /* PC Name */
            final Text pcNameText = new Text("PC Name: " + virusScanHistory.getPcName());
            pcNameText.setLayoutX(50.0);
            pcNameText.setLayoutY(175.0);

            textAreaForHistory.appendText(pcNameText.getText());
            textAreaForHistory.appendText(
                    "                                                                                  ");

            /* Threats Found */
            final Text threatsFoundText = new Text("Threats Found: " + virusScanHistory.getThreatsFound());
            threatsFoundText.setLayoutX(450.0);
            threatsFoundText.setLayoutY(175.0);

            textAreaForHistory.appendText(threatsFoundText.getText());
            virusScanHistoryCount++;

        }
    } else {

        //         if (handler.getVirusScanStatus() == null || handler.getVirusScanStatus() == VirusScanStatus.VIRUS_SCAN_STARTED) {
        //
        //            if (textAreaForHistory.getText() == null || textAreaForHistory.getText().isEmpty()) {
        //               textAreaForHistory.appendText("\n\n\n\n\n\n\n\n\n\n\n                                                  ");
        //
        //               if (StringUtils.equals(drop.getText(), "English")) {
        //                  textAreaForHistory.appendText(HISTORY_UNAVAILABLE);
        //                  textForLastScanInHistory.setText("Last Scan: Please perform a scan.");
        //               } else if (StringUtils.equals(drop.getText(), "Spanish")) {
        //                  textAreaForHistory.appendText(HISTORY_UNAVAILABLE_IN_SPANISH);
        //                  textForLastScanInHistory.setText("ltimo escaneo: Por favor, haga un escaneo.");
        //               } else if (StringUtils.equals(drop.getText(), "French")) {
        //                  textAreaForHistory.appendText(HISTORY_UNAVAILABLE_IN_FRENCH);
        //                  textForLastScanInHistory.setText("Dernier scan: Veuillez effectuer un scan.");
        //               } else if (StringUtils.equals(drop.getText(), "Portuguese")) {
        //                  textAreaForHistory.appendText(HISTORY_UNAVAILABLE_IN_PORTUGUESE);
        //                  textForLastScanInHistory.setText("ltima anlise: Por-favor faa uma anlise.");
        //               } 
        //               
        //               textAreaForHistory.setFont(Font.font("Verdana", FontWeight.EXTRA_BOLD, 12));
        //               
        //               /* First time, button is disabled */
        //               clearHistory.setDisable(true);
        //               
        //            }
        //         }
    }

    virusScanHistoryList.clear();
}

From source file:org.pdfsam.ui.selection.multiple.SelectionTableTest.java

@Test
public void iconsAreShown() throws Exception {
    PdfDocumentDescriptor firstItem = populate();
    FXTestUtils.invokeAndWait(() -> firstItem.moveStatusTo(PdfDescriptorLoadingStatus.REQUESTED), 2);
    Text icon = find(".glyph-icon");
    assertEquals(PdfDescriptorLoadingStatus.REQUESTED.getIcon().characterToString(), icon.getText());
    FXTestUtils.invokeAndWait(() -> firstItem.moveStatusTo(PdfDescriptorLoadingStatus.LOADING), 2);
    icon = find(".glyph-icon");
    assertEquals(PdfDescriptorLoadingStatus.LOADING.getIcon().characterToString(), icon.getText());
}

From source file:org.pdfsam.ui.selection.multiple.SelectionTableTest.java

@Test
public void logEventOnClick() throws Exception {
    PdfDocumentDescriptor firstItem = populate();
    FXTestUtils.invokeAndWait(() -> firstItem.moveStatusTo(PdfDescriptorLoadingStatus.REQUESTED), 2);
    Text icon = find(".glyph-icon");
    assertEquals(PdfDescriptorLoadingStatus.REQUESTED.getIcon().characterToString(), icon.getText());
    FXTestUtils.invokeAndWait(() -> firstItem.moveStatusTo(PdfDescriptorLoadingStatus.LOADING), 2);
    icon = find(".glyph-icon");
    assertEquals(PdfDescriptorLoadingStatus.LOADING.getIcon().characterToString(), icon.getText());
}