update database #4

This commit is contained in:
JunkJumper 2020-05-04 13:41:10 +02:00
parent 80a0c89d49
commit e0b965af5f
10 changed files with 111 additions and 67 deletions

3
.gitignore vendored
View File

@ -41,3 +41,6 @@ local.properties
# Locally stored "Eclipse launch configurations"
*.launch
/.clover/
#others
*.iml

BIN
SHdb.sql

Binary file not shown.

BIN
shDBlatest.sql Normal file

Binary file not shown.

View File

@ -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;
}
}

View File

@ -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);
}

View File

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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));
}
}

View File

@ -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());
}
}