mirror of
https://github.com/LucasVbr/LecteurPdfDoubleAffichage.git
synced 2026-07-09 12:47:45 +00:00
intégration des différent pop-ups dans le main
This commit is contained in:
@@ -35,5 +35,6 @@
|
|||||||
<SOURCES />
|
<SOURCES />
|
||||||
</library>
|
</library>
|
||||||
</orderEntry>
|
</orderEntry>
|
||||||
|
<orderEntry type="library" name="pdfbox-2.0" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -12,6 +12,7 @@ import lecteur_pdf.menu.Menu;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* classe correspondant à l’objet Fenêtre
|
* classe correspondant à l’objet Fenêtre
|
||||||
@@ -75,7 +76,7 @@ public class Fenetre extends JFrame {
|
|||||||
*
|
*
|
||||||
* @param fichier
|
* @param fichier
|
||||||
*/
|
*/
|
||||||
public void chargerPDF(File fichier) {
|
public void chargerPDF(File fichier) throws IOException {
|
||||||
dechargerPDF();
|
dechargerPDF();
|
||||||
|
|
||||||
this.fichier = fichier;
|
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();
|
dechargerPDF();
|
||||||
|
|
||||||
/* Crée le panel qui contient le document PDF */
|
/* 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
|
* @param fichier Le fichier PDF que l’on veut ouvrir
|
||||||
* @throws IllegalArgumentException si le fichier n’existe pas
|
* @throws IllegalArgumentException si le fichier n’existe pas
|
||||||
*/
|
*/
|
||||||
public PDF(File fichier) {
|
public PDF(File fichier) throws IOException{
|
||||||
try {
|
// try {
|
||||||
this.document = PDDocument.load(fichier);
|
this.document = PDDocument.load(fichier);
|
||||||
this.pages = new Page[document.getNumberOfPages()];
|
this.pages = new Page[document.getNumberOfPages()];
|
||||||
this.zoom = 1.0f;
|
this.zoom = 1.0f;
|
||||||
|
|
||||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||||
this.setAlignmentX(Component.CENTER_ALIGNMENT);
|
this.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
} catch (IOException e) {
|
// } catch (IOException e) {
|
||||||
throw new IllegalArgumentException();
|
// throw new IllegalArgumentException();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import lecteur_pdf.affichage.Fenetre;
|
|||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe pour afficher le Menu "Fichier" avec ses options
|
* Classe pour afficher le Menu "Fichier" avec ses options
|
||||||
*
|
*
|
||||||
@@ -185,24 +186,39 @@ public class Menu extends JMenuBar {
|
|||||||
*/
|
*/
|
||||||
public void actionPerformed(ActionEvent ae) {
|
public void actionPerformed(ActionEvent ae) {
|
||||||
String choice = ae.getActionCommand();
|
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) {
|
switch (choice) {
|
||||||
case "Ouvrir" -> {
|
case "Ouvrir" -> {
|
||||||
|
try {
|
||||||
File fichier = SelectionnerFichier.ouvrirFichier();
|
File fichier = SelectionnerFichier.ouvrirFichier();
|
||||||
if (fichier != null) {
|
|
||||||
fenetre.chargerPDF(fichier);
|
fenetre.chargerPDF(fichier);
|
||||||
|
}catch (IOException e) {
|
||||||
|
JOptionPane.showMessageDialog(fenetre,messageErrCorrompu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "Fermer" -> {
|
case "Fermer" -> popupfermer(fenetre);
|
||||||
fenetre.dechargerPDF();
|
case "Quitter" -> popupquitter(fenetre);
|
||||||
fenetre.validate();
|
case "Zoom +" -> {
|
||||||
fenetre.setSize(300, 300);
|
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) {
|
public JMenuItem getMenuItem(int index) {
|
||||||
return itemList.get(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.setBackground(Color.gray);
|
||||||
frame.setVisible(true);
|
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);
|
//JScrollPane scrollPane = new JScrollPane(doc);
|
||||||
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
//scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
//scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||||
frame.add(scrollPane);
|
//frame.add(scrollPane);
|
||||||
frame.validate();
|
frame.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user