From 0d76df4ea4e437395e7502e6e94e30f21af8cbb5 Mon Sep 17 00:00:00 2001 From: Mysaa Date: Thu, 27 May 2021 21:24:28 +0200 Subject: [PATCH] =?UTF-8?q?Premier=20commit=20-=20Introduction=20au=20syst?= =?UTF-8?q?=C3=A8me=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 + src/com/bernard/cercloide/TestDistance.java | 110 +++ src/com/bernard/cercloide/ViewUtil.java | 29 + .../bernard/cercloide/colorset/ColorSet.java | 151 ++++ .../cercloide/factory/ImageCreator.java | 731 ++++++++++++++++++ .../cercloide/factory/JOptPaneCreator.java | 18 + .../factory/LoopingImageCreator.java | 61 ++ .../cercloide/factory/NumberAnalyser.java | 67 ++ .../cercloide/factory/RunnerFactory.java | 28 + src/com/bernard/cercloide/main/Config.java | 10 + src/com/bernard/cercloide/main/Main.java | 36 + src/com/bernard/cercloide/main/Sprach.java | 10 + .../cercloide/theory/PointIterator.java | 29 + .../cercloide/theory/iter/IterEnsemble.java | 80 ++ .../cercloide/theory/iter/IterIntervale.java | 115 +++ .../cercloide/theory/iter/IterOptions.java | 8 + .../bernard/cercloide/theory/plan/Point.java | 136 ++++ .../varSets/CercloidWithGradientArgs.java | 168 ++++ .../bernard/cercloide/view/LoopSetFrame2.java | 357 +++++++++ .../bernard/cercloide/view/LoopUtilFrame.java | 102 +++ .../cercloide/view/LoopUtilVarSet.java | 557 +++++++++++++ src/com/bernard/cercloide/view/MainFrame.java | 87 +++ .../cercloide/view/SelectPointsPos.java | 314 ++++++++ .../bernard/cercloide/view/VarSetFrame.java | 531 +++++++++++++ .../cercloide/view/ViewDrawingProgress.java | 37 + src/com/bernard/cercloide/view/WaitFrame.java | 28 + 26 files changed, 3805 insertions(+) create mode 100644 .gitignore create mode 100644 src/com/bernard/cercloide/TestDistance.java create mode 100644 src/com/bernard/cercloide/ViewUtil.java create mode 100644 src/com/bernard/cercloide/colorset/ColorSet.java create mode 100644 src/com/bernard/cercloide/factory/ImageCreator.java create mode 100644 src/com/bernard/cercloide/factory/JOptPaneCreator.java create mode 100644 src/com/bernard/cercloide/factory/LoopingImageCreator.java create mode 100644 src/com/bernard/cercloide/factory/NumberAnalyser.java create mode 100644 src/com/bernard/cercloide/factory/RunnerFactory.java create mode 100644 src/com/bernard/cercloide/main/Config.java create mode 100644 src/com/bernard/cercloide/main/Main.java create mode 100644 src/com/bernard/cercloide/main/Sprach.java create mode 100644 src/com/bernard/cercloide/theory/PointIterator.java create mode 100644 src/com/bernard/cercloide/theory/iter/IterEnsemble.java create mode 100644 src/com/bernard/cercloide/theory/iter/IterIntervale.java create mode 100644 src/com/bernard/cercloide/theory/iter/IterOptions.java create mode 100644 src/com/bernard/cercloide/theory/plan/Point.java create mode 100644 src/com/bernard/cercloide/varSets/CercloidWithGradientArgs.java create mode 100644 src/com/bernard/cercloide/view/LoopSetFrame2.java create mode 100644 src/com/bernard/cercloide/view/LoopUtilFrame.java create mode 100644 src/com/bernard/cercloide/view/LoopUtilVarSet.java create mode 100644 src/com/bernard/cercloide/view/MainFrame.java create mode 100644 src/com/bernard/cercloide/view/SelectPointsPos.java create mode 100644 src/com/bernard/cercloide/view/VarSetFrame.java create mode 100644 src/com/bernard/cercloide/view/ViewDrawingProgress.java create mode 100644 src/com/bernard/cercloide/view/WaitFrame.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e53caa --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.classpath +.metadata +.project +.settings +bin/ diff --git a/src/com/bernard/cercloide/TestDistance.java b/src/com/bernard/cercloide/TestDistance.java new file mode 100644 index 0000000..c682bfd --- /dev/null +++ b/src/com/bernard/cercloide/TestDistance.java @@ -0,0 +1,110 @@ +package com.bernard.cercloide; + +import static java.lang.Math.abs; +import static java.lang.Math.pow; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.bernard.cercloide.theory.plan.Point; + +/** + * + * @author Zlopeg + * @version 0.893 + */ +public class TestDistance { + + public static double getDistance(Point A, Point[] F, double P) { + double sigmaN = 0.0d, sigmaD = 0.0d; + int N = F.length, D = A.getCoords().length, Dmax = D; + + for (int n = 0; n < N; n++) { + if (F[n].coords.length != D) { + int[] change = new int[Dmax]; + if (F[n].coords.length != Dmax) { + for (int dm = 0; dm < Dmax; dm++) + change[dm] = (dm < F[n].coords.length) ? (F[n].getCoord(dm + 1)) : 0; + F[n].coords = change; + } + } + if (F[n].coords.length > Dmax) { + System.out.println("Dmax passe de " + Dmax + " à " + F[n].coords.length); + Dmax = F[n].coords.length; + } + } + + for (int n = 0; n < N; n++) { + sigmaD = 0.0d; + for (int d = 1; d <= D; d++) + sigmaD += pow(abs(A.getCoord(d) - F[n].getCoord(d)), P); + sigmaN += pow(sigmaD, 1.0 / P); + } + + return sigmaN; + } + + // lorsque P tend vers PosInf + public static double getDistancePI(Point A, Point[] F) { + double sigmaN = 0.0d; + int N = F.length, D = A.getCoords().length, Dmax = D; + + for (int n = 0; n < N; n++) { + if (F[n].coords.length != D) { + int[] change = new int[Dmax]; + if (F[n].coords.length != Dmax) { + for (int dm = 0; dm < Dmax; dm++) + change[dm] = (dm < F[n].coords.length) ? (F[n].getCoord(dm + 1)) : 0; + F[n].coords = change; + } + } + if (F[n].coords.length > Dmax) { + System.out.println("Dmax passe de " + Dmax + " à " + F[n].coords.length); + Dmax = F[n].coords.length; + } + } + + List temp = new ArrayList<>(); + + for (int n = 0; n < N; n++) { + temp.clear(); + for (int d = 1; d <= D; d++) + temp.add(abs((double) A.getCoord(d) - (double) F[n].getCoord(d))); + sigmaN += Collections.max(temp); + } + + return sigmaN; + } + + public static double getDistanceMI(Point A, Point[] F) { + double sigmaN = 0.0d; + int N = F.length, D = A.getCoords().length, Dmax = D; + + for (int n = 0; n < N; n++) { + if (F[n].coords.length != D) { + int[] change = new int[Dmax]; + if (F[n].coords.length != Dmax) { + for (int dm = 0; dm < Dmax; dm++) + change[dm] = (dm < F[n].coords.length) ? (F[n].getCoord(dm + 1)) : 0; + F[n].coords = change; + } + } + if (F[n].coords.length > Dmax) { + System.out.println("Dmax passe de " + Dmax + " à " + F[n].coords.length); + Dmax = F[n].coords.length; + } + } + + List temp = new ArrayList<>(); + + for (int n = 0; n < N; n++) { + temp.clear(); + for (int d = 1; d <= D; d++) + temp.add(abs((double) A.getCoord(d) - (double) F[n].getCoord(d))); + sigmaN += Collections.min(temp); + } + + return sigmaN; + } +} \ No newline at end of file diff --git a/src/com/bernard/cercloide/ViewUtil.java b/src/com/bernard/cercloide/ViewUtil.java new file mode 100644 index 0000000..1e98d3f --- /dev/null +++ b/src/com/bernard/cercloide/ViewUtil.java @@ -0,0 +1,29 @@ +package com.bernard.cercloide; + +import java.awt.Component; +import java.awt.Container; + +public class ViewUtil +{ + public static final void printPanel(Container p) + { + printPanel(p, 0); + } + + private static final void printPanel(Container p, int tab) + { + if(p==null) return; + for(Component c : p.getComponents()) + { + for(int i = 0; i < tab; i++) + { + System.out.print("\t"); + } + System.out.println(c); + if(c instanceof Container) + printPanel((Container)c, tab + 1); + + } + } + +} diff --git a/src/com/bernard/cercloide/colorset/ColorSet.java b/src/com/bernard/cercloide/colorset/ColorSet.java new file mode 100644 index 0000000..e9e4204 --- /dev/null +++ b/src/com/bernard/cercloide/colorset/ColorSet.java @@ -0,0 +1,151 @@ +package com.bernard.cercloide.colorset; + +import java.awt.Color; + +public enum ColorSet { + BlackWhite("Black->White") { + @Override + public Color getByInt(long l) { + return new Color((int) (l % 256), (int) (l % 256), (int) (l % 256)); + } + }, + BlackWhiteBlack("Black->White->Black") { + @Override + public Color getByInt(long l) { + return new Color((int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), + (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), + (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510)); + } + }, + + BlackBlue("Black->Blue") { + @Override + public Color getByInt(long l) { + return new Color(0, 0, (int) (l % 256)); + } + }, + BlackBlueBlack("Black->Blue->Black") { + @Override + public Color getByInt(long l) { + return new Color(0, 0, (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510)); + } + }, + + BlackGreen("Black->Green") { + @Override + public Color getByInt(long l) { + return new Color(0, (int) (l % 256), 0); + } + }, + BlackGreenBlack("Black->Green->Black") { + @Override + public Color getByInt(long l) { + return new Color(0, (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), 0); + } + }, + + BlackRed("Black->Red") { + @Override + public Color getByInt(long l) { + return new Color((int) (l % 256), 0, 0); + } + }, + BlackRedBlack("Black->Red->Black") { + @Override + public Color getByInt(long l) { + return new Color((int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), 0, 0); + } + }, + + BlackMagenta("Black->Magenta") { + @Override + public Color getByInt(long l) { + return new Color((int) (l % 256), 0, (int) (l % 256)); + } + }, + BlackMagentaBlack("Black->Magenta->Black") { + @Override + public Color getByInt(long l) { + return new Color((int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), 0, + (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510)); + } + }, + + BlackYellow("Black->Yellow") { + @Override + public Color getByInt(long l) { + return new Color((int) (l % 256), (int) (l % 256), 0); + } + }, + BlackYellowBlack("Black->Yellow->Black") { + @Override + public Color getByInt(long l) { + return new Color((int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), + (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), 0); + } + }, + + BlackCyan("Black->Cyan") { + @Override + public Color getByInt(long l) { + return new Color(0, (int) (l % 256), (int) (l % 256)); + } + }, + BlackCyanBlack("Black->Cyan->Black") { + @Override + public Color getByInt(long l) { + return new Color(0, (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510), + (int) ((l % 510 > 255) ? 510 - (l % 510) : l % 510)); + } + }, + WhyAreYouAVariable(" ") { + @Override + public Color getByInt(long l) { + int tl = ((int) (l % 14))*3; + switch (tl) { + case 0: + return Color.RED; + case 3: + return Color.GREEN; + case 6: + return Color.BLUE; + case 9: + return Color.MAGENTA; + case 12: + return Color.CYAN; + case 15: + return Color.DARK_GRAY; + case 18: + return Color.WHITE; + case 21: + return Color.GRAY; + case 24: + return Color.WHITE; + case 27: + return Color.YELLOW; + case 30: + return Color.LIGHT_GRAY; + case 33: + return Color.ORANGE; + case 36: + return Color.PINK; + default: + return new Color(42,110,196); + } + } + }; + + String displayName; + + private ColorSet(String displayedName) { + this.displayName = displayedName; + } + + public abstract Color getByInt(long l); + + @Override + public String toString() { + return displayName; + } + +} diff --git a/src/com/bernard/cercloide/factory/ImageCreator.java b/src/com/bernard/cercloide/factory/ImageCreator.java new file mode 100644 index 0000000..782f26b --- /dev/null +++ b/src/com/bernard/cercloide/factory/ImageCreator.java @@ -0,0 +1,731 @@ +package com.bernard.cercloide.factory; + +import static java.lang.Math.*; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Arrays; + +import javax.imageio.ImageIO; +import javax.swing.JOptionPane; + +import com.bernard.cercloide.TestDistance; +import com.bernard.cercloide.colorset.ColorSet; +import com.bernard.cercloide.theory.plan.Point; +import com.bernard.cercloide.view.VarSetFrame; +import com.bernard.cercloide.view.ViewDrawingProgress; +import com.bernard.cercloide.view.WaitFrame; + +public class ImageCreator +{ + + /** + * Iter all the picture and applics the color gave by the ColorSet at all + * pixels according to the rayon + * @param frame + * The main frame , for the endProcess() method + * @param imagePath + * The path where save the image + * @param foyers + * A point array representing all the centers of the cercloid + * @param p + * Value of P + * @param colorSet + * The colorSet for having the paint color + * @param width + * the widtrh of the final image + * @param height + * the height of the final image + * @param foyColor + * the color of the centers + * @param foyCrossConvention + * A char representing how to draw centers + * @param foyCrossSize + * the size of the drawed centers ( if drawed) + * @param progressing + * A frame for viewing draw process : if null , a WaitFrame will + * be shown + */ + public static void createImage(VarSetFrame frame, Path imagePath, Point[] foyers, Double p, ColorSet colorSet, int width, int height, Color foyColor, char foyCrossConvention, int foyCrossSize, ViewDrawingProgress progressing) + { + BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + long total = width * height; + WaitFrame wf = (progressing == null) ? new WaitFrame(total) : null; + long progress = 0; + if(p.equals(Double.POSITIVE_INFINITY)) + { + for(int w = 0; w < width; w++) + { + progress++; + for(int h = 0; h < height; h++) + { + progress++; + if(wf != null) + wf.progressBar.setValue((int)progress); + bi.setRGB(w, h, colorSet.getByInt((long)TestDistance.getDistancePI(new Point(w, h), foyers)).getRGB()); + bi.flush(); + } + if(progressing != null) + progressing.updateWithImage(bi); + } + } + else if(p.equals(Double.NEGATIVE_INFINITY)) + { + for(int w = 0; w < width; w++) + { + progress++; + for(int h = 0; h < height; h++) + { + progress++; + if(wf != null) + wf.progressBar.setValue((int)progress); + bi.setRGB(w, h, colorSet.getByInt((long)TestDistance.getDistanceMI(new Point(w, h), foyers)).getRGB()); + bi.flush(); + } + if(progressing != null) + progressing.updateWithImage(bi); + } + } + else + { + for(int w = 0; w < width; w++) + { + progress++; + for(int h = 0; h < height; h++) + { + progress++; + if(wf != null) + wf.progressBar.setValue((int)progress); + bi.setRGB(w, h, colorSet.getByInt((long)TestDistance.getDistance(new Point(w, h), foyers, p)).getRGB()); + bi.flush(); + } + if(progressing != null) + progressing.updateWithImage(bi); + } + } + /** + * String convention : "a"+45 == absolu de 45 "r"+142 == relatif de 12 + * "d"+0 = valeur par defaut "n"+0 = pas de croix + */ + int pxMax = 0; + boolean doCross = true; + + switch(foyCrossConvention) + { + case 'd': + pxMax = (int)((2.0 * (double)height) / 500.0); + break; + case 'a': + pxMax = foyCrossSize; + break; + case 'r': + pxMax = (int)(((double)foyCrossSize * (double)height) / 500.0); + break; + case 'n': + pxMax = (int)((2.0 * (double)height) / 500.0); + doCross = false; + break; + default: + + break; + + } + if(doCross) + { + for(Point f : foyers) + { + int x = f.getCoord(1); + int y = f.getCoord(2); + int rgb = foyColor.getRGB(); + for(int i = 1; i <= pxMax; i++) + { + + try + { + bi.setRGB(x - i, y, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + + try + { + bi.setRGB(x, y - i, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + + try + { + bi.setRGB(x + i, y, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + + try + { + bi.setRGB(x, y + i, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + try + { + bi.setRGB(x, y, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + bi.flush(); + } + } + + } + + System.out.println("Image crée"); + + try + { + imagePath.getParent().toFile().mkdirs(); + imagePath.toFile().createNewFile(); + ImageIO.write(bi, "png", imagePath.toFile()); + } + catch(IOException e) + { + System.err.println("Erreur lers de la création de l'image au path " + imagePath.toString()); + e.printStackTrace(); + } + System.out.println("Done"); + if(wf != null) + wf.setVisible(false); + if(progressing != null) + progressing.setVisible(false); + if(frame != null) + endProcess(imagePath.toAbsolutePath().toString(), frame); + + } + + /** + * Draws a cercloid with an iteration (long and no-smart algo) + * @param frame + * The main frame , for the endProcess() method + * @param imagePath + * The path where save the image + * @param foyers + * A point array representing all the centers of the cercloid + * @param p + * Value of P + * @param cercloidColor + * The color for drawing the Cercloid + * @param cercloidRayon + * The Rayon of the cercloid + * @param cercloidFourch + * The size of the cercloid "trait" + * @param width + * the widtrh of the final image + * @param height + * the height of the final image + * @param foyColor + * the color of the centers + * @param foyCrossConvention + * A char representing how to draw centers + * @param foyCrossSize + * the size of the drawed centers ( if drawed) + * @param progressing + * A frame for viewing draw process : if null , a WaitFrame will + * be shown + */ + public static void createImage(VarSetFrame frame, Path imagePath, Point[] foyers, Double p, Color cercloidColor, long cercloidRayon, int cercloidFourch, int width, int height, Color foyColor, char foyCrossConvention, int foyCrossSize, ViewDrawingProgress progressing) + { + long rayonMax = cercloidRayon + cercloidFourch, rayonMin = cercloidRayon - cercloidFourch; + BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + long total = width * height; + WaitFrame wf = (progressing == null) ? new WaitFrame(total) : null; + long progress = 0; + if(p.equals(Double.POSITIVE_INFINITY)) + { + for(int w = 0; w < width; progress++, w++) + { + for(int h = 0; h < height; progress++, h++) + { + if(wf != null) + wf.progressBar.setValue((int)progress); + long dis = (long)TestDistance.getDistancePI(new Point(w, h), foyers); + if(rayonMin <= dis && dis <= rayonMax) + { + bi.setRGB(w, h, cercloidColor.getRGB()); + } + else + { + bi.setRGB(w, h, Color.WHITE.getRGB()); + } + bi.flush(); + } + if(progressing != null) + progressing.updateWithImage(bi); + } + } + else if(p.equals(Double.NEGATIVE_INFINITY)) + { + for(int w = 0; w < width; w++) + { + progress++; + for(int h = 0; h < height; h++) + { + if(wf != null) + wf.progressBar.setValue((int)progress); + long dis = (long)TestDistance.getDistanceMI(new Point(w, h), foyers); + if(rayonMin <= dis && dis <= rayonMax) + { + bi.setRGB(w, h, cercloidColor.getRGB()); + } + else + { + bi.setRGB(w, h, Color.WHITE.getRGB()); + } + bi.flush(); + } + if(progressing != null) + progressing.updateWithImage(bi); + } + } + else + { + for(int w = 0; w < width; progress++, w++) + { + + for(int h = 0; h < height; progress++, h++) + { + if(wf != null) + wf.progressBar.setValue((int)progress); + long dis = (long)TestDistance.getDistance(new Point(w, h), foyers, p); + if(rayonMin <= dis && dis <= rayonMax) + { + bi.setRGB(w, h, cercloidColor.getRGB()); + } + else + { + bi.setRGB(w, h, Color.WHITE.getRGB()); + } + bi.flush(); + } + if(progressing != null) + progressing.updateWithImage(bi); + } + } + /** + * String convention : "a"+45 == absolu de 45 "r"+142 == relatif de 12 + * "d"+0 = valeur par defaut "n"+0 = pas de croix + */ + int pxMax = 0; + boolean doCross = true; + + switch(foyCrossConvention) + { + case 'd': + pxMax = (int)((2.0 * (double)height) / 500.0); + break; + case 'a': + pxMax = foyCrossSize; + break; + case 'r': + pxMax = (int)(((double)foyCrossSize * (double)height) / 500.0); + break; + case 'n': + pxMax = (int)((2.0 * (double)height) / 500.0); + doCross = false; + break; + default: + + break; + + } + if(doCross) + { + for(Point f : foyers) + { + int x = f.getCoord(1); + int y = f.getCoord(2); + int rgb = foyColor.getRGB(); + for(int i = 1; i <= pxMax; i++) + { + + try + { + bi.setRGB(x - i, y, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + + try + { + bi.setRGB(x, y - i, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + + try + { + bi.setRGB(x + i, y, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + + try + { + bi.setRGB(x, y + i, rgb); + bi.flush(); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.out.println("Drawing cross out of bounds"); + } + bi.setRGB(x, y, rgb); + bi.flush(); + } + } + + } + System.out.println("Image crée"); + + try + { + ImageIO.write(bi, "png", imagePath.toFile()); + } + catch(IOException e) + { + System.err.println("Erreur lers de la création de l'image au path " + imagePath.toString()); + e.printStackTrace(); + } + System.out.println("Done"); + if(wf != null) + wf.setVisible(false); + if(progressing != null) + progressing.setVisible(false); + if(frame != null) + { + endProcess(imagePath.toAbsolutePath().toString(), frame); + } + + } + + /** + * Create and save a Image af the cercloid specified with arguments (smart + * algo normalerweise) + * @param frame + * The main frame , for the endProcess() method + * @param imagePath + * The path where save the image + * @param foyers + * A point array representing all the centers of the cercloid + * @param p + * Value of P + * @param cercloidColor + * The color for drawing the Cercloid + * @param cercloidRayon + * The Rayon of the cercloid + * @param width + * the widtrh of the final image + * @param height + * the height of the final image + * @param foyColor + * the color of the centers + * @param foyCrossConvention + * A char representing how to draw centers + * @param foyCrossSize + * the size of the drawed centers ( if drawed) + * @param progressing + * A frame for viewing draw process : if null , a WaitFrame will + * be shown + */ + public static void createImage(VarSetFrame frame, Path imagePath, Point[] foyers, Double p, Color cercloidColor, long cercloidRayon, int width, int height, Color foyColor, char foyCrossConvention, int foyCrossSize, ViewDrawingProgress progressing) + { + System.out.println(Arrays.toString(foyers)); + BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + bi.getGraphics().fillRect(0, 0, width, height); + if(p > 0.0) + { + Point barycentre = Point.findBarycentre(foyers); + Point pointNE = barycentre.clone(); + Point pointNO = barycentre.clone(); + Point pointSO = barycentre.clone(); + Point pointSE = barycentre.clone(); + double error = -1.0; + while(error < 0) + { + pointNE.incrementCoord(1); + error = TestDistance.getDistance(pointNE, foyers, p) - cercloidRayon; + } + error = -1.0; + while(error < 0) + { + pointNO.incrementCoord(2); + error = TestDistance.getDistance(pointNO, foyers, p) - cercloidRayon; + } + error = -1.0; + while(error < 0) + { + pointSO.decrementCoord(1); + error = TestDistance.getDistance(pointSO, foyers, p) - cercloidRayon; + } + error = -1.0; + while(error < 0) + { + pointSE.decrementCoord(2); + error = TestDistance.getDistance(pointSE, foyers, p) - cercloidRayon; + } + pointNE.decrementCoord(1); + pointNO.decrementCoord(2); + pointSO.incrementCoord(1); + pointSE.incrementCoord(2); + Point firstPointNE = pointNE.clone(); + System.out.println(pointNE + "," + pointNO + "," + pointSO + "," + pointSE); + // List figure = new ArrayList<>(); + int[][] MODIFIED_COORDS = {{-1, 0}, {0, +1}, {-1, +1}}; + while(pointNE.getCoord(1)>pointNO.getCoord(1)) + { + // figure.add(pointNE); + System.out.println(pointNE); + try + { + bi.setRGB(pointNE.getCoord(1), pointNE.getCoord(2), cercloidColor.getRGB()); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.err.println("error"); + } + pointNE = getBetter(foyers, p, cercloidRayon, pointNE.withModifiedCoords(MODIFIED_COORDS[0]), pointNE.withModifiedCoords(MODIFIED_COORDS[1]), pointNE.withModifiedCoords(MODIFIED_COORDS[2])); + } + MODIFIED_COORDS = new int[][] {{-1, 0}, {0, -1}, {-1, -1}}; + while(pointNO.getCoord(2)>pointSO.getCoord(2)) + { + // figure.add(pointNO); + try + { + bi.setRGB(pointNO.getCoord(1), pointNO.getCoord(2), cercloidColor.getRGB()); + } + catch(ArrayIndexOutOfBoundsException e) + { + System.err.println("error"); + } + pointNO = getBetter(foyers, p, cercloidRayon, pointNO.withModifiedCoords(MODIFIED_COORDS[0]), pointNO.withModifiedCoords(MODIFIED_COORDS[1]), pointNO.withModifiedCoords(MODIFIED_COORDS[2])); + } + MODIFIED_COORDS = new int[][] {{+1, 0}, {0, -1}, {+1, -1}}; + while(pointSO.getCoord(1){ + + int[] xs,ys; + int xpos,ypos; + + @Override + public boolean hasNext() { + return xpos+1==xs.length && ypos+1==ys.length; + } + + @Override + public Point next() { + if(xpos+1 == xs.length){ + if(ypos+1 == ys.length){ + return null; + } + ypos++; + xpos = 0; + } + return new Point(xs[xpos],ys[ypos]); + } + +} diff --git a/src/com/bernard/cercloide/theory/iter/IterEnsemble.java b/src/com/bernard/cercloide/theory/iter/IterEnsemble.java new file mode 100644 index 0000000..99a3c6f --- /dev/null +++ b/src/com/bernard/cercloide/theory/iter/IterEnsemble.java @@ -0,0 +1,80 @@ +package com.bernard.cercloide.theory.iter; + +import java.util.Arrays; +import java.util.Iterator; + +public class IterEnsemble implements IterOptions { + Double[] values; + int randMal; + int actualPos = 0; + long totalIter; + + + public IterEnsemble(Double[] doubles, int randMal) { + this.values = doubles; + this.randMal = randMal; + this.totalIter = getMal(); + } + + public Double[] getValues() { + return values; + } + + public void setValues(Double[] values) { + this.values = values; + } + + public int getRandMal() { + return randMal; + } + + public void setRandMal(int randMal) { + this.randMal = randMal; + } + + @Override + public String toString() { + return "IterEnsemble [values=" + Arrays.toString(values) + ", randMal=" + randMal + "]"; + } + + @Override + public long getMal() { + if (randMal == -1) { + return values.length; + } else { + return randMal; + } + } + + @Override + public boolean hasNext() { + return actualPos <= totalIter-1; + } + + @Override + public Double next() { + if(hasNext()){ + if(randMal == -1){ + Double d = values[actualPos]; + actualPos++; + return d; + }else{ + Double d = values[(int) Math.floor(Math.random()*values.length)]; + actualPos++; + return d; + } + } + return null; + } + + @Override + public Iterator iterator() { + return this; + } + + @Override + public void reInit() { + this.actualPos = 0; + } + +} diff --git a/src/com/bernard/cercloide/theory/iter/IterIntervale.java b/src/com/bernard/cercloide/theory/iter/IterIntervale.java new file mode 100644 index 0000000..463532e --- /dev/null +++ b/src/com/bernard/cercloide/theory/iter/IterIntervale.java @@ -0,0 +1,115 @@ +package com.bernard.cercloide.theory.iter; + +import java.util.Iterator; + +public class IterIntervale implements IterOptions { + Double a, b, pas; + int randNumber; + Double actualPos; + long totalIter = getMal(); + + public IterIntervale(Double iA, Double iB, Double iP, int randNumber) { + this.a = iA; + this.b = iB; + this.pas = iP; + this.randNumber = randNumber; + if(randNumber == -1){ + actualPos = a; + }else{ + actualPos = 0.0; + } + } + + public Double getA() { + return a; + } + + public void setA(Double a) { + this.a = a; + } + + public Double getB() { + return b; + } + + public void setB(Double b) { + this.b = b; + } + + public Double getPas() { + return pas; + } + + public void setPas(Double pas) { + this.pas = pas; + } + + public int getRandNumber() { + return randNumber; + } + + public void setRandNumber(int randNumber) { + this.randNumber = randNumber; + } + + @Override + public String toString() { + return "IterIntervale [a=" + a + ", b=" + b + ", pas=" + pas + ", randNumber=" + randNumber + "]"; + } + + @Override + public long getMal() { + if (randNumber == -1) { + int i = 0; + Double e = a; + while (e < b) { + i++; + e += pas; + } + return i; + } else { + return randNumber; + } + + } + + @Override + public boolean hasNext() { + if (randNumber == -1) { + return actualPos-(actualPos%pas) < b; + } else { + return actualPos < randNumber; + } + } + + @Override + public Double next() { + if (hasNext()) { + if (randNumber == -1) { + Double d = actualPos; + actualPos += pas; + return d.doubleValue(); + } else { + Double d = a+(b-a)*Math.random(); + d-=d%pas; + actualPos += 1.0; + return d; + } + } + return null; + } + + @Override + public Iterator iterator() { + return this; + } + + @Override + public void reInit() { + if(randNumber == -1){ + actualPos = a; + }else{ + actualPos = 0.0; + } + } +} diff --git a/src/com/bernard/cercloide/theory/iter/IterOptions.java b/src/com/bernard/cercloide/theory/iter/IterOptions.java new file mode 100644 index 0000000..8ff8f94 --- /dev/null +++ b/src/com/bernard/cercloide/theory/iter/IterOptions.java @@ -0,0 +1,8 @@ +package com.bernard.cercloide.theory.iter; + +import java.util.Iterator; + +public interface IterOptions extends Iterable ,Iterator{ + long getMal(); + void reInit(); +} diff --git a/src/com/bernard/cercloide/theory/plan/Point.java b/src/com/bernard/cercloide/theory/plan/Point.java new file mode 100644 index 0000000..e6c4f06 --- /dev/null +++ b/src/com/bernard/cercloide/theory/plan/Point.java @@ -0,0 +1,136 @@ +package com.bernard.cercloide.theory.plan; + +import java.util.Arrays; + +/** + * This class represents a point defined by a coordinates tab + * the coord 0 does not exists : coords count start at 1 + * + * @author mysaa + * + */ +public class Point { + public int[] coords; + + public Point(int... cords) { + coords = cords; + } + + public int getCoord(int i) { + return coords[i - 1]; + } + + public int[] getCoords() { + return coords; + } + + public void setCoords(int[] coords) { + this.coords = coords; + } + public void setCoord(int i,int value) { + this.coords[i-1] = value; + } + + @Override + public String toString() { + return "Point [coords=" + Arrays.toString(coords) + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(coords); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Point other = (Point) obj; + if (!Arrays.equals(coords, other.coords)) + return false; + return true; + } + + public static Point findBarycentre(Point[] foyers) { + final int coordNumber = foyers[0].coords.length; + long[] coordsSum = new long[coordNumber]; + Arrays.fill(coordsSum, 0L); + for (Point p : foyers) { + System.out.println(foyers[0]); + if (p.coords.length != coordNumber) { + throw new IllegalArgumentException("Les points ne sont pas de m�me dimension !!!"); + } + for (int i = 0; i < p.getCoords().length; i++) { + coordsSum[i] += p.getCoord(i+1); + } + } + int[] coords = new int[coordsSum.length]; + for (int i = 0; i < coordsSum.length; i++) { + coords[i] = (int) Math.floorDiv(coordsSum[i], foyers.length); + } + return new Point(coords); + } + + public Point incrementCoord(int i) { + coords[i-1]++; + return this; + } + + public Point decrementCoord(int i) { + coords[i-1]--; + return this; + } + /** + * Modify coords by adding modified tab to coords tab (with clone()) + * @param modified The modified coords + * @return a new Point(cloned) with coords modified + */ + public Point withModifiedCoords(int ... modified) { + Point p2 = this.clone(); + for (int i = 0; i < modified.length; i++) { + p2.setCoord(i+1, p2.getCoord(i+1)+modified[i]); + } + return p2; + } + public Point withModifiedCoords(int direction) { + switch (direction) { + case 0: + return this.withModifiedCoords(0,-1); + case 1: + return this.withModifiedCoords(+1,-1); + case 2: + return this.withModifiedCoords(+1,0); + case 3: + return this.withModifiedCoords(+1,+1); + case 4: + return this.withModifiedCoords(0,+1); + case 5: + return this.withModifiedCoords(-1,+1); + case 6: + return this.withModifiedCoords(-1,0); + case 7: + return this.withModifiedCoords(-1,-1); + default: + return this.withModifiedCoords(0,0); + } + } + @Override + public Point clone(){ + return new Point(Arrays.copyOf(coords, coords.length)); + } + + public boolean isAround9(Point point) { + int i = getCoord(1)-point.getCoord(1); + int j = getCoord(2)-point.getCoord(2); + return (i>=-1 && i<=1) || (j>=-1 || j<=1); + } + + +} diff --git a/src/com/bernard/cercloide/varSets/CercloidWithGradientArgs.java b/src/com/bernard/cercloide/varSets/CercloidWithGradientArgs.java new file mode 100644 index 0000000..58232d4 --- /dev/null +++ b/src/com/bernard/cercloide/varSets/CercloidWithGradientArgs.java @@ -0,0 +1,168 @@ +package com.bernard.cercloide.varSets; + +import java.awt.Color; +import java.nio.file.Path; +import java.util.Arrays; + +import com.bernard.cercloide.colorset.ColorSet; +import com.bernard.cercloide.theory.plan.Point; + +public class CercloidWithGradientArgs { + Path imagePath; + Point[] foyers; + Double p; + ColorSet colorSet; + int width; + int height; + Color foyColor; + char foyCrossConvention; + int foyCrossSize7; + + public CercloidWithGradientArgs(Path imagePath, Point[] foyers, Double p, ColorSet colorSet, int width, int height, + Color foyColor, char foyCrossConvention, int foyCrossSize7) { + this.imagePath = imagePath; + this.foyers = foyers; + this.p = p; + this.colorSet = colorSet; + this.width = width; + this.height = height; + this.foyColor = foyColor; + this.foyCrossConvention = foyCrossConvention; + this.foyCrossSize7 = foyCrossSize7; + } + + public Path getImagePath() { + return imagePath; + } + + public void setImagePath(Path imagePath) { + this.imagePath = imagePath; + } + + public Point[] getFoyers() { + return foyers; + } + + public void setFoyers(Point[] foyers) { + this.foyers = foyers; + } + + public Double getP() { + return p; + } + + public void setP(Double p) { + this.p = p; + } + + public ColorSet getColorSet() { + return colorSet; + } + + public void setColorSet(ColorSet colorSet) { + this.colorSet = colorSet; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public Color getFoyColor() { + return foyColor; + } + + public void setFoyColor(Color foyColor) { + this.foyColor = foyColor; + } + + public char getFoyCrossConvention() { + return foyCrossConvention; + } + + public void setFoyCrossConvention(char foyCrossConvention) { + this.foyCrossConvention = foyCrossConvention; + } + + public int getFoyCrossSize7() { + return foyCrossSize7; + } + + public void setFoyCrossSize7(int foyCrossSize7) { + this.foyCrossSize7 = foyCrossSize7; + } + + @Override + public String toString() { + return "CercloidWithGradientArgs [imagePath=" + imagePath + ", foyers=" + Arrays.toString(foyers) + ", p=" + p + + ", colorSet=" + colorSet + ", width=" + width + ", height=" + height + ", foyColor=" + foyColor + + ", foyCrossConvention=" + foyCrossConvention + ", foyCrossSize7=" + foyCrossSize7 + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((colorSet == null) ? 0 : colorSet.hashCode()); + result = prime * result + ((foyColor == null) ? 0 : foyColor.hashCode()); + result = prime * result + foyCrossConvention; + result = prime * result + foyCrossSize7; + result = prime * result + Arrays.hashCode(foyers); + result = prime * result + height; + result = prime * result + ((imagePath == null) ? 0 : imagePath.hashCode()); + result = prime * result + ((p == null) ? 0 : p.hashCode()); + result = prime * result + width; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CercloidWithGradientArgs other = (CercloidWithGradientArgs) obj; + if (colorSet != other.colorSet) + return false; + if (foyColor == null) { + if (other.foyColor != null) + return false; + } else if (!foyColor.equals(other.foyColor)) + return false; + if (foyCrossConvention != other.foyCrossConvention) + return false; + if (foyCrossSize7 != other.foyCrossSize7) + return false; + if (!Arrays.equals(foyers, other.foyers)) + return false; + if (height != other.height) + return false; + if (imagePath == null) { + if (other.imagePath != null) + return false; + } else if (!imagePath.equals(other.imagePath)) + return false; + if (p == null) { + if (other.p != null) + return false; + } else if (!p.equals(other.p)) + return false; + if (width != other.width) + return false; + return true; + } + +} diff --git a/src/com/bernard/cercloide/view/LoopSetFrame2.java b/src/com/bernard/cercloide/view/LoopSetFrame2.java new file mode 100644 index 0000000..c991ce0 --- /dev/null +++ b/src/com/bernard/cercloide/view/LoopSetFrame2.java @@ -0,0 +1,357 @@ +package com.bernard.cercloide.view; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + +import com.bernard.cercloide.factory.JOptPaneCreator; +import com.bernard.cercloide.factory.NumberAnalyser; +import com.bernard.cercloide.theory.iter.IterEnsemble; +import com.bernard.cercloide.theory.iter.IterIntervale; +import com.bernard.cercloide.theory.iter.IterOptions; + +public class LoopSetFrame2 extends JFrame { + + private static final long serialVersionUID = -6114568748667688509L; + + public static final String ENSEMBLE = "ensemble"; + public static final String INTERVALE = "intervale"; + public static final String RAND_ENSEMBLE = "rand_ensemble"; + public static final String RAND_INTERVALE = "rand_intervale"; + + ButtonGroup choiceGroup; + JRadioButton choiceEnsemble, choiceIntervale, choiceRandEnsemble, choiceRandIntervale; + JTextField intervaleA, intervaleB, intervalePas, randIntervaleA, randIntervaleB, randIntervalePas, randIntervaleMal; + JTextField ensemble, randEnsemble, randEnsembleMal; + JPanel settingsPanel; + CardLayout settingsCard; + JButton finish; + + boolean finished; + IterOptions output; + + GlobalListener globalListener = new GlobalListener(); + + public LoopSetFrame2(IterOptions pIter) { + finished = false; + this.setTitle("Cercloïdator"); + this.setSize(1000, 110); + this.setResizable(false); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + init(); + + choiceEnsemble.setSelected(false); + choiceIntervale.setSelected(false); + choiceRandEnsemble.setSelected(false); + choiceRandIntervale.setSelected(false); + if (pIter instanceof IterEnsemble) { + IterEnsemble iterEnsemble = (IterEnsemble) pIter; + String[] out = new String[iterEnsemble.getValues().length]; + for (int i = 0; i < iterEnsemble.getValues().length; i++) { + out[i] = iterEnsemble.getValues()[i].toString(); + } + if (iterEnsemble.getRandMal() == -1) { + ensemble.setText(String.join(",", out)); + choiceEnsemble.setSelected(true); + settingsCard.show(settingsPanel, ENSEMBLE); + } else { + randEnsemble.setText(String.join(",", out)); + choiceRandEnsemble.setSelected(true); + settingsCard.show(settingsPanel, RAND_ENSEMBLE); + randEnsembleMal.setText(Integer.toString(iterEnsemble.getRandMal(), 10)); + } + } else if (pIter instanceof IterIntervale) { + IterIntervale iterIntervale = (IterIntervale) pIter; + if (iterIntervale.getRandNumber() == -1) { + intervaleA.setText(iterIntervale.getA().toString()); + intervaleB.setText(iterIntervale.getB().toString()); + intervalePas.setText(iterIntervale.getPas().toString()); + choiceIntervale.setSelected(true); + settingsCard.show(settingsPanel, INTERVALE); + } else { + randIntervaleA.setText(iterIntervale.getA().toString()); + randIntervaleB.setText(iterIntervale.getB().toString()); + randIntervalePas.setText(iterIntervale.getPas().toString()); + choiceRandIntervale.setSelected(true); + settingsCard.show(settingsPanel, RAND_INTERVALE); + randIntervaleMal.setText(Integer.toString(iterIntervale.getRandNumber(), 10)); + } + } else { + choiceEnsemble.setSelected(true); + } + + this.setLocationRelativeTo(null); + this.setVisible(true); + + } + + private void init() { + final Font generalFont = new Font("OCR A Extended", Font.ITALIC, 20); + + JPanel choicePanel = new JPanel(); + choicePanel.setLayout(new BoxLayout(choicePanel, BoxLayout.LINE_AXIS)); + choiceGroup = new ButtonGroup(); + choiceEnsemble = new JRadioButton("{a,b,c}"); + choiceEnsemble.addActionListener(globalListener); + choiceEnsemble.setSelected(true); + choiceGroup.add(choiceEnsemble); + choiceIntervale = new JRadioButton("[a;b["); + choiceIntervale.addActionListener(globalListener); + choiceGroup.add(choiceIntervale); + choiceRandEnsemble = new JRadioButton("RAND( {a,b,c} )"); + choiceRandEnsemble.addActionListener(globalListener); + choiceGroup.add(choiceRandEnsemble); + choiceRandIntervale = new JRadioButton("RAND( [a;b[ )"); + choiceRandIntervale.addActionListener(globalListener); + choiceGroup.add(choiceRandIntervale); + choicePanel.add(choiceEnsemble); + choicePanel.add(choiceIntervale); + choicePanel.add(choiceRandEnsemble); + choicePanel.add(choiceRandIntervale); + + settingsPanel = new JPanel(); + settingsCard = new CardLayout(); + settingsPanel.setLayout(settingsCard); + + JPanel ensemblePanel = new JPanel(); + ensemblePanel.setLayout(new BorderLayout()); + JLabel ensembleSelectionLabel = new JLabel("Ensemble : {"); + ensembleSelectionLabel.setFont(generalFont); + ensemble = new JTextField(); + ensemble.setFont(generalFont); + ensemble.setToolTipText("Sous la forme \"a,b,c,d,e,f\""); + JLabel ensembleSelectionLabelEnd = new JLabel("}"); + ensembleSelectionLabelEnd.setFont(generalFont); + ensemblePanel.add(ensembleSelectionLabel, BorderLayout.WEST); + ensemblePanel.add(ensembleSelectionLabelEnd, BorderLayout.EAST); + ensemblePanel.add(ensemble, BorderLayout.CENTER); + + JPanel intervalePanel = new JPanel(); + intervalePanel.setLayout(new BoxLayout(intervalePanel, BoxLayout.LINE_AXIS)); + JLabel intervaleLabel1 = new JLabel("Parcourir l'intervale ["); + intervaleLabel1.setFont(generalFont); + intervaleA = new JTextField(); + intervaleA.setFont(generalFont); + JLabel intervaleLabel2 = new JLabel(";"); + intervaleLabel2.setFont(generalFont); + intervaleB = new JTextField(); + intervaleB.setFont(generalFont); + JLabel intervaleLabel3 = new JLabel("[ avec un pas de "); + intervaleLabel3.setFont(generalFont); + intervalePas = new JTextField(); + intervalePas.setFont(generalFont); + intervalePanel.add(intervaleLabel1); + intervalePanel.add(intervaleA); + intervalePanel.add(intervaleLabel2); + intervalePanel.add(intervaleB); + intervalePanel.add(intervaleLabel3); + intervalePanel.add(intervalePas); + + JPanel randEnsemblePanel = new JPanel(); + randEnsemblePanel.setLayout(new BoxLayout(randEnsemblePanel, BoxLayout.LINE_AXIS)); + JLabel randEnsembleSelectionLabel = new JLabel("Nombre dans l'ensemble : {"); + randEnsembleSelectionLabel.setFont(generalFont); + randEnsemble = new JTextField(); + randEnsemble.setFont(generalFont); + randEnsemble.setToolTipText("Sous la forme \"a,b,c,d,e,f\""); + JLabel randEnsembleSelectionLabelEnd = new JLabel("}"); + randEnsembleSelectionLabelEnd.setFont(generalFont); + JLabel randEnsembleLabel4 = new JLabel(", "); + randEnsembleLabel4.setFont(generalFont); + randEnsembleMal = new JTextField(); + randEnsembleMal.setFont(generalFont); + JLabel randEnsembleLabel5 = new JLabel("fois"); + randEnsembleLabel5.setFont(generalFont); + randEnsemblePanel.add(randEnsembleSelectionLabel); + randEnsemblePanel.add(randEnsembleSelectionLabelEnd); + randEnsemblePanel.add(randEnsemble); + randEnsemblePanel.add(randEnsembleLabel4); + randEnsemblePanel.add(randEnsembleMal); + randEnsemblePanel.add(randEnsembleLabel5); + + JPanel randIntervalePanel = new JPanel(); + randIntervalePanel.setLayout(new BoxLayout(randIntervalePanel, BoxLayout.LINE_AXIS)); + JLabel randIntervaleLabel1 = new JLabel("Nombre dans l'intervale ["); + randIntervaleLabel1.setFont(generalFont); + randIntervaleA = new JTextField(); + randIntervaleA.setFont(generalFont); + JLabel randIntervaleLabel2 = new JLabel(";"); + randIntervaleLabel2.setFont(generalFont); + randIntervaleB = new JTextField(); + randIntervaleB.setFont(generalFont); + JLabel randIntervaleLabel3 = new JLabel("[ avec un pas de "); + randIntervaleLabel3.setFont(generalFont); + randIntervalePas = new JTextField(); + randIntervalePas.setFont(generalFont); + JLabel randIntervaleLabel4 = new JLabel(", "); + randIntervaleLabel4.setFont(generalFont); + randIntervaleMal = new JTextField(); + randIntervaleMal.setFont(generalFont); + JLabel randIntervaleLabel5 = new JLabel("fois"); + randIntervaleLabel5.setFont(generalFont); + randIntervalePanel.add(randIntervaleLabel1); + randIntervalePanel.add(randIntervaleA); + randIntervalePanel.add(randIntervaleLabel2); + randIntervalePanel.add(randIntervaleB); + randIntervalePanel.add(randIntervaleLabel3); + randIntervalePanel.add(randIntervalePas); + randIntervalePanel.add(randIntervaleLabel4); + randIntervalePanel.add(randIntervaleMal); + randIntervalePanel.add(randIntervaleLabel5); + + settingsPanel.add(ensemblePanel, ENSEMBLE); + settingsPanel.add(intervalePanel, INTERVALE); + settingsPanel.add(randEnsemblePanel, RAND_ENSEMBLE); + settingsPanel.add(randIntervalePanel, RAND_INTERVALE); + settingsCard.show(settingsPanel, ENSEMBLE); + + finish = new JButton("Terminé !"); + finish.setFont(generalFont); + finish.addActionListener(globalListener); + + this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.PAGE_AXIS)); + this.getContentPane().add(choicePanel); + this.getContentPane().add(settingsPanel); + this.getContentPane().add(finish); + + } + + public IterOptions waitFinish() { + while (!finished) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + return output; + } + + private IterOptions testVars() { + if (choiceEnsemble.isSelected()) { + List doubletab = new ArrayList(); + try { + for (String s : ensemble.getText().split(",")) { + doubletab.add(NumberAnalyser.parseDouble(s)); + } + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'ensemble ne peut pas etre égal à " + ensemble.getText()); + return null; + } + return new IterEnsemble((Double[]) doubletab.toArray(new Double[doubletab.size()]), -1); + } else if (choiceIntervale.isSelected()) { + Double iA, iB, iP; + try { + iA = NumberAnalyser.parseDouble(intervaleA.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'intervale ne peut pas partir de " + intervaleA.getText()); + return null; + } + + try { + iB = NumberAnalyser.parseDouble(intervaleB.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'intervale ne peut pas finir à " + intervaleB.getText()); + return null; + } + try { + iP = NumberAnalyser.parseDouble(intervalePas.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'intervale ne peut pas avoir un pas de " + intervalePas.getText()); + return null; + } + return new IterIntervale(iA, iB, iP, -1); + } else if (choiceRandEnsemble.isSelected()) { + List doubletab = new ArrayList(); + try { + for (String s : randEnsemble.getText().split(",")) { + doubletab.add(NumberAnalyser.parseDouble(s)); + } + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'ensemble ne peut pas etre égal à " + randEnsemble.getText()); + return null; + } + int rand = -1; + try { + rand = NumberAnalyser.parseLong(randEnsembleMal.getText()).intValue(); + } catch (NumberFormatException e) { + JOptPaneCreator + .argumentError("L'iteration ne peut pas s'effectuer " + randEnsembleMal.getText() + " fois"); + return null; + } + return new IterEnsemble((Double[]) doubletab.toArray(new Double[doubletab.size()]), rand); + } else if (choiceRandIntervale.isSelected()) { + Double iA, iB, iP; + try { + iA = NumberAnalyser.parseDouble(randIntervaleA.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'intervale ne peut pas partir de " + randIntervaleA.getText()); + return null; + } + + try { + iB = NumberAnalyser.parseDouble(randIntervaleB.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'intervale ne peut pas finir à " + randIntervaleB.getText()); + return null; + } + try { + iP = NumberAnalyser.parseDouble(randIntervalePas.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("L'intervale ne peut pas avoir un pas de " + randIntervalePas.getText()); + return null; + } + int rand = -1; + try { + rand = NumberAnalyser.parseLong(randIntervaleMal.getText()).intValue(); + } catch (NumberFormatException e) { + JOptPaneCreator + .argumentError("L'iteration ne peut pas s'effectuer " + randIntervaleMal.getText() + " fois"); + return null; + } + return new IterIntervale(iA, iB, iP, rand); + } else { + System.err.println("Destruction de la matrice génériciellement créelle"); + } + return null; + } + + class GlobalListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == finish) { + output = testVars(); + if (output != null) { + finished = true; + setVisible(false); + } + } else if (e.getSource() == choiceEnsemble) { + settingsCard.show(settingsPanel, ENSEMBLE); + } else if (e.getSource() == choiceIntervale) { + settingsCard.show(settingsPanel, INTERVALE); + } else if (e.getSource() == choiceRandEnsemble) { + settingsCard.show(settingsPanel, RAND_ENSEMBLE); + } else if (e.getSource() == choiceRandIntervale) { + settingsCard.show(settingsPanel, RAND_INTERVALE); + } + } + + } + +} diff --git a/src/com/bernard/cercloide/view/LoopUtilFrame.java b/src/com/bernard/cercloide/view/LoopUtilFrame.java new file mode 100644 index 0000000..58a1f6b --- /dev/null +++ b/src/com/bernard/cercloide/view/LoopUtilFrame.java @@ -0,0 +1,102 @@ +package com.bernard.cercloide.view; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +public class LoopUtilFrame extends JFrame { + private static final long serialVersionUID = 7982664157134004776L; + JCheckBox pVar, wVar, hVar, rVar, fVar; + JRadioButton withRay; + JButton go = new JButton(); + + GlobalListener globalListener = new GlobalListener(); + + public LoopUtilFrame() { + this.setTitle("Cercloïdator"); + this.setSize(600, 300); + this.setResizable(false); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + init(); + + this.setLocationRelativeTo(null); + this.setVisible(true); + } + + private void init() { + final Font generalFont = new Font("OCR A Extended", Font.ITALIC, 20); + + JPanel whatToChangePane = new JPanel(); + whatToChangePane.setLayout(new BoxLayout(whatToChangePane, BoxLayout.PAGE_AXIS)); + JLabel whatToChangeLabel = new JLabel("Quelles sont les variables à changer ?"); + whatToChangeLabel.setFont(generalFont); + pVar = new JCheckBox("P"); + pVar.setFont(generalFont); + wVar = new JCheckBox("Largeur"); + wVar.setFont(generalFont); + hVar = new JCheckBox("Hauteur"); + hVar.setFont(generalFont); + withRay = new JRadioButton("Avec un rayon ?"); + withRay.setFont(generalFont); + withRay.addActionListener(globalListener); + rVar = new JCheckBox("Rayon"); + rVar.setFont(generalFont); + rVar.setVisible(false); + fVar = new JCheckBox("Fourchette"); + fVar.setFont(generalFont); + fVar.setVisible(false); + go = new JButton("Lancer"); + go.setFont(generalFont); + go.addActionListener(globalListener); + + whatToChangePane.add(pVar); + whatToChangePane.add(wVar); + whatToChangePane.add(hVar); + whatToChangePane.add(withRay); + whatToChangePane.add(rVar); + whatToChangePane.add(fVar); + + this.getContentPane().setLayout(new BorderLayout()); + this.getContentPane().add(whatToChangeLabel, BorderLayout.NORTH); + this.getContentPane().add(whatToChangePane, BorderLayout.CENTER); + this.getContentPane().add(go, BorderLayout.SOUTH); + } + + class GlobalListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == go) { + Thread t = new Thread(new Runnable() { + public void run() { + new LoopUtilVarSet(withRay.isSelected(), pVar.isSelected(), wVar.isSelected(), + hVar.isSelected(), rVar.isSelected(), fVar.isSelected()); + } + }); + t.start(); + setVisible(false); + } else if (e.getSource() == withRay) { + if (withRay.isSelected()) { + rVar.setVisible(true); + fVar.setVisible(true); + } else { + rVar.setVisible(false); + fVar.setVisible(false); + } + } else { + System.err.println("Non Catched Element"); + } + } + + } +} diff --git a/src/com/bernard/cercloide/view/LoopUtilVarSet.java b/src/com/bernard/cercloide/view/LoopUtilVarSet.java new file mode 100644 index 0000000..f1c91f7 --- /dev/null +++ b/src/com/bernard/cercloide/view/LoopUtilVarSet.java @@ -0,0 +1,557 @@ +package com.bernard.cercloide.view; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JColorChooser; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + +import com.bernard.cercloide.colorset.ColorSet; +import com.bernard.cercloide.factory.JOptPaneCreator; +import com.bernard.cercloide.factory.LoopingImageCreator; +import com.bernard.cercloide.factory.NumberAnalyser; +import com.bernard.cercloide.theory.iter.IterEnsemble; +import com.bernard.cercloide.theory.iter.IterOptions; +import com.bernard.cercloide.theory.plan.Point; + +public class LoopUtilVarSet extends JFrame { + + private static final long serialVersionUID = -1796487518231431773L; + + private static final String WITHABSOLUTEVALUE = "withAV"; + private static final String WITHRELATIVEVALUE = "withRV"; + private static final String WITHNOVALUE = "withNV"; + + JButton setFoyers; + JTextField getP; + JButton dim1, dim2, dim3; + JTextField rayon, rayonFourch; + JTextField widthAsk, heightAsk; + ButtonGroup crossGroup; + JRadioButton crossDefault, crossAbsolute, crossRelative, noCross; + JTextField crossAbsoluteOut, crossRelativeOut; + JPanel crossOutputPane; + CardLayout crossActionLayout; + JComboBox colorSet; + JColorChooser rayonColorChooser; + JPanel colorPanel; + CardLayout colorLayout; + JButton run; + + LoopSetFrame2 loopSetFrame; + + JButton pVarier, wVarier, hVarier, rVarier, fVarier; + IterOptions pIter = null, wIter = null, hIter = null, rIter = null, fIter = null; + + boolean withRayon, pVar, wVar, hVar, rVar, fVar; + Point[] settedFoyers; + SelectPointsPos spp; + + GlobalListener globalListener = new GlobalListener(); + + public LoopUtilVarSet(boolean rayon, boolean pVariable, boolean wVariable, boolean hVariable, boolean rVariable, + boolean fVariable) { + pVar = pVariable; + wVar = wVariable; + hVar = hVariable; + rVar = rVariable; + fVar = fVariable; + withRayon = rayon; + this.setTitle("Cercloïdator"); + this.setSize(1000, 500); + this.setResizable(false); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + settedFoyers = new Point[0]; + + init(); + + this.setLocationRelativeTo(null); + this.setVisible(true); + } + + public void init() { + this.setContentPane(new JPanel()); + final Font generalFont = new Font("OCR A Extended", Font.ITALIC, 20); + + settedFoyers = new Point[0]; + + JPanel foyersPanel = new JPanel(); + foyersPanel.setLayout(new BorderLayout()); + setFoyers = new JButton("Régler les Foyers"); + setFoyers.setFont(generalFont); + setFoyers.addActionListener(globalListener); + foyersPanel.add(setFoyers, BorderLayout.CENTER); + + JPanel pPanel = new JPanel(); + pPanel.setLayout(new BorderLayout()); + if (pVar) { + pVarier = new JButton("Configurer P"); + pVarier.setFont(generalFont); + pVarier.addActionListener(globalListener); + pPanel.add(pVarier, BorderLayout.CENTER); + } else { + JLabel pLabel = new JLabel("P ="); + pLabel.setFont(generalFont); + getP = new JTextField(); + getP.setText("2"); + getP.setToolTipText("ex: 2"); + pPanel.add(pLabel, BorderLayout.WEST); + pPanel.add(getP, BorderLayout.CENTER); + } + + JPanel dimPanel = new JPanel(); + dimPanel.setLayout(new BorderLayout()); + JLabel dimLabel = new JLabel("Dimension :"); + dimLabel.setFont(generalFont); + JPanel dimChoicePanel = new JPanel(); + dimChoicePanel.setLayout(new GridLayout(1, 3)); + dim1 = new JButton("1"); + dim1.setToolTipText("Not implemented(yet)"); + dim1.setEnabled(false); + dim2 = new JButton("2"); + dim3 = new JButton("3"); + dim3.setToolTipText("Not implemented(yet)"); + dim3.setEnabled(false); + dimChoicePanel.add(dim1); + dimChoicePanel.add(dim2); + dimChoicePanel.add(dim3); + dimPanel.add(dimLabel, BorderLayout.WEST); + dimPanel.add(dimChoicePanel, BorderLayout.CENTER); + + JPanel rayonPanel = new JPanel(); + if (withRayon) { + rayonPanel.setLayout(new BoxLayout(rayonPanel, BoxLayout.LINE_AXIS)); + if (rVar) { + rVarier = new JButton("Configurer le rayon"); + rVarier.setFont(generalFont); + rVarier.addActionListener(globalListener); + rayonPanel.add(rVarier); + } else { + JLabel rayonLabel = new JLabel("Rayon :"); + rayonLabel.setFont(generalFont); + rayon = new JTextField(); + rayon.setToolTipText("ex: 403"); + rayonPanel.add(rayonLabel); + rayonPanel.add(rayon); + } + if (fVar) { + fVarier = new JButton("Configurer la fourchette du rayon"); + fVarier.setFont(generalFont); + fVarier.addActionListener(globalListener); + rayonPanel.add(fVarier); + } else { + JLabel rayonFourchLabel = new JLabel("Fourchette =/- :"); + rayonFourchLabel.setFont(generalFont); + rayonFourch = new JTextField(); + rayonFourch.setText("1"); + rayonFourch.setToolTipText("ex: 3"); + rayonPanel.add(rayonFourchLabel); + rayonPanel.add(rayonFourch); + } + } + + JPanel sizePanel = new JPanel(); + sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.LINE_AXIS)); + JLabel sizeLabel = new JLabel("Largeur/Hauteur :"); + sizeLabel.setFont(generalFont); + sizePanel.add(sizeLabel); + if (wVar) { + wVarier = new JButton("Configurer la largeur"); + wVarier.setFont(generalFont); + wVarier.addActionListener(globalListener); + sizePanel.add(wVarier); + } else { + widthAsk = new JTextField(); + widthAsk.setText("500"); + sizePanel.add(widthAsk); + } + JLabel sizeSeparator = new JLabel("/"); + sizeSeparator.setFont(generalFont); + sizePanel.add(sizeSeparator); + if (hVar) { + hVarier = new JButton("Configurer la hauteur"); + hVarier.setFont(generalFont); + hVarier.addActionListener(globalListener); + sizePanel.add(hVarier); + } else { + heightAsk = new JTextField(); + heightAsk.setText("500"); + sizePanel.add(heightAsk); + } + + JPanel crossPane = new JPanel(); + crossPane.setLayout(new BorderLayout()); + JPanel crossRadioPane = new JPanel(); + crossRadioPane.setLayout(new BoxLayout(crossRadioPane, BoxLayout.LINE_AXIS)); + JLabel crossRadioLabel = new JLabel("Marquage des foyers :"); + crossRadioLabel.setFont(generalFont); + crossDefault = new JRadioButton("Par défaut"); + crossDefault.setFont(generalFont); + crossDefault.addActionListener(globalListener); + crossAbsolute = new JRadioButton("Absolu"); + crossAbsolute.setFont(generalFont); + crossAbsolute.addActionListener(globalListener); + crossRelative = new JRadioButton("Relatif"); + crossRelative.setFont(generalFont); + crossRelative.addActionListener(globalListener); + noCross = new JRadioButton("Aucun"); + noCross.setFont(generalFont); + noCross.addActionListener(globalListener); + crossDefault.setSelected(true); + crossGroup = new ButtonGroup(); + crossGroup.add(crossDefault); + crossGroup.add(crossAbsolute); + crossGroup.add(crossRelative); + crossGroup.add(noCross); + crossRadioPane.add(crossRadioLabel); + crossRadioPane.add(crossDefault); + crossRadioPane.add(crossAbsolute); + crossRadioPane.add(crossRelative); + crossRadioPane.add(noCross); + crossPane.add(crossRadioPane, BorderLayout.CENTER); + crossOutputPane = new JPanel(); + crossActionLayout = new CardLayout(); + crossOutputPane.setLayout(crossActionLayout); + crossAbsoluteOut = new JTextField("2"); + crossAbsoluteOut.setToolTipText("Taille de chaque branche *2 pour hauteur=largeur=500"); + crossAbsoluteOut.setFont(generalFont); + crossRelativeOut = new JTextField("2"); + crossRelativeOut.setToolTipText("Taille de chaque branche pour hauteur=largeur=500"); + crossRelativeOut.setFont(generalFont); + crossOutputPane.add(crossAbsoluteOut, WITHABSOLUTEVALUE); + crossOutputPane.add(crossRelativeOut, WITHRELATIVEVALUE); + crossOutputPane.add(new JPanel(), WITHNOVALUE); + crossActionLayout.show(crossOutputPane, WITHNOVALUE); + crossPane.add(crossOutputPane, BorderLayout.SOUTH); + + colorPanel = new JPanel(); + colorPanel.setLayout(new BorderLayout()); + if (withRayon) { + JLabel colorWithRLabel = new JLabel("Couleur du rayon :"); + colorWithRLabel.setFont(generalFont); + rayonColorChooser = new JColorChooser(); + rayonColorChooser.setFont(generalFont); + colorPanel.add(colorWithRLabel, BorderLayout.WEST); + colorPanel.add(rayonColorChooser, BorderLayout.CENTER); + } else { + JPanel colorPanelIn = new JPanel(); + colorPanelIn.setLayout(new BorderLayout()); + JLabel colorWithoutRLabel = new JLabel("Jeu de couleurs :"); + colorWithoutRLabel.setFont(generalFont); + colorSet = new JComboBox<>(ColorSet.values()); + colorSet.setPreferredSize(new Dimension(625, 32)); + colorPanelIn.add(colorWithoutRLabel, BorderLayout.WEST); + colorPanelIn.add(colorSet, BorderLayout.CENTER); + colorPanel.add(colorPanelIn, BorderLayout.NORTH); + + } + + JPanel runPan = new JPanel(); + runPan.setLayout(new BorderLayout()); + run = new JButton("Lancer le dessin"); + run.addActionListener(globalListener); + runPan.add(run, BorderLayout.CENTER); + + this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.PAGE_AXIS)); + this.getContentPane().add(foyersPanel); + this.getContentPane().add(pPanel); + this.getContentPane().add(dimPanel); + this.getContentPane().add(rayonPanel); + this.getContentPane().add(sizePanel); + this.getContentPane().add(crossPane); + this.getContentPane().add(colorPanel); + this.getContentPane().add(runPan); + + this.pack(); + } + + public boolean testVars() { + if (!pVar) { + try { + NumberAnalyser.parseDouble(getP.getText()); + } catch (NumberFormatException e) { + if (getP.getText().toUpperCase().equals("+INF") || getP.getText().toUpperCase().equals("-INF")) { + + } else { + JOptPaneCreator.argumentError("P ne peut pas être égal à " + getP.getText()); + return false; + } + } + } + if (withRayon) { + if (!rVar) { + try { + NumberAnalyser.parseLong(rayon.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("Le rayon ne peut pas être égal à " + rayon.getText()); + return false; + } + } + if (!fVar) { + try { + NumberAnalyser.parseLong(rayonFourch.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator + .argumentError("La fourchette du rayon ne peut pas être égale à " + rayonFourch.getText()); + return false; + } + } + } + if (!wVar) { + try { + NumberAnalyser.parseLong(widthAsk.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("La largeur ne peut pas être égale à " + widthAsk.getText()); + return false; + } + } + if (!hVar) { + try { + NumberAnalyser.parseLong(heightAsk.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError("La hauteur ne peut pas être égale à " + heightAsk.getText()); + return false; + } + } + if (crossRelative.isSelected()) { + try { + NumberAnalyser.parseLong(crossRelativeOut.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError( + "La taille relative de la croix ne peut pas être égale à " + crossRelativeOut.getText()); + return false; + } + } + if (crossAbsolute.isSelected()) { + try { + NumberAnalyser.parseLong(crossAbsoluteOut.getText()); + } catch (NumberFormatException e) { + JOptPaneCreator.argumentError( + "Le taille absolue de la croix ne peut pas être égale à " + crossAbsoluteOut.getText()); + return false; + } + } + if (settedFoyers.length == 0) { + int option = JOptionPane.showConfirmDialog(null, + "Aucun foyer n'a été placé! Voulez-vous quand même générer l'image ?", "Aucun foyer", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + + if (option != JOptionPane.YES_OPTION) { + return false; + } + } + if (pIter == null && pVar) { + JOptPaneCreator.argumentError("Vous devez régler l'itération de P"); + } + if (wIter == null && wVar) { + JOptPaneCreator.argumentError("Vous devez régler l'itération de la largeur"); + } + if (hIter == null && hVar) { + JOptPaneCreator.argumentError("Vous devez régler l'itération de la hauteur"); + } + if (rIter == null && rVar) { + JOptPaneCreator.argumentError("Vous devez régler l'itération du rayon"); + } + if (fIter == null && fVar) { + JOptPaneCreator.argumentError("Vous devez régler l'itération de la fourchette"); + } + return true; + } + + class GlobalListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == setFoyers) { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + int w = NumberAnalyser.parseLong(widthAsk.getText()).intValue(), + h = NumberAnalyser.parseLong(heightAsk.getText()).intValue(); + spp = new SelectPointsPos(w, h, settedFoyers); + + setEnabled(false); + try { + Thread.sleep(250); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + settedFoyers = spp.waitFinish(); + setEnabled(true); + + } + }); + t.start(); + } else if (e.getSource() == crossDefault) { + crossActionLayout.show(crossOutputPane, WITHNOVALUE); + } else if (e.getSource() == crossAbsolute) { + crossActionLayout.show(crossOutputPane, WITHABSOLUTEVALUE); + } else if (e.getSource() == crossRelative) { + crossActionLayout.show(crossOutputPane, WITHRELATIVEVALUE); + } else if (e.getSource() == noCross) { + crossActionLayout.show(crossOutputPane, WITHNOVALUE); + } else if (e.getSource() == pVarier) { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + loopSetFrame = new LoopSetFrame2(pIter); + setEnabled(false); + try { + Thread.sleep(250); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + pIter = loopSetFrame.waitFinish(); + setEnabled(true); + } + }); + t.start(); + } else if (e.getSource() == wVarier) { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + loopSetFrame = new LoopSetFrame2(wIter); + setEnabled(false); + try { + Thread.sleep(250); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + wIter = loopSetFrame.waitFinish(); + setEnabled(true); + } + }); + t.start(); + } else if (e.getSource() == hVarier) { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + loopSetFrame = new LoopSetFrame2(wIter); + setEnabled(false); + try { + Thread.sleep(250); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + pIter = loopSetFrame.waitFinish(); + setEnabled(true); + } + }); + t.start(); + } else if (e.getSource() == rVarier) { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + loopSetFrame = new LoopSetFrame2(rIter); + setEnabled(false); + try { + Thread.sleep(250); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + rIter = loopSetFrame.waitFinish(); + setEnabled(true); + } + }); + t.start(); + } else if (e.getSource() == fVarier) { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + loopSetFrame = new LoopSetFrame2(fIter); + setEnabled(false); + try { + Thread.sleep(250); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + fIter = loopSetFrame.waitFinish(); + setEnabled(true); + } + }); + t.start(); + } else if (e.getSource() == run) { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + if (testVars()) { + if (!pVar) { + pIter = new IterEnsemble(new Double[] { NumberAnalyser.parseDouble(getP.getText()) }, + -1); + } + if (!wVar) { + wIter = new IterEnsemble( + new Double[] { NumberAnalyser.parseDouble(widthAsk.getText()) }, -1); + } + if (!hVar) { + hIter = new IterEnsemble( + new Double[] { NumberAnalyser.parseDouble(heightAsk.getText()) }, -1); + } + if (!rVar) { + if (withRayon) { + rIter = new IterEnsemble( + new Double[] { NumberAnalyser.parseDouble(rayon.getText()) }, -1); + } else { + rIter = new IterEnsemble(new Double[] { 1.0 }, -1); + } + } + if (!fVar) { + if (withRayon) { + fIter = new IterEnsemble( + new Double[] { NumberAnalyser.parseDouble(rayonFourch.getText()) }, -1); + } else { + fIter = new IterEnsemble(new Double[] { 1.0 }, -1); + } + + } + char crossConv = 'µ'; + int crossNum = -1; + if (crossDefault.isSelected()) { + crossConv = 'd'; + crossNum = 0; + } else if (crossAbsolute.isSelected()) { + crossConv = 'a'; + crossNum = NumberAnalyser.parseLong(crossAbsoluteOut.getText()).intValue(); + } else if (crossRelative.isSelected()) { + crossConv = 'r'; + crossNum = NumberAnalyser.parseLong(crossRelativeOut.getText()).intValue(); + } else if (noCross.isSelected()) { + crossConv = 'n'; + crossNum = 0; + } + LoopingImageCreator.createImageWithLoopedParams(pIter, wIter, hIter, rIter, fIter, + withRayon, settedFoyers, (ColorSet) colorSet.getSelectedItem(), Color.RED, + crossConv, crossNum, + (rayonColorChooser == null) ? Color.BLACK : rayonColorChooser.getColor()); + } + } + }); + t.start(); + setVisible(false); + } + } + + } +} \ No newline at end of file diff --git a/src/com/bernard/cercloide/view/MainFrame.java b/src/com/bernard/cercloide/view/MainFrame.java new file mode 100644 index 0000000..7ef8b1c --- /dev/null +++ b/src/com/bernard/cercloide/view/MainFrame.java @@ -0,0 +1,87 @@ +package com.bernard.cercloide.view; + +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; + +import com.bernard.cercloide.main.Main; + +public class MainFrame extends JFrame +{ + + private static final long serialVersionUID = 1814260752002876933L; + + JButton singleImageButton, loopButton, quitButton; + GlobalListener globalListener = new GlobalListener(); + + public MainFrame() + { + this.setTitle("Cercloïdator"); + this.setSize(500, 500); + this.setLocationRelativeTo(null); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + init(); + + this.setVisible(true); + } + + private void init() + { + singleImageButton = new JButton("Générateur de cercloids"); + singleImageButton.addActionListener(globalListener); + loopButton = new JButton("Ouvrir le loopUtil"); + loopButton.addActionListener((e) -> + { + Thread t = new Thread(new Runnable() + { + public void run() + { + Main.loopUtilFrame = new LoopUtilFrame(); + } + }); + t.start(); + setVisible(false); + }); + quitButton = new JButton("Quitter"); + quitButton.addActionListener((e) -> System.exit(0)); + + GridLayout gl = new GridLayout(3, 1); + gl.setHgap(20); + gl.setVgap(40); + this.getContentPane().setLayout(gl); + this.getContentPane().add(singleImageButton); + this.getContentPane().add(loopButton); + this.getContentPane().add(quitButton); + } + + private class GlobalListener implements ActionListener + { + + @Override + public void actionPerformed(ActionEvent e) + { + if(e.getSource() == singleImageButton) + { + Thread t = new Thread(new Runnable() + { + public void run() + { + Main.varSetFrame = new VarSetFrame(); + } + }); + t.start(); + setVisible(false); + } + else + { + System.err.println("ERROR : Qqn à déclenché l'actionPerformed mais il a pas été catché"); + } + } + + } + +} \ No newline at end of file diff --git a/src/com/bernard/cercloide/view/SelectPointsPos.java b/src/com/bernard/cercloide/view/SelectPointsPos.java new file mode 100644 index 0000000..ed03623 --- /dev/null +++ b/src/com/bernard/cercloide/view/SelectPointsPos.java @@ -0,0 +1,314 @@ +package com.bernard.cercloide.view; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.JWindow; + +import com.bernard.cercloide.ViewUtil; +import com.bernard.cercloide.main.Config; +import com.bernard.cercloide.main.Sprach; +import com.bernard.cercloide.theory.plan.Point; + +public class SelectPointsPos extends JWindow +{ + + // JFESH + private static final long serialVersionUID = 8716115807757645201L; + + private static final String GRAPHIC_PAN = "graphics", TABBED_PAN = "tab"; + + Point[] selectedFoyers; + CardLayout pointsGetterLayout; + ClickDetectPanel clickDetect; + PointsGetterTabPanel tabGetter; + /** + * 'g'->graphics + * 't'->tableau + */ + static char mode = 'g'; + JButton finish, removeLast, switchMode; + int outWidght, outHeight; + boolean finished; + + GlobalListener globalListener = new GlobalListener(); + + public static final Point[] adapt(Point[] toAdapt, int outWidght, int outHeight) + { + List out = new ArrayList<>(); + for(Point point : toAdapt) + { + Point newPoint = new Point((outWidght / 500) * point.getCoord(1), (outHeight / 500) * point.getCoord(2)); + out.add(newPoint); + } + return (Point[])out.toArray(new Point[out.size()]); + } + + public SelectPointsPos(int outWidght, int outHeight, Point[] lastSelection) + { + this.finished = false; + this.setSize(500, 600); + this.setLocationRelativeTo(null); + this.setAlwaysOnTop(true); + this.outWidght = outWidght; + this.outHeight = outHeight; + this.selectedFoyers = lastSelection; + + init(); + + this.setVisible(true); + } + + private void init() + { + + JPanel payLoadPan = new JPanel(); + pointsGetterLayout = new CardLayout(); + payLoadPan.setLayout(pointsGetterLayout); + + clickDetect = new ClickDetectPanel(); + clickDetect.setPreferredSize(new Dimension(500, 500)); + payLoadPan.add(clickDetect, GRAPHIC_PAN); + + tabGetter = new PointsGetterTabPanel(); + tabGetter.setPreferredSize(new Dimension(500, 500)); + payLoadPan.add(tabGetter, TABBED_PAN); + + JPanel buttonsPanel = new JPanel(); + removeLast = new JButton("Supprimer un point"); + removeLast.addActionListener(globalListener); + removeLast.setEnabled(selectedFoyers.length != 0); + finish = new JButton("Terminé"); + finish.addActionListener(globalListener); + switchMode = new JButton((mode == 'g') ? Sprach.tabMode : Sprach.graphMode); + switchMode.addActionListener((e) -> + { + if(mode == 'g') + { + tabGetter.genDisplay(); + mode = 't'; + pointsGetterLayout.show(payLoadPan, TABBED_PAN); + switchMode.setText(Sprach.graphMode); + ViewUtil.printPanel(this.getRootPane()); + } + else if(mode == 't') + { + mode = 'g'; + pointsGetterLayout.show(payLoadPan, GRAPHIC_PAN); + switchMode.setText(Sprach.tabMode); + } + else + { + throw new IllegalStateException("Le perroquet jovial entraine un hamburger gluant"); + } + this.repaint(); + }); + buttonsPanel.add(removeLast); + buttonsPanel.add(switchMode); + buttonsPanel.add(finish); + + this.getContentPane().setLayout(new BorderLayout()); + this.getContentPane().add(buttonsPanel, BorderLayout.SOUTH); + this.getContentPane().add(payLoadPan, BorderLayout.CENTER); + + pointsGetterLayout.show(payLoadPan, (mode == 'g') ? GRAPHIC_PAN : TABBED_PAN); + + this.pack(); + this.getRootPane().validate(); + } + + public Point[] waitFinish() + { + while(!finished) + { + try + { + Thread.sleep(100); + } + catch(InterruptedException e) + { + e.printStackTrace(); + } + } + return selectedFoyers; + } + + public class GlobalListener implements ActionListener + { + + @Override + public void actionPerformed(ActionEvent e) + { + if(e.getSource() == removeLast) + { + selectedFoyers = Arrays.copyOf(selectedFoyers, selectedFoyers.length - 1); + removeLast.setEnabled(selectedFoyers.length != 0); + repaint(); + } + else if(e.getSource() == finish) + { + finished = true; + setVisible(false); + } + + } + + } + + public class PointsGetterTabPanel extends JPanel + { + //JFESH + private static final long serialVersionUID = -8114335421442093996L; + + JTextField[][] entries; + int dimension = 2; + JPanel inside; + public PointsGetterTabPanel() + { + genDisplay(); + } + public void genDisplay(){ + System.out.println(Arrays.toString(selectedFoyers)); + this.entries = new JTextField[selectedFoyers.length][dimension]; + GridLayout layout = new GridLayout(selectedFoyers.length,dimension); + try{this.remove(inside);}catch(NullPointerException e){} + inside = new JPanel(); + inside.setLayout(layout); + for(int i = 0; i < selectedFoyers.length; i++) + { + Point adapted = new Point((outWidght / 500) * selectedFoyers[i].getCoord(1), (outHeight / 500) * selectedFoyers[i].getCoord(2)); + for(int j = 0; j < dimension; j++) + { + this.entries[i][j] = new JTextField(); + this.entries[i][j].setText(Double.toString(adapted.getCoord(j+1))); + this.entries[i][j].setEditable(true); + this.entries[i][j].setFocusable(true); + inside.add(this.entries[i][j]); + } + } + this.setLayout(new BorderLayout()); + this.add(inside,BorderLayout.CENTER); + this.validate(); + + } + + + + } + + public class ClickDetectPanel extends JPanel implements MouseListener + { + + // JFESH + private static final long serialVersionUID = -4263910544683853470L; + + public ClickDetectPanel() + { + this.addMouseListener(this); + } + + @Override + protected void paintComponent(Graphics g) + { + g.setColor(new Color(Config.selectPointPosColorBackground)); + g.fillRect(0, 0, 500, 500); + for(Point f : selectedFoyers) + { + int x = f.getCoord(1); + int y = f.getCoord(2); + int width = 500, height = 500; + g.setColor(new Color(Config.selectPointPosColorCross)); + g.drawLine(x, y, x, y); + if(x > 1) + { + g.drawLine(x - 1, y, x - 1, y); + } + if(x > 2) + { + g.drawLine(x - 2, y, x - 2, y); + } + if(y > 1) + { + g.drawLine(x, y - 1, x, y - 1); + } + if(y > 2) + { + g.drawLine(x, y - 2, x, y - 2); + } + if(x < width - 1) + { + g.drawLine(x + 1, y, x + 1, y); + } + if(x < width - 2) + { + g.drawLine(x + 2, y, x + 2, y); + } + if(y < height - 1) + { + g.drawLine(x, y + 1, x, y + 1); + } + if(y < height - 2) + { + g.drawLine(x, y + 2, x, y + 2); + } + + } + } + + @Override + public void mouseReleased(MouseEvent e) + { + Point[] selectedFoyers2 = new Point[selectedFoyers.length + 1]; + System.arraycopy(selectedFoyers, 0, selectedFoyers2, 0, selectedFoyers.length); + selectedFoyers2[selectedFoyers.length] = new Point(e.getX(), e.getY()); + selectedFoyers = selectedFoyers2; + System.out.println("Added point :" + selectedFoyers[selectedFoyers.length - 1]); + removeLast.setEnabled(true); + repaint(); + } + + @Override + public void mouseClicked(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + } + +} diff --git a/src/com/bernard/cercloide/view/VarSetFrame.java b/src/com/bernard/cercloide/view/VarSetFrame.java new file mode 100644 index 0000000..800d758 --- /dev/null +++ b/src/com/bernard/cercloide/view/VarSetFrame.java @@ -0,0 +1,531 @@ +package com.bernard.cercloide.view; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.KeyEventDispatcher; +import java.awt.KeyboardFocusManager; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JColorChooser; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + +import com.bernard.cercloide.colorset.ColorSet; +import com.bernard.cercloide.factory.ImageCreator; +import com.bernard.cercloide.factory.JOptPaneCreator; +import com.bernard.cercloide.factory.NumberAnalyser; +import com.bernard.cercloide.theory.plan.Point; + +public class VarSetFrame extends JFrame +{ + // JFESH + private static final long serialVersionUID = -5880101215078205388L; + private static final String WITHOUTRAYONPANE = "withoutRP"; + private static final String WITHRAYONPANE = "withRP"; + private static final String WITHABSOLUTEVALUE = "withAV"; + private static final String WITHRELATIVEVALUE = "withRV"; + private static final String WITHNOVALUE = "withNV"; + + JButton setFoyers; + JTextField getP; + JButton dim1, dim2, dim3; + JTextField rayon, rayonFourch; + JCheckBox withRayon; + JTextField widthAsk, heightAsk; + ButtonGroup crossGroup; + JRadioButton crossDefault, crossAbsolute, crossRelative, noCross; + JCheckBox viewProgress; + JTextField crossAbsoluteOut, crossRelativeOut; + JPanel crossOutputPane; + CardLayout crossActionLayout; + JComboBox colorSet; + JColorChooser rayonColorChooser; + JPanel colorPanel; + CardLayout colorLayout; + JButton run; + + Point[] settedFoyers; + SelectPointsPos spp; + + GlobalListener globalListener = new GlobalListener(); + + public VarSetFrame() + { + this.setTitle("Cercloïdator"); + this.setSize(1000, 500); + this.setResizable(true); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + settedFoyers = new Point[0]; + + init(); + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(globalListener); + this.setLocationRelativeTo(null); + this.setVisible(true); + } + + public void init() + { + this.setContentPane(new JPanel()); + final Font generalFont = new Font("OCR A Extended", Font.ITALIC, 20); + + settedFoyers = new Point[0]; + + JPanel foyersPanel = new JPanel(); + foyersPanel.setLayout(new BorderLayout()); + setFoyers = new JButton("Régler les Foyers"); + setFoyers.setFont(generalFont); + setFoyers.addActionListener(globalListener); + foyersPanel.add(setFoyers, BorderLayout.CENTER); + + JPanel pPanel = new JPanel(); + pPanel.setLayout(new BorderLayout()); + JLabel pLabel = new JLabel("P ="); + pLabel.setFont(generalFont); + getP = new JTextField(); + getP.setText("2"); + getP.setToolTipText("ex: 2"); + pPanel.add(pLabel, BorderLayout.WEST); + pPanel.add(getP, BorderLayout.CENTER); + + JPanel dimPanel = new JPanel(); + dimPanel.setLayout(new BorderLayout()); + JLabel dimLabel = new JLabel("Dimension :"); + dimLabel.setFont(generalFont); + JPanel dimChoicePanel = new JPanel(); + dimChoicePanel.setLayout(new GridLayout(1, 3)); + dim1 = new JButton("1"); + dim1.setToolTipText("Not implemented(yet)"); + dim1.setEnabled(false); + dim2 = new JButton("2"); + dim3 = new JButton("3"); + dim3.setToolTipText("Not implemented(yet)"); + dim3.setEnabled(false); + dimChoicePanel.add(dim1); + dimChoicePanel.add(dim2); + dimChoicePanel.add(dim3); + dimPanel.add(dimLabel, BorderLayout.WEST); + dimPanel.add(dimChoicePanel, BorderLayout.CENTER); + + JPanel rayonPanel = new JPanel(); + rayonPanel.setLayout(new BoxLayout(rayonPanel, BoxLayout.LINE_AXIS)); + JLabel rayonLabel = new JLabel("Rayon :"); + rayonLabel.setFont(generalFont); + rayon = new JTextField(); + rayon.setToolTipText("ex: 403"); + rayon.setEnabled(false); + JLabel rayonFourchLabel = new JLabel("Fourchette =/- :"); + rayonFourchLabel.setFont(generalFont); + rayonFourch = new JTextField(); + rayonFourch.setText("-1"); + rayonFourch.setToolTipText("ex: 3"); + rayonFourch.setEnabled(false); + withRayon = new JCheckBox(); + withRayon.setToolTipText("Desactiver affichera tous les rayons avec des couleurs différentes"); + withRayon.addActionListener(globalListener); + rayonPanel.add(rayonLabel); + rayonPanel.add(rayon); + rayonPanel.add(rayonFourchLabel); + rayonPanel.add(rayonFourch); + rayonPanel.add(withRayon); + + JPanel sizePanel = new JPanel(); + sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.LINE_AXIS)); + JLabel sizeLabel = new JLabel("Largeur/Hauteur :"); + sizeLabel.setFont(generalFont); + widthAsk = new JTextField(); + widthAsk.setText("500"); + JLabel sizeSeparator = new JLabel("/"); + sizeSeparator.setFont(generalFont); + heightAsk = new JTextField(); + heightAsk.setText("500"); + sizePanel.add(sizeLabel); + sizePanel.add(widthAsk); + sizePanel.add(sizeSeparator); + sizePanel.add(heightAsk); + + JPanel crossPane = new JPanel(); + crossPane.setLayout(new BorderLayout()); + JPanel crossRadioPane = new JPanel(); + crossRadioPane.setLayout(new BoxLayout(crossRadioPane, BoxLayout.LINE_AXIS)); + JLabel crossRadioLabel = new JLabel("Marquage des foyers :"); + crossRadioLabel.setFont(generalFont); + crossDefault = new JRadioButton("Par défaut"); + crossDefault.setFont(generalFont); + crossDefault.addActionListener(globalListener); + crossAbsolute = new JRadioButton("Absolu"); + crossAbsolute.setFont(generalFont); + crossAbsolute.addActionListener(globalListener); + crossRelative = new JRadioButton("Relatif"); + crossRelative.setFont(generalFont); + crossRelative.addActionListener(globalListener); + noCross = new JRadioButton("Aucun"); + noCross.setFont(generalFont); + noCross.addActionListener(globalListener); + crossDefault.setSelected(true); + crossGroup = new ButtonGroup(); + crossGroup.add(crossDefault); + crossGroup.add(crossAbsolute); + crossGroup.add(crossRelative); + crossGroup.add(noCross); + viewProgress = new JCheckBox(); + viewProgress.addActionListener(globalListener); + viewProgress.setSelected(true); + viewProgress.setToolTipText("View the progress of the drawing"); + crossRadioPane.add(crossRadioLabel); + crossRadioPane.add(crossDefault); + crossRadioPane.add(crossAbsolute); + crossRadioPane.add(crossRelative); + crossRadioPane.add(noCross); + crossRadioPane.add(viewProgress); + crossPane.add(crossRadioPane, BorderLayout.CENTER); + crossOutputPane = new JPanel(); + crossActionLayout = new CardLayout(); + crossOutputPane.setLayout(crossActionLayout); + crossAbsoluteOut = new JTextField("2"); + crossAbsoluteOut.setToolTipText("Taille de chaque branche *2 pour hauteur=largeur=500"); + crossAbsoluteOut.setFont(generalFont); + crossRelativeOut = new JTextField("2"); + crossRelativeOut.setToolTipText("Taille de chaque branche pour hauteur=largeur=500"); + crossRelativeOut.setFont(generalFont); + crossOutputPane.add(crossAbsoluteOut, WITHABSOLUTEVALUE); + crossOutputPane.add(crossRelativeOut, WITHRELATIVEVALUE); + crossOutputPane.add(new JPanel(), WITHNOVALUE); + crossActionLayout.show(crossOutputPane, WITHNOVALUE); + crossPane.add(crossOutputPane, BorderLayout.SOUTH); + + colorPanel = new JPanel(); + colorLayout = new CardLayout(); + colorPanel.setLayout(colorLayout); + JPanel colorPanelWithR = new JPanel(); + colorPanelWithR.setLayout(new BorderLayout()); + JLabel colorWithRLabel = new JLabel("Couleur du rayon :"); + colorWithRLabel.setFont(generalFont); + rayonColorChooser = new JColorChooser(); + rayonColorChooser.setFont(generalFont); + colorPanelWithR.add(colorWithRLabel, BorderLayout.WEST); + colorPanelWithR.add(rayonColorChooser, BorderLayout.CENTER); + JPanel colorPanelWithoutR = new JPanel(); + colorPanelWithoutR.setLayout(new BorderLayout()); + JPanel colorPanelWithoutRIn = new JPanel(); + colorPanelWithoutRIn.setLayout(new BorderLayout()); + JLabel colorWithoutRLabel = new JLabel("Jeu de couleurs :"); + colorWithoutRLabel.setFont(generalFont); + colorSet = new JComboBox<>(ColorSet.values()); + colorSet.setPreferredSize(new Dimension(625, 32)); + colorPanelWithoutRIn.add(colorWithoutRLabel, BorderLayout.WEST); + colorPanelWithoutRIn.add(colorSet, BorderLayout.CENTER); + colorPanelWithoutR.add(colorPanelWithoutRIn, BorderLayout.NORTH); + colorPanel.add(colorPanelWithoutR, WITHOUTRAYONPANE); + colorPanel.add(colorPanelWithR, WITHRAYONPANE); + + JPanel runPan = new JPanel(); + runPan.setLayout(new BorderLayout()); + run = new JButton("Lancer le dessin"); + run.addActionListener(globalListener); + runPan.add(run, BorderLayout.CENTER); + + this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.PAGE_AXIS)); + this.getContentPane().add(foyersPanel); + this.getContentPane().add(pPanel); + this.getContentPane().add(dimPanel); + this.getContentPane().add(rayonPanel); + this.getContentPane().add(sizePanel); + this.getContentPane().add(crossPane); + this.getContentPane().add(colorPanel); + this.getContentPane().add(runPan); + + this.pack(); + } + + public boolean testVars() + { + try + { + NumberAnalyser.parseDouble(getP.getText()); + } + catch(NumberFormatException e) + { + if(getP.getText().toUpperCase().equals("+INF") || getP.getText().toUpperCase().equals("-INF")) + { + + } + else + { + JOptPaneCreator.argumentError("P ne peut pas être égal à " + getP.getText()); + return false; + } + } + if(withRayon.isSelected()) + { + + try + { + NumberAnalyser.parseLong(rayon.getText()); + } + catch(NumberFormatException e) + { + JOptPaneCreator.argumentError("Le rayon ne peut pas être égal à " + rayon.getText()); + return false; + } + + try + { + NumberAnalyser.parseLong(rayonFourch.getText()); + } + catch(NumberFormatException e) + { + JOptPaneCreator.argumentError("La fourchette du rayon ne peut pas être égale à " + rayonFourch.getText()); + return false; + } + } + try + { + NumberAnalyser.parseLong(widthAsk.getText()); + } + catch(NumberFormatException e) + { + JOptPaneCreator.argumentError("La largeur ne peut pas être égale à " + widthAsk.getText()); + return false; + } + try + { + NumberAnalyser.parseLong(heightAsk.getText()); + } + catch(NumberFormatException e) + { + JOptPaneCreator.argumentError("La hauteur ne peut pas être égale à " + heightAsk.getText()); + return false; + } + if(crossRelative.isSelected()) + { + try + { + NumberAnalyser.parseLong(crossRelativeOut.getText()); + } + catch(NumberFormatException e) + { + JOptPaneCreator.argumentError("La taille relative de la croix ne peut pas être égale à " + crossRelativeOut.getText()); + return false; + } + } + if(crossAbsolute.isSelected()) + { + try + { + NumberAnalyser.parseLong(crossAbsoluteOut.getText()); + } + catch(NumberFormatException e) + { + JOptPaneCreator.argumentError("Le taille absolue de la croix ne peut pas être égale à " + crossAbsoluteOut.getText()); + return false; + } + } + if(settedFoyers.length == 0) + { + int option = JOptionPane.showConfirmDialog(null, "Aucun foyer n'a été placé! Voulez-vous quand même générer l'image ?", "Aucun foyer", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); + + if(option != JOptionPane.YES_OPTION) + { + return false; + } + } + return true; + } + + private VarSetFrame getThis() + { + return this; + } + + private class GlobalListener implements ActionListener, KeyEventDispatcher + { + + @Override + public void actionPerformed(ActionEvent e) + { + if(e.getSource() == withRayon) + { + if(withRayon.isSelected()) + { + rayon.setEnabled(true); + rayonFourch.setEnabled(true); + colorLayout.show(colorPanel, WITHRAYONPANE); + } + else + { + rayon.setEnabled(false); + rayonFourch.setEnabled(false); + colorLayout.show(colorPanel, WITHOUTRAYONPANE); + } + } + else if(e.getSource() == run) + { + if(testVars()) + { + Thread t = new Thread(new Runnable() + { + + @Override + public void run() + { + if(new File("cercloids_outs").exists()) + { + new File("cercloids_outs").mkdirs(); + } + Double p = NumberAnalyser.parseDouble(getP.getText()); + int w = NumberAnalyser.parseLong(widthAsk.getText()).intValue(), h = NumberAnalyser.parseLong(heightAsk.getText()).intValue(); + char crossConv = 'µ'; + int crossNum = -1; + if(crossDefault.isSelected()) + { + crossConv = 'd'; + crossNum = 0; + } + else if(crossAbsolute.isSelected()) + { + crossConv = 'a'; + crossNum = NumberAnalyser.parseLong(crossAbsoluteOut.getText()).intValue(); + } + else if(crossRelative.isSelected()) + { + crossConv = 'r'; + crossNum = NumberAnalyser.parseLong(crossRelativeOut.getText()).intValue(); + } + else if(noCross.isSelected()) + { + crossConv = 'n'; + crossNum = 0; + } + Path outPath = Paths.get("cercloid_outs/" + getFileName(p, w, h, crossConv, crossNum, withRayon.isSelected(), rayon.getText(), rayonColorChooser.getColor(), rayonFourch.getText(), (ColorSet)colorSet.getSelectedItem()) + ".png"); + if(withRayon.isSelected()) + { + Long fourch = NumberAnalyser.parseLong(rayonFourch.getText()); + if(fourch == -1) + { + ImageCreator.createImage(getThis(), outPath, SelectPointsPos.adapt(settedFoyers, w, h), p, rayonColorChooser.getColor(), NumberAnalyser.parseLong(rayon.getText()), w, h, Color.RED, crossConv, crossNum, (viewProgress.isSelected()) ? new ViewDrawingProgress() : null); + } + else + { + ImageCreator.createImage(getThis(), outPath, SelectPointsPos.adapt(settedFoyers, w, h), p, rayonColorChooser.getColor(), NumberAnalyser.parseLong(rayon.getText()), fourch.intValue(), w, h, Color.RED, crossConv, crossNum, (viewProgress.isSelected()) ? new ViewDrawingProgress() : null); + } + } + else + { + ImageCreator.createImage(getThis(), outPath, SelectPointsPos.adapt(settedFoyers, w, h), p, (ColorSet)colorSet.getSelectedItem(), w, h, Color.RED, crossConv, crossNum, (viewProgress.isSelected()) ? new ViewDrawingProgress() : null); + } + + setVisible(true); + } + + }); + setVisible(false); + t.start(); + } + } + else if(e.getSource() == setFoyers) + { + Thread t = new Thread(new Runnable() + { + + @Override + public void run() + { + int w = NumberAnalyser.parseLong(widthAsk.getText()).intValue(), h = NumberAnalyser.parseLong(heightAsk.getText()).intValue(); + spp = new SelectPointsPos(w, h, settedFoyers); + + setEnabled(false); + try + { + Thread.sleep(250); + } + catch(InterruptedException e1) + { + e1.printStackTrace(); + } + settedFoyers = spp.waitFinish(); + setEnabled(true); + } + }); + t.start(); + + } + else if(e.getSource() == crossDefault) + { + crossActionLayout.show(crossOutputPane, WITHNOVALUE); + } + else if(e.getSource() == crossAbsolute) + { + crossActionLayout.show(crossOutputPane, WITHABSOLUTEVALUE); + } + else if(e.getSource() == crossRelative) + { + crossActionLayout.show(crossOutputPane, WITHRELATIVEVALUE); + } + else if(e.getSource() == noCross) + { + crossActionLayout.show(crossOutputPane, WITHNOVALUE); + } + } + + @Override + public boolean dispatchKeyEvent(KeyEvent e) + { + if(e.isControlDown() && (e.getKeyCode() == KeyEvent.VK_NUMPAD7 || e.getKeyCode() == KeyEvent.VK_7)) + { + widthAsk.setText("5000"); + heightAsk.setText("5000"); + withRayon.setSelected(true); + rayonColorChooser.setColor(17, 23, 142); + rayon.setText("500"); + settedFoyers = new Point[] {new Point(250, 250)}; + System.out.println("Preset 7"); + }else if(e.isControlDown() && (e.getKeyCode() == KeyEvent.VK_NUMPAD1 || e.getKeyCode() == KeyEvent.VK_1)) + { + widthAsk.setText("500"); + heightAsk.setText("500"); + withRayon.setSelected(true); + rayonColorChooser.setColor(0,0,0); + rayon.setText("200"); + settedFoyers = new Point[] {new Point(250, 250)}; + System.out.println("Preset 1"); + } + return false; + } + + } + + public static final String getFileName(Double p, int w, int h, char crossConv, int crossNum, boolean withRayon, String rayon, Color rayonColor, String rayonFourch, ColorSet colorSet) + { + String sgout = "out_"; + sgout += "p=" + p + ";"; + sgout += "w=" + w + "_h=" + h + ";"; + if(withRayon) + { + sgout += (String)("r=" + rayon + "+-" + rayonFourch + "color=" + rayonColor.toString()); + } + else + { + sgout += "color=" + colorSet.toString(); + } + sgout = sgout.replaceAll(">", "-"); + return sgout; + } +} diff --git a/src/com/bernard/cercloide/view/ViewDrawingProgress.java b/src/com/bernard/cercloide/view/ViewDrawingProgress.java new file mode 100644 index 0000000..5382726 --- /dev/null +++ b/src/com/bernard/cercloide/view/ViewDrawingProgress.java @@ -0,0 +1,37 @@ +package com.bernard.cercloide.view; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; + +import javax.swing.JFrame; +import javax.swing.JPanel; + +public class ViewDrawingProgress extends JFrame { + + private static final long serialVersionUID = 4618795009439632909L; + private BufferedImage image; + + public ViewDrawingProgress() { + this.setTitle("Dessin en cours ..."); + this.setSize(500, 500); + this.setLocationRelativeTo(null); + this.setContentPane(new ImagePanel()); + this.setVisible(true); + } + + public void updateWithImage(BufferedImage img) { + this.image = img; + this.repaint(); + } + + public class ImagePanel extends JPanel { + + private static final long serialVersionUID = -4292881599714388236L; + + @Override + protected void paintComponent(Graphics g) { + g.drawImage(image, 0, 0, getWidth(), getHeight(), ViewDrawingProgress.this); + } + } + +} diff --git a/src/com/bernard/cercloide/view/WaitFrame.java b/src/com/bernard/cercloide/view/WaitFrame.java new file mode 100644 index 0000000..483d56e --- /dev/null +++ b/src/com/bernard/cercloide/view/WaitFrame.java @@ -0,0 +1,28 @@ +package com.bernard.cercloide.view; + +import javax.swing.JFrame; +import javax.swing.JProgressBar; + +public class WaitFrame extends JFrame { + + private static final long serialVersionUID = 4962926088577592668L; + + public JProgressBar progressBar; + + public WaitFrame(long total) { + this.setSize(500, 100); + this.setLocationRelativeTo(null); + this.setTitle("Veuillez patienter . . . . . . . . . . . etc"); + this.setResizable(false); + + progressBar = new JProgressBar(); + progressBar.setMaximum((int) total); + progressBar.setStringPainted(true); + + + this.getContentPane().add(progressBar); + + this.setVisible(true); + } + +}