296 lines
9.9 KiB
Java
296 lines
9.9 KiB
Java
package ui.implementation.components.nav;
|
|
|
|
import domain.image.GrayScaleMatrix;
|
|
import domain.image.processing.histogram.Histogramme;
|
|
import domain.common.Mode;
|
|
import jakarta.inject.Inject;
|
|
import org.jfree.chart.ChartFactory;
|
|
import org.jfree.chart.ChartFrame;
|
|
import org.jfree.chart.JFreeChart;
|
|
import org.jfree.chart.axis.ValueAxis;
|
|
import org.jfree.chart.plot.PlotOrientation;
|
|
import org.jfree.chart.plot.XYPlot;
|
|
import org.jfree.data.xy.XYSeries;
|
|
import org.jfree.data.xy.XYSeriesCollection;
|
|
import presenters.NavPresenter;
|
|
import ui.implementation.components.intent.FileChooser;
|
|
import ui.implementation.dialogs.ImageCreatorDialog;
|
|
import ui.implementation.dialogs.GreyScaleImageCreatorDialog;
|
|
import ui.implementation.dialogs.RGBImageCreatorDialog;
|
|
import ui.abstractions.INavBar;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.event.ActionEvent;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* @author Jean-Marc Wagner, Laurent Crema
|
|
*/
|
|
public class NavBar extends JMenuBar implements INavBar {
|
|
|
|
private JMenu imageMenu;
|
|
private JMenu drawingMenu;
|
|
private JMenu fourierMenu;
|
|
private JMenu linearMenu;
|
|
private JMenu morphologyMenu;
|
|
private Menu outlineMenu;
|
|
private Menu thresholdingMenu;
|
|
private JMenu histogramMenu;
|
|
private JMenu useCaseMenu;
|
|
|
|
private NavPresenter presenter;
|
|
|
|
@Inject
|
|
public NavBar(NavPresenter presenter) {
|
|
this.presenter = presenter;
|
|
this.presenter.setView(this);
|
|
initComponents();
|
|
}
|
|
|
|
private void initComponents(){
|
|
|
|
imageMenu = new Menu("Image","/net_13_p1.jpg",
|
|
new Menu("Nouvelle", "/file_65_p3.jpg",
|
|
new MenuItem("RGB", e -> this.createImage(e, new RGBImageCreatorDialog(new JFrame(),true))),
|
|
new MenuItem("NG", e -> this.createImage(e, new GreyScaleImageCreatorDialog(new JFrame(),true)))
|
|
),
|
|
new MenuItem("Ouvrir...", "/folder_036_p3.jpg", this::loadImage),
|
|
new MenuItem("Enregistrer sous...","/dd_27_p3.jpg", e -> {}),
|
|
new MenuItem("Quitter","/cp_59_p3.jpg", this::quit)
|
|
);
|
|
|
|
drawingMenu = new Menu("Editer","/dd_28_p1.jpg",
|
|
new Menu("Dessiner", "/display_14_p3.jpg",
|
|
new MenuItem("Couleur", this::chooseColor),
|
|
new Menu("Formes",
|
|
new MenuItem("Pixel", e -> this.setMode(e, Mode.DRAW_PIXEL)),
|
|
new MenuItem("Ligne", e -> this.setMode(e, Mode.DRAW_LINE)),
|
|
new MenuItem("Rectangle",e -> this.setMode(e, Mode.DRAW_RECTANGLE)),
|
|
new MenuItem("Cercle", e -> this.setMode(e, Mode.DRAW_CIRCLE))
|
|
)
|
|
),
|
|
new Menu("Convertir",
|
|
new MenuItem("RGB", e -> {
|
|
displayErrorMessage("Oups !", "Not implemented.");
|
|
}),
|
|
new MenuItem("NG", e -> {
|
|
displayErrorMessage("Oups !", "Not implemented.");
|
|
})
|
|
)
|
|
);
|
|
|
|
fourierMenu = new Menu("Fourier","/cp_51_p1.jpg",
|
|
new MenuItem("Afficher", "/cp_51_p3.jpg", this::displayFourier)
|
|
);
|
|
|
|
linearMenu = new Menu("Linéaire","/cp_51_p1.jpg",
|
|
new Menu("Global",
|
|
new MenuItem("Ideal", this::displayIdealFilter),
|
|
new MenuItem("Butterworth", this::displayButterworth)
|
|
),
|
|
new Menu("Local",
|
|
new MenuItem("Masque de convolution", this::displayConvolution),
|
|
new MenuItem("Filtre moyenneur", this::displayButterworth)
|
|
)
|
|
);
|
|
|
|
morphologyMenu = new Menu("Morphologie","/cp_51_p1.jpg",
|
|
new MenuItem("Elementaire", this::displayBasicMorphology),
|
|
new MenuItem("Complexe", this::displayComplexeMorphology)
|
|
);
|
|
|
|
outlineMenu = new Menu("Contours","/cp_51_p1.jpg",
|
|
new MenuItem("Linéaire", this::displayLinearOutline),
|
|
new MenuItem("Non-linéaire", this::displayNonLinearOutline)
|
|
);
|
|
|
|
thresholdingMenu = new Menu("Seuillage","/cp_51_p1.jpg",
|
|
new MenuItem("Afficher", this::displayThresholding)
|
|
);
|
|
|
|
histogramMenu = new Menu("Histogramme","/report_48_hot.jpg",
|
|
new MenuItem("Afficher", "/report_32_hot.jpg",this::displayHistogram)
|
|
);
|
|
|
|
useCaseMenu = new Menu("Applications","/report_48_hot.jpg",
|
|
new MenuItem("Afficher", "/report_32_hot.jpg",this::displayUseCase)
|
|
);
|
|
|
|
this.add(imageMenu);
|
|
this.add(drawingMenu);
|
|
this.add(fourierMenu);
|
|
this.add(linearMenu);
|
|
this.add(morphologyMenu);
|
|
this.add(outlineMenu);
|
|
this.add(thresholdingMenu);
|
|
this.add(histogramMenu);
|
|
this.add(useCaseMenu);
|
|
|
|
drawingMenu.setEnabled(false);
|
|
fourierMenu.setEnabled(false);
|
|
linearMenu.setEnabled(false);
|
|
morphologyMenu.setEnabled(false);
|
|
outlineMenu.setEnabled(false);
|
|
thresholdingMenu.setEnabled(false);
|
|
histogramMenu.setEnabled(false);
|
|
useCaseMenu.setEnabled(true);
|
|
}
|
|
|
|
|
|
|
|
//####################################################
|
|
|
|
private File chooseFile(){
|
|
FileChooser chooser = new FileChooser("./src/main/resources");
|
|
|
|
int dialogResult = chooser.showOpenDialog(this);
|
|
if (dialogResult != JFileChooser.APPROVE_OPTION) return null;
|
|
|
|
return chooser.getSelectedFile();
|
|
}
|
|
|
|
private void loadImage(ActionEvent e) {
|
|
try
|
|
{
|
|
File file = chooseFile();
|
|
if(file == null) return;
|
|
presenter.loadImage(file);
|
|
activeMenusRGB();
|
|
activeMenusNG();
|
|
}
|
|
catch (IOException ex)
|
|
{
|
|
System.err.println("Erreur I/O : " + ex.getMessage());
|
|
}
|
|
}
|
|
|
|
private void quit(ActionEvent e) {
|
|
System.exit(0);
|
|
}
|
|
|
|
private void createImage(ActionEvent e, ImageCreatorDialog dialog) {
|
|
dialog.setVisible(true);
|
|
presenter.createImage(
|
|
dialog.getRed(), dialog.getGreen(), dialog.getBlue(),
|
|
dialog.getImageHeight(), dialog.getImageWidth());
|
|
activeMenusRGB();
|
|
activeMenusNG();
|
|
}
|
|
|
|
private void setMode(ActionEvent e, Mode mode) {
|
|
presenter.setMode(mode);
|
|
}
|
|
|
|
private void chooseColor(ActionEvent e) {
|
|
/*if (imageRGB != null)
|
|
{
|
|
Color newC = JColorChooser.showDialog(this,"Couleur du pinceau", couleurPinceauRGB);
|
|
if (newC != null) couleurPinceauRGB = newC;
|
|
observer.setCouleurPinceau(couleurPinceauRGB);
|
|
}
|
|
|
|
if (imageNG != null)
|
|
{
|
|
GreyScalePicker dialog = new GreyScalePicker(new JFrame(),true, couleurPinceauNG);
|
|
dialog.setVisible(true);
|
|
couleurPinceauNG = dialog.getCouleur();
|
|
}*/
|
|
}
|
|
|
|
|
|
private void activeMenusNG()
|
|
{
|
|
drawingMenu.setEnabled(true);
|
|
fourierMenu.setEnabled(true);
|
|
linearMenu.setEnabled(true);
|
|
morphologyMenu.setEnabled(true);
|
|
outlineMenu.setEnabled(true);
|
|
thresholdingMenu.setEnabled(true);
|
|
histogramMenu.setEnabled(true);
|
|
}
|
|
|
|
private void activeMenusRGB()
|
|
{
|
|
drawingMenu.setEnabled(true);
|
|
fourierMenu.setEnabled(false);
|
|
linearMenu.setEnabled(false);
|
|
morphologyMenu.setEnabled(false);
|
|
outlineMenu.setEnabled(false);
|
|
thresholdingMenu.setEnabled(false);
|
|
histogramMenu.setEnabled(false);
|
|
}
|
|
|
|
//####################################################
|
|
|
|
private void displayHistogram(ActionEvent e) {
|
|
GrayScaleMatrix i_graymatrix = presenter.getImageGrayMatrix();
|
|
int[] histo = Histogramme.Histogramme256(i_graymatrix);
|
|
|
|
//Création du dataset
|
|
XYSeries serie = new XYSeries("Histo");
|
|
for(int i=0 ; i<256 ; i++) serie.add(i,histo[i]);
|
|
XYSeriesCollection dataset = new XYSeriesCollection();
|
|
dataset.addSeries(serie);
|
|
|
|
// Creation du chart
|
|
JFreeChart chart = ChartFactory.createHistogram("Histogramme","Niveaux de gris",
|
|
"Nombre de pixels", dataset, PlotOrientation.VERTICAL,false,false,false);
|
|
|
|
XYPlot plot = chart.getXYPlot();
|
|
ValueAxis axeX = plot.getDomainAxis();
|
|
axeX.setRange(0,255);
|
|
plot.setDomainAxis(axeX);
|
|
|
|
// creation d'une frame
|
|
ChartFrame frame = new ChartFrame("Histogramme de l'image",chart);
|
|
frame.pack();
|
|
frame.setVisible(true);
|
|
}
|
|
|
|
private void displayFourier(ActionEvent e) {
|
|
try
|
|
{
|
|
presenter.goToFourier();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.out.println("Erreur CImageNG : " + ex.getMessage());
|
|
}
|
|
}
|
|
|
|
private void displayIdealFilter(ActionEvent e) {
|
|
presenter.goToFiltering();
|
|
}
|
|
|
|
private void displayButterworth(ActionEvent e) {
|
|
presenter.gotToButterworth();
|
|
}
|
|
|
|
private void displayConvolution(ActionEvent actionEvent) {
|
|
presenter.goToConvolution();
|
|
}
|
|
|
|
private void displayBasicMorphology(ActionEvent actionEvent) { presenter.goToBasicMorphology(); }
|
|
|
|
private void displayComplexeMorphology(ActionEvent actionEvent) { presenter.goToComplexMorphology(); }
|
|
|
|
private void displayLinearOutline(ActionEvent actionEvent) { presenter.goToLinearOutline(); }
|
|
|
|
private void displayNonLinearOutline(ActionEvent actionEvent) { presenter.goToNonLinearOutline();}
|
|
|
|
private void displayThresholding(ActionEvent actionEvent) { presenter.goToThresholding(); }
|
|
|
|
private void displayUseCase(ActionEvent actionEvent) { presenter.goToUseCase(); }
|
|
|
|
private void displayErrorMessage(String title, String message) {
|
|
JOptionPane.showMessageDialog(
|
|
this,
|
|
message,
|
|
title,
|
|
JOptionPane.ERROR_MESSAGE
|
|
);
|
|
}
|
|
|
|
}
|