mirror of
https://github.com/LucasVbr/LecteurPdfDoubleAffichage.git
synced 2026-07-09 12:47:45 +00:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -23,52 +23,49 @@ import java.io.IOException;
|
|||||||
* @author Noé VILLENEUVE
|
* @author Noé VILLENEUVE
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Fenetre extends JFrame {
|
public class Fenetre extends JFrame {
|
||||||
|
|
||||||
/**
|
/** Titre de la fenêtre */
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
private final String TITRE = "Lecteur PDF";
|
private final String TITRE = "Lecteur PDF";
|
||||||
|
|
||||||
/**
|
/** Le menu de la fenêtre */
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
private Menu menu;
|
private Menu menu;
|
||||||
|
|
||||||
/**
|
/** Le fichier courant */
|
||||||
* TODO
|
|
||||||
*/
|
|
||||||
private File fichier;
|
private File fichier;
|
||||||
|
|
||||||
|
/** Le document PDF courant */
|
||||||
public PDF documentPDF;
|
public PDF documentPDF;
|
||||||
|
|
||||||
|
/** Défini la disposition d'affichage des pages du document PDF */
|
||||||
private boolean affichageVertical;
|
private boolean affichageVertical;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Crée une nouvelle fenêtre contenant un Menu
|
||||||
*/
|
*/
|
||||||
public Fenetre() {
|
public Fenetre() {
|
||||||
|
|
||||||
/* Change le style de la fenêtre */
|
/* Change le style de la fenêtre */
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
} catch (ClassNotFoundException
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
||||||
| InstantiationException
|
|
||||||
| IllegalAccessException
|
|
||||||
| UnsupportedLookAndFeelException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Création du menu
|
/* Création du menu */
|
||||||
menu = new Menu(this);
|
menu = new Menu(this);
|
||||||
this.setJMenuBar(menu);
|
this.setJMenuBar(menu);
|
||||||
|
|
||||||
|
/* Definis l'affichage Vertical comme affichage par défaut */
|
||||||
this.affichageVertical = true;
|
this.affichageVertical = true;
|
||||||
|
|
||||||
|
/* Initialise l'état par défaut de la fenêtre */
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fonction utilitaire qui permet de définir l'état par défaut de la fenêtre
|
||||||
|
*/
|
||||||
public void setup() {
|
public void setup() {
|
||||||
setTitle(TITRE);
|
setTitle(TITRE);
|
||||||
|
|
||||||
@@ -83,11 +80,42 @@ public class Fenetre extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* Charge le document PDF courant si possible
|
||||||
*
|
*
|
||||||
* @param fichier
|
* @throws IOException Si l'on arrive pas a charger le PDF
|
||||||
|
*/
|
||||||
|
public void chargerPDF() throws IOException {
|
||||||
|
if (haveDocument()) chargerPDF(fichier, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charge le document PDF courant avec un zoom spécifique si possible
|
||||||
|
*
|
||||||
|
* @param zoom La taille du zoom sur les pages
|
||||||
|
* @throws IOException Si l'on arrive pas a charger le PDF
|
||||||
|
*/
|
||||||
|
public void chargerPDF(float zoom) throws IOException {
|
||||||
|
if (haveDocument()) chargerPDF(fichier, zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charge un document PDF
|
||||||
|
*
|
||||||
|
* @param fichier Le fichier PDF à afficher dans la fenêtre
|
||||||
|
* @throws IOException Si l'on arrive pas a charger le PDF
|
||||||
*/
|
*/
|
||||||
public void chargerPDF(File fichier) throws IOException {
|
public void chargerPDF(File fichier) throws IOException {
|
||||||
|
chargerPDF(fichier, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charge un document PDF
|
||||||
|
*
|
||||||
|
* @param fichier Le fichier PDF à afficher dans la fenêtre
|
||||||
|
* @param zoom La taille du zoom sur les pages
|
||||||
|
* @throws IOException Si l'on arrive pas a charger le PDF
|
||||||
|
*/
|
||||||
|
public void chargerPDF(File fichier, float zoom) throws IOException {
|
||||||
dechargerPDF();
|
dechargerPDF();
|
||||||
|
|
||||||
this.fichier = fichier;
|
this.fichier = fichier;
|
||||||
@@ -100,50 +128,10 @@ public class Fenetre extends JFrame {
|
|||||||
scrollPane.getHorizontalScrollBar().setUnitIncrement(16);
|
scrollPane.getHorizontalScrollBar().setUnitIncrement(16);
|
||||||
this.add(scrollPane, BorderLayout.CENTER);
|
this.add(scrollPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
documentPDF = new PDF(fichier, affichageVertical);
|
|
||||||
pdfPanel.add(documentPDF);
|
|
||||||
|
|
||||||
/* Charge les pages */
|
|
||||||
documentPDF.loadPages();
|
|
||||||
|
|
||||||
/* Met à jour la page */
|
|
||||||
this.setTitle(TITRE + " | " + fichier.getName());
|
|
||||||
this.validate();
|
|
||||||
this.pack();
|
|
||||||
this.setLocationRelativeTo(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void rechargerPDF() throws IOException {
|
|
||||||
rechargerPDF(1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param zoom
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void rechargerPDF(float zoom) throws IOException {
|
|
||||||
dechargerPDF();
|
|
||||||
|
|
||||||
/* Crée le panel qui contient le document PDF */
|
|
||||||
JPanel pdfPanel = new JPanel();
|
|
||||||
/* Crée l’élément scrollable */
|
|
||||||
JScrollPane scrollPane = new JScrollPane(pdfPanel);
|
|
||||||
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
|
|
||||||
scrollPane.getHorizontalScrollBar().setUnitIncrement(16);
|
|
||||||
this.add(scrollPane);
|
|
||||||
|
|
||||||
documentPDF = new PDF(fichier, affichageVertical);
|
documentPDF = new PDF(fichier, affichageVertical);
|
||||||
documentPDF.setZoom(zoom);
|
documentPDF.setZoom(zoom);
|
||||||
pdfPanel.add(documentPDF);
|
pdfPanel.add(documentPDF);
|
||||||
|
|
||||||
/* Charge les pages */
|
|
||||||
documentPDF.loadPages();
|
|
||||||
|
|
||||||
/* Met à jour la page */
|
/* Met à jour la page */
|
||||||
this.setTitle(TITRE + " | " + fichier.getName());
|
this.setTitle(TITRE + " | " + fichier.getName());
|
||||||
this.validate();
|
this.validate();
|
||||||
@@ -152,7 +140,7 @@ public class Fenetre extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Supprime le PDF de la fenêtre
|
||||||
*/
|
*/
|
||||||
public void dechargerPDF() {
|
public void dechargerPDF() {
|
||||||
if (this.getContentPane() != null) {
|
if (this.getContentPane() != null) {
|
||||||
@@ -161,24 +149,22 @@ public class Fenetre extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prédicat qui vérifie si un PDF est affiché dans la fenêtre
|
||||||
|
*
|
||||||
|
* @return true si le prédicat est vérifié, false sinon
|
||||||
|
*/
|
||||||
public boolean haveDocument() {
|
public boolean haveDocument() {
|
||||||
return documentPDF != null;
|
return documentPDF != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Définis le mode d'affichage du PDF
|
||||||
|
*
|
||||||
|
* @param affichageVertical true pour un affichage Vertical, false pour
|
||||||
|
* un affichage horizontal
|
||||||
|
*/
|
||||||
public void setAffichageVertical(boolean affichageVertical) {
|
public void setAffichageVertical(boolean affichageVertical) {
|
||||||
this.affichageVertical = affichageVertical;
|
this.affichageVertical = affichageVertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAffichageVertical() {
|
|
||||||
return affichageVertical;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO comment main
|
|
||||||
*
|
|
||||||
* @param args non utilisé
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new Fenetre();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,58 +1,48 @@
|
|||||||
/*
|
///*
|
||||||
* gestionFenetre, 22/11/2021
|
// * gestionFenetre, 22/11/2021
|
||||||
* IUT Rodez 2021, INFO2
|
// * IUT Rodez 2021, INFO2
|
||||||
* pas de copyright, aucun droits
|
// * pas de copyright, aucun droits
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
package lecteur_pdf.affichage;
|
//package lecteur_pdf.affichage;
|
||||||
|
//
|
||||||
import lecteur_pdf.document.PDF;
|
//import javax.swing.*;
|
||||||
import lecteur_pdf.menu.Menu;
|
//import java.io.File;
|
||||||
|
//
|
||||||
import javax.swing.*;
|
///**
|
||||||
import java.io.File;
|
// * classe de gestion des fenêtres
|
||||||
import java.io.IOException;
|
// *
|
||||||
import java.util.ArrayList;
|
// * @author Léo FRANCH
|
||||||
|
// * @author Tristan NOGARET
|
||||||
/**
|
// * @author Lucàs VABRE
|
||||||
* classe de gestion des fenêtres
|
// * @author Noé VILLENEUVE
|
||||||
*
|
// * @version 1.0
|
||||||
* @author Léo FRANCH
|
// */
|
||||||
* @author Tristan NOGARET
|
//public class gestionFenetre {
|
||||||
* @author Lucàs VABRE
|
//
|
||||||
* @author Noé VILLENEUVE
|
// final int NB_MAX_FENETRE = 2 ;
|
||||||
* @version 1.0
|
// private Fenetre[] fenetresOuvertes;
|
||||||
*/
|
// File fichier = null ;
|
||||||
public class gestionFenetre {
|
//
|
||||||
|
//
|
||||||
|
// public void ouvrirFenetre(){
|
||||||
final int NB_MAX_FENETRE = 2 ;
|
// int placeVide;
|
||||||
private Fenetre[] fenetresOuvertes;
|
// for (placeVide=0; placeVide<2; placeVide++){
|
||||||
File fichier = null ;
|
// if (fenetresOuvertes[placeVide] == null) break;
|
||||||
|
// }
|
||||||
|
// if(placeVide==2) {
|
||||||
public void ouvrirFenetre(){
|
// //todo erreur trop de fenetres
|
||||||
int placeVide;
|
// }else {
|
||||||
for (placeVide=0; placeVide<2; placeVide++){
|
// Fenetre fenetre = new Fenetre();
|
||||||
if (fenetresOuvertes[placeVide]==null){
|
// fenetresOuvertes[placeVide] = fenetre;
|
||||||
break;
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// public void fermerFenetre(JFrame fenetre){
|
||||||
if(placeVide==2) {
|
// for (int i = 0; i<2 ; i++){
|
||||||
//todo erreur trop de fenetres
|
// if (fenetre==fenetresOuvertes[i]){
|
||||||
}else {
|
// fenetre.dispose();
|
||||||
Fenetre fenetre = new Fenetre();
|
// fenetresOuvertes[i]= null ;
|
||||||
fenetresOuvertes[placeVide] = fenetre;
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
public void fermerFenetre(JFrame fenetre){
|
//}
|
||||||
for (int i = 0; i<2 ; i++){
|
|
||||||
if (fenetre==fenetresOuvertes[i]){
|
|
||||||
fenetre.dispose();
|
|
||||||
fenetresOuvertes[i]= null ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,27 +23,19 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class PDF extends JPanel {
|
public class PDF extends JPanel {
|
||||||
|
|
||||||
/**
|
/** Document chargé */
|
||||||
* Espacement entre chaque page
|
|
||||||
*/
|
|
||||||
public static final int OFFSET_PAGES = 10; // px
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Document PDF chargé
|
|
||||||
*/
|
|
||||||
private final PDDocument document;
|
private final PDDocument document;
|
||||||
|
|
||||||
/**
|
/** Les pages chargés */
|
||||||
* Les pages du PDF sous forme de JLabel contenant des images
|
|
||||||
*/
|
|
||||||
private final Page[] pages;
|
private final Page[] pages;
|
||||||
|
|
||||||
|
/** Le zoom des pages du document */
|
||||||
private float zoom;
|
private float zoom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crée un document PDF qui est capable d’être affiché dans une fenêtre
|
* Crée un document PDF affichable dans une fenêtre
|
||||||
*
|
*
|
||||||
* @param fichier Le fichier PDF que l’on veut ouvrir
|
* @param fichier Le fichier 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, boolean vertical) throws IOException {
|
public PDF(File fichier, boolean vertical) throws IOException {
|
||||||
@@ -67,18 +59,15 @@ public class PDF extends JPanel {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("PDF: Loaded successfully");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Le nombre de pages chargées
|
* Défini le zoom des pages du document
|
||||||
|
*
|
||||||
|
* @param zoom la nouvelle valeur du zoom (1.0f == 100%)
|
||||||
*/
|
*/
|
||||||
public int getNbPages() {
|
|
||||||
return document.getNumberOfPages();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZoom(float zoom) {
|
public void setZoom(float zoom) {
|
||||||
this.zoom = zoom;
|
this.zoom = zoom;
|
||||||
|
loadPages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,6 @@ public class Page extends JLabel {
|
|||||||
/** Zoom de la page (1.0f == 100 %, 0.5 == 50%, ...) */
|
/** Zoom de la page (1.0f == 100 %, 0.5 == 50%, ...) */
|
||||||
private final float ZOOM;
|
private final float ZOOM;
|
||||||
|
|
||||||
/** Hauteur de la page */
|
|
||||||
private int hauteur;
|
|
||||||
|
|
||||||
/** Largeur de la page */
|
|
||||||
private int largeur;
|
|
||||||
|
|
||||||
/** Image de la page générée */
|
/** Image de la page générée */
|
||||||
private final ImageIcon IMAGE_ICON;
|
private final ImageIcon IMAGE_ICON;
|
||||||
|
|
||||||
@@ -74,15 +68,13 @@ public class Page extends JLabel {
|
|||||||
public Page(PDDocument document, int index, float zoom) throws
|
public Page(PDDocument document, int index, float zoom) throws
|
||||||
IllegalArgumentException,
|
IllegalArgumentException,
|
||||||
IOException {
|
IOException {
|
||||||
if (!isValid(document, index)) {
|
if (!isValid(document, index)) throw new IllegalArgumentException();
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.INDEX = index;
|
this.INDEX = index;
|
||||||
this.ZOOM = zoom;
|
this.ZOOM = zoom;
|
||||||
this.IMAGE_ICON = generateImage(document);
|
this.IMAGE_ICON = generateImage(document); // Génère la page
|
||||||
|
|
||||||
/* Render */
|
/* Fait le rendu de la page */
|
||||||
this.setIcon(IMAGE_ICON);
|
this.setIcon(IMAGE_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,30 +101,20 @@ public class Page extends JLabel {
|
|||||||
*/
|
*/
|
||||||
private ImageIcon generateImage(PDDocument document) throws IOException {
|
private ImageIcon generateImage(PDDocument document) throws IOException {
|
||||||
|
|
||||||
|
/* Défini la qualité de l’image par rapport au zoom */
|
||||||
final int DPI = 120;
|
final int DPI = 120;
|
||||||
int imageScale = (ZOOM > 1.0f) ? Image.SCALE_SMOOTH : Image.SCALE_FAST;
|
int imageScale = (ZOOM > 1.0f) ? Image.SCALE_SMOOTH : Image.SCALE_FAST;
|
||||||
|
|
||||||
|
/* Crée une image de la page à afficher */
|
||||||
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
||||||
BufferedImage bufferedImage = pdfRenderer.renderImageWithDPI(INDEX, DPI);
|
BufferedImage bufferedImage = pdfRenderer.renderImageWithDPI(INDEX, DPI);
|
||||||
|
|
||||||
this.largeur = (int)(bufferedImage.getWidth() * ZOOM);
|
/* Redimensionne l'image */
|
||||||
this.hauteur = (int)(bufferedImage.getHeight() * ZOOM);
|
final int LARGEUR = (int)(bufferedImage.getWidth() * ZOOM);
|
||||||
|
final int HAUTEUR = (int)(bufferedImage.getHeight() * ZOOM);
|
||||||
|
|
||||||
return new ImageIcon(bufferedImage.getScaledInstance(largeur, hauteur,
|
/* Retourne l’image à la bonne taille */
|
||||||
|
return new ImageIcon(bufferedImage.getScaledInstance(LARGEUR, HAUTEUR,
|
||||||
imageScale));
|
imageScale));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return La hauteur de la page
|
|
||||||
*/
|
|
||||||
public int getHauteur() {
|
|
||||||
return hauteur;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return La largeur de la page
|
|
||||||
*/
|
|
||||||
public int getLargeur() {
|
|
||||||
return largeur;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,21 +239,21 @@ public class Menu extends JMenuBar {
|
|||||||
}
|
}
|
||||||
case "Zoom 150%" -> {
|
case "Zoom 150%" -> {
|
||||||
try {
|
try {
|
||||||
FENETRE.rechargerPDF(2.0f);
|
FENETRE.chargerPDF(2.0f);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "Zoom 100%" -> {
|
case "Zoom 100%" -> {
|
||||||
try {
|
try {
|
||||||
FENETRE.rechargerPDF(1.0f);
|
FENETRE.chargerPDF(1.0f);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "Zoom 50%" -> {
|
case "Zoom 50%" -> {
|
||||||
try {
|
try {
|
||||||
FENETRE.rechargerPDF(0.5f);
|
FENETRE.chargerPDF(0.5f);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ public class Menu extends JMenuBar {
|
|||||||
if (FENETRE.haveDocument()) {
|
if (FENETRE.haveDocument()) {
|
||||||
FENETRE.setAffichageVertical(true);
|
FENETRE.setAffichageVertical(true);
|
||||||
try {
|
try {
|
||||||
FENETRE.rechargerPDF();
|
FENETRE.chargerPDF();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ public class Menu extends JMenuBar {
|
|||||||
if (FENETRE.haveDocument()) {
|
if (FENETRE.haveDocument()) {
|
||||||
FENETRE.setAffichageVertical(false);
|
FENETRE.setAffichageVertical(false);
|
||||||
try {
|
try {
|
||||||
FENETRE.rechargerPDF();
|
FENETRE.chargerPDF();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
JOptionPane.showMessageDialog(FENETRE, messageErrCorrompu);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package lecteur_pdf.affichage;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class FenetreTest {
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lance les methodes de tests
|
||||||
|
*
|
||||||
|
* @param args non utilisé
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Fenetre();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,33 +1,14 @@
|
|||||||
package lecteur_pdf.document;
|
package lecteur_pdf.document;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
class PDFTest {
|
class PDFTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO comment main
|
* Lance les methodes de tests
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args non utilisé
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame frame = new JFrame();
|
// TODO
|
||||||
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setLocationRelativeTo(null);
|
|
||||||
|
|
||||||
frame.setSize(300,300);
|
|
||||||
frame.setBackground(Color.gray);
|
|
||||||
frame.setVisible(true);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
frame.validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,32 +3,49 @@ package lecteur_pdf.document;
|
|||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
class PageTest {
|
class PageTest {
|
||||||
|
|
||||||
|
public static void testPage() {
|
||||||
|
try {
|
||||||
|
PDDocument document = PDDocument.load(
|
||||||
|
new File("Documents_PDF/paysage_35pages.pdf"));
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.add(new Page(document, 0, 1.0f));
|
||||||
|
frame.pack();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void testPageZoom() {
|
||||||
|
try {
|
||||||
|
PDDocument document = PDDocument.load(
|
||||||
|
new File("Documents_PDF/paysage_35pages.pdf"));
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.add(new Page(document, 0, 2.0f));
|
||||||
|
frame.pack();
|
||||||
|
|
||||||
|
JFrame frame2 = new JFrame();
|
||||||
|
frame2.setVisible(true);
|
||||||
|
frame2.add(new Page(document, 0, 0.5f));
|
||||||
|
frame2.pack();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test du constructeur {@link Page#Page(PDDocument, int)}
|
* Lance les methodes de tests
|
||||||
*
|
*
|
||||||
* @param args non utilisé
|
* @param args non utilisé
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) {
|
||||||
/* Mise en place du JFrame de test */
|
testPage();
|
||||||
JFrame frame = new JFrame();
|
testPageZoom();
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setLocationRelativeTo(null);
|
|
||||||
frame.setSize(300, 300);
|
|
||||||
frame.setBackground(Color.gray);
|
|
||||||
frame.setVisible(true);
|
|
||||||
|
|
||||||
/* Creation de l’objet Page */
|
|
||||||
PDDocument document = PDDocument.load(new File("F:/paysage_35pages.pdf"));
|
|
||||||
Page page = new Page(document, 0);
|
|
||||||
|
|
||||||
/* Ajout de l’objet dans la frame et mise à jour de la frame */
|
|
||||||
// frame.add(page);
|
|
||||||
frame.validate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user