-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from dlemmermann/master
New DateField support.
- Loading branch information
Showing
11 changed files
with
225 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
formsfx-core/src/main/java/com/dlsc/formsfx/model/structure/DateField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.dlsc.formsfx.model.structure; | ||
|
||
/*- | ||
* ========================LICENSE_START================================= | ||
* FormsFX | ||
* %% | ||
* Copyright (C) 2017 - 2018 DLSC Software & Consulting | ||
* %% | ||
* Licensed 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. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
|
||
import com.dlsc.formsfx.view.controls.SimpleDateControl; | ||
import javafx.beans.property.ObjectProperty; | ||
import javafx.beans.value.ChangeListener; | ||
import javafx.beans.value.ObservableValue; | ||
import javafx.util.converter.LocalDateStringConverter; | ||
|
||
import java.time.LocalDate; | ||
import java.time.chrono.Chronology; | ||
import java.time.format.FormatStyle; | ||
import java.util.Locale; | ||
|
||
/** | ||
* This class provides an implementation of a {@link Field} containing a {@code LocalDate} value. | ||
* | ||
* @author Tomasz Krzemiński | ||
*/ | ||
public class DateField extends DataField<ObjectProperty<LocalDate>, LocalDate, DateField> { | ||
/** | ||
* Internal constructor for the {@code DataField} class. To create new | ||
* elements, see the static factory methods in {@code Field}. | ||
* | ||
* @param valueProperty The property that is used to store the current valid value | ||
* of the field. | ||
* @param persistentValueProperty The property that is used to store the latest persisted | ||
* @see Field ::ofStringType | ||
* @see Field ::ofIntegerType | ||
* @see Field ::ofDoubleType | ||
* @see Field ::ofBooleanType | ||
*/ | ||
public DateField(ObjectProperty<LocalDate> valueProperty, ObjectProperty<LocalDate> persistentValueProperty) { | ||
super(valueProperty, persistentValueProperty); | ||
|
||
Chronology chronology = Chronology.ofLocale(Locale.getDefault(Locale.Category.FORMAT)); | ||
stringConverter = new LocalDateStringConverter(FormatStyle.SHORT, null, chronology); | ||
renderer = new SimpleDateControl(); | ||
userInput.setValue(null); | ||
userInput.setValue(stringConverter.toString((LocalDate) persistentValue.getValue())); | ||
} | ||
|
||
@Override | ||
public DateField bind(ObjectProperty<LocalDate> binding) { | ||
return super.bind(binding); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
formsfx-core/src/main/java/com/dlsc/formsfx/view/controls/SimpleDateControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.dlsc.formsfx.view.controls; | ||
|
||
/*- | ||
* ========================LICENSE_START================================= | ||
* FormsFX | ||
* %% | ||
* Copyright (C) 2017 - 2018 DLSC Software & Consulting | ||
* %% | ||
* Licensed 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. | ||
* =========================LICENSE_END================================== | ||
*/ | ||
|
||
import com.dlsc.formsfx.model.structure.DateField; | ||
import javafx.geometry.Pos; | ||
import javafx.geometry.VPos; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.DatePicker; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.scene.layout.StackPane; | ||
|
||
/** | ||
* This class provides a specific implementation to edit date values. | ||
* | ||
* @author Tomasz Krzemiński | ||
*/ | ||
public class SimpleDateControl extends SimpleControl<DateField> { | ||
|
||
protected Label fieldLabel; | ||
protected DatePicker picker; | ||
protected Label readOnlyLabel; | ||
protected StackPane stack; | ||
|
||
@Override | ||
public void initializeParts() { | ||
super.initializeParts(); | ||
|
||
stack = new StackPane(); | ||
|
||
fieldLabel = new Label(); | ||
readOnlyLabel = new Label(); | ||
picker = new DatePicker(); | ||
picker.setEditable(true); | ||
} | ||
|
||
@Override | ||
public void layoutParts() { | ||
super.layoutParts(); | ||
|
||
int columns = field.getSpan(); | ||
readOnlyLabel.getStyleClass().add("read-only-label"); | ||
|
||
picker.setMaxWidth(Double.MAX_VALUE); | ||
|
||
stack.setAlignment(Pos.CENTER_LEFT); | ||
stack.getChildren().addAll(picker, readOnlyLabel); | ||
|
||
Node labelDescription = field.getLabelDescription(); | ||
Node valueDescription = field.getValueDescription(); | ||
|
||
add(fieldLabel, 0, 0, 2, 1); | ||
if (labelDescription != null) { | ||
GridPane.setValignment(labelDescription, VPos.TOP); | ||
add(labelDescription, 0, 1, 2, 1); | ||
} | ||
add(stack, 2, 0, columns - 2, 1); | ||
if (valueDescription != null) { | ||
GridPane.setValignment(valueDescription, VPos.TOP); | ||
add(valueDescription, 2, 1, columns - 2, 1); | ||
} | ||
} | ||
|
||
@Override | ||
public void setupBindings() { | ||
super.setupBindings(); | ||
|
||
picker.disableProperty().bind(field.editableProperty().not()); | ||
readOnlyLabel.visibleProperty().bind(field.editableProperty().not()); | ||
|
||
picker.getEditor().textProperty().bindBidirectional(field.userInputProperty()); | ||
fieldLabel.textProperty().bind(field.labelProperty()); | ||
picker.promptTextProperty().bind(field.placeholderProperty()); | ||
picker.managedProperty().bind(picker.visibleProperty()); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void setupEventHandlers() { | ||
picker.getEditor().textProperty().addListener((observable, oldValue, newValue) -> field.userInputProperty().setValue(String.valueOf(newValue))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters