<commit_before>package gui.componentdrawers;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import gui.mainclasses.StageInitializer;


public class GridDrawer extends ComponentDrawer {

    public static final double GRID_WIDTH_RATIO = .6;
    public static final double GRID_HEIGHT_RATIO = .6;
    public static final double GRID_WIDTH = StageInitializer.SCREEN_WIDTH * GRID_WIDTH_RATIO;
    public static final double GRID_HEIGHT = StageInitializer.SCREEN_HEIGHT * GRID_HEIGHT_RATIO;
    public static final int GRID_NUM_ROWS = 10;
    public static final int GRID_NUM_COLS = 10;
    
    //This is just for the grid lines
    private GridPane myGridPane;
    
    //This is the actual grid to which nodes will be drawn.
    private Pane myGrid;
    
    public GridDrawer (String name) {
        super(name);
        myGridPane = initializeGridPane();
        this.setPrefWidth(GRID_WIDTH);
        this.setPrefHeight(GRID_HEIGHT + 20);
        this.getChildren().addAll(new Label("SLogo Grid"), myGridPane);
    }
    
    /**
     * Creates the gridpane whose sole purpose is to aid the ToggleRelativeGridFeature
     * @return
     */
    private GridPane initializeGridPane () {
        GridPane pane = new GridPane();
        pane.setHgap(GridDrawer.GRID_WIDTH / GRID_NUM_ROWS);
        pane.setVgap(GridDrawer.GRID_HEIGHT / GRID_NUM_COLS);
        pane.add(new Rectangle(), GRID_NUM_ROWS, GRID_NUM_COLS);
        return pane;
    }

   /**
    * If the grid lines are already visible, they are removed. Otherwise,
    * the grid lines are displayed.
    */
    public void toggleGrid () {
        myGridPane.setGridLinesVisible(!myGridPane.isGridLinesVisible());
    }
    
    /**
     * Adds the grid to the GridDrawer pane. Adds the GridPane used for drawing
     * relative grid lines to the grid.
     * @param grid
     */
    public void setGrid(Pane grid){
        myGrid = grid;
        drawShape(myGridPane);
        super.drawShape(grid);
    }
    
    /**
     * Overrides the super drawShapeMethod - Instead of drawing shapes on the
     * GridDrawer pane (which would have been the default), shapes will be drawn
     * on the grid.
     */
    @Override
    public void drawShape(Node n){
        myGrid.getChildren().add(n);
    }

    /**
     * Changes the background color of the grid, this method is called from the
     * SetGridColorFeature
     * @param style
     */
    public void changeGridColor (String style) {
        myGrid.setStyle(style);  
    }
}<commit_msg>fixed grid problem where turtle is added to the grid group multiple times<commit_after>package gui.componentdrawers;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import gui.mainclasses.StageInitializer;


public class GridDrawer extends ComponentDrawer {

    public static final double GRID_WIDTH_RATIO = .6;
    public static final double GRID_HEIGHT_RATIO = .6;
    public static final double GRID_WIDTH = StageInitializer.SCREEN_WIDTH * GRID_WIDTH_RATIO;
    public static final double GRID_HEIGHT = StageInitializer.SCREEN_HEIGHT * GRID_HEIGHT_RATIO;
    public static final int GRID_NUM_ROWS = 10;
    public static final int GRID_NUM_COLS = 10;
    
    //This is just for the grid lines
    private GridPane myGridPane;
    
    //This is the actual grid to which nodes will be drawn.
    private Pane myGrid;
    
    public GridDrawer (String name) {
        super(name);
        myGridPane = initializeGridPane();
        this.setPrefWidth(GRID_WIDTH);
        this.setPrefHeight(GRID_HEIGHT + 20);
        this.getChildren().addAll(new Label("SLogo Grid"), myGridPane);
    }
    
    /**
     * Creates the gridpane whose sole purpose is to aid the ToggleRelativeGridFeature
     * @return
     */
    private GridPane initializeGridPane () {
        GridPane pane = new GridPane();
        pane.setHgap(GridDrawer.GRID_WIDTH / GRID_NUM_ROWS);
        pane.setVgap(GridDrawer.GRID_HEIGHT / GRID_NUM_COLS);
        pane.add(new Rectangle(), GRID_NUM_ROWS, GRID_NUM_COLS);
        return pane;
    }

   /**
    * If the grid lines are already visible, they are removed. Otherwise,
    * the grid lines are displayed.
    */
    public void toggleGrid () {
        myGridPane.setGridLinesVisible(!myGridPane.isGridLinesVisible());
    }
    
    /**
     * Adds the grid to the GridDrawer pane. Adds the GridPane used for drawing
     * relative grid lines to the grid.
     * @param grid
     */
    public void setGrid(Pane grid){
        myGrid = grid;
        drawShape(myGridPane);
        super.drawShape(grid);
    }
    
    /**
     * Overrides the super drawShapeMethod - Instead of drawing shapes on the
     * GridDrawer pane (which would have been the default), shapes will be drawn
     * on the grid.
     */
    @Override
    public void drawShape(Node n){
        if(!myGrid.getChildren().contains(n))
            myGrid.getChildren().add(n);
    }

    /**
     * Changes the background color of the grid, this method is called from the
     * SetGridColorFeature
     * @param style
     */
    public void changeGridColor (String style) {
        myGrid.setStyle(style);  
    }
}
{'fraction_non_alphanumeric': 0.08115671641791045, 'fraction_numerical': 0.0029850746268656717, 'mean_word_length': 2.754201680672269, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5616126', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1605, 'n_words': 465}