• Tidak ada hasil yang ditemukan

C. Flowchart Diagram - AI Expert

VI. Discussions 24

The reason for the choice of environmental variables used in the system’s built in model is due to the available data as of the time of study. This is why all of the environmental variables used are meteorological data from PAG ASA. The propo- nent have found no available data on edaphic (soil information) variables, which could be even more significant than the climate data. Looking at the variable contributions, we can see that despite having six variables, only 2 have contribu- tions with one of them being contributing significantly more to the model than the other one.

Another problem on the dataset is that the only available source of data con- tains localities on Central Visayas only even though the program is capable of handling data for the whole Philippines (the program would run relatively slower though) indicating that the program/tool is not being used to its full potential.

From the AUC score in the table below, we can see that the model have a score of 99.64%. However, there are some problems with this. As stated before the localities are only from Central Visayas, what more is that the localities are relatively close to one another which could have an effect on the model by making the surrounding area overrepresented, having an effect on the weights that would be produced.

Description Result

AUC Score 99.64%

Tmin Contribution 88.2043%

Tmax Contribution 11.7957%

VII. Conclusions

The software produced in this study is a stand-alone application that aims to provide researchers with a way to create models that could be used to predict the habitat suitability of Dipterocarp trees. Aside from it, the software also gives the user an existing model that could already be used to predict habitat suitability through data provided by PAG ASA and DENR.

The software uses a machine learning algorithm, MaxEnt, to predict the likely

species distribution of Dipterocarp trees. It is able to achieve 99.64% accuracy in

terms of AUC in predicting the suitable habitat for Visayas. Do note however, that

the data used for the built in model are only from Central Visayas, so predictions

using the built in model is accuracte only within the vicinity of the region.

VIII. Recommendations

The proponent suggests that the built in model be improved by collecting more presence data of Dipterocarp species nationwide as well as collecting more climate data and if possible soil information (altitude and soil type). As according to [18], these variables could characterize more the presence of Dipterocarp species.

A way to view what model could be used given a set of environmental variables would also be handy as from the current constraints, you could only predict using the same type of variables you used training your model. Not having to guess which environmental variables are used for which models would save a lot of time and avoid confusion.

For the implementation aspect, the proponent suggests moving the software

online. An online implementation of the said software would be more accessible

to more researchers, benefitting more people. Aside from being accessible to more

people, it would also be available over a larger area as you don’t need to have the

software installed on your machine.

IX. Bibliography

[1] P. S. Ashton et al., Dipterocarpaceae., vol. 9. 1982.

[2] T. Whitmore, “Tropical rain forests of the far east, 2nd edn. clarendon,” 1984.

[3] M. Newman, P. Burgess, and T. Whitmore, “Manuals of dipterocarps for foresters. borneo island light hardwoods,” Center for International Forestry Research, Jakarta, 1996.

[4] E. L. Boado, “Incentive policies and forest use in the philippines,” Public policies and the misuse of forest resources, pp. 165–204, 1988.

[5] E. Guiang and R. Aragon, “Forest restoration at the landscape level in the philippines,” Forest landscape restoration for Asia-Pacific forests, p. 125, 2016.

[6] A. Revilla Jr., “The worlds dipterocarp forests. in forest renewal in actual practice,” Columbian Publishing Corporation, 1984.

[7] Ecosystem Research and Development, “Development and management of forest plantations: a guidebook.,” 2010.

[8] E. T. Jaynes, “Information theory and statistical mechanics,” Physical review, vol. 106, no. 4, p. 620, 1957.

[9] M. Ramos, “COA: P7b tree-planting project of denr

a failure.” http://newsinfo.inquirer.net/687426/

coa-p7b-tree-planting-project-of-denr-a-failure. Retrieved:

2015-05-24.

[10] J. Grinnell, “The niche-relationships of the california thrasher,” The Auk, vol. 34, no. 4, pp. 427–433, 1917.

[11] A. Guisan and N. E. Zimmermann, “Predictive habitat distribution models

in ecology,” Ecological modelling, vol. 135, no. 2, pp. 147–186, 2000.

[12] R. P Anderson, M. Dud´ık, S. Ferrier, A. Guisan, R. J Hijmans, F. Huettmann, J. R Leathwick, A. Lehmann, J. Li, L. G Lohmann, et al., “Novel methods improve prediction of species distributions from occurrence data,” Ecography, vol. 29, no. 2, pp. 129–151, 2006.

[13] A. Townsend Peterson, M. Pape¸s, and M. Eaton, “Transferability and model evaluation in ecological niche modeling: a comparison of garp and maxent,”

Ecography, vol. 30, no. 4, pp. 550–560, 2007.

[14] R. KHOSRAVI, M.-R. HEMAMI, M. MALEKIAN, A. L. FLINT, and L. E.

FLINT, “Maxent modeling for predicting potential distribution of goitered gazelle in central iran: the effect of extent and grain size on performance of the model,” Turkish Journal of Zoology, p. 40, 2016.

[15] S. J. Phillips, R. P. Anderson, and R. E. Schapire, “Maximum entropy model- ing of species geographic distributions,” Ecological modelling, vol. 190, no. 3, pp. 231–259, 2006.

[16] R. G. Pearson, C. J. Raxworthy, M. Nakamura, and A. Townsend Peterson,

“Predicting species distributions from small numbers of occurrence records:

a test case using cryptic geckos in madagascar,” Journal of biogeography, vol. 34, no. 1, pp. 102–117, 2007.

[17] R. G. Mateo, ´ A. M. Felic´ısimo, and J. Mu˜ noz, “Effects of the number of presences on reliability and stability of mars species distribution models: the importance of regional niche variation and ecological heterogeneity,” Journal of Vegetation Science, vol. 21, no. 5, pp. 908–922, 2010.

[18] E. S. Fernando, M. J. Bande, R. A. Piollo, D. D. Sopot, N. E. Dolotina,

W. G. Granert, P. P. Milan, M. J. C. Ceniza, and M. T. Pollisco, “Habitats

of philippine dipterocarps,” 2009.

[19] C. Merow, M. J. Smith, and J. A. Silander, “A practical guide to maxent for modeling species distributions: what it does, and why inputs and settings matter,” Ecography, vol. 36, no. 10, pp. 1058–1069, 2013.

[20] K. Garcia, R. Lasco, A. Ines, B. Lyon, and F. Pulhin, “Predicting geographic distribution and habitat suitability due to climate change of selected threat- ened forest tree species in the philippines,” Applied Geography, vol. 44, pp. 12–

22, 2013.

[21] J. W. Gibbs, “On the equilibrium of heterogeneous substances,” American Journal of Science, no. 96, pp. 441–458, 1878.

[22] P. M. Williams, “Bayesian regularization and pruning using a laplace prior,”

Neural computation, vol. 7, no. 1, pp. 117–143, 1995.

X. Appendix

A. Source Code

#i n c l u d e <i o s t r e a m>

u s i n g n a m e s p a c e s t d ; i n t main{

c o u t << ” H e l l o w o r l d ! ” << e n d l ; r e t u r n 0 ;

}

A..1 UI

p a c k a g e u i ;

i m p o r t j a v a . awt . C o l o r ; i m p o r t j a v a . awt . D i m e n s i o n ;

i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a . awt . i m a g e . B u f f e r e d I m a g e ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a . i o . I O E x c e p t i o n ; i m p o r t j a v a . u t i l . A r r a y L i s t ; i m p o r t j a v a x . i m a g e i o . ImageIO ;

i m p o r t j a v a x . s w i n g . DefaultComboBoxModel ; i m p o r t j a v a x . s w i n g . I m a g e I c o n ;

i m p o r t j a v a x . s w i n g . J B u t t o n ; i m p o r t j a v a x . s w i n g . JCheckBox ; i m p o r t j a v a x . s w i n g . JComboBox ; i m p o r t j a v a x . s w i n g . J F i l e C h o o s e r ; i m p o r t j a v a x . s w i n g . JFrame ; i m p o r t j a v a x . s w i n g . J L a b e l ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J P a n e l ; i m p o r t j a v a x . s w i n g . J S c r o l l P a n e ; i m p o r t j a v a x . s w i n g . J S p i n n e r ; i m p o r t j a v a x . s w i n g . JTabbedPane ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ;

i m p o r t j a v a x . s w i n g . SpinnerNumberModel ; i m p o r t j a v a x . s w i n g . b o r d e r . B e v e l B o r d e r ; i m p o r t j a v a x . s w i n g . e v e n t . ChangeEvent ; i m p o r t j a v a x . s w i n g . e v e n t . C h a n g e L i s t e n e r ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R s e r v e E x c e p t i o n ; i m p o r t c o m p o n e n t A c t i o n s . Enable Own Model ;

i m p o r t c o m p o n e n t A c t i o n s . M P P r e d i c t ; i m p o r t c o m p o n e n t A c t i o n s . R e m o d e l P r e p ; i m p o r t c o m p o n e n t A c t i o n s . S P P r e d i c t ; i m p o r t c o m p o n e n t A c t i o n s . S e l e c t E V ; i m p o r t c o m p o n e n t A c t i o n s . S e l e c t M o d e l ; i m p o r t j a v a B a c k e n d . F i l t e r R e s u l t s ; i m p o r t j a v a B a c k e n d . I m a g e D i s p l a y e r ; i m p o r t j a v a B a c k e n d . M P D i s p l a y e r ; i m p o r t j a v a B a c k e n d . R e g i o n ; i m p o r t j a v a B a c k e n d . R e g i o n P a r s e r ; i m p o r t n e t . m i g i n f o c o m . s w i n g . MigLayout ; i m p o r t r B a c k e n d . RConnector ;

p u b l i c c l a s s Main {

p r i v a t e JFrame f r a m e ; p r i v a t e J P a n e l s p P a n e l ; p r i v a t e J P a n e l s p I n p u t s ; p r i v a t e JCheckBox spDefModCB ; p r i v a t e J T e x t F i e l d spModTF ; p r i v a t e J B u t t o n spModBtn ; p r i v a t e J T e x t F i e l d spEVTF ; p r i v a t e J B u t t o n spEVBtn ; p r i v a t e J B u t t o n s p P r e d i c t ; p r i v a t e R C o n n e c t i o n c ; p r i v a t e J P a n e l mpPanel ; p r i v a t e J P a n e l mpInputs ; p r i v a t e J L a b e l l b l I n p u t s ; p r i v a t e JCheckBox mpDefModCB ; p r i v a t e J T e x t F i e l d mpModTF ; p r i v a t e J B u t t o n mpModBtn ;

p r i v a t e J L a b e l l b l S e l e c t N u m b e r O f ; p r i v a t e J S p i n n e r s p i n n e r ;

p r i v a t e J P a n e l mpEVPanel ;

p r i v a t e A r r a y L i s t<R e g i o n> r e g i o n s ; p r i v a t e J T e x t F i e l d mpYear1EVTF ; p r i v a t e J T e x t F i e l d mpYear2EVTF ;

p r i v a t e A r r a y L i s t<J T e x t F i e l d>mpEVTF = new A r r a y L i s t<J T e x t F i e l d>() ; p r i v a t e A r r a y L i s t<JButton>mpEVBtn = new A r r a y L i s t<JButton>() ; p r i v a t e i n t envDataAdded = 2 ;

p r i v a t e J S c r o l l P a n e s c r o l l P a n e ; p r i v a t e J P a n e l p a n e l ;

p r i v a t e JComboBox f i l t e r B o x ; p r i v a t e J B u t t o n f i l t e r B t n ; p r i v a t e J L a b e l l b l F i l t e r B y R e g i o n ; p r i v a t e JTabbedPane d i s p l a y P a n e ; p r i v a t e J B u t t o n m p P r e d i c t ; p r i v a t e JComboBox m p F i l t e r B o x ; p r i v a t e J B u t t o n b t n D i s p l a y ; p r i v a t e J P a n e l g r a p h P a n e l ; p r i v a t e J P a n e l modPanel ;

p r i v a t e J T e x t F i e l d l o c a l i t i e s T F ; p r i v a t e J B u t t o n b t n L o c a l i t i e s ; p r i v a t e J T e x t F i e l d l a y e r s T F ; p r i v a t e J B u t t o n b t n L a y e r s ; p r i v a t e J T e x t F i e l d destTF ;

p r i v a t e J B u t t o n b t n S e l e c t D e s t i n a t i o n ; p r i v a t e J T e x t F i e l d f a c t o r s T F ;

p r i v a t e J L a b e l f a c t o r s L b l ;

p r i v a t e J B u t t o n b t n S t a r t M o d e l l i n g ; p r i v a t e J L a b e l l b l M o d e l P a r a m e t e r s ;

p r i v a t e J B u t t o n b t n S h o w V a r i a b l e C o n t r i b u t i o n ;

/∗∗

∗ Launch t h e a p p l i c a t i o n .

∗/

p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { Main window = new Main ( ) ; window . f r a m e . s e t V i s i b l e ( t r u e ) ; }

/∗∗

∗ C r e a t e t h e a p p l i c a t i o n .

∗/

p u b l i c Main ( ) {

RConnector n e w C o n n e c t i o n = new RConnector ( ) ; R e g i o n P a r s e r r p = new R e g i o n P a r s e r ( ) ; r e g i o n s = r p . r e g i o n P a r s e r ( ) ;

Runtime . g e t R u n t i m e ( ) . addShutdownHook ( new Thread ( new Runnable ( ) { p u b l i c v o i d r u n ( ) {

t r y {

c . shutdown ( ) ;

System . o u t . p r i n t l n ( ” R s e r v e t e r m i n a t e d ” ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” R s e r v e d i d n ’ t shutdown p r o p e r l y . Shut i t down m a n u a l l y t o d e a l l o c a t e r e s o u r c e s ” , ” N o t i c e ” , JO ptio nPa ne . WARNING MESSAGE) ;

} }

}) ) ;

t h i s . c = n e w C o n n e c t i o n . g e t R C o n n e c t i o n ( ) ; i n i t i a l i z e ( ) ;

} /∗∗

∗ I n i t i a l i z e t h e c o n t e n t s o f t h e f r a m e .

∗/

p r i v a t e v o i d i n i t i a l i z e ( ) { f r a m e = new JFrame ( ) ;

f r a m e . s e t T i t l e ( ” D i p t e r o c a r p M o d e l l i n g T o o l ” ) ; f r a m e . s e t M i n i m u m S i z e ( new D i m e n s i o n ( 8 0 0 , 6 0 0 ) ) ; f r a m e . s e t D e f a u l t C l o s e O p e r a t i o n ( JFrame . EXIT ON CLOSE ) ;

f r a m e . g e t C o n t e n t P a n e ( ) . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ;

d i s p l a y P a n e = new JTabbedPane ( JTabbedPane .TOP) ;

f r a m e . g e t C o n t e n t P a n e ( ) . add ( d i s p l a y P a n e , ” c e l l 0 0 , grow ” ) ; s p P a n e l = new J P a n e l ( ) ;

d i s p l a y P a n e . addTab ( ” S i n g l e Year P r e d i c t i o n ” , n u l l , s p P a n e l , n u l l ) ; s p P a n e l . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ;

s p I n p u t s = new J P a n e l ( ) ;

s p P a n e l . add ( s p I n p u t s , ” c e l l 0 0 , grow ” ) ;

s p I n p u t s . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] [ ] ” ,

” [ ] [ ] [ ] [ 1 0 % ] [ ] [ ] [ 1 0 % ] [ ] [ grow ] ” ) ) ; spModTF = new J T e x t F i e l d ( ) ;

