From 16db96f88760ec15b46927aefc38ff6334563312 Mon Sep 17 00:00:00 2001 From: mathi Date: Sat, 23 Apr 2022 16:05:32 +0200 Subject: [PATCH 1/4] STEP 1 : ADD Deck and Rack classes with UPDATE LaticeApplicationConsole --- .../application/LaticeApplicationConsole.java | 11 ++++++---- src/main/java/latice/model/Deck.java | 8 ++++++- src/main/java/latice/model/Rack.java | 21 ++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index 5f94db2..ad11012 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import latice.model.Color; import latice.model.Deck; +import latice.model.Rack; import latice.model.Shape; import latice.model.Tile; @@ -18,18 +19,20 @@ public class LaticeApplicationConsole { for (Color color : Color.values()) { for (Shape shape : Shape.values()) { Tile tile = new Tile(color, shape); - System.out.println("tuile : couleur = " + tile.getColor() + " forme = " + tile.getShape()); + listOfTile.add(tile); } } - + System.out.println("-----------------"); System.out.println("Notre Deck :"); Deck deck = new Deck(listOfTile); - deck.getListTile(); + deck.displayListTile(); System.out.println("-----------------"); - + Rack rack = new Rack(deck); + System.out.println("-----------------"); + deck.displayListTile(); diff --git a/src/main/java/latice/model/Deck.java b/src/main/java/latice/model/Deck.java index df59de1..39b4449 100644 --- a/src/main/java/latice/model/Deck.java +++ b/src/main/java/latice/model/Deck.java @@ -9,12 +9,18 @@ public class Deck { this.deckTile = deckTile; } - public void getListTile() { + public void displayListTile() { for (Tile tile : deckTile) { System.out.println("tuile : couleur = " + tile.getColor() + " forme = " + tile.getShape()); } } + + public ArrayList getListTile() { + return this.deckTile; + } + + } diff --git a/src/main/java/latice/model/Rack.java b/src/main/java/latice/model/Rack.java index f4af62f..36f0e60 100644 --- a/src/main/java/latice/model/Rack.java +++ b/src/main/java/latice/model/Rack.java @@ -5,17 +5,24 @@ import java.util.ArrayList; public class Rack { private ArrayList listRackTile = new ArrayList(); - public Rack(ArrayList deck) { + public Rack(Deck deck) { + System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); + for (int i = 0; i < 5; i++) { - int index = (int)(Math.random()*(deck.size()-0+1)+0); - listRackTile.add(deck.get(index)); - System.out.println("l'indice de la tuile ajouté au rack est : " + index + " qui est la tuile " + deck.get(index)); + int index = (int)(Math.random()*((deck.getListTile()).size()-0+1)+0); //(int)(Math.random()*(max-min+1)+min); + listRackTile.add((deck.getListTile()).get(index)); + System.out.println("l'indice de la tuile ajouté au rack est : " + index + + " qui est la tuile : couleur = " + (deck.getListTile()).get(index).getColor() + + " forme = " + (deck.getListTile()).get(index).getShape()); + deck.getListTile().remove(index); } - + System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); } + + + // TODO add method(s) javafx + } - -//(int)(Math.random()*(max-min+1)+min); \ No newline at end of file From b056b09aac61ec412630fcf8d6462f05d35a6066 Mon Sep 17 00:00:00 2001 From: cemal Date: Sun, 24 Apr 2022 15:12:45 +0200 Subject: [PATCH 2/4] Added Rack view in JavaFX --- .../application/LaticeApplicationWindow.java | 53 +++++++++++++++---- src/main/java/latice/model/Rack.java | 11 +++- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 9c8afa6..5219ab9 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -1,6 +1,7 @@ package latice.application; import java.io.File; +import java.util.ArrayList; import javafx.application.Application; import javafx.geometry.Insets; @@ -15,6 +16,8 @@ import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; import latice.model.Color; +import latice.model.Deck; +import latice.model.Rack; import latice.model.Shape; import latice.model.Tile; @@ -23,6 +26,8 @@ public class LaticeApplicationWindow extends Application{ Image image = new Image("C:/Users/cemal/saebut1/latice/src/main/resources/laticePlateau.png"); ImageView imageView = new ImageView(image); + + Tile blueBird = new Tile(Color.BLUE, Shape.BIRD); Tile greenLeaf = new Tile(Color.GREEN, Shape.LEAF); Tile redFlower = new Tile(Color.RED, Shape.FLOWER); @@ -45,21 +50,51 @@ public class LaticeApplicationWindow extends Application{ root.setCenter(imageView); //Rack - HBox rack = new HBox(); + HBox rackBox = new HBox(); + + rackBox.setSpacing(10); + rackBox.setPadding(new Insets(15,20, 10,10)); + + + ArrayList listOfTile = new ArrayList(); + + 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 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()); - rack.getChildren().addAll(rackTile1, rackTile2, rackTile3); - rack.setAlignment(Pos.CENTER); - root.setBottom(rack); + rackBox.getChildren().addAll(rackTile1, rackTile2, rackTile3, rackTile4, rackTile5); + rackBox.setAlignment(Pos.CENTER); + root.setBottom(rackBox); Scene scene = new Scene(root, 1280, 720); diff --git a/src/main/java/latice/model/Rack.java b/src/main/java/latice/model/Rack.java index 36f0e60..77da402 100644 --- a/src/main/java/latice/model/Rack.java +++ b/src/main/java/latice/model/Rack.java @@ -3,7 +3,7 @@ package latice.model; import java.util.ArrayList; public class Rack { - private ArrayList listRackTile = new ArrayList(); + private static ArrayList listRackTile = new ArrayList(); public Rack(Deck deck) { System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); @@ -20,6 +20,15 @@ public class Rack { System.out.println("Il y a dans le rack : " + listRackTile.size() + " valeurs"); } + + public static ArrayList getListRackTile() { + return listRackTile; + } + + public void setListRackTile(ArrayList listRackTile) { + this.listRackTile = listRackTile; + } + // TODO add method(s) javafx From a959e044d67c86bc0ac259a0d34cb5c28551a921 Mon Sep 17 00:00:00 2001 From: cemal Date: Tue, 26 Apr 2022 15:12:14 +0200 Subject: [PATCH 3/4] WIP adding rectangles for drag n drop --- .../application/LaticeApplicationConsole.java | 5 +++ .../application/LaticeApplicationWindow.java | 44 +++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/main/java/latice/application/LaticeApplicationConsole.java b/src/main/java/latice/application/LaticeApplicationConsole.java index ad11012..6836f32 100644 --- a/src/main/java/latice/application/LaticeApplicationConsole.java +++ b/src/main/java/latice/application/LaticeApplicationConsole.java @@ -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; @@ -24,6 +27,8 @@ public class LaticeApplicationConsole { } } + + System.out.println("-----------------"); System.out.println("Notre Deck :"); diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 5219ab9..0ec9ff2 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -1,6 +1,5 @@ package latice.application; -import java.io.File; import java.util.ArrayList; import javafx.application.Application; @@ -9,9 +8,16 @@ import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +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.GridPane; import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; +import javafx.scene.layout.Pane; +import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; @@ -23,6 +29,8 @@ import latice.model.Tile; public class LaticeApplicationWindow extends Application{ + javafx.scene.paint.Color realColor = new javafx.scene.paint.Color(0, 0, 0, 0); + Image image = new Image("C:/Users/cemal/saebut1/latice/src/main/resources/laticePlateau.png"); ImageView imageView = new ImageView(image); @@ -47,7 +55,31 @@ public class LaticeApplicationWindow extends Application{ root.setAlignment(title, Pos.CENTER); //Image - root.setCenter(imageView); + Rectangle rectangle = new Rectangle(); + + rectangle.setWidth(50); + rectangle.setHeight(50); + //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)); + pane.getChildren().add(rectangle); + + for (int i=0; i<450 ;i += 50) { + for (int j=0; j < 450 ; j += 50) { + Rectangle r = new Rectangle(i,j,50,50); + r.setFill(realColor.TRANSPARENT); + r.setStroke(realColor.BLACK); + + pane.getChildren().add(r); + } + } + pane.setLayoutX(100); + pane.setLayoutY(50); + root.setCenter(pane); //Rack HBox rackBox = new HBox(); @@ -91,14 +123,18 @@ public class LaticeApplicationWindow extends Application{ 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()); - + + rackBox.getChildren().addAll(rackTile1, rackTile2, rackTile3, rackTile4, rackTile5); rackBox.setAlignment(Pos.CENTER); root.setBottom(rackBox); + root.setPadding(new Insets(20,20,20,20)); + Scene scene = new Scene(root, 1280, 720); + primaryStage.setResizable(false); primaryStage.setTitle("Latice"); primaryStage.setScene(scene); primaryStage.show(); From 6780348413aeb7abc5e659c0ea4f82c91130cca5 Mon Sep 17 00:00:00 2001 From: cemal Date: Thu, 28 Apr 2022 17:01:47 +0200 Subject: [PATCH 4/4] Added improvments to drag&drop(only for one tile) --- .../application/LaticeApplicationWindow.java | 89 +++++++++++++++---- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/src/main/java/latice/application/LaticeApplicationWindow.java b/src/main/java/latice/application/LaticeApplicationWindow.java index 0ec9ff2..478480c 100644 --- a/src/main/java/latice/application/LaticeApplicationWindow.java +++ b/src/main/java/latice/application/LaticeApplicationWindow.java @@ -3,20 +3,26 @@ 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.GridPane; 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; @@ -55,10 +61,7 @@ public class LaticeApplicationWindow extends Application{ root.setAlignment(title, Pos.CENTER); //Image - Rectangle rectangle = new Rectangle(); - rectangle.setWidth(50); - rectangle.setHeight(50); //rectangle.setFill(realColor.TRANSPARENT); Pane pane = new Pane(); @@ -66,19 +69,20 @@ public class LaticeApplicationWindow extends Application{ BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT); pane.setBackground(new Background(myBG)); - pane.getChildren().add(rectangle); - - for (int i=0; i<450 ;i += 50) { - for (int j=0; j < 450 ; j += 50) { - Rectangle r = new Rectangle(i,j,50,50); - r.setFill(realColor.TRANSPARENT); - r.setStroke(realColor.BLACK); - pane.getChildren().add(r); + + 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]); } } - pane.setLayoutX(100); - pane.setLayoutY(50); + root.setCenter(pane); //Rack @@ -125,6 +129,60 @@ public class LaticeApplicationWindow extends Application{ rackTile5.setText(listRackTile.get(4).getShape().toString() + listRackTile.get(4).getColor().toString()); + rackTile1.setOnDragDetected(new EventHandler() { + + @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() { + + @Override + public void handle(DragEvent arg0) { + if (arg0.getDragboard().hasString()){ + r[1].setFill(imagePattern); + } + arg0.consume(); + } + }); + + r[1].setOnDragExited(new EventHandler() { + + @Override + public void handle(DragEvent arg0) { + r[1].setFill(realColor.BLUE); + arg0.consume(); + } + + }); + + r[1].setOnDragDropped(new EventHandler() { + @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); @@ -132,9 +190,10 @@ public class LaticeApplicationWindow extends Application{ + Scene scene = new Scene(root, 1280, 720); - primaryStage.setResizable(false); + //primaryStage.setResizable(false); primaryStage.setTitle("Latice"); primaryStage.setScene(scene); primaryStage.show();