| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package demo; |
| |
| import java.net.URL; |
| import java.util.ResourceBundle; |
| import javafx.animation.FadeTransition; |
| import javafx.event.ActionEvent; |
| import javafx.event.EventHandler; |
| import javafx.fxml.FXML; |
| import javafx.fxml.Initializable; |
| import javafx.scene.control.*; |
| import javafx.scene.layout.AnchorPane; |
| import javafx.util.Duration; |
| import demo.model.User; |
| |
| /** |
| * Profile Controller. |
| */ |
| public class ProfileController extends AnchorPane implements Initializable { |
| |
| @FXML |
| private TextField user; |
| @FXML |
| private TextField phone; |
| @FXML |
| private TextField email; |
| @FXML |
| private TextArea address; |
| @FXML |
| private CheckBox subscribed; |
| @FXML |
| private Hyperlink logout; |
| @FXML |
| private Button save; |
| |
| @FXML |
| private Label success; |
| |
| private Main application; |
| |
| public void setApp(Main application){ |
| this.application = application; |
| User loggedUser = application.getLoggedUser(); |
| user.setText(loggedUser.getId()); |
| email.setText(loggedUser.getEmail()); |
| phone.setText(loggedUser.getPhone()); |
| if (loggedUser.getAddress() != null) { |
| address.setText(loggedUser.getAddress()); |
| } |
| subscribed.setSelected(loggedUser.isSubscribed()); |
| success.setOpacity(0); |
| } |
| |
| @Override |
| public void initialize(URL location, ResourceBundle resources) { |
| } |
| |
| public void processLogout(ActionEvent event) { |
| if (application == null){ |
| // We are running in isolated FXML, possibly in Scene Builder. |
| // NO-OP. |
| return; |
| } |
| |
| application.userLogout(); |
| } |
| |
| public void saveProfile(ActionEvent event) { |
| if (application == null){ |
| // We are running in isolated FXML, possibly in Scene Builder. |
| // NO-OP. |
| animateMessage(); |
| return; |
| } |
| User loggedUser = application.getLoggedUser(); |
| loggedUser.setEmail(email.getText()); |
| loggedUser.setPhone(phone.getText()); |
| loggedUser.setSubscribed(subscribed.isSelected()); |
| loggedUser.setAddress(address.getText()); |
| animateMessage(); |
| } |
| |
| public void resetProfile(ActionEvent event){ |
| if (application == null){ |
| return; |
| } |
| email.setText(""); |
| phone.setText(""); |
| subscribed.setSelected(false); |
| address.setText(""); |
| success.setOpacity(0.0); |
| |
| } |
| |
| private void animateMessage() { |
| FadeTransition ft = new FadeTransition(Duration.millis(1000), success); |
| ft.setFromValue(0.0); |
| ft.setToValue(1); |
| ft.play(); |
| } |
| } |