001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2012 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.client.tide.javafx;
022
023 import javafx.beans.property.BooleanProperty;
024 import javafx.beans.property.ReadOnlyBooleanProperty;
025 import javafx.beans.property.ReadOnlyBooleanWrapper;
026 import javafx.beans.property.SimpleBooleanProperty;
027 import javafx.beans.value.ChangeListener;
028 import javafx.beans.value.ObservableValue;
029 import javafx.scene.Cursor;
030 import javafx.stage.Stage;
031
032 import org.granite.client.tide.server.ServerSession.Status;
033
034 /**
035 * @author William DRAI
036 */
037 public class JavaFXServerSessionStatus implements Status {
038
039 private Stage stage = null;
040
041 private BooleanProperty busy = new ReadOnlyBooleanWrapper(this, "busy", false);
042 private BooleanProperty connected = new ReadOnlyBooleanWrapper(this, "connected", false);
043 private BooleanProperty showBusyCursor = new SimpleBooleanProperty(this, "showBusyCursor", true);
044
045
046 public JavaFXServerSessionStatus() {
047 busy.addListener(new ChangeListener<Boolean>() {
048
049 private Cursor saveCursor = Cursor.DEFAULT;
050
051 @Override
052 public void changed(ObservableValue<? extends Boolean> property, Boolean oldValue, Boolean newValue) {
053 if (stage != null && stage.getScene() != null && showBusyCursor.get()) {
054 if (Boolean.FALSE.equals(oldValue)) {
055 saveCursor = stage.getScene().getCursor();
056 stage.getScene().setCursor(Cursor.WAIT);
057 }
058 else
059 stage.getScene().setCursor(saveCursor);
060 }
061 }
062 });
063 }
064
065 public void setStage(Stage stage) {
066 this.stage = stage;
067 }
068
069
070 public ReadOnlyBooleanProperty busyProperty() {
071 return busy;
072 }
073
074 public ReadOnlyBooleanProperty connectedProperty() {
075 return connected;
076 }
077
078 public BooleanProperty showBusyCursorProperty() {
079 return showBusyCursor;
080 }
081
082 @Override
083 public boolean isBusy() {
084 return busy.get();
085 }
086
087 @Override
088 public void setBusy(boolean busy) {
089 this.busy.set(busy);
090 }
091
092 @Override
093 public boolean isConnected() {
094 return connected.get();
095 }
096
097 @Override
098 public void setConnected(boolean connected) {
099 this.connected.set(connected);
100 }
101
102 @Override
103 public boolean isShowBusyCursor() {
104 return showBusyCursor.get();
105 }
106
107 @Override
108 public void setShowBusyCursor(boolean showBusyCursor) {
109 this.showBusyCursor.set(showBusyCursor);
110 }
111
112 }