Merge branch 'master' into 'Image_in_Rack'

# Conflicts:
#   src/main/java/latice/application/LaticeApplicationWindow.java
master
Odabasioglu Cemal 2022-05-03 14:50:55 +00:00
commit 7ac6bc4763
3 changed files with 150 additions and 12 deletions

View File

@ -1,7 +1,10 @@
package latice.application;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import javafx.scene.image.Image;
import latice.model.Color;
import latice.model.Deck;
import latice.model.Rack;
@ -25,6 +28,8 @@ public class LaticeApplicationConsole {
}
}
System.out.println("-----------------");
System.out.println("Notre Deck :");

View File

@ -3,13 +3,27 @@ package latice.application;
import java.util.ArrayList;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
@ -43,7 +57,29 @@ public class LaticeApplicationWindow extends Application{
root.setAlignment(title, Pos.CENTER);
//Image
root.setCenter(imageView);
//rectangle.setFill(realColor.TRANSPARENT);
Pane pane = new Pane();
BackgroundImage myBG= new BackgroundImage(image,
BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
BackgroundSize.DEFAULT);
pane.setBackground(new Background(myBG));
Rectangle r[] = new Rectangle[81];
for (int i=1; i<10 ; i++) {
for (int j=1; j < 10 ; j++) {
r[i] = new Rectangle(i*52+336,j*52+15,50,50);
r[i].setFill(realColor.TRANSPARENT);
r[i].setStroke(realColor.BLACK);
pane.getChildren().add(r[i]);
System.out.println(r[i]);
}
}
root.setCenter(pane);
//--------------------------------------------------------------------------------------
//Deck
@ -64,22 +100,109 @@ public class LaticeApplicationWindow extends Application{
//--------------------------------------------------------------------------------------
//Rack
//Without Image
HBox rack = new HBox();
HBox rackBox = new HBox();
rackBox.setSpacing(10);
rackBox.setPadding(new Insets(15,20, 10,10));
ArrayList<Tile> listOfTile = new ArrayList<Tile>();
System.out.println("Hello Latice !");
for (Color color : Color.values()) {
for (Shape shape : Shape.values()) {
Tile tile = new Tile(color, shape);
listOfTile.add(tile);
}
}
System.out.println("-----------------");
System.out.println("Notre Deck :");
Deck deck = new Deck(listOfTile);
System.out.println("-----------------");
Rack rack = new Rack(deck);
System.out.println("-----------------");
//deck.displayListTile();
ArrayList<Tile> listRackTile = Rack.getListRackTile();
rack.setSpacing(10);
rack.setPadding(new Insets(15,20, 10,10));
Text rackTile1 = new Text();
rackTile1.setText(blueBird.getShape().toString() + blueBird.getColor());
rackTile1.setText(listRackTile.get(0).getShape().toString() + listRackTile.get(0).getColor().toString());
Text rackTile2 = new Text();
rackTile2.setText(greenLeaf.getShape().toString() + greenLeaf.getColor());
rackTile2.setText(listRackTile.get(1).getShape().toString() + listRackTile.get(1).getColor().toString());
Text rackTile3 = new Text();
rackTile3.setText(redFlower.getShape().toString() + redFlower.getColor());
rackTile3.setText(listRackTile.get(2).getShape().toString() + listRackTile.get(2).getColor().toString());
Text rackTile4 = new Text();
rackTile4.setText(listRackTile.get(3).getShape().toString() + listRackTile.get(3).getColor().toString());
Text rackTile5 = new Text();
rackTile5.setText(listRackTile.get(4).getShape().toString() + listRackTile.get(4).getColor().toString());
rackTile1.setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
Dragboard dragboard = rackTile1.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.putString("Hello !");
dragboard.setContent(content);
arg0.consume();
}
});
ImagePattern imagePattern = new ImagePattern(image);
r[1].setOnDragEntered(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent arg0) {
if (arg0.getDragboard().hasString()){
r[1].setFill(imagePattern);
}
arg0.consume();
}
});
r[1].setOnDragExited(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent arg0) {
r[1].setFill(realColor.BLUE);
arg0.consume();
}
});
r[1].setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent arg0) {
System.out.println("entered");
Dragboard dragboard = arg0.getDragboard();
boolean success = false;
r[1].setFill(imagePattern);
System.out.println("got files :" + dragboard.getFiles());
if (dragboard.hasString()){
success = true;
r[1].setFill(imagePattern);
}
arg0.setDropCompleted(success);
arg0.consume();
}
});
rackBox.getChildren().addAll(rackTile1, rackTile2, rackTile3, rackTile4, rackTile5);
rackBox.setAlignment(Pos.CENTER);
root.setBottom(rackBox);
root.setPadding(new Insets(20,20,20,20));
rack.getChildren().addAll(rackTile1, rackTile2, rackTile3);
rack.setAlignment(Pos.CENTER);
root.setBottom(rack);
//With Image
Rack rack2 = new Rack(deck);
@ -92,6 +215,7 @@ public class LaticeApplicationWindow extends Application{
Scene scene = new Scene(root, 1280, 720);
//primaryStage.setResizable(false);
primaryStage.setTitle("Latice");
primaryStage.setScene(scene);
primaryStage.show();

View File

@ -10,7 +10,7 @@ import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
public class Rack {
private ArrayList<Tile> listRackTile = new ArrayList<Tile>();
private static ArrayList<Tile> listRackTile = new ArrayList<Tile>();
public Rack(Deck deck) {
@ -35,6 +35,15 @@ public class Rack {
System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs");
}
public static ArrayList<Tile> getListRackTile() {
return listRackTile;
}
public void setListRackTile(ArrayList<Tile> listRackTile) {
this.listRackTile = listRackTile;
}