Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TestSurvey.DisplayManager;
- import java.util.ArrayList;
- import java.util.Arrays;
- import edu.drexel.cs350.FeatureFactory;
- import edu.drexel.cs350.Geometry;
- import edu.drexel.cs350.graphics.*;
- import TestSurvey.Questions.Question;
- public abstract class AbstractDisplayManager {
- /**
- * @author Zachary Tahenakos
- * @version 1.0
- *
- * AbstractDisplayManager
- * This abstract class provides a means in which to Print out a Survey or Test. This class has 3 direct children:
- * 1. ConsoleDisplayManager: Display to Console
- * 2. PNGDisplayManager: Output to a png file*
- * 3. PSDisplayManager: Output to a ps file*
- * * Only Surveys can be outputted to these.
- */
- /* <-----> CLASS VARIABLES <-----> */
- protected Renderer gfx;
- protected Geometry geom;
- protected FeatureFactory featFact;
- protected String docName;
- private int dy = 14;
- private final int X_CORD = 5;
- private final int FONT_SIZE = 14;
- public void OutputBlankSurvey(ArrayList<Question> questions){
- /**
- * @param ArrayList<Question>: List of Questions
- *
- * run
- * The run function is the main driver of the DisplayManagers. Given an ArrayList of Questions,
- * it will iterate through them one by one and spit them out to the appropriate medium, whether it be
- * a ps file, a png file, or to stdout.
- */
- //Put the Name of the Survey in a cute little Rectangle
- geom.add(featFact.createRectangle(2, 2, docName.length() * 8, 15));
- geom.add(featFact.createText(X_CORD, 14, docName, FONT_SIZE));
- int qNum = 0;
- for(Question q : questions){
- //Iterate through each question, adding them to our Geometry object
- incYOffset(); // Increase Y Axis offset per run
- incYOffset(); // We do this twice for nice spacing between each question
- this.Display(++qNum, q);
- }
- //All done! Now, render the Geometry and Graphics
- geom.render();
- gfx.render();
- }
- public void Display(int qNum, Question q){
- /**
- * @param int: The question number
- * @param Question: The question
- *
- * Display
- * The Display method's job is to take a Question, parse out its data, and send it to the appropriate
- * output stream. We have a little hacky way of doing Prompts if it is a ShortAnswerquestion because
- * its prompt is created on the fly.
- */
- ArrayList<String> qData = q.getQuestionData();
- String prompt = Integer.toString(qNum) + ": " + qData.remove(0);
- if(q.getClass().getSimpleName().equals("ShortAnswerQuestion")){
- prompt = prompt + " (Response limited to " + qData.remove(0) + " characters)";
- }
- geom.add(featFact.createText(X_CORD, dy, prompt, FONT_SIZE));
- for(String data : qData){
- //Iterate through the rest of the fun stuff
- incYOffset(); //Can't forget to offset!
- data = data.replace("[", ""); //Clean up the nasty Array stuff from our String
- data = data.replace("]", "");
- ArrayList<String> responseList = new ArrayList<String>(Arrays.asList(data.split(",")));
- StringBuilder responseBuilder = new StringBuilder();
- for(int i = 0; i < responseList.size(); ++i){
- //We now iterate through each element in our ArrayList, adding it to a StringBuilder.
- //Unfortunately, a : must be used instead of a ) for Response Letters, the ) confuses ps
- responseBuilder.append((char) ('a'+i) + ": " + responseList.get(i) + " ");
- }
- geom.add(featFact.createText(X_CORD, dy, responseBuilder.toString(), FONT_SIZE));
- }
- }
- private void incYOffset(){
- /**
- * incYOffset
- * Simple method for increase our y position in the document
- */
- dy += 18;
- }
- }
Add Comment
Please, Sign In to add comment