Package Core

Source Code of Core.GraphResultDrawer

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package Core;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;

/**
*This class is in charge of converting the numeral result values into graphical
* figures (Charts)
* @author LauretHa,Amir
*/
public class GraphResultDrawer extends ResultDrawer
{
    private Result r;
    private JFreeChart movementChart;
    private JFreeChart soilPressureChart;
    private JFreeChart limitPressureChart;
    private JFreeChart displacementChart;
    private JFreeChart rotationChart;
    private JFreeChart bendingMomentChart;
    private JFreeChart shearForceChart;

    /**
     * Constructor for objects of class GraphResultDrawer
     * It calls the required graphical functions and draws the graph represnations
     * @param result result to be drawn
     */
    public GraphResultDrawer(Result result)
    {
        r = result;
        movementChart = drawMovementChart();
        soilPressureChart = drawPressureChart();
        limitPressureChart = drawLimitPressureChart();
        displacementChart = drawDispChart();
        rotationChart = drawRotationChart();
        bendingMomentChart = drawBendingMomentChart();
        shearForceChart = drawShearForceChart();

    }

    /**
     * Returns a 4x2 Panel containing the drawn graphs
     * @return
     *  4x2 Panel containing the drawn graphs
     */
    @Override
    public JPanel Draw() {
        JPanel mainPanel = new JPanel(new GridLayout(2, 4, 5, 5));
        mainPanel.add(new ChartPanel(movementChart));
        mainPanel.add(new ChartPanel(soilPressureChart));
        mainPanel.add(new ChartPanel(limitPressureChart));
        mainPanel.add(new ChartPanel(rotationChart));
        mainPanel.add(new ChartPanel(displacementChart));
        mainPanel.add(new ChartPanel(bendingMomentChart));
        mainPanel.add(new ChartPanel(shearForceChart));
        return mainPanel;

    }

    /**
     * Returns an array of drawn charts in Image format
     * @return
     *  Array of drawn charts in Image format
     */
    public Image[] getGraphImages(){
       
        final int imageWidth=300,imageHeight=350;
        BufferedImage[] images = new BufferedImage[7];
        for(int i=0;i<7;i++){
            images[i] = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
        }

        Graphics2D[] graphics = new Graphics2D[7];
        for(int i=0;i<7;i++){
            graphics[i] = images[i].createGraphics();
        }
        Rectangle drawArea = new Rectangle(imageWidth, imageHeight);
       
        movementChart.draw(graphics[0], drawArea);
        soilPressureChart.draw(graphics[1], drawArea);
        limitPressureChart.draw(graphics[2], drawArea);
        rotationChart.draw(graphics[3], drawArea);
        displacementChart.draw(graphics[4], drawArea);
        bendingMomentChart.draw(graphics[5], drawArea);
        shearForceChart.draw(graphics[6], drawArea);

        return images;

    }

    /**
     * Returns the Movement Chart
     * @return
     *  Movement Chart
     */
    public JFreeChart getMovementChart(){
        return movementChart;
    }
    /**
     * Returns the Soil Pressure Chart
     * @return
     *  Soil Pressure Chart
     */
    public JFreeChart getSoilPressureChart(){
        return soilPressureChart;
    }
    /**
     * Returns the Limit Pressure Chart
     * @return
     *  Limit Pressure Chart
     */
    public JFreeChart getLimitPressureChart(){
        return limitPressureChart;
    }
    /**
     * Returns the Displacement Chart
     * @return
     *  Displacement Chart
     */
    public JFreeChart getDisplacementChart(){
        return displacementChart;
    }
    /**
     * Returns the Rotation Chart
     * @return
     *  Rotation Chart
     */
    public JFreeChart getRotationChart(){
        return rotationChart;
    }
    /**
     * Returns the Bending Moment Chart
     * @return
     *  Bending Moment Chart
     */
    public JFreeChart getBendingMomentChart(){
        return bendingMomentChart;
    }
    /**
     * Returns the Shear Force Chart
     * @return
     *  Shear Force Chart
     */
    public JFreeChart getShearForceChart(){
        return shearForceChart;
    }


