Premier commit - Inclusion dans le système git
This commit is contained in:
commit
a6dd92269a
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
bin/
|
||||
13
src/com/bernard/inutil/BinarYnutil.java
Normal file
13
src/com/bernard/inutil/BinarYnutil.java
Normal file
@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
7
src/com/bernard/math/geom/Figure.java
Normal file
7
src/com/bernard/math/geom/Figure.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.bernard.math.geom;
|
||||
|
||||
public interface Figure {
|
||||
|
||||
public boolean appartient(Point p);
|
||||
|
||||
}
|
||||
5
src/com/bernard/math/geom/Map2D.java
Normal file
5
src/com/bernard/math/geom/Map2D.java
Normal file
@ -0,0 +1,5 @@
|
||||
package com.bernard.math.geom;
|
||||
|
||||
public class Map2D {
|
||||
double[] data;
|
||||
}
|
||||
9
src/com/bernard/math/geom/Point.java
Normal file
9
src/com/bernard/math/geom/Point.java
Normal file
@ -0,0 +1,9 @@
|
||||
package com.bernard.math.geom;
|
||||
|
||||
public class Point {
|
||||
|
||||
double[] coords;
|
||||
|
||||
|
||||
|
||||
}
|
||||
76
src/com/bernard/util/BaseFrame.java
Normal file
76
src/com/bernard/util/BaseFrame.java
Normal file
@ -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<Configuration> 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();
|
||||
|
||||
}
|
||||
95
src/com/bernard/util/ConfiguredFrame.java
Normal file
95
src/com/bernard/util/ConfiguredFrame.java
Normal file
@ -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<Configuration> 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);
|
||||
|
||||
}
|
||||
38
src/com/bernard/util/ErrorDialog.java
Normal file
38
src/com/bernard/util/ErrorDialog.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user