spModTF . s e t B a c k g r o u n d ( C o l o r . WHITE) ; spModTF . s e t E d i t a b l e ( f a l s e ) ;

s p I n p u t s . add ( spModTF , ” f l o w x , c e l l 0 1 2 1 , growx ” ) ; spModTF . s e t C o l u m n s ( 1 0 ) ;

spModBtn = new J B u t t o n ( ” I n p u t y o u r own model ” ) ; s p I n p u t s . add ( spModBtn , ” c e l l 0 2 2 1 , grow ” ) ; spModBtn . s e t E n a b l e d ( f a l s e ) ;

spModBtn . a d d A c t i o n L i s t e n e r ( new S e l e c t M o d e l ( spModTF ) ) ; spEVTF = new J T e x t F i e l d ( ) ;

spEVTF . s e t B a c k g r o u n d ( C o l o r . WHITE) ; spEVTF . s e t E d i t a b l e ( f a l s e ) ;

s p I n p u t s . add ( spEVTF , ” c e l l 0 4 2 1 , growx ” ) ; spEVTF . s e t C o l u m n s ( 1 0 ) ;

spEVBtn = new J B u t t o n ( ” I n p u t l a y e r s ” ) ; s p I n p u t s . add ( spEVBtn , ” c e l l 0 5 2 1 , grow ” ) ; spEVBtn . a d d A c t i o n L i s t e n e r ( new S e l e c t E V ( spEVTF ) ) ; spDefModCB = new JCheckBox ( ” Use d e f a u l t model ” ) ; s p I n p u t s . add ( spDefModCB , ” c e l l 0 0 ” ) ;

spDefModCB . s e t S e l e c t e d ( t r u e ) ;

spDefModCB . a d d C h a n g e L i s t e n e r ( new Enable Own Model ( spDefModCB , spModBtn ) ) ;

p a n e l = new J P a n e l ( ) ;

s p I n p u t s . add ( p a n e l , ” c e l l 0 8 2 1 , grow ” ) ; p a n e l . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] [ ] ” ,

” [ 1 5 % ] [ ] ” ) ) ;

l b l F i l t e r B y R e g i o n = new J L a b e l ( ” F i l t e r by r e g i o n : ” ) ; p a n e l . add ( l b l F i l t e r B y R e g i o n , ” c e l l 0 1 ” ) ;

f i l t e r B o x = new JComboBox ( ) ; f i l t e r B o x . s e t E n a b l e d ( f a l s e ) ;

f i l t e r B o x . s e t M o d e l ( new DefaultComboBoxModel ( new S t r i n g [ ] {”− Whole P h i l i p p i n e s −” , ” N e g r o s I s l a n d R e g i o n

” , ” N a t i o n a l C a p i t a l R e g i o n ” , ” C o r d i l l e r a

A d m i n i s t r a t i v e R e g i o n ” , ” I − I l o c o s R e g i o n ” , ” I I − Cagayan V a l l e y ” , ” I I I − C e n t r a l Luzon ” , ” IV−A− CALABARZON” , ”MIMAROPA R e g i o n ” , ”V− B i c o l ” , ” VI −

Western V i s a y a s ” , ” V I I − C e n t r a l V i s a y a s ” , ” V I I I

− E a s t e r n V i s a y a s ” , ” IX− Zamboanga P e n i n s u l a ” , ”X

− N o r t h e r n Mindanao ” , ” XI− Davao R e g i o n ” , ” X I I − S o c c s k s a r g e n ” , ” X I I I − Caraga ” , ”ARMM”}) ) ; p a n e l . add ( f i l t e r B o x , ” c e l l 0 2 , growx ” ) ;

f i l t e r B t n = new J B u t t o n ( ” F i l t e r ” ) ; f i l t e r B t n . s e t E n a b l e d ( f a l s e ) ; p a n e l . add ( f i l t e r B t n , ” c e l l 1 2 ” ) ;

f i l t e r B t n . a d d A c t i o n L i s t e n e r ( new S P F i l t e r R e s u l t s ( ) ) ; s p P r e d i c t = new J B u t t o n ( ” P r e d i c t ” ) ;

s p I n p u t s . add ( s p P r e d i c t , ” c e l l 0 7 2 1 , a l i g n x c e n t e r ” ) ; s p P r e d i c t . a d d A c t i o n L i s t e n e r ( new S P P r e d i c t ( spModTF ,

spEVTF , spDefModCB , c , f i l t e r B t n , f i l t e r B o x ) ) ; mpPanel = new J P a n e l ( ) ;

d i s p l a y P a n e . addTab ( ” M u l t i−Year P r e d i c t i o n ” , n u l l , mpPanel , n u l l ) ; mpPanel . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ;

mpInputs = new J P a n e l ( ) ;

mpPanel . add ( mpInputs , ” c e l l 0 0 , grow ” ) ;

mpInputs . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] [ grow ] ” ,

” [ ] [ ] [ ] [ ] [ grow ] [ ] ” ) ) ;

l b l I n p u t s = new J L a b e l ( ” INPUTS ” ) ; mpInputs . add ( l b l I n p u t s , ” c e l l 0 0 ” ) ; g r a p h P a n e l = new J P a n e l ( ) ;

g r a p h P a n e l . s e t B o r d e r ( new B e v e l B o r d e r ( B e v e l B o r d e r . LOWERED, n u l l , n u l l , n u l l , n u l l ) ) ;

mpInputs . add ( g r a p h P a n e l , ” c e l l 1 0 1 6 , grow ” ) ; mpModTF = new J T e x t F i e l d ( ) ;

mpModTF . s e t E d i t a b l e ( f a l s e ) ;

mpInputs . add (mpModTF, ” f l o w x , c e l l 0 2 , growx ” ) ; mpModTF . s e t C o l u m n s ( 1 0 ) ;

mpModBtn = new J B u t t o n ( ” S e l e c t model ” ) ; mpModBtn . s e t E n a b l e d ( f a l s e ) ;

mpModBtn . a d d A c t i o n L i s t e n e r ( new S e l e c t M o d e l (mpModTF) ) ; mpInputs . add ( mpModBtn , ” c e l l 0 2 , wmin 1 0 0 ” ) ;

mpDefModCB = new JCheckBox ( ” Use d e f a u l t model ” ) ; mpDefModCB . s e t S e l e c t e d ( t r u e ) ;

mpDefModCB . a d d C h a n g e L i s t e n e r ( new Enable Own Model ( mpDefModCB , mpModBtn ) ) ;

mpInputs . add ( mpDefModCB , ” c e l l 0 1 ” ) ;

l b l S e l e c t N u m b e r O f = new J L a b e l ( ” S e l e c t number o f y e a r s t o p r e d i c t : ” ) ;

mpInputs . add ( l b l S e l e c t N u m b e r O f , ” f l o w x , c e l l 0 3 ” ) ; s p i n n e r = new J S p i n n e r ( ) ;

s p i n n e r . s e t M o d e l ( new SpinnerNumberModel ( new I n t e g e r ( 2 ) , new I n t e g e r ( 2 ) , n u l l , new I n t e g e r ( 1 ) ) ) ;

mpInputs . add ( s p i n n e r , ” c e l l 0 3 ” ) ; s c r o l l P a n e = new J S c r o l l P a n e ( ) ;

mpInputs . add ( s c r o l l P a n e , ” c e l l 0 4 , grow ” ) ; mpEVPanel = new J P a n e l ( ) ;

s c r o l l P a n e . s e t V i e w p o r t V i e w ( mpEVPanel ) ;

mpEVPanel . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” ,

” [ ] [ ] ” ) ) ;

mpYear1EVTF = new J T e x t F i e l d ( ) ;

mpEVPanel . add ( mpYear1EVTF , ” f l o w x , c e l l 0 0 , growx ” ) ;

mpYear1EVTF . s e t C o l u m n s ( 1 0 ) ; mpYear1EVTF . s e t E d i t a b l e ( f a l s e ) ;

J B u t t o n mpYear1EVBtn = new J B u t t o n ( ” S e l e c t l a y e r s f o r y e a r 1 ” ) ;

mpEVPanel . add ( mpYear1EVBtn , ” c e l l 0 0 , wmin 2 0 0 ” ) ; mpYear1EVBtn . a d d A c t i o n L i s t e n e r ( new S e l e c t E V (

mpYear1EVTF ) ) ;

mpYear2EVTF = new J T e x t F i e l d ( ) ;

mpEVPanel . add ( mpYear2EVTF , ” f l o w x , c e l l 0 1 , growx ” ) ; mpYear2EVTF . s e t C o l u m n s ( 1 0 ) ;

mpYear2EVTF . s e t E d i t a b l e ( f a l s e ) ;

J B u t t o n mpYear2EVBtn = new J B u t t o n ( ” S e l e c t l a y e r s f o r y e a r 2 ” ) ;

mpEVPanel . add ( mpYear2EVBtn , ” c e l l 0 1 , wmin 2 0 0 ” ) ; mpYear2EVBtn . a d d A c t i o n L i s t e n e r ( new S e l e c t E V (

mpYear2EVTF ) ) ; mpEVTF . add ( mpYear1EVTF ) ; mpEVTF . add ( mpYear2EVTF ) ; mpEVBtn . add ( mpYear2EVBtn ) ; mpEVBtn . add ( mpYear1EVBtn ) ; m p F i l t e r B o x = new JComboBox ( ) ; m p F i l t e r B o x . s e t E n a b l e d ( f a l s e ) ;

mpInputs . add ( m p F i l t e r B o x , ” f l o w x , c e l l 0 5 , growx ” ) ; m p F i l t e r B o x . s e t M o d e l ( new DefaultComboBoxModel ( new

S t r i n g [ ] {”− Whole P h i l i p p i n e s −” , ” N e g r o s I s l a n d R e g i o n ” , ” N a t i o n a l C a p i t a l R e g i o n ” , ” C o r d i l l e r a A d m i n i s t r a t i v e R e g i o n ” , ” I − I l o c o s R e g i o n ” , ” I I −

Cagayan V a l l e y ” , ” I I I − C e n t r a l Luzon ” , ” IV−A− CALABARZON” , ”MIMAROPA R e g i o n ” , ”V− B i c o l ” , ” VI −

Western V i s a y a s ” , ” V I I − C e n t r a l V i s a y a s ” , ” V I I I

− E a s t e r n V i s a y a s ” , ” IX− Zamboanga P e n i n s u l a ” , ”X

− N o r t h e r n Mindanao ” , ” XI− Davao R e g i o n ” , ” X I I − S o c c s k s a r g e n ” , ” X I I I − Caraga ” , ”ARMM”}) ) ; b t n D i s p l a y = new J B u t t o n ( ” D i s p l a y ” ) ;

b t n D i s p l a y . s e t E n a b l e d ( f a l s e ) ;

mpInputs . add ( b t n D i s p l a y , ” c e l l 0 5 , a l i g n x r i g h t ” ) ; b t n D i s p l a y . a d d A c t i o n L i s t e n e r ( new M P F i l t e r R e s u l t s ( ) ) ; m p P r e d i c t = new J B u t t o n ( ” P r e d i c t ” ) ;

mpInputs . add ( m p P r e d i c t , ” c e l l 0 2 , wmin 1 0 0 ” ) ; m p P r e d i c t . a d d A c t i o n L i s t e n e r ( new M P P r e d i c t (mpModTF,

mpEVTF, mpDefModCB , c , m p F i l t e r B o x , b t n D i s p l a y , g r a p h P a n e l ) ) ;

modPanel = new J P a n e l ( ) ;

d i s p l a y P a n e . addTab ( ” R e m o d e l l i n g ” , n u l l , modPanel , n u l l ) ;

modPanel . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] [ ] ” ,

” [ 1 0 % ] [ ] [ ] [ ] [ ] [ 5 0 % , grow ] ” ) ) ;

l b l M o d e l P a r a m e t e r s = new J L a b e l ( ” Model P a r a m e t e r s : ” ) ; modPanel . add ( l b l M o d e l P a r a m e t e r s , ” c e l l 0 0 ” ) ;

l o c a l i t i e s T F = new J T e x t F i e l d ( ) ; l o c a l i t i e s T F . s e t E d i t a b l e ( f a l s e ) ;

