This commit is contained in:
xdrm-brackets 2017-12-14 14:50:00 +01:00
parent 9f0bc020ec
commit 4e5980c175
5 changed files with 133 additions and 134 deletions

View File

@ -28,7 +28,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Pair; import javafx.util.Pair;
import model.DictionaryModel; import model.TraductionModel;
import model.NewsListModel; import model.NewsListModel;
import model.NewsModel; import model.NewsModel;
import model.WordTraductionModel; import model.WordTraductionModel;
@ -40,7 +40,7 @@ public class RootLayout extends Application implements EventObserver {
private AnchorPane root_layout; private AnchorPane root_layout;
private FlowPane main_container; private FlowPane main_container;
private Article articles; private Article articles;
private Dictionary dico; private Traduction dico;
@Override @Override
@ -74,8 +74,7 @@ public class RootLayout extends Application implements EventObserver {
/* (2) Create container */ /* (2) Create container */
this.articles = new Article(this.main_container, this); this.articles = new Article(this.main_container, this);
this.dico = new Traduction(this.main_container, this);
this.dico = new Dictionary(this.main_container, this);
/* (2) CSS /* (2) CSS
@ -102,7 +101,7 @@ public class RootLayout extends Application implements EventObserver {
NewsListModel.getInstance().setCategory(Category.all); NewsListModel.getInstance().setCategory(Category.all);
NewsListModel.getInstance().setSortType(SortTypes.relevancy); NewsListModel.getInstance().setSortType(SortTypes.relevancy);
DictionaryModel.getInstance().addObserver("MainClass", this); TraductionModel.getInstance().addObserver("MainClass", this);
VBox subMenuContainer = (VBox) this.root_layout.lookup("#submenu"); VBox subMenuContainer = (VBox) this.root_layout.lookup("#submenu");
@ -248,8 +247,8 @@ public class RootLayout extends Application implements EventObserver {
case "WordQuerySuccess": case "WordQuerySuccess":
System.out.println(DictionaryModel.getInstance().getTranslations().size()+" Traductions ont été trouvés"); System.out.println(TraductionModel.getInstance().getTranslations().size()+" Traductions ont été trouvés");
System.out.println(DictionaryModel.getInstance().getUsages().size()+" Exemples ont été trouvés"); System.out.println(TraductionModel.getInstance().getUsages().size()+" Exemples ont été trouvés");
this.dico.clearContent(); this.dico.clearContent();
@ -264,7 +263,7 @@ public class RootLayout extends Application implements EventObserver {
@Override @Override
public void handle(KeyEvent arg0) { public void handle(KeyEvent arg0) {
if(arg0.getCode() == KeyCode.ENTER) { if(arg0.getCode() == KeyCode.ENTER) {
DictionaryModel.getInstance().query(tx1.textProperty().get()); TraductionModel.getInstance().query(tx1.textProperty().get());
} }
} }
@ -282,10 +281,10 @@ public class RootLayout extends Application implements EventObserver {
}); });
if(DictionaryModel.getInstance().getTranslations().size() != 0) { if(TraductionModel.getInstance().getTranslations().size() != 0) {
// For each news // For each news
for( Pair<WordTraductionModel, WordTraductionModel> news : DictionaryModel.getInstance().getTranslations() ){ for( Pair<WordTraductionModel, WordTraductionModel> news : TraductionModel.getInstance().getTranslations() ){
try{ try{
@ -316,13 +315,13 @@ public class RootLayout extends Application implements EventObserver {
switch(layout) { switch(layout) {
case "dictionary" : case "dictionary" :
DictionaryModel.getInstance().query(""); container.getChildren().add(new Text("dictionary"));
break; break;
case "exercises" : case "exercises" :
container.getChildren().add(new Text("exercises")); container.getChildren().add(new Text("exercises"));
break; break;
case "translator" : case "translator" :
container.getChildren().add(new Text("translator")); TraductionModel.getInstance().query("");
break; break;
case "magazines" : case "magazines" :
NewsListModel.getInstance().query(""); NewsListModel.getInstance().query("");

View File

@ -18,7 +18,7 @@ import javafx.scene.text.Text;
import model.NewsModel; import model.NewsModel;
import model.WordTraductionModel; import model.WordTraductionModel;
public class Dictionary{ public class Traduction{
/* Data */ /* Data */
private ArrayList<AnchorPane> items; private ArrayList<AnchorPane> items;
@ -27,7 +27,7 @@ public class Dictionary{
/* Constructor */ /* Constructor */
public Dictionary(FlowPane p_parent, EventObserver observer){ public Traduction(FlowPane p_parent, EventObserver observer){
this.parent = p_parent; this.parent = p_parent;
this.items = new ArrayList<AnchorPane>(); this.items = new ArrayList<AnchorPane>();
this.observer = observer; this.observer = observer;
@ -76,7 +76,7 @@ public class Dictionary{
/* (11) Add to parent (graphics) */ /* (11) Add to parent (graphics) */
Platform.runLater(new Runnable(){ Platform.runLater(new Runnable(){
public void run(){ public void run(){
Dictionary.this.parent.getChildren().add(item); Traduction.this.parent.getChildren().add(item);
} }
}); });
} }
@ -84,7 +84,7 @@ public class Dictionary{
public void clearContent() { public void clearContent() {
Platform.runLater(new Runnable(){ Platform.runLater(new Runnable(){
public void run(){ public void run(){
Dictionary.this.parent.getChildren().clear(); Traduction.this.parent.getChildren().clear();
} }
}); });
} }

View File

@ -69,7 +69,7 @@
<Image url="@../src/menu/dictionary.png" /> <Image url="@../src/menu/dictionary.png" />
</image> </image>
</ImageView> </ImageView>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Dictionnaire" /> <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Vocabulaire" />
</children> </children>
</FlowPane> </FlowPane>
<FlowPane id="exercises" alignment="CENTER" columnHalignment="CENTER" layoutX="10.0" layoutY="182.0" prefHeight="58.0" prefWidth="234.0" styleClass="menu_item"> <FlowPane id="exercises" alignment="CENTER" columnHalignment="CENTER" layoutX="10.0" layoutY="182.0" prefHeight="58.0" prefWidth="234.0" styleClass="menu_item">

View File

@ -13,23 +13,23 @@ import Interfaces.EventObserver;
import Interfaces.Observable; import Interfaces.Observable;
import javafx.util.Pair; import javafx.util.Pair;
public class DictionaryModel implements Observable { public class TraductionModel implements Observable {
private HashMap<String,EventObserver> observers; private HashMap<String,EventObserver> observers;
private static DictionaryModel instance; private static TraductionModel instance;
private ArrayList<Pair<WordTraductionModel,WordTraductionModel>> translations; private ArrayList<Pair<WordTraductionModel,WordTraductionModel>> translations;
private ArrayList<Pair<WordTraductionModel,WordTraductionModel>> usages; private ArrayList<Pair<WordTraductionModel,WordTraductionModel>> usages;
private DictionaryModel() { private TraductionModel() {
this.observers = new HashMap<String,EventObserver>(); this.observers = new HashMap<String,EventObserver>();
} }
public static DictionaryModel getInstance() { public static TraductionModel getInstance() {
if(DictionaryModel.instance == null) { if(TraductionModel.instance == null) {
DictionaryModel.instance = new DictionaryModel(); TraductionModel.instance = new TraductionModel();
} }
return DictionaryModel.instance; return TraductionModel.instance;
} }
public void query(String search) { public void query(String search) {
@ -64,36 +64,36 @@ public class DictionaryModel implements Observable {
try { try {
//on reset le contenu du modele //on reset le contenu du modele
DictionaryModel.this.translations = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>(); TraductionModel.this.translations = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>();
DictionaryModel.this.usages = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>(); TraductionModel.this.usages = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>();
if(response.has("Error")) { if(response.has("Error")) {
//pas de résultat //pas de résultat
DictionaryModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed")); TraductionModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed"));
}else{ }else{
//Traitement des traductions principales //Traitement des traductions principales
DictionaryModel.this.translations.addAll( TraductionModel.this.translations.addAll(
DictionaryModel.this.computeJSON( TraductionModel.this.computeJSON(
response.getJSONObject("term0").getJSONObject("PrincipalTranslations") response.getJSONObject("term0").getJSONObject("PrincipalTranslations")
) )
); );
//Traitement des traductions secondaires //Traitement des traductions secondaires
if(response.getJSONObject("term0").has("AdditionalTranslations")) { if(response.getJSONObject("term0").has("AdditionalTranslations")) {
DictionaryModel.this.translations.addAll( TraductionModel.this.translations.addAll(
DictionaryModel.this.computeJSON( TraductionModel.this.computeJSON(
response.getJSONObject("term0").getJSONObject("AdditionalTranslations") response.getJSONObject("term0").getJSONObject("AdditionalTranslations")
) )
); );
} }
//traitement des usages //traitement des usages
DictionaryModel.this.usages.addAll( TraductionModel.this.usages.addAll(
DictionaryModel.this.computeJSON( TraductionModel.this.computeJSON(
response.getJSONObject("original").getJSONObject("Compounds") response.getJSONObject("original").getJSONObject("Compounds")
) )
); );
DictionaryModel.this.notifyObservers(new Event("DictionaryModel","WordQuerySuccess")); TraductionModel.this.notifyObservers(new Event("DictionaryModel","WordQuerySuccess"));
} }
@ -105,7 +105,7 @@ public class DictionaryModel implements Observable {
@Override @Override
public void onError() { public void onError() {
DictionaryModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed")); TraductionModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed"));
} }
}); });