本文整理汇总了Java中javafx.collections.ObservableList.setAll方法的典型用法代码示例。如果您正苦于以下问题:Java ObservableList.setAll方法的具体用法?Java ObservableList.setAll怎么用?Java ObservableList.setAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.collections.ObservableList
的用法示例。
在下文中一共展示了ObservableList.setAll方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildren
import javafx.collections.ObservableList; //导入方法依赖的package包/类
@Override public ObservableList<TreeItem<Test>> getChildren() {
ObservableList<TreeItem<Test>> children = super.getChildren();
if (!children.isEmpty()) {
if (testRunner.showFailures()) {
List<TreeItem<Test>> failures = children.stream().filter(new Predicate<TreeItem<Test>>() {
@Override public boolean test(TreeItem<Test> t) {
return ((TestTreeItem) t).getState() == State.ERROR || ((TestTreeItem) t).getState() == State.FAILURE;
}
}).collect(Collectors.toList());
children.setAll(failures);
} else {
if (children.containsAll(allChildren)) {
return children;
}
children.setAll(allChildren);
}
} else {
if (test instanceof TestSuite) {
TestSuite suite = (TestSuite) test;
int countTestCases = suite.testCount();
for (int i = 0; i < countTestCases; i++) {
children.add(new TestTreeItem(suite.testAt(i), testRunner));
}
allChildren.setAll(children);
}
}
return children;
}
示例2: map
import javafx.collections.ObservableList; //导入方法依赖的package包/类
public static <F, T> ObservableList<T> map(ObservableList<F> list, Function<F, T> forward, Function<T, F> backward) {
ObservableList<T> newList = FXCollections.observableArrayList();
newList.setAll(Lists.transform(list, forward::apply));
MapToTargetListener<F, T> forwardListener = new MapToTargetListener<>(list, newList, forward);
MapToTargetListener<T, F> backwardListener = new MapToTargetListener<>(newList, list, backward);
forwardListener.updating.bindBidirectional(backwardListener.updating);
list.addListener(forwardListener);
newList.addListener(backwardListener);
return newList;
}
示例3: updateElementsTest
import javafx.collections.ObservableList; //导入方法依赖的package包/类
@Test
public void updateElementsTest()
{
final ObservableList<Model> collection1 = FXCollections.observableArrayList(m -> new ObservableValue[] {
m.textProperty() });
collection1.setAll(new Model("value1"), new Model("value2"), new Model("value3"), new Model("value4"));
final ObservableList<String> collection2 = FXCollections.observableArrayList();
IFXContentBinding.bind(collection2, collection1, Model::getText);
final AtomicReference<ListChangeListener.Change<? extends String>> change = new AtomicReference<>(null);
collection2.addListener((ListChangeListener<String>) c -> {
change.set(c);
});
collection1.get(1).setText("value2bis");
assertNotNull("Change event", change.get());
assertTrue("Has change", change.get().next());
assertTrue("Was added", change.get().wasAdded());
assertTrue("Was removed", change.get().wasRemoved());
assertFalse("Was update", change.get().wasUpdated());
assertFalse("Was permuted", change.get().wasPermutated());
assertEquals("from", 1, change.get().getFrom());
assertEquals("to", 2, change.get().getTo());
assertEquals("Added sub-list", Arrays.asList("value2bis"), change.get().getAddedSubList());
assertEquals("Removed", Arrays.asList("value2"), change.get().getRemoved());
assertFalse("Has more change", change.get().next());
assertEquals(Arrays.asList("value1", "value2bis", "value3", "value4"), collection2);
}
示例4: replaceElementsTest
import javafx.collections.ObservableList; //导入方法依赖的package包/类
@Test
public void replaceElementsTest()
{
final ObservableList<Integer> list1 = FXCollections.observableArrayList(0, 1, 2);
final ObservableList<Integer> list2 = FXCollections.observableArrayList(3);
final ObservableList<Integer> list3 = FXCollections.observableArrayList(4, 5);
final ObservableListAggregation<Integer> listAggregation = new ObservableListAggregation<>(list1, list2, list3);
final AtomicReference<Change<? extends Integer>> change = new AtomicReference<>(null);
listAggregation.addListener((ListChangeListener<Integer>) c -> {
change.set(c);
});
list1.setAll(6, 7, 8);
assertNotNull("Change event", change.get());
assertTrue("Has change", change.get().next());
assertTrue("Was added", change.get().wasAdded());
assertTrue("Was removed", change.get().wasRemoved());
assertFalse("Was update", change.get().wasUpdated());
assertFalse("Was permuted", change.get().wasPermutated());
assertEquals("from", 0, change.get().getFrom());
assertEquals("to", 3, change.get().getTo());
assertEquals("Added sub-list", Arrays.asList(6, 7, 8), change.get().getAddedSubList());
assertEquals("Removed", Arrays.asList(0, 1, 2), change.get().getRemoved());
assertFalse("Has more change", change.get().next());
assertEquals("size", 6, listAggregation.size());
assertEquals("get(0)", Integer.valueOf(6), listAggregation.get(0));
assertEquals("get(1)", Integer.valueOf(7), listAggregation.get(1));
assertEquals("get(2)", Integer.valueOf(8), listAggregation.get(2));
assertEquals("get(3)", Integer.valueOf(3), listAggregation.get(3));
assertEquals("get(4)", Integer.valueOf(4), listAggregation.get(4));
assertEquals("get(5)", Integer.valueOf(5), listAggregation.get(5));
}
示例5: drawVolume
import javafx.collections.ObservableList; //导入方法依赖的package包/类
/**
* Draw Volume bars
*/
public void drawVolume() {
BaseTimeCanvas timeCanvas = this.getTimeCanvas();
if (timeCanvas == null) {
return;
}
BaseYCanvas priceCanvas = this.getYCanvas();
if (priceCanvas == null) {
return;
}
GraphicsContext gc = getGraphicsContext2D();
ObservableList<OHLC> data = FXCollections.observableArrayList();
if (this.ChartTypeProperty.getValue() == ChartType.DAY.ordinal()){
data.setAll(dailyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.WEEK.ordinal()) {
data.setAll(weeklyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.MONTH.ordinal()) {
data.setAll(monthlyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.YEAR.ordinal()) {
data.setAll(yearlyData);
}
boolean bIsStroke = true;
for (int i = 0; i<data.size(); i++) {
OHLC cur = data.get(i);
Color curColor = getBarColor(data, i);
//Draw tail up
Calendar calendar = cur.getDate();
Double x = timeCanvas.getXPosByDay(calendar);
if (x == null){
//continue;
return;
}
Double y = priceCanvas.getYPosByValue(0f);
if (y == null){
//continue;
return;
}
Double volume = new Double(cur.getVolume());
float value = volume.floatValue();
value/=1000000;
value *= 10000;
value = (float)Math.round(value);
value /= 10000;
Double yy= priceCanvas.getYPosByValue(value);
if (yy == null){
System.out.println("Volume is not found at value: " + value + " Date should be : " + cur.getDate().getTime().toString());
continue;
}
gc.setLineWidth(1);
gc.setStroke(curColor);
gc.strokeLine(x, y, x, yy);
}
}
示例6: drawBarChart
import javafx.collections.ObservableList; //导入方法依赖的package包/类
/**
* Draw bar chart
*/
public void drawBarChart() {
BaseTimeCanvas timeCanvas = this.getTimeCanvas();
if (timeCanvas == null) {
return;
}
BaseYCanvas priceCanvas = this.getYCanvas();
if (priceCanvas == null) {
return;
}
GraphicsContext gc = getGraphicsContext2D();
ObservableList<OHLC> data = FXCollections.observableArrayList();
if (this.ChartTypeProperty.getValue() == ChartType.DAY.ordinal()){
data.setAll(dailyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.WEEK.ordinal()) {
data.setAll(weeklyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.MONTH.ordinal()) {
data.setAll(monthlyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.YEAR.ordinal()) {
data.setAll(yearlyData);
}
for (int i = 0; i<data.size(); i++) {
OHLC cur = data.get(i);
Color curColor = getBarColor(data, i);
Calendar calendar = cur.getDate();
Double xCenter = timeCanvas.getXPosByDay(calendar);
if (xCenter == null){
//System.out.println("getXPOSByDate returns Null: " + calendar.getTime().toString());
continue;
}
Double xOpen = xCenter - new Double((xIntervalProperty.getValue()/2)).intValue() + 1;
Double xClose = xCenter + new Double((xIntervalProperty.getValue()/2)).intValue() - 1;
Double yHigh = priceCanvas.getYPosByValue(cur.getHigh());
if (yHigh == null) {
continue;
}
Double yLow = priceCanvas.getYPosByValue(cur.getLow());
if (yLow == null) {
continue;
}
Double yOpen = priceCanvas.getYPosByValue(cur.getOpen());
if (yOpen == null) {
continue;
}
Double yClose = yOpen;
if (cur.getOpen()!= cur.getClose()){
yClose = priceCanvas.getYPosByValue(cur.getClose());
if (yClose == null) {
continue;
}
}
//Draw Bar
gc.setLineWidth(1);
gc.setStroke(curColor);
gc.strokeLine(xCenter, yHigh, xCenter, yLow);
gc.strokeLine(xCenter, yHigh, xCenter, yLow);
gc.strokeLine(xCenter, yHigh, xCenter, yLow);
//Draw tick open
gc.strokeLine(xOpen, yOpen, xCenter, yOpen);
gc.strokeLine(xOpen, yOpen, xCenter, yOpen);
gc.strokeLine(xOpen, yOpen, xCenter, yOpen);
//Draw tick close
gc.strokeLine(xCenter, yClose, xClose, yClose);
gc.strokeLine(xCenter, yClose, xClose, yClose);
gc.strokeLine(xCenter, yClose, xClose, yClose);
}
}
示例7: drawLineChart
import javafx.collections.ObservableList; //导入方法依赖的package包/类
/**
* Draw line chart
*/
public void drawLineChart() {
BaseTimeCanvas timeCanvas = this.getTimeCanvas();
if (timeCanvas == null) {
return;
}
BaseYCanvas priceCanvas = this.getYCanvas();
if (priceCanvas == null) {
return;
}
GraphicsContext gc = getGraphicsContext2D();
gc.setLineWidth(LineChartWidthProperty.getValue());
Color curColor = LineChartColorProperty.getValue();
gc.setStroke(curColor);
ObservableList<OHLC> data = FXCollections.observableArrayList();
if (this.ChartTypeProperty.getValue() == ChartType.DAY.ordinal()){
data.setAll(dailyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.WEEK.ordinal()) {
data.setAll(weeklyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.MONTH.ordinal()) {
data.setAll(monthlyData);
}
else if (this.ChartTypeProperty.getValue() == ChartType.YEAR.ordinal()) {
data.setAll(yearlyData);
}
//Can not draw line if only one point
if (data.size() == 1){
return;
}
for (int i = 0; i<data.size(); i++) {
int j = i + 1;
if (j == data.size()){
//Last point reached
gc.stroke();
gc.closePath();
break;
}
OHLC cur = data.get(i);
OHLC next = data.get(j);
Calendar calendar = cur.getDate();
Calendar nextCalendar = next.getDate();
Double xCenter = timeCanvas.getXPosByDay(calendar);
Double xCenter_next = timeCanvas.getXPosByDay(nextCalendar);
if (xCenter == null || xCenter_next == null){
continue;
}
Double xClose = xCenter + new Double((xIntervalProperty.getValue()/2)).intValue() - 1;
Double xClose_next = xCenter_next + new Double((xIntervalProperty.getValue()/2)).intValue() - 1;
Double yClose = priceCanvas.getYPosByValue(cur.getClose());
Double yClose_next = priceCanvas.getYPosByValue(next.getClose());
if (yClose == null || yClose_next == null) {
continue;
}
//Draw line
if (i == 0){
gc.beginPath();
gc.moveTo(xClose, yClose);
}
gc.lineTo(xClose_next, yClose_next);
}
}
示例8: bind
import javafx.collections.ObservableList; //导入方法依赖的package包/类
/**
* Binds an observable list to a list property.
*
* @param list the observable list to bind
* @param observable the property to bind to
* @param <T> the type of elements in the list
*/
public static <T> void bind(ObservableList<? super T> list,
ObservableValue<? extends List<? extends T>> observable) {
list.setAll(observable.getValue());
observable.addListener((__, oldList, newList) -> list.setAll(newList));
}