modPanel . add ( l o c a l i t i e s T F , ” f l o w x , c e l l 0 1 , growx ” ) ; l o c a l i t i e s T F . s e t C o l u m n s ( 1 0 ) ;

b t n L o c a l i t i e s = new J B u t t o n ( ” S e l e c t l o c a l i t i e s ” ) ; b t n L o c a l i t i e s . a d d A c t i o n L i s t e n e r ( new A c t i o n L i s t e n e r ( ) {

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t e ) { J F i l e C h o o s e r c h o o s e r = new

J F i l e C h o o s e r ( ) ;

c h o o s e r . s e t D i a l o g T i t l e ( ” S e l e c t l o c a l i t i e s ” ) ;

i n t u s e r S e l e c t i o n = c h o o s e r . s h o w O p e n D i a l o g ( f r a m e ) ; i f ( u s e r S e l e c t i o n == J F i l e C h o o s e r .

APPROVE OPTION) {

l o c a l i t i e s T F . s e t T e x t ( c h o o s e r . g e t S e l e c t e d F i l e ( ) . g e t A b s o l u t e P a t h ( ) ) ; }

} }) ;

modPanel . add ( b t n L o c a l i t i e s , ” c e l l 0 1 , wmin 1 5 0 ” ) ;

l a y e r s T F = new J T e x t F i e l d ( ) ; l a y e r s T F . s e t E d i t a b l e ( f a l s e ) ;

modPanel . add ( l a y e r s T F , ” f l o w x , c e l l 0 2 , growx ” ) ; l a y e r s T F . s e t C o l u m n s ( 1 0 ) ;

b t n L a y e r s = new J B u t t o n ( ” S e l e c t l a y e r s ” ) ;

b t n L a y e r s . a d d A c t i o n L i s t e n e r ( new S e l e c t E V ( l a y e r s T F ) ) ; modPanel . add ( b t n L a y e r s , ” c e l l 0 2 , wmin 1 5 0 ” ) ;

b t n S e l e c t D e s t i n a t i o n = new J B u t t o n ( ” S e l e c t d e s t i n a t i o n

” ) ;

b t n S e l e c t D e s t i n a t i o n . a d d A c t i o n L i s t e n e r ( new A c t i o n L i s t e n e r ( ) {

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t e ) { J F i l e C h o o s e r c h o o s e r = new

J F i l e C h o o s e r ( ) ;

c h o o s e r . s e t D i a l o g T i t l e ( ” S e l e c t d e s t i n a t i o n o f model o b j e c t ” ) ; i n t u s e r S e l e c t i o n = c h o o s e r .

s h o w S a v e D i a l o g ( f r a m e ) ; i f ( u s e r S e l e c t i o n == J F i l e C h o o s e r .

APPROVE OPTION) {

F i l e p a t h = c h o o s e r . g e t S e l e c t e d F i l e ( ) ; destTF . s e t T e x t ( p a t h .

g e t A b s o l u t e P a t h ( ) ) ; }

} }) ;

destTF = new J T e x t F i e l d ( ) ; destTF . s e t E d i t a b l e ( f a l s e ) ;

modPanel . add ( destTF , ” f l o w x , c e l l 0 3 , growx ” ) ; destTF . s e t C o l u m n s ( 1 0 ) ;

modPanel . add ( b t n S e l e c t D e s t i n a t i o n , ” c e l l 0 3 , wmin 1 5 0 ” ) ;

f a c t o r s L b l = new J L a b e l ( ” F a c t o r s ( h o v e r mouse f o r t o o l t i p ) : ” ) ;

f a c t o r s L b l . s e t T o o l T i p T e x t ( ” f a c t o r 1 , f a c t o r 2 , f a c t o r 3 ” )

;

modPanel . add ( f a c t o r s L b l , ” f l o w x , c e l l 0 4 ” ) ; f a c t o r s T F = new J T e x t F i e l d ( ) ;

modPanel . add ( f a c t o r s T F , ” c e l l 0 4 , wmin 2 0 0 ” ) ; f a c t o r s T F . s e t C o l u m n s ( 1 0 ) ;

b t n S t a r t M o d e l l i n g = new J B u t t o n ( ” S t a r t M o d e l l i n g ” ) ; modPanel . add ( b t n S t a r t M o d e l l i n g , ” c e l l 1 1 1 3 , wmin

1 8 0 , grow ” ) ;

b t n S h o w V a r i a b l e C o n t r i b u t i o n = new J B u t t o n ( ” Show v a r i a b l e c o n t r i b u t i o n ” ) ;

b t n S h o w V a r i a b l e C o n t r i b u t i o n . s e t E n a b l e d ( f a l s e ) ; b t n S h o w V a r i a b l e C o n t r i b u t i o n . a d d A c t i o n L i s t e n e r ( new

A c t i o n L i s t e n e r ( ) {

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t a r g 0 ) {

I m a g e D i s p l a y e r d i s p l a y e r = new I m a g e D i s p l a y e r ( ” p i c t u r e s / w e i g h t s . png ” , ” model ” ) ;

} }) ;

modPanel . add ( b t n S h o w V a r i a b l e C o n t r i b u t i o n , ” c e l l 1 4 , wmin 1 8 0 , grow ” ) ;

b t n S t a r t M o d e l l i n g . a d d A c t i o n L i s t e n e r ( new R e m o d e l P r e p ( c , l a y e r s T F , l o c a l i t i e s T F , f a c t o r s T F , destTF , b t n S h o w V a r i a b l e C o n t r i b u t i o n ) ) ;

S p i n n e r L i s t e n e r c l = new S p i n n e r L i s t e n e r ( ) ; s p i n n e r . a d d C h a n g e L i s t e n e r ( c l ) ;

}

p u b l i c c l a s s S p i n n e r L i s t e n e r i m p l e m e n t s C h a n g e L i s t e n e r {

@ O v e r r i d e

p u b l i c v o i d s t a t e C h a n g e d ( ChangeEvent a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b i n t newVal = ( i n t ) s p i n n e r . g e t V a l u e ( ) ; i f ( newVal > envDataAdded ) {

J T e x t F i e l d newTf = new J T e x t F i e l d ( ) ; newTf . s e t E d i t a b l e ( f a l s e ) ;

newTf . s e t C o l u m n s ( 1 0 ) ;

J B u t t o n newButt = new J B u t t o n ( ” S e l e c t l a y e r s f o r y e a r ” + I n t e g e r . t o S t r i n g ( envDataAdded + 1 ) ) ;

mpEVPanel . add ( newTf , ” f l o w x , c e l l 0 ” + I n t e g e r . t o S t r i n g ( envDataAdded ) + ” , growx ” ) ;

mpEVPanel . add ( newButt , ”wmin 2 0 0 , c e l l 0 ” + I n t e g e r . t o S t r i n g ( envDataAdded ) ) ;

newButt . a d d A c t i o n L i s t e n e r ( new S e l e c t E V ( newTf ) ) ; envDataAdded++;

mpEVTF . add ( newTf ) ; mpEVBtn . add ( newButt ) ;

// System . o u t . p r i n t l n ( newVal + ”\t ” + c u r r S p i n n e r V a l u e + ” add

” + envDataAdded ) ; }

e l s e i f ( newVal < envDataAdded ) {

mpEVTF . g e t ( envDataAdded − 1 ) . s e t V i s i b l e ( f a l s e ) ; mpEVBtn . g e t ( envDataAdded− 1 ) . s e t V i s i b l e ( f a l s e ) ; mpEVPanel . remove (mpEVTF . g e t ( envDataAdded − 1 ) ) ; mpEVPanel . remove ( mpEVBtn . g e t ( envDataAdded− 1 ) ) ; mpEVTF . remove ( envDataAdded − 1 ) ;

mpEVBtn . remove ( envDataAdded − 1 ) ; envDataAdded−−;

// System . o u t . p r i n t l n ( newVal + ”\t ” + c u r r S p i n n e r V a l u e + ” remove ” + envDataAdded ) ;

}

mpEVPanel . v a l i d a t e ( ) ; mpInputs . v a l i d a t e ( ) ; mpPanel . v a l i d a t e ( ) ; envDataAdded = newVal ;

s c r o l l P a n e . g e t V e r t i c a l S c r o l l B a r ( ) . s e t V a l u e ( ( i n t ) mpEVPanel . g e t P r e f e r r e d S i z e ( ) . g e t H e i g h t ( ) ) ;

} }

p u b l i c c l a s s S P F i l t e r R e s u l t s i m p l e m e n t s A c t i o n L i s t e n e r {

@ O v e r r i d e

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b S t r i n g f i l e n a m e = ” s p ” ;

S t r i n g r e g i o n = ( S t r i n g ) f i l t e r B o x . g e t S e l e c t e d I t e m ( ) ; i f ( r e g i o n . e q u a l s (”− Whole P h i l i p p i n e s −”) ) {

I m a g e D i s p l a y e r d i s p l a y = new I m a g e D i s p l a y e r ( ” p i c t u r e s / p r e d i c t i o n s p . png ” , ” s p ” ) ;

} e l s e {

f o r ( i n t i = 0 ; i < r e g i o n s . s i z e ( ) ; i ++) {

i f ( r e g i o n s . g e t ( i ) . getRegionName ( ) . e q u a l s ( r e g i o n ) ) { F i l t e r R e s u l t s f i l t e r = new F i l t e r R e s u l t s (

f i l e n a m e , r e g i o n , r e g i o n s . g e t ( i ) . g e t P r o v i n c e s ( ) , c ) ;

b r e a k ; }

} }

} }

p u b l i c c l a s s M P F i l t e r R e s u l t s i m p l e m e n t s A c t i o n L i s t e n e r {

@ O v e r r i d e

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b S t r i n g f i l e n a m e = ”mp ” ;

S t r i n g r e g i o n = ( S t r i n g ) m p F i l t e r B o x . g e t S e l e c t e d I t e m ( ) ; i f ( r e g i o n . e q u a l s (”− Whole P h i l i p p i n e s −”) ) {

// I m a g e D i s p l a y e r d i s p l a y = new I m a g e D i s p l a y e r ( ” p i c t u r e s / p r e d i c t i o n s p . png ” , ” s p ” ) ;

A r r a y L i s t<S t r i n g> i m a g e P a t h s = new A r r a y L i s t<S t r i n g>() ; f o r ( i n t i = 0 ; i <mpEVTF . s i z e ( ) ; i ++) {

i m a g e P a t h s . add ( ” p i c t u r e s / p r e d i c t i o n m p ” + i + ” . png ” ) ; }

M P D i s p l a y e r d i s p l a y e r = new M P D i s p l a y e r ( i m a g e P a t h s ) ; }

e l s e {

f o r ( i n t i = 0 ; i < r e g i o n s . s i z e ( ) ; i ++) {

i f ( r e g i o n s . g e t ( i ) . getRegionName ( ) . e q u a l s ( r e g i o n ) ) { // F i l t e r R e s u l t s f i l t e r = new F i l t e r R e s u l t s (

f i l e n a m e , r e g i o n , r e g i o n s . g e t ( i ) . g e t P r o v i n c e s ( ) , c ) ;

S t r i n g B u i l d e r command = new S t r i n g B u i l d e r ( ” ” ) ; command . append ( ” f i l t e r <− ph [ ” ) ;

f o r ( i n t j = 0 ; j < r e g i o n s . g e t ( i ) . g e t P r o v i n c e s ( ) . s i z e ( ) ; j ++) {

i f ( j == 0 ) {

command . append ( ” ph$NAME 1 ==

\”” + r e g i o n s . g e t ( i ) . g e t P r o v i n c e s ( ) . g e t ( j ) +

”\” ” ) ; }

e l s e {

command . append ( ” | ph$NAME 1

==\”” + r e g i o n s . g e t ( i ) . g e t P r o v i n c e s ( ) . g e t ( j ) +

”\” ” ) ; }

}

command . append ( ” , ] ” ) ; t r y {

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) )

;

c . e v a l ( command . t o S t r i n g ( ) ) ; A r r a y L i s t<S t r i n g> i m a g e P a t h s = new

A r r a y L i s t<S t r i n g>() ;

f o r ( i n t j = 0 ; j <mpEVTF . s i z e ( ) ; j ++) {

command = new S t r i n g B u i l d e r ( ” ” ) ;

command . append ( ” c r <− c r o p ( p r e d i c t i o n ” + f i l e n a m e + j

+ ” , e x t e n t ( f i l t e r ) , s n a p

= \” o u t\” ) ” ) ; command . append ( ”\n ” ) ; command . append ( ” f r <−

r a s t e r i z e ( f i l t e r , c r ) ” ) ; command . append ( ”\n ” ) ;

command . append ( ” f i l t e r m p ” + j + ”<− mask ( c r , f r ) ” ) ; command . append ( ”\n ” ) ; command . append ( ” png (\” ” +

System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) +

”/ p i c t u r e s / f i l t e r ”+

f i l e n a m e + j + ” . png\” )\n

” ) ;

command . append ( ” p l o t ( f i l t e r ”+ f i l e n a m e + j + ” , x l a b = ’ L o n g i t u d e ’ , y l a b = ’ L a t i t u d e ’ )\n ” ) ;

command . append ( ” p l o t ( f i l t e r , add = T)\n ” ) ; command . append ( ” dev . o f f ( )\n ” ) ;

c . e v a l ( command . t o S t r i n g ( ) ) ; i m a g e P a t h s . add ( ” p i c t u r e s /

f i l t e r m p ” + j + ” . png ” ) ; }

M P D i s p l a y e r d i s p l a y e r = new M P D i s p l a y e r ( i m a g e P a t h s ) ; g r a p h P a n e l . r e m o v e A l l ( ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k e . p r i n t S t a c k T r a c e ( ) ;

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r ” , ” T h e r e i s an e r r o r i n p r o j e c t f i l e − a s s e t s / r e g i o n s . t x t

” , J Opt ionP ane . ERROR MESSAGE) ; }

