package Ġhap . rule engine . editor . view model čĊč Ċ import Ġhap . rule engine . editor . view . parts . Component View č Ċ import Ġhap . rule engine . editor . view model . event .* č Ċ import Ġhap . rule engine . editor . view model . parts . Component VM č Ċ import Ġhap . rule engine . editor . view model . user interaction . User Interaction FSM č Ċ import Ġhap . rule engine . parts . Composite Serializer č Ċ import Ġhap . rule engine . parts . I Connection Point č Ċ import Ġhap . rule engine . parts . Wire . I Wire č Ċ import Ġhap . rule engine . parts . composite . Composite Component č Ċ import Ġjavafx . application . Platform č Ċ import Ġjavafx . geometry . Point 2 D č Ċ import Ġt orn ad of x . ViewModel č Ċ import Ġt orn ad of x . getProperty č Ċ import Ġt orn ad of x . property č Ċ import Ġt orn ad of x . single Assign č Ċ import Ġjava . io . File č Ċ import Ġjava . util .* č Ċ import Ġkotlin . concurrent . timer Task čĊč Ċ class ĠDraw ing Surface VM Ġ: ĠViewModel () č Ċ { čĊ ĉ private Ġvar Ġinteraction : ĠUser Interaction FSM Ġby Ġsingle Assign () čĊ ĉ private Ġvar Ġcurrent CC : ĠComposite Component Ġ= ĠComposite Component ( UUID . randomUUID (), Ġnull , Ġfalse ) čĊ ĉ private Ġval Ġtick Timer Ġ= Ġjava . util . Timer ( true ) čĊ ĉ private Ġvar Ġlive Components Ġ= Ġfalse čĊčĊ ĉ var Ġsurface : ĠID raw ing Surface View Ġby Ġsingle Assign () čĊčĊ ĉ fun Ġget Live Components () Ġ= Ġlive Components čĊčĊ ĉ init čĊ ĉ { čĊĉ ĉ subscribe To Events () čĊčĊĉ ĉ tick Timer . schedule ( timer Task Ġ{ čĊĉĉ ĉ Platform . run Later Ġ{ čĊĉĉĉ ĉ current CC . tick () čĊĉĉ ĉ } čĊĉ ĉ }, Ġ 1 0 , Ġ 1 0 ) čĊ ĉ } čĊčĊ ĉ fun Ġinit ( s : ĠID raw ing Surface View ) čĊ ĉ { čĊĉ ĉ surface Ġ= Ġs čĊĉ ĉ interaction Ġ= ĠUser Interaction FSM ( surface , Ġthis ) čĊ ĉ } čĊčĊ ĉ private Ġfun Ġsubscribe To Events () čĊ ĉ { čĊĉ ĉ subscribe < Drag Composite From Component P allet > Ġ{ čĊĉĉ ĉ interaction . drag Composite From Component P allet ( it . source file ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Drag Component From Component P allet > Ġ{ čĊĉĉ ĉ interaction . drag Component From Component P allet ( it . component Type ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < End Drag Component From P allet > Ġ{ čĊĉĉ ĉ interaction . end Drag Component From Component P allet () čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Mouse Drag Drop Released > Ġ{ čĊĉĉ ĉ interaction . mouse Drag Drop Released ( it , Ġsurface , Ġcurrent CC ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Open Composite FromFile > Ġ{ čĊĉĉ ĉ interaction . open Composite ( this , Ġit . window ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Select Component > Ġ{ čĊĉĉ ĉ interaction . select Component ( it . component , Ġit . addTo Or Remove From Selection ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Component Drag ged > Ġ{ čĊĉĉ ĉ interaction . component Drag ged ( it ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Mouse Released > Ġ{ čĊĉĉ ĉ interaction . mouse Released () čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Save Composite > Ġ{ čĊĉĉ ĉ interaction . save Composite ( this , Ġit . window ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Begin Connect Wire > Ġ{ čĊĉĉ ĉ interaction . begin Connect Wire ( it . connection Point , Ġit . scene Relative Center ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Mouse Entered Connection Point > Ġ{ čĊĉĉ ĉ interaction . mouse Entered Connection Point ( it . connection Point ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Update Drag Wire > Ġ{ čĊĉĉ ĉ interaction . update Drag Wire ( it . scene X , Ġit . scene Y ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Delete Wire > Ġ{ čĊĉĉ ĉ interaction . delete Wire ( it . wire ) čĊĉ ĉ } čĊčĊĉ ĉ subscribe < Delete Component > Ġ{ čĊĉĉ ĉ interaction . delete Component ( it . component ) čĊĉ ĉ } čĊ ĉ } čĊčĊ ĉ private Ġfun Ġvisualize () čĊ ĉ { čĊĉ ĉ // ĠVisual ize Ġall Ġcomponents Ġin Ġthe Ġcurrent Ġcomposite čĊĉ ĉ current CC . components čĊĉĉĉ ĉ . map Ġ{ čĊĉĉĉĉ ĉ val Ġvm Ġ= ĠComponent VM ( it ) čĊĉĉĉĉ ĉ vm . x . value Ġ= Ġit . x čĊĉĉĉĉ ĉ vm . y . value Ġ= Ġit . y čĊĉĉĉĉ ĉ surface . add ( vm ) čĊĉĉĉ ĉ } čĊčĊĉ ĉ // ĠOnce Ġall Ġcomponents Ġare Ġvisual ized , Ġdraw Ġthe Ġwire s . čĊĉ ĉ // ĠIt Ġis Ġrun Ġ' later ' Ġso Ġthat Ġthe ĠGrid Pane Ġhas Ġcompleted Ġits Ġlayout Ġphase . čĊĉ ĉ // ĠIf Ġwe Ġdon 't Ġwait Ġfor Ġthat Ġto Ġcomplete , Ġwe Ġget Ġinvalid Ġcoordinates Ġwhen Ġcalling Ġbounds In Parent Ġetc . čĊĉ ĉ Platform . run Later Ġ{ čĊĉĉ ĉ surface . draw W ires ( current CC ) čĊĉ ĉ } čĊ ĉ } čĊčĊ ĉ fun Ġset Composite ( cc : ĠComposite Component ) čĊ ĉ { čĊĉ ĉ surface . clear Components () čĊĉ ĉ current CC . te ar Down () čĊĉ ĉ current CC Ġ= Ġcc čĊĉ ĉ visual ize () čĊĉ ĉ current CC . execution State Ġ= Ġlive Components čĊ ĉ } čĊčĊ ĉ fun Ġsave Composite ( file : ĠFile ): ĠBoolean čĊ ĉ { čĊĉ ĉ val Ġserializer Ġ= ĠComposite Serializer () čĊĉ ĉ return Ġserializer . serialize ( current CC , Ġfile ) čĊ ĉ } čĊčĊ ĉ fun Ġadd Wire ( start Point : ĠI Connection Point , Ġlast Entered : ĠI Connection Point ) čĊ ĉ { čĊĉ ĉ val Ġwire : ĠI Wire ? Ġ= Ġcurrent CC . add Wire ( start Point , Ġlast Entered ) čĊĉ ĉ if Ġ( wire Ġ!= Ġnull ) čĊĉ ĉ { čĊĉĉ ĉ surface . draw W ires ( current CC ) čĊĉ ĉ } čĊ ĉ } čĊčĊ ĉ fun Ġdelete ( wire : ĠI Wire ?) čĊ ĉ { čĊĉ ĉ current CC . delete Wire ( wire ) čĊ ĉ } čĊčĊ ĉ fun Ġset Drag Wire ( start Scene Relative Center : ĠPoint 2 D , Ġscene X : ĠDouble , Ġscene Y : ĠDouble ) čĊ ĉ { čĊĉ ĉ val Ġoffset Ġ= Ġ Ġsurface . get Scroll Offset () čĊĉ ĉ var Ġxy Ġ= Ġsurface . scene ToLocal ( start Scene Relative Center . x Ġ- Ġoffset . x , Ġstart Scene Relative Center . y Ġ- Ġoffset . y ) čĊĉ ĉ drag Line Start X Ġ= Ġxy . x čĊĉ ĉ drag Line Start Y Ġ= Ġxy . y čĊĉ ĉ xy Ġ= Ġsurface . scene ToLocal ( scene X Ġ- Ġoffset . x , Ġscene Y Ġ- Ġoffset . y ) čĊĉ ĉ drag Line End X Ġ= Ġxy . x čĊĉ ĉ drag Line End Y Ġ= Ġxy . y čĊĉ ĉ drag Line Visible Ġ= Ġtrue čĊ ĉ } čĊčĊ ĉ fun Ġhide Drag Wire () čĊ ĉ { čĊĉ ĉ drag Line Visible Ġ= Ġfalse čĊ ĉ } čĊčĊ ĉ fun Ġdelete Component ( component : ĠComponent View ) čĊ ĉ { čĊĉ ĉ current CC . delete Component ( component . vm . component ) čĊĉ ĉ component . delete () čĊ ĉ } čĊčĊ ĉ var Ġdrag Line Start X : ĠDouble Ġby Ġproperty ( 0 . 0 ) čĊ ĉ fun Ġdrag Line Start X Property () Ġ= ĠgetProperty ( Drawing Surface VM :: drag Line Start X ) čĊ ĉ var Ġdrag Line Start Y : ĠDouble Ġby Ġproperty ( 0 . 0 ) čĊ ĉ fun Ġdrag Line Start Y Property () Ġ= ĠgetProperty ( Drawing Surface VM :: drag Line Start Y ) čĊ ĉ var Ġdrag Line End X : ĠDouble Ġby Ġproperty ( 0 . 0 ) čĊ ĉ fun Ġdrag Line End X Property () Ġ= ĠgetProperty ( Drawing Surface VM :: drag Line End X ) čĊ ĉ var Ġdrag Line End Y : ĠDouble Ġby Ġproperty ( 0 . 0 ) čĊ ĉ fun Ġdrag Line End Y Property () Ġ= ĠgetProperty ( Drawing Surface VM :: drag Line End Y ) čĊ ĉ var Ġdrag Line Visible : ĠBoolean Ġby Ġproperty ( false ) čĊ ĉ fun Ġdrag Line Visible Property () Ġ= ĠgetProperty ( Drawing Surface VM :: drag Line Visible ) čĊčĊ ĉ fun Ġtoggle Live Components ( live : ĠBoolean ) čĊ ĉ { čĊĉ ĉ live Components Ġ= Ġlive čĊĉ ĉ current CC . execution State Ġ= Ġlive čĊ ĉ } čĊčĊ ĉ fun Ġshutdown () čĊ ĉ { čĊĉ ĉ toggle Live Components ( false ) čĊĉ ĉ tick Timer . cancel () čĊĉ ĉ // ĠGive Ġthe Ġcomponent Ġa Ġlast Ġtick Ġso Ġthat Ġthey Ġcan Ġshutdown Ġany Ġtimers Ġand Ġthreads . čĊĉ ĉ current CC . tick () čĊĉ ĉ current CC . te ar Down () čĊ ĉ } čĊč Ċ }