From a6dd92269a6c60cbc29a6ade4dcf37af9c1f2e98 Mon Sep 17 00:00:00 2001 From: Mysaa Date: Sun, 23 May 2021 20:59:39 +0200 Subject: [PATCH] =?UTF-8?q?Premier=20commit=20-=20Inclusion=20dans=20le=20?= =?UTF-8?q?syst=C3=A8me=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 + src/com/bernard/inutil/BinarYnutil.java | 13 ++++ src/com/bernard/math/geom/Figure.java | 7 ++ src/com/bernard/math/geom/Map2D.java | 5 ++ src/com/bernard/math/geom/Point.java | 9 +++ src/com/bernard/util/BaseFrame.java | 76 ++++++++++++++++++ src/com/bernard/util/ConfiguredFrame.java | 95 +++++++++++++++++++++++ src/com/bernard/util/ErrorDialog.java | 38 +++++++++ 8 files changed, 247 insertions(+) create mode 100644 .gitignore create mode 100644 src/com/bernard/inutil/BinarYnutil.java create mode 100644 src/com/bernard/math/geom/Figure.java create mode 100644 src/com/bernard/math/geom/Map2D.java create mode 100644 src/com/bernard/math/geom/Point.java create mode 100644 src/com/bernard/util/BaseFrame.java create mode 100644 src/com/bernard/util/ConfiguredFrame.java create mode 100644 src/com/bernard/util/ErrorDialog.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c04a4e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.classpath +.project +.settings/ +bin/ diff --git a/src/com/bernard/inutil/BinarYnutil.java b/src/com/bernard/inutil/BinarYnutil.java new file mode 100644 index 0000000..d5f3ef5 --- /dev/null +++ b/src/com/bernard/inutil/BinarYnutil.java @@ -0,0 +1,13 @@ +package com.bernard.inutil; + +public class BinarYnutil { + + public static int concat(byte b1,byte b2,byte b3,byte b4) { + return (int)b1 << 0x30 + (int)b2 << 0x20 + (int)b3 << 0x10 + (int)b4; + } + public static int concatInt(byte... data) { + assert data.length ==4; + return concat(data[0],data[1],data[2],data[3]); + } + +} diff --git a/src/com/bernard/math/geom/Figure.java b/src/com/bernard/math/geom/Figure.java new file mode 100644 index 0000000..602654c --- /dev/null +++ b/src/com/bernard/math/geom/Figure.java @@ -0,0 +1,7 @@ +package com.bernard.math.geom; + +public interface Figure { + + public boolean appartient(Point p); + +} diff --git a/src/com/bernard/math/geom/Map2D.java b/src/com/bernard/math/geom/Map2D.java new file mode 100644 index 0000000..3dd83c6 --- /dev/null +++ b/src/com/bernard/math/geom/Map2D.java @@ -0,0 +1,5 @@ +package com.bernard.math.geom; + +public class Map2D { + double[] data; +} diff --git a/src/com/bernard/math/geom/Point.java b/src/com/bernard/math/geom/Point.java new file mode 100644 index 0000000..76f259c --- /dev/null +++ b/src/com/bernard/math/geom/Point.java @@ -0,0 +1,9 @@ +package com.bernard.math.geom; + +public class Point { + + double[] coords; + + + +} diff --git a/src/com/bernard/util/BaseFrame.java b/src/com/bernard/util/BaseFrame.java new file mode 100644 index 0000000..501ab4f --- /dev/null +++ b/src/com/bernard/util/BaseFrame.java @@ -0,0 +1,76 @@ +package com.bernard.util; + +import java.awt.Dimension; +import java.awt.event.ActionListener; + +import javax.swing.JFrame; + +public abstract class BaseFrame extends JFrame implements ActionListener +{ + + /** + * Just for eclipse to shut up + */ + private static final long serialVersionUID = -2440841592914910177L; + + /** + * Create and show a frame which is centered and which has the + * EXIT_ON_CLOSE default close operation with the given parameters + * @param title The frame's title + * @param width The frame width + * @param height The frame height + */ + public BaseFrame(String title, int width, int height) + { + this(title, width, height, true); + } + + /** + * Create and show a frame which is centered and which has the + * EXIT_ON_CLOSE default close operation with the given parameters + * @param title The frame's title + * @param dimension The frame dimensions (int casted) + */ + public BaseFrame(String title, Dimension dimension) + { + this(title, dimension, true); + } + + /** + * Create a frame which is centered and which has the + * EXIT_ON_CLOSE default close operation with the given parameters + * @param title The frame's title + * @param dimension The frame dimensions (int casted) + * @param visible Must the frame be visible once constructed ? + */ + public BaseFrame(String title, Dimension dimension, boolean visible) + { + this(title, (int)dimension.getWidth(), (int)dimension.getHeight(), visible); + } + + /** + * Create a frame which is centered and which has the + * EXIT_ON_CLOSE default close operation with the given parameters + * @param title The frame's title + * @param width The frame width + * @param height The frame height + * @param visible Must the frame be visible once constructed ? + */ + public BaseFrame(String title, int width, int height, boolean visible) + { + this.setTitle(title); + this.setSize(width, height); + this.setLocationRelativeTo(null); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + init(); + + this.setVisible(visible); + } + + /** + * In this method, do all the stuff for drawing components (pannels,layouts) an make them active (Listeners) + */ + public abstract void init(); + +} diff --git a/src/com/bernard/util/ConfiguredFrame.java b/src/com/bernard/util/ConfiguredFrame.java new file mode 100644 index 0000000..9c6e7ab --- /dev/null +++ b/src/com/bernard/util/ConfiguredFrame.java @@ -0,0 +1,95 @@ +package com.bernard.util; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.io.FileNotFoundException; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + +import org.ho.yaml.Yaml; + +public abstract class ConfiguredFrame extends JFrame implements ActionListener { + + /** + * Just for eclipse to shut up + */ + private static final long serialVersionUID = -2440841592914910177L; + private final String defaultConfigPath = "config.yml"; + private Configuration config = getConfig(); + private Class configurationClass; + + public ConfiguredFrame(String title,int width,int height,Class configClass) { + configurationClass = configClass; + this.setTitle(title); + this.setSize(width,height); + this.setLocationRelativeTo(null); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent arg0) { + super.windowClosing(arg0); + end(); + } + }); + + init(); + + this.setVisible(true); + } + + public abstract void init(); + + /** + * To be overrided : default output : "config.yml" + * @return the yaml config file path (relative or absolute) + */ + public String getConfigPath(){ + return "config.yml"; + } + + @SuppressWarnings("unchecked")//Les tests sont faits + public Configuration getConfig(){ + File configFile = new File(getConfigPath()); + if(configFile.exists()){ + Configuration out; + try { + out = (Configuration)Yaml.load(configFile); + return out; + } catch (FileNotFoundException e) {//TODO add others errors witch need to be catched + error("Fichier non trouvé", "Le fichier n'a pas été trouvé"); + }catch(ClassCastException e){ + error("Fichier corrompu","Le fichier de configuration (\""+configFile.getPath()+"\") est corrompu : supprimez ou remplacez le"); + } + }else{ + try { + return (Configuration) configurationClass.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + error("Impossible de créer le fichier de configuration","La configuration n'a pas pu être créée : verifiez que le paramêtre configClass représente une classe accessible et instanciable sans arguments."); + } catch (ClassCastException e) { + error("Non correspondance","Le type génerique \"Configuration\" et l'objet configurationClass ne correspondent pas"); + } + } + return null; + } + + private void error(String title,String description){ + JOptionPane.showMessageDialog(null,description,title,JOptionPane.ERROR_MESSAGE); + System.exit(0); + } + + public void end(){ + try { + Yaml.dump(config, new File(defaultConfigPath)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + @Override + public abstract void actionPerformed(ActionEvent e); + +} diff --git a/src/com/bernard/util/ErrorDialog.java b/src/com/bernard/util/ErrorDialog.java new file mode 100644 index 0000000..fec0bbb --- /dev/null +++ b/src/com/bernard/util/ErrorDialog.java @@ -0,0 +1,38 @@ +package com.bernard.util; + +import java.awt.Frame; + +import javax.swing.JDialog; + +public class ErrorDialog extends JDialog{ + + /** + * JFESU + */ + private static final long serialVersionUID = 5223556105926415144L; + + private Exception exception; + + public ErrorDialog(Exception e,Frame f) { + super(f,"A "+e.getClass().getName()+" occured",true); + exception = e; + this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); + this.setSize(500, 200); + this.setResizable(false); + this.setLocationRelativeTo(null); + this.setVisible(false); + this.initComponent(); + } + private void initComponent() { + // TODO Auto-generated method stub + + } + public ErrorDialog(Exception e) { + this(e,null); + } + + + + + +}