b r e a k ; }

}

S t r i n g B u i l d e r command = new S t r i n g B u i l d e r ( ” ” ) ;

command . append ( ” g r a p h <− v e c t o r ( mode = \” n u m e r i c\” , l e n g t h = 0 )\n ” ) ;

f o r ( i n t i = 0 ; i <mpEVTF . s i z e ( ) ; i ++) {

command . append ( ” g r a p h <− append ( graph , mean ( a s . v e c t o r ( f i l t e r m p ”+ i +”) [ ! i s . na ( a s . v e c t o r ( f i l t e r m p ”+ i +”) ) ] ) )\n ” ) ;

}

command . append ( ” png (\” ” + System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) + ”/ p i c t u r e s / g r a p h . png\” )\n ” ) ; command . append ( ” p l o t ( s e q ( 1 , l e n g t h ( g r a p h ) ) , graph , x l a b = ’ Year ’ , y l a b

= ’ L i k e l i h o o d ’ )\n ” ) ;

command . append ( ” l i n e s ( s e q ( 1 , l e n g t h ( g r a p h ) ) , g r a p h )\n ” ) ; command . append ( ” dev . o f f ( )\n ” ) ;

t r y {

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) ) ; c . e v a l ( command . t o S t r i n g ( ) ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k e . p r i n t S t a c k T r a c e ( ) ;

} t r y {

B u f f e r e d I m a g e g r a p h = ImageIO . r e a d ( new F i l e ( ” p i c t u r e s / g r a p h . png ” ) ) ;

J L a b e l p i c L a b e l = new J L a b e l ( new I m a g e I c o n ( g r a p h ) ) ; g r a p h P a n e l . r e m o v e A l l ( ) ;

g r a p h P a n e l . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ;

g r a p h P a n e l . add ( p i c L a b e l , ” c e l l 0 0 , grow , a l i g n c e n t e r

” ) ;

g r a p h P a n e l . r e p a i n t ( ) ; g r a p h P a n e l . r e v a l i d a t e ( ) ; } c a t c h ( I O E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” g r a p h . png i s m i s s i n g ” , ” E r r o r ” , JO pti onPa ne . ERROR MESSAGE) ; }

} }

} }

A..2 Java Backend

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a x . s w i n g . J T e x t F i e l d ; p u b l i c c l a s s F i l e P a r s e r {

p u b l i c F i l e [ ] t e x t F i e l d P a r s e r ( J T e x t F i e l d t f ) { S t r i n g [ ] f i l e s T e x t = t f . g e t T e x t ( ) . s p l i t ( ” ; ” ) ; F i l e [ ] f i l e s = new F i l e [ f i l e s T e x t . l e n g t h ] ; f o r ( i n t i = 0 ; i < f i l e s T e x t . l e n g t h ; i ++) {

f i l e s [ i ] = new F i l e ( f i l e s T e x t [ i ] ) ; }

r e t u r n f i l e s ; }

}

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . u t i l . A r r a y L i s t ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J P a n e l ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R s e r v e E x c e p t i o n ; p u b l i c c l a s s F i l t e r R e s u l t s {

p u b l i c F i l t e r R e s u l t s ( S t r i n g f i l e n a m e , S t r i n g r e g i o n , A r r a y L i s t<S t r i n g> p r o v i n c e s , R C o n n e c t i o n c ) {

S t r i n g B u i l d e r command = new S t r i n g B u i l d e r ( ” ” ) ; command . append ( ” f i l t e r <− ph [ ” ) ;

f o r ( i n t i = 0 ; i < p r o v i n c e s . s i z e ( ) ; i ++) { i f ( i == 0 ) {

command . append ( ” ph$NAME 1 == \”” + p r o v i n c e s . g e t ( i ) + ”\” ” ) ; }

e l s e {

command . append ( ” | ph$NAME 1 == \”” + p r o v i n c e s . g e t ( i ) + ”\” ” )

; }

}

command . append ( ” , ] ” ) ; t r y {

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) ) ; c . e v a l ( command . t o S t r i n g ( ) ) ;

command = new S t r i n g B u i l d e r ( ” ” ) ;

command . append ( ” c r <− c r o p ( p r e d i c t i o n ” + f i l e n a m e + ” , e x t e n t ( f i l t e r ) , s n a p = \” o u t\” ) ” ) ;

command . append ( ”\n ” ) ;

command . append ( ” f r <− r a s t e r i z e ( f i l t e r , c r ) ” ) ; command . append ( ”\n ” ) ;

command . append ( ” f i l t e r s p <−mask ( c r , f r ) ” ) ; command . append ( ”\n ” ) ;

command . append ( ” png (\” ” + System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ ,

’ / ’ ) + ”/ p i c t u r e s / f i l t e r ”+ f i l e n a m e +”. png\” )\n ” ) ;

command . append ( ” p l o t ( f i l t e r ”+ f i l e n a m e +” , x l a b = ’ L o n g i t u d e ’ , y l a b = ’ L a t i t u d e ’ )\ n ” ) ;

command . append ( ” p l o t ( f i l t e r , add = T)\n ” ) ; command . append ( ” dev . o f f ( )\n ” ) ;

c . e v a l ( command . t o S t r i n g ( ) ) ;

I m a g e D i s p l a y e r i m a g e = new I m a g e D i s p l a y e r ( ” p i c t u r e s / f i l t e r ” + f i l e n a m e + ” . png ” , f i l e n a m e ) ;

} c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k // e . p r i n t S t a c k T r a c e ( ) ;

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r ” , ” T h e r e i s an e r r o r i n p r o j e c t f i l e − a s s e t s / r e g i o n s . t x t ” , JOp tio nPan e . ERROR MESSAGE) ; }

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) ) ; }

p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) {

// A r r a y L i s t<S t r i n g> p = new A r r a y L i s t<S t r i n g>() ;

// p . add ( ” Prov 1 ” ) ;

// p . add ( ” Prov 2 ” ) ;

// S t r i n g r e g i o n = ” T e s t R e g i o n ” ;

// S t r i n g f i l e n a m e = ” s p ” ;

//

// F i l t e r R e s u l t s t e s t = new F i l t e r R e s u l t s ( f i l e n a m e , r e g i o n , p ) ; }

}

p a c k a g e j a v a B a c k e n d ;

i m p o r t j a v a . awt . B o r d e r L a y o u t ; i m p o r t j a v a . awt . Image ; i m p o r t j a v a . awt . Window ; i m p o r t j a v a . i o . F i l e ; i m p o r t j a v a . i o . I O E x c e p t i o n ; i m p o r t j a v a x . i m a g e i o . ImageIO ; i m p o r t j a v a x . s w i n g . JFrame ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t u i . Main ;

p u b l i c c l a s s I m a g e D i s p l a y e r { p r i v a t e Image i m a g e F i l e ;

p u b l i c I m a g e D i s p l a y e r ( S t r i n g imagePath , S t r i n g mode ) { t r y {

i m a g e F i l e = ImageIO . r e a d ( new F i l e ( i m a g e P a t h ) ) ; } c a t c h ( I O E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k // e . p r i n t S t a c k T r a c e ( ) ;

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r d i s p l a y i n g i m a g e ” ) ; }

T r a n s f o r m i n g C a n v a s c a n v a s = new T r a n s f o r m i n g C a n v a s ( i m a g e P a t h ) ; T r a n s l a t e H a n d l e r t r a n s l a t e r = new T r a n s l a t e H a n d l e r ( c a n v a s ) ; c a n v a s . a d d M o u s e L i s t e n e r ( t r a n s l a t e r ) ;

c a n v a s . a d d M o u s e M o t i o n L i s t e n e r ( t r a n s l a t e r ) ;

c a n v a s . a d d M o u s e W h e e l L i s t e n e r ( new S c a l e H a n d l e r ( c a n v a s ) ) ; Window [ ] windows = Window . getWindows ( ) ;

i f ( mode . e q u a l s ( ” s p ” ) ) {

b o o l e a n f i r s t W i n d o w C h e c k e d = f a l s e ; // T h i s i s a g h e t t o way o f h a n d l i n g t h i s . P l e a s e r e c o n s i d e r

f o r ( i n t i = 0 ; i < windows . l e n g t h ; i ++) {

i f ( windows [ i ] . g e t C l a s s ( ) . t o S t r i n g ( ) . e q u a l s ( ” c l a s s j a v a x . s w i n g . JFrame ” ) ) {

i f ( f i r s t W i n d o w C h e c k e d ) windows [ i ] . d i s p o s e ( ) ; e l s e f i r s t W i n d o w C h e c k e d = t r u e ;

} }

}

JFrame f r a m e = new JFrame ( ) ;

f r a m e . s e t L a y o u t ( new B o r d e r L a y o u t ( ) ) ;

f r a m e . g e t C o n t e n t P a n e ( ) . add ( c a n v a s , B o r d e r L a y o u t .CENTER) ; f r a m e . s e t S i z e ( 5 0 0 , 5 0 0 ) ;

f r a m e . s e t D e f a u l t C l o s e O p e r a t i o n ( JFrame . DISPOSE ON CLOSE ) ; f r a m e . s e t V i s i b l e ( t r u e ) ;

/∗p a n e l . s e t L a y o u t ( new B o r d e r L a y o u t ( ) ) ; p a n e l . add ( c a n v a s , B o r d e r L a y o u t .CENTER) ; c a n v a s . r e p a i n t ( ) ;

p a n e l . r e p a i n t ( ) ; p a n e l . r e v a l i d a t e ( ) ;∗/

} }

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . awt . D i m e n s i o n ; i m p o r t j a v a . awt . Window ; i m p o r t j a v a . u t i l . A r r a y L i s t ; i m p o r t j a v a x . s w i n g . JFrame ; i m p o r t j a v a x . s w i n g . J P a n e l ; i m p o r t j a v a x . s w i n g . J S c r o l l P a n e ; i m p o r t n e t . m i g i n f o c o m . s w i n g . MigLayout ; i m p o r t t e s t s . G I F T e s t ;

p u b l i c c l a s s M P D i s p l a y e r { p r i v a t e JFrame f r a m e ;

p r i v a t e s t a t i c A r r a y L i s t<S t r i n g> i m a g e s ; /∗∗

∗ C r e a t e t h e a p p l i c a t i o n .

∗/

p u b l i c M P D i s p l a y e r ( A r r a y L i s t<S t r i n g> i m a g e s ) { t h i s . i m a g e s = i m a g e s ;

i n i t i a l i z e ( ) ; }

p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) {

A r r a y L i s t<S t r i n g> t e s t = new A r r a y L i s t<S t r i n g>() ; M P D i s p l a y e r d i s p l a y = new M P D i s p l a y e r ( t e s t ) ; }

/∗∗

∗ I n i t i a l i z e t h e c o n t e n t s o f t h e f r a m e .

∗/

p r i v a t e v o i d i n i t i a l i z e ( ) {

Window [ ] windows = Window . getWindows ( ) ;

b o o l e a n f i r s t W i n d o w C h e c k e d = f a l s e ; // T h i s i s a g h e t t o way o f h a n d l i n g t h i s . P l e a s e r e c o n s i d e r

f o r ( i n t i = 0 ; i < windows . l e n g t h ; i ++) {

i f ( windows [ i ] . g e t C l a s s ( ) . t o S t r i n g ( ) . e q u a l s ( ” c l a s s j a v a x . s w i n g . JFrame ” ) ) {

i f ( f i r s t W i n d o w C h e c k e d ) windows [ i ] . d i s p o s e ( ) ; e l s e f i r s t W i n d o w C h e c k e d = t r u e ;

} }

f r a m e = new JFrame ( ) ;

f r a m e . s e t T i t l e ( ” D i p t e r o c a r p M o d e l l i n g T o o l ” ) ; f r a m e . s e t M i n i m u m S i z e ( new D i m e n s i o n ( 5 0 0 , 5 0 0 ) ) ;

f r a m e . s e t D e f a u l t C l o s e O p e r a t i o n ( JFrame . DISPOSE ON CLOSE ) ;

f r a m e . g e t C o n t e n t P a n e ( ) . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ; J S c r o l l P a n e s c r o l l P a n e = new J S c r o l l P a n e ( ) ;

f r a m e . g e t C o n t e n t P a n e ( ) . add ( s c r o l l P a n e , ” c e l l 0 0 , grow ” ) ; J P a n e l d i s p l a y P a n e l = new J P a n e l ( ) ;

s c r o l l P a n e . s e t V i e w p o r t V i e w ( d i s p l a y P a n e l ) ;

d i s p l a y P a n e l . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ; System . o u t . p r i n t l n ( i m a g e s . s i z e ( ) ) ;

G I F T e s t p r e d i c t i o n s = new G I F T e s t ( i m a g e s ) ; d i s p l a y P a n e l . r e m o v e A l l ( ) ;

d i s p l a y P a n e l . add ( p r e d i c t i o n s , ” c e l l 0 0 , grow , a l i g n c e n t e r ” ) ;

p r e d i c t i o n s . s e t V i s i b l e ( t r u e ) ; f r a m e . s e t V i s i b l e ( t r u e ) ; }

}

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J P a n e l ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R s e r v e E x c e p t i o n ; p u b l i c c l a s s P r e d i c t D i s t {

p r i v a t e b o o l e a n e r r o r ; p r i v a t e R C o n n e c t i o n c ; p u b l i c b o o l e a n g e t E r r o r ( ) {

r e t u r n t h i s . e r r o r ; }

p u b l i c v o i d g e t G r a p h ( i n t numberOfYears , R C o n n e c t i o n c ) { S t r i n g B u i l d e r command = new S t r i n g B u i l d e r ( ” ” ) ;

command . append ( ” g r a p h <− v e c t o r ( mode = \” n u m e r i c\” , l e n g t h = 0 )\n ” ) ; f o r ( i n t i = 0 ; i < numberOfYears ; i ++) {

command . append ( ” g r a p h <− append ( graph , mean ( a s . v e c t o r ( p r e d i c t i o n m p ”+ i +”) [ ! i s . na ( a s . v e c t o r ( p r e d i c t i o n m p ”+ i +”) ) ] ) )\n ” ) ;

}

command . append ( ” png (\” ” + System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) +

”/ p i c t u r e s / g r a p h . png\” )\n ” ) ;

command . append ( ” p l o t ( s e q ( 1 , l e n g t h ( g r a p h ) ) , graph , x l a b = ’ Year ’ , y l a b = ’ L i k e l i h o o d ’ )\ n ” ) ;

command . append ( ” l i n e s ( s e q ( 1 , l e n g t h ( g r a p h ) ) , g r a p h )\n ” ) ; command . append ( ” dev . o f f ( )\n ” ) ;

t r y {

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) ) ; c . e v a l ( command . t o S t r i n g ( ) ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k e . p r i n t S t a c k T r a c e ( ) ;

} }

