{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Scala API to EasyForm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "val form : EasyForm = new com.twosigma.beakerx.scala.easyform.EasyForm(\"Form and Run\")\n", "form.addTextField(\"First\", 250)\n", "form.addTextField(\"Last\", 250)\n", "form.addButton(\"Go!\", \"run\")\n", "\n", "form" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [ "run" ] }, "outputs": [], "source": [ "\"Good morning \" + form.get(\"First\") + \" \" + form.get(\"Last\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "val h = new EasyForm(\"Form and Run\")\n", "h.addTextField(\"first\", 380)\n", "h.addTextArea(\"Text Area\",500,200)\n", "h" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "val g2 = new com.twosigma.beakerx.scala.easyform.EasyForm(\"Field Types\")\n", "val options = Seq(\"a\", \"b\", \"c\", \"d\")\n", "g2.addList(\"List Single\", options, false)\n", "g2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "//You can use onInit and onChange to handle component events. For button events use actionPerfromed or addAction.\n", "val f1 = new EasyForm(\"Form and Run\")\n", "val first = f1.addTextField(\"first\", 15)\n", "first.onInit(new EasyFormListener {\n", " override def execute(value: String): Unit = {\n", " first.setValue(\"Changed!\");\n", " }\n", " }).onChange(new EasyFormListener {\n", " override def execute(value: String): Unit = {\n", " first.setValue(\"Changed!\");\n", " }\n", " });\n", "\n", "val last = f1.addTextField(\"last\", 15)\n", "val button = f1.addButton(\"action button\")\n", "button.actionPerformed = new EasyFormListener {\n", " override def execute(value: String): Unit = first.setValue(\"Pressed!\"); last.setValue(\"Pressed!\")\n", "}\n", "\n", "f1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "//All Kinds of Fields\n", "\n", "val g = new EasyForm(\"Field Types\")\n", "g.addTextField(\"Short Text Field\", 10)\n", "g.addTextField(\"Text Field\")\n", "g.addTextArea(\"Text Area\")\n", "g.addCheckBox(\"Check Box\")\n", "val options = Seq(\"a\", \"b\", \"c\", \"d\")\n", "g.addComboBox(\"Combo Box\", options)\n", "g.addComboBox(\"Editable Combo\", options, true)\n", "\n", "g.addList(\"List\", options)\n", "g.addList(\"List Single\", options, false)\n", "g.addList(\"List Two Row\", options, 2)\n", "\n", "g.addCheckBoxes(\"Check Boxes\", options)\n", "g.addCheckBoxes(\"Check Boxes H\", options, EasyForm.HORIZONTAL)\n", "\n", "g.addRadioButtons(\"Radio Buttons\", options)\n", "g.addRadioButtons(\"Radio Buttons H\", options, EasyForm.HORIZONTAL)\n", "\n", "g.addDatePicker(\"Date\")\n", "\n", "g.addButton(\"Go!\", \"run2\")\n", "g" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "val gdp = new EasyForm(\"Field Types\")\n", "val date = gdp.addDatePicker(\"Date\")\n", "gdp" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "date.getValue()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "form.put(\"First\", \"Micheal\")\n", "form.put(\"Last\", \"Fox\")\n", "// Read values from form\n", "val firstName = form.get(\"First\")\n", "val lastName = form.get(\"Last\")\n", "\n", "print(\"Good morning \" + firstName + \" \" + lastName)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "EasyForm.HORIZONTAL" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "beakerx_kernel_parameters": {}, "kernelspec": { "display_name": "Scala", "language": "scala", "name": "scala" }, "language_info": { "codemirror_mode": "text/x-scala", "file_extension": ".scala", "mimetype": "", "name": "Scala", "nbconverter_exporter": "", "version": "2.11.11" } }, "nbformat": 4, "nbformat_minor": 1 }