Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. public Touche creerTouche()
  2. {
  3. Touche touche= new Touche();
  4. Note note = new Note();
  5.  
  6. validateCreation(touche,note);
  7.  
  8. return touche;
  9. }
  10.  
  11. public ArrayList<ValidationResult> validateCreation(Touche p_touche, Note p_note)
  12. {
  13. ArrayList<ValidationResult> arrayValidationResultErrors = new ArrayList<ValidationResult>();
  14.  
  15. int rougeTouche = 0;
  16. int greenTouche=0;
  17. int blueTouche=0;
  18.  
  19. int rougeBordure=0;
  20. int greenBordure=0;
  21. int blueBordure=0;
  22.  
  23. FormeEnum formeEnum=FormeEnum.valueOf(mainWindow.getFormeComboBox().toString());
  24.  
  25. float taille=0;
  26. float epaisseur=0;
  27.  
  28. String nom="";
  29. //À FAIRE FILE PATH
  30. String pathImage="";
  31. float persistance=0;
  32. float amplitude=0;
  33. float frequence=0;
  34. float octave=0;
  35.  
  36.  
  37. //RGB
  38. arrayValidationResultErrors.add(rgbValidate(mainWindow.getRougeTextFieldTouche().toString(), rougeTouche));
  39. arrayValidationResultErrors.add(rgbValidate(mainWindow.getBleuTextFieldTouche().toString(), blueTouche));
  40. arrayValidationResultErrors.add(rgbValidate(mainWindow.getVertTextFieldTouche().toString(), greenTouche));
  41. arrayValidationResultErrors.add(rgbValidate(mainWindow.getRougeTextFieldBordure().toString(), rougeBordure));
  42. arrayValidationResultErrors.add(rgbValidate(mainWindow.getBleuTextFieldBordure().toString(), blueBordure));
  43. arrayValidationResultErrors.add(rgbValidate(mainWindow.getVertTextFieldBordure().toString(), greenBordure));
  44. //FLOAT
  45. arrayValidationResultErrors.add(floatValidate(mainWindow.getTailleTextField().toString(),taille));
  46. arrayValidationResultErrors.add(floatValidate(mainWindow.getEpaisseurTextField().toString(),epaisseur));
  47. arrayValidationResultErrors.add(floatValidate(mainWindow.getPersistanceTextField().toString(),persistance));
  48. arrayValidationResultErrors.add(floatValidate(mainWindow.getFrequenceTextField().toString(),frequence));
  49. arrayValidationResultErrors.add(floatValidate(mainWindow.getOctaveTextField().toString(),octave));
  50. arrayValidationResultErrors.add(floatValidate(mainWindow.getAmplitudeTextField().toString(),amplitude));
  51. //STRING
  52. arrayValidationResultErrors.add(stringValidate(mainWindow.getNomTextField().toString(),nom));
  53.  
  54. for(ValidationResult validation : arrayValidationResultErrors)
  55. {
  56. if(!validation.isSuccess())
  57. {
  58. return null;
  59. }
  60. }
  61.  
  62. p_touche= new Touche(formeEnum,null,rougeTouche,greenTouche,blueTouche,new Bordure(rougeBordure,greenBordure,blueBordure,epaisseur),taille,p_note);
  63. return arrayValidationResultErrors;
  64.  
  65. }
  66.  
  67. public ValidationResult rgbValidate(String p_string, int ref)
  68. {
  69. if(isInteger(p_string).isSuccess())
  70. {
  71. int value= Integer.parseInt(p_string);
  72. if(value>=0&&value<=255)
  73. {
  74. ref=value;
  75. return new ValidationResult(true);
  76. }
  77. else
  78. {
  79. return new ValidationResult(false,"Champ doit être de 0 à 255");
  80. }
  81. }
  82. else
  83. {
  84. return new ValidationResult(false,"Champ vide ou pas un nombre");
  85. }
  86. }
  87.  
  88. public ValidationResult floatValidate(String p_string, float ref)
  89. {
  90. try {
  91. ref=Float.parseFloat(p_string);
  92. } catch(NumberFormatException e) {
  93. return new ValidationResult(false,e.getMessage()) ;
  94. } catch(NullPointerException e) {
  95. return new ValidationResult(false,e.getMessage());
  96. }
  97. return new ValidationResult(true);
  98. }
  99.  
  100. public ValidationResult integerValidate(String p_string, int ref)
  101. {
  102. try {
  103. ref=Integer.parseInt(p_string);
  104. } catch(NumberFormatException e) {
  105. return new ValidationResult(false,e.getMessage()) ;
  106. } catch(NullPointerException e) {
  107. return new ValidationResult(false,e.getMessage());
  108. }
  109. return new ValidationResult(true);
  110. }
  111.  
  112. public ValidationResult stringValidate(String p_string,String ref)
  113. {
  114. if(!ref.isEmpty())
  115. {
  116. return new ValidationResult(true);
  117. }
  118. else
  119. {
  120. return new ValidationResult(false,"Champ vide");
  121. }
  122. }
  123.  
  124.  
  125. public ValidationResult isFloat(String s) {
  126. try {
  127. Float.parseFloat(s);
  128. } catch(NumberFormatException e) {
  129. return new ValidationResult(false,e.getMessage()) ;
  130. } catch(NullPointerException e) {
  131. return new ValidationResult(false,e.getMessage());
  132. }
  133. return new ValidationResult(true);
  134. }
  135.  
  136.  
  137. public ValidationResult isInteger(String s) {
  138. try {
  139. Integer.parseInt(s);
  140. } catch(NumberFormatException e) {
  141. return new ValidationResult(false,e.getMessage()) ;
  142. } catch(NullPointerException e) {
  143. return new ValidationResult(false,e.getMessage());
  144. }
  145. return new ValidationResult(true);
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement