
/*
 * File: NameSurferGraph.java
 * ---------------------------
 * This class represents the canvas on which the graph of
 * names is drawn. This class is responsible for updating
 * (redrawing) the graphs whenever the list of entries changes or the window is resized.
 */

import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;

public class NameSurferGraph extends Pane implements NameSurferConstants {
    public NameSurferGraph() {
        super();

        setWhiteBackground();
        drawDecadeLines();
    }

    private void setWhiteBackground() {
        this.setStyle("-fx-background-color: white");
    }

    private void drawDecadeLines() {
        for (int i = 0; i < NDECADES; i++) {
            drawVerticalLine(i);
        }
    }

    private void drawVerticalLine(int decadeIndex) {
        Line line = new Line();
        line.setStartY(0);
        line.endYProperty().bind(heightProperty());
        line.startXProperty().bind(widthProperty().divide(NDECADES).multiply(decadeIndex));
        line.endXProperty().bind(line.startXProperty());

        this.getChildren().add(line);
    }
}

// public class NameSurferGraph extends GCanvas
// implements NameSurferConstants, ComponentListener {
//
// /**
// * Creates a new NameSurferGraph object that displays the data.
// */
// public NameSurferGraph() {
// addComponentListener(this);
// // You fill in the rest //
// }
//
// /**
// * Clears the list of name surfer entries stored inside this class.
// */
// public void clear() {
// // You fill this in //
// }
//
// /* Method: addEntry(entry) */
// /**
// * Adds a new NameSurferEntry to the list of entries on the display.
// * Note that this method does not actually draw the graph, but
// * simply stores the entry; the graph is drawn by calling update.
// */
// public void addEntry(NameSurferEntry entry) {
// // You fill this in //
// }
//
//
//
// /**
// * Updates the display image by deleting all the graphical objects
// * from the canvas and then reassembling the display according to
// * the list of entries. Your application must call update after
// * calling either clear or addEntry; update is also called whenever
// * the size of the canvas changes.
// */
// public void update() {
// // You fill this in //
// }
//
//
//
//
// /* Implementation of the ComponentListener interface */
// public void componentHidden(ComponentEvent e) { }
// public void componentMoved(ComponentEvent e) { }
// public void componentResized(ComponentEvent e) { update(); }
// public void componentShown(ComponentEvent e) { }
// }

@@ -268,16 +268,51 @@
 d.%0A */%0A%0A
+import javafx.scene.control.Label;%0A
 import j
@@ -444,16 +444,65 @@
 tants %7B%0A
+    private static final int LABEL_PADDING = 2;%0A%0A
     publ
@@ -584,26 +584,95 @@
     draw
-DecadeLine
+VerticalGridLines();%0A        drawHorizontalGridLines();%0A        drawDecadeLabel
 s();%0A   
@@ -797,22 +797,28 @@
 oid draw
-Decade
+VerticalGrid
 Lines() 
@@ -1017,70 +1017,431 @@
 ne.s
-etStartY(0);%0A        line.endYProperty().bind(heightProperty()
+tartXProperty().bind(widthProperty().divide(NDECADES).multiply(decadeIndex));%0A        line.endXProperty().bind(line.startXProperty());%0A        line.setStartY(0);%0A        line.endYProperty().bind(heightProperty());%0A%0A        this.getChildren().add(line);%0A    %7D%0A%0A    private void drawHorizontalGridLines() %7B%0A        drawTopLine();%0A        drawBottomLine();%0A    %7D%0A%0A    private void drawTopLine() %7B%0A        Line line = new Line(
 );%0A 
@@ -1445,37 +1445,62 @@
 ;%0A        line.s
+etS
 tartX
+(0);%0A        line.endX
 Property().bind(
@@ -1518,103 +1518,1001 @@
 ty()
-.divide(NDECADES).multiply(decadeIndex));%0A        line.endXProperty().bind(line.startXProperty(
+);%0A        line.setStartY(GRAPH_MARGIN_SIZE);%0A        line.setEndY(GRAPH_MARGIN_SIZE);%0A%0A        this.getChildren().add(line);%0A    %7D%0A%0A    private void drawBottomLine() %7B%0A        Line line = new Line();%0A        line.setStartX(0);%0A        line.endXProperty().bind(widthProperty());%0A        line.startYProperty().bind(heightProperty().subtract(GRAPH_MARGIN_SIZE));%0A        line.endYProperty().bind(line.startYProperty());%0A%0A        this.getChildren().add(line);%0A    %7D%0A%0A    private void drawDecadeLabels() %7B%0A        for (int i = 0; i %3C NDECADES; i++) %7B%0A            drawDecadeLabel(i);%0A        %7D%0A    %7D%0A%0A    private void drawDecadeLabel(int decadeIndex) %7B%0A        Label label = new Label(Integer.toString(START_DECADE + decadeIndex * 10));%0A        // TODO: can we remove duplication here?%0A        label.layoutXProperty().bind(widthProperty().divide(NDECADES).multiply(decadeIndex).add(LABEL_PADDING));%0A        label.layoutYProperty().bind(heightProperty().subtract(GRAPH_MARGIN_SIZE).add(LABEL_PADDING
 ));%0A
@@ -2536,35 +2536,36 @@
 Children().add(l
-ine
+abel
 );%0A    %7D%0A%7D%0A%0A// p

Implement assignment 6 milestone 4