2026-01-05 10:19:59 +01:00
|
|
|
|
package fr.iutfbleau.sae;
|
2026-01-07 19:27:03 +01:00
|
|
|
|
|
2026-01-05 10:19:59 +01:00
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Fenêtre principale du convertisseur.
|
2026-01-07 19:27:03 +01:00
|
|
|
|
* Cette classe affiche l'image chargée, les tables de fréquences,
|
|
|
|
|
|
* les codes Huffman et les codes canoniques.
|
|
|
|
|
|
* C'est la partie "Vue" de l'application.
|
2026-01-05 10:19:59 +01:00
|
|
|
|
*/
|
|
|
|
|
|
public class ConverterWindow extends JFrame {
|
|
|
|
|
|
|
|
|
|
|
|
private ImagePreviewPanel imagePreviewPanel;
|
|
|
|
|
|
private FrequencyTablePanel frequencyTablePanel;
|
|
|
|
|
|
private CodeTablePanel codeTablePanel;
|
2026-01-07 20:30:37 +01:00
|
|
|
|
private JPanel bottomPanel;
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-07 19:27:03 +01:00
|
|
|
|
* Constructeur de la fenêtre du convertisseur.
|
|
|
|
|
|
* Initialise la fenêtre et installe tous les panneaux graphiques.
|
2026-01-05 10:19:59 +01:00
|
|
|
|
*/
|
|
|
|
|
|
public ConverterWindow() {
|
|
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
setTitle("Convertisseur PIF - Visualisation des données");
|
|
|
|
|
|
setSize(900, 600);
|
|
|
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
|
|
setLocationRelativeTo(null);
|
|
|
|
|
|
setResizable(true);
|
|
|
|
|
|
setLayout(new BorderLayout());
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
// Création des panneaux d'affichage
|
|
|
|
|
|
imagePreviewPanel = new ImagePreviewPanel();
|
|
|
|
|
|
frequencyTablePanel = new FrequencyTablePanel();
|
|
|
|
|
|
codeTablePanel = new CodeTablePanel();
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
// Panneau principal avec un scroll
|
|
|
|
|
|
JPanel contentPanel = new JPanel(new BorderLayout());
|
2026-01-05 10:19:59 +01:00
|
|
|
|
contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
|
|
|
|
|
|
|
|
|
|
|
JLabel header = new JLabel(" Convertisseur PIF – Visualisation des données ");
|
|
|
|
|
|
header.setFont(new Font("SansSerif", Font.BOLD, 18));
|
2026-01-07 19:27:03 +01:00
|
|
|
|
header.setHorizontalAlignment(SwingConstants.CENTER);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
contentPanel.add(header, BorderLayout.NORTH);
|
|
|
|
|
|
contentPanel.add(imagePreviewPanel, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
|
|
// Les tables en bas
|
|
|
|
|
|
JPanel tablesPanel = new JPanel();
|
|
|
|
|
|
tablesPanel.setLayout(new BoxLayout(tablesPanel, BoxLayout.Y_AXIS));
|
|
|
|
|
|
tablesPanel.add(frequencyTablePanel);
|
|
|
|
|
|
tablesPanel.add(Box.createRigidArea(new Dimension(0, 5)));
|
|
|
|
|
|
tablesPanel.add(codeTablePanel);
|
|
|
|
|
|
|
|
|
|
|
|
contentPanel.add(tablesPanel, BorderLayout.SOUTH);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
|
|
|
|
|
JScrollPane scrollPane = new JScrollPane(contentPanel);
|
|
|
|
|
|
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
|
|
|
|
|
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
2026-01-07 19:27:03 +01:00
|
|
|
|
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
add(scrollPane, BorderLayout.CENTER);
|
|
|
|
|
|
|
|
|
|
|
|
// Fenêtre visible immédiatement
|
|
|
|
|
|
setVisible(true);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-07 19:27:03 +01:00
|
|
|
|
* Affiche l'image chargée dans le panneau d'aperçu.
|
|
|
|
|
|
* @param img l'image à afficher
|
2026-01-05 10:19:59 +01:00
|
|
|
|
*/
|
|
|
|
|
|
public void setImagePreview(BufferedImage img) {
|
|
|
|
|
|
imagePreviewPanel.setImage(img);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-07 19:27:03 +01:00
|
|
|
|
* Met à jour l'affichage des fréquences des trois composantes.
|
2026-01-05 10:19:59 +01:00
|
|
|
|
*/
|
2026-01-07 19:27:03 +01:00
|
|
|
|
public void setFrequencyTable(int[] freqR, int[] freqG, int[] freqB) {
|
|
|
|
|
|
frequencyTablePanel.updateFrequencies(freqR, freqG, freqB);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-07 19:27:03 +01:00
|
|
|
|
* Met à jour l'affichage des codes Huffman.
|
2026-01-05 10:19:59 +01:00
|
|
|
|
*/
|
2026-01-07 19:27:03 +01:00
|
|
|
|
public void setHuffmanTable(Map<Integer, String> r,
|
|
|
|
|
|
Map<Integer, String> g,
|
|
|
|
|
|
Map<Integer, String> b) {
|
|
|
|
|
|
codeTablePanel.updateCodes(r, g, b);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-07 19:27:03 +01:00
|
|
|
|
* Met à jour l'affichage des codes canoniques.
|
2026-01-05 10:19:59 +01:00
|
|
|
|
*/
|
2026-01-07 19:27:03 +01:00
|
|
|
|
public void setCanonicalTable(Map<Integer, String> r,
|
|
|
|
|
|
Map<Integer, String> g,
|
|
|
|
|
|
Map<Integer, String> b) {
|
|
|
|
|
|
codeTablePanel.updateCanonicalCodes(r, g, b);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Ajoute un bouton permettant d'exporter l'image en .pif.
|
|
|
|
|
|
* Le contrôleur est envoyé au listener responsable de la sauvegarde.
|
|
|
|
|
|
*/
|
2026-01-05 10:19:59 +01:00
|
|
|
|
public void addSaveButton(ConverterController controller) {
|
|
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
JButton saveBtn = new JButton("Exporter en .pif");
|
|
|
|
|
|
ExportButtonListener listener = new ExportButtonListener(controller);
|
|
|
|
|
|
saveBtn.addActionListener(listener);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
2026-01-07 20:30:37 +01:00
|
|
|
|
this.bottomPanel = new JPanel();
|
2026-01-07 19:27:03 +01:00
|
|
|
|
bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
|
|
|
|
|
|
bottomPanel.add(saveBtn);
|
2026-01-05 10:19:59 +01:00
|
|
|
|
|
2026-01-07 19:27:03 +01:00
|
|
|
|
add(bottomPanel, BorderLayout.SOUTH);
|
|
|
|
|
|
|
|
|
|
|
|
revalidate();
|
|
|
|
|
|
repaint();
|
|
|
|
|
|
}
|
2026-01-07 20:30:37 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Retire le bouton d'export apres la sauvegarde.
|
|
|
|
|
|
* Utilise dans le cas ou un chemin de sortie est fourni en argument.
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void removeSaveButton() {
|
|
|
|
|
|
if (bottomPanel != null) {
|
|
|
|
|
|
remove(bottomPanel);
|
|
|
|
|
|
bottomPanel = null;
|
|
|
|
|
|
revalidate();
|
|
|
|
|
|
repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-05 10:19:59 +01:00
|
|
|
|
}
|