Example usage for org.jfree.chart.plot XYPlot XYPlot

List of usage examples for org.jfree.chart.plot XYPlot XYPlot

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot XYPlot.

Prototype

public XYPlot() 

Source Link

Document

Creates a new XYPlot instance with no dataset, no axes and no renderer.

Usage

From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java

private void createGraphTab(final CTabFolder parentTabFolder) {
    plotTab = new CTabItem(parentTabFolder, SWT.NONE);
    plotTab.setText(Messages.MoranScatterPlotDialog_Graph);

    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);//from   w ww  . ja  v  a 2  s  .com
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    JFreeChart chart = new JFreeChart(EMPTY, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite = new ChartComposite2(parentTabFolder, SWT.NONE | SWT.EMBEDDED, chart, true);
    chartComposite.setLayout(new FillLayout());
    chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    chartComposite.setDomainZoomable(false);
    chartComposite.setRangeZoomable(false);
    chartComposite.setMap(map);
    chartComposite.addChartMouseListener(new PlotMouseListener());

    plotTab.setControl(chartComposite);

    chartComposite.pack();
}

From source file:org.toobsframework.pres.chart.ChartBuilder.java

private Plot configurePlot(IRequest componentRequest, String id, BasePlot plotDef, Map params,
        boolean isSubPlot, int parentPlotType, BasePlot parentPlot) throws ChartException {

    boolean is3D = (ParameterUtil.resolveParam(componentRequest, plotDef.getIs3D(), params, "false")[0]
            .equals("false") ? false : true);
    Integer plotType = ChartUtil.getSupportedPlots()
            .get(ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]);
    if (plotType == null) {
        throw new ChartException("Unsupported Plot type "
                + ParameterUtil.resolveParam(componentRequest, plotDef.getType(), params, "multiCategory")[0]);
    }/*from ww w.j  a  v a 2s  .c  o m*/

    Plot plot = null;
    switch (plotType) {
    case ChartUtil.PLOT_CATEGORY_TYPE:

        DomainAxisDef domainAxis = null;
        RangeAxisDef rangeAxis = null;
        plot = new CategoryPlot();
        if (isSubPlot) {
            if (plotDef.getDomainAxisDef() != null
                    && parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) {
                domainAxis = plotDef.getDomainAxisDef();
            } else if (parentPlotType != ChartUtil.PLOT_COMBINEDDOMAINCATEGORY_TYPE) {
                domainAxis = parentPlot.getDomainAxisDef();
            }
            if (plotDef.getRangeAxisDef() != null
                    && parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) {
                rangeAxis = plotDef.getRangeAxisDef();
            } else if (parentPlotType != ChartUtil.PLOT_COMBINEDRANGECATEGORY_TYPE) {
                rangeAxis = parentPlot.getRangeAxisDef();
            }
        } else {
            domainAxis = plotDef.getDomainAxisDef();
            rangeAxis = plotDef.getRangeAxisDef();
        }
        ((CategoryPlot) plot)
                .setDomainAxis(ChartUtil.createCategoryAxis(componentRequest, domainAxis, params, is3D));
        ((CategoryPlot) plot).setRangeAxis(createValueAxis(componentRequest, rangeAxis, params, is3D));

        for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) {
            org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g);
            CategoryItemRenderer renderer = (CategoryItemRenderer) ChartUtil.getRenderer(componentRequest,
                    plotDef, group, params);
            if (group.getUrlBase() != null) {
                renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase()));
            }
            ((CategoryPlot) plot).setRenderer(g, renderer);
            DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();
            if (group.getId() != null) {
                DatasetGroup datasetGroup = new DatasetGroup(group.getId());
                categoryDataset.setGroup(datasetGroup);
            }
            for (int i = 0; i < group.getDatasetCount(); i++) {
                Dataset dataset = group.getDataset(i);
                generateCategoryDataset(componentRequest, id, categoryDataset, dataset, params);
                this.setValueAxisBounds(componentRequest, ((CategoryPlot) plot).getRangeAxis(), rangeAxis,
                        params);
            }
            ((CategoryPlot) plot).setDataset(g, categoryDataset);
        }

        ChartUtil.configurePlot(componentRequest, plot, plotDef, domainAxis, rangeAxis, params);
        break;
    case ChartUtil.PLOT_XY_TYPE:
        plot = new XYPlot();
        break;
    case ChartUtil.PLOT_SPIDER_TYPE:
        plot = new SpiderWebPlot();
        DefaultCategoryDataset categoryDataset = new DefaultCategoryDataset();
        for (int g = 0; g < plotDef.getDatasetGroupCount(); g++) {
            org.toobsframework.pres.chart.config.DatasetGroup group = plotDef.getDatasetGroup(g);

            if (group.getUrlBase() != null) {
                ((SpiderWebPlot) plot).setURLGenerator(new StandardCategoryURLGenerator(group.getUrlBase()));
            }
            if (group.getId() != null) {
                DatasetGroup datasetGroup = new DatasetGroup(group.getId());
                categoryDataset.setGroup(datasetGroup);
            }
            for (int i = 0; i < group.getDatasetCount(); i++) {
                Dataset dataset = group.getDataset(i);
                //generateCategoryDataset(id, categoryDataset, dataset, params);
                for (int s = 0; s < dataset.getDatasetSeriesCount(); s++) {
                    DatasetSeries series = dataset.getDatasetSeries(s);
                    if (series.getColor() != null) {
                        ((SpiderWebPlot) plot).setSeriesPaint(i + s, ChartUtil.getColor(series.getColor()));
                    }
                }
            }
        }
        ((SpiderWebPlot) plot).setDataset(categoryDataset);
        ChartUtil.configurePlot(componentRequest, plot, plotDef, null, null, params);
        break;
    }

    return plot;
}

