Example usage for java.awt BasicStroke JOIN_MITER

List of usage examples for java.awt BasicStroke JOIN_MITER

Introduction

In this page you can find the example usage for java.awt BasicStroke JOIN_MITER.

Prototype

int JOIN_MITER

To view the source code for java.awt BasicStroke JOIN_MITER.

Click Source Link

Document

Joins path segments by extending their outside edges until they meet.

Usage

From source file:org.fhaes.jsea.JSEABarChart.java

/**
 * TODO//from w  w  w.j  av  a  2s. c  o  m
 * 
 * @param c
 * @param k
 * @return
 */
@SuppressWarnings("deprecation")
private static CategoryItemRenderer createCategoryItemRenderer(Paint c, int k) {

    CategoryItemRenderer renderer = new LineAndShapeRenderer();
    renderer.setPaint(Color.black);
    renderer.setShape(new Ellipse2D.Double(0, 0, 0, 0));
    if (k == 3) {
        renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    }
    if (k == 2) {
        renderer.setSeriesStroke(0, new BasicStroke(3.0f, BasicStroke.JOIN_MITER, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 1.0f, 5.0f }, 0.0f));
    }
    if (k == 1) {
        renderer.setSeriesStroke(0, new BasicStroke(3.0f, BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_ROUND, 1.0f,
                new float[] { 5.0f, 10.0f }, 0.0f));
    }

    return renderer;
}

From source file:fungus.JungObserver.java

public JungObserver(String name) {
    this.name = name;
    this.hyphadataPid = Configuration.getPid(name + "." + PAR_HYPHADATA_PROTO);
    this.hyphalinkPid = Configuration.getPid(name + "." + PAR_HYPHALINK_PROTO);
    this.mycocastPid = Configuration.getPid(name + "." + PAR_MYCOCAST_PROTO);
    self = this;//from ww w.  j a v a2  s  .c  om
    mainThread = Thread.currentThread();

    graph = new DirectedSparseGraph<MycoNode, String>();
    edu.uci.ics.jung.algorithms.layout.SpringLayout<MycoNode, String> layout = new edu.uci.ics.jung.algorithms.layout.SpringLayout<MycoNode, String>(
            graph);
    layout.setSize(new Dimension(650, 650));
    layout.setRepulsionRange(75);
    //layout.setForceMultiplier(0.75);
    layout.setStretch(0.85);

    Dimension preferredSize = new Dimension(650, 650);
    VisualizationModel<MycoNode, String> visualizationModel = new DefaultVisualizationModel<MycoNode, String>(
            layout, preferredSize);
    visualizer = new VisualizationViewer<MycoNode, String>(visualizationModel, preferredSize);
    visualizer.addGraphMouseListener(new InfoFrameVertexListener());

    //visualizer = new BasicVisualizationServer<Node,String>(layout);
    //visualizer.setPreferredSize(new Dimension(650, 650));

    Transformer<MycoNode, String> nodeLabeller = new Transformer<MycoNode, String>() {
        public String transform(MycoNode n) {
            return Long.toString(n.getID());
        }
    };

    final Shape biomassCircle = new Ellipse2D.Float(-2.5f, -2.5f, 5.0f, 5.0f);
    final Shape hyphaCircle = new Ellipse2D.Float(-5.0f, -5.0f, 10.0f, 10.0f);
    Transformer<MycoNode, Shape> shapeTransformer = new Transformer<MycoNode, Shape>() {
        public Shape transform(MycoNode n) {
            HyphaData data = n.getHyphaData();
            if (data.isBiomass()) {
                return biomassCircle;
            } else {
                return hyphaCircle;
            }
        }

    };

    Transformer<MycoNode, Paint> nodeFillRenderer = new Transformer<MycoNode, Paint>() {
        public Paint transform(MycoNode n) {
            HyphaData data = (HyphaData) n.getProtocol(hyphadataPid);
            if (!n.isUp()) {
                return Color.BLACK;
            }
            if (data.isBiomass()) {
                return Color.BLUE;
            } else if (data.isExtending()) {
                return Color.RED;
            } else if (data.isBranching()) {
                return Color.YELLOW;
            } else {
                return Color.GREEN;
            }
        }
    };
    Transformer<MycoNode, Paint> nodeShapeRenderer = new Transformer<MycoNode, Paint>() {
        public Paint transform(MycoNode n) {
            HyphaData data = (HyphaData) n.getProtocol(hyphadataPid);
            if (data.isBiomass()) {
                return Color.BLUE;
            } else if (data.isExtending()) {
                return Color.RED;
            } else if (data.isBranching()) {
                return Color.YELLOW;
            } else {
                return Color.GREEN;
            }
        }
    };

    final Stroke biomassStroke = new BasicStroke(0.25f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f);
    final Stroke hyphalStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f);

    Transformer<String, Stroke> edgeStrokeTransformer = new Transformer<String, Stroke>() {
        public Stroke transform(String s) {
            Pair<MycoNode> vertices = graph.getEndpoints(s);
            HyphaData firstData = vertices.getFirst().getHyphaData();
            HyphaData secondData = vertices.getSecond().getHyphaData();
            if (firstData.isHypha() && secondData.isHypha()) {
                return hyphalStroke;
            } else {
                return biomassStroke;
            }
        }
    };

    visualizer.getRenderContext().setVertexFillPaintTransformer(nodeFillRenderer);
    visualizer.getRenderContext().setVertexShapeTransformer(shapeTransformer);
    visualizer.getRenderContext().setVertexLabelTransformer(nodeLabeller);
    visualizer.setVertexToolTipTransformer(new ToStringLabeller<MycoNode>());
    visualizer.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container c = frame.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));

    //JScrollPane scrollPane = new JScrollPane(visualizer);
    //c.add(scrollPane);
    c.add(visualizer);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));

    JButton pauseButton = new JButton("pause");
    ActionListener pauser = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //e.consume();
            synchronized (self) {
                stepBlocked = true;
                noBlock = false;
                //self.notifyAll();
            }
        }
    };
    pauseButton.addActionListener(pauser);

    JButton stepButton = new JButton("step");
    ActionListener stepper = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Clicked!\n");
            //e.consume();
            synchronized (self) {
                stepBlocked = false;
                self.notifyAll();
            }
        }
    };
    stepButton.addActionListener(stepper);

    JButton runButton = new JButton("run");
    ActionListener runner = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //e.consume();
            synchronized (self) {
                stepBlocked = false;
                noBlock = true;
                self.notifyAll();
            }
        }
    };
    runButton.addActionListener(runner);

    buttonPane.add(pauseButton);
    buttonPane.add(stepButton);
    buttonPane.add(runButton);
    c.add(buttonPane);

    frame.pack();
    frame.setVisible(true);
}

