Import from internal git
This commit is contained in:
126
src/main/java/presenters/DoubleMatrixPresenter.java
Normal file
126
src/main/java/presenters/DoubleMatrixPresenter.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package presenters;
|
||||
|
||||
import app.state.DoubleMatrixState;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Inject;
|
||||
import domain.events.fourier.ImaginaryChangedEvent;
|
||||
import domain.events.fourier.ModuleChangedEvent;
|
||||
import domain.events.fourier.PhaseChangedEvent;
|
||||
import domain.events.fourier.RealChangedEvent;
|
||||
import domain.image.GrayScaleMatrix;
|
||||
import domain.image.Image;
|
||||
import domain.image.processing.complex.ComplexMatrix;
|
||||
import services.ImageService;
|
||||
import ui.interfaces.IDoubleMatrix;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Laurent Crema
|
||||
*/
|
||||
public class DoubleMatrixPresenter {
|
||||
|
||||
private IDoubleMatrix view;
|
||||
private final DoubleMatrixState state;
|
||||
private final ImageService imageService;
|
||||
|
||||
@Inject
|
||||
public DoubleMatrixPresenter(ImageService imageService, DoubleMatrixState state) {
|
||||
this.imageService = imageService;
|
||||
this.state = state;
|
||||
this.state.register(this);
|
||||
}
|
||||
|
||||
public void setView(IDoubleMatrix view){
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public void saveImage(Image image) throws IOException {
|
||||
this.imageService.saveImage(image);
|
||||
}
|
||||
|
||||
public void loadModule(){
|
||||
double[][] module = getFourier().getModule();
|
||||
state.setModule(new GrayScaleMatrix(module));
|
||||
}
|
||||
|
||||
public void loadPhase(){
|
||||
double[][] phase = getFourier().getPhase();
|
||||
state.setPhase(new GrayScaleMatrix(phase));
|
||||
}
|
||||
|
||||
public void loadReal(){
|
||||
double[][] real = getFourier().getPartieReelle();
|
||||
state.setReal(new GrayScaleMatrix(real));
|
||||
}
|
||||
|
||||
public void loadImaginary(){
|
||||
double[][] imaginary = getFourier().getPartieImaginaire();
|
||||
state.setImaginary(new GrayScaleMatrix(imaginary));
|
||||
}
|
||||
|
||||
public double getValueAt(GrayScaleMatrix matrix, double normalized){
|
||||
return matrix.getValueAt(normalized);
|
||||
}
|
||||
|
||||
public void clipModule(double black, double white){
|
||||
GrayScaleMatrix module = new GrayScaleMatrix(getFourier().getModule());
|
||||
GrayScaleMatrix matrix = clip(module, black, white);
|
||||
state.setModule(matrix);
|
||||
}
|
||||
|
||||
public void clipPhase(double black, double white){
|
||||
GrayScaleMatrix phase = new GrayScaleMatrix(getFourier().getPhase());
|
||||
GrayScaleMatrix matrix = clip(phase, black, white);
|
||||
state.setPhase(matrix);
|
||||
}
|
||||
|
||||
public void clipReal(double black, double white){
|
||||
GrayScaleMatrix real = new GrayScaleMatrix(getFourier().getPartieReelle());
|
||||
GrayScaleMatrix matrix = clip(real, black, white);
|
||||
state.setReal(matrix);
|
||||
}
|
||||
|
||||
public void clipImaginary(double black, double white){
|
||||
GrayScaleMatrix imaginary = new GrayScaleMatrix(getFourier().getPartieImaginaire());
|
||||
GrayScaleMatrix matrix = clip(imaginary, black, white);
|
||||
state.setImaginary(matrix);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onModuleUpdate(ModuleChangedEvent event) {
|
||||
GrayScaleMatrix module = new GrayScaleMatrix(getFourier().getModule());
|
||||
view.updateModule(module, event.matrix());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPhaseUpdate(PhaseChangedEvent event) {
|
||||
GrayScaleMatrix phase = new GrayScaleMatrix(getFourier().getPhase());
|
||||
view.updatePhase(phase, event.matrix());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onRealUpdate(RealChangedEvent event) {
|
||||
GrayScaleMatrix real = new GrayScaleMatrix(getFourier().getPartieReelle());
|
||||
view.updateReal(real, event.matrix());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onImaginaryUpdate(ImaginaryChangedEvent event) {
|
||||
GrayScaleMatrix imaginary = new GrayScaleMatrix(getFourier().getPartieImaginaire());
|
||||
view.updateImaginary(imaginary, event.matrix());
|
||||
}
|
||||
|
||||
private GrayScaleMatrix clip(GrayScaleMatrix matrix, double black, double white){
|
||||
double lowerBound = matrix.getValueAt(black);
|
||||
double upperBound = matrix.getValueAt(white);
|
||||
return matrix.clip(lowerBound, upperBound);
|
||||
}
|
||||
|
||||
private ComplexMatrix getFourier() {
|
||||
if (state.getFourier() == null) {
|
||||
state.setFourier(imageService.computeFourier());
|
||||
}
|
||||
return state.getFourier();
|
||||
}
|
||||
}
|
||||
67
src/main/java/presenters/MainPresenter.java
Normal file
67
src/main/java/presenters/MainPresenter.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package presenters;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Inject;
|
||||
import domain.common.Mode;
|
||||
import domain.events.ImageChangedEvent;
|
||||
import domain.events.ModeChangedEvent;
|
||||
import domain.image.Image;
|
||||
import services.ImageService;
|
||||
import services.ModeService;
|
||||
import ui.interfaces.IMainView;
|
||||
|
||||
/**
|
||||
* @author Laurent Crema
|
||||
*/
|
||||
public class MainPresenter {
|
||||
|
||||
private IMainView view;
|
||||
private final ModeService modeService;
|
||||
private final ImageService imageService;
|
||||
|
||||
@Inject
|
||||
public MainPresenter(ModeService modeService, ImageService imageService, EventBus eventBus) {
|
||||
this.modeService = modeService;
|
||||
this.imageService = imageService;
|
||||
eventBus.register(this);
|
||||
}
|
||||
|
||||
public void setView(IMainView view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onImageChanged(ImageChangedEvent e){
|
||||
view.displayImage(e.image());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onModeChanged(ModeChangedEvent e){
|
||||
view.changeMode(e.mode());
|
||||
}
|
||||
|
||||
public void drawPixel(int x, int y, int red, int green, int blue){
|
||||
if(modeService.getMode() != Mode.DRAW_PIXEL) return;
|
||||
Image image = imageService.getImage();
|
||||
image.setPixelColor(x, y, red, green, blue);
|
||||
imageService.setImage(image);
|
||||
}
|
||||
|
||||
public void drawShape(int x1, int x2, int y1, int y2, int red, int green, int blue){
|
||||
Image image = imageService.getImage();
|
||||
switch (modeService.getMode()) {
|
||||
case DRAW_RECTANGLE:
|
||||
image.setRectangleColor(x1, x2, y1, y2, red, green, blue);
|
||||
break;
|
||||
case DRAW_LINE:
|
||||
image.setLineColor(x1, x2, y1, y2, red, green, blue);
|
||||
break;
|
||||
case DRAW_CIRCLE:
|
||||
break;
|
||||
}
|
||||
imageService.setImage(image);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
55
src/main/java/presenters/NavPresenter.java
Normal file
55
src/main/java/presenters/NavPresenter.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package presenters;
|
||||
|
||||
import app.INavigator;
|
||||
import com.google.inject.Inject;
|
||||
import domain.common.Mode;
|
||||
import domain.image.GrayScaleMatrix;
|
||||
import services.ImageService;
|
||||
import services.ModeService;
|
||||
import ui.interfaces.INavBar;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Laurent Crema
|
||||
*/
|
||||
public class NavPresenter {
|
||||
|
||||
private INavBar navBar;
|
||||
private INavigator navigator;
|
||||
private final ImageService imageService;
|
||||
private final ModeService modeService;
|
||||
|
||||
@Inject
|
||||
public NavPresenter(INavigator navigator, ImageService imageService, ModeService modeService) {
|
||||
this.navigator = navigator;
|
||||
this.imageService = imageService;
|
||||
this.modeService = modeService;
|
||||
}
|
||||
|
||||
public void setView(INavBar navBar) {
|
||||
this.navBar = navBar;
|
||||
}
|
||||
|
||||
public void createImage(int red, int green, int blue, int height, int width) {
|
||||
imageService.createImage(red, green, blue, height, width);
|
||||
}
|
||||
|
||||
public void loadImage(File f) throws IOException {
|
||||
imageService.loadImage(f);
|
||||
}
|
||||
|
||||
public void goToFourier(){
|
||||
navigator.showFourier();
|
||||
}
|
||||
|
||||
public GrayScaleMatrix getImageGrayMatrix() {
|
||||
//return ((CImageNG)appState.getImage()).getMatrice();
|
||||
return imageService.getImage().toGrayScale();
|
||||
}
|
||||
|
||||
public void setMode(Mode mode) {
|
||||
modeService.setMode(mode);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user