p u b l i c P r e d i c t D i s t ( F i l e [ ] EV, S t r i n g pathMod , S t r i n g f i l e n a m e , R C o n n e c t i o n c ) { t h i s . c = c ;

e r r o r = f a l s e ;

S t r i n g B u i l d e r command = new S t r i n g B u i l d e r ( ” ” ) ;

command . append ( ” model <− readRDS (\” ” + pathMod + ”\” )\n ” ) ; t r y {

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) ) ; c . e v a l ( command . t o S t r i n g ( ) ) ;

command = new S t r i n g B u i l d e r ( ” ” ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

// e . p r i n t S t a c k T r a c e ( ) ;

JO ptio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” I n v a l i d model ” , ” Warning ” , JO ptio nPa ne . WARNING MESSAGE) ;

e r r o r = t r u e ; }

i f ( e r r o r ){}

e l s e {

command . append ( ” f i l e s <− a s . v e c t o r ( c ( ” ) ; f o r ( i n t i = 0 ; i <EV . l e n g t h ; i ++) { i f ( i == 0 ) {

command . append ( ’ ” ’ ) ;

command . append (EV [ i ] . g e t A b s o l u t e P a t h ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) ) ; command . append ( ’ ” ’ ) ;

} e l s e {

command . append ( ’ , ’ ) ; command . append ( ’ ” ’ ) ;

command . append (EV [ i ] . g e t A b s o l u t e P a t h ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) ) ; command . append ( ’ ” ’ ) ;

} }

command . append ( ” ) )\n ” ) ;

command . append ( ” p r e d i c t o r s <− s t a c k ( f i l e s )\n ” ) ;

command . append ( ” p r e d i c t i o n ” + f i l e n a m e + ”<− p r e d i c t ( model , p r e d i c t o r s , p r o g r e s s = ’ window ’ )\n ” ) ;

command . append ( ” c r <− c r o p ( p r e d i c t i o n ” + f i l e n a m e + ” , e x t e n t ( ph ) , s n a p = \” o u t\” )\n ” ) ;

command . append ( ” f r <− r a s t e r i z e ( ph , c r )\n ” ) ;

command . append ( ” p r e d i c t i o n ” + f i l e n a m e + ”<− mask ( x=c r , mask= f r )\n ” ) ; command . append ( ” png (\” ” + System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ ,

’ / ’ ) + ”/ p i c t u r e s / p r e d i c t i o n ”+ f i l e n a m e +”. png\” )\n ” ) ; command . append ( ” p l o t ( p r e d i c t i o n ”+ f i l e n a m e +” , x l a b = ’ L o n g i t u d e ’ , y l a b = ’

L a t i t u d e ’ )\n ” ) ;

command . append ( ” p l o t ( ph , add = T)\n ” ) ; command . append ( ” dev . o f f ( )\n ” ) ;

// command . append ( ” png (\” ” + System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) + ”/

p i c t u r e s / w e i g h t s ”+ f i l e n a m e +”. png\” )\n ” ) ;

// command . append ( ” p l o t ( model )\n ” ) ;

// command . append ( ” dev . o f f ( )\n ” ) ;

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) ) ; t r y {

c . e v a l ( command . t o S t r i n g ( ) ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

// e . p r i n t S t a c k T r a c e ( ) ;

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r w h i l e p r e d i c t i n g ” ,

” E r r o r ” , JO ptio nPa ne . ERROR MESSAGE) ; }

} }

}

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . u t i l . A r r a y L i s t ; p u b l i c c l a s s R e g i o n {

p r i v a t e A r r a y L i s t<S t r i n g> p r o v i n c e s ; p r i v a t e S t r i n g r e g i o n N a m e ;

p u b l i c R e g i o n ( A r r a y L i s t<S t r i n g> p r o v i n c e s , S t r i n g r e g i o n N a m e ) { t h i s . p r o v i n c e s = p r o v i n c e s ;

t h i s . r e g i o n N a m e = r e g i o n N a m e ; }

p u b l i c A r r a y L i s t<S t r i n g> g e t P r o v i n c e s ( ) { r e t u r n p r o v i n c e s ;

}

p u b l i c v o i d s e t P r o v i n c e s ( A r r a y L i s t<S t r i n g> p r o v i n c e s ) { t h i s . p r o v i n c e s = p r o v i n c e s ;

}

p u b l i c S t r i n g getRegionName ( ) { r e t u r n r e g i o n N a m e ; }

p u b l i c v o i d s e t R e g i o n N a m e ( S t r i n g r e g i o n N a m e ) { t h i s . r e g i o n N a m e = r e g i o n N a m e ;

} }

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a . i o . F i l e N o t F o u n d E x c e p t i o n ; i m p o r t j a v a . u t i l . A r r a y L i s t ;

i m p o r t j a v a . u t i l . S c a n n e r ;

i m p o r t j a v a . u t i l . S t r i n g T o k e n i z e r ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; p u b l i c c l a s s R e g i o n P a r s e r {

p u b l i c A r r a y L i s t<R e g i o n> r e g i o n P a r s e r ( ) {

F i l e r e g i o n F i l e = new F i l e ( ” a s s e t s / r e g i o n s . t x t ” ) ; A r r a y L i s t<R e g i o n> r e g i o n s = new A r r a y L i s t<R e g i o n>() ; t r y {

S c a n n e r s c = new S c a n n e r ( r e g i o n F i l e ) ; w h i l e ( s c . h a s N e x t L i n e ( ) ) {

S t r i n g l i n e = s c . n e x t L i n e ( ) ;

S t r i n g T o k e n i z e r s p l i t L i n e = new S t r i n g T o k e n i z e r ( l i n e , ”|” ) ; S t r i n g r e g i o n N a m e = s p l i t L i n e . n e x t T o k e n ( ) ;

A r r a y L i s t<S t r i n g> p r o v i n c e s = new A r r a y L i s t<S t r i n g>() ; w h i l e ( s p l i t L i n e . hasMoreTokens ( ) ) {

p r o v i n c e s . add ( s p l i t L i n e . n e x t T o k e n ( ) ) ; }

r e g i o n s . add ( new R e g i o n ( p r o v i n c e s , r e g i o n N a m e ) ) ; }

} c a t c h ( F i l e N o t F o u n d E x c e p t i o n e ) { // TODO Auto−g e n e r a t e d c a t c h b l o c k

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r ” , ” M i s s i n g p r o j e c t f i l e − r e g i o n s . t x t ” , JOp tio nPan e . ERROR MESSAGE) ;

}

r e t u r n r e g i o n s ; }

p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { // TODO Auto−g e n e r a t e d method s t u b

R e g i o n P a r s e r r p = new R e g i o n P a r s e r ( ) ; r p . r e g i o n P a r s e r ( ) ;

} }

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . i o . F i l e ; i m p o r t j a v a . u t i l . A r r a y L i s t ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R s e r v e E x c e p t i o n ; p u b l i c c l a s s R e m o d e l l i n g {

p r i v a t e R C o n n e c t i o n c ;

p r i v a t e J T e x t F i e l d p r e d i c t o r s ; p r i v a t e J T e x t F i e l d d a t a l o c s ; p r i v a t e A r r a y L i s t<S t r i n g> f a c t o r s ; p r i v a t e J T e x t F i e l d destTF ;

p u b l i c R e m o d e l l i n g ( R C o n n e c t i o n c , J T e x t F i e l d p r e d i c t o r s , J T e x t F i e l d d a t a l o c s , A r r a y L i s t<S t r i n g> f a c t o r s , J T e x t F i e l d destTF ) {

t h i s . c = c ;

t h i s . p r e d i c t o r s = p r e d i c t o r s ; t h i s . d a t a l o c s = d a t a l o c s ; t h i s . f a c t o r s = f a c t o r s ; t h i s . destTF = destTF ; }

p u b l i c v o i d model ( ) {

F i l e P a r s e r p a r s e r = new F i l e P a r s e r ( ) ;

F i l e [ ] t o S t a c k = p a r s e r . t e x t F i e l d P a r s e r ( p r e d i c t o r s ) ; S t r i n g B u i l d e r command = new S t r i n g B u i l d e r ( ” ” ) ;

command . append ( ” l o c s <− r e a d . c s v (\” ” + d a t a l o c s . g e t T e x t ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) +

”\” )\n ” ) ;

command . append ( ” d a t a l o c s <− d a t a . f r a m e ( l o c s $ l o n g i t u d e , l o c s $ l a t i t u d e )\n ” ) ; command . append ( ” f i l e s <− a s . v e c t o r ( c ( ” ) ;

f o r ( i n t i = 0 ; i < t o S t a c k . l e n g t h ; i ++) { i f ( i == 0 ) {

command . append ( ’ ” ’ ) ;

command . append ( t o S t a c k [ i ] . g e t A b s o l u t e P a t h ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) ) ;

command . append ( ’ ” ’ ) ; } e l s e {

command . append ( ’ , ’ ) ; command . append ( ’ ” ’ ) ;

command . append ( t o S t a c k [ i ] . g e t A b s o l u t e P a t h ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) ) ;

command . append ( ’ ” ’ ) ; }

}

command . append ( ” ) )\n ” ) ;

command . append ( ” p r e d i c t o r s <− s t a c k ( f i l e s )\n ” ) ;

i f ( f a c t o r s . s i z e ( ) == 0 ) command . append ( ” model <− maxent ( p r e d i c t o r s , d a t a l o c s ” )

; e l s e {

command . append ( ” model <− maxent ( p r e d i c t o r s , d a t a l o c s , f a c t o r s = ” ) ; f o r ( i n t i = 0 ; i < f a c t o r s . s i z e ( ) ; i ++) {

i f ( i == 0 ) {

command . append ( ”\” ” ) ;

command . append ( f a c t o r s . g e t ( i ) ) ; command . append ( ”\” ” ) ;

} e l s e {

command . append ( ” , \” ” ) ;

command . append ( f a c t o r s . g e t ( i ) ) ; command . append ( ”\” ” ) ;

} }

}

command . append ( ” )\n ” ) ;

command . append ( ” saveRDS ( model , \”” + destTF . g e t T e x t ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) +

”\” )\n ” ) ;

command . append ( ” png (\” ” + System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) +

”/ p i c t u r e s / w e i g h t s . png\” )\n ” ) ;

command . append ( ” p l o t ( model , x l a b = ’ V a r i a b l e C o n t r i b u t i o n ’ , y l a b = ’ V a r i a b l e ’ )\n ” ) ; command . append ( ” dev . o f f ( )\n ” ) ;

System . o u t . p r i n t l n ( command . t o S t r i n g ( ) ) ; t r y {

c . e v a l ( command . t o S t r i n g ( ) ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r s a v i n g t h e model . R e c h e c k d e s t i n a t i o n i f v a l i d ” , ” E r r o r ” , JOpt ionP ane . ERROR MESSAGE) ; }

} }

p a c k a g e j a v a B a c k e n d ;

i m p o r t j a v a . awt . e v e n t . MouseWheelEvent ; i m p o r t j a v a . awt . e v e n t . M o u s e W h e e l L i s t e n e r ;

p u b l i c c l a s s S c a l e H a n d l e r i m p l e m e n t s M o u s e W h e e l L i s t e n e r { p r i v a t e T r a n s f o r m i n g C a n v a s c a n v a s ;

p u b l i c S c a l e H a n d l e r ( T r a n s f o r m i n g C a n v a s c a n v a s ) { t h i s . c a n v a s = c a n v a s ;

}

p u b l i c v o i d mouseWheelMoved ( MouseWheelEvent e ) {

i f ( e . g e t S c r o l l T y p e ( ) == MouseWheelEvent . WHEEL UNIT SCROLL) {

c a n v a s . s e t S c a l e ( c a n v a s . g e t S c a l e ( ) − ( . 0 5 ∗ e . g e t W h e e l R o t a t i o n ( ) ) ) ; // don ’ t c r o s s n e g a t i v e t h r e s h o l d .

// a l s o , s e t t i n g s c a l e t o 0 h a s bad e f f e c t s c a n v a s . s e t S c a l e ( Math . max ( 0 , c a n v a s . g e t S c a l e ( ) ) ) ; c a n v a s . r e p a i n t ( ) ;

} }

}

p a c k a g e j a v a B a c k e n d ; i m p o r t j a v a . awt . C o l o r ; i m p o r t j a v a . awt . G r a p h i c s ; i m p o r t j a v a . awt . G r a p h i c s 2 D ;

i m p o r t j a v a . awt . geom . A f f i n e T r a n s f o r m ; i m p o r t j a v a . awt . i m a g e . B u f f e r e d I m a g e ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a . i o . I O E x c e p t i o n ; i m p o r t j a v a x . i m a g e i o . ImageIO ; i m p o r t j a v a x . s w i n g . JComponent ; i m p o r t j a v a x . s w i n g . J Opti onP ane ;

