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

View File

@ -18,7 +18,7 @@ import javafx.scene.text.Text;
import model.NewsModel;
import model.WordTraductionModel;
public class Dictionary{
public class Traduction{
/* Data */
private ArrayList<AnchorPane> items;
@ -27,7 +27,7 @@ public class Dictionary{
/* Constructor */
public Dictionary(FlowPane p_parent, EventObserver observer){
public Traduction(FlowPane p_parent, EventObserver observer){
this.parent = p_parent;
this.items = new ArrayList<AnchorPane>();
this.observer = observer;
@ -76,7 +76,7 @@ public class Dictionary{
/* (11) Add to parent (graphics) */
Platform.runLater(new Runnable(){
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() {
Platform.runLater(new Runnable(){
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>
</ImageView>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Dictionnaire" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Vocabulaire" />
</children>
</FlowPane>
<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 javafx.util.Pair;
public class DictionaryModel implements Observable {
public class TraductionModel implements Observable {
private HashMap<String,EventObserver> observers;
private static DictionaryModel instance;
private static TraductionModel instance;
private ArrayList<Pair<WordTraductionModel,WordTraductionModel>> translations;
private ArrayList<Pair<WordTraductionModel,WordTraductionModel>> usages;
private DictionaryModel() {
private TraductionModel() {
this.observers = new HashMap<String,EventObserver>();
}
public static DictionaryModel getInstance() {
if(DictionaryModel.instance == null) {
DictionaryModel.instance = new DictionaryModel();
public static TraductionModel getInstance() {
if(TraductionModel.instance == null) {
TraductionModel.instance = new TraductionModel();
}
return DictionaryModel.instance;
return TraductionModel.instance;
}
public void query(String search) {
@ -64,36 +64,36 @@ public class DictionaryModel implements Observable {
try {
//on reset le contenu du modele
DictionaryModel.this.translations = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>();
DictionaryModel.this.usages = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>();
TraductionModel.this.translations = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>();
TraductionModel.this.usages = new ArrayList<Pair<WordTraductionModel,WordTraductionModel>>();
if(response.has("Error")) {
//pas de résultat
DictionaryModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed"));
TraductionModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed"));
}else{
//Traitement des traductions principales
DictionaryModel.this.translations.addAll(
DictionaryModel.this.computeJSON(
TraductionModel.this.translations.addAll(
TraductionModel.this.computeJSON(
response.getJSONObject("term0").getJSONObject("PrincipalTranslations")
)
);
//Traitement des traductions secondaires
if(response.getJSONObject("term0").has("AdditionalTranslations")) {
DictionaryModel.this.translations.addAll(
DictionaryModel.this.computeJSON(
TraductionModel.this.translations.addAll(
TraductionModel.this.computeJSON(
response.getJSONObject("term0").getJSONObject("AdditionalTranslations")
)
);
}
//traitement des usages
DictionaryModel.this.usages.addAll(
DictionaryModel.this.computeJSON(
TraductionModel.this.usages.addAll(
TraductionModel.this.computeJSON(
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
public void onError() {
DictionaryModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed"));
TraductionModel.this.notifyObservers(new Event("DictionaryModel","WordQueryFailed"));
}
});