From source file:ec.ui.view.RevisionSaSeriesView.java

private JFreeChart createMainChart() {
    XYPlot plot = new XYPlot();
    configureAxis(plot);/*from  ww  w.  j a va2  s.c o m*/

    plot.setRenderer(S_INDEX, sRenderer);

    plot.setRenderer(REV_INDEX, revRenderer);

    plot.setNoDataMessage("Not enough data to compute revision history !");
    JFreeChart result = new JFreeChart("", TsCharts.CHART_TITLE_FONT, plot, false);
    result.setPadding(TsCharts.CHART_PADDING);
    return result;
}

From source file:com.chart.SwingChart.java

/**
 * //  ww w. j a va 2 s .  c  o m
 * @param name Chart name
 * @param parent Skeleton parent
 * @param axes Configuration of axes
 * @param abcissaName Abcissa name
 */
public SwingChart(String name, final Skeleton parent, List<AxisChart> axes, String abcissaName) {
    this.skeleton = parent;
    this.axes = axes;
    this.name = name;

    this.abcissaFormat = NumberFormat.getInstance(Locale.getDefault());
    this.ordinateFormat = NumberFormat.getInstance(Locale.getDefault());

    plot = new XYPlot();
    plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor)));
    plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));
    plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    abcissaAxis = new NumberAxis(abcissaName);
    ((NumberAxis) abcissaAxis).setAutoRangeIncludesZero(false);
    abcissaAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    abcissaAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    abcissaAxis.setAutoRange(true);
    abcissaAxis.setLowerMargin(0.0);
    abcissaAxis.setUpperMargin(0.0);
    abcissaAxis.setTickLabelsVisible(true);
    abcissaAxis.setLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize));
    abcissaAxis.setTickLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize));

    plot.setDomainAxis(abcissaAxis);

    for (int i = 0; i < axes.size(); i++) {
        AxisChart categoria = axes.get(i);
        addAxis(categoria.getName());

        for (int j = 0; j < categoria.configSerieList.size(); j++) {
            SimpleSeriesConfiguration cs = categoria.configSerieList.get(j);
            addSeries(categoria.getName(), cs);
        }
    }
    chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 16), plot, false);

    chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));

    chartPanel = new ChartPanel(chart);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)))));

    chartPanel.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escape");
    chartPanel.getActionMap().put("escape", new AbstractAction() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            for (int i = 0; i < plot.getDatasetCount(); i++) {
                XYDataset test = plot.getDataset(i);
                XYItemRenderer r = plot.getRenderer(i);
                r.removeAnnotations();
            }
        }
    });

    chartPanel.addChartMouseListener(cml = new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            try {
                XYItemEntity xyitem = (XYItemEntity) event.getEntity(); // get clicked entity
                XYDataset dataset = (XYDataset) xyitem.getDataset(); // get data set    
                double x = dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem());
                double y = dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem());

                final XYPlot plot = chart.getXYPlot();
                for (int i = 0; i < plot.getDatasetCount(); i++) {
                    XYDataset test = plot.getDataset(i);
                    XYItemRenderer r = plot.getRenderer(i);
                    r.removeAnnotations();
                    if (test == dataset) {
                        NumberAxis ejeOrdenada = AxesList.get(i);
                        double y_max = ejeOrdenada.getUpperBound();
                        double y_min = ejeOrdenada.getLowerBound();
                        double x_max = abcissaAxis.getUpperBound();
                        double x_min = abcissaAxis.getLowerBound();
                        double angulo;
                        if (y > (y_max + y_min) / 2 && x > (x_max + x_min) / 2) {
                            angulo = 3.0 * Math.PI / 4.0;
                        } else if (y > (y_max + y_min) / 2 && x < (x_max + x_min) / 2) {
                            angulo = 1.0 * Math.PI / 4.0;
                        } else if (y < (y_max + y_min) / 2 && x < (x_max + x_min) / 2) {
                            angulo = 7.0 * Math.PI / 4.0;
                        } else {
                            angulo = 5.0 * Math.PI / 4.0;
                        }

                        CircleDrawer cd = new CircleDrawer((Color) r.getSeriesPaint(xyitem.getSeriesIndex()),
                                new BasicStroke(2.0f), null);
                        //XYAnnotation bestBid = new XYDrawableAnnotation(dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()), dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), 11, 11, cd);
                        String txt = "X:" + abcissaFormat.format(x) + ", Y:" + ordinateFormat.format(y);
                        XYPointerAnnotation anotacion = new XYPointerAnnotation(txt,
                                dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()),
                                dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), angulo);
                        anotacion.setTipRadius(10.0);
                        anotacion.setBaseRadius(35.0);
                        anotacion.setFont(new Font("SansSerif", Font.PLAIN, 10));

                        if (Long.parseLong((strChartBackgroundColor.replace("#", "")), 16) > 0xffffff / 2) {
                            anotacion.setPaint(Color.black);
                            anotacion.setArrowPaint(Color.black);
                        } else {
                            anotacion.setPaint(Color.white);
                            anotacion.setArrowPaint(Color.white);
                        }

                        //bestBid.setPaint((Color) r.getSeriesPaint(xyitem.getSeriesIndex()));
                        r.addAnnotation(anotacion);
                    }
                }

                //LabelValorVariable.setSize(LabelValorVariable.getPreferredSize());
            } catch (NullPointerException | ClassCastException ex) {

            }
        }
    });

    chartPanel.setPopupMenu(null);
    chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));

    SwingNode sn = new SwingNode();
    sn.setContent(chartPanel);
    chartFrame = new VBox();
    chartFrame.getChildren().addAll(sn, legendFrame);
    VBox.setVgrow(sn, Priority.ALWAYS);
    VBox.setVgrow(legendFrame, Priority.NEVER);

    chartFrame.getStylesheets().addAll(SwingChart.class.getResource("overlay-chart.css").toExternalForm());

    legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;");

    MenuItem mi;
    mi = new MenuItem("Print");
    mi.setOnAction((ActionEvent t) -> {
        print(chartFrame);
    });
    contextMenuList.add(mi);

    sn.setOnMouseClicked((MouseEvent t) -> {
        if (menu != null) {
            menu.hide();
        }
        if (t.getClickCount() == 2) {
            backgroundEdition();
        }
    });

    mi = new MenuItem("Copy to clipboard");
    mi.setOnAction((ActionEvent t) -> {
        copyClipboard(chartFrame);
    });
    contextMenuList.add(mi);

    mi = new MenuItem("Export values");
    mi.setOnAction((ActionEvent t) -> {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Export to file");
        fileChooser.getExtensionFilters()
                .addAll(new FileChooser.ExtensionFilter("Comma Separated Values", "*.csv"));

        Window w = null;
        try {
            w = parent.getScene().getWindow();
        } catch (NullPointerException e) {

        }
        File file = fileChooser.showSaveDialog(w);
        if (file != null) {
            export(file);
        }
    });
    contextMenuList.add(mi);

    chartFrame.setOnContextMenuRequested((ContextMenuEvent t) -> {
        if (menu != null) {
            menu.hide();
        }
        menu = new ContextMenu();
        menu.getItems().addAll(contextMenuList);
        menu.show(chartFrame, t.getScreenX(), t.getScreenY());
    });

}

