From 5d632387d7a4ffe40b70a6f30ee84653d638f09c Mon Sep 17 00:00:00 2001 From: William Steele Date: Wed, 25 Nov 2015 13:46:30 -0500 Subject: [PATCH 1/3] Started flowmeter string return --- LIQUID/bin/liquid/engine/LiquidEngine.class | Bin 6218 -> 6257 bytes LIQUID/src/liquid/engine/Flowmeter.java | 20 +++++++++++++----- .../src/liquid/engine/FluidEnvironment.java | 6 +++--- LIQUID/src/liquid/engine/LiquidEngine.java | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/LIQUID/bin/liquid/engine/LiquidEngine.class b/LIQUID/bin/liquid/engine/LiquidEngine.class index dbf8dab82790b312d44fc3b0371921918c6c1847..88ca4533ab90dbb3037d3a869938e1604c4c73c4 100644 GIT binary patch delta 1499 zcmZuwdu)?c6#t#>YrlS9@3yX6+jUPT+t{PdIayg5=i8?p7m`&M`X-E|5 zA2w(rg81PB5Og{yWIos!WkH;YCWN5Lj0uU+XhI~>U?lMm6CZK)+^roL>DS!f@0{Pc z_nvd_xtFSctJW{go|^`+gjS8~FX%=85JY!xZ|I4k9b5aJ>f27Rl!Zc#<@f8TMqCh# zlX`KAsWD)Dq4yQ)1huz+c-zo$p9UhkKqj(ul#)YGCS@7THec8!$c;J<3~mf`wKm?X zvFs6)BYoDU=GB3&rsj3hnI|Y;I<@;&x3>n9p@o8Oliu`};HLIqYg^Y%%iJz#k<{!- z?dIi51eLOAD8j9j2`V=VMYd8Y$ZOP#0;NjOoyNl=C;KizHF6ELrF~;^&n1FtjeWx9 zTq>weidsiYV_Q%rs?xI4=fsd%dk-1}K*x+4M`fzwQ|+qH8l~P!r`34O;m^`Mn%kT@ z=(eN|#_&zWB<}EN#-w9SpJspX6I@xQr}%79tnuhh+sC-lDPx_s-HsnU`tfhk-a zkggs%|3Cg~1Jc!V7QePeY~-|Y{7C$~NAu{+Vz{2zX>;a14Mkq1W(pTVUbBQcMM@=Z z#i>SAis7$_m7Lbf>5v;6JlIQ6fey)-ljCccEX)dJF%QnI8Nb&pPy%(Nl-R2P#Z&uJ*_zkrK4hkoYE3WE1NAf zY2+G>uJXJB8DLBLirBIwjbdZ3D>t}U1}sdfU`t5^U`$FG$#8DN5^K_^mePWCw{hK- z6ZT18V)f3`lzs{h*tuu($&Uh*p_0+dCsxPk$6ACK*Kt#{F}8Dq^e}G0R%~N@63^f{ z#$9-kTgA`4{yGja9>OU1q#q|Rj!DKde7B!5evU7TF~j65e2ecHf51<;#`p_<#~+M; zQVLnfZ;ZK%cGbs`B`>XB4t_MrVZ#EOGj9yH5^nfz#pdS1M9aA$Ow>Rt7i~^e_vnS&f!OP^*`LdTSqw-1fs?XeWme(-n(2S zD1AFdM}|lHH4vo=q$5K|AvpxyKu+U6TV*IikPB6u7-*^uwl&OKNIkv%faj z*jz8gY(dMUsBQIkv;~r>xq|Yfn${X<=?Jv72bUbPLeP!Ub0oc`$K?xJ$)@2HndU-4 ztBg{SWnL|)*k}-W<`O}r#)BezbD5xWd4|&3(UiQiLeQ;Jv$qA>Wp%-={#Jji@U?;} zrK5GWHnaz%r%=_&FU7D$dkz|G0F4_PonGCcR4QQ#dR>a~sIxjl^{AN^`%tFUJ`}-s z#j_~&sKy!Rrhe6N&!@P&PD`oO!`S4}T>2-t+$D2e`T^%p9&P@>(BK??9+Xm#-2XrQ z%Ak~bKEiKp`*m{ZoIe>o?NL1%vj~1q+_W=&OI1#Zxnd4y>q;yVs?5?V$TUar_kM+3 zig$i;VM1yV{5!)lkb-Pp-$s#fHQf`c!1JiV3#i9IG~q>T!%OJK%NW2b7>0qz@hY=J z7{}|F!W%e_!k~=%(Wlc>c+$<9oqgyz#Bu~0qTFzwR8W|<->^e#IX*l8FLCqx}@=ydX zV+q#s3-zHIn^DJDj~28ucJO5MF!o{>MnX&;!d^VV_#~d;A@T8qAHreABRn)=#$!Bg zvy7+k89rzHf~WWblxRy>#^8gnD}jh*W0LuQRiw3VWHbMdj129!Yh#g diff --git a/LIQUID/src/liquid/engine/Flowmeter.java b/LIQUID/src/liquid/engine/Flowmeter.java index 31cbd51..01c2ac5 100644 --- a/LIQUID/src/liquid/engine/Flowmeter.java +++ b/LIQUID/src/liquid/engine/Flowmeter.java @@ -3,6 +3,7 @@ */ package liquid.engine; +import java.text.DecimalFormat; import java.util.ArrayList; import org.jbox2d.common.Vec2; @@ -15,24 +16,33 @@ public class Flowmeter { private World myWorld; private Vec2 myLoc; - private float timer; + private int myID; /** * * @param imHere the world this flow meter is monitoring * @param loc the location this flow meter monitors */ - public Flowmeter(World imHere, Vec2 loc){ + public Flowmeter(World imHere, Vec2 loc, int ID){ myWorld = imHere; myLoc = loc; - timer = 0; + myID = ID; } + + public String update(){ + DecimalFormat adj = new DecimalFormat(); +// Vec2 +// adj.setMaximumFractionDigits(4); + String send = "" + myID + ": "; + + return send; + } + /** * Gets the average x and y velocities of particles within 2.0 units of this flowmeter's position * @return Vec2 object containing the average x and y velocities of nearby particles */ - public Vec2 pollVelocity(float delta){ - timer += delta; + private Vec2 pollVelocity(){ ArrayList vel = new ArrayList(); Vec2[] pos = myWorld.getParticlePositionBuffer(); Vec2 bounds = new Vec2(10.0f, 10.0f); //To change boundaries to check, simply change parameters of constructor diff --git a/LIQUID/src/liquid/engine/FluidEnvironment.java b/LIQUID/src/liquid/engine/FluidEnvironment.java index 401fe85..834c61e 100644 --- a/LIQUID/src/liquid/engine/FluidEnvironment.java +++ b/LIQUID/src/liquid/engine/FluidEnvironment.java @@ -80,7 +80,7 @@ public void update(float delta){ if(timer >= 10){ timer = 0; for (Flowmeter f: meters){ - System.out.println(f.pollVelocity(delta)); + System.out.println(f.update()); } } } @@ -105,8 +105,8 @@ public void addSource(float x, float y, float velx, float vely){ * @param x x-position of the new flow meter * @param y y-position of the new flow meter */ - public void addFlowmeter(float x, float y){ - meters.add(new Flowmeter(world, new Vec2(x, y))); + public void addFlowmeter(float x, float y, int ID){ + meters.add(new Flowmeter(world, new Vec2(x, y), ID)); } public void addParticle(float x, float y, float velx, float vely){ diff --git a/LIQUID/src/liquid/engine/LiquidEngine.java b/LIQUID/src/liquid/engine/LiquidEngine.java index be810ff..7cfab24 100644 --- a/LIQUID/src/liquid/engine/LiquidEngine.java +++ b/LIQUID/src/liquid/engine/LiquidEngine.java @@ -136,6 +136,7 @@ public void initiateSim(String[] args) { enviro = new FluidEnvironment(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1])); float x, y, l, w; + int ID = 1; for (int i = 7; i < args.length; i++) { tokens = args[i].split(" "); if (tokens[0].equals("Rectangular")) { @@ -170,7 +171,7 @@ public void initiateSim(String[] args) { if (tokens[0].equals("Flowmeter")) { x = Float.parseFloat(tokens[1]); y = Float.parseFloat(tokens[2]); - enviro.addFlowmeter(x, y); + enviro.addFlowmeter(x, y, ID++); } } enviro.init(); From b1444dec27fbb11b03707fea85b47a9b6a98353a Mon Sep 17 00:00:00 2001 From: William Steele Date: Wed, 25 Nov 2015 13:50:32 -0500 Subject: [PATCH 2/3] Merge remote-tracking branch 'origin/master' Conflicts: LIQUID/bin/liquid/engine/LiquidEngine.class LIQUID/src/liquid/engine/LiquidEngine.java --- LIQUID/bin/liquid/core/DesktopLauncher.class | Bin 514 -> 514 bytes .../bin/liquid/core/LiquidApplication.class | Bin 999 -> 999 bytes LIQUID/bin/liquid/engine/LiquidEngine.class | Bin 6257 -> 5086 bytes LIQUID/bin/liquid/gui/ConsolePanel.class | Bin 1785 -> 1785 bytes LIQUID/bin/liquid/gui/LiquidFrame.class | Bin 1099 -> 1099 bytes LIQUID/bin/liquid/gui/LiquidGUI.class | Bin 4677 -> 4677 bytes LIQUID/bin/liquid/gui/LiquidMenuBar$1.class | Bin 1286 -> 1286 bytes LIQUID/bin/liquid/gui/LiquidMenuBar$2.class | Bin 2030 -> 2030 bytes LIQUID/bin/liquid/gui/LiquidMenuBar.class | Bin 2000 -> 2000 bytes LIQUID/bin/liquid/gui/ParameterPanel.class | Bin 6729 -> 6603 bytes LIQUID/src/liquid/core/DesktopLauncher.java | 1 + LIQUID/src/liquid/core/Interfaceable.java | 1 + LIQUID/src/liquid/core/LiquidApplication.java | 1 + .../src/liquid/engine/FluidEnvironment.java | 4 +- LIQUID/src/liquid/engine/LiquidEngine.java | 7 +- LIQUID/src/liquid/engine/Source.java | 6 +- LIQUID/src/liquid/gui/ConsolePanel.java | 1 + .../src/liquid/gui/EnviroAddiParamPanel.java | 119 +++++ LIQUID/src/liquid/gui/EnviroForcesPanel.java | 187 ++++++++ LIQUID/src/liquid/gui/EnviroObstacles.java | 189 -------- .../src/liquid/gui/EnviroObstaclesPanel.java | 191 ++++++++ LIQUID/src/liquid/gui/EnviroSensorsPanel.java | 141 ++++++ LIQUID/src/liquid/gui/EnviroSources.java | 137 ------ .../liquid/gui/EnvironmentEditorPanel.java | 439 ++++++------------ LIQUID/src/liquid/gui/LiquidFrame.java | 4 +- LIQUID/src/liquid/gui/LiquidGUI.java | 7 +- LIQUID/src/liquid/gui/LiquidGuiVariables.java | 5 +- LIQUID/src/liquid/gui/LiquidMenuBar.java | 1 + LIQUID/src/liquid/gui/ParameterPanel.java | 1 - .../src/liquid/logger/LiquidFileWriter.java | 6 +- logs/test.log | 8 +- logs/test1.log | 17 +- logs/test2.log | 9 +- logs/test3.log | 8 - logs/test4.log | 16 - 35 files changed, 839 insertions(+), 667 deletions(-) create mode 100644 LIQUID/src/liquid/gui/EnviroAddiParamPanel.java create mode 100644 LIQUID/src/liquid/gui/EnviroForcesPanel.java delete mode 100644 LIQUID/src/liquid/gui/EnviroObstacles.java create mode 100644 LIQUID/src/liquid/gui/EnviroObstaclesPanel.java create mode 100644 LIQUID/src/liquid/gui/EnviroSensorsPanel.java delete mode 100644 LIQUID/src/liquid/gui/EnviroSources.java delete mode 100644 logs/test3.log delete mode 100644 logs/test4.log diff --git a/LIQUID/bin/liquid/core/DesktopLauncher.class b/LIQUID/bin/liquid/core/DesktopLauncher.class index 68f9d2c08e7628aeed635d28560be7575cc856ce..aa61e629d698aca6e070f4bb36ccf4e8045d0bd5 100644 GIT binary patch delta 23 ecmZo-X=2$hjggUk@^nTARsjYM2Eoa97}Wqs6$Og` delta 23 ecmZo-X=2$hjggUU@^nTAR(=K!27$?U7}Wqr_yvdn diff --git a/LIQUID/bin/liquid/core/LiquidApplication.class b/LIQUID/bin/liquid/core/LiquidApplication.class index 925857c3ca89febc86e95f005d0033f2a655b099..4ea8ce30336120f215c983b48d19f88f04126370 100644 GIT binary patch delta 79 zcmaFP{+xZobtXY^1{MYh20jK!ASuP5#2`KS1(O%AA_E(c&BLI~AjF_D*`C>uQD<@? akTjjVnAuR+jzNKefq@B#85#7zEPVhoa|@sV delta 79 zcmaFP{+xZobtXYE1{MZ!20jJ}Ae3ZKVvw5rg2{_lfq{)dk%0%u7h+JJY|m`Ss6Dw5 aNSaJu%xoxZ%b>u(z`z8=j0}2UmOcP6K?{@s diff --git a/LIQUID/bin/liquid/engine/LiquidEngine.class b/LIQUID/bin/liquid/engine/LiquidEngine.class index 88ca4533ab90dbb3037d3a869938e1604c4c73c4..afdb2e53035f65fc0ba5f2fa38d7804afe97f344 100644 GIT binary patch delta 1430 zcmaJ=TWl0n82+YZyWQ!LmVzZkYEDRif+g@^lL|htVVBZSDRg&J`e2sn?tzZX&Wt-l zEfC#Tg1${+f=@n>z$1tk(qfCPA_59>Q@OOZUQ6MX^xGhw!EviPw7_kaKQU(WvL z%%c@!i`7$)2ZjK=ibsdlzr%$v1{GAlrS)mc4b9xPJf6>6`AU4LD34QSUO1M~C$c`RMvWS!BTHA%`H1Vu3ge$n)D;%S9BGBID8;bklK#mQ^Fk zUOJZ8>MrZm%q(~Gtl-vGu9;kO9DSRa6Q;{^I~A zx;opEajAvz@W@GKhE~#-Q;stFg496_bk`pH0z<>Z$}o>?1#Jk}i^OiKUBpgE#sc;ov2Z}n zcy?W5E6&P{svvltSVcfCNhuPrk0q-P*w2y`dtLR$>*@;_qhMu_aZ_d#*&Sk`K-w&& z+JN1c?Ag%nBRGBtwWy&@G++WRqY)yV7HLO&e~*M;%h6YQP?g&b)n&@RpTqUX~|Q%abOmGb;rdLX~k#4`MW QKM7TO5R2$3{I$CNDZ+Z9`Tzg` delta 2573 zcma)8X>e0j6#h=LyyWFU7f3_cQCreBkXivLWvjGhiiJWKu;N(KG*ePSQj>t7Xnxp1 z9dM1Ph@dD?7&o@23}8`EL}YWp9TXK&a6?=`lzMKK(kg>y^6uHb``vTyJ?|z*2cFKB z_g>iA3SbD0-5{TltTMLYWeM8}$@TWRcAMMosk0S(0?s<8PeCho5OfW8pWn&8&<>U9 z>S7&UB~X7Eqp(ZCYj~ZY@i(|#0m48_$wiX#fY0Tr%gYGaRo!@*H}Ix}J%q%Ih$6Sw z9#F6sZxQ6kA`y>RCRijR8~YU)ae(cEXWAQ_e%oZPdw!kQ zQ!XqS!NV}iIE;@Jd@M51`JI7$|8?GZBCSsq9Klh}#a>%mTH_Dc9d0MHTS_j+A0f_* z*6}$Lj&u1Oq6i6J5K=qMoITqc^w_349XaZ8n*kZeaYDk^gkJxId2AEyfti&7m)o!4 z8+=PpIlR0HYD-ZD@8EHqQt(~G?RR-(9K(K5)Q<{&!fD2GQG`C0>75hj>LO95O1CB3^@6GvTef2CYBXWsVpq7 zsO~^>g+f<`4#+(;l%`O6=#*>@l0~76PWZCQNpY?$g{&fGjB}M2R*2QBC+C;tM-m&X zkWCg3xb0oX$|Hw|v;yEUb zNgKv5qN=lEUJwKRF);=-N{teQ@kgVMjJmAWl^2$YKo}P`@K1pXJ$YP%3?3KqZF4ue z;~wZeSQ8HFgZ>*$rJi~3bibi2I6<`gOpouE5mTtm2s>gFQ2hY<2 zyg-e3kwREZ%dvr0VIz8Rn%}@Anhd?shb^JqjA~F2-RU7BRueeK0!l!bt82odsK(2r z$Fv17#iCUhNh-#vIpMpa8mH1XrZpll7Pa$FrkZgYF6#EE#_6WUd@fi?gJ2k1uGh~h zYg|d!sD{COe`(Pb5^`u3rn9EwO}mmL((wzk2lX-SARMG8nGfL|Odtc}44AF%$_$mH@Ri5?nWl>)vIU~ux`r)HoazPs#`FeOZozH1 zgXNw4A}nIL7>{Bp%O|jkyEPYUu>qS|HuI_PWVs9baFFF8{?~AXpk#44OcB zZJ?+QgB61=gBODyLokCrLo|aCLpp;oLkWWkLluK5Lj!}^X3%4ZW-w$(XE0(YVK8Q>VlZK7U@)DW%$Ck+3pCFTXrle(%WP@@ DI=2u8 diff --git a/LIQUID/bin/liquid/gui/LiquidFrame.class b/LIQUID/bin/liquid/gui/LiquidFrame.class index febd4a662c4b5f58a05a044e6cb92535396f7c2f..8a9fc030e0cda704ecdc9b3fc9bb21196b0ff7ef 100644 GIT binary patch delta 67 zcmX@jahhYpRAxyL1~vv!1_1^!ASuou#UQ~T&mhU5!XPzy9kZXL5(6WHG6O4+&(5I4 Uz|Ek_z|Ww@Ak3gXS(L>L07PO3^#A|> delta 67 zcmX@jahhYpRAxzG1~vu}1_1_9AQWSeVi0GLXOLh}VUV1>j@eIAk%5sxiGh_tnSq@_ Uk%1d1&d;FAAk3gPS(L>L079Y%=Kufz diff --git a/LIQUID/bin/liquid/gui/LiquidGUI.class b/LIQUID/bin/liquid/gui/LiquidGUI.class index e8bead0161055e988b70e10747031d5b65fe5c73..5e7beded63829655af184bc575f7d580618bdca2 100644 GIT binary patch delta 14 WcmX@Aa#Ur*J$}ZeoA2|dF#!NFaRwg% delta 14 WcmX@Aa#Ur*J$}X|oA2|dF#!NFYX%+w diff --git a/LIQUID/bin/liquid/gui/LiquidMenuBar$1.class b/LIQUID/bin/liquid/gui/LiquidMenuBar$1.class index f800d858faf2afa81acd2b2a004d7fedc2790365..652cdf763671a99a2809bb7c5b4ad7b012a7ad18 100644 GIT binary patch delta 47 zcmZqUYUA2q&cbLl*@7in)`o$N!IpuG!H$84!G=MA!Ja{c!GS@F!I43k!FloqmM{Rr Cg9n}f delta 47 zcmZqUYUA2q&cbLp*@7in)|!Eh!G?j0!IpuC!J0vU!Hz+M!Ja{i!GS@U!D;damM{Rq C#0QlC diff --git a/LIQUID/bin/liquid/gui/LiquidMenuBar$2.class b/LIQUID/bin/liquid/gui/LiquidMenuBar$2.class index 24da5d2194514232c105bc23bb70a35b45722cde..29fd6cb861c85a91e7749e7c969509c1c32bd616 100644 GIT binary patch delta 47 zcmaFI|BipdH8w`i$=BIt$@(zxGx#$IGXyZmG6XVcG6XUBG6XY3GK4TBF@#O-V^078 DKKToK delta 47 zcmaFI|BipdH8w_%$=BIt$$B&JGx#wGGx#&eG6XPaG6XXCG6XS1G6XXuF@#R;V^078 DJ~|6> diff --git a/LIQUID/bin/liquid/gui/LiquidMenuBar.class b/LIQUID/bin/liquid/gui/LiquidMenuBar.class index 86fdc64b902fcdddec6aa77aa599d8f2e3c81103..3242360772836bf978ac6f0948d792a19aedad59 100644 GIT binary patch delta 150 zcmWN~KMMh20KnnjD|bjbXEGS9$3_X;4dfO!DGbz!GAJgLI!xzJy3rRfsvE4nz}0;K ztI2FsZhnTxSA6AOmtq=Wazx3yEy)mOfdoZTl*mv)qe__?It`i_^yx67%bXq-18jy| yFu5}3#)Jnmo`HHSc(LNmnhzVkSR%w$#Mudzz4Mc&svV>Uk{n5MBFouXM%sVFWFVjb delta 150 zcmcb>e}R948!M*<0}F#D0|$fFW`9;s##BQFUIrruAqGte4nZRDJz?XaR`vw4q-5Vua(|yfAAjuDGUg9kYa2*f7t` zO3kc#KyGLVp;yH-w={0ku*UsU^Er(>Tq0bVWWH>q);+Q=Xe_p!b2E`MlFMzir*Xfn z+{L6(UP-MbT|BU^{aJgJ(5=o6z3B@i+@4D)pwwEm3c=J&LtYBzBzxeH{6avMLnNlD zAVnMI#cDqnSU_BeT(v%e@o@V8I0UD758PDIMKAiOVVE5lqtD9dkzA(u40}C)&&}4O znvUEudxt0I#trOwfxLkI7j^|4KTvEkQ-=)!=<;I;{Rm@JW&}~GSF+yq!HM!0x zBfnr4u8j+~e1#BWSeQtnY+U&#h<`!6BhiI%bKX4X+5MsooU(arHuJ<#dBQ2X_kmkXVoK46@SN#PNv*#v^~@7I<}kDd6%Zf zdqn?#V!;`>gti>~Xtjx+uCwBJI@VYfoW&?{u2&kS({koLXCVsmfxsY6>)7Wb!N+{! ze~MkpJ{7ciOEyjCsx>n|6_xS4;6mVq%M%qdcRR2a1(yOVV&%-*oqRE;vEdKJXVea1 z_$T^|t#|Q>Nc0U9P@cf@e+=X&H#xbBgKd1@#^Daj8!}LEL+T*HQjd_3Z!eIzP6c^} zFiRC#nTX>OjA2|7S@GTEcHMgRZ+ diff --git a/LIQUID/src/liquid/core/DesktopLauncher.java b/LIQUID/src/liquid/core/DesktopLauncher.java index daadc69..9155a70 100644 --- a/LIQUID/src/liquid/core/DesktopLauncher.java +++ b/LIQUID/src/liquid/core/DesktopLauncher.java @@ -1,3 +1,4 @@ +// DONE! package liquid.core; /** diff --git a/LIQUID/src/liquid/core/Interfaceable.java b/LIQUID/src/liquid/core/Interfaceable.java index 229ef55..4b3de6d 100644 --- a/LIQUID/src/liquid/core/Interfaceable.java +++ b/LIQUID/src/liquid/core/Interfaceable.java @@ -1,3 +1,4 @@ +// DONE! package liquid.core; /** diff --git a/LIQUID/src/liquid/core/LiquidApplication.java b/LIQUID/src/liquid/core/LiquidApplication.java index 95c0532..995704c 100644 --- a/LIQUID/src/liquid/core/LiquidApplication.java +++ b/LIQUID/src/liquid/core/LiquidApplication.java @@ -1,3 +1,4 @@ +// DONE! package liquid.core; import liquid.engine.LiquidEngine; diff --git a/LIQUID/src/liquid/engine/FluidEnvironment.java b/LIQUID/src/liquid/engine/FluidEnvironment.java index 834c61e..84d189f 100644 --- a/LIQUID/src/liquid/engine/FluidEnvironment.java +++ b/LIQUID/src/liquid/engine/FluidEnvironment.java @@ -96,8 +96,8 @@ public void addObstacle(Shape s,float x, float y){ b.createFixture(fd); } - public void addSource(float x, float y, float velx, float vely){ - sources.add(new Source(this, x, y, velx, vely)); + public void addSource(float x, float y, float velx, float vely, float flow){ + sources.add(new Source(this, x, y, velx, vely, flow)); } /** diff --git a/LIQUID/src/liquid/engine/LiquidEngine.java b/LIQUID/src/liquid/engine/LiquidEngine.java index 7cfab24..6ce31ff 100644 --- a/LIQUID/src/liquid/engine/LiquidEngine.java +++ b/LIQUID/src/liquid/engine/LiquidEngine.java @@ -135,8 +135,12 @@ public void initiateSim(String[] args) { String[] tokens = args[6].split(" "); enviro = new FluidEnvironment(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1])); +<<<<<<< HEAD float x, y, l, w; int ID = 1; +======= + float x, y, l, w, r; +>>>>>>> origin/master for (int i = 7; i < args.length; i++) { tokens = args[i].split(" "); if (tokens[0].equals("Rectangular")) { @@ -166,7 +170,8 @@ public void initiateSim(String[] args) { y = Float.parseFloat(tokens[2]); l = Float.parseFloat(tokens[3]); w = Float.parseFloat(tokens[4]); - enviro.addSource(x, y, l, w); + r = Float.parseFloat(tokens[5]); + enviro.addSource(x, y, l, w, r); } if (tokens[0].equals("Flowmeter")) { x = Float.parseFloat(tokens[1]); diff --git a/LIQUID/src/liquid/engine/Source.java b/LIQUID/src/liquid/engine/Source.java index 66345e9..7f1c3e3 100644 --- a/LIQUID/src/liquid/engine/Source.java +++ b/LIQUID/src/liquid/engine/Source.java @@ -5,6 +5,8 @@ import org.jbox2d.common.Vec2; +import liquid.core.LiquidApplication; + /** * @author Rafael Zamora * @@ -17,11 +19,11 @@ public class Source { private float flowspeed; private float timer; - public Source(FluidEnvironment enviro, float x, float y, float velx, float vely){ + public Source(FluidEnvironment enviro, float x, float y, float velx, float vely, float flow){ this.enviro = enviro; pos = new Vec2(x, y); force = new Vec2(velx,vely); - flowspeed = force.length(); + flowspeed = flow; timer = 0; } diff --git a/LIQUID/src/liquid/gui/ConsolePanel.java b/LIQUID/src/liquid/gui/ConsolePanel.java index 5f6bec7..9b1a411 100644 --- a/LIQUID/src/liquid/gui/ConsolePanel.java +++ b/LIQUID/src/liquid/gui/ConsolePanel.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import java.awt.Color; diff --git a/LIQUID/src/liquid/gui/EnviroAddiParamPanel.java b/LIQUID/src/liquid/gui/EnviroAddiParamPanel.java new file mode 100644 index 0000000..7db531e --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroAddiParamPanel.java @@ -0,0 +1,119 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class creates the additional parameters of the EnvironmentEditorPanel. This is currently + * located at the bottom of the panel, where it is shared by all drop-down options. + */ +public class EnviroAddiParamPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // defines variables of the additional parameters + JButton selectNext; + JButton selectPrev; + JButton selectUpdate; + JButton delete; + + /** + * Constructor adds the additional parameters of the EnvironmentEditorPanel. + */ + public EnviroAddiParamPanel() { + initComponents(); + } + + /** + * Initializes the buttons of the additional parameters. + */ + public void initComponents() { + setBounds(5,240,240,65); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + //selectNext = new JButton("Next Item"); + //selectNext.setBounds(35,5,(this.getWidth()/2),25); + //add(selectNext); + + selectNext = new JButton("Next Item"); + selectPrev = new JButton("Prev Item"); + selectUpdate = new JButton("Update Item"); + delete = new JButton("Delete"); + nextParam(); + prevParam(); + updateParam(); + deleteParam(); + } + + public void nextParam() { + selectNext.setBounds(5,4,(int)(this.getWidth()/2.2),25); + ActionListener next = new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + if (LiquidApplication.getGUI().variables.selectedObject < LiquidApplication.getGUI().variables.objects.size()-1){ + LiquidApplication.getGUI().variables.selectedObject += 1; + } else { + LiquidApplication.getGUI().variables.selectedObject = 0; + } + LiquidApplication.getGUI().enviroeditor.update(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + }; + selectNext.addActionListener(next); + add(selectNext); + } + + public void prevParam() { + selectPrev.setBounds(125,4,(int)(this.getWidth()/2.2),25); + ActionListener prev = new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + if( LiquidApplication.getGUI().variables.selectedObject > 0) { + LiquidApplication.getGUI().variables.selectedObject -= 1; + } else { + LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; + } + LiquidApplication.getGUI().enviroeditor.update(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + }; + selectPrev.addActionListener(prev); + add(selectPrev); + } + + public void updateParam() { + selectUpdate.setBounds(5,34,(int)(this.getWidth()/2.2),25); + selectUpdate.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent actionEvent) { + if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Obstacles")) { + LiquidApplication.getGUI().enviroeditor.obstacles.createObstacle(true); + } else if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Initial Forces")) { + LiquidApplication.getGUI().enviroeditor.forces.createForce(true); + } else if (LiquidApplication.getGUI().enviroeditor.select.getSelectedItem().equals("Flow Sensors")) { + LiquidApplication.getGUI().enviroeditor.sensors.createSensor(true); + } + } + }); + add(selectUpdate); + } + + public void deleteParam() { + delete.setBounds(125,34,(int)(this.getWidth()/2.2),25); + delete.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent actionEvent) { + LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); + LiquidApplication.getGUI().variables.selectedObject = 0; + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + }); + add(delete); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroForcesPanel.java b/LIQUID/src/liquid/gui/EnviroForcesPanel.java new file mode 100644 index 0000000..3e79db1 --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroForcesPanel.java @@ -0,0 +1,187 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked + * to creating a force are present, such as the force in the X/Y directions. + */ +public class EnviroForcesPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // list of components needed to create a force + JComboBox forceType; + JComboBox forceSpeed; + JComboBox forceX; + JComboBox forceY; + JComboBox forceXComp; + JComboBox forceYComp; + + String[] foType = {"Source"}; + ArrayList params; + + /** + * Constructor creates the Force (or Initial Force) section of the EnvironmentEditorPanel. + */ + public EnviroForcesPanel() { + initComponents(); + } + + /** + * Method creates the labels and drop-downs associated with creating forces. + */ + public void initComponents() { + setBounds(5,30,240,205); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + // makes labels specific to creating forces + JLabel l = new JLabel("Object Type:"); + l.setBounds(5,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Flow Speed:"); + l.setBounds(125,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Coordinate:"); + l.setBounds(5,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Coordinate:"); + l.setBounds(125,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Force:"); + l.setBounds(5,110,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Force:"); + l.setBounds(125,110,(this.getWidth()/2),25); + add(l); + + // makes the drop-downs needed to create forces + forceType = new JComboBox(foType); + forceType.setBounds(5,30,(int)(this.getWidth()/2.2),25); + add(forceType); + + forceSpeed = new JComboBox(); + forceX = new JComboBox(); + forceY = new JComboBox(); + forceXComp = new JComboBox(); + forceYComp = new JComboBox(); + forcesParam(); // populates the drop-down information + createButton(); // makes a Create button + } + + /** + * Method adjusts the force's settings to be within the limit of the environment's size. It also provides + * a real-time update of the force parameters to prevent them from exceeding the environment's boundaries. + */ + public void forcesParam() { + // each drop-down first gets all items removed from it, then gets + // populated with items all dependent on the environment boundaries + forceSpeed.removeAllItems(); + for (int i = 0; i <= 100; i++) { + forceSpeed.addItem(Float.valueOf(i));} + forceSpeed.setBounds(125,30,(int)(this.getWidth()/2.2),25); + add(forceSpeed); + + forceX.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + forceX.addItem(Float.valueOf(i));} + forceX.setBounds(5,85,(int)(this.getWidth()/2.2),25); + add(forceX); + + forceY.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + forceY.addItem(Float.valueOf(i));} + forceY.setBounds(125,85,(int)(this.getWidth()/2.2),25); + add(forceY); + + forceXComp.removeAllItems(); + for (int i = -100; i <= 100; i++) { + forceXComp.addItem(Float.valueOf(i));} + forceXComp.setBounds(5,135,(int)(this.getWidth()/2.2),25); + add(forceXComp); + + forceYComp.removeAllItems(); + for (int i = -100; i <= 100; i++) { + forceYComp.addItem(Float.valueOf(i));} + forceYComp.setBounds(125,135,(int)(this.getWidth()/2.2),25); + add(forceYComp); + + // sets the default parameters even after an environment size change + resetForces(); + } + + /** + * Method used to call the editor panel to make a Create button for Forces. + */ + public void createButton() { + // button creates the obstacle according to the parameters set + JButton create = new JButton("Create"); + create.setBounds(65,170,(int)(this.getWidth()/2.2),25); + create.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + createForce(false); + } + }); + add(create); + } + + /** + * Method packages data and sends it to editor to check if valid and + * to be added into object list. + */ + public void createForce(boolean update){ + params = new ArrayList(); + params.add((Float) forceX.getSelectedItem()); + params.add((Float) forceY.getSelectedItem()); + params.add((Float) forceXComp.getSelectedItem()); + params.add((Float) forceYComp.getSelectedItem()); + params.add((Float) forceSpeed.getSelectedItem()); + LiquidApplication.getGUI().enviroeditor.checkBoundaries(forceType, params, update); + } + + /** + * Method splits up the String[] of the log file in order to correctly set the + * parameters of the Forces (or Initial Forces) section of the EnvironmentEditorPanel. + * + * @param tokens - String[] of the log file to split + */ + public void updateForces(String[] tokens) { + try { + forceType.setSelectedItem(tokens[0]); + forceX.setSelectedItem(Float.parseFloat(tokens[1])); + forceY.setSelectedItem(Float.parseFloat(tokens[2])); + forceXComp.setSelectedItem(Float.parseFloat(tokens[3])); + forceYComp.setSelectedItem(Float.parseFloat(tokens[4])); + forceSpeed.setSelectedItem(Float.parseFloat(tokens[5])); + } catch (Exception e) { + e.printStackTrace();} + } + + /** + * Method resets the parameters of the Forces section. + */ + public void resetForces() { + forceType.setSelectedIndex(0); + forceSpeed.setSelectedIndex(20); + forceX.setSelectedIndex(0); + forceY.setSelectedIndex(0); + forceXComp.setSelectedIndex(150); + forceYComp.setSelectedIndex(150); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroObstacles.java b/LIQUID/src/liquid/gui/EnviroObstacles.java deleted file mode 100644 index 93b70bb..0000000 --- a/LIQUID/src/liquid/gui/EnviroObstacles.java +++ /dev/null @@ -1,189 +0,0 @@ -package liquid.gui; - -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; - -import liquid.core.LiquidApplication; - -/** - * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked - * to creating an obstacle are present, such as the X-/Y-Coordinates. - */ -public class EnviroObstacles extends JPanel { - - private static final long serialVersionUID = 1L; - - // list of components needed to create an obstacle - JComboBox obstacleType; - JComboBox obstacleX; - JComboBox obstacleY; - JComboBox obstacleL; - JComboBox obstacleW; - String[] obstype = {"Rectangular", "Circular"}; - - /** - * Constructor creates the Obstacles section of the EnvironmentEditorPanel. - */ - public EnviroObstacles() { - initComponents(); - } - - /** - * Method creates the labels and drop-downs associated with creating obstacles. - */ - public void initComponents() { - setBounds(5,30,240,175); - setBackground(Color.LIGHT_GRAY); - setLayout(null); - - // makes labels specific to creating obstacles - JLabel l = new JLabel("Object Type:"); - l.setBounds(35,5,(this.getWidth()/2),25); - add(l); - - l = new JLabel("X-Coordinate:"); - l.setBounds(5,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Y-Coordinate:"); - l.setBounds(125,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Length:"); - l.setBounds(5,80,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Width:"); - l.setBounds(125,80,(this.getWidth()/2),25); - add(l); - - // makes the drop-downs needed to create obstacles - obstacleType = new JComboBox(obstype); - obstacleType.setBounds(115,5,(this.getWidth()/2),25); - add(obstacleType); - - // makes drop-downs to represent the parameters of an obstacle - obstacleX = new JComboBox(); - obstacleY = new JComboBox(); - obstacleL = new JComboBox(); - obstacleW = new JComboBox(); - adjustSettings(); // populates the drop-down information - createButton(); // creates the Create button - } - - /** - * Method adjusts the obstacles settings to be within the limit of the environment's size. It also provides - * a real-time update of the obstacle parameters to prevent them from exceeding the environment's boundaries. - */ - public void adjustSettings() { - // each drop-down first gets all items removed from it, then gets - // populated with items all dependent on the environment boundaries - obstacleX.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { - obstacleX.addItem(Float.valueOf(i));} - obstacleX.setBounds(5,55,(int)(this.getWidth()/2.2),25); - add(obstacleX); - - obstacleY.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { - obstacleY.addItem(Float.valueOf(i));} - obstacleY.setBounds(125,55,(int)(this.getWidth()/2.2),25); - add(obstacleY); - - // sets the default settings to be always 50, unless restricted by the environment - obstacleL.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { - obstacleL.addItem(Float.valueOf(i));} - obstacleL.setBounds(5,105,(int)(this.getWidth()/2.2),25); - add(obstacleL); - - obstacleW.removeAllItems(); - for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { - obstacleW.addItem(Float.valueOf(i));} - obstacleW.setBounds(125,105,(int)(this.getWidth()/2.2),25); - add(obstacleW); - - // sets what the default parameters should be - resetObstacles(); - } - - /** - * Method creates the Create button and throws error messages when - * the obstacle will go out of the predefined environment size. - */ - public void createButton() { - // button creates the obstacle according to the parameters set - JButton create = new JButton("Create"); - create.setBounds(65,140,(int)(this.getWidth()/2.2),25); - create.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - // throws error messages when the obstacle will go beyond the environment (determined - // by the X-/Y-Coordinates and the Length/Width of the obstacle, respectively) - if ((obstacleX.getSelectedIndex() + obstacleL.getSelectedIndex()) > EnvironmentEditorPanel.enviroLenLimit) { - JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, - "Warning!! Your X-Coordinate must be from 0.0 - " + (EnvironmentEditorPanel.enviroLenLimit - obstacleL.getSelectedIndex()) + - ",\n or your Length must be from 0.0 - " + (EnvironmentEditorPanel.enviroLenLimit - obstacleX.getSelectedIndex()) + - "\n to be in the boundaries of your desired environment size.", - "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); - } else if ((obstacleY.getSelectedIndex() + obstacleW.getSelectedIndex() > EnvironmentEditorPanel.enviroWidLimit)) { - JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, - "Warning!! Your Y-Coordinate must be from 0.0 - " + (EnvironmentEditorPanel.enviroWidLimit - obstacleW.getSelectedIndex()) + - ",\n or your Width must be from 0.0 - " + (EnvironmentEditorPanel.enviroWidLimit - obstacleY.getSelectedIndex()) + - "\n to be in the boundaries of your desired environment size.", - "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); - - // else sends the obstacle's information to the ArrayList of objects to store - } else { - String arg = obstacleType.getSelectedItem() + " " + - obstacleX.getSelectedItem() + " " + obstacleY.getSelectedItem() + " " + - obstacleL.getSelectedItem() + " " + obstacleW.getSelectedItem(); - LiquidApplication.getGUI().variables.objects.add(arg); - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size() - 1; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - } - }); - add(create); - } - - /** - * Method splits up the String[] of the log file in order to correctly set - * the parameters of the Obstacles section of the EnvironmentEditorPanel. - * - * @param tokens - String[] of the log file to split - */ - public void updateObstacles(String[] tokens) { - try { - obstacleType.setSelectedItem(tokens[0]); - obstacleX.setSelectedItem(tokens[1]); - obstacleY.setSelectedItem(tokens[2]); - obstacleL.setSelectedItem(tokens[3]); - obstacleW.setSelectedItem(tokens[4]); - } catch (Exception e) { - e.printStackTrace();} - } - - /** - * Method resets the parameters of the Obstacles section. - */ - public void resetObstacles() { - obstacleType.setSelectedIndex(0); - obstacleX.setSelectedIndex(0); - obstacleY.setSelectedIndex(0); - - // sets the default settings to be always 50, unless restricted by the environment - if (EnvironmentEditorPanel.enviroLenLimit >= 50) obstacleL.setSelectedIndex(50); - else obstacleL.setSelectedIndex((int) (EnvironmentEditorPanel.enviroLenLimit/10)); - - if (EnvironmentEditorPanel.enviroLenLimit >= 50) obstacleW.setSelectedIndex(50); - else obstacleW.setSelectedIndex((int) (EnvironmentEditorPanel.enviroLenLimit/10)); - } -} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroObstaclesPanel.java b/LIQUID/src/liquid/gui/EnviroObstaclesPanel.java new file mode 100644 index 0000000..5a4a2da --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroObstaclesPanel.java @@ -0,0 +1,191 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked + * to creating an obstacle are present, such as the X-/Y-Coordinates. + */ +public class EnviroObstaclesPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // list of components needed to create an obstacle + JComboBox obstacleType; + JComboBox obstacleRotation; + JComboBox obstacleX; + JComboBox obstacleY; + JComboBox obstacleL; + JComboBox obstacleW; + JButton create; + + String[] obsType = {"Rectangular", "Circular"}; + ArrayList params; + + /** + * Constructor creates the Obstacles section of the EnvironmentEditorPanel. + */ + public EnviroObstaclesPanel() { + initComponents(); + } + + /** + * Method creates the labels and drop-downs associated with creating obstacles. + */ + public void initComponents() { + setBounds(5,30,240,205); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + // makes labels specific to creating obstacles + JLabel l = new JLabel("Object Type:"); + l.setBounds(5,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Rotation (Degrees):"); + l.setBounds(125,5,(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Coordinate:"); + l.setBounds(5,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Coordinate:"); + l.setBounds(125,60,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Length:"); + l.setBounds(5,110,(this.getWidth()/2),25); + add(l); + + l = new JLabel("Width:"); + l.setBounds(125,110,(this.getWidth()/2),25); + add(l); + + // makes the drop-downs needed to creating obstacles + obstacleType = new JComboBox(obsType); + obstacleType.setBounds(5,30,(int)(this.getWidth()/2.2),25); + add(obstacleType); + + obstacleRotation = new JComboBox(); + obstacleX = new JComboBox(); + obstacleY = new JComboBox(); + obstacleL = new JComboBox(); + obstacleW = new JComboBox(); + create = new JButton("Create"); + obstaclesParam(); // populates the drop-down information + createButton(); // makes a Create button + + //EnviroAddiParamPanel test = new EnviroAddiParamPanel(); + //add(test); + } + + /** + * Method adjusts the obstacle's settings to be within the limit of the environment's size. It also provides + * a real-time update of the obstacle parameters to prevent them from exceeding the environment's boundaries. + */ + public void obstaclesParam() { + // each drop-down first gets all items removed from it, then gets + // populated with items all dependent on the environment boundaries + obstacleRotation.removeAllItems(); + for (int i = 0; i <= 360; i++) { + obstacleRotation.addItem(Float.valueOf(i));} + obstacleRotation.setBounds(125,30,(int)(this.getWidth()/2.2),25); + add(obstacleRotation); + + obstacleX.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + obstacleX.addItem(Float.valueOf(i));} + obstacleX.setBounds(5,85,(int)(this.getWidth()/2.2),25); + add(obstacleX); + + obstacleY.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + obstacleY.addItem(Float.valueOf(i));} + obstacleY.setBounds(125,85,(int)(this.getWidth()/2.2),25); + add(obstacleY); + + obstacleL.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + obstacleL.addItem(Float.valueOf(i));} + obstacleL.setBounds(5,135,(int)(this.getWidth()/2.2),25); + add(obstacleL); + + obstacleW.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + obstacleW.addItem(Float.valueOf(i));} + obstacleW.setBounds(125,135,(int)(this.getWidth()/2.2),25); + add(obstacleW); + + // sets the default parameters even after an environment size change + resetObstacles(); + } + + /** + * Method used to call the editor panel to make a Create button for Obstacles. + */ + public void createButton() { + // button creates the obstacle according to the parameters set + create.setBounds(65,170,(int)(this.getWidth()/2.2),25); + create.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + createObstacle(false); + } + }); + add(create); + } + + /** + * Method packages data and sends it to editor to check if valid and + * to be added into obstacle list. + */ + public void createObstacle(boolean update){ + params = new ArrayList(); + params.add((Float) obstacleX.getSelectedItem()); + params.add((Float) obstacleY.getSelectedItem()); + params.add((Float) obstacleL.getSelectedItem()); + params.add((Float) obstacleW.getSelectedItem()); + params.add((Float) obstacleRotation.getSelectedItem()); + LiquidApplication.getGUI().enviroeditor.checkBoundaries(obstacleType, params, update); + } + + /** + * Method splits up the String[] of the log file in order to correctly set + * the parameters of the Obstacles section of the EnvironmentEditorPanel. + * + * @param tokens - String[] of the log file to split + */ + public void updateObstacles(String[] tokens) { + try { + obstacleType.setSelectedItem(tokens[0]); + obstacleX.setSelectedItem(Float.parseFloat(tokens[1])); + obstacleY.setSelectedItem(Float.parseFloat(tokens[2])); + obstacleL.setSelectedItem(Float.parseFloat(tokens[3])); + obstacleW.setSelectedItem(Float.parseFloat(tokens[4])); + obstacleRotation.setSelectedItem(Float.parseFloat(tokens[5])); + } catch (Exception e) { + e.printStackTrace();} + } + + /** + * Method resets the parameters of the Obstacles section. + */ + public void resetObstacles() { + obstacleType.setSelectedIndex(0); + obstacleRotation.setSelectedIndex(0); + obstacleX.setSelectedIndex(0); + obstacleY.setSelectedIndex(0); + obstacleL.setSelectedIndex((int) (EnvironmentEditorPanel.enviroLenLimit/10)); + obstacleW.setSelectedIndex((int) (EnvironmentEditorPanel.enviroWidLimit/8)); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroSensorsPanel.java b/LIQUID/src/liquid/gui/EnviroSensorsPanel.java new file mode 100644 index 0000000..89f3295 --- /dev/null +++ b/LIQUID/src/liquid/gui/EnviroSensorsPanel.java @@ -0,0 +1,141 @@ +package liquid.gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import liquid.core.LiquidApplication; + +/** + * Class is a branch of the EnvironmentEditorPanel. Here, all elements + * linked to creating a sensor are present, such as the X-/Y-Coordinates. + */ +public class EnviroSensorsPanel extends JPanel { + + private static final long serialVersionUID = 1L; + + // list of components needed to create a source + JComboBox sensorType; + JComboBox sensorX; + JComboBox sensorY; + String[] senType = {"Flowmeter"}; // changed to "Flowmeter" without space to fix "flowmeters" not being rendered + ArrayList params; + + /** + * Constructor creates the Sensors (or Flow Sensors) section of the EnvironmentEditorPanel. + */ + public EnviroSensorsPanel() { + initComponents(); + } + + /** + * Method creates the labels and drop-downs associated with creating sensors. + */ + public void initComponents() { + setBounds(5,30,240,205); + setBackground(Color.LIGHT_GRAY); + setLayout(null); + + // makes labels specific to creating sensors + JLabel l = new JLabel("Object Type:"); + l.setBounds(35,5,(int)(this.getWidth()/2),25); + add(l); + + l = new JLabel("X-Coordinate:"); + l.setBounds(5,30,(int)(this.getWidth()/2),25); + add(l); + + l = new JLabel("Y-Coordinate:"); + l.setBounds(125, 30, 110, 25); + add(l); + + // makes the drop-downs needed to creating sensors + sensorType = new JComboBox(senType); + sensorType.setBounds(115,5,(int)(this.getWidth()/2),25); + add(sensorType); + + sensorX = new JComboBox(); + sensorY = new JComboBox(); + sensorsParam(); // populates the drop-down information + createButton(); // creates the Create button + } + + /** + * Method adjusts the sensor's settings to be within the limit of the environment's size. It also provides + * a real-time update of the sensor parameters to prevent them from exceeding the environment's boundaries. + */ + public void sensorsParam() { + // each drop-down first gets all items removed from it, then gets + // populated with items all dependent on the environment boundaries + sensorX.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroLenLimit; i++) { + sensorX.addItem(Float.valueOf(i));} + sensorX.setBounds(5,55,(int)(this.getWidth()/2.2),25); + add(sensorX); + + sensorY.removeAllItems(); + for (int i = 0; i <= EnvironmentEditorPanel.enviroWidLimit; i++) { + sensorY.addItem(Float.valueOf(i));} + sensorY.setBounds(125,55,(int)(this.getWidth()/2.2),25); + add(sensorY); + + // sets the default parameters even after an environment size change + resetSensors(); + } + + /** + * Method creates the Create button to add in a sensor. + */ + public void createButton() { + // button creates the obstacle according to the parameters set + JButton create = new JButton("Create"); + create.setBounds(65,90,(int)(this.getWidth()/2.2),25); + create.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + createSensor(false); + } + }); + add(create); + } + + /** + * Method packages data and sends it to editor to check if valid and + * to be added into object list. + */ + public void createSensor(boolean update){ + params = new ArrayList(); + params.add((Float) sensorX.getSelectedItem()); + params.add((Float) sensorY.getSelectedItem()); + LiquidApplication.getGUI().enviroeditor.checkBoundaries(sensorType, params, update); + } + + /** + * Method splits up the String[] of the log file in order to correctly set + * the parameters of the Sensors section of the EnvironmentEditorPanel. + * + * @param tokens - String[] of the log file to split + */ + public void updateSensors(String[] tokens) { + try { + sensorType.setSelectedItem(tokens[0]); + sensorX.setSelectedItem(Float.parseFloat(tokens[1])); + sensorY.setSelectedItem(Float.parseFloat(tokens[2])); + } catch (Exception e) { + e.printStackTrace();} + } + + /** + * Method resets the parameters of the Sensors section. + */ + public void resetSensors() { + sensorType.setSelectedIndex(0); + sensorX.setSelectedIndex(0); + sensorY.setSelectedIndex(0); + } +} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnviroSources.java b/LIQUID/src/liquid/gui/EnviroSources.java deleted file mode 100644 index 1de03d0..0000000 --- a/LIQUID/src/liquid/gui/EnviroSources.java +++ /dev/null @@ -1,137 +0,0 @@ -package liquid.gui; - -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import liquid.core.LiquidApplication; - -/** - * Class is a branch of the EnvironmentEditorPanel. Here, all elements linked - * to creating a source are present, such as the force in the X-/Y-Coordinates. - */ -public class EnviroSources extends JPanel { - - private static final long serialVersionUID = 1L; - - // list of components needed to create a source - JComboBox forceType; - JTextField forceX; - JTextField forceY; - JTextField forceXComp; - JTextField forceYComp; - String[] fotype = {"Source"}; - - /** - * Constructor creates the Source (or Initial Force) section of the EnvironmentEditorPanel. - */ - public EnviroSources() { - initComponents(); - } - - /** - * Method creates the labels and drop-downs associated with creating sources. - */ - public void initComponents() { - setBounds(5,30,240,175); - setBackground(Color.LIGHT_GRAY); - setLayout(null); - setVisible(false); - - // makes labels specific to creating sources - JLabel l = new JLabel("Object Type:"); - l.setBounds(35,5,(this.getWidth()/2),25); - add(l); - - l = new JLabel("X-Coordinate:"); - l.setBounds(5,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Y-Coordinate:"); - l.setBounds(125,30,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Force-X:"); - l.setBounds(5,80,(this.getWidth()/2),25); - add(l); - - l = new JLabel("Force-Y:"); - l.setBounds(125,80,(this.getWidth()/2),25); - add(l); - - // makes the drop-downs needed to create sources - forceType = new JComboBox(fotype); - forceType.setSelectedIndex(0); - forceType.setBounds(115, 5, 110, 25); - add(forceType); - - forceX = new JTextField("0"); - forceX.setBounds(5, 55, 110, 25); - add(forceX); - - forceY = new JTextField("0"); - forceY.setBounds(125, 55, 110, 25); - add(forceY); - - forceXComp = new JTextField("10"); - forceXComp.setBounds(5, 105, 110, 25); - add(forceXComp); - - forceYComp = new JTextField("10"); - forceYComp.setBounds(125, 105, 110, 25); - add(forceYComp); - - JButton create = new JButton("Create"); - create.setBounds(65, 140, 110, 25); - create.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - try { - String arg = forceType.getSelectedItem() + " " + - Float.parseFloat(forceX.getText()) + " " + Float.parseFloat(forceY.getText()) + " " + - Float.parseFloat(forceXComp.getText()) + " " + Float.parseFloat(forceYComp.getText()); - LiquidApplication.getGUI().variables.objects.add(arg); - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } catch (Exception e) { - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - add(create); - } - - /** - * Method splits up the String[] of the log file in order to correctly set - * the parameters of the Sources section of the EnvironmentEditorPanel. - * - * @param tokens - String[] of the log file to split - */ - public void updateSources(String[] tokens) { - try { - forceType.setSelectedItem(tokens[0]); - forceX.setText(tokens[1]); - forceY.setText(tokens[2]); - forceXComp.setText(tokens[3]); - forceYComp.setText(tokens[4]); - } catch (Exception e) { - e.printStackTrace();} - } - - /** - * Method resets the parameters of the Sources section. - */ - public void resetSources() { - forceType.setSelectedIndex(0); - forceX.setText("0"); - forceY.setText("0"); - forceXComp.setText("10"); - forceYComp.setText("10"); - } -} \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java b/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java index a3b52fb..6df79b3 100644 --- a/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java +++ b/LIQUID/src/liquid/gui/EnvironmentEditorPanel.java @@ -8,75 +8,60 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JTextField; import liquid.core.LiquidApplication; +/** + * Class stores the details of the EnvironmentEditorPanel section of the ParameterPanel + * class. Here, users will be able to create obstacles, liquid sources, or flow meters. + */ public class EnvironmentEditorPanel extends JPanel { private static final long serialVersionUID = 1L; String[] options = {"Environment", "Obstacles", "Initial Forces", "Flow Sensors"}; - JComboBox select; + + // defines parameters needed to adjust the environment size JPanel enviro; JComboBox enviroLen; JComboBox enviroWid; static float enviroLenLimit = 500; static float enviroWidLimit = 400; - EnviroObstacles obstacles; - EnviroSources forces; - - JPanel sensors; - JComboBox sensorType; - JTextField sensorX; - JTextField sensorY; + // creates the Obstacles, Forces, and Sensors parts of the panel + EnviroObstaclesPanel obstacles; + EnviroForcesPanel forces; + EnviroSensorsPanel sensors; + EnviroAddiParamPanel addiParam; + /** + * Constructor sets up the EnvironmentEditorPanel part of the ParameterPanel. It + * is currently located around the center part of the right side of the simulator. + */ public EnvironmentEditorPanel() { super(); initComponents(); setLayout(null); setBackground(Color.GRAY); - setBounds(25, 150, 250, 310); + setBounds(25,150,250,310); setVisible(true); } + /** + * Sets up some of the components of the EnvironmentEditorPanel. + */ public void initComponents() { Font font = new Font("Verdana", Font.BOLD, 12); setFont(font); - ActionListener snext = new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (LiquidApplication.getGUI().variables.selectedObject < LiquidApplication.getGUI().variables.objects.size()-1){ - LiquidApplication.getGUI().variables.selectedObject += 1; - } else { - LiquidApplication.getGUI().variables.selectedObject = 0; - } - update(); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }; - - ActionListener sprev = new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if( LiquidApplication.getGUI().variables.selectedObject > 0) { - LiquidApplication.getGUI().variables.selectedObject -= 1; - } else { - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; - } - update(); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }; - // sets the overall drop-down options for the EnvironmentEditorPanel select = new JComboBox(options); select.setBounds(5,5,240,25); @@ -96,21 +81,50 @@ public void itemStateChanged(ItemEvent arg0) { }); add(select); + // creates the Environment section + createEnvironment(); + + // creates the Obstacle section, which represents the EnviroObstacles class + obstacles = new EnviroObstaclesPanel(); + obstacles.setVisible(false); + add(obstacles); + + // creates the Initial Forces section, which represents the EnviroForces class + forces = new EnviroForcesPanel(); + forces.setVisible(false); + add(forces); + + // creates the Flow Sensors section, which represents the EnviroSensors class + sensors = new EnviroSensorsPanel(); + sensors.setVisible(false); + add(sensors); + + // creates the additional set of parameters + addiParam = new EnviroAddiParamPanel(); + addiParam.setVisible(true); + add(addiParam); + } + + /** + * Method creates the parameters to set the length/width of the simulating environment + * itself. A new method is created to provide flexibility in where it is created. + */ + public void createEnvironment() { // creates the Environment section, which sets the length/width of the environment enviro = new JPanel(); - enviro.setBounds(5,30,240,275); + enviro.setBounds(5,30,240,205); enviro.setBackground(Color.LIGHT_GRAY); enviro.setLayout(null); - + // makes labels for creating an environment JLabel l = new JLabel("Length:"); l.setBounds(5,0,110,25); enviro.add(l); - + l = new JLabel("Width:"); l.setBounds(5,50,110,25); enviro.add(l); - + // makes drop-downs for creating an environment enviroLen = new JComboBox(); for (int i = 0; i <= enviroLenLimit; i++) { @@ -118,285 +132,140 @@ public void itemStateChanged(ItemEvent arg0) { enviroLen.setSelectedIndex((int) enviroLenLimit); enviroLen.setBounds(5,25,110,25); enviro.add(enviroLen); - + enviroWid = new JComboBox(); for (int i = 0; i <= enviroWidLimit; i++) { enviroWid.addItem(Float.valueOf(i));} enviroWid.setSelectedIndex((int) enviroWidLimit); enviroWid.setBounds(5,75,110,25); enviro.add(enviroWid); - + // draws the size of the environment based on the parameters set JButton draw = new JButton("Draw"); draw.setBounds(5,125,110,25); draw.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - // sets the length/width according to the drop-downs - LiquidApplication.getGUI().variables.enviroLength = (float) enviroLen.getSelectedItem(); - LiquidApplication.getGUI().variables.enviroWidth = (float) enviroWid.getSelectedItem(); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - - // resets the limits to adjust the boundaries of creating various objects - enviroLenLimit = (float) enviroLen.getSelectedItem(); - enviroWidLimit = (float) enviroWid.getSelectedItem(); - obstacles.adjustSettings(); + public void actionPerformed(ActionEvent actionEvent) { + // sets the length/width according to the drop-downs + LiquidApplication.getGUI().variables.enviroLength = (float) enviroLen.getSelectedItem(); + LiquidApplication.getGUI().variables.enviroWidth = (float) enviroWid.getSelectedItem(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + + // resets the limits to adjust the boundaries of creating various objects + enviroLenLimit = (float) enviroLen.getSelectedItem(); + enviroWidLimit = (float) enviroWid.getSelectedItem(); + obstacles.obstaclesParam(); + forces.forcesParam(); + sensors.sensorsParam(); } - }); + }); enviro.add(draw); add(enviro); - - // creates the Obstacle section, which represents the EnviroObstacle class - obstacles = new EnviroObstacles(); - obstacles.setVisible(false); - add(obstacles); - - // creates the Initial Forces section, which represents the EnviroSource class - forces = new EnviroSources(); - add(forces); - - /**JButton selectNext = new JButton("Next Object"); - selectNext.setBounds(5, 200, 110, 25); - selectNext.addActionListener(snext); - obstacles.add(selectNext); - - JButton selectPrev = new JButton("Prev Object"); - selectPrev.setBounds(125, 200, 110, 25); - selectPrev.addActionListener(sprev); - obstacles.add(selectPrev); - - JButton selectUpdate = new JButton("Update Obj"); - selectUpdate.setBounds(5, 240, 110, 25); - selectUpdate.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = obstacleType.getSelectedItem() + " "; - arg += Float.parseFloat(obstacleX.getText()) + " "; - arg += Float.parseFloat(obstacleY.getText()) + " "; - arg += Float.parseFloat(obstacleL.getText()) + " "; - arg += Float.parseFloat(obstacleW.getText()); - LiquidApplication.getGUI().variables.objects.add(LiquidApplication.getGUI().variables.selectedObject, arg); - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject+1); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - obstacles.add(selectUpdate); - - JButton delete = new JButton("Delete"); - delete.setBounds(125, 240, 110, 25); - delete.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); - LiquidApplication.getGUI().variables.selectedObject = 0; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }); - obstacles.add(delete); - obstacles.setVisible(false); - add(obstacles); */ - - - - /**JButton selectNext = new JButton("Next Force"); - selectNext.setBounds(5, 200, 110, 25); - selectNext.addActionListener(snext); - forces.add(selectNext); - - JButton selectPrev = new JButton("Prev Force"); - selectPrev.setBounds(125, 200, 110, 25); - selectPrev.addActionListener(sprev); - forces.add(selectPrev); - - JButton selectUpdate = new JButton("Update For"); - selectUpdate.setBounds(5, 240, 110, 25); - selectUpdate.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = forceType.getSelectedItem() + " "; - arg += Float.parseFloat(forceX.getText()) + " "; - arg += Float.parseFloat(forceY.getText()) + " "; - arg += Float.parseFloat(forceXComp.getText()) + " "; - arg += Float.parseFloat(forceYComp.getText()); - LiquidApplication.getGUI().variables.objects.add(LiquidApplication.getGUI().variables.selectedObject, arg); - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject+1); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - forces.add(selectUpdate); - - JButton delete = new JButton("Delete"); - delete.setBounds(125, 240, 110, 25); - delete.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); - LiquidApplication.getGUI().variables.selectedObject = 0; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - } - }); - forces.add(delete); - add(forces);*/ - - sensors = new JPanel(); - sensors.setBounds(5, 30, 240, 275); - sensors.setLayout(null); - sensors.setBackground(Color.LIGHT_GRAY); - - l = new JLabel("Object Type:"); - l.setBounds(35, 5, 110, 25); - sensors.add(l); - - l = new JLabel("X:"); - l.setBounds(5, 30, 110, 25); - sensors.add(l); - - l = new JLabel("Y:"); - l.setBounds(125, 30, 110, 25); - sensors.add(l); - - String[] sentype = {"Flowmeter"}; //changed to "Flowmeter" without space to fix flowmeters not being rendered - sensorType = new JComboBox(sentype); - sensorType.setBounds(115, 5, 110, 25); - sensors.add(sensorType); - - sensorX = new JTextField("0"); - sensorX.setBounds(5, 55, 110, 25); - sensors.add(sensorX); - - sensorY = new JTextField("0"); - sensorY.setBounds(125, 55, 110, 25); - sensors.add(sensorY); - - JButton create = new JButton("Create"); - create.setBounds(65, 90, 110, 25); - create.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = sensorType.getSelectedItem() + " "; - arg += Float.parseFloat(sensorX.getText()) + " "; - arg += Float.parseFloat(sensorY.getText()); - LiquidApplication.getGUI().variables.objects.add(arg); - LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size()-1; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } - } - }); - sensors.add(create); - - - JButton selectNext = new JButton("Next Sensor"); - selectNext.setBounds(5, 200, 110, 25); - selectNext.addActionListener(snext); - sensors.add(selectNext); - - JButton selectPrev = new JButton("Prev Sensor"); - selectPrev.setBounds(125, 200, 110, 25); - selectPrev.addActionListener(sprev); - sensors.add(selectPrev); - - JButton selectUpdate = new JButton("Update Sen"); - selectUpdate.setBounds(5, 240, 110, 25); - selectUpdate.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - try{ - String arg = sensorType.getSelectedItem() + " "; - arg += Float.parseFloat(sensorX.getText()) + " "; - arg += Float.parseFloat(sensorY.getText()); - LiquidApplication.getGUI().variables.objects.add(LiquidApplication.getGUI().variables.selectedObject, arg); - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject+1); - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); - }catch(Exception e){ - LiquidApplication.getGUI().console.print_to_Console("Error: Inputed Value is Not Valid.\n"); - } + } + + /** + * Method checks the boundaries of the environment and throws error messages + * when the obstacle will go out of the predefined environment size. + * + * For the ArrayList: + * - 1 - X-Coordinate of Obstacle/Force + * - 2 - Y-Coordinate of Obstacle/Force + * - 3 - Length of Obstacle/X-Force of Force + * - 4 - Width of Obstacle/Y-Force of Force + * - 5 - Rotation of Obstacle/Flow Speed of Force + */ + public void checkBoundaries(JComboBox type, ArrayList params, boolean update) { + // throws error messages when the obstacle will go beyond the environment (determined + // by the X-/Y-Coordinates and the Length/Width of the obstacle, respectively) + if ((type.getSelectedItem().equals("Rectangular") || type.getSelectedItem().equals("Circular")) + &&(params.get(0) + params.get(2) > enviroLenLimit)) { + JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, + "Warning!! Your X-Coordinate must be from 0.0 - " + (enviroLenLimit - params.get(2)) + + ",\n or our Length must be from 0.0 - " + (enviroLenLimit - params.get(0)) + + "\n to be in the boundaries of your desired environment size.", + "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); + } else if ((type.getSelectedItem().equals("Rectangular") || type.getSelectedItem().equals("Circular")) + &&(params.get(1) + params.get(3) > enviroWidLimit)) { + JOptionPane.showMessageDialog(LiquidApplication.getGUI().frame, + "Warning!! Your Y-Coordinate must be from 0.0 - " + (enviroWidLimit - params.get(3)) + + ",\n or your Width must be from 0.0 - " + (enviroWidLimit - params.get(1)) + + "\n to be in the boundaries of your desired environment size.", + "Invalid Parameters!!", JOptionPane.WARNING_MESSAGE); + + // else sends the obstacle's information to the ArrayList of objects to store + } else { + String arg = type.getSelectedItem() + ""; + for(int i = 0; i < params.size(); i++) arg += " " + params.get(i); + if(update){ + LiquidApplication.getGUI().variables.objects.set(LiquidApplication.getGUI().variables.selectedObject, arg); + }else{ + LiquidApplication.getGUI().variables.objects.add(arg); + LiquidApplication.getGUI().variables.selectedObject = LiquidApplication.getGUI().variables.objects.size() - 1; } - }); - sensors.add(selectUpdate); - - JButton delete = new JButton("Delete"); - delete.setBounds(125, 240, 110, 25); - delete.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent actionEvent) { - LiquidApplication.getGUI().variables.objects.remove(LiquidApplication.getGUI().variables.selectedObject); - LiquidApplication.getGUI().variables.selectedObject = 0; - LiquidApplication.getGUI().variables.saveState(); - LiquidApplication.getGUI().sim.repaint(); + LiquidApplication.getGUI().variables.saveState(); + LiquidApplication.getGUI().sim.repaint(); + } + } + + /** + * Method enables/disables the components of the EnvironmentEditorPanel. + */ + public void setEnabled(boolean enable) { + for (Component x : getComponents()) { + x.setEnabled(enable); + if (x instanceof Container) { + for (Component y : ((Container) x).getComponents()) { + y.setEnabled(enable);} } - }); - sensors.add(delete); - sensors.setVisible(false); - add(sensors); + } } - public void update(){ + /** + * Method updates the simulation with the information presented in the log file. + */ + public void update() { enviroLen.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroLength)); enviroWid.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroWidth)); - try{ + try { + // obtains the line of parameters associated with a EnvironmentEditorPanel item String[] tokens = LiquidApplication.getGUI().variables.objects.get(LiquidApplication.getGUI().variables.selectedObject).split(" "); - if(tokens[0].equals("Rectangular") || tokens[0].equals("Circular")){ + // creates obstacle items, if any present + if (tokens[0].equals("Rectangular") || tokens[0].equals("Circular")) { select.setSelectedItem("Obstacles"); + obstacles.setVisible(true); forces.setVisible(false); sensors.setVisible(false); - obstacles.setVisible(true); - obstacles.updateObstacles(tokens); - } - if(tokens[0].equals("Source")){ + + // creates source items, if any present + } else if (tokens[0].equals("Source")) { select.setSelectedItem("Initial Forces"); + obstacles.setVisible(false); forces.setVisible(true); sensors.setVisible(false); + forces.updateForces(tokens); + + // creates flow meter items, if any present + } else if (tokens[0].equals("Flowmeter")) { + select.setSelectedItem("Flow Sensors"); obstacles.setVisible(false); - - forces.updateSources(tokens); - - } - if(tokens[0].equals("Flowmeter")){ - select.setSelectedItem("Sensors"); sensors.setVisible(true); forces.setVisible(false); - obstacles.setVisible(false); - sensorType.setSelectedItem(tokens[0]); - sensorX.setText(tokens[1]); - sensorY.setText(tokens[2]); + sensors.updateSensors(tokens); } - }catch(Exception e){ - e.printStackTrace(); - } + } catch(Exception e) { + e.printStackTrace();} } - public void reset(){ - enviroLen.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroLength)); - enviroWid.setSelectedItem(Float.toString(LiquidApplication.getGUI().variables.enviroWidth)); + /** + * Resets all parts of the EnvironmentEditorPanel to its default settings. + */ + public void reset() { select.setSelectedItem("Environment"); - + enviroLen.setSelectedItem(enviroLenLimit); + enviroWid.setSelectedItem(enviroWidLimit); obstacles.resetObstacles(); - forces.resetSources(); - - sensorType.setSelectedIndex(0); - sensorX.setText("0"); - sensorY.setText("0"); - } - - public void setEnabled(boolean enable){ - for(Component x : getComponents()){ - x.setEnabled(enable); - if(x instanceof Container){ - for(Component y : ((Container) x).getComponents()){ - y.setEnabled(enable); - } - } - } + forces.resetForces(); + sensors.resetSensors(); } } \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/LiquidFrame.java b/LIQUID/src/liquid/gui/LiquidFrame.java index 3788495..9c91439 100644 --- a/LIQUID/src/liquid/gui/LiquidFrame.java +++ b/LIQUID/src/liquid/gui/LiquidFrame.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import javax.swing.JFrame; @@ -35,7 +36,6 @@ public void dispose() { JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (exitSim == JOptionPane.YES_OPTION) { super.dispose(); - LiquidApplication.dispose(); - } + LiquidApplication.dispose();} } } \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/LiquidGUI.java b/LIQUID/src/liquid/gui/LiquidGUI.java index 11e7b2c..4476970 100644 --- a/LIQUID/src/liquid/gui/LiquidGUI.java +++ b/LIQUID/src/liquid/gui/LiquidGUI.java @@ -159,7 +159,8 @@ public void reset() { param.reset(); } - public void dispose() { - - } + /** + * Represents a placeholder method for when necessary to dispose something. + */ + public void dispose() {} } \ No newline at end of file diff --git a/LIQUID/src/liquid/gui/LiquidGuiVariables.java b/LIQUID/src/liquid/gui/LiquidGuiVariables.java index 77e4f31..1d6897b 100644 --- a/LIQUID/src/liquid/gui/LiquidGuiVariables.java +++ b/LIQUID/src/liquid/gui/LiquidGuiVariables.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import java.util.ArrayList; @@ -115,7 +116,7 @@ public void saveState() { } /** - * Un-does the lastest change made by the user. + * Un-does the latest change made by the user. */ public void undo() { // if there are unsaved changes, the latest changes will get be popped @@ -126,7 +127,7 @@ public void undo() { } /** - * Re-does the lastest change made by the user. + * Re-does the latest change made by the user. */ public void redo() { // if a set of un-did changes is present, then those set of parameters diff --git a/LIQUID/src/liquid/gui/LiquidMenuBar.java b/LIQUID/src/liquid/gui/LiquidMenuBar.java index 046fcf3..6c88452 100644 --- a/LIQUID/src/liquid/gui/LiquidMenuBar.java +++ b/LIQUID/src/liquid/gui/LiquidMenuBar.java @@ -1,3 +1,4 @@ +// DONE! package liquid.gui; import java.awt.Font; diff --git a/LIQUID/src/liquid/gui/ParameterPanel.java b/LIQUID/src/liquid/gui/ParameterPanel.java index a2fbdbf..7e124d8 100644 --- a/LIQUID/src/liquid/gui/ParameterPanel.java +++ b/LIQUID/src/liquid/gui/ParameterPanel.java @@ -256,7 +256,6 @@ public void update() { time.setSelectedItem(LiquidApplication.getGUI().variables.runtime); temp.setSelectedItem(LiquidApplication.getGUI().variables.temperature); visc.setSelectedItem(LiquidApplication.getGUI().variables.viscosity); - System.out.println(LiquidApplication.getGUI().variables.runtime); } /** diff --git a/LIQUID/src/liquid/logger/LiquidFileWriter.java b/LIQUID/src/liquid/logger/LiquidFileWriter.java index 07ec99d..22bb61e 100644 --- a/LIQUID/src/liquid/logger/LiquidFileWriter.java +++ b/LIQUID/src/liquid/logger/LiquidFileWriter.java @@ -20,7 +20,7 @@ public class LiquidFileWriter { * represent the log file, which stores all parameter information. * * @param fileName - the file's name to store in - * @param args - the String[] of parameters + * @param args - the String[] of parameters */ public void writetoLogFile(String fileName, String args[]) { try { @@ -53,8 +53,8 @@ public void appendtoLogFile(String fileName, String arg){ * is saved in the correct directory and whether or not it will override an existing file. * * @param fileDialog - uses same JFileChooser to keep consistency - * @param frame - the frame with which to display - * @return - String name of the file + * @param frame - the frame with which to display + * @return - String name of the file */ public String setUpFileToSave(JFileChooser fileDialog, Component frame) { File origFile = fileDialog.getCurrentDirectory(); diff --git a/logs/test.log b/logs/test.log index 3134f6d..33dd54e 100644 --- a/logs/test.log +++ b/logs/test.log @@ -1,9 +1,11 @@ C:\Users\Lauren\Documents\GitHub\AtlasSoft\logs\test.log Water -0 +2 70.0 1.0 300 -460.0 400.0 -Rectangular 0.0 0.0 50.0 50.0 +500.0 400.0 +Rectangular 75.0 0.0 50.0 89.0 0.0 +Source 270.0 276.0 172.0 2.0 20.0 +Source 67.0 46.0 99.0 149.0 50.0 break diff --git a/logs/test1.log b/logs/test1.log index 35d1518..7b725c5 100644 --- a/logs/test1.log +++ b/logs/test1.log @@ -1,15 +1,16 @@ C:\Users\GameDesign\Documents\GitHub\AtlasSoft\logs\test1.log Glycerin 6 -50.0 +53.0 2.0 15 400.0 300.0 -Rectangular 0 0 400 50 -Rectangular 0 250 400 50 -Rectangular 0 100 50 150 -Rectangular 350 50 50 150 -Rectangular 150.0 100.0 100.0 100.0 -Source 375.0 225.0 -100.0 0.0 -Source 25.0 75.0 100.0 0.0 +Rectangular 0 0 400 50 0.0 +Rectangular 0 250 400 50 0.0 +Rectangular 0 100 50 150 0.0 +Rectangular 350 50 50 150 0.0 +Rectangular 150.0 100.0 100.0 100.0 0.0 +Source 375.0 225.0 -100.0 0.0 10.0 +Source 25.0 75.0 100.0 0.0 10.0 +Circular 150.0 60.0 100.0 100.0 0.0 break diff --git a/logs/test2.log b/logs/test2.log index 53cbbad..2169028 100644 --- a/logs/test2.log +++ b/logs/test2.log @@ -1,10 +1,9 @@ C:\Users\GameDesign\Documents\GitHub\AtlasSoft\logs\test2.log Water -1 +0 70.0 1.0 -300 -300.0 300.0 -Rectangular 0.0 0.0 50.0 50.0 -Source 299.0 299.0 -100.0 -100.0 +15 +500.0 400.0 +Source 50.0 50.0 1.0 1.0 100.0 break diff --git a/logs/test3.log b/logs/test3.log deleted file mode 100644 index db9fc58..0000000 --- a/logs/test3.log +++ /dev/null @@ -1,8 +0,0 @@ -C:\Users\Lauren\Documents\GitHub\AtlasSoft\logs\test3.log -Water -0 -70.0 -1.0 -300 -500.0 400.0 -break diff --git a/logs/test4.log b/logs/test4.log deleted file mode 100644 index 89c1e3a..0000000 --- a/logs/test4.log +++ /dev/null @@ -1,16 +0,0 @@ -C:\Users\billi\Documents\GitHub\AtlasSoft\logs\test4.log -Glycerin -1 -50.0 -2.0 -15 -400.0 300.0 -Rectangular 0 0 400 50 -Rectangular 0 250 400 50 -Rectangular 0 100 50 150 -Rectangular 350 50 50 150 -Rectangular 150.0 100.0 100.0 100.0 -Source 375.0 225.0 -100.0 0.0 -Source 25.0 75.0 100.0 0.0 -Flowmeter 260.0 148.0 -break From 7f293c5192a08d05fac070f2e16e2bb9f6deea19 Mon Sep 17 00:00:00 2001 From: William Steele Date: Wed, 25 Nov 2015 14:00:48 -0500 Subject: [PATCH 3/3] Fixed conflicts? Hopefully, this should have fixed conflicts between master and this branch --- LIQUID/bin/liquid/engine/LiquidEngine.class | Bin 5086 -> 6297 bytes LIQUID/src/liquid/engine/Flowmeter.java | 7 +++---- LIQUID/src/liquid/engine/LiquidEngine.java | 6 ++---- logs/test3.log | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 logs/test3.log diff --git a/LIQUID/bin/liquid/engine/LiquidEngine.class b/LIQUID/bin/liquid/engine/LiquidEngine.class index afdb2e53035f65fc0ba5f2fa38d7804afe97f344..5e816c2aa9f2df092414c33692b593718436272c 100644 GIT binary patch delta 2613 zcma)8X>e0j7(HLJyyWGUZiEo93doYSsVS9WX#pwFVx`#9P_Z&&Nz+V84M|A?f}`e7 z2T>VZf->Mn2Sye*&^Dl8aYaQ1QE>;wU2w$}QR;Woq@@m{X8P{8oqO*2?!9^Gkuht> zs{2kq*#%%6m2FplQtT>r;VA{X2^lS}B`$~0dkBVBS1{z^Ty&4d zGPcryX9zS*#Uwl@@H}21=t8YNZnMj3-0=y<*#(w6vRaE3$ZoumVQ?17xW{rz|uAr3ghQOP6i=g)` zTI}+L2<9_2R5!LTyfo)Z1#c5Qs4t|c~0^h{bA+KM>QM@Lb`d;7%{K!~tijZxa*Izgy2^}VAxXh;2md~y$ zcg|@zgXVleBcuD(!8#f(XiW6DYK>5ipxl1=+PcesOdo#YwbEYqgZFx$F1J3#I3Rmhw69Wof6fmS|a*XzeP#)$M9}$2l6>1 z6WT_Zv*;RQ_&^eW6enKuzlqbYdm{>UEYJMZYU*0@LUJlmqTL==l5hM#4VzsE^N{F5XJ&Ti9C41cs4$!yH)YCnCmEW~hnJO4gtFoegg z$mMZ4zk+VWK&-%dxCu74dAJ4nScP%86_arrDsekz;||m#iiiuV;l-T@;x0t6hR3yN z$2x4m-Pn$M@C5F~Gq{i6`}gA@*5e(tQx?|q7i0t3u#t-J08POrx&)i423zO~Y^C{l zkQU$}T82lc4Uf`FY@^lKP8+a_9!3Xspc6w`>In>v$eV|AkjN`w2afS{I(vCh2 z$LrW-kJS(F@pw=2NzXZjyAStx+?O@sEkFh-Ts5$O>oAW68hHmtl7Wo8{rhlr!aIm2 zQpp4p-om9M7$-2FJDm$dH=l>9I6(@f@*lrd`NQKWxVkX~sY-7pg+CnNkU|3(Fu5D& z^32|H-^6J-jH9$@RmK?IPTqhgqDwP!CQ^F+UTC+?-AS2UyVaSwkD(}rQRxG!H$gi$ z_c0nIBaw`(94X1*oao^U+YCBSB23BT2#)m0V3aHw6A{+SC@opD$*7krFItt!Z^a8Z zX-Fc*NIzxPOad>GQDV{h$0>aqGLg=gKATE-Gi=CXYex~k<4Q0A(@?>7 z249&uZ0q&}yX0I0y`-Za> e`f_LU;&YKgllatAXfj>QR^@9m8akRX#rijD1a64{ delta 1418 zcmaJ=T}%{L6#fQ*Wru4)YcSAaZb($97}Hb|v^8<#E`~rs+1(JHHpA{!ww;}s?u>{{ zbYC0wZIVX%+=M25!P0623KmtXGQlGzMi~YJr@I(h&wcfq+vTkOQ`-x zA6-lAa@O~0MuOYPgy7~bt{Ggj?c{DFB@BnB_Sg>Z6&7tWpB;^-d2rX1>t8D*zen!}#smmv*Dn=1h;7cTJ z%d~|b3cg@?5i3-z!D)ss@s-Hy~xy*1yYL%Y0xZG8SYiK5QnWyH}y}@uZ zuWnbg!|QpQVb<+nwI#U2aM!h1br9b({2=3fi{gG__*wdvhC>ngir9`oS0MYqUl@Ls ziod(7H4>7V4-ZDpGoxfPeXk`bqHm^-VYFxYiQ^cbAXbDLvZXXe;2>Ti%d%$`FQb;2 zf(h4GwYFpwB^YyGt7>=yr+Utyc)0s>Opc#W+g|wuO~T5A0Bg#GJC1Rx>`OclKs%gP>8Ieo7MXcD1_*hEIJT^zH%p>=tlw&`-TUJ(Q za9=u~)$bX>sbMTfB|W+p^H_y?tRrkh6PgJ(VH;Wqw__(Fgi*xMOBhEA7U4U17yAhh z;5{57JdF1-NcaIh#1P>}IEqgRKf?qj2~T77G-l{mpyM{LV=ho`~ E0J?0Y=Kufz diff --git a/LIQUID/src/liquid/engine/Flowmeter.java b/LIQUID/src/liquid/engine/Flowmeter.java index 01c2ac5..cef93dd 100644 --- a/LIQUID/src/liquid/engine/Flowmeter.java +++ b/LIQUID/src/liquid/engine/Flowmeter.java @@ -31,10 +31,9 @@ public Flowmeter(World imHere, Vec2 loc, int ID){ public String update(){ DecimalFormat adj = new DecimalFormat(); -// Vec2 -// adj.setMaximumFractionDigits(4); - String send = "" + myID + ": "; - + Vec2 curVel = pollVelocity(); + adj.setMaximumFractionDigits(4); + String send = "" + myID + ": " + "X-Velocity " + adj.format(curVel.x) + " Y-Velocity " + adj.format(curVel.y); return send; } diff --git a/LIQUID/src/liquid/engine/LiquidEngine.java b/LIQUID/src/liquid/engine/LiquidEngine.java index 6ce31ff..d8cc374 100644 --- a/LIQUID/src/liquid/engine/LiquidEngine.java +++ b/LIQUID/src/liquid/engine/LiquidEngine.java @@ -135,12 +135,10 @@ public void initiateSim(String[] args) { String[] tokens = args[6].split(" "); enviro = new FluidEnvironment(Float.parseFloat(tokens[0]), Float.parseFloat(tokens[1])); -<<<<<<< HEAD - float x, y, l, w; + int ID = 1; -======= float x, y, l, w, r; ->>>>>>> origin/master + for (int i = 7; i < args.length; i++) { tokens = args[i].split(" "); if (tokens[0].equals("Rectangular")) { diff --git a/logs/test3.log b/logs/test3.log new file mode 100644 index 0000000..2becdf2 --- /dev/null +++ b/logs/test3.log @@ -0,0 +1,17 @@ +C:\Users\Will\Documents\GitHub\AtlasSoft\logs\test3.log +Glycerin +8 +53.0 +2.0 +15 +400.0 300.0 +Rectangular 0 0 400 50 0.0 +Rectangular 0 250 400 50 0.0 +Rectangular 0 100 50 150 0.0 +Rectangular 350 50 50 150 0.0 +Rectangular 150.0 100.0 100.0 100.0 0.0 +Source 375.0 225.0 -100.0 0.0 10.0 +Source 25.0 75.0 100.0 0.0 10.0 +Circular 150.0 60.0 100.0 100.0 0.0 +Flowmeter 246.0 60.0 +break