// Path: src/com/sproutlife/model/utils/EchosystemUtils.java
// public class EchosystemUtils {
// 
//     public static void updateBoardBounds(Echosystem echosystem, Rectangle bounds) {
//         echosystem.getBoard().setSize(new Dimension(bounds.width, bounds.height));
// 
//         echosystem.getBoard().resetBoard();
// 
//         ArrayList<Cell> removeList = new ArrayList<Cell>(0);
// 
//         for (Organism o : echosystem.getOrganisms()) {
//             Point ol = o.getLocation();
//             o.setLocation(ol.x-bounds.x , ol.y-bounds.y);
//             for (Cell current : o.getCells()) {
//                 if (current.x < bounds.x || current.x >= echosystem.getBoard().getWidth()+bounds.x
//                         || current.y < bounds.y || current.y >= echosystem.getBoard().getHeight()+bounds.y) {
//                     removeList.add(current);
//                 }
//                 else {
//                     Point cl = current.getLocation();
//                     current.setLocation(new Point(cl.x-bounds.x, cl.y-bounds.y));
//                     echosystem.getBoard().setCell(current);
//                 }
//             }
//         }
//         for (Organism o : echosystem.getRetiredOrganisms()) {
//             Point ol = o.getLocation();
//             o.setLocation(ol.x-bounds.x , ol.y-bounds.y);
//         }
//         for (Cell r : removeList) {
//             echosystem.removeCell(r, true);
//         }
//         pruneEmptyOrganisms(echosystem);
//     }
// 
//     /*
//      * Make sure the all cells on the board are contained within organisms, and
//      * that all cells in organisms are on the board.
//      * 
//      * @return if the board isn't consistent with organisms, return false
//      */
//     public static boolean validateBoard(Echosystem echosystem) {
//         for (Organism o : echosystem.getOrganisms()) {
//             for (Cell current : o.getCells()) {
//                 if (echosystem.getBoard().getCell(current.x, current.y) != current) {
//                     return false;
//                 }
//             }
//         }
//         for (int i = 0; i < echosystem.getBoard().getWidth(); i++) {
//             for (int j = 0; j < echosystem.getBoard().getHeight(); j++) {
//                 Cell c = echosystem.getBoard().getCell(i, j);
//                 if (c != null && c.getOrganism().getCell(c.x, c.y) != c) {
//                     return false;
//                 }
// 
//             }
//         }
// 
//         return true;
//     }
//     
//     public static void pruneEmptyOrganisms(Echosystem echosystem) {
//         HashSet<Organism> pruneOrgs = new HashSet<Organism>();
//         pruneOrgs.addAll(echosystem.getOrganisms());
//         for (Organism org : pruneOrgs) {
//             if (org.getCells().size() == 0) {
//                 echosystem.retireOrganism(org);
//             }
//         }
//     }
// }
// 
// Path: src/com/sproutlife/panel/gamepanel/ScrollPanel.java
// public interface ViewportResizedListener {
//     public void viewportResized(int viewportWidth, int viewportHeight);
// }
// 
// Path: src/com/sproutlife/renderer/Dimension2Double.java
// public class Dimension2Double extends Dimension2D {
//     private double width;
//     private double height;
//     
//     public Dimension2Double(double width, double height) {
//         setSize(width, height);
//     }
// 
//     @Override
//     public double getWidth() {
//         return width;
//     }
// 
//     @Override
//     public double getHeight() {
//         return height;
//     }
// 
//     @Override
//     public void setSize(double width, double height) {
//         this.width = width;
//         this.height = height;
//     }
// 
// }


import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.geom.Rectangle2D;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.sproutlife.model.utils.EchosystemUtils;
import com.sproutlife.panel.gamepanel.ScrollPanel.ViewportResizedListener;
import com.sproutlife.renderer.Dimension2Double;
package com.sproutlife.panel;




public class BoardSizeHandler {
    PanelController pc;
    boolean updatingSize = false;
    ChangeListener boardSizeSpinnerListener;
    ChangeListener imageSizeSpinnerListener;

    public BoardSizeHandler(PanelController panelController) {
        this.pc = panelController;
    }

