SlideshowViewer Updated to version 1.1. Changes include:
- Ability to specify duration in seconds instead of minutes. - Added a debug box which shows additional information to the user. - Changed Output Folder to an Output file dialog instead. - Fixed a bug causing minutes to being converted as seconds and rounding down, causing slideshows to stop randomly. - Fixed a bug causing directories to be selected as slideshow images when directories are created inside slideshow folders.
This commit is contained in:
parent
4468b9d327
commit
a90bce1983
Binary file not shown.
@ -13,6 +13,8 @@ import java.awt.event.WindowListener;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
@ -21,6 +23,8 @@ import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.Timer;
|
||||
|
||||
@ -29,7 +33,7 @@ import org.apache.commons.io.FileUtils;
|
||||
public class SlideshowViewer {
|
||||
|
||||
public static String slideshowFolderPath = "./slideshow/";
|
||||
public static String outputFolderPath = "./";
|
||||
public static String outputFilePath = "./slideshow_image.png";
|
||||
public static String[] slideshowDataFiles = null;
|
||||
public static JLabel slideshowpath_button = null;
|
||||
public static JLabel slideshowpath_label = null;
|
||||
@ -41,13 +45,15 @@ public class SlideshowViewer {
|
||||
public static JButton slideshowdir_button = null;
|
||||
public static JButton outputimage_button = null;
|
||||
public static JTextField delayAmtBox = null;
|
||||
public static JTextArea debugBox = null;
|
||||
public static String currentDisplayedFile = "";
|
||||
public static boolean randomness = true;
|
||||
public static Checkbox random = null;
|
||||
public static long currentTick = 0;
|
||||
public static long nextImageChange = 0;
|
||||
public static int slideshowDelay = 5;
|
||||
public static int slideshowDelay = 60;
|
||||
public static int slideshowMarker = 0;
|
||||
final public static String PROGRAM_VERSION = "1.1";
|
||||
static Timer programClock = new Timer(1000,new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -59,41 +65,41 @@ public class SlideshowViewer {
|
||||
public static ActionListener buttonListener = new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (button.getText().contains("Start")) {
|
||||
System.out.println("Running slideshow...");
|
||||
PrintToSystemAndAddToDebugBox("Running slideshow...");
|
||||
SelectImage();
|
||||
button.setText("Stop Slideshow");
|
||||
} else {
|
||||
System.out.println("Stopping slideshow...");
|
||||
PrintToSystemAndAddToDebugBox("Stopping slideshow...");
|
||||
button.setText("Start Slideshow");
|
||||
}
|
||||
}
|
||||
};
|
||||
public static ActionListener decreaseDelayListener = new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
int currentdelay = 5;
|
||||
int currentdelay = 60;
|
||||
try {
|
||||
currentdelay = Integer.parseInt(delayAmtBox.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
currentdelay = 5;
|
||||
currentdelay = 60;
|
||||
}
|
||||
|
||||
currentdelay = Math.max(currentdelay-1, 1);
|
||||
delayAmtBox.setText(Integer.toString(currentdelay));
|
||||
slideshowDelay = currentdelay*60;
|
||||
slideshowDelay = currentdelay;
|
||||
}
|
||||
};
|
||||
public static ActionListener increaseDelayListener = new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
int currentdelay = 5;
|
||||
int currentdelay = 60;
|
||||
try {
|
||||
currentdelay = Integer.parseInt(delayAmtBox.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
currentdelay = 5;
|
||||
currentdelay = 60;
|
||||
}
|
||||
|
||||
currentdelay = Math.min(currentdelay+1, 120);
|
||||
currentdelay = Math.min(currentdelay+1, 7200);
|
||||
delayAmtBox.setText(Integer.toString(currentdelay));
|
||||
slideshowDelay = currentdelay*60;
|
||||
slideshowDelay = currentdelay;
|
||||
}
|
||||
};
|
||||
public static ActionListener slidershowdir_buttonListener = new ActionListener(){
|
||||
@ -117,21 +123,22 @@ public class SlideshowViewer {
|
||||
}
|
||||
}
|
||||
};
|
||||
public static ActionListener outputdir_buttonListener = new ActionListener(){
|
||||
public static ActionListener outputfile_buttonListener = new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
File path = new File(outputFolderPath);
|
||||
File path = new File(outputFilePath);
|
||||
if (path.exists()) {
|
||||
chooser.setCurrentDirectory(path);
|
||||
} else {
|
||||
chooser.setCurrentDirectory(new File("."));
|
||||
}
|
||||
chooser.setDialogTitle("Load Slideshow Images Directory");
|
||||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
chooser.setSelectedFile(path);
|
||||
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
outputFolderPath = chooser.getSelectedFile().getAbsolutePath()+"/";
|
||||
outputFilePath = chooser.getSelectedFile().getAbsolutePath()+"/";
|
||||
try {
|
||||
outputpath_label.setText("Output Location: "+new File(outputFolderPath).getCanonicalPath());
|
||||
outputpath_label.setText("Output File: "+new File(outputFilePath).getCanonicalPath());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@ -146,12 +153,12 @@ public class SlideshowViewer {
|
||||
}
|
||||
currentDisplayedFile = slideshowFolderPath+selectedFile;
|
||||
nextImageChange = currentTick + slideshowDelay;
|
||||
System.out.println("Selected image "+selectedFile+". Next change in "+slideshowDelay+" seconds.");
|
||||
PrintToSystemAndAddToDebugBox("Selected image "+selectedFile+". Next change in "+slideshowDelay+" second"+((slideshowDelay!=1)?"s":"")+".");
|
||||
ChangeSlideshowImage();
|
||||
}
|
||||
|
||||
private static void ChangeSlideshowImage() {
|
||||
File filer = new File("./slideshow_image.png");
|
||||
File filer = new File(outputFilePath);
|
||||
if (!filer.exists()) {
|
||||
try {
|
||||
filer.createNewFile();
|
||||
@ -167,14 +174,16 @@ public class SlideshowViewer {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Slideshow Viewer v1.0 Started.");
|
||||
List<String> debugqueue = new ArrayList<String>();
|
||||
|
||||
PrintToSystemAndAddToQueue(debugqueue,"Slideshow Viewer v"+PROGRAM_VERSION+" Started.");
|
||||
|
||||
programClock.start();
|
||||
|
||||
File config_file = new File("config_slideshow.txt");
|
||||
File slideshowdirectory = null;
|
||||
if (!config_file.exists()) {
|
||||
System.out.println("\nConfiguration file does not exist...Creating one.");
|
||||
PrintToSystemAndAddToQueue(debugqueue,"\nConfiguration file does not exist...Creating one.");
|
||||
CreateAndSaveConfigurationFile();
|
||||
} else {
|
||||
LoadConfigurationFile();
|
||||
@ -182,23 +191,23 @@ public class SlideshowViewer {
|
||||
slideshowdirectory = new File(slideshowFolderPath);
|
||||
|
||||
if (slideshowdirectory!=null && slideshowdirectory.exists()) {
|
||||
System.out.println(" Loading slideshow data...");
|
||||
PrintToSystemAndAddToQueue(debugqueue," Loading slideshow data...");
|
||||
if (!LoadSlideshowData(slideshowdirectory)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
System.out.println("\nSlideshow data does not exist...Creating a slideshow directory...");
|
||||
PrintToSystemAndAddToQueue(debugqueue,"\nSlideshow data does not exist...Creating a slideshow directory...");
|
||||
slideshowdirectory = new File("./slideshow");
|
||||
slideshowdirectory.mkdirs();
|
||||
slideshowDataFiles = new String[]{};
|
||||
try {
|
||||
System.out.println("\nPlease insert files into the "+slideshowdirectory.getCanonicalPath()+" directory!");
|
||||
PrintToSystemAndAddToQueue(debugqueue,"\nPlease insert files into the "+slideshowdirectory.getCanonicalPath()+" directory!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
JFrame f = new JFrame("SlideshowViewer v1.0");
|
||||
JFrame f = new JFrame("SlideshowViewer v"+PROGRAM_VERSION);
|
||||
|
||||
f.addWindowListener(new WindowListener() {
|
||||
|
||||
@ -252,6 +261,7 @@ public class SlideshowViewer {
|
||||
JPanel panel = new JPanel();
|
||||
JPanel panel2 = new JPanel();
|
||||
JPanel panel3 = new JPanel();
|
||||
JPanel panel4 = new JPanel();
|
||||
|
||||
panel.setLayout(new BoxLayout(panel,BoxLayout.LINE_AXIS));
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
@ -261,7 +271,7 @@ public class SlideshowViewer {
|
||||
button.addActionListener(buttonListener);
|
||||
|
||||
JLabel label = new JLabel();
|
||||
label.setText(" Delay (min): ");
|
||||
label.setText(" Delay (sec): ");
|
||||
label.setMinimumSize(new Dimension(16,10));
|
||||
|
||||
delayAmtBox = new JTextField(2);
|
||||
@ -285,7 +295,7 @@ public class SlideshowViewer {
|
||||
outputpath_label = new JLabel("");
|
||||
|
||||
try {
|
||||
outputpath_label.setText("Output Folder: "+new File(outputFolderPath).getCanonicalPath());
|
||||
outputpath_label.setText("Output Folder: "+new File(outputFilePath).getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -295,7 +305,7 @@ public class SlideshowViewer {
|
||||
slideshowdir_button.addActionListener(slidershowdir_buttonListener);
|
||||
outputpath_button = new JButton("Change");
|
||||
outputpath_button.setMaximumSize(new Dimension(32,24));
|
||||
outputpath_button.addActionListener(outputdir_buttonListener);
|
||||
outputpath_button.addActionListener(outputfile_buttonListener);
|
||||
|
||||
JLabel label2 = new JLabel();
|
||||
label2.setText(" ");
|
||||
@ -309,6 +319,19 @@ public class SlideshowViewer {
|
||||
panel.setSize(480, 36);
|
||||
//panel.setBounds(0,0,72,36);
|
||||
|
||||
debugBox = new JTextArea(8,32);
|
||||
debugBox.setEditable(false);
|
||||
debugBox.setLineWrap(true);
|
||||
debugBox.setAutoscrolls(true);
|
||||
for (String s : debugqueue) {
|
||||
debugBox.setText(debugBox.getText()+s+"\n");
|
||||
}
|
||||
debugBox.setWrapStyleWord(true);
|
||||
JScrollPane scrollPane = new JScrollPane(debugBox);
|
||||
scrollPane.setPreferredSize(new Dimension(320,96));
|
||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
|
||||
//f.add(panel);
|
||||
|
||||
String[] options = new String[]{};
|
||||
@ -323,10 +346,13 @@ public class SlideshowViewer {
|
||||
panel2.add(slideshowdir_button);
|
||||
panel3.add(outputpath_label);
|
||||
panel3.add(outputpath_button);
|
||||
panel4.add(scrollPane);
|
||||
//panel4.add(debugBox);
|
||||
|
||||
container.add(panel);
|
||||
container.add(panel2);
|
||||
container.add(panel3);
|
||||
container.add(panel4);
|
||||
|
||||
f.add(container);
|
||||
//f.pack();
|
||||
@ -335,6 +361,16 @@ public class SlideshowViewer {
|
||||
f.pack();
|
||||
}
|
||||
|
||||
private static void PrintToSystemAndAddToQueue(List<String> debugqueue, String string) {
|
||||
debugqueue.add(string);
|
||||
System.out.println(string);
|
||||
}
|
||||
|
||||
public static void PrintToSystemAndAddToDebugBox(String message) {
|
||||
debugBox.setText((debugBox.getText().length()>5000?debugBox.getText().substring(debugBox.getText().length()-5000, debugBox.getText().length()-1):debugBox.getText())+message+"\n");
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
protected static void performStep() {
|
||||
DetectDirectoryChange();
|
||||
if (button.getText().contains("Stop")) {
|
||||
@ -344,33 +380,35 @@ public class SlideshowViewer {
|
||||
SelectImage();
|
||||
}
|
||||
}
|
||||
int currentdelay = 5;
|
||||
int currentdelay = 60;
|
||||
try {
|
||||
currentdelay = Integer.parseInt(delayAmtBox.getText());
|
||||
} catch (NumberFormatException ex) {
|
||||
currentdelay = -1;
|
||||
}
|
||||
if (currentdelay>120 || currentdelay<=0) {
|
||||
currentdelay = 5;
|
||||
if (currentdelay>7200 || currentdelay<=0) {
|
||||
currentdelay = 60;
|
||||
delayAmtBox.setText(Integer.toString(currentdelay));
|
||||
}
|
||||
slideshowDelay = currentdelay*60;
|
||||
slideshowDelay = currentdelay;
|
||||
}
|
||||
|
||||
private static void DetectDirectoryChange() {
|
||||
File dir = new File(slideshowFolderPath);
|
||||
if (dir.list().length!=slideshowDataFiles.length) {
|
||||
System.out.println(" A change has been detected in the slideshow directory! Reloading images...");
|
||||
String[] list = trimNonImageFiles(dir.list());
|
||||
if (list.length!=slideshowDataFiles.length) {
|
||||
PrintToSystemAndAddToDebugBox(" A change has been detected in the slideshow directory! Reloading images...");
|
||||
LoadSlideshowData(dir);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean LoadSlideshowData(File dir) {
|
||||
String[] filelist = dir.list();
|
||||
filelist = trimNonImageFiles(filelist);
|
||||
if (filelist.length==0) {
|
||||
System.out.println("Could not find any files to load!");
|
||||
PrintToSystemAndAddToDebugBox("Could not find any files to load!");
|
||||
try {
|
||||
System.out.println("\nPlease insert files into the "+dir.getCanonicalPath()+" directory!");
|
||||
PrintToSystemAndAddToDebugBox("\nPlease insert files into the "+dir.getCanonicalPath()+" directory!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -383,6 +421,22 @@ public class SlideshowViewer {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String[] trimNonImageFiles(String[] files) {
|
||||
List<String> finallist = new ArrayList<String>();
|
||||
for (String file : files) {
|
||||
File f = new File(slideshowFolderPath+file);
|
||||
try {
|
||||
if (!f.isDirectory() && !f.getCanonicalPath().equalsIgnoreCase(new File(outputFilePath).getCanonicalPath())) {
|
||||
finallist.add(file);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return finallist.toArray(new String[finallist.size()]);
|
||||
}
|
||||
|
||||
private static void CreateAndSaveConfigurationFile() {
|
||||
File configFile = new File("config_slideshow.txt");
|
||||
if (!configFile.exists()) {
|
||||
@ -399,16 +453,22 @@ public class SlideshowViewer {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sig.SlideshowViewer.FileUtils.logToFile("SLIDESHOW_PATH="+slideshowFolderPath, "config_slideshow.txt");
|
||||
sig.SlideshowViewer.FileUtils.logToFile("OUTPUT_PATH="+outputFolderPath, "config_slideshow.txt");
|
||||
sig.SlideshowViewer.FileUtils.logToFile("OUTPUT_PATH="+outputFilePath, "config_slideshow.txt");
|
||||
sig.SlideshowViewer.FileUtils.logToFile("RANDOM="+Boolean.toString((random!=null)?random.getState():true)+"", "config_slideshow.txt");
|
||||
sig.SlideshowViewer.FileUtils.logToFile("DELAY="+slideshowDelay+"", "config_slideshow.txt");
|
||||
sig.SlideshowViewer.FileUtils.logToFile("MARKER="+slideshowMarker+"", "config_slideshow.txt");
|
||||
sig.SlideshowViewer.FileUtils.logToFile("VERSION="+PROGRAM_VERSION+"", "config_slideshow.txt");
|
||||
}
|
||||
|
||||
private static void LoadConfigurationFile() {
|
||||
File configFile = new File("config_slideshow.txt");
|
||||
if (configFile.exists()) {
|
||||
String[] data = sig.SlideshowViewer.FileUtils.readFromFile("config_slideshow.txt");
|
||||
if (data.length==5) {
|
||||
System.out.println("\nConfig does not have correct number of data points! Set it up as version 1.0!");
|
||||
sig.SlideshowViewer.FileUtils.logToFile("VERSION=1.0", "config_slideshow.txt");
|
||||
}
|
||||
data = sig.SlideshowViewer.FileUtils.readFromFile("config_slideshow.txt");
|
||||
int counter = 0;
|
||||
for (String line : data) {
|
||||
String split = line.split("=")[1];
|
||||
@ -417,23 +477,39 @@ public class SlideshowViewer {
|
||||
slideshowFolderPath = split;
|
||||
}break;
|
||||
case 1:{
|
||||
outputFolderPath = split;
|
||||
outputFilePath = split;
|
||||
File filer = new File(outputFilePath);
|
||||
if (!filer.isFile()) {
|
||||
try {
|
||||
filer.createNewFile();
|
||||
} catch (IOException e) {
|
||||
outputFilePath = "./slideshow_image.png";
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 2:{
|
||||
randomness = Boolean.parseBoolean(split);
|
||||
}break;
|
||||
case 3:{
|
||||
slideshowDelay = Integer.parseInt(split)/60;
|
||||
slideshowDelay = Integer.parseInt(split);
|
||||
}break;
|
||||
case 4:{
|
||||
slideshowMarker = Integer.parseInt(split);
|
||||
}break;
|
||||
case 5:{
|
||||
String version = split;
|
||||
if (version.equalsIgnoreCase("1.0")) {
|
||||
System.out.println("Upgrading to version 1.1...");
|
||||
outputFilePath = "./slideshow_image.png";
|
||||
}
|
||||
}break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Could not load from Config file!");
|
||||
PrintToSystemAndAddToDebugBox("Could not load from Config file!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user