From source file:wef.articulab.view.ui.BNXYPlot.java

/**
 * Creates an overlaid chart.//from  w  ww  .  j  a  va  2s  .c  om
 *
 * @return The chart.
 */
private JFreeChart createChart() {
    createDataset();
    final JFreeChart chart = ChartFactory.createXYLineChart("Real Time Network Dynamics", "Time", "Activation",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    target = new IntervalMarker(14, 16);
    target.setLabel("Activation Threshold");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    BasicStroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    for (int i = 0; i < series.length - 1; i++) {
        renderer.setSeriesStroke(i, stroke);
    }
    renderer.setSeriesStroke(series.length - 1, new BasicStroke(2.0f, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f));
    plot.setRenderer(renderer);
    return chart;
}

From source file:org.squale.squaleweb.util.graph.KiviatMaker.java

/**
 * Create the JreeChart object/*from  ww w. j  a  v a2  s .  co m*/
 * 
 * @param showLegend indicate if it should display the legend or not
 * @param showBackground indicate if we want showBackground
 * @return The JreeChart object
 */
public JFreeChart getChart(boolean showLegend, boolean showBackground) {
    JFreeChart retChart = super.getChart();

    // Creation of the graph if it not already exist
    if (null == retChart) {

        // Creation of the plot
        SpiderWebPlot plot = new SpiderWebPlot(mDataset);

        // Creation of the picture. The plot is inside the picture
        retChart = new JFreeChart(mTitle, TextTitle.DEFAULT_FONT, plot, false);

        // Display of the legend
        if (showLegend) {
            LegendTitle legendtitle = new LegendTitle(plot);
            legendtitle.setPosition(RectangleEdge.BOTTOM);
            retChart.addSubtitle(legendtitle);
        }

        // Definition of the style of the three first draw in the spiderWEbPlot.
        // This three first draw represent the scale for the mark 1.0, 2.0 and 3.0 in the plot
        // First we define the style
        final float miterLimit = 10.0f;
        final float[] dashPattern = { 5.0f, 3.0f };
        BasicStroke dash = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, // End cap
                BasicStroke.JOIN_MITER, // Join style
                miterLimit, // Miter limit
                dashPattern, // Dash pattern
                0.0f);
        // We associate this style to the draw
        plot.setSeriesPaint(0, new Color(WebMessages.getInt("kiviat.color.1")));
        plot.setSeriesOutlineStroke(0, dash);
        plot.setSeriesPaint(1, new Color(WebMessages.getInt("kiviat.color.2")));
        plot.setSeriesOutlineStroke(1, dash);
        plot.setSeriesPaint(2, new Color(WebMessages.getInt("kiviat.color.3")));
        plot.setSeriesOutlineStroke(2, dash);

        // Define the gap what is draw and the border of the plot
        plot.setInteriorGap(DEFAULT_GAP);

        // Define the style of the line stroke
        plot.setBaseSeriesOutlineStroke(new BasicStroke(2.0f));

        // The max value put in the plot (for the scale)
        plot.setMaxValue(SCALE_MAX_VALUE);

        // Indicate if we want fill the inner of the draw
        plot.setWebFilled(FILL_RADAR);

        if (!showBackground) {
            // Set the background of the picture to white
            retChart.setBackgroundPaint(Color.WHITE);

            // Set the border of the plot to white
            plot.setOutlinePaint(Color.WHITE);
        }
        super.setChart(retChart);
    }
    return retChart;
}