    public void addListeners() {
        boardSizeSpinnerListener = new ChangeListener() {
            public void stateChanged(ChangeEvent arg0) {
                pc.getDisplayControlPanel().getAutoSizeGridCheckbox().setSelected(false);
                int width = (int) pc.getDisplayControlPanel().getBoardWidthSpinner().getValue();
                int height = (int) pc.getDisplayControlPanel().getBoardHeightSpinner().getValue();
                updateBoardSize(width, height);
            }
        };

        imageSizeSpinnerListener = new ChangeListener() {
            public void stateChanged(ChangeEvent arg0) {
                pc.getDisplayControlPanel().getAutoSizeGridCheckbox().setSelected(false);
                int width =  (int) pc.getDisplayControlPanel().getImageWidthSpinner().getValue();
                int height = (int) pc.getDisplayControlPanel().getImageHeightSpinner().getValue();
                updateBoardSizeFromImageSize(new Dimension(width, height));
            }
        };

// Path: src/com/sproutlife/model/utils/EchosystemUtils.java
// public class EchosystemUtils {
// 
//     public static void updateBoardBounds(Echosystem echosystem, Rectangle bounds) {
//         echosystem.getBoard().setSize(new Dimension(bounds.width, bounds.height));
// 
//         echosystem.getBoard().resetBoard();
// 
//         ArrayList<Cell> removeList = new ArrayList<Cell>(0);
// 
//         for (Organism o : echosystem.getOrganisms()) {
//             Point ol = o.getLocation();
//             o.setLocation(ol.x-bounds.x , ol.y-bounds.y);
//             for (Cell current : o.getCells()) {
//                 if (current.x < bounds.x || current.x >= echosystem.getBoard().getWidth()+bounds.x
//                         || current.y < bounds.y || current.y >= echosystem.getBoard().getHeight()+bounds.y) {
//                     removeList.add(current);
//                 }
//                 else {
//                     Point cl = current.getLocation();
//                     current.setLocation(new Point(cl.x-bounds.x, cl.y-bounds.y));
//                     echosystem.getBoard().setCell(current);
//                 }
//             }
//         }
//         for (Organism o : echosystem.getRetiredOrganisms()) {
//             Point ol = o.getLocation();
//             o.setLocation(ol.x-bounds.x , ol.y-bounds.y);
//         }
//         for (Cell r : removeList) {
//             echosystem.removeCell(r, true);
//         }
//         pruneEmptyOrganisms(echosystem);
//     }
// 
//     /*
//      * Make sure the all cells on the board are contained within organisms, and
//      * that all cells in organisms are on the board.
//      * 
//      * @return if the board isn't consistent with organisms, return false
//      */
//     public static boolean validateBoard(Echosystem echosystem) {
//         for (Organism o : echosystem.getOrganisms()) {
//             for (Cell current : o.getCells()) {
//                 if (echosystem.getBoard().getCell(current.x, current.y) != current) {
//                     return false;
//                 }
//             }
//         }
//         for (int i = 0; i < echosystem.getBoard().getWidth(); i++) {
//             for (int j = 0; j < echosystem.getBoard().getHeight(); j++) {
//                 Cell c = echosystem.getBoard().getCell(i, j);
//                 if (c != null && c.getOrganism().getCell(c.x, c.y) != c) {
//                     return false;
//                 }
// 
//             }
//         }
// 
//         return true;
//     }
//     
//     public static void pruneEmptyOrganisms(Echosystem echosystem) {
//         HashSet<Organism> pruneOrgs = new HashSet<Organism>();
//         pruneOrgs.addAll(echosystem.getOrganisms());
//         for (Organism org : pruneOrgs) {
//             if (org.getCells().size() == 0) {
//                 echosystem.retireOrganism(org);
//             }
//         }
//     }
// }
// 
// Path: src/com/sproutlife/panel/gamepanel/ScrollPanel.java
// public interface ViewportResizedListener {
//     public void viewportResized(int viewportWidth, int viewportHeight);
// }
// 
// Path: src/com/sproutlife/renderer/Dimension2Double.java
// public class Dimension2Double extends Dimension2D {
//     private double width;
//     private double height;
//     
//     public Dimension2Double(double width, double height) {
//         setSize(width, height);
//     }
// 
//     @Override
//     public double getWidth() {
//         return width;
//     }
// 
//     @Override
//     public double getHeight() {
//         return height;
//     }
// 
//     @Override
//     public void setSize(double width, double height) {
//         this.width = width;
//         this.height = height;
//     }
// 
// }


// Path: src/com/sproutlife/panel/BoardSizeHandler.java
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.geom.Rectangle2D;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.sproutlife.model.utils.EchosystemUtils;
import com.sproutlife.panel.gamepanel.ScrollPanel.ViewportResizedListener;
import com.sproutlife.renderer.Dimension2Double;

package com.sproutlife.panel;




public class BoardSizeHandler {
    PanelController pc;
    boolean updatingSize = false;
    ChangeListener boardSizeSpinnerListener;
    ChangeListener imageSizeSpinnerListener;

    public BoardSizeHandler(PanelController panelController) {
        this.pc = panelController;
    }

    public void addListeners() {
        boardSizeSpinnerListener = new ChangeListener() {
            public void stateChanged(ChangeEvent arg0) {
                pc.getDisplayControlPanel().getAutoSizeGridCheckbox().setSelected(false);
                int width = (int) pc.getDisplayControlPanel().getBoardWidthSpinner().getValue();
                int height = (int) pc.getDisplayControlPanel().getBoardHeightSpinner().getValue();
                updateBoardSize(width, height);
            }
        };

        imageSizeSpinnerListener = new ChangeListener() {
            public void stateChanged(ChangeEvent arg0) {
                pc.getDisplayControlPanel().getAutoSizeGridCheckbox().setSelected(false);
                int width =  (int) pc.getDisplayControlPanel().getImageWidthSpinner().getValue();
                int height = (int) pc.getDisplayControlPanel().getImageHeightSpinner().getValue();
                updateBoardSizeFromImageSize(new Dimension(width, height));
            }
        };

        pc.getScrollPanel().addViewportResizedListener(new ViewportResizedListener() {