diff --git a/DEV/DEV3.1/TP02/.DS_Store b/DEV/DEV3.1/TP02/.DS_Store new file mode 100644 index 0000000..cc2a19f Binary files /dev/null and b/DEV/DEV3.1/TP02/.DS_Store differ diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java deleted file mode 100644 index 998a2ee..0000000 --- a/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java +++ /dev/null @@ -1,5 +0,0 @@ -package Part2; - -public class ClickSwapImageEvent { - -} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java b/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java deleted file mode 100644 index b210479..0000000 --- a/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java +++ /dev/null @@ -1,26 +0,0 @@ -import java.io.File; - -import java.awt.CardLayout; - -import javax.swing.ImageIcon; -import javax.swing.JFrame; - -public class ImageWindow extends JFrame { - - private CardLayout card; - - public ImageWindow() { - this.card = new CardLayout(); - - File resourcesDirectory = new File("../resources/"); - - if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) { - File[] files = resourcesDirectory.listFiles(); - - if(files != null) { - for(File file : files) { - } - } - } - } -} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java b/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java deleted file mode 100644 index 57f8e1d..0000000 --- a/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java +++ /dev/null @@ -1,5 +0,0 @@ -package Part2; - -public class Main { - -} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Part1/ClickSwapImageEvent.java similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java rename to DEV/DEV3.1/TP02/Part1/ClickSwapImageEvent.java diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java b/DEV/DEV3.1/TP02/Part1/ImageWindow.java similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java rename to DEV/DEV3.1/TP02/Part1/ImageWindow.java diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/Main.java b/DEV/DEV3.1/TP02/Part1/Main.java similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/Part1/Main.java rename to DEV/DEV3.1/TP02/Part1/Main.java diff --git a/DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java b/DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java new file mode 100644 index 0000000..3fc07a4 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java @@ -0,0 +1,19 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JDialog; + +public class ApprovedButtonPressedEvent implements ActionListener{ + + private JDialog dialog; + + public ApprovedButtonPressedEvent(JDialog dialog) { + this.dialog = dialog; + } + + @Override + public void actionPerformed(ActionEvent event) { + this.dialog.dispose(); + this.dialog.getOwner().dispose(); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java b/DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java new file mode 100644 index 0000000..d33ae82 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java @@ -0,0 +1,18 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JDialog; + +public class CancelButtonPressedEvent implements ActionListener{ + + private JDialog dialog; + + public CancelButtonPressedEvent(JDialog dialog) { + this.dialog = dialog; + } + + @Override + public void actionPerformed(ActionEvent event) { + this.dialog.dispose(); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java new file mode 100644 index 0000000..09c8cb8 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java @@ -0,0 +1,20 @@ +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class ClickSwapImageEvent extends MouseAdapter { + + private ImageWindow window; + + public ClickSwapImageEvent(ImageWindow window) { + this.window = window; + } + + public void mouseClicked(MouseEvent event) { + if(event.getX() > this.window.getWidth() / 2) { + this.window.nextImage(); + return; + } + + this.window.lastImage(); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java b/DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java new file mode 100644 index 0000000..96dce6d --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java @@ -0,0 +1,37 @@ +import java.awt.BorderLayout; +import java.awt.GridLayout; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class CloseVerificationWindow extends JDialog { + + public CloseVerificationWindow(ImageWindow parent) { + super(parent, true); + + this.setSize(parent.getWidth() / 3, parent.getHeight() / 3); + this.setLocationRelativeTo(parent); + this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + this.setLayout(new GridLayout(2, 1)); + + JLabel text = new JLabel("Are you sure you want to close the window?"); + text.setVerticalAlignment(JLabel.CENTER); + text.setHorizontalAlignment(JLabel.CENTER); + this.add(text); + + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JButton approveButton = new JButton("Yes"); + approveButton.addActionListener(new ApprovedButtonPressedEvent(this)); + panel.add(approveButton, BorderLayout.WEST); + + JButton cancelButton = new JButton("No"); + cancelButton.addActionListener(new CancelButtonPressedEvent(this)); + panel.add(cancelButton, BorderLayout.EAST); + + this.add(panel); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/ImageWindow.java b/DEV/DEV3.1/TP02/Part2/ImageWindow.java new file mode 100644 index 0000000..cb766f5 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/ImageWindow.java @@ -0,0 +1,55 @@ +import java.io.File; + +import java.awt.CardLayout; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class ImageWindow extends JFrame { + + private CardLayout cards; + private JPanel imagePanel; + + public ImageWindow() { + this.setSize(1024, 1024); + this.setLocationRelativeTo(null); + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + File resourcesDirectory = new File("../resources/"); + + if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) { + File[] files = resourcesDirectory.listFiles(); + + if(files != null) { + + this.cards = new CardLayout(); + this.imagePanel = new JPanel(); + this.imagePanel.setLayout(this.cards); + + for(File file : files) { + JLabel label = new JLabel(new ImageIcon(file.getPath())); + label.setHorizontalAlignment(JLabel.CENTER); + label.setVerticalAlignment(JLabel.CENTER); + this.imagePanel.add(new JLabel(new ImageIcon(file.getPath())), file.getName()); + } + + this.add(this.imagePanel); + + this.addMouseListener(new ClickSwapImageEvent(this)); + this.addWindowListener(new WindowClosedEvent(this)); + + this.nextImage(); + } + } + } + + public void nextImage() { + this.cards.next(this.imagePanel); + } + + public void lastImage() { + this.cards.previous(this.imagePanel); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/Main.java b/DEV/DEV3.1/TP02/Part2/Main.java new file mode 100644 index 0000000..6f93356 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/Main.java @@ -0,0 +1,6 @@ +public class Main { + public static void main(String[] args) { + ImageWindow window = new ImageWindow(); + window.setVisible(true); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java b/DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java new file mode 100644 index 0000000..87ffb18 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java @@ -0,0 +1,16 @@ +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +public class WindowClosedEvent extends WindowAdapter { + + private ImageWindow window; + + public WindowClosedEvent(ImageWindow window) { + this.window = window; + } + + @Override + public void windowClosing(WindowEvent event) { + (new CloseVerificationWindow(this.window)).setVisible(true); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/start.sh b/DEV/DEV3.1/TP02/Part2/start.sh new file mode 100755 index 0000000..d50086b --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/start.sh @@ -0,0 +1,3 @@ +rm -rf *.class +javac Main.java +java Main \ No newline at end of file diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg b/DEV/DEV3.1/TP02/resources/dice.jpg similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg rename to DEV/DEV3.1/TP02/resources/dice.jpg diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/frog.png b/DEV/DEV3.1/TP02/resources/frog.png similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/resources/frog.png rename to DEV/DEV3.1/TP02/resources/frog.png diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/random.jpg b/DEV/DEV3.1/TP02/resources/random.jpg similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/resources/random.jpg rename to DEV/DEV3.1/TP02/resources/random.jpg