From source file:org.locationtech.udig.processingtoolbox.tools.MoranScatterPlotDialog.java

private void updateChart(SimpleFeatureCollection features, String propertyName, String morani) {
    // 1. Create a single plot containing both the scatter and line
    XYPlot plot = new XYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainPannable(false);//w  w  w  .j  av  a  2  s . co m
    plot.setRangePannable(false);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairLockedOnData(true);
    plot.setDomainCrosshairPaint(java.awt.Color.CYAN);
    plot.setRangeCrosshairPaint(java.awt.Color.CYAN);

    plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY);

    // 2. Setup Scatter plot
    // Create the scatter data, renderer, and axis
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];

    NumberAxis xPlotAxis = new NumberAxis(propertyName); // ZScore
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    NumberAxis yPlotAxis = new NumberAxis("lagged " + propertyName); //$NON-NLS-1$
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));

    XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator();

    XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only
    plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
    plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot
    plotRenderer.setBaseToolTipGenerator(plotToolTip);

    // Set the scatter data, renderer, and axis into plot
    plot.setDataset(0, getScatterPlotData(features));
    plot.setRenderer(0, plotRenderer);
    plot.setDomainAxis(0, xPlotAxis);
    plot.setRangeAxis(0, yPlotAxis);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup line
    // Create the line data, renderer, and axis
    XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); // dot

    // Set the line data, renderer, and axis into plot
    NumberAxis xLineAxis = new NumberAxis(EMPTY);
    xLineAxis.setTickMarksVisible(false);
    xLineAxis.setTickLabelsVisible(false);
    NumberAxis yLineAxis = new NumberAxis(EMPTY);
    yLineAxis.setTickMarksVisible(false);
    yLineAxis.setTickLabelsVisible(false);

    plot.setDataset(1, getLinePlotData(crossCenter));
    plot.setRenderer(1, lineRenderer);
    plot.setDomainAxis(1, xLineAxis);
    plot.setRangeAxis(1, yLineAxis);

    // Map the line to the second Domain and second Range
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 0);

    // 4. Setup Selection
    NumberAxis xSelectionAxis = new NumberAxis(EMPTY);
    xSelectionAxis.setTickMarksVisible(false);
    xSelectionAxis.setTickLabelsVisible(false);
    NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
    ySelectionAxis.setTickMarksVisible(false);
    ySelectionAxis.setTickLabelsVisible(false);

    XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only
    selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6));
    selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot

    plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY)));
    plot.setRenderer(2, selectionRenderer);
    plot.setDomainAxis(2, xSelectionAxis);
    plot.setRangeAxis(2, ySelectionAxis);

    // Map the scatter to the second Domain and second Range
    plot.mapDatasetToDomainAxis(2, 0);
    plot.mapDatasetToRangeAxis(2, 0);

    // 5. Finally, Create the chart with the plot and a legend
    String title = "Moran's I = " + morani; //$NON-NLS-1$
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(title, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java

private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection shipments,
        XYSeriesCollection solution) {/*from   w w w.  jav  a 2 s. co m*/
    XYPlot plot = new XYPlot();
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

    XYLineAndShapeRenderer problemRenderer = getProblemRenderer(problem);
    plot.setDataset(0, problem);
    plot.setRenderer(0, problemRenderer);

    XYItemRenderer shipmentsRenderer = getShipmentRenderer(shipments);
    plot.setDataset(1, shipments);
    plot.setRenderer(1, shipmentsRenderer);

    if (solution != null) {
        XYItemRenderer solutionRenderer = getRouteRenderer(solution);
        plot.setDataset(2, solution);
        plot.setRenderer(2, solutionRenderer);
    }

    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();

    if (boundingBox == null) {
        xAxis.setRangeWithMargins(getDomainRange(problem));
        yAxis.setRangeWithMargins(getRange(problem));
    } else {
        xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX));
        yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY));
    }

    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    return plot;
}