From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java

public final String chartJobCount() throws Exception {

    final Calendar calendarToday = CalendarUtils.getCalendarWithoutTime();

    final Calendar calendar30 = CalendarUtils.getCalendarWithoutTime();
    calendar30.add(Calendar.MONTH, -36);

    final List<JobCountPerDay> jobCountPerDayList = jobService.getJobCountPerDayAndPeriod(calendar30.getTime(),
            calendarToday.getTime());//from w  ww.j  a v a2 s .co  m

    final TimeSeries hitsPerDayData = new TimeSeries("Hits", Day.class);
    final XYDataset hitsPerDayDataset = new TimeSeriesCollection(hitsPerDayData);
    this.chart = ChartFactory.createTimeSeriesChart("",
            super.getText("class.ShowStatisticsAcion.chart.job.count.caption"), "", hitsPerDayDataset, false,
            true, false);

    final XYPlot xyplot = (XYPlot) this.chart.getPlot();

    for (JobCountPerDay jobCountPerDay : jobCountPerDayList) {

        final Day day = new Day(jobCountPerDay.getJobDate());

        if (jobCountPerDay.getAutomaticallyCleaned()) {

            final Marker originalEnd = new ValueMarker(day.getFirstMillisecond());
            originalEnd.setPaint(new Color(0, 80, 138, 150));
            float[] dashPattern = { 6, 2 };

            originalEnd.setStroke(
                    new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0));
            originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT);
            originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
            originalEnd.setLabel("C");
            originalEnd.setAlpha(0.1F);
            xyplot.addDomainMarker(originalEnd);
        }

        hitsPerDayData.add(day, jobCountPerDay.getTotalNumberOfJobs());
    }

    chart.setBackgroundPaint(new Color(255, 255, 255, 0));

    xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setBackgroundPaint(new Color(255, 255, 255, 0));

    xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(false);
        xyitemrenderer.setSeriesPaint(0, new Color(244, 66, 0));
    }

    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();

    dateaxis.setAutoRange(true);
    dateaxis.setAutoTickUnitSelection(true);

    NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return SUCCESS;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a residue plot.//from  ww  w.  j ava2 s .  c  o m
 * 
 * @param yValues
 * @param header
 * @param xAxis
 * @param yAxis
 * @param seriesNames
 * @return
 */
