Example usage for javafx.scene.paint Color GAINSBORO

List of usage examples for javafx.scene.paint Color GAINSBORO

Introduction

In this page you can find the example usage for javafx.scene.paint Color GAINSBORO.

Prototype

Color GAINSBORO

To view the source code for javafx.scene.paint Color GAINSBORO.

Click Source Link

Document

The color gainsboro with an RGB value of #DCDCDC

Usage

From source file:ui.main.MainViewController.java

private synchronized void paintReceivedMessage(Chat chat, String msg, String time) {
    //this method draws the recievied text message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override/* w w w .  j a  v  a 2 s  .c  o m*/
        protected HBox call() throws Exception {

            VBox vbox = new VBox(); //to add text

            ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image
            imageRec.setFitHeight(60);
            imageRec.setFitWidth(50);

            String strChatterName = chat.getParticipant(); //add name of the chatter with light color
            strChatterName = Character.toUpperCase(strChatterName.charAt(0))
                    + strChatterName.substring(1, strChatterName.indexOf("@"));
            Label chatterName = new Label(strChatterName);
            chatterName.setDisable(true);

            Label timeL = new Label(time);
            timeL.setDisable(true);
            timeL.setFont(new Font("Arial", 10));

            //chat message
            BubbledLabel bbl = new BubbledLabel();
            bbl.setText(msg);
            bbl.setBackground(new Background(new BackgroundFill(Color.GAINSBORO, null, null)));

            vbox.getChildren().addAll(chatterName, bbl, timeL);
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageRec, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());

    });

    if (chat.getParticipant().contains(currentChat.getParticipant())) {
        Thread t = new Thread(recievedMessages);
        //t.setDaemon(true);
        t.start();
        try {
            t.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
        }
        scrollPane.setVvalue(scrollPane.getHmax());
    }
}

From source file:ui.main.MainViewController.java

private void paintConversationMessage(Message msg) {
    //this method draws the recievied text message
    Task<HBox> recievedMessages = new Task<HBox>() {
        @Override//from w  ww  .  j  a v  a 2  s .  c om
        protected HBox call() throws Exception {

            VBox vbox = new VBox(); //to add text
            String user = msg.getFrom();
            user = user.substring(user.indexOf("/") + 1, user.length());
            ImageView imageView = new ImageView(); //image
            imageView.setFitHeight(60);
            imageView.setFitWidth(50);
            VCard vcard = new VCard();
            try {
                vcard.load(ConnectionManager.getConnectionManager().getXMPPConnection(),
                        user.concat(AppData.serviceNameAt));
                if (vcard.getAvatar() != null) {
                    BufferedImage img = ImageIO.read(new ByteArrayInputStream(vcard.getAvatar()));
                    Image image = SwingFXUtils.toFXImage(img, null);
                    imageView.setImage(image);
                } else {
                    Image defaultAvatar = new Image("resources/defaultAvatar.png", 50, 60, true, true);
                    imageView.setImage(defaultAvatar);
                }
            } catch (XMPPException e) {
                Image defaultAvatar = new Image("resources/defaultAvatar.png", 50, 60, true, true);
                imageView.setImage(defaultAvatar);
                System.out.println(e);
            }

            Label chatterName = new Label(user);
            chatterName.setDisable(true);

            //chat message
            BubbledLabel bbl = new BubbledLabel();
            bbl.setText(msg.getBody());
            bbl.setBackground(new Background(new BackgroundFill(Color.GAINSBORO, null, null)));

            vbox.getChildren().addAll(chatterName, bbl);
            vbox.setAlignment(Pos.CENTER_RIGHT);
            HBox hbox = new HBox();
            bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER);
            hbox.getChildren().addAll(imageView, vbox);
            return hbox;
        }
    };

    recievedMessages.setOnSucceeded(event -> {
        chatList.getChildren().add(recievedMessages.getValue());

    });

    Thread t = new Thread(recievedMessages);
    //t.setDaemon(true);
    t.start();
    try {
        t.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
    Task t1 = new Task() {
        @Override
        protected Object call() throws Exception {
            Thread.sleep(500);
            return new Object();
        }
    };

    t1.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax()));

    Thread thread1 = new Thread(t1);
    thread1.start();
}