p u b l i c c l a s s T r a n s f o r m i n g C a n v a s e x t e n d s JComponent { p r i v a t e d o u b l e t r a n s l a t e X ;

p r i v a t e d o u b l e t r a n s l a t e Y ; p r i v a t e d o u b l e s c a l e ; p r i v a t e S t r i n g f i l e n a m e ;

T r a n s f o r m i n g C a n v a s ( S t r i n g f i l e n a m e ) { t r a n s l a t e X = 0 ;

t r a n s l a t e Y = 0 ; s c a l e = 1 ;

t h i s . f i l e n a m e = f i l e n a m e ; s e t O p a q u e ( t r u e ) ;

s e t D o u b l e B u f f e r e d ( t r u e ) ; }

@ O v e r r i d e p u b l i c v o i d p a i n t ( G r a p h i c s g ) {

A f f i n e T r a n s f o r m t x = new A f f i n e T r a n s f o r m ( ) ; t x . s c a l e ( s c a l e , s c a l e ) ;

t x . t r a n s l a t e ( t r a n s l a t e X , t r a n s l a t e Y ) ;

System . o u t . p r i n t l n ( ” S c a l e :\t ” + s c a l e + ” TX:\t ” + t r a n s l a t e X + ”TY:\t ” + t r a n s l a t e Y ) ;

// System . o u t . p r i n t l n ( t r a n s l a t e X + ”\t ” + t r a n s l a t e Y ) ;

G r a p h i c s 2 D o u r G r a p h i c s = ( G r a p h i c s 2 D ) g ; o u r G r a p h i c s . s e t C o l o r ( C o l o r . WHITE) ;

o u r G r a p h i c s . f i l l R e c t ( 0 , 0 , g e t W i d t h ( ) , g e t H e i g h t ( ) ) ; o u r G r a p h i c s . s e t T r a n s f o r m ( t x ) ;

// System . o u t . p r i n t l n ( ” t e s t ” ) ; F i l e i m a g e = new F i l e ( f i l e n a m e ) ; B u f f e r e d I m a g e b i ;

t r y {

b i = ImageIO . r e a d ( i m a g e ) ;

o u r G r a p h i c s . draw RenderedImage ( b i , t x ) ; } c a t c h ( I O E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r d i s p l a y i n g i m a g e ” ) ; }

}

p u b l i c d o u b l e g e t T r a n s l a t e X ( ) { r e t u r n t r a n s l a t e X ; }

p u b l i c v o i d s e t T r a n s l a t e X ( d o u b l e t r a n s l a t e X ) { t h i s . t r a n s l a t e X = t r a n s l a t e X ;

}

p u b l i c d o u b l e g e t T r a n s l a t e Y ( ) { r e t u r n t r a n s l a t e Y ; }

p u b l i c v o i d s e t T r a n s l a t e Y ( d o u b l e t r a n s l a t e Y ) { t h i s . t r a n s l a t e Y = t r a n s l a t e Y ;

}

p u b l i c d o u b l e g e t S c a l e ( ) { r e t u r n s c a l e ; }

p u b l i c v o i d s e t S c a l e ( d o u b l e s c a l e ) { t h i s . s c a l e = s c a l e ;

} }

p a c k a g e j a v a B a c k e n d ;

i m p o r t j a v a . awt . e v e n t . MouseEvent ; i m p o r t j a v a . awt . e v e n t . M o u s e L i s t e n e r ; i m p o r t j a v a . awt . e v e n t . M o u s e M o t i o n L i s t e n e r ;

p u b l i c c l a s s T r a n s l a t e H a n d l e r i m p l e m e n t s M o u s e L i s t e n e r , M o u s e M o t i o n L i s t e n e r {

p r i v a t e i n t l a s t O f f s e t X ; p r i v a t e i n t l a s t O f f s e t Y ;

p r i v a t e T r a n s f o r m i n g C a n v a s c a n v a s ;

p u b l i c T r a n s l a t e H a n d l e r ( T r a n s f o r m i n g C a n v a s c a n v a s ) { t h i s . c a n v a s = c a n v a s ;

}

p u b l i c v o i d m o u s e P r e s s e d ( MouseEvent e ) { // c a p t u r e s t a r t i n g p o i n t l a s t O f f s e t X = e . getX ( ) ; l a s t O f f s e t Y = e . getY ( ) ; }

p u b l i c v o i d mouseDragged ( MouseEvent e ) {

// new x and y a r e d e f i n e d by c u r r e n t mouse l o c a t i o n s u b t r a c t e d // by p r e v i o u s l y p r o c e s s e d mouse l o c a t i o n

i n t newX = e . getX ( ) − l a s t O f f s e t X ; i n t newY = e . getY ( ) − l a s t O f f s e t Y ;

// i n c r e m e n t l a s t o f f s e t t o l a s t p r o c e s s e d by d r a g e v e n t . l a s t O f f s e t X += newX ;

l a s t O f f s e t Y += newY ;

// u p d a t e t h e c a n v a s l o c a t i o n s

c a n v a s . s e t T r a n s l a t e X ( c a n v a s . g e t T r a n s l a t e X ( ) + newX ) ; c a n v a s . s e t T r a n s l a t e Y ( c a n v a s . g e t T r a n s l a t e Y ( ) + newY ) ; // s c h e d u l e a r e p a i n t .

c a n v a s . r e p a i n t ( ) ; }

p u b l i c v o i d m o u s e C l i c k e d ( MouseEvent e ) {}

p u b l i c v o i d m o u s e E n t e r e d ( MouseEvent e ) {}

p u b l i c v o i d m o u s e E x i t e d ( MouseEvent e ) {}

p u b l i c v o i d mouseMoved ( MouseEvent e ) {}

p u b l i c v o i d m o u s e R e l e a s e d ( MouseEvent e ) {}

}

p a c k a g e t e s t s ;

i m p o r t j a v a . awt . B o r d e r L a y o u t ; i m p o r t j a v a . awt . G r a p h i c s ; i m p o r t j a v a . awt . M e d i a T r a c k e r ; i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a . u t i l . A r r a y L i s t ;

i m p o r t j a v a x . s w i n g . I m a g e I c o n ; i m p o r t j a v a x . s w i n g . JFrame ; i m p o r t j a v a x . s w i n g . J P a n e l ; i m p o r t j a v a x . s w i n g . Timer ;

i m p o r t n e t . m i g i n f o c o m . s w i n g . MigLayout ;

p u b l i c c l a s s G I F T e s t e x t e n d s J P a n e l i m p l e m e n t s A c t i o n L i s t e n e r { I m a g e I c o n i m a g e s [ ] ;

i n t t o t a l I m a g e s , c u r r e n t I m a g e = 0 , a n i m a t i o n D e l a y = 3 0 0 ; Timer a n i m a t i o n T i m e r ;

p u b l i c G I F T e s t ( A r r a y L i s t<S t r i n g> p a t h s ) { t o t a l I m a g e s = p a t h s . s i z e ( ) ;

i m a g e s = new I m a g e I c o n [ t o t a l I m a g e s ] ; f o r ( i n t i = 0 ; i < i m a g e s . l e n g t h ; ++i )

i m a g e s [ i ] = new I m a g e I c o n ( p a t h s . g e t ( i ) ) ; s t a r t A n i m a t i o n ( ) ;

}

p u b l i c v o i d pain tCompon ent ( G r a p h i c s g ) { s u p e r . paintCo mponen t ( g ) ;

i f ( i m a g e s [ c u r r e n t I m a g e ] . g e t I m a g e L o a d S t a t u s ( ) == M e d i a T r a c k e r .COMPLETE) { i n t x = ( t h i s . g e t W i d t h ( ) − i m a g e s [ c u r r e n t I m a g e ] . g e t I c o n W i d t h ( ) ) / 2 ; i n t y = ( t h i s . g e t H e i g h t ( ) − i m a g e s [ c u r r e n t I m a g e ] . g e t I c o n H e i g h t ( ) ) / 2 ;

i m a g e s [ c u r r e n t I m a g e ] . p a i n t I c o n ( t h i s , g , x , y ) ; c u r r e n t I m a g e = ( c u r r e n t I m a g e + 1 ) % t o t a l I m a g e s ; }

}

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t e ) { r e p a i n t ( ) ;

}

p u b l i c v o i d s t a r t A n i m a t i o n ( ) { i f ( a n i m a t i o n T i m e r == n u l l ) {

c u r r e n t I m a g e = 0 ;

a n i m a t i o n T i m e r = new Timer ( a n i m a t i o n D e l a y , t h i s ) ; a n i m a t i o n T i m e r . s t a r t ( ) ;

} e l s e i f ( ! a n i m a t i o n T i m e r . i s R u n n i n g ( ) ) a n i m a t i o n T i m e r . r e s t a r t ( ) ; }

p u b l i c v o i d s t o p A n i m a t i o n ( ) { a n i m a t i o n T i m e r . s t o p ( ) ; }

p u b l i c s t a t i c v o i d main ( S t r i n g a r g s [ ] ) {

A r r a y L i s t<S t r i n g> p i c s = new A r r a y L i s t<S t r i n g>() ; p i c s . add ( ” p i c t u r e s / p r e d i c t i o n m p 0 . png ” ) ;

p i c s . add ( ” p i c t u r e s / p r e d i c t i o n m p 1 . png ” ) ; G I F T e s t anim = new G I F T e s t ( p i c s ) ; JFrame app = new JFrame ( ” Animator t e s t ” ) ;

app . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ; app . add ( anim , ” c e l l 0 0 ” ) ;

app . s e t S i z e ( 3 0 0 , 3 0 0 ) ;

app . s e t D e f a u l t C l o s e O p e r a t i o n ( JFrame . EXIT ON CLOSE ) ; app . s e t V i s i b l e ( t r u e ) ;

} }

A..3 R Backend

p a c k a g e r B a c k e n d ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a x . s w i n g . J Opti onP ane ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R s e r v e E x c e p t i o n ; p u b l i c c l a s s D a t a l o c s V a l i d a t o r {

p r i v a t e F i l e d a t a l o c s ; p r i v a t e R C o n n e c t i o n c ;

p u b l i c D a t a l o c s V a l i d a t o r ( F i l e d a t a l o c s , R C o n n e c t i o n c ) { t h i s . d a t a l o c s = d a t a l o c s ;

t h i s . c = c ; }

p u b l i c b o o l e a n a r e D a t a l o c s V a l i d ( ) { S t r i n g B u i l d e r command ; t r y {

command = new S t r i n g B u i l d e r ( ” ” ) ;

command . append ( ” l o c s <− r e a d . c s v (\” ” + d a t a l o c s . g e t A b s o l u t e P a t h ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) + ”\” )\n ” ) ;

command . append ( ” d a t a l o c s <− d a t a . f r a m e ( l o c s $ l o n g i t u d e , l o c s $ l a t i t u d e )\ n ” ) ;

c . e v a l ( command . t o S t r i n g ( ) ) ; }

c a t c h ( R s e r v e E x c e p t i o n r s ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” T h e r e i s a p r o b l e m w i t h i n p u t d a t a l o c a l i t i e s . P l e a s e r e c h e c k t h e f i l e . ” , ” E r r o r ” , J Opti onP ane . ERROR MESSAGE) ;

r e t u r n f a l s e ; }

r e t u r n t r u e ; }

}

p a c k a g e r B a c k e n d ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a x . s w i n g . J Opti onP ane ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R s e r v e E x c e p t i o n ; p u b l i c c l a s s E n v i V a r V a l i d a t o r {

p r i v a t e R C o n n e c t i o n c ; p r i v a t e F i l e [ ] e n v i V a r s ;

p u b l i c E n v i V a r V a l i d a t o r ( R C o n n e c t i o n c , F i l e [ ] e n v i V a r s ) { t h i s . c = c ;

t h i s . e n v i V a r s = e n v i V a r s ; }

p u b l i c b o o l e a n a r e E n v i V a r V a l i d ( ) { S t r i n g B u i l d e r command ;

f o r ( i n t i = 0 ; i < e n v i V a r s . l e n g t h ; i ++) { t r y {

command = new S t r i n g B u i l d e r ( ” s t a c k (\” ” + e n v i V a r s [ i ] . g e t A b s o l u t e P a t h ( ) + ”\” ) ” ) ;

c . e v a l ( command . t o S t r i n g ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) ) ; }

c a t c h ( R s e r v e E x c e p t i o n r s ) {

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ” I n v a l i d f i l e : ” +

e n v i V a r s [ i ] . getName ( ) , ” E r r o r ” , J Opt ionP ane . ERROR MESSAGE)

; r e t u r n f a l s e ; }

} t r y {

command = new S t r i n g B u i l d e r ( ” f i l e s <− a s . v e c t o r ( c ( ” ) ; f o r ( i n t i = 0 ; i < e n v i V a r s . l e n g t h ; i ++) {

i f ( i == 0 ) {

command . append ( ’ ” ’ ) ;

command . append ( e n v i V a r s [ i ] . g e t A b s o l u t e P a t h ( ) . r e p l a c e ( ’\ \’ ,

’ / ’ ) ) ;

command . append ( ’ ” ’ ) ; }

e l s e {

command . append ( ’ , ’ ) ; command . append ( ’ ” ’ ) ;

command . append ( e n v i V a r s [ i ] . g e t A b s o l u t e P a t h ( ) . r e p l a c e ( ’\ \’ ,

’ / ’ ) ) ;

command . append ( ’ ” ’ ) ; }

}

command . append ( ” ) )\n ” ) ;

command . append ( ” s t a c k ( f i l e s ) ” ) ; c . e v a l ( command . t o S t r i n g ( ) ) ; }