From source file:no.met.jtimeseries.chart.Utility.java

/**
 * Create a plot with an error message in case of error.
 * /*from   w  w w. j  a v a2  s.  c o  m*/
 * @param width
 *            The width of the plot
 * @return The JFreeChart error plot
 */
public static JFreeChart createErrorChart(int width) {
    XYPlot plot = new XYPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImage(Symbols.getImage("/error.png"));
    JFreeChart jchart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    jchart.setBorderVisible(false);
    Paint paint = new GradientPaint(0, 0, Color.WHITE, width, 0, Color.WHITE);
    jchart.setBackgroundPaint(paint);

    return jchart;
}

From source file:ec.util.chart.swing.JTimeSeriesChart.java

private void growSubPlots(int size) {
    for (int i = 0; i < size; i++) {
        XYPlot plot = new XYPlot();

        for (int rendererIndex = 0; rendererIndex < supportedRendererTypes.size(); rendererIndex++) {
            SeriesIndexResolver resolver = SeriesIndexResolver.create(plot, rendererIndex);
            JTimeSeriesRendererSupport support = new RendererSupport(resolver);
            plot.setRenderer(rendererIndex, support.createRenderer(supportedRendererTypes.get(rendererIndex)));
        }/*from   w w  w  .j ava2 s.c  o  m*/

        NumberAxis rangeAxis = new NumberAxis();
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setTickLabelInsets(new RectangleInsets(10, 5, 10, 2));
        rangeAxis.setLowerMargin(0.02);
        rangeAxis.setUpperMargin(0.02);
        plot.setRangeAxis(rangeAxis);

        mainPlot.add(plot);

        onDatasetChange(plot);
        onColorSchemeSupportChange(plot);
        onValueFormatChange(plot);
        onNoDataMessageChange(plot);
        onElementVisibleChange(plot);
        onFontSupportChange(plot);
    }
}

