diff --git a/.gradle/2.2.1/taskArtifacts/cache.properties b/.gradle/2.2.1/taskArtifacts/cache.properties new file mode 100644 index 0000000..4a1fbd6 --- /dev/null +++ b/.gradle/2.2.1/taskArtifacts/cache.properties @@ -0,0 +1 @@ +#Tue Jun 16 19:33:16 CEST 2015 diff --git a/.gradle/2.2.1/taskArtifacts/cache.properties.lock b/.gradle/2.2.1/taskArtifacts/cache.properties.lock new file mode 100644 index 0000000..8e82b4d Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/cache.properties.lock differ diff --git a/.gradle/2.2.1/taskArtifacts/fileHashes.bin b/.gradle/2.2.1/taskArtifacts/fileHashes.bin new file mode 100644 index 0000000..d589b74 Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/fileHashes.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin b/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin new file mode 100644 index 0000000..1583500 Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/outputFileStates.bin b/.gradle/2.2.1/taskArtifacts/outputFileStates.bin new file mode 100644 index 0000000..143931d Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/outputFileStates.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin b/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin new file mode 100644 index 0000000..915bc2e Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin differ diff --git a/README.md b/README.md index 4449879..89e9351 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # HelloCharm + HelloWorld sample to introduce Gluon Charm capabilities + +Get Charm [here](http://gluonhq.com/products/charm/downloads/) + +Read the documentation [here](http://docs.gluonhq.com/charm/0.0.1/) + +Access the JavaDoc [here](http://docs.gluonhq.com/javadoc/0.0.1/) + +For questions, go to the forum [here](http://gluonhq.com/forums/) \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..0a85731 --- /dev/null +++ b/build.gradle @@ -0,0 +1,49 @@ +buildscript { + repositories { + jcenter() + maven { + url 'https://oss.sonatype.org/content/repositories/snapshots/' + } + } + dependencies { + classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b10-SNAPSHOT' + } +} + +apply plugin: 'org.javafxports.jfxmobile' + +repositories { + jcenter() + maven { + credentials { + File propsFile = file("C:\\Java\\repo.properties"); + if (propsFile.exists()) { + Properties props = new Properties(); + props.load(new FileInputStream(propsFile)) + username props.getProperty('ALIAS') + password props.getProperty('PASSWORD') + } + } + url 'http://gluonhq.com:8081/nexus/content/repositories/snapshots/' + } + maven { + url 'https://oss.sonatype.org/content/repositories/snapshots/' + } +} + +ext.GLUON_VERSION = "0.0.1-SNAPSHOT" + +dependencies { + compile "com.gluonhq:charm:$GLUON_VERSION" + desktopRuntime "com.gluonhq:charm-desktop:$GLUON_VERSION" + androidRuntime "com.gluonhq:charm-android:$GLUON_VERSION" + iosRuntime "com.gluonhq:charm-ios:$GLUON_VERSION" +} + +mainClassName = 'org.jpereda.charm.HelloCharm' + +jfxmobile { + ios { + forceLinkClasses = [ 'org.jpereda.charm.**.*', 'com.gluonhq.charm.down.**.*' ] + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..2322723 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..1a620d1 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Feb 27 12:47:11 CET 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/org/jpereda/charm/HelloCharm.java b/src/main/java/org/jpereda/charm/HelloCharm.java new file mode 100644 index 0000000..2f802c3 --- /dev/null +++ b/src/main/java/org/jpereda/charm/HelloCharm.java @@ -0,0 +1,222 @@ +package org.jpereda.charm; + +import com.gluonhq.charm.down.common.JavaFXPlatform; +import com.gluonhq.charm.glisten.application.MobileApplication; +import static com.gluonhq.charm.glisten.application.MobileApplication.HOME_VIEW; +import com.gluonhq.charm.glisten.control.Dialog; +import com.gluonhq.charm.glisten.control.Icon; +import com.gluonhq.charm.glisten.layout.layer.MenuPopupView; +import com.gluonhq.charm.glisten.layout.layer.SidePopupView; +import com.gluonhq.charm.glisten.mvc.View; +import com.gluonhq.charm.glisten.visual.MaterialDesignIcon; +import com.gluonhq.charm.glisten.visual.Swatch; +import java.util.Optional; +import javafx.application.Platform; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.geometry.Side; +import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Label; +import javafx.scene.control.Menu; +import javafx.scene.control.MenuItem; +import javafx.scene.control.ToggleButton; +import javafx.scene.control.ToolBar; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; +import javafx.scene.layout.VBox; + +public class HelloCharm extends MobileApplication { + + private final Label labelDialog = new Label(); + private final Label labelCheck = new Label(); + private ToolBar homeToolbar; + + + @Override + public void init() throws Exception { + super.init(); + + /* + Create default home view + */ + addViewFactory(HOME_VIEW, ()->{ + View home = new View("Home View"); + + VBox vBox = new VBox(20,new Label("Hello Charm!"),labelDialog,labelCheck); + vBox.setAlignment(Pos.CENTER); + + home.setCenter(vBox); + + /* + BOTTOM + */ + homeToolbar = new ToolBar(); + + Button menu = new Button(null,new Icon(MaterialDesignIcon.MENU)); + menu.setOnAction(e->showLayer("Side Menu")); + + Button dialog = new Button(null, new Icon(MaterialDesignIcon.DIALPAD)); + dialog.setOnAction(e->showDialog()); + + HBox hbox = new HBox(); + HBox.setHgrow(hbox, Priority.ALWAYS); + + Button more = new Button(null,new Icon(MaterialDesignIcon.MORE_VERT)); + more.setOnAction(e->showLayer("Popup")); + + homeToolbar.getItems().addAll(menu,dialog,hbox,more); + + home.setBottom(homeToolbar); + + /* + JavaFX thread + */ + home.showingProperty().addListener((obs,b,b1)->{ + if(b1){ + home.setSwatch(Swatch.AMBER); + + if(JavaFXPlatform.isDesktop()){ + home.getScene().getWindow().setWidth(400); + home.getScene().getWindow().setHeight(700); + } + } + }); + + return home; + }); + + /* + Other View + */ + + addViewFactory("Other View", ()->{ + View otherView = new View("Other View"); + + otherView.setCenter(new Label("Other view")); + + /* + BOTTOM + */ + ToolBar toolBar = new ToolBar(); + + Button menu = new Button(null,new Icon(MaterialDesignIcon.MENU)); + menu.setOnAction(e->showLayer("Side Menu")); + + toolBar.getItems().add(menu); + + otherView.setBottom(toolBar); + + return otherView; + }); + + /* + SideMenu + */ + addLayerFactory("Side Menu", ()->{ + BorderPane borderPane = new BorderPane(); + borderPane.setStyle("-fx-background-color: -primary-swatch-100;"); + borderPane.setPrefWidth(200); + + Label labelTop = new Label("User not registered",MaterialDesignIcon.ACCOUNT_CIRCLE.graphic()); + HBox hbox = new HBox(labelTop); + hbox.setPadding(new Insets(20)); + hbox.setAlignment(Pos.CENTER_LEFT); + hbox.setStyle("-fx-background-color: -primary-swatch-500;"); + + borderPane.setTop(hbox); + + HBox homeView = new HBox(new Label("Home View",MaterialDesignIcon.HOME.graphic())); + homeView.setAlignment(Pos.CENTER_LEFT); + homeView.setPrefHeight(50); + homeView.setStyle("-fx-padding: 0 10 0 10;-fx-border-color: #e0e0e0; -fx-border-width: 1 0 0 0;"); + homeView.setOnMouseClicked(e->{ + hideLayer("Side Menu"); + switchView(HOME_VIEW); + }); + + HBox otherView = new HBox(new Label("Other View",MaterialDesignIcon.CAMERA.graphic())); + otherView.setAlignment(Pos.CENTER_LEFT); + otherView.setPrefHeight(50); + otherView.setStyle("-fx-padding: 0 10 0 10;-fx-border-color: #e0e0e0; -fx-border-width: 1 0 0 0;"); + otherView.setOnMouseClicked(e->{ + MobileApplication.getInstance().hideLayer("Side Menu"); + MobileApplication.getInstance().switchView("Other View"); + }); + + ToggleButton check = new ToggleButton(); + check.getStyleClass().add("switch"); + check.selectedProperty().addListener((obs,b0,b1)->{ + labelCheck.setText("User selected: "+(b1?"On":"Off")); + }); + + HBox gap=new HBox(); + gap.setMinWidth(20); + HBox.setHgrow(gap, Priority.ALWAYS); + HBox settings = new HBox(new Label("Select option",MaterialDesignIcon.SETTINGS.graphic()),gap,check); + settings.setAlignment(Pos.CENTER_LEFT); + settings.setPrefHeight(50); + settings.setStyle("-fx-padding: 0 10 0 10; -fx-border-color: #e0e0e0; -fx-border-width: 1 0 1 0;"); + + HBox empty = new HBox(); + VBox.setVgrow(empty, Priority.ALWAYS); + + VBox center = new VBox(); + center.getChildren().addAll(homeView,otherView,settings,empty); + borderPane.setCenter(center); + + SidePopupView sideMenu=new SidePopupView(borderPane, Side.LEFT); + + return sideMenu; + }); + + /* + Popup + */ + addLayerFactory("Popup", ()->{ + Menu menu=new Menu(); + MenuItem itemBlue = new MenuItem("Blue swatch",MaterialDesignIcon.STAR.graphic()); + itemBlue.setOnAction(e->{ + hideLayer("Popup"); + getView().setSwatch(Swatch.BLUE); + }); + MenuItem itemAmber = new MenuItem("Amber swatch",MaterialDesignIcon.REFRESH.graphic()); + itemAmber.setOnAction(e->{ + hideLayer("Popup"); + getView().setSwatch(Swatch.AMBER); + }); + menu.getItems().addAll(itemBlue,itemAmber); + + MenuPopupView menuPopupView = new MenuPopupView(homeToolbar.getItems().get(homeToolbar.getItems().size()-1), menu); + return menuPopupView; + }); + + } + + private void showDialog() { + HBox title = new HBox(10); + title.setAlignment(Pos.CENTER_LEFT); + title.getChildren().add(new ImageView(new Image(getClass().getResource("G_Grey_charm_opaque.png").toExternalForm(),64,64,true,true))); + title.getChildren().add(new Label("Title")); + Dialog dialog = new Dialog(); + dialog.setContent(new Label("This is a dialog. \nDo you want to continue?")); + dialog.setTitle(title); + Button yes = new Button("Yes"); + yes.setOnAction(e->{dialog.setResult(ButtonType.YES); dialog.hide();}); + yes.setDefaultButton(true); + Button no = new Button("No"); + no.setCancelButton(true); + no.setOnAction(e->{dialog.setResult(ButtonType.NO); dialog.hide();}); + dialog.getButtons().addAll(yes,no); + Platform.runLater(()->{ + Optional result = dialog.show(); + if(result.isPresent()){ + labelDialog.setText("User selected: "+(result.get().equals(ButtonType.YES)?"Yes":"No")); + } + }); + } + +} diff --git a/src/main/resources/org/jpereda/charm/G_Grey_charm_opaque.png b/src/main/resources/org/jpereda/charm/G_Grey_charm_opaque.png new file mode 100644 index 0000000..1d98158 Binary files /dev/null and b/src/main/resources/org/jpereda/charm/G_Grey_charm_opaque.png differ