Skip to content

Commit

Permalink
✨ Added fluent API builders for MaterialFX components and JavaFX pane…
Browse files Browse the repository at this point in the history
…s, as requested by #78

Signed-off-by: palexdev <alessandro.parisi406@gmail.com>
  • Loading branch information
palexdev committed Feb 3, 2022
1 parent ff4b4f4 commit c450e16
Show file tree
Hide file tree
Showing 52 changed files with 5,220 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ColorUtils: added some new methods to convert Colors to Strings
- FunctionalStringConverter: added two new convenience methods
- New utils class SwingFXUtils (copied from javafx.embed.swing)
- Added fluent API builders for MaterialFX components and JavaFX Panes, as requested by #78

### Changed
- ColorUtils: changed some method to be null-safe
Expand Down
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2022 Parisi Alessandro
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX).
*
* MaterialFX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see <http://www.gnu.org/licenses/>.
*/

package io.github.palexdev.materialfx.builders.base;

import io.github.palexdev.materialfx.controls.base.AbstractMFXListView;
import io.github.palexdev.materialfx.effects.DepthLevel;
import io.github.palexdev.virtualizedfx.cell.Cell;
import javafx.collections.ObservableList;
import javafx.scene.paint.Paint;
import javafx.util.Duration;
import javafx.util.StringConverter;

public class BaseListViewBuilder<T, C extends Cell<T>, L extends AbstractMFXListView<T, C>> extends ControlBuilder<L> {

//================================================================================
// Constructors
//================================================================================
public BaseListViewBuilder(L control) {
super(control);
}

public static <T, C extends Cell<T>> BaseListViewBuilder<T, C, AbstractMFXListView<T, C>> baseList(AbstractMFXListView<T, C> list) {
return new BaseListViewBuilder<>(list);
}

//================================================================================
// Delegate Methods
//================================================================================

public BaseListViewBuilder<T, C, L> setTrackColor(Paint trackColor) {
node.setTrackColor(trackColor);
return this;
}

public BaseListViewBuilder<T, C, L> setThumbColor(Paint thumbColor) {
node.setThumbColor(thumbColor);
return this;
}

public BaseListViewBuilder<T, C, L> setThumbHoverColor(Paint thumbHoverColor) {
node.setThumbHoverColor(thumbHoverColor);
return this;
}

public BaseListViewBuilder<T, C, L> setHideAfter(Duration hideAfter) {
node.setHideAfter(hideAfter);
return this;
}

public BaseListViewBuilder<T, C, L> setItems(ObservableList<T> items) {
node.setItems(items);
return this;
}

public BaseListViewBuilder<T, C, L> setConverter(StringConverter<T> converter) {
node.setConverter(converter);
return this;
}

public BaseListViewBuilder<T, C, L> setHideScrollBars(boolean hideScrollBars) {
node.setHideScrollBars(hideScrollBars);
return this;
}

public BaseListViewBuilder<T, C, L> setDepthLevel(DepthLevel depthLevel) {
node.setDepthLevel(depthLevel);
return this;
}
}
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2022 Parisi Alessandro
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX).
*
* MaterialFX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see <http://www.gnu.org/licenses/>.
*/

package io.github.palexdev.materialfx.builders.base;

import javafx.scene.control.ProgressIndicator;

