Implémentation de la recherche par catégorie

This commit is contained in:
SeekDaSky 2017-12-12 14:39:34 +01:00
parent ee956629ea
commit e52280bc21
4 changed files with 44 additions and 14 deletions

View File

@ -22,4 +22,5 @@ public enum Category {
public String getLabel(){ return this.label; }
public String getColor(){ return this.color; }
}

View File

@ -124,7 +124,11 @@ public class Article{
ImageView g_image = (ImageView) p_parent.getChildren().get(0);
/* (2) Update title */
try {
g_image.setImage(new Image(p_uri));
}catch(Exception e) {
g_image.setImage(new Image("http://lorempicsum.com/futurama/255/200/2"));
}
}

View File

@ -1,5 +1,6 @@
package controller;
import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
@ -25,6 +26,7 @@ import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
@ -49,7 +51,7 @@ public class RootLayout extends Application implements EventObserver {
/* (1) store primary stage + title it */
this.root_stage = primary_stage;
this.root_stage.setTitle("Inifiny Mail Client");
this.root_stage.setTitle("Language learner pro plus 2000");
/* (2) Load the root layout*/
this.loadRootLayout();
@ -92,6 +94,8 @@ public class RootLayout extends Application implements EventObserver {
/* (4) #header_icon*/
new HeaderIconStyleSheet( this.root_scene.lookup("#header_icon") );
this.handleMainLayoutChange("magazines");
}
public void loadRootLayout(){
@ -201,6 +205,9 @@ public class RootLayout extends Application implements EventObserver {
System.out.println(DictionaryModel.getInstance().getTranslations().size()+" Traductions ont été trouvés");
System.out.println(DictionaryModel.getInstance().getUsages().size()+" Exemples ont été trouvés");
break;
case "changeMagCategory":
NewsListModel.getInstance().setCategory(Category.valueOf(e.getObjectId().toLowerCase()));
}
}
@ -223,6 +230,21 @@ public class RootLayout extends Application implements EventObserver {
break;
case "magazines" :
VBox subMenuContainer = (VBox) this.root_layout.lookup("#submenu");
for(Node n : subMenuContainer.getChildren()) {
FlowPane p = (FlowPane) n;
p.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
//horreur...malheur
p.setStyle("-fx-background-color: #DDDDDD");
RootLayout.this.root_layout.lookup("#"+NewsListModel.getInstance().getCategory().getLabel()).setStyle("fx-background-color: #F3F3F3");
RootLayout.this.handleEvent(new Classes.Event(p.getChildren().get(0).getId(), "changeMagCategory"));
}
});
}
NewsListModel.getInstance().addObserver("MainClass", this);
NewsListModel.getInstance().setCategory(Category.gaming);
NewsListModel.getInstance().setSortType(SortTypes.relevancy);

View File

@ -118,7 +118,7 @@
<children>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Tout afficher" />
<Text fx:id="all" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Tout afficher" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -134,7 +134,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="30.0" layoutY="60.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Science" />
<Text fx:id="science" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Science" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -150,7 +150,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="30.0" layoutY="95.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Business" />
<Text fx:id="business" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Business" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -166,7 +166,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="30.0" layoutY="130.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Entertainement" />
<Text fx:id="entertainment" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Entertainement" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -182,7 +182,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="10.0" layoutY="165.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Gaming" />
<Text fx:id="gaming" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Gaming" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -198,7 +198,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="10.0" layoutY="200.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Health" />
<Text fx:id="health" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Health" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -214,7 +214,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="30.0" layoutY="235.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Music" />
<Text fx:id="music" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Music" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -230,7 +230,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="10.0" layoutY="270.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Sport" />
<Text fx:id="sport" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Sport" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -246,7 +246,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="10.0" layoutY="305.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Nature" />
<Text fx:id="nature" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Nature" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -262,7 +262,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="10.0" layoutY="340.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Economics" />
<Text fx:id="economics" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Economics" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -279,7 +279,7 @@
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="10.0" layoutY="375.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Politics" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<ImageView fx:id="politics" fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
</FlowPane.margin>
@ -294,7 +294,7 @@
</FlowPane>
<FlowPane alignment="CENTER_RIGHT" columnHalignment="CENTER" layoutX="10.0" layoutY="410.0" prefHeight="35.0" prefWidth="234.0" styleClass="menu_item">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Technology" />
<Text fx:id="technology" fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Technology" />
<ImageView fitHeight="15.0" fitWidth="15.0" pickOnBounds="true" preserveRatio="true">
<FlowPane.margin>
<Insets left="15.0" />
@ -374,6 +374,9 @@
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets top="20.0" />
</padding>
</FlowPane>
</content>
</ScrollPane>