Skip to content
Snippets Groups Projects
Commit d7046339 authored by NicolasAnquetil's avatar NicolasAnquetil
Browse files

cleancode

parent 5104dcbd
Branches
No related tags found
No related merge requests found
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> <classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes> <attributes>
<attribute name="module" value="true"/> <attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes> <attributes>
<attribute name="test" value="true"/> <attribute name="module" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
......
package fr.univlille.iutinfo.m3105.modelQ2; package fr.univlille.iutinfo.m3105.modelQ2;
import java.util.Map;
import java.util.function.Function;
public enum Echelle { public enum Echelle {
CELSIUS("Celsius", "C"), CELSIUS("Celsius", "C"),
DELISLE("Delisle", "D"), DELISLE("Delisle", "D"),
...@@ -14,6 +17,22 @@ public enum Echelle { ...@@ -14,6 +17,22 @@ public enum Echelle {
private String name; private String name;
private String abbrev; private String abbrev;
private static Map<Echelle,Function<Double,Double>> fromKelvin = Map.ofEntries(
Map.entry(CELSIUS, (v) -> v - 273.15 ) ,
Map.entry(FAHRENHEIT, (v) -> (v - 273.15) * 9.0 / 5.0 + 32.0 ) ,
Map.entry(KELVIN, (v) -> v ) ,
Map.entry(NEWTON, (v) -> (v - 273.15) * 0.33 ) ,
Map.entry(RANKINE, (v) -> v * 1.8 )
);
private static Map<Echelle,Function<Double,Double>> toKelvin = Map.ofEntries(
Map.entry(CELSIUS, (v) -> v + 273.15 ) ,
Map.entry(FAHRENHEIT, (v) -> (v - 32.0) * 5.0 / 9.0 + 273.15 ) ,
Map.entry(KELVIN, (v) -> v ) ,
Map.entry(NEWTON, (v) -> v / 0.33 + 273.15 ) ,
Map.entry(RANKINE, (v) -> v / 1.8 )
);
private Echelle(String name, String abbrev) { private Echelle(String name, String abbrev) {
this.name = name; this.name = name;
this.abbrev = abbrev; this.abbrev = abbrev;
...@@ -28,51 +47,11 @@ public enum Echelle { ...@@ -28,51 +47,11 @@ public enum Echelle {
} }
public double toKelvin(double value) { public double toKelvin(double value) {
switch (this) { return toKelvin.get(this).apply(value);
case CELSIUS:
return value + 273.15;
case DELISLE:
return value;
case FAHRENHEIT:
return (value - 32.0) * 5.0 / 9.0 + 273.15;
case KELVIN:
return value;
case LEYDEN:
return value;
case NEWTON:
return value / 0.33 + 273.15;
case RANKINE:
return value / 1.8;
case REAUMUR:
return value;
case ROMER:
return value;
}
return 0; // should never happen
} }
public double fromKelvin(double value) { public double fromKelvin(double value) {
switch (this) { return fromKelvin.get(this).apply(value);
case CELSIUS:
return value - 273.15;
case DELISLE:
return( value);
case FAHRENHEIT:
return (value - 273.15) * 9.0 / 5.0 + 32.0;
case KELVIN:
return( value);
case LEYDEN:
return value;
case NEWTON:
return (value - 273.15) * 0.33;
case RANKINE:
return value * 1.8;
case REAUMUR:
return( value);
case ROMER:
return( value);
}
return 0; // should never happen
} }
} }
...@@ -7,9 +7,12 @@ import fr.univlille.iutinfo.m3105.utils.Subject; ...@@ -7,9 +7,12 @@ import fr.univlille.iutinfo.m3105.utils.Subject;
import fr.univlille.iutinfo.m3105.viewQ1.ITemperatureView; import fr.univlille.iutinfo.m3105.viewQ1.ITemperatureView;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
public abstract class AbstractVue extends Stage implements Observer, ITemperatureView { public abstract class AbstractVue extends Stage implements Observer, ITemperatureView {
...@@ -71,4 +74,12 @@ public abstract class AbstractVue extends Stage implements Observer, ITemperatur ...@@ -71,4 +74,12 @@ public abstract class AbstractVue extends Stage implements Observer, ITemperatur
return modele.getEchelle(); return modele.getEchelle();
} }
protected VBox createVBox() {
VBox vb = new VBox();
vb.setAlignment(Pos.CENTER);
vb.setPadding(new Insets(5, 10, 5, 10));
vb.setSpacing(10);
return vb;
}
} }
\ No newline at end of file
...@@ -2,9 +2,7 @@ package fr.univlille.iutinfo.m3105.viewQ3; ...@@ -2,9 +2,7 @@ package fr.univlille.iutinfo.m3105.viewQ3;
import fr.univlille.iutinfo.m3105.modelQ2.Echelle; import fr.univlille.iutinfo.m3105.modelQ2.Echelle;
import fr.univlille.iutinfo.m3105.modelQ2.Temperature; import fr.univlille.iutinfo.m3105.modelQ2.Temperature;
import javafx.geometry.Insets;
import javafx.geometry.Orientation; import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.control.Slider; import javafx.scene.control.Slider;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
...@@ -18,10 +16,7 @@ public class SliderView extends AbstractVue { ...@@ -18,10 +16,7 @@ public class SliderView extends AbstractVue {
@Override @Override
protected Region createSceneContent() { protected Region createSceneContent() {
VBox vb = new VBox(); VBox vb = createVBox();
vb.setAlignment(Pos.CENTER);
vb.setPadding(new Insets(5, 10, 5, 10));
vb.setSpacing(10);
saisie = createSlider(); saisie = createSlider();
vb.getChildren().addAll( vb.getChildren().addAll(
...@@ -37,14 +32,19 @@ public class SliderView extends AbstractVue { ...@@ -37,14 +32,19 @@ public class SliderView extends AbstractVue {
int min = (int) getEchelle().fromKelvin( Echelle.CELSIUS.toKelvin(-10.0) ); int min = (int) getEchelle().fromKelvin( Echelle.CELSIUS.toKelvin(-10.0) );
int max = (int) getEchelle().fromKelvin( Echelle.CELSIUS.toKelvin(50.0) ); int max = (int) getEchelle().fromKelvin( Echelle.CELSIUS.toKelvin(50.0) );
slid = configureSlider(min, max);
slid.valueProperty().addListener( (e,o,n) -> modele.setTemperature((double)n) );
return slid;
}
private Slider configureSlider(int min, int max) {
Slider slid;
slid = new Slider(min,max,0); slid = new Slider(min,max,0);
slid.setOrientation(Orientation.VERTICAL); slid.setOrientation(Orientation.VERTICAL);
slid.setMajorTickUnit( (max - min) / 10 ); slid.setMajorTickUnit( (max - min) / 10 );
slid.setShowTickMarks(true); slid.setShowTickMarks(true);
slid.setShowTickLabels(true); slid.setShowTickLabels(true);
slid.valueProperty().addListener( (e,o,n) -> modele.setTemperature((double)n) );
return slid; return slid;
} }
......
...@@ -20,10 +20,8 @@ public class TextView extends AbstractVue { ...@@ -20,10 +20,8 @@ public class TextView extends AbstractVue {
@Override @Override
protected Region createSceneContent() { protected Region createSceneContent() {
VBox vb = new VBox(); VBox vb = createVBox();
vb.setAlignment(Pos.CENTER);
vb.setPadding(new Insets(5, 10, 5, 10));
vb.setSpacing(10);
vb.getChildren().add(new Label( "Température en " + getEchelle().getName())); vb.getChildren().add(new Label( "Température en " + getEchelle().getName()));
HBox hbox = new HBox(); HBox hbox = new HBox();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment