diff --git a/gradle.properties b/gradle.properties index 551c98466..a2d84c395 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group = org.jfxtras archivesBaseName = jfxtras-labs -version = 2.2-r5 +version = 2.2-r6-SNAPSHOT jfxtras_requiredJavaFxVersion = 2.2 jfxtras_junitVersion = 4.10 diff --git a/src/main/java/jfxtras/labs/internal/scene/control/behavior/LocalDatePickerBehavior.java b/src/main/java/jfxtras/labs/internal/scene/control/behavior/LocalDatePickerBehavior.java index 0d4f46ba6..b49c61644 100644 --- a/src/main/java/jfxtras/labs/internal/scene/control/behavior/LocalDatePickerBehavior.java +++ b/src/main/java/jfxtras/labs/internal/scene/control/behavior/LocalDatePickerBehavior.java @@ -26,7 +26,7 @@ */ package jfxtras.labs.internal.scene.control.behavior; -import jfxtras.labs.scene.control.LocalDatePicker; +import jfxtras.labs.scene.control.LocalDateTimePicker; import com.sun.javafx.scene.control.behavior.BehaviorBase; @@ -35,7 +35,7 @@ * @author Tom Eugelink * */ -public class LocalDatePickerBehavior extends BehaviorBase +public class LocalDatePickerBehavior extends BehaviorBase { // ================================================================================================================== // CONSTRUCTOR @@ -44,7 +44,7 @@ public class LocalDatePickerBehavior extends BehaviorBase * * @param control */ - public LocalDatePickerBehavior(LocalDatePicker control) + public LocalDatePickerBehavior(LocalDateTimePicker control) { super(control); } diff --git a/src/main/java/jfxtras/labs/internal/scene/control/skin/AgendaWeekSkin.java b/src/main/java/jfxtras/labs/internal/scene/control/skin/AgendaWeekSkin.java index fe22e8bbb..3ad8eba30 100644 --- a/src/main/java/jfxtras/labs/internal/scene/control/skin/AgendaWeekSkin.java +++ b/src/main/java/jfxtras/labs/internal/scene/control/skin/AgendaWeekSkin.java @@ -1781,14 +1781,14 @@ public void handle(WindowEvent arg0) // start final CalendarTextField lStartCalendarTextField = new CalendarTextField().withDateFormat(SimpleDateFormat.getDateTimeInstance()); lStartCalendarTextField.setLocale(getSkinnable().getLocale()); - lStartCalendarTextField.setValue(abstractAppointmentPane.appointment.getStartTime()); + lStartCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getStartTime()); lMenuVBox.getChildren().add(lStartCalendarTextField); // end final CalendarTextField lEndCalendarTextField = new CalendarTextField().withDateFormat(SimpleDateFormat.getDateTimeInstance()); lEndCalendarTextField.setLocale(getSkinnable().getLocale()); - lEndCalendarTextField.setValue(abstractAppointmentPane.appointment.getEndTime()); + lEndCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getEndTime()); lMenuVBox.getChildren().add(lEndCalendarTextField); - lEndCalendarTextField.valueProperty().addListener(new ChangeListener() + lEndCalendarTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue arg0, Calendar oldValue, Calendar newValue) @@ -1819,7 +1819,7 @@ public void changed(ObservableValue arg0, Boolean oldValue, B Calendar lEndTime = (Calendar)abstractAppointmentPane.appointment.getStartTime().clone(); lEndTime.add(Calendar.MINUTE, 30); abstractAppointmentPane.appointment.setEndTime(lEndTime); - lEndCalendarTextField.setValue(abstractAppointmentPane.appointment.getEndTime()); + lEndCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getEndTime()); } lEndCalendarTextField.setVisible(abstractAppointmentPane.appointment.getEndTime() != null); // refresh is done upon popup close @@ -1827,7 +1827,7 @@ public void changed(ObservableValue arg0, Boolean oldValue, B }); } // event handling - lStartCalendarTextField.valueProperty().addListener(new ChangeListener() + lStartCalendarTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue arg0, Calendar oldValue, Calendar newValue) @@ -1854,7 +1854,7 @@ public void changed(ObservableValue arg0, Calendar oldValue, abstractAppointmentPane.appointment.setEndTime(lEndCalendar); // update field - lEndCalendarTextField.setValue(abstractAppointmentPane.appointment.getEndTime()); + lEndCalendarTextField.setCalendar(abstractAppointmentPane.appointment.getEndTime()); } // refresh is done upon popup close diff --git a/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTextFieldCaspianSkin.java b/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTextFieldCaspianSkin.java index 8b7bbc70b..618b155af 100644 --- a/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTextFieldCaspianSkin.java +++ b/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTextFieldCaspianSkin.java @@ -88,7 +88,7 @@ private void construct() createNodes(); // react to value changes in the model - getSkinnable().valueProperty().addListener(new ChangeListener() + getSkinnable().calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) @@ -108,7 +108,7 @@ public void changed(ObservableValue observableValue, Calenda private void refreshValue() { // write out to textfield - Calendar c = getSkinnable().getValue(); + Calendar c = getSkinnable().getCalendar(); String s = c == null ? "" : getSkinnable().getDateFormat().format( c.getTime() ); textField.setText( s ); } @@ -179,7 +179,7 @@ public void handle(KeyEvent keyEvent) parse(); // get the calendar to modify - Calendar lCalendar = (Calendar)getSkinnable().getValue().clone(); + Calendar lCalendar = (Calendar)getSkinnable().getCalendar().clone(); // modify int lField = Calendar.DATE; @@ -190,7 +190,7 @@ public void handle(KeyEvent keyEvent) lCalendar.add(lField, keyEvent.getCode() == KeyCode.UP ? 1 : -1); // set it - getSkinnable().setValue(lCalendar); + getSkinnable().setCalendar(lCalendar); } } }); @@ -236,7 +236,7 @@ public void handle(KeyEvent keyEvent) calendarPicker.setMode(CalendarPicker.Mode.SINGLE); // bind our properties to the picker's Bindings.bindBidirectional(calendarPicker.localeProperty(), getSkinnable().localeProperty()); // order is important, because the value of the first field is overwritten initially with the value of the last field - Bindings.bindBidirectional(calendarPicker.calendarProperty(), getSkinnable().valueProperty()); // order is important, because the value of the first field is overwritten initially with the value of the last field + Bindings.bindBidirectional(calendarPicker.calendarProperty(), getSkinnable().calendarProperty()); // order is important, because the value of the first field is overwritten initially with the value of the last field calendarPicker.calendarProperty().addListener(new ChangeListener() { @Override @@ -270,7 +270,7 @@ private void parse() lText = lText.trim(); if (lText.length() == 0) { - getSkinnable().setValue(null); + getSkinnable().setCalendar(null); return; } @@ -290,20 +290,20 @@ private void parse() // parse the delta int lDelta = Integer.parseInt(lText); - Calendar lCalendar = (Calendar)getSkinnable().getValue().clone(); // TODO locale + Calendar lCalendar = (Calendar)getSkinnable().getCalendar().clone(); // TODO locale lCalendar.add(lUnit, lDelta); // set the value - getSkinnable().setValue(lCalendar); + getSkinnable().setCalendar(lCalendar); } else if (lText.equals("#")) { // set the value - getSkinnable().setValue(Calendar.getInstance()); // TODO locale + getSkinnable().setCalendar(Calendar.getInstance()); // TODO locale } else { - Calendar lCalendar = getSkinnable().getValue(); + Calendar lCalendar = getSkinnable().getCalendar(); java.text.ParseException lParseException = null; try { @@ -334,7 +334,7 @@ else if (lText.equals("#")) } // set the value - getSkinnable().setValue(lCalendar); + getSkinnable().setCalendar(lCalendar); refreshValue(); // rethrow initial exception if all parsing failed diff --git a/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimePickerSkin.java b/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimePickerSkin.java index dfd283d7d..6353a5fa9 100644 --- a/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimePickerSkin.java +++ b/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimePickerSkin.java @@ -94,17 +94,6 @@ public void invalidated(Observable observable) } }); minuteScrollSlider.setBlockIncrement(getSkinnable().getMinuteStep().doubleValue()); - - // react to changes in showLabels - getSkinnable().showLabelsProperty().addListener(new InvalidationListener() - { - @Override - public void invalidated(Observable observable) - { - // paint - refreshLayout(); - } - }); } // ================================================================================================================== @@ -122,14 +111,10 @@ private void createNodes() // two sliders hourScrollSlider.minProperty().set(00); hourScrollSlider.maxProperty().set(23); -// hourScrollSlider.setShowTickLabels(true); -// hourScrollSlider.setShowTickMarks(true); hourScrollSlider.setMajorTickUnit(12); hourScrollSlider.setMinorTickCount(3); minuteScrollSlider.minProperty().set(00); minuteScrollSlider.maxProperty().set(59); -// minuteScrollSlider.setShowTickLabels(true); -// minuteScrollSlider.setShowTickMarks(true); minuteScrollSlider.setMajorTickUnit(10); hourScrollSlider.valueProperty().addListener(new ChangeListener() { @@ -177,116 +162,6 @@ public void changed(ObservableValue observable, Number oldValu final private Slider hourScrollSlider = new Slider(); final private Slider minuteScrollSlider = new Slider(); final private Text timeText = new Text("XX:XX"); - final Pane hourLabelsPane = new Pane() - { - { - prefWidthProperty().bind(hourScrollSlider.prefWidthProperty()); - layoutChildren(); - //setStyle("-fx-border-color: red; -fx-border-width:1px;"); - } - - protected void layoutChildren() - { - getChildren().clear(); - - // get some basic numbers - double lLabelWidth = new Text("88").prefWidth(0); - double lWhitespace = lLabelWidth / 2; - double lLabelWidthPlusWhitespace = lLabelWidth + lWhitespace; - double lScrollSliderOuterPadding = 5; - - // add a dummy rectangle to make sure the are has enough height - { - Text lText = new Text("0"); - Rectangle lRectangle = new Rectangle(0,0, minuteScrollSlider.getWidth(), lText.prefHeight(0)); - lRectangle.setFill(Color.TRANSPARENT); - getChildren().add(lRectangle); - } - - // now we're going to play with some numbers - // given the available width, how many labels cold we place (rounded down) - int lNumberOfLabels = (int)(this.getWidth() / lLabelWidthPlusWhitespace) + 2; - int lStep = 24; - if (lNumberOfLabels >= 24/1) lStep = 1; - else if (lNumberOfLabels >= 24/2) lStep = 2; - else if (lNumberOfLabels >= 24/3) lStep = 3; - else if (lNumberOfLabels >= 24/4) lStep = 4; - else if (lNumberOfLabels > 24/6) lStep = 6; - else if (lNumberOfLabels > 24/12) lStep = 12; - for (int i = 0; i < 24; i += lStep) - { - Text lText = new Text("" + i); - lText.setY(lText.prefHeight(0)); - double lX = (lScrollSliderOuterPadding + ((minuteScrollSlider.getWidth() - (2*lScrollSliderOuterPadding)) / 23 * i)) - (lText.prefWidth(0) - / (i == 23 ? 1 : 2) // center, except the most right - * ( i == 0 ? 0 : 1)); // and the most left - lText.setX(lX); - getChildren().add(lText); - } - for (int i = 0; i < 24; i += 1) - { - Text lText = new Text("0"); - double lX = (lScrollSliderOuterPadding + ((minuteScrollSlider.getWidth() - (2*lScrollSliderOuterPadding)) / 23 * i)); - getChildren().add(new Line(lX, lText.prefHeight(0) + 3, lX, lText.prefHeight(0) + 3 + 3)); - } - } - }; - final Pane minuteLabelsPane = new Pane() - { - { - layoutChildren(); - //setStyle("-fx-border-color: red; -fx-border-width:1px;"); - } - - protected void layoutChildren() - { - getChildren().clear(); - - // get some basic numbers - double lLabelWidth = new Text("88").prefWidth(0); - double lWhitespace = lLabelWidth / 2; - double lLabelWidthPlusWhitespace = lLabelWidth + lWhitespace; - double lScrollSliderOuterPadding = 5; - - // add a dummy rectangle to make sure the are has enough height - if (getSkinnable().showLabelsProperty().get()) - { - Text lText = new Text("0"); - Rectangle lRectangle = new Rectangle(0,0, minuteScrollSlider.getWidth(), lText.prefHeight(0)); - lRectangle.setFill(Color.TRANSPARENT); - getChildren().add(lRectangle); - } - - // now we're going to play with some numbers - // given the available width, how many labels cold we place (rounded down) - int lNumberOfLabels = (int)(this.getWidth() / lLabelWidthPlusWhitespace) + 2; - int lStep = 60; - if (lNumberOfLabels >= 60/1) lStep = 1; - else if (lNumberOfLabels >= 60/2) lStep = 2; - else if (lNumberOfLabels >= 60/3) lStep = 3; - else if (lNumberOfLabels >= 60/4) lStep = 4; - else if (lNumberOfLabels >= 60/5) lStep = 5; - else if (lNumberOfLabels >= 60/10) lStep = 10; - else if (lNumberOfLabels >= 60/15) lStep = 15; - else if (lNumberOfLabels >= 60/30) lStep = 30; - if (lStep < getSkinnable().getMinuteStep()) lStep = getSkinnable().getMinuteStep(); - for (int i = 0; i <= 59; i += lStep) - { - Text lText = new Text("" + i); - lText.setY(lText.prefHeight(0)); - double lX = (lScrollSliderOuterPadding + ((minuteScrollSlider.getWidth() - (2*lScrollSliderOuterPadding)) / 59 * i)) - (lText.prefWidth(0) - / (i == 59? 1 : 2) // center, except the most right - * ( i == 0 ? 0 : 1)); // and the most left - lText.setX(lX); - getChildren().add(lText); - } - for (int i = 0; i <= 59; i += 1) - { - double lX = (lScrollSliderOuterPadding + ((minuteScrollSlider.getWidth() - (2*lScrollSliderOuterPadding)) / 59 * i)); - getChildren().add(new Line(lX, 0, lX, 3)); - } - } - }; /** * @@ -297,10 +172,8 @@ private void refreshLayout() getChildren().clear(); VBox lVBox = new VBox(0); lVBox.alignmentProperty().set(Pos.CENTER); - if (getSkinnable().getShowLabels()) lVBox.getChildren().add(hourLabelsPane); lVBox.getChildren().add(hourScrollSlider); lVBox.getChildren().add(minuteScrollSlider); - if (getSkinnable().getShowLabels()) lVBox.getChildren().add(minuteLabelsPane); getChildren().add(lVBox); getChildren().add(timeText); } diff --git a/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimeTextFieldCaspianSkin.java b/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimeTextFieldCaspianSkin.java index 4961dab2a..9b7912323 100644 --- a/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimeTextFieldCaspianSkin.java +++ b/src/main/java/jfxtras/labs/internal/scene/control/skin/CalendarTimeTextFieldCaspianSkin.java @@ -89,7 +89,7 @@ private void construct() createNodes(); // react to value changes in the model - getSkinnable().valueProperty().addListener(new InvalidationListener() // invalidation is also fired if there is no change (which is the case if a time if blocked to the existing time), but the text must be refreshed + getSkinnable().calendarProperty().addListener(new InvalidationListener() // invalidation is also fired if there is no change (which is the case if a time if blocked to the existing time), but the text must be refreshed { @Override @@ -110,7 +110,7 @@ public void invalidated(Observable arg0) private void refreshValue() { // write out to textfield - Calendar c = getSkinnable().getValue(); + Calendar c = getSkinnable().getCalendar(); String s = c == null ? "" : getSkinnable().getDateFormat().format(c.getTime()); textField.setText( s ); } @@ -181,14 +181,14 @@ public void handle(KeyEvent keyEvent) parse(); // get the calendar to modify - Calendar lCalendar = (Calendar)getSkinnable().getValue().clone(); + Calendar lCalendar = (Calendar)getSkinnable().getCalendar().clone(); // modify if (keyEvent.isControlDown()) lCalendar.add(Calendar.HOUR_OF_DAY, keyEvent.getCode() == KeyCode.UP ? 1 : -1); else lCalendar.add(Calendar.MINUTE, keyEvent.getCode() == KeyCode.UP ? getSkinnable().getMinuteStep() : -1 * getSkinnable().getMinuteStep()); // set it - getSkinnable().setValue( CalendarTimePickerSkin.blockMinutesToStep(lCalendar, getSkinnable().getMinuteStep()) ); + getSkinnable().setCalendar( CalendarTimePickerSkin.blockMinutesToStep(lCalendar, getSkinnable().getMinuteStep()) ); } } }); @@ -233,9 +233,8 @@ public void handle(KeyEvent keyEvent) // prep the picker TimePicker = new CalendarTimePicker(); // bind our properties to the picker's - Bindings.bindBidirectional(TimePicker.calendarProperty(), getSkinnable().valueProperty()); // order is important, because the value of the first field is overwritten initially with the value of the last field + Bindings.bindBidirectional(TimePicker.calendarProperty(), getSkinnable().calendarProperty()); // order is important, because the value of the first field is overwritten initially with the value of the last field Bindings.bindBidirectional(TimePicker.minuteStepProperty(), getSkinnable().minuteStepProperty()); // order is important, because the value of the first field is overwritten initially with the value of the last field - Bindings.bindBidirectional(TimePicker.showLabelsProperty(), getSkinnable().showLabelsProperty()); // order is important, because the value of the first field is overwritten initially with the value of the last field // close icon closeIconImage = new Image(this.getClass().getResourceAsStream(this.getClass().getSimpleName() + "CloseWindowIcon.png")); @@ -258,7 +257,7 @@ private void parse() lText = lText.trim(); if (lText.length() == 0) { - getSkinnable().setValue(null); + getSkinnable().setCalendar(null); return; } @@ -276,20 +275,20 @@ private void parse() // parse the delta int lDelta = Integer.parseInt(lText); - Calendar lCalendar = (Calendar)getSkinnable().getValue().clone(); // TODO locale + Calendar lCalendar = (Calendar)getSkinnable().getCalendar().clone(); // TODO locale lCalendar.add(lUnit, lDelta); // set the value - getSkinnable().setValue( CalendarTimePickerSkin.blockMinutesToStep(lCalendar, getSkinnable().getMinuteStep()) ); + getSkinnable().setCalendar( CalendarTimePickerSkin.blockMinutesToStep(lCalendar, getSkinnable().getMinuteStep()) ); } else if (lText.equals("#")) { // set the value - getSkinnable().setValue( CalendarTimePickerSkin.blockMinutesToStep(Calendar.getInstance(), getSkinnable().getMinuteStep()) ); // TODO locale + getSkinnable().setCalendar( CalendarTimePickerSkin.blockMinutesToStep(Calendar.getInstance(), getSkinnable().getMinuteStep()) ); // TODO locale } else { - Calendar lCalendar = getSkinnable().getValue(); + Calendar lCalendar = getSkinnable().getCalendar(); java.text.ParseException lParseException = null; try { @@ -320,7 +319,7 @@ else if (lText.equals("#")) } // set the value - getSkinnable().setValue(lCalendar); + getSkinnable().setCalendar(lCalendar); refreshValue(); // rethrow initial exception if all parsing failed diff --git a/src/main/java/jfxtras/labs/scene/control/CalendarTextField.java b/src/main/java/jfxtras/labs/scene/control/CalendarTextField.java index ca6bb471f..829b4058f 100644 --- a/src/main/java/jfxtras/labs/scene/control/CalendarTextField.java +++ b/src/main/java/jfxtras/labs/scene/control/CalendarTextField.java @@ -85,18 +85,18 @@ private void construct() */ @Override protected String getUserAgentStylesheet() { - return this.getClass().getResource("/jfxtras/labs/internal/scene/control/" + this.getClass().getSimpleName() + ".css").toString(); + return this.getClass().getResource("/jfxtras/labs/internal/scene/control/" + CalendarTextField.class.getSimpleName() + ".css").toString(); } // ================================================================================================================== // PROPERTIES - /** Value: */ - public ObjectProperty valueProperty() { return valueObjectProperty; } - final private ObjectProperty valueObjectProperty = new SimpleObjectProperty(this, "value", null); - public Calendar getValue() { return valueObjectProperty.getValue(); } - public void setValue(Calendar value) { valueObjectProperty.setValue(value); } - public CalendarTextField withValue(Calendar value) { setValue(value); return this; } + /** Calendar: */ + public ObjectProperty calendarProperty() { return calendarObjectProperty; } + final private ObjectProperty calendarObjectProperty = new SimpleObjectProperty(this, "calendar", null); + public Calendar getCalendar() { return calendarObjectProperty.getValue(); } + public void setCalendar(Calendar value) { calendarObjectProperty.setValue(value); } + public CalendarTextField withCalendar(Calendar value) { setCalendar(value); return this; } /** * The DateFormat used to render/parse the date in the textfield. diff --git a/src/main/java/jfxtras/labs/scene/control/CalendarTimePicker.java b/src/main/java/jfxtras/labs/scene/control/CalendarTimePicker.java index dc56e67c0..d636e901e 100644 --- a/src/main/java/jfxtras/labs/scene/control/CalendarTimePicker.java +++ b/src/main/java/jfxtras/labs/scene/control/CalendarTimePicker.java @@ -68,7 +68,7 @@ private void construct() */ @Override protected String getUserAgentStylesheet() { - return this.getClass().getResource("/jfxtras/labs/internal/scene/control/" + this.getClass().getSimpleName() + ".css").toString(); + return this.getClass().getResource("/jfxtras/labs/internal/scene/control/" + CalendarTimePicker.class.getSimpleName() + ".css").toString(); } // ================================================================================================================== @@ -102,22 +102,7 @@ public void set(Integer value) public void setMinuteStep(Integer value) { minuteStepProperty.setValue(value); } public CalendarTimePicker withMinuteStep(Integer value) { setMinuteStep(value); return this; } - /** ShowLabels */ - public ObjectProperty showLabelsProperty() { return showLabelsProperty; } - final private SimpleObjectProperty showLabelsProperty = new SimpleObjectProperty(this, "showLabels", false) - { - public void set(Boolean value) - { - if (value == null) throw new NullPointerException("showLabels cannot be null"); - super.set(value); - } - }; - public Boolean getShowLabels() { return showLabelsProperty.getValue(); } - public void setShowLabels(Boolean value) { showLabelsProperty.setValue(value); } - public CalendarTimePicker withShowLabels(Boolean value) { setShowLabels(value); return this; } - // TODO: add showTimeLabels, but the labels make the layout jump - // ================================================================================================================== // SUPPORT diff --git a/src/main/java/jfxtras/labs/scene/control/CalendarTimeTextField.java b/src/main/java/jfxtras/labs/scene/control/CalendarTimeTextField.java index ae59e31f2..f4d6d7195 100644 --- a/src/main/java/jfxtras/labs/scene/control/CalendarTimeTextField.java +++ b/src/main/java/jfxtras/labs/scene/control/CalendarTimeTextField.java @@ -84,18 +84,18 @@ private void construct() */ @Override protected String getUserAgentStylesheet() { - return this.getClass().getResource("/jfxtras/labs/internal/scene/control/" + this.getClass().getSimpleName() + ".css").toString(); + return this.getClass().getResource("/jfxtras/labs/internal/scene/control/" + CalendarTimeTextField.class.getSimpleName() + ".css").toString(); } // ================================================================================================================== // PROPERTIES /** Value: */ - public ObjectProperty valueProperty() { return valueObjectProperty; } - final private ObjectProperty valueObjectProperty = new SimpleObjectProperty(this, "value", null); - public Calendar getValue() { return valueObjectProperty.getValue(); } - public void setValue(Calendar value) { valueObjectProperty.setValue(value); } - public CalendarTimeTextField withValue(Calendar value) { setValue(value); return this; } + public ObjectProperty calendarProperty() { return calendarObjectProperty; } + final private ObjectProperty calendarObjectProperty = new SimpleObjectProperty(this, "calendar", null); + public Calendar getCalendar() { return calendarObjectProperty.getValue(); } + public void setCalendar(Calendar value) { calendarObjectProperty.setValue(value); } + public CalendarTimeTextField withCalendar(Calendar value) { setCalendar(value); return this; } /** * The DateFormat used to render/parse the date in the textfield. diff --git a/src/main/java/jfxtras/labs/scene/control/LocalDatePicker.java b/src/main/java/jfxtras/labs/scene/control/LocalDateTimePicker.java similarity index 54% rename from src/main/java/jfxtras/labs/scene/control/LocalDatePicker.java rename to src/main/java/jfxtras/labs/scene/control/LocalDateTimePicker.java index 251b05817..13f7fac48 100644 --- a/src/main/java/jfxtras/labs/scene/control/LocalDatePicker.java +++ b/src/main/java/jfxtras/labs/scene/control/LocalDateTimePicker.java @@ -27,7 +27,6 @@ package jfxtras.labs.scene.control; import java.util.Calendar; -import java.util.Locale; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; @@ -35,18 +34,19 @@ import javafx.beans.value.ObservableValue; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; -import javafx.scene.control.Control; -import javax.time.calendar.LocalDate; +import javax.time.calendar.LocalDateTime; + +import jfxtras.labs.util.DateTimeUtil; /** - * LocalDate (JSR-310) picker component. - * This is an extention of the CalendarPicker adding the new date API JSR-310. + * LocalDateTime (JSR-310) picker component. + * This is an extension of the CalendarPicker adding the new date API JSR-310. * Since Calendar will not be removed from the JDK, too many applications use it, this approach of extending CalendarPicker is the most flexible one. * * @author Tom Eugelink */ -public class LocalDatePicker extends CalendarPicker +public class LocalDateTimePicker extends CalendarPicker { // ================================================================================================================== // CONSTRUCTOR @@ -54,19 +54,19 @@ public class LocalDatePicker extends CalendarPicker /** * */ - public LocalDatePicker() + public LocalDateTimePicker() { construct(); } /** * - * @param localDate + * @param localDateTime */ - public LocalDatePicker(LocalDate localDate) + public LocalDateTimePicker(LocalDateTime localDateTime) { construct(); - setLocalDate(localDate); + setLocalDateTime(localDateTime); } /* @@ -75,20 +75,20 @@ public LocalDatePicker(LocalDate localDate) private void construct() { // construct properties - constructLocalDate(); - constructLocalDates(); + constructLocalDateTime(); + constructLocalDateTimes(); } // ================================================================================================================== // PROPERTIES - /** LocalDate: */ - public ObjectProperty localDateProperty() { return localDateObjectProperty; } - private final ObjectProperty localDateObjectProperty = new SimpleObjectProperty(this, "localDate"); - public LocalDate getLocalDate() { return localDateObjectProperty.getValue(); } - public void setLocalDate(LocalDate value) { localDateObjectProperty.setValue(value); } - public LocalDatePicker withLocalDate(LocalDate value) { setLocalDate(value); return this; } - private void constructLocalDate() + /** LocalDateTime: */ + public ObjectProperty localDateProperty() { return localDateObjectProperty; } + private final ObjectProperty localDateObjectProperty = new SimpleObjectProperty(this, "localDate"); + public LocalDateTime getLocalDateTime() { return localDateObjectProperty.getValue(); } + public void setLocalDateTime(LocalDateTime value) { localDateObjectProperty.setValue(value); } + public LocalDateTimePicker withLocalDateTime(LocalDateTime value) { setLocalDateTime(value); return this; } + private void constructLocalDateTime() { // if this value is changed by binding, make sure related things are updated calendarProperty().addListener(new ChangeListener() @@ -96,25 +96,25 @@ private void constructLocalDate() @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) { - localDateProperty().set(createLocalDateFromCalendar(newValue)); + localDateProperty().set(DateTimeUtil.createLocalDateTimeFromCalendar(newValue)); } }); // if the inherited value is changed, make sure calendar is updated - localDateProperty().addListener(new ChangeListener() + localDateProperty().addListener(new ChangeListener() { @Override - public void changed(ObservableValue observableValue, LocalDate oldValue, LocalDate newValue) + public void changed(ObservableValue observableValue, LocalDateTime oldValue, LocalDateTime newValue) { - calendarProperty().set( newValue == null ? null : createCalendarFromLocalDate(newValue)); + calendarProperty().set( newValue == null ? null : DateTimeUtil.createCalendarFromLocalDateTime(newValue, getLocale())); } }); } - /** LocalDates: */ - public ObservableList localDates() { return localDates; } - private final ObservableList localDates = javafx.collections.FXCollections.observableArrayList(); - private void constructLocalDates() + /** LocalDateTimes: */ + public ObservableList localDates() { return localDates; } + private final ObservableList localDates = javafx.collections.FXCollections.observableArrayList(); + private void constructLocalDateTimes() { // forward changes calendars().addListener(new ListChangeListener() @@ -126,33 +126,33 @@ public void onChanged(ListChangeListener.Change change) { for (Calendar lCalendar : change.getRemoved()) { - LocalDate lLocalDate = createLocalDateFromCalendar(lCalendar); - if (localDates().contains(lLocalDate)) localDates().remove(lLocalDate); + LocalDateTime lLocalDateTime = DateTimeUtil.createLocalDateTimeFromCalendar(lCalendar); + if (localDates().contains(lLocalDateTime)) localDates().remove(lLocalDateTime); } for (Calendar lCalendar : change.getAddedSubList()) { - LocalDate lLocalDate = createLocalDateFromCalendar(lCalendar); - if (localDates().contains(lLocalDate) == false) localDates().add(lLocalDate); + LocalDateTime lLocalDateTime = DateTimeUtil.createLocalDateTimeFromCalendar(lCalendar); + if (localDates().contains(lLocalDateTime) == false) localDates().add(lLocalDateTime); } } } }); // handle changes - localDates().addListener(new ListChangeListener() + localDates().addListener(new ListChangeListener() { @Override - public void onChanged(ListChangeListener.Change change) + public void onChanged(ListChangeListener.Change change) { while (change.next()) { - for (LocalDate lLocalDate : change.getRemoved()) + for (LocalDateTime lLocalDateTime : change.getRemoved()) { - Calendar lCalendar = createCalendarFromLocalDate(lLocalDate); + Calendar lCalendar = DateTimeUtil.createCalendarFromLocalDateTime(lLocalDateTime, getLocale()); if (calendars().contains(lCalendar)) calendars().remove(lCalendar); } - for (LocalDate lLocalDate : change.getAddedSubList()) + for (LocalDateTime lLocalDateTime : change.getAddedSubList()) { - Calendar lCalendar = createCalendarFromLocalDate(lLocalDate); + Calendar lCalendar = DateTimeUtil.createCalendarFromLocalDateTime(lLocalDateTime, getLocale()); if (calendars().contains(lCalendar) == false) calendars().add(lCalendar); } } @@ -163,34 +163,4 @@ public void onChanged(ListChangeListener.Change change) // ================================================================================================================== // SUPPORT - /** - * - * @param localDate - * @return - */ - private Calendar createCalendarFromLocalDate(LocalDate localDate) - { - if (localDate == null) return null; - Calendar lCalendar = Calendar.getInstance(getLocale()); - lCalendar.set(Calendar.YEAR, localDate.getYear()); - lCalendar.set(Calendar.MONTH, localDate.getMonthOfYear().getValue() - 1); - lCalendar.set(Calendar.DATE, localDate.getDayOfMonth()); - lCalendar.set(Calendar.HOUR_OF_DAY, 0); - lCalendar.set(Calendar.MINUTE, 0); - lCalendar.set(Calendar.SECOND, 0); - lCalendar.set(Calendar.MILLISECOND, 0); - return lCalendar; - } - - /** - * - * @param calendar - * @return - */ - private LocalDate createLocalDateFromCalendar(Calendar calendar) - { - if (calendar == null) return null; - LocalDate lLocalDate = LocalDate.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DATE)); - return lLocalDate; - } } diff --git a/src/main/java/jfxtras/labs/scene/control/LocalDateTimeTextField.java b/src/main/java/jfxtras/labs/scene/control/LocalDateTimeTextField.java new file mode 100644 index 000000000..4680bbcc4 --- /dev/null +++ b/src/main/java/jfxtras/labs/scene/control/LocalDateTimeTextField.java @@ -0,0 +1,89 @@ +package jfxtras.labs.scene.control; + +import java.util.Calendar; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +import javax.time.calendar.LocalDateTime; + +import jfxtras.labs.util.DateTimeUtil; + +/** + * LocalDateTime (JSR-310) text field component. + * This is an extension of the CalendarTextField adding the new date API JSR-310. + * Since Calendar will not be removed from the JDK, too many applications use it, this approach of extending CalendarTextField is the most flexible one. + * + * @author Tom Eugelink + */ +public class LocalDateTimeTextField extends CalendarTextField +{ + // ================================================================================================================== + // CONSTRUCTOR + + /** + * + */ + public LocalDateTimeTextField() + { + construct(); + } + + /** + * + * @param localDateTime + */ + public LocalDateTimeTextField(LocalDateTime localDateTime) + { + construct(); + setLocalDateTime(localDateTime); + } + + /* + * + */ + private void construct() + { + // construct properties + constructLocalDateTime(); + } + + + // ================================================================================================================== + // PROPERTIES + + /** LocalDateTime: */ + public ObjectProperty localDateTimeProperty() { return localDateTimeObjectProperty; } + private final ObjectProperty localDateTimeObjectProperty = new SimpleObjectProperty(this, "localDateTime"); + public LocalDateTime getLocalDateTime() { return localDateTimeObjectProperty.getValue(); } + public void setLocalDateTime(LocalDateTime value) { localDateTimeObjectProperty.setValue(value); } + public LocalDateTimeTextField withLocalDateTime(LocalDateTime value) { setLocalDateTime(value); return this; } + private void constructLocalDateTime() + { + // if this value is changed by binding, make sure related things are updated + calendarProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) + { + localDateTimeProperty().set(DateTimeUtil.createLocalDateTimeFromCalendar(newValue)); + } + }); + + // if the inherited value is changed, make sure calendar is updated + localDateTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalDateTime oldValue, LocalDateTime newValue) + { + calendarProperty().set( newValue == null ? null : DateTimeUtil.createCalendarFromLocalDateTime(newValue, getLocale())); + } + }); + } + + + // ================================================================================================================== + // SUPPORT +} diff --git a/src/main/java/jfxtras/labs/scene/control/LocalTimePicker.java b/src/main/java/jfxtras/labs/scene/control/LocalTimePicker.java new file mode 100644 index 000000000..bfc43bc62 --- /dev/null +++ b/src/main/java/jfxtras/labs/scene/control/LocalTimePicker.java @@ -0,0 +1,116 @@ +/** + * Copyright (c) 2011, JFXtras + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package jfxtras.labs.scene.control; + +import java.util.Calendar; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; + +import javax.time.calendar.LocalTime; + +import jfxtras.labs.util.DateTimeUtil; + +/** + * LocalTime (JSR-310) picker component. + * This is an extension of the CalendarPicker adding the new date API JSR-310. + * Since Calendar will not be removed from the JDK, too many applications use it, this approach of extending CalendarPicker is the most flexible one. + * + * @author Tom Eugelink + */ +public class LocalTimePicker extends CalendarTimePicker +{ + // ================================================================================================================== + // CONSTRUCTOR + + /** + * + */ + public LocalTimePicker() + { + construct(); + } + + /** + * + * @param localTime + */ + public LocalTimePicker(LocalTime localTime) + { + construct(); + setLocalTime(localTime); + } + + /* + * + */ + private void construct() + { + // construct properties + constructLocalTime(); + } + + // ================================================================================================================== + // PROPERTIES + + /** LocalTime: */ + public ObjectProperty localDateProperty() { return localDateObjectProperty; } + private final ObjectProperty localDateObjectProperty = new SimpleObjectProperty(this, "localDate"); + public LocalTime getLocalTime() { return localDateObjectProperty.getValue(); } + public void setLocalTime(LocalTime value) { localDateObjectProperty.setValue(value); } + public LocalTimePicker withLocalTime(LocalTime value) { setLocalTime(value); return this; } + private void constructLocalTime() + { + // if this value is changed by binding, make sure related things are updated + calendarProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) + { + localDateProperty().set(DateTimeUtil.createLocalTimeFromCalendar(newValue)); + } + }); + + // if the inherited value is changed, make sure calendar is updated + localDateProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalTime oldValue, LocalTime newValue) + { + calendarProperty().set( newValue == null ? null : DateTimeUtil.createCalendarFromLocalTime(newValue)); + } + }); + } + + // ================================================================================================================== + // SUPPORT + +} diff --git a/src/main/java/jfxtras/labs/scene/control/LocalTimeTextField.java b/src/main/java/jfxtras/labs/scene/control/LocalTimeTextField.java new file mode 100644 index 000000000..7d16e70aa --- /dev/null +++ b/src/main/java/jfxtras/labs/scene/control/LocalTimeTextField.java @@ -0,0 +1,89 @@ +package jfxtras.labs.scene.control; + +import java.util.Calendar; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; + +import javax.time.calendar.LocalTime; + +import jfxtras.labs.util.DateTimeUtil; + +/** + * LocalTime (JSR-310) text field component. + * This is an extension of the CalendarTimeTextField adding the new date API JSR-310. + * Since Calendar will not be removed from the JDK, too many applications use it, this approach of extending CalendarTextField is the most flexible one. + * + * @author Tom Eugelink + */ +public class LocalTimeTextField extends CalendarTimeTextField +{ + // ================================================================================================================== + // CONSTRUCTOR + + /** + * + */ + public LocalTimeTextField() + { + construct(); + } + + /** + * + * @param localTime + */ + public LocalTimeTextField(LocalTime localTime) + { + construct(); + setLocalTime(localTime); + } + + /* + * + */ + private void construct() + { + // construct properties + constructLocalTime(); + } + + + // ================================================================================================================== + // PROPERTIES + + /** LocalTime: */ + public ObjectProperty localTimeProperty() { return localTimeObjectProperty; } + private final ObjectProperty localTimeObjectProperty = new SimpleObjectProperty(this, "localTime"); + public LocalTime getLocalTime() { return localTimeObjectProperty.getValue(); } + public void setLocalTime(LocalTime value) { localTimeObjectProperty.setValue(value); } + public LocalTimeTextField withLocalTime(LocalTime value) { setLocalTime(value); return this; } + private void constructLocalTime() + { + // if this value is changed by binding, make sure related things are updated + calendarProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) + { + localTimeProperty().set(DateTimeUtil.createLocalTimeFromCalendar(newValue)); + } + }); + + // if the inherited value is changed, make sure calendar is updated + localTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalTime oldValue, LocalTime newValue) + { + calendarProperty().set( newValue == null ? null : DateTimeUtil.createCalendarFromLocalTime(newValue)); + } + }); + } + + + // ================================================================================================================== + // SUPPORT +} diff --git a/src/main/java/jfxtras/labs/util/DateTimeUtil.java b/src/main/java/jfxtras/labs/util/DateTimeUtil.java new file mode 100644 index 000000000..157f42877 --- /dev/null +++ b/src/main/java/jfxtras/labs/util/DateTimeUtil.java @@ -0,0 +1,101 @@ +package jfxtras.labs.util; + +import java.util.Calendar; +import java.util.Locale; + +import javax.time.calendar.LocalDate; +import javax.time.calendar.LocalDateTime; +import javax.time.calendar.LocalTime; + +public class DateTimeUtil +{ + /** + * + * @param localDate + * @return + */ + public static Calendar createCalendarFromLocalDate(LocalDate localDate, Locale locale) + { + if (localDate == null) return null; + Calendar lCalendar = Calendar.getInstance(locale); + lCalendar.set(Calendar.YEAR, localDate.getYear()); + lCalendar.set(Calendar.MONTH, localDate.getMonthOfYear().getValue() - 1); + lCalendar.set(Calendar.DATE, localDate.getDayOfMonth()); + lCalendar.set(Calendar.HOUR_OF_DAY, 0); + lCalendar.set(Calendar.MINUTE, 0); + lCalendar.set(Calendar.SECOND, 0); + lCalendar.set(Calendar.MILLISECOND, 0); + return lCalendar; + } + + /** + * + * @param localDate + * @return + */ + public static Calendar createCalendarFromLocalDateTime(LocalDateTime localDateTime, Locale locale) + { + if (localDateTime == null) return null; + Calendar lCalendar = Calendar.getInstance(locale); + lCalendar.set(Calendar.YEAR, localDateTime.getYear()); + lCalendar.set(Calendar.MONTH, localDateTime.getMonthOfYear().getValue() - 1); + lCalendar.set(Calendar.DATE, localDateTime.getDayOfMonth()); + lCalendar.set(Calendar.HOUR_OF_DAY, localDateTime.getHourOfDay()); + lCalendar.set(Calendar.MINUTE, localDateTime.getMinuteOfHour()); + lCalendar.set(Calendar.SECOND, localDateTime.getSecondOfMinute()); + lCalendar.set(Calendar.MILLISECOND, localDateTime.getNanoOfSecond() / 1000000); + return lCalendar; + } + + /** + * + * @param localDate + * @return + */ + public static Calendar createCalendarFromLocalTime(LocalTime localTime) + { + if (localTime == null) return null; + Calendar lCalendar = Calendar.getInstance(); + lCalendar.set(Calendar.HOUR_OF_DAY, localTime.getHourOfDay()); + lCalendar.set(Calendar.MINUTE, localTime.getMinuteOfHour()); + lCalendar.set(Calendar.SECOND, localTime.getSecondOfMinute()); + lCalendar.set(Calendar.MILLISECOND, localTime.getNanoOfSecond() / 1000000); + return lCalendar; + } + + /** + * + * @param calendar + * @return + */ + public static LocalDate createLocalDateFromCalendar(Calendar calendar) + { + if (calendar == null) return null; + LocalDate lLocalDate = LocalDate.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DATE)); + return lLocalDate; + } + + /** + * + * @param calendar + * @return + */ + public static LocalDateTime createLocalDateTimeFromCalendar(Calendar calendar) + { + if (calendar == null) return null; + LocalDateTime lLocalDateTime = LocalDateTime.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DATE), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND) * 1000000); + return lLocalDateTime; + } + + /** + * + * @param calendar + * @return + */ + public static LocalTime createLocalTimeFromCalendar(Calendar calendar) + { + if (calendar == null) return null; + LocalTime lLocalTime = LocalTime.of(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND) * 1000000); + return lLocalTime; + } +} diff --git a/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTextField.css b/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTextField.css index 682bc68ac..8a506fb32 100644 --- a/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTextField.css +++ b/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTextField.css @@ -2,6 +2,9 @@ .CalendarTextField { -fx-skin: "jfxtras.labs.internal.scene.control.skin.CalendarTextFieldCaspianSkin"; } +.LocalDateTimeTextField { + -fx-skin: "jfxtras.labs.internal.scene.control.skin.CalendarTextFieldCaspianSkin"; +} .CalendarTextFieldCaspianSkin .icon { -fx-image: url("skin/CalendarTextFieldCaspianSkinIcon.png"); diff --git a/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimePicker.css b/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimePicker.css index cf9c705e4..8ec27c596 100644 --- a/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimePicker.css +++ b/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimePicker.css @@ -2,6 +2,9 @@ .CalendarTimePicker { -fx-skin: "jfxtras.labs.internal.scene.control.skin.CalendarTimePickerSkin"; } +.LocalTimePicker { + -fx-skin: "jfxtras.labs.internal.scene.control.skin.CalendarTimePickerSkin"; +} /* skin level .CalendarTimePickerSkin { diff --git a/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimeTextField.css b/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimeTextField.css index d5f38b334..23a58696c 100644 --- a/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimeTextField.css +++ b/src/main/resources/jfxtras/labs/internal/scene/control/CalendarTimeTextField.css @@ -2,6 +2,9 @@ .CalendarTimeTextField { -fx-skin: "jfxtras.labs.internal.scene.control.skin.CalendarTimeTextFieldCaspianSkin"; } +.LocalTimeTextField { + -fx-skin: "jfxtras.labs.internal.scene.control.skin.CalendarTimeTextFieldCaspianSkin"; +} .CalendarTimeTextFieldCaspianSkin .icon { -fx-image: url("skin/CalendarTimeTextFieldCaspianSkinIcon.png"); diff --git a/src/test/java/jfxtras/labs/scene/control/AgendaTrial1.java b/src/test/java/jfxtras/labs/scene/control/AgendaTrial1.java index 8e649f5e6..efb56147d 100644 --- a/src/test/java/jfxtras/labs/scene/control/AgendaTrial1.java +++ b/src/test/java/jfxtras/labs/scene/control/AgendaTrial1.java @@ -307,7 +307,7 @@ public Void call(CalendarRange arg0) HBox lHBox = new HBox(); CalendarTextField lCalendarTextField = new CalendarTextField(); - lCalendarTextField.valueProperty().bindBidirectional(lAgenda.displayedCalendar()); + lCalendarTextField.calendarProperty().bindBidirectional(lAgenda.displayedCalendar()); lHBox.getChildren().add(lCalendarTextField); // create scene diff --git a/src/test/java/jfxtras/labs/scene/control/BeanPathAdapterTrial1.java b/src/test/java/jfxtras/labs/scene/control/BeanPathAdapterTrial1.java index ca6b1437e..159cff6d1 100644 --- a/src/test/java/jfxtras/labs/scene/control/BeanPathAdapterTrial1.java +++ b/src/test/java/jfxtras/labs/scene/control/BeanPathAdapterTrial1.java @@ -455,7 +455,7 @@ private boolean matchTest(String text) { ctrl = tf; } else if (controlType == CalendarTextField.class) { final CalendarTextField ctf = new CalendarTextField(); - personPA.bindBidirectional(path, ctf.valueProperty(), + personPA.bindBidirectional(path, ctf.calendarProperty(), Calendar.class); ctrl = ctf; } else if (controlType == ListSpinner.class) { diff --git a/src/test/java/jfxtras/labs/scene/control/CalendarLabelDemo.java b/src/test/java/jfxtras/labs/scene/control/CalendarLabelDemo.java index 1f6573f46..268ccad53 100644 --- a/src/test/java/jfxtras/labs/scene/control/CalendarLabelDemo.java +++ b/src/test/java/jfxtras/labs/scene/control/CalendarLabelDemo.java @@ -63,9 +63,9 @@ public void start(Stage primaryStage) { root.setVgap(10); root.setPadding(new Insets(10, 10, 10, 10)); final CalendarTextField calendarField = new CalendarTextField(); - calendarField.setValue(new GregorianCalendar()); + calendarField.setCalendar(new GregorianCalendar()); final CalendarLabel calendarLabel = new CalendarLabel(); - calendarLabel.valueProperty().bind(calendarField.valueProperty()); + calendarLabel.valueProperty().bind(calendarField.calendarProperty()); root.addRow(1, new Label("CalendarTextField:"), calendarField); root.addRow(2, new Label("CalendarLabel"), calendarLabel); Button btnSetUKFormat = new Button("MEDIUM UK DateFormat"); diff --git a/src/test/java/jfxtras/labs/scene/control/CalendarTextFieldTrial1.java b/src/test/java/jfxtras/labs/scene/control/CalendarTextFieldTrial1.java index ef79401c0..a8933bbd0 100644 --- a/src/test/java/jfxtras/labs/scene/control/CalendarTextFieldTrial1.java +++ b/src/test/java/jfxtras/labs/scene/control/CalendarTextFieldTrial1.java @@ -73,7 +73,7 @@ public void start(Stage stage) { lGridPane.add(lCalendarTextField, 1, lRowIdx); final TextField lValueTextField = new TextField(); - lCalendarTextField.valueProperty().addListener(new ChangeListener() + lCalendarTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) @@ -81,7 +81,7 @@ public void changed(ObservableValue observableValue, Calenda lValueTextField.setText(CalendarPicker.quickFormatCalendar(newValue)); } }); - lValueTextField.setText(CalendarPicker.quickFormatCalendar(lCalendarTextField.getValue())); + lValueTextField.setText(CalendarPicker.quickFormatCalendar(lCalendarTextField.getCalendar())); lValueTextField.setDisable(true); lGridPane.add(lValueTextField, 2, lRowIdx++); } @@ -92,7 +92,7 @@ public void changed(ObservableValue observableValue, Calenda CalendarTextField lCalendarTextField = new CalendarTextField(); lGridPane.add(lCalendarTextField, 1, lRowIdx++); - lCalendarTextField.valueProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value + lCalendarTextField.calendarProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value lCalendarTextField.parseErrorCallbackProperty().set(new Callback() { @Override @@ -115,7 +115,7 @@ public Void call(Throwable t) lGridPane.add(lCalendarTextField, 1, lRowIdx); final TextField lValueTextField = new TextField(); - lCalendarTextField.valueProperty().addListener(new ChangeListener() + lCalendarTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) @@ -123,13 +123,13 @@ public void changed(ObservableValue observableValue, Calenda lValueTextField.setText(CalendarPicker.quickFormatCalendar(newValue)); } }); - lValueTextField.setText(CalendarPicker.quickFormatCalendar(lCalendarTextField.getValue())); + lValueTextField.setText(CalendarPicker.quickFormatCalendar(lCalendarTextField.getCalendar())); lValueTextField.setDisable(true); lGridPane.add(lValueTextField, 2, lRowIdx++); // set - lCalendarTextField.setValue(Calendar.getInstance()); - lCalendarTextField.setValue(null); + lCalendarTextField.setCalendar(Calendar.getInstance()); + lCalendarTextField.setCalendar(null); } // preset value with time @@ -139,7 +139,7 @@ public void changed(ObservableValue observableValue, Calenda lCalendarTextField.dateFormatProperty().set(SimpleDateFormat.getDateTimeInstance()); lGridPane.add(lCalendarTextField, 1, lRowIdx++); - lCalendarTextField.valueProperty().set(Calendar.getInstance()); // set a value + lCalendarTextField.calendarProperty().set(Calendar.getInstance()); // set a value } // alternate parsers @@ -150,7 +150,7 @@ public void changed(ObservableValue observableValue, Calenda lCalendarTextField.dateFormatsProperty().add(new SimpleDateFormat("yyyyMMdd")); lGridPane.add(lCalendarTextField, 1, lRowIdx++); - lCalendarTextField.valueProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value + lCalendarTextField.calendarProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value } // disabled @@ -160,7 +160,7 @@ public void changed(ObservableValue observableValue, Calenda lCalendarTextField.disableProperty().set(true); lGridPane.add(lCalendarTextField, 1, lRowIdx++); - lCalendarTextField.valueProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value + lCalendarTextField.calendarProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value } // custom icon @@ -170,7 +170,7 @@ public void changed(ObservableValue observableValue, Calenda lCalendarTextField.setId("custom"); lGridPane.add(lCalendarTextField, 1, lRowIdx++); - lCalendarTextField.valueProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value + lCalendarTextField.calendarProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value } // custom icon disabled @@ -181,7 +181,7 @@ public void changed(ObservableValue observableValue, Calenda lCalendarTextField.disableProperty().set(true); lGridPane.add(lCalendarTextField, 1, lRowIdx++); - lCalendarTextField.valueProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value + lCalendarTextField.calendarProperty().set(new GregorianCalendar(2011, 2, 01)); // set a value } lHBox.getChildren().add(lGridPane); diff --git a/src/test/java/jfxtras/labs/scene/control/CalendarTimePickerTrial1.java b/src/test/java/jfxtras/labs/scene/control/CalendarTimePickerTrial1.java index 1a8228f99..62eb64918 100644 --- a/src/test/java/jfxtras/labs/scene/control/CalendarTimePickerTrial1.java +++ b/src/test/java/jfxtras/labs/scene/control/CalendarTimePickerTrial1.java @@ -45,7 +45,6 @@ public void start(Stage stage) { // add a node CalendarTimePicker lTimePicker = new CalendarTimePicker(); // lTimePicker.setMinuteStep(5); - lTimePicker.setShowLabels(true); // create scene Scene scene = new Scene(lTimePicker, 900, 100); diff --git a/src/test/java/jfxtras/labs/scene/control/CalendarTimeTextFieldTrial1.java b/src/test/java/jfxtras/labs/scene/control/CalendarTimeTextFieldTrial1.java index 632c38f61..c400f624e 100644 --- a/src/test/java/jfxtras/labs/scene/control/CalendarTimeTextFieldTrial1.java +++ b/src/test/java/jfxtras/labs/scene/control/CalendarTimeTextFieldTrial1.java @@ -68,13 +68,13 @@ public void start(Stage stage) { { lGridPane.add(new Label("default"), 0, lRowIdx); CalendarTimeTextField lCalendarTimeTextField = new CalendarTimeTextField(); - lCalendarTimeTextField.setValue(Calendar.getInstance()); + lCalendarTimeTextField.setCalendar(Calendar.getInstance()); lCalendarTimeTextField.setMinuteStep(5); lCalendarTimeTextField.setShowLabels(false); lGridPane.add(lCalendarTimeTextField, 1, lRowIdx); final TextField lValueTextField = new TextField(); - lCalendarTimeTextField.valueProperty().addListener(new ChangeListener() + lCalendarTimeTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) @@ -82,7 +82,7 @@ public void changed(ObservableValue observableValue, Calenda lValueTextField.setText(quickFormatCalendar(newValue)); } }); - lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getValue())); + lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getCalendar())); lValueTextField.setDisable(true); lGridPane.add(lValueTextField, 2, lRowIdx++); } @@ -93,7 +93,7 @@ public void changed(ObservableValue observableValue, Calenda CalendarTimeTextField lCalendarTimeTextField = new CalendarTimeTextField(); lGridPane.add(lCalendarTimeTextField, 1, lRowIdx++); - lCalendarTimeTextField.valueProperty().set(new GregorianCalendar(2011, 2, 01, 13, 45, 30)); // set a value + lCalendarTimeTextField.calendarProperty().set(new GregorianCalendar(2011, 2, 01, 13, 45, 30)); // set a value lCalendarTimeTextField.parseErrorCallbackProperty().set(new Callback() { @Override @@ -116,7 +116,7 @@ public Void call(Throwable t) lGridPane.add(lCalendarTimeTextField, 1, lRowIdx); final TextField lValueTextField = new TextField(); - lCalendarTimeTextField.valueProperty().addListener(new ChangeListener() + lCalendarTimeTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) @@ -124,13 +124,13 @@ public void changed(ObservableValue observableValue, Calenda lValueTextField.setText(quickFormatCalendar(newValue)); } }); - lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getValue())); + lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getCalendar())); lValueTextField.setDisable(true); lGridPane.add(lValueTextField, 2, lRowIdx++); // set - lCalendarTimeTextField.setValue(Calendar.getInstance()); - lCalendarTimeTextField.setValue(null); + lCalendarTimeTextField.setCalendar(Calendar.getInstance()); + lCalendarTimeTextField.setCalendar(null); } // DateFormat @@ -141,7 +141,7 @@ public void changed(ObservableValue observableValue, Calenda lGridPane.add(lCalendarTimeTextField, 1, lRowIdx); final TextField lValueTextField = new TextField(); - lCalendarTimeTextField.valueProperty().addListener(new ChangeListener() + lCalendarTimeTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) @@ -149,7 +149,7 @@ public void changed(ObservableValue observableValue, Calenda lValueTextField.setText(quickFormatCalendar(newValue)); } }); - lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getValue())); + lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getCalendar())); lValueTextField.setDisable(true); lGridPane.add(lValueTextField, 2, lRowIdx++); @@ -165,7 +165,7 @@ public Void call(Throwable t) }); // set - lCalendarTimeTextField.setValue(Calendar.getInstance()); + lCalendarTimeTextField.setCalendar(Calendar.getInstance()); } // DateFormats @@ -179,7 +179,7 @@ public Void call(Throwable t) lGridPane.add(lCalendarTimeTextField, 1, lRowIdx); final TextField lValueTextField = new TextField(); - lCalendarTimeTextField.valueProperty().addListener(new ChangeListener() + lCalendarTimeTextField.calendarProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Calendar oldValue, Calendar newValue) @@ -187,12 +187,12 @@ public void changed(ObservableValue observableValue, Calenda lValueTextField.setText(quickFormatCalendar(newValue)); } }); - lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getValue())); + lValueTextField.setText(quickFormatCalendar(lCalendarTimeTextField.getCalendar())); lValueTextField.setDisable(true); lGridPane.add(lValueTextField, 2, lRowIdx++); // set - lCalendarTimeTextField.setValue(Calendar.getInstance()); + lCalendarTimeTextField.setCalendar(Calendar.getInstance()); } // disabled @@ -202,7 +202,7 @@ public void changed(ObservableValue observableValue, Calenda lCalendarTimeTextField.disableProperty().set(true); lGridPane.add(lCalendarTimeTextField, 1, lRowIdx++); - lCalendarTimeTextField.valueProperty().set(new GregorianCalendar(2011, 2, 01, 13, 45, 30)); // set a value + lCalendarTimeTextField.calendarProperty().set(new GregorianCalendar(2011, 2, 01, 13, 45, 30)); // set a value } lHBox.getChildren().add(lGridPane); diff --git a/src/test/java/jfxtras/labs/scene/control/LocalDatePickerTrial1.java b/src/test/java/jfxtras/labs/scene/control/LocalDateTimePickerTrial1.java similarity index 74% rename from src/test/java/jfxtras/labs/scene/control/LocalDatePickerTrial1.java rename to src/test/java/jfxtras/labs/scene/control/LocalDateTimePickerTrial1.java index 8ea0e76ea..2b53b3976 100644 --- a/src/test/java/jfxtras/labs/scene/control/LocalDatePickerTrial1.java +++ b/src/test/java/jfxtras/labs/scene/control/LocalDateTimePickerTrial1.java @@ -35,12 +35,12 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; -import javax.time.calendar.LocalDate; +import javax.time.calendar.LocalDateTime; /** * @author Tom Eugelink */ -public class LocalDatePickerTrial1 extends Application { +public class LocalDateTimePickerTrial1 extends Application { public static void main(String[] args) { // java.util.Locale.setDefault(new java.util.Locale("de")); // weeks starts on monday @@ -54,17 +54,17 @@ public void start(Stage stage) lVBox.setSpacing(25); // add a node - final LocalDatePicker lLocalDatePicker = new LocalDatePicker(); - lVBox.getChildren().add(lLocalDatePicker); + final LocalDateTimePicker lLocalDateTimePicker = new LocalDateTimePicker(); + lVBox.getChildren().add(lLocalDateTimePicker); // textfield { final TextField lTextField = new TextField(); lTextField.setEditable(false); - lLocalDatePicker.localDateProperty().addListener(new ChangeListener() + lLocalDateTimePicker.localDateProperty().addListener(new ChangeListener() { @Override - public void changed(ObservableValue localDateProperty, LocalDate oldValue, LocalDate newValue) + public void changed(ObservableValue localDateProperty, LocalDateTime oldValue, LocalDateTime newValue) { lTextField.setText(newValue == null ? "null" : newValue.toString()); } @@ -76,22 +76,22 @@ public void changed(ObservableValue localDateProperty, Loca { final TextField lTextField = new TextField(); lTextField.setEditable(false); - lLocalDatePicker.localDates().addListener(new ListChangeListener() + lLocalDateTimePicker.localDates().addListener(new ListChangeListener() { @Override - public void onChanged(javafx.collections.ListChangeListener.Change arg0) + public void onChanged(javafx.collections.ListChangeListener.Change arg0) { - lTextField.setText(lLocalDatePicker.localDates().toString()); + lTextField.setText(lLocalDateTimePicker.localDates().toString()); } }); lVBox.getChildren().add(lTextField); } // setup - lLocalDatePicker.setLocalDate(LocalDate.of(2011, 06, 01)); // set a value -// lLocalDatePicker.setMode(LocalDatePicker.Mode.RANGE); - lLocalDatePicker.setMode(LocalDatePicker.Mode.MULTIPLE); -// lLocalDatePicker.setMode(null); + lLocalDateTimePicker.setLocalDateTime(LocalDateTime.of(2011, 06, 01, 0, 0, 0)); // set a value +// lLocalDateTimePicker.setMode(LocalDateTimePicker.Mode.RANGE); + lLocalDateTimePicker.setMode(LocalDateTimePicker.Mode.MULTIPLE); +// lLocalDateTimePicker.setMode(null); // create scene Scene scene = new Scene(lVBox, 300, 300); diff --git a/src/test/java/jfxtras/labs/scene/control/LocalDateTimeTextFieldTrial1.java b/src/test/java/jfxtras/labs/scene/control/LocalDateTimeTextFieldTrial1.java new file mode 100644 index 000000000..23e99892a --- /dev/null +++ b/src/test/java/jfxtras/labs/scene/control/LocalDateTimeTextFieldTrial1.java @@ -0,0 +1,203 @@ +/** + * Copyright (c) 2011, JFXtras + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package jfxtras.labs.scene.control; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +import javafx.application.Application; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.control.Tooltip; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; +import javafx.util.Callback; + +import javax.time.calendar.LocalDateTime; + +/** + * @author Tom Eugelink + */ +public class LocalDateTimeTextFieldTrial1 extends Application { + + public static void main(String[] args) { + //java.util.Locale.setDefault(new java.util.Locale("de")); // weeks starts on monday + launch(args); + } + + @Override + public void start(Stage stage) { + + HBox lHBox = new HBox(); + LocalDateTimeTextField lFocusRequestingLocalDateTimeTextField = null; + + { + GridPane lGridPane = new GridPane(); + lGridPane.setVgap(5.0); + lGridPane.setPadding(new Insets(5.0)); + int lRowIdx = 0; + + // default textfield + { + lGridPane.add(new Label("default"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lLocalDateTimeTextField.setTooltip(new Tooltip("custom tooltip")); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx); + + final TextField lValueTextField = new TextField(); + lLocalDateTimeTextField.localDateTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalDateTime oldValue, LocalDateTime newValue) + { + lValueTextField.setText("" + newValue); + } + }); + lValueTextField.setText("" + lLocalDateTimeTextField.getLocalDateTime()); + lValueTextField.setDisable(true); + lGridPane.add(lValueTextField, 2, lRowIdx++); + } + + // preset value + { + lGridPane.add(new Label("preset value with parse error"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx++); + + lLocalDateTimeTextField.localDateTimeProperty().set(LocalDateTime.of(2011, 2, 01, 21, 22, 23)); // set a value + lLocalDateTimeTextField.parseErrorCallbackProperty().set(new Callback() + { + @Override + public Void call(Throwable t) + { + System.out.println("parse error: " + t.getMessage()); + return null; + } + }); + + // test requesting focus + lFocusRequestingLocalDateTimeTextField = lLocalDateTimeTextField; + } + + // programmatically set to null + { + lGridPane.add(new Label("programatically to null"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lLocalDateTimeTextField.setPromptText("type date here"); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx); + + final TextField lValueTextField = new TextField(); + lLocalDateTimeTextField.localDateTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalDateTime oldValue, LocalDateTime newValue) + { + lValueTextField.setText("" + newValue); + } + }); + lValueTextField.setText("" + lLocalDateTimeTextField.getLocalDateTime()); + lValueTextField.setDisable(true); + lGridPane.add(lValueTextField, 2, lRowIdx++); + + // set + lLocalDateTimeTextField.setCalendar(Calendar.getInstance()); + lLocalDateTimeTextField.setCalendar(null); + } + + // preset value with time + { + lGridPane.add(new Label("preset value with time"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lLocalDateTimeTextField.dateFormatProperty().set(SimpleDateFormat.getDateTimeInstance()); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx++); + + lLocalDateTimeTextField.localDateTimeProperty().set(LocalDateTime.now()); // set a value + } + + // alternate parsers + { + lGridPane.add(new Label("alternate parser"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lLocalDateTimeTextField.dateFormatsProperty().add(new SimpleDateFormat("yyyy-MM-dd")); + lLocalDateTimeTextField.dateFormatsProperty().add(new SimpleDateFormat("yyyyMMdd")); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx++); + + lLocalDateTimeTextField.localDateTimeProperty().set(LocalDateTime.of(2011, 2, 01, 21, 22, 23)); // set a value + } + + // disabled + { + lGridPane.add(new Label("custom icon disabled"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lLocalDateTimeTextField.disableProperty().set(true); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx++); + + lLocalDateTimeTextField.localDateTimeProperty().set(LocalDateTime.of(2011, 2, 01, 21, 22, 23)); // set a value + } + + // custom icon + { + lGridPane.add(new Label("custom icon"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lLocalDateTimeTextField.setId("custom"); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx++); + + lLocalDateTimeTextField.localDateTimeProperty().set(LocalDateTime.of(2011, 2, 01, 21, 22, 23)); // set a value + } + + // custom icon disabled + { + lGridPane.add(new Label("custom icon disabled"), 0, lRowIdx); + LocalDateTimeTextField lLocalDateTimeTextField = new LocalDateTimeTextField(); + lLocalDateTimeTextField.setId("custom"); + lLocalDateTimeTextField.disableProperty().set(true); + lGridPane.add(lLocalDateTimeTextField, 1, lRowIdx++); + + lLocalDateTimeTextField.localDateTimeProperty().set(LocalDateTime.of(2011, 2, 01, 21, 22, 23)); // set a value + } + + lHBox.getChildren().add(lGridPane); + } + + // create scene + Scene scene = new Scene(lHBox, 800, 600); + + // load custom CSS + //scene.getStylesheets().addAll(this.getClass().getResource(this.getClass().getSimpleName() + ".css").toExternalForm()); + + // create stage + stage.setTitle(this.getClass().getSimpleName()); + stage.setScene(scene); + stage.show(); + lFocusRequestingLocalDateTimeTextField.requestFocus(); + } +} diff --git a/src/test/java/jfxtras/labs/scene/control/LocalTimePickerTrial1.java b/src/test/java/jfxtras/labs/scene/control/LocalTimePickerTrial1.java new file mode 100644 index 000000000..119e4c870 --- /dev/null +++ b/src/test/java/jfxtras/labs/scene/control/LocalTimePickerTrial1.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2011, JFXtras + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package jfxtras.labs.scene.control; + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.stage.Stage; + +/** + * @author Tom Eugelink + */ +public class LocalTimePickerTrial1 extends Application { + + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage stage) { + + // add a node + LocalTimePicker lTimePicker = new LocalTimePicker(); +// lTimePicker.setMinuteStep(5); + + // create scene + Scene scene = new Scene(lTimePicker, 900, 100); + + // create stage + stage.setTitle(this.getClass().getSimpleName()); + stage.setScene(scene); + stage.show(); + } +} diff --git a/src/test/java/jfxtras/labs/scene/control/LocalTimeTextFieldTrial1.java b/src/test/java/jfxtras/labs/scene/control/LocalTimeTextFieldTrial1.java new file mode 100644 index 000000000..ca041e1ee --- /dev/null +++ b/src/test/java/jfxtras/labs/scene/control/LocalTimeTextFieldTrial1.java @@ -0,0 +1,223 @@ +/** + * Copyright (c) 2011, JFXtras + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package jfxtras.labs.scene.control; + +import java.text.SimpleDateFormat; + +import javax.time.calendar.LocalTime; + +import javafx.application.Application; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; +import javafx.util.Callback; + +/** + * @author Tom Eugelink + */ +public class LocalTimeTextFieldTrial1 extends Application { + + public static void main(String[] args) { + //java.util.Locale.setDefault(new java.util.Locale("de")); // weeks starts on monday + launch(args); + } + + @Override + public void start(Stage stage) { + + HBox lHBox = new HBox(); + LocalTimeTextField lFocusRequestingLocalTimeTextField = null; + + { + GridPane lGridPane = new GridPane(); + lGridPane.setVgap(5.0); + lGridPane.setPadding(new Insets(5.0)); + int lRowIdx = 0; + + // default textfield + { + lGridPane.add(new Label("default"), 0, lRowIdx); + LocalTimeTextField lLocalTimeTextField = new LocalTimeTextField(); + lLocalTimeTextField.setLocalTime(LocalTime.now()); + lLocalTimeTextField.setMinuteStep(5); + lLocalTimeTextField.setShowLabels(false); + lGridPane.add(lLocalTimeTextField, 1, lRowIdx); + + final TextField lValueTextField = new TextField(); + lLocalTimeTextField.localTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalTime oldValue, LocalTime newValue) + { + lValueTextField.setText("" + newValue); + } + }); + lValueTextField.setText("" + lLocalTimeTextField.getLocalTime()); + lValueTextField.setDisable(true); + lGridPane.add(lValueTextField, 2, lRowIdx++); + } + + // preset value + { + lGridPane.add(new Label("preset value"), 0, lRowIdx); + LocalTimeTextField lLocalTimeTextField = new LocalTimeTextField(); + lGridPane.add(lLocalTimeTextField, 1, lRowIdx++); + + lLocalTimeTextField.localTimeProperty().set(LocalTime.of(13, 45, 30)); // set a value + lLocalTimeTextField.parseErrorCallbackProperty().set(new Callback() + { + @Override + public Void call(Throwable t) + { + System.out.println("parse error: " + t.getMessage()); + return null; + } + }); + + // for setting focus + lFocusRequestingLocalTimeTextField = lLocalTimeTextField; + } + + // programmatically set to null + { + lGridPane.add(new Label("programatically to null"), 0, lRowIdx); + LocalTimeTextField lLocalTimeTextField = new LocalTimeTextField(); + lLocalTimeTextField.setPromptText("type time here"); + lGridPane.add(lLocalTimeTextField, 1, lRowIdx); + + final TextField lValueTextField = new TextField(); + lLocalTimeTextField.localTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalTime oldValue, LocalTime newValue) + { + lValueTextField.setText("" + newValue); + } + }); + lValueTextField.setText("" + lLocalTimeTextField.getLocalTime()); + lValueTextField.setDisable(true); + lGridPane.add(lValueTextField, 2, lRowIdx++); + + // set + lLocalTimeTextField.setLocalTime(LocalTime.now()); + lLocalTimeTextField.setLocalTime(null); + } + + // DateFormat + { + lGridPane.add(new Label("date format"), 0, lRowIdx); + LocalTimeTextField lLocalTimeTextField = new LocalTimeTextField(); + lLocalTimeTextField.setDateFormat(new SimpleDateFormat("HH:mm:ss.SSS")); + lGridPane.add(lLocalTimeTextField, 1, lRowIdx); + + final TextField lValueTextField = new TextField(); + lLocalTimeTextField.localTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalTime oldValue, LocalTime newValue) + { + lValueTextField.setText("" + newValue); + } + }); + lValueTextField.setText("" + lLocalTimeTextField.getLocalTime()); + lValueTextField.setDisable(true); + lGridPane.add(lValueTextField, 2, lRowIdx++); + + // process an error + lLocalTimeTextField.parseErrorCallbackProperty().set(new Callback() + { + @Override + public Void call(Throwable t) + { + System.out.println("parse error: " + t.getMessage()); + return null; + } + }); + + // set + lLocalTimeTextField.setLocalTime(LocalTime.now()); + } + + // DateFormats + { + lGridPane.add(new Label("multiple date formats"), 0, lRowIdx); + LocalTimeTextField lLocalTimeTextField = new LocalTimeTextField(); + lLocalTimeTextField.setDateFormat(new SimpleDateFormat("HH:mm:ss")); + lLocalTimeTextField.dateFormatsProperty().add(new SimpleDateFormat("HH:mm:ss.SSS")); + lLocalTimeTextField.dateFormatsProperty().add(new SimpleDateFormat("HH:mm")); + lLocalTimeTextField.dateFormatsProperty().add(new SimpleDateFormat("HH")); + lGridPane.add(lLocalTimeTextField, 1, lRowIdx); + + final TextField lValueTextField = new TextField(); + lLocalTimeTextField.localTimeProperty().addListener(new ChangeListener() + { + @Override + public void changed(ObservableValue observableValue, LocalTime oldValue, LocalTime newValue) + { + lValueTextField.setText("" + newValue); + } + }); + lValueTextField.setText("" + lLocalTimeTextField.getLocalTime()); + lValueTextField.setDisable(true); + lGridPane.add(lValueTextField, 2, lRowIdx++); + + // set + lLocalTimeTextField.setLocalTime(LocalTime.now()); + } + + // disabled + { + lGridPane.add(new Label("disabled"), 0, lRowIdx); + LocalTimeTextField lLocalTimeTextField = new LocalTimeTextField(); + lLocalTimeTextField.disableProperty().set(true); + lGridPane.add(lLocalTimeTextField, 1, lRowIdx++); + + lLocalTimeTextField.localTimeProperty().set(javax.time.calendar.LocalTime.of(13, 45, 30)); // set a value + } + + lHBox.getChildren().add(lGridPane); + } + + + // create scene + Scene scene = new Scene(lHBox, 800, 600); + + // create stage + stage.setTitle(this.getClass().getSimpleName()); + stage.setScene(scene); + stage.show(); + + // set focus + lFocusRequestingLocalTimeTextField.requestFocus(); + } +}