public class BaseProgressBuilder<P extends ProgressIndicator> extends ControlBuilder<P> {

//================================================================================
// Constructors
//================================================================================
@SuppressWarnings("unchecked")
public BaseProgressBuilder() {
this((P) new ProgressIndicator());
}

public BaseProgressBuilder(P progressIndicator) {
super(progressIndicator);
}

public static BaseProgressBuilder<ProgressIndicator> progressIndicator() {
return new BaseProgressBuilder<>();
}

public static BaseProgressBuilder<ProgressIndicator> progressIndicator(ProgressIndicator progressIndicator) {
return new BaseProgressBuilder<>(progressIndicator);
}

//================================================================================
// Delegate Methods
//================================================================================

public BaseProgressBuilder<P> setProgress(double value) {
node.setProgress(value);
return this;
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2022 Parisi Alessandro
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX).
*
* MaterialFX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see <http://www.gnu.org/licenses/>.
*/

package io.github.palexdev.materialfx.builders.base;

import io.github.palexdev.materialfx.controls.base.AbstractMFXToggleNode;
import javafx.scene.Node;
import javafx.scene.control.ToggleGroup;

public class BaseToggleNodeBuilder<T extends AbstractMFXToggleNode> extends ButtonBaseBuilder<T> {

//================================================================================
// Constructors
//================================================================================
public BaseToggleNodeBuilder(T toggleNode) {
super(toggleNode);
}

public static BaseToggleNodeBuilder<AbstractMFXToggleNode> toggleNode(AbstractMFXToggleNode toggleNode) {
return new BaseToggleNodeBuilder<>(toggleNode);
}

//================================================================================
// Delegate Methods
//================================================================================

public BaseToggleNodeBuilder<T> setLabelLeadingIcon(Node labelLeadingIcon) {
node.setLabelLeadingIcon(labelLeadingIcon);
return this;
}

public BaseToggleNodeBuilder<T> setLabelTrailingIcon(Node labelTrailingIcon) {
node.setLabelTrailingIcon(labelTrailingIcon);
return this;
}

public BaseToggleNodeBuilder<T> setSelected(boolean value) {
node.setSelected(value);
return this;
}

public BaseToggleNodeBuilder<T> setToggleGroup(ToggleGroup value) {
node.setToggleGroup(value);
return this;
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2022 Parisi Alessandro
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX).
*
* MaterialFX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see <http://www.gnu.org/licenses/>.
*/

package io.github.palexdev.materialfx.builders.base;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.ButtonBase;

public class ButtonBaseBuilder<B extends ButtonBase> extends LabeledBuilder<B> {

//================================================================================
// Constructors
//================================================================================
public ButtonBaseBuilder(B buttonBase) {
super(buttonBase);
}

public static ButtonBaseBuilder<ButtonBase> control(ButtonBase buttonBase) {
return new ButtonBaseBuilder<>(buttonBase);
}

//================================================================================
// Delegate Methods
//================================================================================

public ButtonBaseBuilder<B> setOnAction(EventHandler<ActionEvent> handler) {
node.setOnAction(handler);
return this;
}

public ButtonBaseBuilder<B> arm() {
node.arm();
return this;
}

public ButtonBaseBuilder<B> disarm() {
node.disarm();
return this;
}

public ButtonBaseBuilder<B> fire() {
node.fire();
return this;
}
}
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2022 Parisi Alessandro
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX).
*
* MaterialFX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see <http://www.gnu.org/licenses/>.
*/

package io.github.palexdev.materialfx.builders.base;

import io.github.palexdev.materialfx.builders.layout.RegionBuilder;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Control;
import javafx.scene.control.Skin;
import javafx.scene.control.Tooltip;

public class ControlBuilder<C extends Control> extends RegionBuilder<C> {

//================================================================================
// Constructors
//================================================================================
public ControlBuilder(C control) {
super(control);
}

public static ControlBuilder<Control> control(Control control) {
return new ControlBuilder<>(control);
}

//================================================================================
// Delegate Methods
//================================================================================

public ControlBuilder<C> setSkin(Skin<?> value) {
node.setSkin(value);
return this;
}

public ControlBuilder<C> setTooltip(Tooltip value) {
node.setTooltip(value);
return this;
}

public ControlBuilder<C> setContextMenu(ContextMenu value) {
node.setContextMenu(value);
return this;
}
}
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 Parisi Alessandro
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX).
*
* MaterialFX is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see <http://www.gnu.org/licenses/>.
*/

package io.github.palexdev.materialfx.builders.base;

import javafx.scene.Node;

public interface INodeBuilder<N extends Node> {
N getNode();
}

0 comments on commit c450e16

Please sign in to comment.