mirror of
https://github.com/LucasVbr/LecteurPdfDoubleAffichage.git
synced 2026-05-13 17:11:51 +00:00
intégration des différent pop-ups dans le main
This commit is contained in:
@@ -35,5 +35,6 @@
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="pdfbox-2.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -12,6 +12,7 @@ import lecteur_pdf.menu.Menu;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* classe correspondant à l’objet Fenêtre
|
||||
@@ -75,7 +76,7 @@ public class Fenetre extends JFrame {
|
||||
*
|
||||
* @param fichier
|
||||
*/
|
||||
public void chargerPDF(File fichier) {
|
||||
public void chargerPDF(File fichier) throws IOException {
|
||||
dechargerPDF();
|
||||
|
||||
this.fichier = fichier;
|
||||
@@ -106,7 +107,7 @@ public class Fenetre extends JFrame {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void rechargerPDF(float zoom) {
|
||||
public void rechargerPDF(float zoom) throws IOException{
|
||||
dechargerPDF();
|
||||
|
||||
/* Crée le panel qui contient le document PDF */
|
||||
|
||||
@@ -46,17 +46,17 @@ public class PDF extends JPanel {
|
||||
* @param fichier Le fichier PDF que l’on veut ouvrir
|
||||
* @throws IllegalArgumentException si le fichier n’existe pas
|
||||
*/
|
||||
public PDF(File fichier) {
|
||||
try {
|
||||
public PDF(File fichier) throws IOException{
|
||||
// try {
|
||||
this.document = PDDocument.load(fichier);
|
||||
this.pages = new Page[document.getNumberOfPages()];
|
||||
this.zoom = 1.0f;
|
||||
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
this.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
// } catch (IOException e) {
|
||||
// throw new IllegalArgumentException();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,11 +10,12 @@ import lecteur_pdf.affichage.Fenetre;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Classe pour afficher le Menu "Fichier" avec ses options
|
||||
*
|
||||
@@ -185,24 +186,39 @@ public class Menu extends JMenuBar {
|
||||
*/
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
String choice = ae.getActionCommand();
|
||||
|
||||
String messageErrCorrompu = "Une erreur s'est produite dans le chargement de votre document, il a peut-être été corrompu. ";
|
||||
switch (choice) {
|
||||
case "Ouvrir" -> {
|
||||
File fichier = SelectionnerFichier.ouvrirFichier();
|
||||
if (fichier != null) {
|
||||
try {
|
||||
File fichier = SelectionnerFichier.ouvrirFichier();
|
||||
fenetre.chargerPDF(fichier);
|
||||
}catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(fenetre,messageErrCorrompu);
|
||||
}
|
||||
}
|
||||
case "Fermer" -> {
|
||||
fenetre.dechargerPDF();
|
||||
fenetre.validate();
|
||||
fenetre.setSize(300, 300);
|
||||
case "Fermer" -> popupfermer(fenetre);
|
||||
case "Quitter" -> popupquitter(fenetre);
|
||||
case "Zoom +" -> {
|
||||
try {
|
||||
fenetre.rechargerPDF(2.0f);
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(fenetre,messageErrCorrompu);
|
||||
}
|
||||
}
|
||||
case "Zoom 0" -> {
|
||||
try {
|
||||
fenetre.rechargerPDF(1.0f);
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(fenetre,messageErrCorrompu);
|
||||
}
|
||||
}
|
||||
case "Zoom -" -> {
|
||||
try {
|
||||
fenetre.rechargerPDF(0.5f);
|
||||
} catch (IOException e) {
|
||||
JOptionPane.showMessageDialog(fenetre,messageErrCorrompu);
|
||||
}
|
||||
}
|
||||
case "Quitter" -> System.exit(
|
||||
0);
|
||||
case "Zoom +" -> fenetre.rechargerPDF(2.0f);
|
||||
case "Zoom 0" -> fenetre.rechargerPDF(1.0f);
|
||||
case "Zoom -" -> fenetre.rechargerPDF(0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,4 +238,44 @@ public class Menu extends JMenuBar {
|
||||
public JMenuItem getMenuItem(int index) {
|
||||
return itemList.get(index);
|
||||
}
|
||||
|
||||
|
||||
public void popupfermer(Fenetre fenetre){
|
||||
JDialog jd = new JDialog(fenetre);
|
||||
jd.setLayout(new FlowLayout());
|
||||
jd.setBounds(500,300,400,100);
|
||||
JLabel jlabel = new JLabel("etes vous sûr de vouloir fermer ? ");
|
||||
JButton oui = new JButton("oui");
|
||||
oui.addActionListener(e -> {
|
||||
fenetre.documentPDF.removeAll();
|
||||
fenetre.documentPDF.revalidate();
|
||||
fenetre.documentPDF.repaint();
|
||||
jd.setVisible(false);
|
||||
});
|
||||
JButton non = new JButton("non");
|
||||
non.addActionListener(e -> jd.setVisible(false));
|
||||
jd.add(jlabel);
|
||||
jd.add(oui);
|
||||
jd.add(non);
|
||||
jd.setVisible(true);
|
||||
}
|
||||
|
||||
private void popupquitter(Fenetre fenetre) {
|
||||
JDialog jd = new JDialog(fenetre);
|
||||
jd.setLayout(new FlowLayout());
|
||||
jd.setBounds(500,300,400,100);
|
||||
JLabel jlabel = new JLabel("etes vous sûr de vouloir quitter ? ");
|
||||
JButton oui = new JButton("oui");
|
||||
oui.addActionListener(e -> {
|
||||
System.exit(0);
|
||||
jd.setVisible(false);
|
||||
});
|
||||
JButton non = new JButton("non");
|
||||
non.addActionListener(e -> jd.setVisible(false));
|
||||
jd.add(jlabel);
|
||||
jd.add(oui);
|
||||
jd.add(non);
|
||||
jd.setVisible(true);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,12 @@ class PDFTest {
|
||||
frame.setBackground(Color.gray);
|
||||
frame.setVisible(true);
|
||||
|
||||
PDF doc = new PDF(new File("C:/Users/public/test.pdf"));
|
||||
//PDF doc = new PDF(new File("C:/Users/public/test.pdf"));
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(doc);
|
||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
frame.add(scrollPane);
|
||||
//JScrollPane scrollPane = new JScrollPane(doc);
|
||||
//scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
//scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
//frame.add(scrollPane);
|
||||
frame.validate();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user