Skip to content

Commit

Permalink
JSR310 additions
Browse files Browse the repository at this point in the history
Conflicts:
	gradle.properties
  • Loading branch information
tbee committed May 21, 2013
1 parent 56e3a8b commit 0d04191
Show file tree
Hide file tree
Showing 27 changed files with 1,014 additions and 301 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -35,7 +35,7 @@
* @author Tom Eugelink
*
*/
public class LocalDatePickerBehavior extends BehaviorBase<LocalDatePicker>
public class LocalDatePickerBehavior extends BehaviorBase<LocalDateTimePicker>
{
// ==================================================================================================================
// CONSTRUCTOR
Expand All @@ -44,7 +44,7 @@ public class LocalDatePickerBehavior extends BehaviorBase<LocalDatePicker>
*
* @param control
*/
public LocalDatePickerBehavior(LocalDatePicker control)
public LocalDatePickerBehavior(LocalDateTimePicker control)
{
super(control);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Calendar>()
lEndCalendarTextField.calendarProperty().addListener(new ChangeListener<Calendar>()
{
@Override
public void changed(ObservableValue<? extends Calendar> arg0, Calendar oldValue, Calendar newValue)
Expand Down Expand Up @@ -1819,15 +1819,15 @@ public void changed(ObservableValue<? extends Boolean> 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
}
});
}
// event handling
lStartCalendarTextField.valueProperty().addListener(new ChangeListener<Calendar>()
lStartCalendarTextField.calendarProperty().addListener(new ChangeListener<Calendar>()
{
@Override
public void changed(ObservableValue<? extends Calendar> arg0, Calendar oldValue, Calendar newValue)
Expand All @@ -1854,7 +1854,7 @@ public void changed(ObservableValue<? extends Calendar> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void construct()
createNodes();

// react to value changes in the model
getSkinnable().valueProperty().addListener(new ChangeListener<Calendar>()
getSkinnable().calendarProperty().addListener(new ChangeListener<Calendar>()
{
@Override
public void changed(ObservableValue<? extends Calendar> observableValue, Calendar oldValue, Calendar newValue)
Expand All @@ -108,7 +108,7 @@ public void changed(ObservableValue<? extends Calendar> 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 );
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
});
Expand Down Expand Up @@ -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<Calendar>()
{
@Override
Expand Down Expand Up @@ -270,7 +270,7 @@ private void parse()
lText = lText.trim();
if (lText.length() == 0)
{
getSkinnable().setValue(null);
getSkinnable().setCalendar(null);
return;
}

Expand All @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}

// ==================================================================================================================
Expand All @@ -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<Number>()
{
Expand Down Expand Up @@ -177,116 +162,6 @@ public void changed(ObservableValue<? extends Number> 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));
}
}
};

/**
*
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 0d04191

Please sign in to comment.