Skip to content

Commit

Permalink
Fullscreen mode now works on Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonUden committed Apr 2, 2018
1 parent 6657341 commit 389ed88
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/se/Zeeraa/slideshow/Slideshow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package se.Zeeraa.slideshow;

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand All @@ -23,19 +25,19 @@ public class Slideshow {
private Path p;

private File[] folderContent;

private int imageIndex = 0;
private Timer nextTimer = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
nextImage();
}
});

private Timer updateTimer = new Timer(5000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!Arrays.equals(folderContent, p.toFile().listFiles())) {
if (!Arrays.equals(folderContent, p.toFile().listFiles())) {
nextTimer.stop();
System.out.println("Update in image folder detected. Reloading files");
loadImages(p.toFile());
Expand All @@ -49,7 +51,7 @@ public static void main(String[] args) {
}

public Slideshow(String[] args) {
if(!(args.length < 2 || args.length > 2)) {
if (!(args.length < 2 || args.length > 2)) {
try {
p = Paths.get(args[0]);
nextTimer.setDelay(Integer.parseInt(args[1]));
Expand All @@ -62,45 +64,52 @@ public Slideshow(String[] args) {
System.err.println("Error. use java -jar Slideshow.jar <path> <delay>");
System.exit(0);
}

fileTypes.clear();
for (String ext : ImageIO.getReaderFormatNames()) {
fileTypes.add(ext);
}

loadImages(p.toFile());

frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice vc = env.getDefaultScreenDevice();

frame.setUndecorated(true);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.add(imgP);

frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);

frame.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}

@Override
public void keyReleased(KeyEvent e) {
}

@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
System.out.println("Escape Pressed. Closing");
System.exit(0);
}
}
});

vc.setFullScreenWindow(frame);

nextTimer.start();
updateTimer.start();
nextImage();
}

public void nextImage() {
if(images.size() > 0) {
if(imageIndex >= images.size()) {
if (images.size() > 0) {
if (imageIndex >= images.size()) {
imageIndex = 0;
}
imgP.setImage(images.get(imageIndex));
Expand All @@ -109,7 +118,7 @@ public void nextImage() {
imgP.clearImage();
}
}

public boolean loadImages(File folder) {
images.clear();
System.out.println("Loading images...");
Expand Down

0 comments on commit 389ed88

Please sign in to comment.