From source file:org.mwc.debrief.editable.test.EditableTests.java

private Editable getEditable(IType type) {
    Editable editable = null;//w  w  w . j a v  a  2s .  c  o  m
    switch (type.getFullyQualifiedName()) {
    case "Debrief.Wrappers.SensorWrapper":
        SensorWrapper sensor = new SensorWrapper("tester");
        final java.util.Calendar cal = new java.util.GregorianCalendar(2001, 10, 4, 4, 4, 0);

        // and create the list of sensor contact data items
        cal.set(2001, 10, 4, 4, 4, 0);
        sensor.add(new SensorContactWrapper("tester", new HiResDate(cal.getTime().getTime()), null, null, null,
                null, null, 1, sensor.getName()));

        cal.set(2001, 10, 4, 4, 4, 23);
        sensor.add(new SensorContactWrapper("tester", new HiResDate(cal.getTime().getTime()), null, null, null,
                null, null, 1, sensor.getName()));
        editable = sensor;
        break;
    case "MWC.GUI.Shapes.ChartFolio":
        editable = new ChartFolio(false, Color.white);
        break;
    case "org.mwc.cmap.naturalearth.wrapper.NELayer":
        editable = new NELayer(Activator.getDefault().getDefaultStyleSet());
        break;
    case "MWC.GUI.VPF.CoverageLayer$ReferenceCoverageLayer":
        final LibrarySelectionTable LST = null;
        final DebriefFeatureWarehouse myWarehouse = new DebriefFeatureWarehouse();
        final FeaturePainter fp = new FeaturePainter("libref", "Coastline");
        fp.setVisible(true);
        editable = new CoverageLayer.ReferenceCoverageLayer(LST, myWarehouse, "libref", "libref", "Coastline",
                fp);
        break;
    case "MWC.GUI.Chart.Painters.ETOPOPainter":
        editable = new ETOPOPainter("etopo", null);
        break;
    case "MWC.GUI.ETOPO.ETOPO_2_Minute":
        editable = new ETOPO_2_Minute("etopo");
        break;
    case "MWC.GUI.ExternallyManagedDataLayer":
        editable = new ExternallyManagedDataLayer("test", "test", "test");
        break;
    case "MWC.GUI.Shapes.CircleShape":
        editable = new CircleShape(new WorldLocation(2d, 2d, 2d), 2d);
        break;
    case "Debrief.Wrappers.Track.SplittableLayer":
        editable = new SplittableLayer(true);
        break;
    case "org.mwc.debrief.satc_interface.data.SATC_Solution":
        final ISolversManager solvMgr = SATC_Activator.getDefault().getService(ISolversManager.class, true);
        final ISolver newSolution = solvMgr.createSolver("test");
        editable = new SATC_Solution(newSolution);
        break;
    case "MWC.GUI.Shapes.PolygonShape":
        editable = new PolygonShape(null);
        break;
    case "ASSET.GUI.Painters.NoiseSourcePainter":
        editable = new ASSET.GUI.Painters.NoiseSourcePainter.PainterTest().getEditable();
        break;
    case "ASSET.GUI.Painters.ScenarioNoiseLevelPainter":
        editable = new ASSET.GUI.Painters.ScenarioNoiseLevelPainter.NoiseLevelTest().getEditable();
        break;
    case "ASSET.GUI.Workbench.Plotters.ScenarioParticipantWrapper":
        editable = new ScenarioParticipantWrapper(new SSN(12), null);
        break;
    case "Debrief.Wrappers.PolygonWrapper":
        // get centre of area
        WorldLocation centre = new WorldLocation(12, 12, 12);
        // create the shape, based on the centre
        final Vector<PolygonNode> path2 = new Vector<PolygonNode>();
        final PolygonShape newShape = new PolygonShape(path2);
        // and now wrap the shape
        final PolygonWrapper theWrapper = new PolygonWrapper("New Polygon", newShape, PlainShape.DEFAULT_COLOR,
                null);
        // store the new point
        newShape.add(new PolygonNode("1", centre, (PolygonShape) theWrapper.getShape()));
        editable = theWrapper;
        break;
    case "Debrief.Wrappers.Track.AbsoluteTMASegment":
        WorldSpeed speed = new WorldSpeed(5, WorldSpeed.Kts);
        double course = 33;
        WorldLocation origin = new WorldLocation(12, 12, 12);
        HiResDate startTime = new HiResDate(11 * 60 * 1000);
        HiResDate endTime = new HiResDate(17 * 60 * 1000);
        editable = new AbsoluteTMASegment(course, speed, origin, startTime, endTime);
        break;
    case "Debrief.Wrappers.Track.RelativeTMASegment":
        speed = new WorldSpeed(5, WorldSpeed.Kts);
        course = 33;
        final WorldVector offset = new WorldVector(12, 12, 0);
        editable = new RelativeTMASegment(course, speed, offset, null);
        break;
    case "Debrief.Wrappers.Track.PlanningSegment":
        speed = new WorldSpeed(5, WorldSpeed.Kts);
        course = 33;
        final WorldDistance worldDistance = new WorldDistance(5, WorldDistance.MINUTES);
        editable = new PlanningSegment("test", course, speed, worldDistance, Color.WHITE);
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.BMC_Wrapper":
        BearingMeasurementContribution bmc = new BearingMeasurementContribution();
        bmc.setName("Measured bearing");
        bmc.setAutoDetect(false);
        editable = new BMC_Wrapper(bmc);
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.FMC_Wrapper":
        FrequencyMeasurementContribution fmc = new FrequencyMeasurementContribution();
        fmc.setName("Measured frequence");
        editable = new FMC_Wrapper(fmc);
        break;
    case "Debrief.Wrappers.SensorContactWrapper":
        origin = new WorldLocation(0, 0, 0);
        editable = new SensorContactWrapper("blank track", new HiResDate(new java.util.Date().getTime()),
                new WorldDistance(1, WorldDistance.DEGS), 55d, origin, java.awt.Color.red, "my label", 1,
                "theSensorName");
        break;
    case "Debrief.Wrappers.FixWrapper":
        final Fix fx = new Fix(new HiResDate(12, 0), new WorldLocation(2d, 2d, 2d), 2d, 2d);
        final TrackWrapper tw = new TrackWrapper();
        tw.setName("here ew arw");
        FixWrapper ed = new FixWrapper(fx);
        ed.setTrackWrapper(tw);
        editable = ed;
        break;
    case "Debrief.Wrappers.ShapeWrapper":
        centre = new WorldLocation(2d, 2d, 2d);
        editable = new ShapeWrapper("new ellipse", new EllipseShape(centre, 0,
                new WorldDistance(0, WorldDistance.DEGS), new WorldDistance(0, WorldDistance.DEGS)),
                java.awt.Color.red, null);
        break;
    case "Debrief.GUI.Tote.Painters.PainterManager":
        final StepControl stepper = new Debrief.GUI.Tote.Swing.SwingStepControl(null, null, null, null, null,
                null);
        editable = new PainterManager(stepper);
        break;
    case "Debrief.Wrappers.TMAContactWrapper":
        origin = new WorldLocation(2, 2, 0);
        final HiResDate theDTG = new HiResDate(new java.util.Date().getTime());
        final EllipseShape theEllipse = new EllipseShape(origin, 45, new WorldDistance(10, WorldDistance.DEGS),
                new WorldDistance(5, WorldDistance.DEGS));
        theEllipse.setName("test ellipse");
        editable = new TMAContactWrapper("blank sensor", "blank track", theDTG, origin, 5d, 6d, 1d, Color.pink,
                "my label", theEllipse, "some symbol");
        break;
    case "MWC.GUI.JFreeChart.NewFormattedJFreeChart":
        XYPlot plot = new XYPlot();
        DefaultXYItemRenderer renderer = new DefaultXYItemRenderer();
        plot.setRenderer(renderer);
        editable = new NewFormattedJFreeChart("test", new java.awt.Font("Dialog", 0, 18), plot, false);
        break;
    case "org.mwc.cmap.core.ui_support.swt.SWTCanvasAdapter":
        final Editable[] edit = new Editable[1];
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                edit[0] = new SWTCanvasAdapter(null);
            }
        });
        editable = edit[0];
        break;
    case "ASSET.Models.Decision.Conditions.OrCondition":
        System.out.println(type.getFullyQualifiedName() + " hasn't public constructor.");
        return null;
    case "ASSET.Models.Decision.Movement.RectangleWander":
        final WorldLocation topLeft = SupportTesting.createLocation(0, 10000);
        final WorldLocation bottomRight = SupportTesting.createLocation(10000, 0);
        final WorldArea theArea = new WorldArea(topLeft, bottomRight);
        editable = new RectangleWander(theArea, "rect wander");
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.BMC_Wrapper$BearingMeasurementWrapper":
        bmc = new BearingMeasurementContribution();
        bmc.setName("Measured bearing");
        bmc.setAutoDetect(false);
        CoreMeasurement cm = new CoreMeasurement(new Date());
        BMC_Wrapper bmcw = new BMC_Wrapper(bmc);
        editable = bmcw.new BearingMeasurementWrapper(cm);
        break;
    case "org.mwc.debrief.satc_interface.data.wrappers.FMC_Wrapper$FrequencyMeasurementEditable":
        fmc = new FrequencyMeasurementContribution();
        fmc.setName("Measured frequence");
        FMC_Wrapper fmcw = new FMC_Wrapper(fmc);
        cm = new CoreMeasurement(new Date());
        editable = fmcw.new FrequencyMeasurementEditable(cm);
        break;
    case "ASSET.GUI.SuperSearch.Plotters.SSGuiSupport$ParticipantListener":
        SSGuiSupport ssgs = new SSGuiSupport();
        ssgs.setScenario(new MultiForceScenario());
        editable = new SSGuiSupport.ParticipantListener(new CoreParticipant(12), ssgs);
        break;
    case "ASSET.GUI.Workbench.Plotters.BasePlottable":
        // skip it
        return null;
    case "MWC.TacticalData.GND.GTrack":
        // skip it
        return null;
    default:
        break;
    }

    if (editable != null) {
        return editable;
    }
    Class<?> clazz;
    try {
        clazz = Class.forName(type.getFullyQualifiedName());
    } catch (ClassNotFoundException e1) {
        //e1.printStackTrace();
        System.out.println("CNFE " + e1.getMessage() + " " + type.getFullyQualifiedName());
        return null;
    }
    try {
        @SuppressWarnings("unused")
        Method infoMethod = clazz.getDeclaredMethod("getInfo", new Class[0]);
    } catch (Exception e) {
        return null;
    }
    try {
        editable = (Editable) clazz.newInstance();
    } catch (Exception e) {
        Constructor<?>[] constructors = clazz.getConstructors();
        for (Constructor<?> constructor : constructors) {
            try {
                Class<?>[] paramTypes = constructor.getParameterTypes();
                Object[] params = new Object[paramTypes.length];
                for (int i = 0; i < paramTypes.length; i++) {
                    Class<?> paramType = paramTypes[i];
                    if (HiResDate.class.equals(paramType)) {
                        params[i] = new HiResDate(new Date());
                    } else if (WorldDistance.class.equals(paramType)) {
                        params[i] = new WorldDistance(12d, WorldDistance.DEGS);
                    } else if (WorldSpeed.class.equals(paramType)) {
                        params[i] = new WorldSpeed(12, WorldSpeed.M_sec);
                    } else if (WorldLocation.class.equals(paramType)) {
                        params[i] = new WorldLocation(12, 12, 12);
                    } else if ("java.lang.String".equals(paramType.getName())) {
                        params[i] = "test";
                    } else if (!paramType.isPrimitive()) {
                        params[i] = null;
                    } else {
                        if (paramType.equals(int.class)) {
                            params[i] = new Integer("0");
                        }
                        if (paramType.equals(boolean.class)) {
                            params[i] = Boolean.FALSE;
                        }
                        if (paramType.equals(long.class)) {
                            params[i] = new Long("0");
                        }
                        if (paramType.equals(double.class)) {
                            params[i] = new Double("0");
                        }
                        if (paramType.equals(float.class)) {
                            params[i] = new Float("0");
                        }
                        if (paramType.equals(short.class)) {
                            params[i] = new Short("0");
                        }
                    }
                }
                editable = (Editable) constructor.newInstance(params);
                break;
            } catch (Exception e1) {
                // ignore
                //System.out.println(e1.getMessage());
                //e1.printStackTrace();
            }
        }
    }
    if (editable == null) {
        System.out.println("Can't instantiate type " + type.getFullyQualifiedName());
    }
    return editable;
}

