diff --git a/.gitignore b/.gitignore index 3f7ec60..a6739c9 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ local.properties # Locally stored "Eclipse launch configurations" *.launch /.clover/ + +#others +*.iml \ No newline at end of file diff --git a/SHdb.sql b/SHdb.sql deleted file mode 100644 index 8c6e6d7..0000000 Binary files a/SHdb.sql and /dev/null differ diff --git a/shDBlatest.sql b/shDBlatest.sql new file mode 100644 index 0000000..ec90c5a Binary files /dev/null and b/shDBlatest.sql differ diff --git a/src/database/ByteaToCardImage.java b/src/database/ByteaToCardImage.java index a3983bd..22ad585 100644 --- a/src/database/ByteaToCardImage.java +++ b/src/database/ByteaToCardImage.java @@ -1,20 +1,62 @@ package database; +/** + * @author James Thompson + * @source https://gist.github.com/jamesthompson/3344090 + * @date 08/12/2012 + **/ + import java.io.ByteArrayInputStream; import java.awt.image.BufferedImage; import java.io.IOException; +import javafx.scene.image.Image; import javax.imageio.ImageIO; +import java.awt.image.*; +import java.io.ByteArrayOutputStream; public class ByteaToCardImage { - public static BufferedImage getImg(byte[] imageData) { - ByteArrayInputStream bais = new ByteArrayInputStream(imageData); + public static Image getJavaFXImage(byte[] rawPixels) { + //public Image getJavaFXImage(byte[] rawPixels, int width, int height) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); try { - return ImageIO.read(bais); - } catch (IOException e) { - throw new RuntimeException(e); + ImageIO.write((RenderedImage) createBufferedImage(rawPixels, 467, 652), "png", out); + //ImageIO.write((RenderedImage) createBufferedImage(rawPixels, width, height), "png", out); + out.flush(); + } catch (IOException ex) { + } + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + return new javafx.scene.image.Image(in); } + + private static BufferedImage createBufferedImage(byte[] pixels, int width, int height) { + SampleModel sm = getIndexSampleModel(width, height); + DataBuffer db = new DataBufferByte(pixels, width*height, 0); + WritableRaster raster = Raster.createWritableRaster(sm, db, null); + IndexColorModel cm = getDefaultColorModel(); + BufferedImage image = new BufferedImage(cm, raster, false, null); + return image; } + private static SampleModel getIndexSampleModel(int width, int height) { + IndexColorModel icm = getDefaultColorModel(); + WritableRaster wr = icm.createCompatibleWritableRaster(1, 1); + SampleModel sampleModel = wr.getSampleModel(); + sampleModel = sampleModel.createCompatibleSampleModel(width, height); + return sampleModel; + } + + private static IndexColorModel getDefaultColorModel() { + byte[] r = new byte[256]; + byte[] g = new byte[256]; + byte[] b = new byte[256]; + for(int i=0; i<256; i++) { + r[i]=(byte)i; + g[i]=(byte)i; + b[i]=(byte)i; + } + IndexColorModel defaultColorModel = new IndexColorModel(8, 256, r, g, b); + return defaultColorModel; + } } \ No newline at end of file diff --git a/src/database/DatabaseTesting.java b/src/database/DatabaseTesting.java index e5aad7c..e89a2cf 100644 --- a/src/database/DatabaseTesting.java +++ b/src/database/DatabaseTesting.java @@ -1,6 +1,13 @@ package database; import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.imageio.ImageIO; + +import javafx.scene.image.Image; /* import java.sql.Connection; @@ -11,21 +18,25 @@ import java.sql.Statement; */ public class DatabaseTesting { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { Table a = new Table("a"); a.remplirTableAllFrom("CartesAll"); System.out.println(a.toString()); - BufferedImage jpg = new BufferedImage(467, 652, 1); + Image image = ByteaToCardImage.getJavaFXImage(a.getList().get(1).getImg()); + System.out.println(image); - /* - try { - ByteaToCardImage.getImg(a.getList().get(5).getImg()); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - */ + //a.getList().get(1).getImg(); + + } + + public BufferedImage createImageFromBytes(byte[] imageData) { + ByteArrayInputStream bais = new ByteArrayInputStream(imageData); + try { + return ImageIO.read(bais); + } catch (IOException e) { + throw new RuntimeException(e); + } diff --git a/src/ihm/.gitkeep b/src/ihm/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/tmpmeth/DamageCalculator.java b/src/tmpmeth/DamageCalculator.java deleted file mode 100644 index 65e71d9..0000000 --- a/src/tmpmeth/DamageCalculator.java +++ /dev/null @@ -1,13 +0,0 @@ -package tmpmeth; - -public class DamageCalculator { - - public static int calculDamage(Dice d6, Dice d4) { - int r = d6.roll() - d4.roll(); - if(r < 0) { - r = 0; - } - return r; - } -} - diff --git a/src/tmpmeth/Dice.java b/src/tmpmeth/Dice.java deleted file mode 100644 index 54d6040..0000000 --- a/src/tmpmeth/Dice.java +++ /dev/null @@ -1,24 +0,0 @@ -package tmpmeth; -import java.lang.Math; - -public class Dice { - - private int max; - - public Dice() { - this(0); - } - - public Dice(int m) { - this.max = m; - } - - public int roll() { - return (int)((max)*Math.random())+1; - } - - public int getMax() { - return this.max; - } - -} diff --git a/src/tmpmeth/start.java b/src/tmpmeth/start.java deleted file mode 100644 index bb2c7d8..0000000 --- a/src/tmpmeth/start.java +++ /dev/null @@ -1,13 +0,0 @@ -package tmpmeth; - -public class start { - - public static void main(String[] args) { - // TODO Auto-generated method stub - Dice d4 = new Dice(4); - Dice d6 = new Dice(6); - - System.out.println(DamageCalculator.calculDamage(d6, d4)); - - } -} diff --git a/tests/database/TestDatabse.java b/tests/database/TestDatabse.java index 6b54c00..ab7520b 100644 --- a/tests/database/TestDatabse.java +++ b/tests/database/TestDatabse.java @@ -21,11 +21,12 @@ public class TestDatabse { @AfterEach private void free() { + System.gc(); System.out.println("=====Fin du test=====\n\n\n"); } @Test - private void testDBConnexion() { + void testDBConnexion() { try (Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/ShadowHunterDatabase", "shManager", "shadowhunter1234")) { //notre utilisateur que l'on utilisera (: System.out.println("Connected to PostgreSQL database!"); @@ -36,8 +37,45 @@ public class TestDatabse { } @Test - private void getEntireTableCartesLumiere() { + void getEntireTableCartesLumiere() { + System.out.println("Test getEntireTableCartesLumiere"); t.remplirTableAllFrom("CartesLumiere"); Assert.assertFalse(t.isEmpty()); } + + @Test + void getEntireTableCartesTenebre() { + System.out.println("Test getEntireTableCartesTenebre"); + t.remplirTableAllFrom("CartesTenebre"); + Assert.assertFalse(t.isEmpty()); + } + + @Test + void getEntireTableCartesVision() { + System.out.println("Test getEntireTableCartesVision"); + t.remplirTableAllFrom("CartesVision"); + Assert.assertFalse(t.isEmpty()); + } + + @Test + void getEntireTableCartesPersonnage() { + System.out.println("Test getEntireTableCartesPersonnage"); + t.remplirTableAllFrom("CartesPersonnage"); + Assert.assertFalse(t.isEmpty()); + } + + @Test + void getEntireTableCartesDos() { + System.out.println("Test getEntireTableCartesDos"); + t.remplirTableAllFrom("CartesDos"); + Assert.assertFalse(t.isEmpty()); + } + + @Test + void getEntireTableCartesAll() { + System.out.println("Test getEntireTableCartesAll"); + t.remplirTableAllFrom("CartesAll"); + Assert.assertFalse(t.isEmpty()); + } + }