Guest User

Untitled

a guest
Mar 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. package TestSurvey.DisplayManager;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5.  
  6. import edu.drexel.cs350.FeatureFactory;
  7. import edu.drexel.cs350.Geometry;
  8. import edu.drexel.cs350.graphics.*;
  9.  
  10. import TestSurvey.Questions.Question;
  11.  
  12. public abstract class AbstractDisplayManager {
  13. /**
  14. * @author Zachary Tahenakos
  15. * @version 1.0
  16. *
  17. * AbstractDisplayManager
  18. * This abstract class provides a means in which to Print out a Survey or Test. This class has 3 direct children:
  19. * 1. ConsoleDisplayManager: Display to Console
  20. * 2. PNGDisplayManager: Output to a png file*
  21. * 3. PSDisplayManager: Output to a ps file*
  22. * * Only Surveys can be outputted to these.
  23. */
  24.  
  25. /* <-----> CLASS VARIABLES <-----> */
  26. protected Renderer gfx;
  27. protected Geometry geom;
  28. protected FeatureFactory featFact;
  29. protected String docName;
  30. private int dy = 14;
  31. private final int X_CORD = 5;
  32. private final int FONT_SIZE = 14;
  33.  
  34. public void OutputBlankSurvey(ArrayList<Question> questions){
  35. /**
  36. * @param ArrayList<Question>: List of Questions
  37. *
  38. * run
  39. * The run function is the main driver of the DisplayManagers. Given an ArrayList of Questions,
  40. * it will iterate through them one by one and spit them out to the appropriate medium, whether it be
  41. * a ps file, a png file, or to stdout.
  42. */
  43.  
  44. //Put the Name of the Survey in a cute little Rectangle
  45. geom.add(featFact.createRectangle(2, 2, docName.length() * 8, 15));
  46. geom.add(featFact.createText(X_CORD, 14, docName, FONT_SIZE));
  47.  
  48. int qNum = 0;
  49. for(Question q : questions){
  50. //Iterate through each question, adding them to our Geometry object
  51. incYOffset(); // Increase Y Axis offset per run
  52. incYOffset(); // We do this twice for nice spacing between each question
  53. this.Display(++qNum, q);
  54. }
  55.  
  56. //All done! Now, render the Geometry and Graphics
  57. geom.render();
  58. gfx.render();
  59. }
  60.  
  61. public void Display(int qNum, Question q){
  62. /**
  63. * @param int: The question number
  64. * @param Question: The question
  65. *
  66. * Display
  67. * The Display method's job is to take a Question, parse out its data, and send it to the appropriate
  68. * output stream. We have a little hacky way of doing Prompts if it is a ShortAnswerquestion because
  69. * its prompt is created on the fly.
  70. */
  71.  
  72. ArrayList<String> qData = q.getQuestionData();
  73.  
  74. String prompt = Integer.toString(qNum) + ": " + qData.remove(0);
  75. if(q.getClass().getSimpleName().equals("ShortAnswerQuestion")){
  76. prompt = prompt + " (Response limited to " + qData.remove(0) + " characters)";
  77. }
  78.  
  79. geom.add(featFact.createText(X_CORD, dy, prompt, FONT_SIZE));
  80.  
  81. for(String data : qData){
  82. //Iterate through the rest of the fun stuff
  83. incYOffset(); //Can't forget to offset!
  84. data = data.replace("[", ""); //Clean up the nasty Array stuff from our String
  85. data = data.replace("]", "");
  86. ArrayList<String> responseList = new ArrayList<String>(Arrays.asList(data.split(",")));
  87. StringBuilder responseBuilder = new StringBuilder();
  88. for(int i = 0; i < responseList.size(); ++i){
  89. //We now iterate through each element in our ArrayList, adding it to a StringBuilder.
  90. //Unfortunately, a : must be used instead of a ) for Response Letters, the ) confuses ps
  91. responseBuilder.append((char) ('a'+i) + ": " + responseList.get(i) + " ");
  92. }
  93. geom.add(featFact.createText(X_CORD, dy, responseBuilder.toString(), FONT_SIZE));
  94. }
  95. }
  96.  
  97. private void incYOffset(){
  98. /**
  99. * incYOffset
  100. * Simple method for increase our y position in the document
  101. */
  102.  
  103. dy += 18;
  104. }
  105. }
Add Comment
Please, Sign In to add comment