c a t c h ( R s e r v e E x c e p t i o n r s ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” E r r o r c o m b i n i n g t h e e n v i r o n m e n t a l v a r i a b l e s . Check i f e x t e n t o f e a c h f i l e a r e same ” , ” E r r o r ” , JO ptio nPa ne . ERROR MESSAGE) ;

r e t u r n f a l s e ; }

r e t u r n t r u e ; }

p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) t h r o w s R s e r v e E x c e p t i o n {

RConnector s = new RConnector ( ) ;

R C o n n e c t i o n c = s . g e t R C o n n e c t i o n ( ) ; F i l e [ ] f i l e s = new F i l e [ 2 ] ;

f i l e s [ 0 ] = new F i l e ( ”C : / U s e r s / a d r i a / D e s k t o p / t e s t . png ” ) ; f i l e s [ 1 ] = new F i l e ( ”C : / U s e r s / a d r i a / D e s k t o p / t e s t . t i f ” ) ; E n v i V a r V a l i d a t o r t e s t = new E n v i V a r V a l i d a t o r ( c , f i l e s ) ; System . o u t . p r i n t l n ( t e s t . a r e E n v i V a r V a l i d ( ) ) ;

} }

p a c k a g e r B a c k e n d ;

i m p o r t j a v a . i o . I O E x c e p t i o n ; i m p o r t j a v a x . s w i n g . J Opti onP ane ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t o r g . r o s u d a . REngine . R s e r v e . R s e r v e E x c e p t i o n ; p u b l i c c l a s s RConnector {

p r i v a t e R C o n n e c t i o n c ; p u b l i c RConnector ( ) {

s t a r t R C o n n e c t i o n ( ) ; l o a d L i b r a r i e s ( ) ; }

p u b l i c v o i d l o a d L i b r a r i e s ( ) { t r y {

S t r i n g B u i l d e r command = new S t r i n g B u i l d e r ( ” ” ) ; command . append ( ” l i b r a r y ( d i s m o ) ” ) ;

command . append ( ”\n ” ) ;

command . append ( ” l i b r a r y ( sdm ) ” ) ; command . append ( ”\n ” ) ;

command . append ( ” l i b r a r y ( r a s t e r ) ” ) ; command . append ( ”\n ” ) ;

command . append ( ” l i b r a r y ( r g d a l ) ” ) ; command . append ( ”\n ” ) ;

command . append ( ” ph<− readOGR (\” ” + System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) + ”/ PHL adm shp /PHL adm1 . s h p\” )\n ” ) ; c . e v a l ( command . t o S t r i n g ( ) ) ;

System . o u t . p r i n t l n ( ” L i b r a r i e s l o a d e d ” ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k // e . p r i n t S t a c k T r a c e ( ) ;

System . o u t . p r i n t l n ( ” Ui R s e r v e E x c e p t i o n ” ) ; }

}

p u b l i c v o i d s t a r t R C o n n e c t i o n ( ) { t r y {

P r o c e s s p r o = n u l l ;

P r o c e s s B u i l d e r pb = new P r o c e s s B u i l d e r ( ” R S c r i p t ” , ” a s s e t s / I n i t R s e r v e . t x t ” ) ;

p r o = pb . s t a r t ( ) ; p r o . w a i t F o r ( ) ;

p r o . d e s t r o y ( ) ; }

c a t c h ( I O E x c e p t i o n i o ) {

System . o u t . p r i n t l n ( ” I O E x c e p t i o n s t a r t i n g R s e r v e ” ) ; } c a t c h ( I n t e r r u p t e d E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

System . o u t . p r i n t l n ( ” I n t e r r u p t e d s t a r t i n g R s e r v e ” ) ; }

w h i l e ( c == n u l l ) { t r y {

c = new R C o n n e c t i o n ( ” l o c a l h o s t ” ) ;

System . o u t . p r i n t l n ( ” C o n n e c t e d t o R s e r v e ” ) ; } c a t c h ( R s e r v e E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k // e . p r i n t S t a c k T r a c e ( ) ;

System . o u t . p r i n t l n ( ” Ui R s e r v e E x c e p t i o n ” ) ; }

} }

p u b l i c R C o n n e c t i o n g e t R C o n n e c t i o n ( ) { r e t u r n t h i s . c ;

} }

A..4 Component Actions

p a c k a g e c o m p o n e n t A c t i o n s ; i m p o r t j a v a x . s w i n g . J B u t t o n ; i m p o r t j a v a x . s w i n g . JCheckBox ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ; i m p o r t j a v a x . s w i n g . e v e n t . ChangeEvent ; i m p o r t j a v a x . s w i n g . e v e n t . C h a n g e L i s t e n e r ;

p u b l i c c l a s s Enable Own Model i m p l e m e n t s C h a n g e L i s t e n e r{

p r i v a t e JCheckBox c h c k b x ; p r i v a t e J B u t t o n b t n ;

p u b l i c Enable Own Model ( JCheckBox chckbx , J B u t t o n b t n ) { t h i s . c h c k b x = c h c k b x ;

t h i s . b t n = b t n ; }

@ O v e r r i d e

p u b l i c v o i d s t a t e C h a n g e d ( ChangeEvent a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b i f ( ! c h c k b x . i s S e l e c t e d ( ) ) {

b t n . s e t E n a b l e d ( t r u e ) ; }

e l s e {

b t n . s e t E n a b l e d ( f a l s e ) ; }

}

}

p a c k a g e c o m p o n e n t A c t i o n s ; i m p o r t j a v a . awt . B o r d e r L a y o u t ; i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a . awt . i m a g e . B u f f e r e d I m a g e ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a . i o . I O E x c e p t i o n ; i m p o r t j a v a . u t i l . A r r a y L i s t ; i m p o r t j a v a x . i m a g e i o . ImageIO ; i m p o r t j a v a x . s w i n g . I m a g e I c o n ; i m p o r t j a v a x . s w i n g . J B u t t o n ; i m p o r t j a v a x . s w i n g . JCheckBox ; i m p o r t j a v a x . s w i n g . JComboBox ; i m p o r t j a v a x . s w i n g . J L a b e l ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J P a n e l ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t j a v a B a c k e n d . F i l e P a r s e r ;

i m p o r t j a v a B a c k e n d . M P D i s p l a y e r ; i m p o r t j a v a B a c k e n d . P r e d i c t D i s t ; i m p o r t n e t . m i g i n f o c o m . s w i n g . MigLayout ;

p u b l i c c l a s s M P P r e d i c t i m p l e m e n t s A c t i o n L i s t e n e r { p r i v a t e J T e x t F i e l d tfMod ;

p r i v a t e A r r a y L i s t<J T e x t F i e l d>tfEV ; p r i v a t e JCheckBox d e f a u l t M o d e l ; p r i v a t e R C o n n e c t i o n c ;

p r i v a t e JComboBox f i l t e r B o x ; p r i v a t e J B u t t o n d i s p l a y ; p r i v a t e P r e d i c t D i s t p r e d i c t ; p r i v a t e J P a n e l g r a p h P a n e l ;

p u b l i c M P P r e d i c t ( J T e x t F i e l d tfMod , A r r a y L i s t<J T e x t F i e l d>tfEV , JCheckBox d e f a u l t M o d e l , R C o n n e c t i o n c , JComboBox f i l t e r B o x , J B u t t o n d i s p l a y , J P a n e l g r a p h P a n e l ) {

t h i s . tfMod = tfMod ; t h i s . tfEV = tfEV ;

t h i s . d e f a u l t M o d e l = d e f a u l t M o d e l ; t h i s . c = c ;

t h i s . f i l t e r B o x = f i l t e r B o x ; t h i s . d i s p l a y = d i s p l a y ; t h i s . g r a p h P a n e l = g r a p h P a n e l ; }

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b b o o l e a n e r r o r = f a l s e ;

f o r ( J T e x t F i e l d t f : tfEV ) {

i f ( t f . g e t T e x t ( ) . e q u a l s ( ” ” ) ) {

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ”No e n v i r o n m e n t a l v a r i a b l e s s e l e c t e d f o r o n e o f t h e y e a r s ” , ” Warning ” , JOp tio nPan e . WARNING MESSAGE) ;

e r r o r = t r u e ; }

}

i f ( ! e r r o r ) {

e r r o r = f a l s e ;

i f ( d e f a u l t M o d e l . i s S e l e c t e d ( ) ) {

A r r a y L i s t<S t r i n g> i m a g e P a t h s = new A r r a y L i s t<S t r i n g>() ; f o r ( i n t i = 0 ; i < tfEV . s i z e ( ) ; i ++) {

F i l e P a r s e r p a r s e r = new F i l e P a r s e r ( ) ;

F i l e [ ] EV = p a r s e r . t e x t F i e l d P a r s e r ( tfEV . g e t ( i ) ) ; p r e d i c t = new P r e d i c t D i s t (EV, System . g e t P r o p e r t y ( ”

u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) +”/ model / model . r d s ” ,

”mp” + i , c ) ;

i f ( ! e r r o r && p r e d i c t . g e t E r r o r ( ) ) e r r o r = t r u e ; i m a g e P a t h s . add ( ” p i c t u r e s / p r e d i c t i o n m p ” + i + ” . png ” ) ; }

i f ( e r r o r ){

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ” There ’ s a p r o b l e m w i t h some o f y o u r e n v i r o n m e n t a l v a r i a b l e s . P l e a s e r e c h e c k ” , ” E r r o r ” , JO ptio nPa ne . ERROR MESSAGE) ; }

e l s e {

M P D i s p l a y e r d i s p l a y e r = new M P D i s p l a y e r ( i m a g e P a t h s ) ; p r e d i c t . g e t G r a p h ( tfEV . s i z e ( ) , c ) ;

t r y {

B u f f e r e d I m a g e g r a p h = ImageIO . r e a d ( new F i l e ( ” p i c t u r e s / g r a p h . png ” ) ) ;

J L a b e l p i c L a b e l = new J L a b e l ( new I m a g e I c o n ( g r a p h ) ) ;

g r a p h P a n e l . r e m o v e A l l ( ) ;

g r a p h P a n e l . s e t L a y o u t ( new MigLayout ( ” ” , ” [ grow ] ” , ” [ grow ] ” ) ) ;

g r a p h P a n e l . add ( p i c L a b e l , ” c e l l 0 0 , grow , a l i g n c e n t e r ” ) ;

g r a p h P a n e l . r e p a i n t ( ) ; g r a p h P a n e l . r e v a l i d a t e ( ) ; f i l t e r B o x . s e t E n a b l e d ( t r u e ) ; d i s p l a y . s e t E n a b l e d ( t r u e ) ; } c a t c h ( I O E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ” g r a p h . png i s m i s s i n g ” , ” E r r o r ” , JO ptio nPa ne . ERROR MESSAGE) ;

} }

} e l s e {

i f ( tfMod . g e t T e x t ( ) . e q u a l s ( ” ” ) ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ”No model s e l e c t e d

” , ” Warning ” , J Opti onP ane . WARNING MESSAGE) ; }

e l s e {

// P r e d i c t

A r r a y L i s t<S t r i n g> i m a g e P a t h s = new A r r a y L i s t<S t r i n g>()

;

e r r o r = f a l s e ;

f o r ( i n t i = 0 ; i < tfEV . s i z e ( ) ; i ++) { F i l e P a r s e r p a r s e r = new F i l e P a r s e r ( ) ;

F i l e [ ] EV = p a r s e r . t e x t F i e l d P a r s e r ( tfEV . g e t ( i ) ) ;

p r e d i c t = new P r e d i c t D i s t (EV, tfMod . g e t T e x t ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) , ”mp” + i , c ) ; i f ( ! e r r o r && p r e d i c t . g e t E r r o r ( ) ) e r r o r = t r u e ; i m a g e P a t h s . add ( ” p i c t u r e s / p r e d i c t i o n m p ” + i +

” . png ” ) ; }

i f ( e r r o r ){

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ” There ’ s a p r o b l e m w i t h some o f y o u r e n v i r o n m e n t a l v a r i a b l e s . P l e a s e r e c h e c k ” , ” E r r o r ” , JOp tio nPan e . ERROR MESSAGE) ;

} e l s e {

M P D i s p l a y e r d i s p l a y e r = new M P D i s p l a y e r ( i m a g e P a t h s ) ;

p r e d i c t . g e t G r a p h ( tfEV . s i z e ( ) , c ) ; t r y {

B u f f e r e d I m a g e g r a p h = ImageIO . r e a d ( new F i l e ( ” p i c t u r e s / g r a p h . png ” ) ) ;

J L a b e l p i c L a b e l = new J L a b e l ( new I m a g e I c o n ( g r a p h ) ) ;

g r a p h P a n e l . r e m o v e A l l ( ) ;

g r a p h P a n e l . s e t L a y o u t ( new MigLayout ( ” ” ,

” [ grow ] ” , ” [ grow ] ” ) ) ;

g r a p h P a n e l . add ( p i c L a b e l , ” c e l l 0 0 , grow , a l i g n c e n t e r ” ) ;

g r a p h P a n e l . r e p a i n t ( ) ; g r a p h P a n e l . r e v a l i d a t e ( ) ; f i l t e r B o x . s e t E n a b l e d ( t r u e ) ; d i s p l a y . s e t E n a b l e d ( t r u e ) ; } c a t c h ( I O E x c e p t i o n e ) {

// TODO Auto−g e n e r a t e d c a t c h b l o c k JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ”

g r a p h . png i s m i s s i n g ” , ” E r r o r ” , JO ptio nPa ne . ERROR MESSAGE) ; }

} }

} }

} }

p a c k a g e c o m p o n e n t A c t i o n s ;

i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a . u t i l . A r r a y L i s t ; i m p o r t j a v a . u t i l . S t r i n g T o k e n i z e r ; i m p o r t j a v a x . s w i n g . J B u t t o n ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t j a v a B a c k e n d . F i l e P a r s e r ;

