1 /******************************************************************************* 2 * JDateButton: JavaFX Date Button 3 * Copyright 2012,2014 Tony Washer 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * ------------------------------------------------------------ 17 * SubVersion Revision Information: 18 * $URL: https://svn.code.sf.net/p/jdatebutton/code/tags/v2.1.0-b3/jdatebutton-javafx/src/main/java/net/sourceforge/jdatebutton/javafx/JDateConfig.java $ 19 * $Revision: 34 $ 20 * $Author: tonywasher $ 21 * $Date: 2015-12-01 16:21:13 +0000 (Tue, 01 Dec 2015) $ 22 ******************************************************************************/ 23 package net.sourceforge.jdatebutton.javafx; 24 25 import java.time.LocalDate; 26 27 import javafx.beans.property.ObjectProperty; 28 import javafx.beans.property.SimpleObjectProperty; 29 import net.sourceforge.jdatebutton.JDateBaseConfig; 30 import net.sourceforge.jdatebutton.JDateFormatter; 31 32 /** 33 * Provides Date Management support for {@link JDateButton}. 34 */ 35 public class JDateConfig 36 extends JDateBaseConfig<JDateButton> { 37 /** 38 * The Selected Date Property. 39 */ 40 private final ObjectProperty<LocalDate> theSelectedDate; 41 42 /** 43 * Constructor. 44 */ 45 public JDateConfig() { 46 /* Create properties */ 47 theSelectedDate = new SimpleObjectProperty<LocalDate>(this, PROPERTY_DATE); 48 } 49 50 /** 51 * Constructor. 52 * @param pFormatter the date formatter 53 */ 54 public JDateConfig(final JDateFormatter pFormatter) { 55 /* Set formatter */ 56 super(pFormatter); 57 58 /* Create properties */ 59 theSelectedDate = new SimpleObjectProperty<LocalDate>(this, PROPERTY_DATE); 60 } 61 62 @Override 63 public final LocalDate getSelectedDate() { 64 return theSelectedDate.get(); 65 } 66 67 /** 68 * Get the selected date property. 69 * @return the Selected date 70 */ 71 public final ObjectProperty<LocalDate> selectedDateProperty() { 72 return theSelectedDate; 73 } 74 75 @Override 76 public final void storeSelectedDate(final LocalDate pDate) { 77 /* Store the date */ 78 theSelectedDate.set(pDate); 79 } 80 81 @Override 82 protected LocalDate getInitialDate() { 83 LocalDate myDate = getSelectedDate(); 84 return (myDate == null) 85 ? currentDate() 86 : myDate; 87 } 88 }