From source file:gda.plots.SimplePlot.java

/**
 * @param type/*from w  ww.j  a  va  2s.  com*/
 * @param autoRange
 * @param enableHistory 
 */
public SimplePlot(int type, boolean autoRange, boolean enableHistory) {

    super(new JFreeChart(new XYPlot()));
    setChart(ChartFactory.createXYLineChart(title, "xaxis", "yaxis", leftSeriesCollection,
            PlotOrientation.VERTICAL, true, false, false));
    this.type = type;
    if (enableHistory) {
        history = new LinkedList<SimpleXYSeries>();
        addHistoryCommandsToPopupMenu();
    }

    // For width and height greater than these values the graph is drawn by
    // using a transform on the Graphics2D. If this comes into operation
    // then the placing of components added with wrapAndDisplay goes wrong.
    // The easiest way to keep out of trouble is to make them large. This
    // also
    // stops distortion of fonts when expanding to full screen size.
    setMaximumDrawWidth(5000);
    setMaximumDrawHeight(2000);

    // Next line added to fix sun.dc.pr.PRException on Windows PC's
    getChart().setAntiAlias(false);

    xYPlot = getChart().getXYPlot();
    if (type == BARCHART) {
        xYPlot.setRenderer(new SimpleXYBarRenderer());
    } else {
        xYPlot.setRenderer(new SimpleXYItemRenderer());
        xYPlot.getRenderer().setToolTipGenerator(new SimpleXYToolTipGenerator());
    }

    // The x and y axes are created and set here so that SimpleNumberAxis
    // can
    // be used. This allows SimplePlot to keep the CoordinateFormatter up to
    // date about the accuracy required (seeForXAxis paintComponent()). NB
    // Any secondary y axes will be of type NumberAxis.

    createXAxes(autoRange);
    xYPlot.setDomainAxis(linearXAxis);

    createYAxes(autoRange);
    xYPlot.setRangeAxis(linearYAxis);

    // There are two legends. We use the exisiting default one for
    // lines displayed with respect to the left Y axis and create a
    // new one for those of the right Y axis (if there is one).
    // Normally getChart().getPlot() would provide the LegendItemSource
    // for the default legend but we extract it and set its Source to be a
    // LegendItemsGetter (defined here) and change its position to RIGHT
    // (default is TOP).
    // leftSeriesLegend = getChart().getLegend();
    // leftSeriesLegend.setPosition(RectangleEdge.RIGHT);

    // This LegendItemsGetter will return only left series legend items.
    leftSeriesLegendItemsGetter = new LegendItemsGetter(0);

    // TEST CODE DO NOT REMOVE
    leftSeriesLegend = new SimpleLegendTitle(leftSeriesLegendItemsGetter);
    leftSeriesLegend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    leftSeriesLegend.setBorder(new BlockBorder());
    leftSeriesLegend.setBackgroundPaint(Color.white);
    leftSeriesLegend.setPosition(RectangleEdge.BOTTOM);
    leftSeriesLegend.setPosition(RectangleEdge.RIGHT);
    getChart().removeLegend();
    getChart().addLegend(leftSeriesLegend);
    // END OF TEST CODE

    leftSeriesLegend.setSources(new LegendItemSource[] { leftSeriesLegendItemsGetter });

    rightSeriesLegend = new SimpleLegendTitle(null);
    rightSeriesLegend.setPosition(RectangleEdge.RIGHT);
    rightSeriesLegend.setBorder(leftSeriesLegend.getBorder());
    rightSeriesLegend.setBackgroundPaint(leftSeriesLegend.getBackgroundPaint());

    // This LegendItemsGetter will return only right series legend items.
    rightSeriesLegendItemsGetter = new LegendItemsGetter(1);
    rightSeriesLegend.setSources(new LegendItemSource[] { rightSeriesLegendItemsGetter });
    getChart().addLegend(rightSeriesLegend);

    // The mousePositionTracker is added as a subtitle
    mpt = new MousePositionTracker("");
    addChartMouseListener(mpt);
    getChart().addSubtitle(mpt);

    // The coordinateFormatter is used in the MousePositionTracker when
    // displaying the mouse position.
    coordinateFormatter = new SimpleCoordinateFormatter();

    dataMagnifierWindow = new DataMagnifierWindow(SwingUtilities.getRoot(this));
    dataMagnifierWindow.setSimplePlot(this, leftSeriesCollection);

    // Make sure zooming starts in the correct state.
    setZooming(false);

    setTurboMode(false);
    setStripWidth(null);
    setTrackPointer(true);

}