Added a handled case for when there are no images in the specified

slideshow directory to prevent errors.
master
sigonasr2 7 years ago
parent a90bce1983
commit 6e904003b9
  1. BIN
      SlideshowViewer/SlideshowViewer.jar
  2. 42
      SlideshowViewer/src/sig/SlideshowViewer/SlideshowViewer.java

@ -54,6 +54,7 @@ public class SlideshowViewer {
public static int slideshowDelay = 60; public static int slideshowDelay = 60;
public static int slideshowMarker = 0; public static int slideshowMarker = 0;
final public static String PROGRAM_VERSION = "1.1"; final public static String PROGRAM_VERSION = "1.1";
public static List<String> debugqueue = new ArrayList<String>();
static Timer programClock = new Timer(1000,new ActionListener(){ static Timer programClock = new Timer(1000,new ActionListener(){
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -67,7 +68,9 @@ public class SlideshowViewer {
if (button.getText().contains("Start")) { if (button.getText().contains("Start")) {
PrintToSystemAndAddToDebugBox("Running slideshow..."); PrintToSystemAndAddToDebugBox("Running slideshow...");
SelectImage(); SelectImage();
if (slideshowDataFiles.length>0) {
button.setText("Stop Slideshow"); button.setText("Stop Slideshow");
}
} else { } else {
PrintToSystemAndAddToDebugBox("Stopping slideshow..."); PrintToSystemAndAddToDebugBox("Stopping slideshow...");
button.setText("Start Slideshow"); button.setText("Start Slideshow");
@ -147,6 +150,7 @@ public class SlideshowViewer {
}; };
public static void SelectImage() { public static void SelectImage() {
if (slideshowDataFiles.length>0) {
String selectedFile = slideshowDataFiles[(slideshowMarker++)%slideshowDataFiles.length]; String selectedFile = slideshowDataFiles[(slideshowMarker++)%slideshowDataFiles.length];
if (random.getState()) { if (random.getState()) {
selectedFile = slideshowDataFiles[(int)(Math.random()*slideshowDataFiles.length)]; selectedFile = slideshowDataFiles[(int)(Math.random()*slideshowDataFiles.length)];
@ -155,6 +159,14 @@ public class SlideshowViewer {
nextImageChange = currentTick + slideshowDelay; nextImageChange = currentTick + slideshowDelay;
PrintToSystemAndAddToDebugBox("Selected image "+selectedFile+". Next change in "+slideshowDelay+" second"+((slideshowDelay!=1)?"s":"")+"."); PrintToSystemAndAddToDebugBox("Selected image "+selectedFile+". Next change in "+slideshowDelay+" second"+((slideshowDelay!=1)?"s":"")+".");
ChangeSlideshowImage(); ChangeSlideshowImage();
} else {
try {
PrintToSystemAndAddToDebugBox("\nCount not start slideshow! Please insert images into the "+new File(slideshowFolderPath).getCanonicalPath()+" directory or select a valid slideshow directory!");
button.setText("Stop Slideshow");
} catch (IOException e) {
e.printStackTrace();
}
}
} }
private static void ChangeSlideshowImage() { private static void ChangeSlideshowImage() {
@ -174,16 +186,15 @@ public class SlideshowViewer {
} }
public static void main(String[] args) { public static void main(String[] args) {
List<String> debugqueue = new ArrayList<String>();
PrintToSystemAndAddToQueue(debugqueue,"Slideshow Viewer v"+PROGRAM_VERSION+" Started."); PrintToSystemAndAddToQueue("Slideshow Viewer v"+PROGRAM_VERSION+" Started.");
programClock.start(); programClock.start();
File config_file = new File("config_slideshow.txt"); File config_file = new File("config_slideshow.txt");
File slideshowdirectory = null; File slideshowdirectory = null;
if (!config_file.exists()) { if (!config_file.exists()) {
PrintToSystemAndAddToQueue(debugqueue,"\nConfiguration file does not exist...Creating one."); PrintToSystemAndAddToQueue("\nConfiguration file does not exist...Creating one.");
CreateAndSaveConfigurationFile(); CreateAndSaveConfigurationFile();
} else { } else {
LoadConfigurationFile(); LoadConfigurationFile();
@ -191,17 +202,17 @@ public class SlideshowViewer {
slideshowdirectory = new File(slideshowFolderPath); slideshowdirectory = new File(slideshowFolderPath);
if (slideshowdirectory!=null && slideshowdirectory.exists()) { if (slideshowdirectory!=null && slideshowdirectory.exists()) {
PrintToSystemAndAddToQueue(debugqueue," Loading slideshow data..."); PrintToSystemAndAddToQueue(" Loading slideshow data...");
if (!LoadSlideshowData(slideshowdirectory)) { if (!LoadSlideshowData(slideshowdirectory)) {
return; return;
} }
} else { } else {
PrintToSystemAndAddToQueue(debugqueue,"\nSlideshow data does not exist...Creating a slideshow directory..."); PrintToSystemAndAddToQueue("\nSlideshow data does not exist...Creating a slideshow directory...");
slideshowdirectory = new File("./slideshow"); slideshowdirectory = new File("./slideshow");
slideshowdirectory.mkdirs(); slideshowdirectory.mkdirs();
slideshowDataFiles = new String[]{}; slideshowDataFiles = new String[]{};
try { try {
PrintToSystemAndAddToQueue(debugqueue,"\nPlease insert files into the "+slideshowdirectory.getCanonicalPath()+" directory!"); PrintToSystemAndAddToQueue("\nPlease insert files into the "+slideshowdirectory.getCanonicalPath()+" directory!");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -326,6 +337,7 @@ public class SlideshowViewer {
for (String s : debugqueue) { for (String s : debugqueue) {
debugBox.setText(debugBox.getText()+s+"\n"); debugBox.setText(debugBox.getText()+s+"\n");
} }
debugqueue.clear();
debugBox.setWrapStyleWord(true); debugBox.setWrapStyleWord(true);
JScrollPane scrollPane = new JScrollPane(debugBox); JScrollPane scrollPane = new JScrollPane(debugBox);
scrollPane.setPreferredSize(new Dimension(320,96)); scrollPane.setPreferredSize(new Dimension(320,96));
@ -361,16 +373,29 @@ public class SlideshowViewer {
f.pack(); f.pack();
} }
private static void PrintToSystemAndAddToQueue(List<String> debugqueue, String string) { private static void PrintToSystemAndAddToQueue(String string) {
debugqueue.add(string); debugqueue.add(string);
System.out.println(string); System.out.println(string);
} }
public static void PrintToSystemAndAddToDebugBox(String message) { public static void PrintToSystemAndAddToDebugBox(String message) {
if (debugBox!=null) {
debugBox.setText((debugBox.getText().length()>5000?debugBox.getText().substring(debugBox.getText().length()-5000, debugBox.getText().length()-1):debugBox.getText())+message+"\n"); debugBox.setText((debugBox.getText().length()>5000?debugBox.getText().substring(debugBox.getText().length()-5000, debugBox.getText().length()-1):debugBox.getText())+message+"\n");
} else {
debugqueue.add(message);
}
System.out.println(message); System.out.println(message);
} }
public static void FlushDebugQueue() {
if (debugBox!=null) {
for (String s : debugqueue) {
debugBox.setText((debugBox.getText().length()>5000?debugBox.getText().substring(debugBox.getText().length()-5000, debugBox.getText().length()-1):debugBox.getText())+s+"\n");
}
debugqueue.clear();
}
}
protected static void performStep() { protected static void performStep() {
DetectDirectoryChange(); DetectDirectoryChange();
if (button.getText().contains("Stop")) { if (button.getText().contains("Stop")) {
@ -390,6 +415,9 @@ public class SlideshowViewer {
currentdelay = 60; currentdelay = 60;
delayAmtBox.setText(Integer.toString(currentdelay)); delayAmtBox.setText(Integer.toString(currentdelay));
} }
if (debugqueue.size()>0) {
FlushDebugQueue();
}
slideshowDelay = currentdelay; slideshowDelay = currentdelay;
} }

Loading…
Cancel
Save