B4J Library jToggleSwitch V1.0.0

jToggleSwitch
Author:
DonManfred (wrapper)
Version: 1
  • ToggleSwitch
    Events:
    • selectedChanged (selected As Boolean)
    Fields:
    • ba As BA
    Methods:
    • DesignerCreateView (base As ConcretePaneWrapper, label As LabelWrapper, args As Map)
    • Initialize (arg1 As String)
    • IsInitialized As Boolean
    • RemoveNodeFromParent
    • RequestFocus
    • SetAlphaAnimated (arg0 As Int, arg1 As Double)
    • SetLayoutAnimated (arg0 As Int, arg1 As Double, arg2 As Double, arg3 As Double, arg4 As Double)
    • SetSize (arg0 As Double, arg1 As Double)
    • Snapshot As ImageWrapper
    • Snapshot2 (arg0 As Paint) As ImageWrapper
    • isWrapText As Boolean
    Properties:
    • Alpha As Double
    • ContextMenu As ContextMenuWrapper
    • Enabled As Boolean
    • Height As Double [read only]
    • Id As String
    • LayoutX As Double [write only]
    • LayoutY As Double [write only]
    • Left As Double
    • MouseCursor As Cursor
    • PrefHeight As Double
    • PrefWidth As Double
    • Selected As Boolean
    • Style As String
    • StyleClass As String [write only]
    • StyleClasses As List [read only]
    • Tag As Object
    • Text As String
      Gets or sets the default label text value.
    • TooltipText As String
    • Top As Double
    • Visible As Boolean
    • Width As Double [read only]
    • WrapText As Boolean [write only]

toggleswitch0082.png



If you want to donate for my work building the wrapper you can do it here:
 

Attachments

Here's is a similar toggleswitch made in native Java. It might be of interest to people visiting this thread. Have a look here
 
Allready did. We posted at the same time funny, that's a good omen haha
 
@DonManfred This might help you alot. The Native Java source code

Go here for the source

I also post the code bwlow, for lazy people like myself :p


Code: Copy
package com.almasb.ios;

import javafx.animation.FillTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;

public class IOSApp extends Application {

    private Parent createContent() {
        Pane root = new Pane();
        root.setPrefSize(300, 300);

        Rectangle bg = new Rectangle(300, 300);

        ToggleSwitch toggle = new ToggleSwitch();
        toggle.setTranslateX(100);
        toggle.setTranslateY(100);

        Text text = new Text();
        text.setFont(Font.font(18));
        text.setFill(Color.WHITE);
        text.setTranslateX(100);
        text.setTranslateY(200);
        text.textProperty().bind(Bindings.when(toggle.switchedOnProperty()).then("ON").otherwise("OFF"));

        root.getChildren().addAll(toggle, text);
        return root;
    }

    private static class ToggleSwitch extends Parent {

        private BooleanProperty switchedOn = new SimpleBooleanProperty(false);

        private TranslateTransition translateAnimation = new TranslateTransition(Duration.seconds(0.25));
        private FillTransition fillAnimation = new FillTransition(Duration.seconds(0.25));

        private ParallelTransition animation = new ParallelTransition(translateAnimation, fillAnimation);

        public BooleanProperty switchedOnProperty() {
            return switchedOn;
        }

        public ToggleSwitch() {
            Rectangle background = new Rectangle(100, 50);
            background.setArcWidth(50);
            background.setArcHeight(50);
            background.setFill(Color.WHITE);
            background.setStroke(Color.LIGHTGRAY);

            Circle trigger = new Circle(25);
            trigger.setCenterX(25);
            trigger.setCenterY(25);
            trigger.setFill(Color.WHITE);
            trigger.setStroke(Color.LIGHTGRAY);

            DropShadow shadow = new DropShadow();
            shadow.setRadius(2);
            trigger.setEffect(shadow);

            translateAnimation.setNode(trigger);
            fillAnimation.setShape(background);

            getChildren().addAll(background, trigger);

            switchedOn.addListener((obs, oldState, newState) -> {
                boolean isOn = newState.booleanValue();
                translateAnimation.setToX(isOn ? 100 - 50 : 0);
                fillAnimation.setFromValue(isOn ? Color.WHITE : Color.LIGHTGREEN);
                fillAnimation.setToValue(isOn ? Color.LIGHTGREEN : Color.WHITE);

                animation.play();
            });

            setOnMouseClicked(event -> {
                switchedOn.set(!switchedOn.get());
            });
        }
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(createContent()));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
 
OK in an attempt to put this one to bed, I took a peek at Don Manfreds library, after he gave permission. It wraps the controlsFX Toggleswitch, which is not available in the Java 9 Version.
 
Back
Top