    /**
     * Draws and returns the Soil Displacement Chart
     * @return
     *  Soil Displacement Chart
     */
    private JFreeChart drawDispChart(){
        XYSeries series1 = new XYSeries("Pile Displacement");
        int numOfElements = r.getNumOfNodes();
        for(int i=0;i<numOfElements;i++){
                series1.add(-r.getDepth(i), r.getDisplacement(i)*1000);
            }
            XYSeriesCollection dataset = new XYSeriesCollection(series1);
            JFreeChart chart = ChartFactory.createXYLineChart("Pile Displacement", "Depth (m)", "Displacement (mm)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
           
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            plot.setBackgroundPaint(Color.WHITE);
            plot.setRangeGridlinePaint(Color.GRAY);
            plot.setDomainGridlinePaint(Color.GRAY);
            return chart;
    }

    /**
     *Draws and returns the Soil Movement Chart
     * @return
     *  Soil Movement Chart
     */
    private JFreeChart drawMovementChart(){
        XYSeries series1 = new XYSeries("Soil Movement");
        int numOfElements = r.getNumOfNodes();
        for(int i=0;i<numOfElements;i++){
                series1.add(-r.getDepth(i), r.getSoilMovement(i)*1000);
            }
            XYSeriesCollection dataset = new XYSeriesCollection(series1);
            JFreeChart chart = ChartFactory.createXYLineChart("Soil Movement", "Depth (m)", "Soil Movement (mm)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            plot.setBackgroundPaint(Color.WHITE);
            plot.setRangeGridlinePaint(Color.GRAY);
            plot.setDomainGridlinePaint(Color.GRAY);
            return chart;
    }

    /**
     * Draws and Returns the Soil Pressure Chart
     * @return
     *  Soil Pressure Chart
     */
    private JFreeChart drawPressureChart(){
        XYSeries series1 = new XYSeries("Soil Pressure");
        int numOfElements = r.getNumOfNodes();
        for(int i=0;i<numOfElements;i++){
                series1.add(-r.getDepth(i), r.getSoilPressure(i));
            }
            XYSeriesCollection dataset = new XYSeriesCollection(series1);
            JFreeChart chart = ChartFactory.createXYLineChart("Soil Pressure", "Depth (m)", "Soil Pressure (kPa)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            plot.setBackgroundPaint(Color.WHITE);
            plot.setRangeGridlinePaint(Color.GRAY);
            plot.setDomainGridlinePaint(Color.GRAY);
            return chart;
    }

    /**
     * Draws and returns the Limit Pressure Chart
     * @return
     *  Limit Pressure Chart
     */
    private JFreeChart drawLimitPressureChart(){
        XYSeries series1 = new XYSeries("ABS Limit Pressure");
        int numOfElements = r.getNumOfNodes();
        for(int i=0;i<numOfElements;i++){
                series1.add(-r.getDepth(i), r.getLimitPressure(i));
            }
            XYSeriesCollection dataset = new XYSeriesCollection(series1);
            JFreeChart chart = ChartFactory.createXYLineChart("ABS Limit Pressure", "Depth (m)", "ABS Limit Pressure (kPa)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            plot.setBackgroundPaint(Color.WHITE);
            plot.setRangeGridlinePaint(Color.GRAY);
            plot.setDomainGridlinePaint(Color.GRAY);
            return chart;
    }

    /**
     * Draws and returns the Rotation Chart
     * @return
     */
    private JFreeChart drawRotationChart(){
        XYSeries series1 = new XYSeries("Rotation");
        int numOfElements = r.getNumOfNodes();
        for(int i=0;i<numOfElements;i++){
                series1.add(-r.getDepth(i), r.getRotation(i));
            }
            XYSeriesCollection dataset = new XYSeriesCollection(series1);
            JFreeChart chart = ChartFactory.createXYLineChart("Rotation", "Depth (m)", "Rotation (rad)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            plot.setBackgroundPaint(Color.WHITE);
            plot.setRangeGridlinePaint(Color.GRAY);
            plot.setDomainGridlinePaint(Color.GRAY);
            return chart;
    }

    /**
     * Draws and returns the Bending Moment Chart
     * @return
     */
    private JFreeChart drawBendingMomentChart(){
        XYSeries series1 = new XYSeries("Bending Moment");
        int numOfElements = r.getNumOfNodes();
        for(int i=0;i<numOfElements;i++){
                series1.add(-r.getDepth(i), r.getBendingMoment(i));
            }
            XYSeriesCollection dataset = new XYSeriesCollection(series1);
            JFreeChart chart = ChartFactory.createXYLineChart("Bending Moment", "Depth (m)", "Bending Moment (kNm)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            plot.setBackgroundPaint(Color.WHITE);
            plot.setRangeGridlinePaint(Color.GRAY);
            plot.setDomainGridlinePaint(Color.GRAY);
            return chart;
    }

    /**
     * Draws and returns the Shear Force Chart
     * @return
     *  Shear Force Chart
     */
    private JFreeChart drawShearForceChart(){
        XYSeries series1 = new XYSeries("Shear Force");
        int numOfElements = r.getNumOfNodes();
        for(int i=0;i<numOfElements;i++){
                series1.add(-r.getDepth(i), r.getShearForce(i));
            }
            XYSeriesCollection dataset = new XYSeriesCollection(series1);
            JFreeChart chart = ChartFactory.createXYLineChart("Shear Force", "Depth (m)", "Shear Force (kN)", dataset, PlotOrientation.HORIZONTAL, true, true, false);
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
            renderer.setShapesVisible(true);
            plot.setBackgroundPaint(Color.WHITE);
            plot.setRangeGridlinePaint(Color.GRAY);
            plot.setDomainGridlinePaint(Color.GRAY);
            return chart;
    }




}
TOP

Related Classes of Core.GraphResultDrawer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.