i m p o r t j a v a B a c k e n d . R e m o d e l l i n g ; i m p o r t r B a c k e n d . D a t a l o c s V a l i d a t o r ; i m p o r t r B a c k e n d . E n v i V a r V a l i d a t o r ;

p u b l i c c l a s s R e m o d e l P r e p i m p l e m e n t s A c t i o n L i s t e n e r { p r i v a t e R C o n n e c t i o n c ;

p r i v a t e J T e x t F i e l d p r e d i c t o r s ; p r i v a t e J T e x t F i e l d d a t a l o c s ; p r i v a t e J T e x t F i e l d f a c t o r s ; p r i v a t e J T e x t F i e l d destTF ; p r i v a t e J B u t t o n s h o w C o n t r i b ;

p u b l i c R e m o d e l P r e p ( R C o n n e c t i o n c , J T e x t F i e l d p r e d i c t o r s , J T e x t F i e l d d a t a l o c s , J T e x t F i e l d f a c t o r s , J T e x t F i e l d destTF , J B u t t o n s h o w C o n t r i b ) {

t h i s . c = c ;

t h i s . p r e d i c t o r s = p r e d i c t o r s ; t h i s . d a t a l o c s = d a t a l o c s ; t h i s . f a c t o r s = f a c t o r s ; t h i s . destTF = destTF ;

t h i s . s h o w C o n t r i b = s h o w C o n t r i b ; }

p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ) { S t r i n g t e s t = ” 1 2 3 4 5 ” ;

System . o u t . p r i n t l n ( t e s t . i n d e x O f ( ” a ” ) ) ; }

@ O v e r r i d e

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b b o o l e a n p r e d i c t o r E r r o r = f a l s e ; b o o l e a n l o c s E r r o r = f a l s e ; b o o l e a n f a c t o r E r r o r = f a l s e ;

F i l e P a r s e r p a r s e r = new F i l e P a r s e r ( ) ;

F i l e [ ] f i l e P r e d i c t o r s = p a r s e r . t e x t F i e l d P a r s e r ( p r e d i c t o r s ) ;

E n v i V a r V a l i d a t o r e v V a l i d a t o r = new E n v i V a r V a l i d a t o r ( c , f i l e P r e d i c t o r s ) ; p r e d i c t o r E r r o r = ! e v V a l i d a t o r . a r e E n v i V a r V a l i d ( ) ;

D a t a l o c s V a l i d a t o r d l V a l i d a t o r = new D a t a l o c s V a l i d a t o r ( new F i l e ( d a t a l o c s . g e t T e x t ( ) ) , c ) ;

l o c s E r r o r = ! d l V a l i d a t o r . a r e D a t a l o c s V a l i d ( ) ;

S t r i n g T o k e n i z e r s t = new S t r i n g T o k e n i z e r ( f a c t o r s . g e t T e x t ( ) , ” , ” ) ; A r r a y L i s t<S t r i n g> f a c t o r S t r i n g = new A r r a y L i s t<S t r i n g>() ;

w h i l e ( s t . hasMoreTokens ( ) ) {

f a c t o r S t r i n g . add ( s t . n e x t T o k e n ( ) ) ; }

f o r ( i n t i = 0 ; i < f a c t o r S t r i n g . s i z e ( ) ; i ++) { b o o l e a n hasMatch = f a l s e ;

f o r ( i n t j = 0 ; j < f i l e P r e d i c t o r s . l e n g t h ; j ++) {

i f ( f i l e P r e d i c t o r s [ j ] . g e t A b s o l u t e P a t h ( ) . i n d e x O f ( f a c t o r S t r i n g . g e t ( i ) ) != −1) hasMatch = t r u e ;

}

i f ( ! hasMatch ) {

f a c t o r E r r o r = t r u e ; b r e a k ;

} }

i f ( f a c t o r E r r o r ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ”A f a c t o r d o e s n ’ t match any o f t h e p r e d i c t o r s ” , ” E r r o r ” , J Opti onP ane . ERROR MESSAGE) ;

}

System . o u t . p r i n t l n ( p r e d i c t o r E r r o r + ”\t ” + l o c s E r r o r + ”\t ” + f a c t o r E r r o r ) ; i f ( ! p r e d i c t o r E r r o r && ! l o c s E r r o r && ! f a c t o r E r r o r ) {

R e m o d e l l i n g model = new R e m o d e l l i n g ( c , p r e d i c t o r s , d a t a l o c s , f a c t o r S t r i n g , destTF ) ;

model . model ( ) ;

s h o w C o n t r i b . s e t E n a b l e d ( t r u e ) ; System . o u t . p r i n t l n ( ” Yey ? ” ) ; }

} }

p a c k a g e c o m p o n e n t A c t i o n s ;

i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a x . s w i n g . J F i l e C h o o s e r ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ;

p u b l i c c l a s s S e l e c t E V i m p l e m e n t s A c t i o n L i s t e n e r{ p r i v a t e J T e x t F i e l d t f ;

p u b l i c S e l e c t E V ( J T e x t F i e l d t f ) { t h i s . t f = t f ;

}

@ O v e r r i d e

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t e ) { // TODO Auto−g e n e r a t e d method s t u b

S t r i n g c h o o s e r t i t l e = ” S e l e c t e n v i r o n m e n t a l v a r i a b l e s ” ; J F i l e C h o o s e r c h o o s e r = new J F i l e C h o o s e r ( ) ;

c h o o s e r . s e t C u r r e n t D i r e c t o r y ( new j a v a . i o . F i l e ( ” . ” ) ) ; c h o o s e r . s e t D i a l o g T i t l e ( c h o o s e r t i t l e ) ;

c h o o s e r . s e t M u l t i S e l e c t i o n E n a b l e d ( t r u e ) ; c h o o s e r . s e t A c c e p t A l l F i l e F i l t e r U s e d ( f a l s e ) ;

i f ( c h o o s e r . s h o w O p e n D i a l o g ( n u l l ) == J F i l e C h o o s e r . APPROVE OPTION) { S t r i n g B u i l d e r f i l e n a m e s = new S t r i n g B u i l d e r ( ” ” ) ;

F i l e [ ] f i l e s = c h o o s e r . g e t S e l e c t e d F i l e s ( ) ; f o r ( F i l e f i l e : f i l e s ) {

// f i l e n a m e s . append ( ’ ” ’ ) ;

f i l e n a m e s . append ( f i l e . g e t A b s o l u t e P a t h ( ) ) ; // f i l e n a m e s . append ( ’ ” ’ ) ;

f i l e n a m e s . append ( ’ ; ’ ) ; }

t f . s e t T e x t ( f i l e n a m e s . t o S t r i n g ( ) ) ; }

e l s e {

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ”No e n v i r o n m e n t a l v a r i a b l e s s e l e c t e d ” ) ; }

} }

p a c k a g e c o m p o n e n t A c t i o n s ;

i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a x . s w i n g . J F i l e C h o o s e r ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ;

i m p o r t j a v a x . s w i n g . f i l e c h o o s e r . F i l e N a m e E x t e n s i o n F i l t e r ; p u b l i c c l a s s S e l e c t M o d e l i m p l e m e n t s A c t i o n L i s t e n e r {

p r i v a t e J T e x t F i e l d t f = new J T e x t F i e l d ( ) ; p u b l i c S e l e c t M o d e l ( J T e x t F i e l d t e x t f i e l d ) {

t f = t e x t f i e l d ; }

@ O v e r r i d e

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t e ) { // TODO Auto−g e n e r a t e d method s t u b

S t r i n g c h o o s e r t i t l e = ” S e l e c t y o u r model ” ; J F i l e C h o o s e r c h o o s e r = new J F i l e C h o o s e r ( ) ; c h o o s e r . s e t C u r r e n t D i r e c t o r y ( new j a v a . i o . F i l e ( ” . ” ) ) ; c h o o s e r . s e t D i a l o g T i t l e ( c h o o s e r t i t l e ) ;

F i l e N a m e E x t e n s i o n F i l t e r f i l t e r = new F i l e N a m e E x t e n s i o n F i l t e r ( ”∗. r d s ” , ” r d s ” ) ; c h o o s e r . s e t F i l e F i l t e r ( f i l t e r ) ;

c h o o s e r . s e t A c c e p t A l l F i l e F i l t e r U s e d ( f a l s e ) ;

i f ( c h o o s e r . s h o w O p e n D i a l o g ( n u l l ) == J F i l e C h o o s e r . APPROVE OPTION) { t f . s e t T e x t ( c h o o s e r . g e t S e l e c t e d F i l e ( ) . g e t A b s o l u t e P a t h ( ) ) ;

} e l s e {

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ”No model s e l e c t e d ” ) ; }

} }

p a c k a g e c o m p o n e n t A c t i o n s ;

i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a B a c k e n d . I m a g e D i s p l a y e r ;

p u b l i c c l a s s S P L a s t P r e d i m p l e m e n t s A c t i o n L i s t e n e r {

@ O v e r r i d e

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b

// I m a g e D i s p l a y e r p r e d i c t i o n = new I m a g e D i s p l a y e r ( ” p i c t u r e s / p r e d i c t i o n s p . png ” ) ; }

}

p a c k a g e c o m p o n e n t A c t i o n s ;

i m p o r t j a v a . awt . e v e n t . A c t i o n E v e n t ; i m p o r t j a v a . awt . e v e n t . A c t i o n L i s t e n e r ; i m p o r t j a v a . i o . F i l e ;

i m p o r t j a v a x . s w i n g . J B u t t o n ; i m p o r t j a v a x . s w i n g . JCheckBox ; i m p o r t j a v a x . s w i n g . JComboBox ; i m p o r t j a v a x . s w i n g . J Opti onP ane ; i m p o r t j a v a x . s w i n g . J P a n e l ; i m p o r t j a v a x . s w i n g . J T e x t F i e l d ;

i m p o r t o r g . r o s u d a . REngine . R s e r v e . R C o n n e c t i o n ; i m p o r t j a v a B a c k e n d . F i l e P a r s e r ;

i m p o r t j a v a B a c k e n d . I m a g e D i s p l a y e r ; i m p o r t j a v a B a c k e n d . P r e d i c t D i s t ;

p u b l i c c l a s s S P P r e d i c t i m p l e m e n t s A c t i o n L i s t e n e r{ p r i v a t e J T e x t F i e l d tfMod ;

p r i v a t e J T e x t F i e l d tfEV ; p r i v a t e JCheckBox d e f a u l t M o d e l ; p r i v a t e R C o n n e c t i o n c ;

p r i v a t e J B u t t o n f i l t e r B t n ; p r i v a t e JComboBox f i l t e r B o x ;

p u b l i c S P P r e d i c t ( J T e x t F i e l d tfMod , J T e x t F i e l d tfEV , JCheckBox d e f a u l t M o d e l , R C o n n e c t i o n c , J B u t t o n f i l t e r B t n , JComboBox f i l t e r B o x ) {

t h i s . tfMod = tfMod ; t h i s . tfEV = tfEV ;

t h i s . d e f a u l t M o d e l = d e f a u l t M o d e l ; t h i s . c = c ;

t h i s . f i l t e r B o x = f i l t e r B o x ; t h i s . f i l t e r B t n = f i l t e r B t n ; }

@ O v e r r i d e

p u b l i c v o i d a c t i o n P e r f o r m e d ( A c t i o n E v e n t a r g 0 ) { // TODO Auto−g e n e r a t e d method s t u b i f ( tfEV . g e t T e x t ( ) . e q u a l s ( ” ” ) ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g ( n u l l , ”No e n v i r o n m e n t a l v a r i a b l e s s e l e c t e d ” , ” Warning ” , J Opt ionP ane . WARNING MESSAGE) ; }

e l s e i f ( d e f a u l t M o d e l . i s S e l e c t e d ( ) ) { // P r e d i c t

f i l t e r B o x . s e t E n a b l e d ( t r u e ) ; f i l t e r B t n . s e t E n a b l e d ( t r u e ) ;

F i l e P a r s e r p a r s e r = new F i l e P a r s e r ( ) ; F i l e [ ] EV = p a r s e r . t e x t F i e l d P a r s e r ( tfEV ) ;

P r e d i c t D i s t p r e d i c t = new P r e d i c t D i s t (EV, System . g e t P r o p e r t y ( ” u s e r . d i r ” ) . r e p l a c e ( ’\ \’ , ’ / ’ ) +”/ model / model . r d s ” , ” s p ” , c ) ;

i f ( ! p r e d i c t . g e t E r r o r ( ) ) {

I m a g e D i s p l a y e r i m a g e = new I m a g e D i s p l a y e r ( ” p i c t u r e s / p r e d i c t i o n

” + ” s p ” + ” . png ” , ” s p ” ) ; }

} e l s e {

i f ( tfMod . g e t T e x t ( ) . e q u a l s ( ” ” ) ) {

JO ptio nPa ne . s h o w M e s s a g e D i a l o g ( n u l l , ”No model s e l e c t e d ” , ” Warning ” , JOp tion Pan e . WARNING MESSAGE) ;

} e l s e {

// P r e d i c t

f i l t e r B o x . s e t E n a b l e d ( t r u e ) ; f i l t e r B t n . s e t E n a b l e d ( t r u e ) ;

F i l e P a r s e r p a r s e r = new F i l e P a r s e r ( ) ; F i l e [ ] EV = p a r s e r . t e x t F i e l d P a r s e r ( tfEV ) ;

P r e d i c t D i s t p r e d i c t = new P r e d i c t D i s t (EV, tfMod . g e t T e x t ( ) . r e p l a c e ( ’\ \’ , ’ / ’ ) , ” s p ” , c ) ;

i f ( ! p r e d i c t . g e t E r r o r ( ) ) {

I m a g e D i s p l a y e r i m a g e = new I m a g e D i s p l a y e r ( ” p i c t u r e s / p r e d i c t i o n ” + ” s p ” + ” . png ” , ” s p ” ) ;

} }

} }

}

Dokumen terkait