public JFreeChart createResiduePlot(List<Double[]> yValues, String header, String xAxis, String yAxis,
        List<String> seriesNames) {
    LinkedList<XYLineAnnotation> lines = new LinkedList<XYLineAnnotation>();
    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    for (int j = 0; j < yValues.size(); j++) {
        XYSeries series = new XYSeries(seriesNames.get(j));
        for (int i = 0; i < yValues.get(j).length; i++) {
            series.add(i + 1, yValues.get(j)[i]);
            float dash[] = { 10.0f };
            BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    dash, 0.0f);
            XYLineAnnotation annotation = new XYLineAnnotation(i + 1, 0, i + 1, yValues.get(j)[i], stroke,
                    Color.BLUE);
            lines.add(annotation);
        }
        xyDataSet.addSeries(seriesNames.get(j), series.toArray());
    }
    JFreeChart chart = ChartFactory.createScatterPlot(header, xAxis, yAxis, xyDataSet, PlotOrientation.VERTICAL,
            true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    for (int i = 0; i < lines.size(); i++) {
        plot.addAnnotation(lines.get(i));
    }
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(0.0f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(0.0f);

    return chart;
}

From source file:ega.projekt.graphDraw.DrawGraph.java

public static BasicVisualizationServer<Node, Edge> generatePanel(int panelWidth, int panelHeight) {
    DrawGraph graphView = new DrawGraph();
    Layout<Node, Edge> layout = new StaticLayout(graphView.drawGraph);
    for (Node n : graphView.drawGraph.getVertices()) {
        layout.setLocation(n, new java.awt.geom.Point2D.Double(n.getX(), n.getY()));
    }//  w w  w.ja  va 2  s  . c o m
    layout.setSize(new Dimension(panelWidth, panelHeight));
    BasicVisualizationServer<Node, Edge> vv = new BasicVisualizationServer<>(layout);
    vv.setPreferredSize(new Dimension(panelWidth, panelHeight));
    Transformer<Node, Paint> vertexPaint = new Transformer<Node, Paint>() {
        public Paint transform(Node i) {
            return Color.GREEN;
        }
    };
    final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    Transformer<Edge, Stroke> edgeStrokeTransformer = new Transformer<Edge, Stroke>() {
        public Stroke transform(Edge e) {
            return edgeStroke;
        }
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<Node, Edge>());
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Edge, String>() {
        public String transform(Edge e) {
            return (e.getFlowString() + "/" + Integer.toString(e.getCapacity()));
        }
    });
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<Node, String>() {
        public String transform(Node n) {
            return (Integer.toString(n.getID()));
        }
    });
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    return vv;
}

From source file:Util.PacketGenerator.java

public static void GenerateGraph() {
    try {/*from w  w w  .j a v a2  s.co m*/
        for (int j = 6; j <= 6; j++) {
            File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology"
                    + j + "\\Real.csv");
            for (int k = 1; k <= 4; k++) {
                File simu = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".csv");

                FileInputStream simuFIS = new FileInputStream(simu);
                DataInputStream simuDIS = new DataInputStream(simuFIS);
                BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS));

                FileInputStream realFIS = new FileInputStream(real);
                DataInputStream realDIS = new DataInputStream(realFIS);
                BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS));

                String lineSimu = simuBR.readLine();
                String lineReal = realBR.readLine();

                XYSeries matrix = new XYSeries("Matriz", false, true);
                while (lineSimu != null && lineReal != null) {

                    lineSimu = lineSimu.replaceAll(",", ".");
                    String[] simuMatriz = lineSimu.split(";");
                    String[] realMatriz = lineReal.split(";");

                    for (int i = 0; i < simuMatriz.length; i++) {
                        try {
                            Integer valorReal = Integer.parseInt(realMatriz[i]);
                            Float valorSimu = Float.parseFloat(simuMatriz[i]);
                            matrix.add(valorReal.doubleValue() / 1000.0, valorSimu.doubleValue() / 1000.0);
                        } catch (NumberFormatException ex) {

                        }
                    }
                    lineSimu = simuBR.readLine();
                    lineReal = realBR.readLine();
                }

                simuFIS.close();
                simuDIS.close();
                simuBR.close();

                realFIS.close();
                realDIS.close();
                realBR.close();

                double maxPlot = Double.max(matrix.getMaxX(), matrix.getMaxY()) * 1.1;
                XYSeries middle = new XYSeries("Referncia");
                ;
                middle.add(0, 0);
                middle.add(maxPlot, maxPlot);
                XYSeries max = new XYSeries("Superior 20%");
                max.add(0, 0);
                max.add(maxPlot, maxPlot * 1.2);
                XYSeries min = new XYSeries("Inferior 20%");
                min.add(0, 0);
                min.add(maxPlot, maxPlot * 0.8);

                XYSeriesCollection dataset = new XYSeriesCollection();
                dataset.addSeries(middle);
                dataset.addSeries(matrix);
                dataset.addSeries(max);
                dataset.addSeries(min);
                JFreeChart chart;
                if (k == 4) {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "Real", "CMO-MT", dataset);
                } else {
                    chart = ChartFactory.createXYLineChart("Matriz de Trfego", "CMO-MT", "Zhao", dataset);
                }
                chart.setBackgroundPaint(Color.WHITE);
                chart.getPlot().setBackgroundPaint(Color.WHITE);
                chart.getTitle().setFont(new Font("Times New Roman", Font.BOLD, 13));

                chart.getLegend().setItemFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 10));

                chart.getXYPlot().getDomainAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getDomainAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));
                chart.getXYPlot().getRangeAxis().setLabelFont(new Font("Times New Roman", Font.BOLD, 10));
                chart.getXYPlot().getRangeAxis()
                        .setTickLabelFont(new Font("Times New Roman", Font.TRUETYPE_FONT, 1));

                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();

                renderer.setSeriesLinesVisible(1, false);
                renderer.setSeriesShapesVisible(1, true);

                renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 0.1f }, 0.0f));
                renderer.setSeriesShape(1, new Ellipse2D.Float(-1.5f, -1.5f, 3f, 3f));
                renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));
                renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                        10.0f, new float[] { 3.0f }, 0.0f));

                renderer.setSeriesPaint(0, Color.BLACK);
                renderer.setSeriesPaint(1, Color.BLACK);
                renderer.setSeriesPaint(2, Color.BLACK);
                renderer.setSeriesPaint(3, Color.BLACK);

                int width = (int) (192 * 1.5f); /* Width of the image */

                int height = (int) (144 * 1.5f); /* Height of the image */

                File XYChart = new File(
                        "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j
                                + "\\SimulacaoInstancia" + k + ".jpeg");
                ChartUtilities.saveChartAsJPEG(XYChart, chart, width, height);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.bfs.radon.omsimulation.gui.data.OMCharts.java

