22 * @author Chinedu Oguejiofor
33 *10 Aug. 2017
44 * 3:23:29 pm
5- */
5+ */ /*
66package com.solutioninventors.tournament.GUI.controller;
77
88import java.io.File;
99import java.io.FileInputStream;
1010import java.io.FileNotFoundException;
1111import java.io.IOException;
12+ import java.io.InputStream;
1213import java.net.MalformedURLException;
1314import java.net.URISyntaxException;
1415import java.net.URL;
1516import java.util.Arrays;
1617import java.util.List;
1718
19+ import org.apache.commons.io.FileUtils;
20+
1821import com.solutioninventors.tournament.GUI.utility.ConfirmBox;
1922import com.solutioninventors.tournament.GUI.utility.Paths;
2023import com.solutioninventors.tournament.exceptions.InvalidBreakerException;
@@ -65,8 +68,8 @@ public class InputCompetitorController {
6568 private Font font[] = new Font[3];
6669 private Stage window;
6770
68- private URL url1 = getClass ().getResource (Paths .images + "clickme.PNG" );
69- private URL url2 = getClass ().getResource (Paths .images + "nologo.jpg" );
71+ private InputStream url1 = getClass().getResourceAsStream (Paths.images + "clickme.PNG");
72+ private InputStream url2 = getClass().getResourceAsStream (Paths.images + "nologo.jpg");
7073 private Image image;
7174 // shared variables
7275 private String TournamentName;
@@ -182,43 +185,38 @@ public void setMultiStageTournament(String tn, Boolean goalScored, int rud, int
182185 }
183186
184187 public void loadcomponents() {
185- // this was used to set the default no logo image
186- try {
187- image = new Image (new FileInputStream (new File (url1 .toURI ())));
188-
189- comps = new Competitor [noOfCompetitors ];
190- file = new File [noOfCompetitors ];
191- imageTracker = new int [noOfCompetitors ];
192- Arrays .fill (imageTracker , -1 );
193- for (int i = 0 ; i < txtArray .size (); i ++) {
194- txtArray .get (i ).setText (null );
195- }
196- /*for (int i = 0; i < comps.length; i++) {
197- comps[i] = new Competitor("Player " + String.valueOf(i + 1), new File(url1.toURI()));
198- }
199- fo
200- */
201- btnPrevious .setVisible (false );
202- btnNext .setVisible (noOfCompetitors <= 4 ? false : true );
203-
204- if (TournamentType == TournamentTypes .CHALLENGE ) {
205- comps [0 ] = new Competitor ("Champion" , new File (url1 .toURI ()));
206- comps [1 ] = new Competitor ("Challenger" , new File (url1 .toURI ()));
207- txtArray .get (0 ).setPromptText ("Champion" );
208- txtArray .get (1 ).setPromptText ("Challenger" );
209- for (int i = 2 ; i < 4 ; i ++) {
210- txtArray .get (i ).setVisible (false );
211- imgArray .get (i ).setVisible (false );
212- SNArray .get (i ).setVisible (false );
213- }
214- endValue = 2 ;
215- } else if (noOfCompetitors == 3 ) {
216- txtArray .get (3 ).setVisible (false );
217- imgArray .get (3 ).setVisible (false );
218- SNArray .get (3 ).setVisible (false );
188+ image = new Image(url1);
189+
190+ comps = new Competitor[noOfCompetitors];
191+ file = new File[noOfCompetitors];
192+ imageTracker = new int[noOfCompetitors];
193+ Arrays.fill(imageTracker, -1);
194+ for (int i = 0; i < txtArray.size(); i++) {
195+ txtArray.get(i).setText(null);
196+ }
197+ for (int i = 0; i < comps.length; i++) {
198+ comps[i] = new Competitor("Player " + String.valueOf(i + 1), new File(url1.toURI()));
199+ }
200+ fo
201+
202+ btnPrevious.setVisible(false);
203+ btnNext.setVisible(noOfCompetitors <= 4 ? false : true);
204+
205+ if (TournamentType == TournamentTypes.CHALLENGE) {
206+ comps[0] = new Competitor("Champion", new File(url1.toString()));
207+ comps[1] = new Competitor("Challenger", new File(url1.toString()));
208+ txtArray.get(0).setPromptText("Champion");
209+ txtArray.get(1).setPromptText("Challenger");
210+ for (int i = 2; i < 4; i++) {
211+ txtArray.get(i).setVisible(false);
212+ imgArray.get(i).setVisible(false);
213+ SNArray.get(i).setVisible(false);
219214 }
220- } catch (FileNotFoundException | URISyntaxException e ) {
221- e .printStackTrace ();
215+ endValue = 2;
216+ } else if (noOfCompetitors == 3) {
217+ txtArray.get(3).setVisible(false);
218+ imgArray.get(3).setVisible(false);
219+ SNArray.get(3).setVisible(false);
222220 }
223221
224222 if (goalScored) {
@@ -239,7 +237,7 @@ public void cancel(ActionEvent event) {
239237 }
240238
241239 @FXML
242- public void previous (ActionEvent event ) throws MalformedURLException , URISyntaxException {
240+ public void previous(ActionEvent event) throws URISyntaxException, IOException {
243241 btnNext.setVisible(true);
244242 btnPrevious.setVisible(startValue - 4 == 0 ? false : true);
245243 for (int i = startValue; i < endValue; i++) {
@@ -248,7 +246,11 @@ public void previous(ActionEvent event) throws MalformedURLException, URISyntaxE
248246 if (file[i] != null) {
249247 file[i] = file[i];
250248 } else {
251- file [i ] = new File (url1 .toURI ());
249+ File tempFile = null;
250+ FileUtils.copyInputStreamToFile(url1,tempFile);
251+
252+ //file[i] = new File(url1.toURI());
253+ //file[i] =
252254 imageTracker[i] = i;//track the location in which Click to add image is used
253255 }
254256 comps[i] = new Competitor(tempCompName, file[i]);
@@ -553,3 +555,4 @@ public void changeimage4(ActionEvent e) throws MalformedURLException {
553555 changeImage4(null);
554556 }
555557}// end class
558+ */
0 commit comments