From f09258190a8406b09ea2788d66d2776dda4ae476 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Sat, 16 Sep 2017 17:08:50 +0200 Subject: [PATCH] save windows size only if ther is 500ms no action * if the window is resized, the new size is only saved if no resize action is done for 5000ms --- bin/application/Main.class | Bin 9049 -> 9049 bytes src/application/Main.java | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/bin/application/Main.class b/bin/application/Main.class index 3ad29be880c869e5ef8dca4221f48f514e9fcfd8..10476688368fbb465756ef5ab9fa3df0f70c8f6c 100644 GIT binary patch delta 495 zcmWO2%S)7T7{&4L^ZY8ai#pbr?*v&+1lomk5vJ7?(o`taq-7SNSVk8sY;sBxrmGe~ zY42!GlLTrwnML(>C+V{3KL`dQTDmO=B7*vD&f;*+=939$!cS6;uY_r=rid~sDQ6=k z?t~NZt!FwL@DajqJBLkPP9SOGo5>|ifUN|nVHLHkVLR3AU?&lxHWSqGf_lENiwwJ& zqCv9RBc(J-4SS`HCW+B3=V_7a9FRT^%57R@h(j{W5&6JT`NlDsqD_8sT>fxEm3E!O zDJ_T-)c~h8NQW*brsbT`D$Z(%bGnT#jS$y;T+mi7YCD&-lgrx86;05sNqTgYtD5GT zPH;m#Zt5hx`k6lc$}RmtLVwe*{}?bc7&Ly8W+it_1t}BauBm3om@VA%(uFX`eHJ-nuuH>7xL-|y^e z(yrdS&5Qp!pUCDr`TSy`WU)+UQf3j?$t_ha#XS?d-BEB^yeS#I|L delta 495 zcmWO3Urfz$7{~GV^L(*2|8{Jdb8Mnx=K^KAXm&!TiI#sy(TrAV$e&44)7G5)%SHa> z7j?uW;fzN4`7_3F<=TzyZ05QRZSpTNaF8DtY>AtilA4dj-A+&0CevD`6^yOeQ{D(+Lm0JRL#h)**QIb}@ec}zD?tnt*Q zpYed_Ughku;7ihY%QOR=$wwl5ViBM17sGzToJ^w}VKQG?z&E?{-LQX9%1`4T#p4%U U{NV;;w)L;~I widthListener = new ChangeListener() { + + final Timer timer = new Timer(); + TimerTask saveTask = null; //task to execute save operation + final long delayTime = 500; //delay until the window size is saved, if the window is resized earlier it will be killed, default is 500ms @Override public void changed(ObservableValue observable, Number oldValue, final Number newValue) { @@ -201,16 +208,37 @@ public class Main extends Application { mainWindowController.refreshUIData(); } - //TODO saveSettings only on left mouseBtn release - mainWindowController.saveSettings(); + //if saveTask is already running kill it + if (saveTask != null) saveTask.cancel(); + + saveTask = new TimerTask() { + @Override + public void run() { + mainWindowController.saveSettings(); + } + }; + timer.schedule(saveTask, delayTime); } }; final ChangeListener heightListener = new ChangeListener() { + final Timer timer = new Timer(); + TimerTask saveTask = null; //task to execute save operation + final long delayTime = 500; //delay until the window size is saved, if the window is resized earlier it will be killed, default is 500ms + @Override public void changed(ObservableValue observable, Number oldValue, final Number newValue) { - mainWindowController.saveSettings(); + + if (saveTask != null) saveTask.cancel(); + + saveTask = new TimerTask() { + @Override + public void run() { + mainWindowController.saveSettings(); + } + }; + timer.schedule(saveTask, delayTime); } };