/**
 * Creates a chart displaying the radon concentration of a virtual campaign.
 * Uses red for normal rooms and blue for cellar rooms.
 * // www  . jav a  2s. co  m
 * @param campaign
 *          The campaign object containing all rooms and radon data.
 * @param preview
 *          Will hide annotations, labels and headlines if true.
 * @return A chart displaying the radon concentration of a virtual campaign.
 */
public static JFreeChart createCampaignChart(OMCampaign campaign, boolean preview) {
    OMRoom[] rooms = new OMRoom[7];
    OMRoom[] tmpRooms = campaign.getRooms();
    OMRoom tmpCellar = campaign.getCellar();
    String variation = campaign.getVariation();
    char[] variationChar = variation.toCharArray();
    int cellarPosition = 0;
    for (int i = 0; i < variationChar.length; i++) {
        if (variationChar[i] == 'C' || variationChar[i] == 'c') {
            cellarPosition = i / 2;
        }
    }
    int c = 0;
    for (int i = 0; i < rooms.length; i++) {
        if (i == cellarPosition) {
            rooms[i] = tmpCellar;
            c++;
        } else {
            rooms[i] = tmpRooms[i - c];
        }
    }
    int start = campaign.getStart();
    final int finalStart = start;
    String title = "Campaign: " + rooms[0].getId() + rooms[1].getId() + rooms[2].getId() + rooms[3].getId()
            + rooms[4].getId() + rooms[5].getId() + rooms[6].getId() + ", Start: " + finalStart;
    int count = 168;
    double[] values = campaign.getValueChain();
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries roomSeries1 = new XYSeries(" Radon Rooms");
    XYSeries cellarSeries = new XYSeries("Radon Cellar");
    XYSeries roomSeries2 = new XYSeries("Radon Rooms");
    int cellarSeriesStart = cellarPosition * 24;
    int cellarSeriesEnd = cellarSeriesStart + 24;
    double cellarMaximum = campaign.getCellarMaximum();
    double cellarMaximumKey = 0;
    double roomMaximum = campaign.getRoomMaximum();
    double roomMaximumKey = 0;
    if (cellarSeriesStart > 0) {
        for (int i = 0; i < cellarSeriesStart; i++) {
            roomSeries1.add(finalStart + i, values[i]);
            if (values[i] == roomMaximum) {
                roomMaximumKey = i;
            }
        }
    }
    for (int i = cellarSeriesStart - 1; i < cellarSeriesEnd; i++) {
        if (i >= 0) {
            cellarSeries.add(finalStart + i, values[i]);
            if (values[i] == cellarMaximum) {
                cellarMaximumKey = i;
            }
        }
    }
    if (cellarSeriesEnd < count) {
        for (int i = cellarSeriesEnd - 1; i < count; i++) {
            roomSeries2.add(finalStart + i, values[i]);
            if (values[i] == roomMaximum) {
                roomMaximumKey = i;
            }
        }
    }
    dataSet.addSeries(roomSeries1);
    dataSet.addSeries(cellarSeries);
    dataSet.addSeries(roomSeries2);
    JFreeChart chart = ChartFactory.createXYLineChart(title, "T [h]", "Rn [Bq/m\u00B3]", dataSet,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueMarker sepMarker;
    Color sepColor = Color.BLACK;
    float[] sepDash = { 1, 2 };
    Stroke sepStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, sepDash, 0);
    RectangleInsets sepLabelInsets = new RectangleInsets(20, -20, 0, 0);
    Font sepLabelFont = new Font(Font.SANS_SERIF, Font.BOLD, 16);
    sepMarker = new ValueMarker(finalStart + 0, sepColor, sepStroke);
    sepMarker.setLabel(rooms[0].getId());
    sepMarker.setLabelOffset(sepLabelInsets);
    sepMarker.setLabelFont(sepLabelFont);
    plot.addDomainMarker(sepMarker);
    if (rooms[0].getId() != rooms[1].getId()) {
        sepMarker = new ValueMarker(finalStart + 23, sepColor, sepStroke);
        sepMarker.setLabel(rooms[1].getId());
        sepMarker.setLabelOffset(sepLabelInsets);
        sepMarker.setLabelFont(sepLabelFont);
        plot.addDomainMarker(sepMarker);
    }
    if (rooms[1].getId() != rooms[2].getId()) {
        sepMarker = new ValueMarker(finalStart + 47, sepColor, sepStroke);
        sepMarker.setLabel(rooms[2].getId());
        sepMarker.setLabelOffset(sepLabelInsets);
        sepMarker.setLabelFont(sepLabelFont);
        plot.addDomainMarker(sepMarker);
    }
    if (rooms[2].getId() != rooms[3].getId()) {
        sepMarker = new ValueMarker(finalStart + 71, sepColor, sepStroke);
        sepMarker.setLabel(rooms[3].getId());
        sepMarker.setLabelOffset(sepLabelInsets);
        sepMarker.setLabelFont(sepLabelFont);
        plot.addDomainMarker(sepMarker);
    }
    if (rooms[3].getId() != rooms[4].getId()) {
        sepMarker = new ValueMarker(finalStart + 95, sepColor, sepStroke);
        sepMarker.setLabel(rooms[4].getId());
        sepMarker.setLabelOffset(sepLabelInsets);
        sepMarker.setLabelFont(sepLabelFont);
        plot.addDomainMarker(sepMarker);
    }
    if (rooms[4].getId() != rooms[5].getId()) {
        sepMarker = new ValueMarker(finalStart + 119, sepColor, sepStroke);
        sepMarker.setLabel(rooms[5].getId());
        sepMarker.setLabelOffset(sepLabelInsets);
        sepMarker.setLabelFont(sepLabelFont);
        plot.addDomainMarker(sepMarker);
    }
    if (rooms[5].getId() != rooms[6].getId()) {
        sepMarker = new ValueMarker(finalStart + 143, sepColor, sepStroke);
        sepMarker.setLabel(rooms[6].getId());
        sepMarker.setLabelOffset(sepLabelInsets);
        sepMarker.setLabelFont(sepLabelFont);
        plot.addDomainMarker(sepMarker);
    }
    double positiveCellarDeviation = campaign.getCellarAverage() + campaign.getCellarDeviation();
    double negativeCellarDeviation = campaign.getCellarAverage() - campaign.getCellarDeviation();
    IntervalMarker cellarDeviation = new IntervalMarker(negativeCellarDeviation, positiveCellarDeviation);
    float[] dash = { 5, 3 };
    cellarDeviation.setPaint(new Color(222, 222, 255, 128));
    cellarDeviation.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(cellarDeviation, Layer.BACKGROUND);
    ValueMarker arithCellarMarker = new ValueMarker(campaign.getCellarAverage(), new Color(0, 0, 255, 128),
            new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(arithCellarMarker);
    XYTextAnnotation amCellarLabel = new XYTextAnnotation("C_AM=" + (int) campaign.getCellarAverage(),
            finalStart + count, campaign.getCellarAverage() * 1.01);
    plot.addAnnotation(amCellarLabel);
    XYTextAnnotation sdCellarLabel = new XYTextAnnotation("C_SD=" + (int) campaign.getCellarDeviation(),
            finalStart + count, (campaign.getCellarAverage() + campaign.getCellarDeviation()) * 1.01);
    plot.addAnnotation(sdCellarLabel);
    ValueMarker maxiCellarMarker = new ValueMarker(cellarMaximum, new Color(0, 0, 255, 128),
            new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(maxiCellarMarker);
    XYTextAnnotation maxCellarLabel = new XYTextAnnotation("C_MAX=" + (int) cellarMaximum, finalStart + count,
            cellarMaximum * 1.01);
    plot.addAnnotation(maxCellarLabel);
    XYPointerAnnotation maxCellarPointer = new XYPointerAnnotation("", finalStart + cellarMaximumKey,
            cellarMaximum, Math.PI * 1.1);
    plot.addAnnotation(maxCellarPointer);
    double positiveRoomDeviation = campaign.getRoomAverage() + campaign.getRoomDeviation();
    double negativeRoomDeviation = campaign.getRoomAverage() - campaign.getRoomDeviation();
    IntervalMarker roomDeviation = new IntervalMarker(negativeRoomDeviation, positiveRoomDeviation);
    roomDeviation.setPaint(new Color(255, 222, 222, 128));
    roomDeviation.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(roomDeviation, Layer.BACKGROUND);
    ValueMarker arithRoomMarker = new ValueMarker(campaign.getRoomAverage(), new Color(255, 0, 0, 128),
            new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(arithRoomMarker);
    XYTextAnnotation amRoomLabel = new XYTextAnnotation("R_AM=" + (int) campaign.getRoomAverage(),
            finalStart + count, campaign.getRoomAverage() * 1.01);
    plot.addAnnotation(amRoomLabel);
    XYTextAnnotation sdRoomLabel = new XYTextAnnotation("R_SD=" + (int) campaign.getRoomDeviation(),
            finalStart + count, (campaign.getRoomAverage() + campaign.getRoomDeviation()) * 1.01);
    plot.addAnnotation(sdRoomLabel);
    ValueMarker maxiRoomMarker = new ValueMarker(roomMaximum, new Color(255, 0, 0, 128),
            new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, dash, 0));
    plot.addRangeMarker(maxiRoomMarker);
    XYTextAnnotation maxRoomLabel = new XYTextAnnotation("R_MAX=" + (int) roomMaximum, finalStart + count,
            roomMaximum * 1.01);
    plot.addAnnotation(maxRoomLabel);
    XYPointerAnnotation maxRoomPointer = new XYPointerAnnotation("", finalStart + roomMaximumKey, roomMaximum,
            Math.PI * 1.1);
    plot.addAnnotation(maxRoomPointer);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, new Color(255, 0, 0, 128));
    renderer.setSeriesPaint(1, new Color(0, 0, 255, 128));
    renderer.setSeriesPaint(2, new Color(255, 0, 0, 128));
    if (preview) {
        chart.setTitle("");
        plot.clearAnnotations();
    }
    return chart;
}

From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java

/**
 * Adds annotations to the Gaussian fit parameters
 * //ww w.j  a v  a2  s .  c o  m
 * @param plot
 * @param fit Gaussian fit {normalisation factor, mean, sigma}
 */
public static void addGaussianFitAnnotations(XYPlot plot, double[] fit) {
    Paint c = plot.getDomainCrosshairPaint();
    BasicStroke s = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1,
            new float[] { 5f, 2.5f }, 0);

    plot.addDomainMarker(new ValueMarker(fit[1], c, s));
    plot.addDomainMarker(new ValueMarker(fit[1] - fit[2], c, s));
    plot.addDomainMarker(new ValueMarker(fit[1] + fit[2], c, s));
}