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

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

Introduction

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

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the primary dataset and sends a change event to all registered listeners.

Usage

From source file:org.gephi.statistics.plugin.DegreeDistribution.java

/**
 *
 * @return The undirected version of this report.
 *///w  w w  .  j  a  va2s .  c om
private String getUndirectedReport() {
    double max = 0;
    XYSeries series2 = new XYSeries("Series 2");
    for (int i = 1; i < combinedDistribution[1].length; i++) {
        if (combinedDistribution[1][i] > 0) {
            series2.add((Math.log(combinedDistribution[0][i]) / Math.log(Math.E)),
                    (Math.log(combinedDistribution[1][i]) / Math.log(Math.E)));
            max = (float) Math.max((Math.log(combinedDistribution[0][i]) / Math.log(Math.E)), max);
        }
    }
    double a = combinedAlpha;
    double b = combinedBeta;

    XYSeries series1 = new XYSeries(combinedAlpha + " ");
    series1.add(0, a);
    series1.add(max, a + b * max);

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series2);

    JFreeChart chart = ChartFactory.createXYLineChart("Degree Distribution", "Degree", "Occurrence", dataset,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesShape(1, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1));
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setDomainGridlinePaint(java.awt.Color.GRAY);
    plot.setRangeGridlinePaint(java.awt.Color.GRAY);

    plot.setRenderer(renderer);

    String imageFile = "";
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        TempDir tempDir = TempDirUtils.createTempDir();
        final String fileName = "distribution.png";
        final File file1 = tempDir.createFile(fileName);
        imageFile = "<IMG SRC=\"file:" + file1.getAbsolutePath() + "\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>";
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

    } catch (IOException e) {
        System.out.println(e.toString());
    }

    String report = "<HTML> <BODY> <h1>Degree Distribution Metric Report </h1> " + "<hr>" + "<br>"
            + "<h2> Parameters: </h2>" + "Network Interpretation:  " + (isDirected ? "directed" : "undirected")
            + "<br>" + "<br> <h2> Results: </h2>" + "Degree Power Law: -" + combinedAlpha + "\n <BR>"
            + imageFile + "</BODY> </HTML>";
    return report;
}

From source file:correlation.and.regression.analysis.MainWindow.java

private void showCorrelationField() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries correlation = new XYSeries("Correlation Field");
    for (int i = 0; i < arr[0].countOfNumbers; i++) {
        //XYSeries tmp = new XYSeries(""+i);
        correlation.add(arr[0].getNumber(i), arr[1].getNumber(i));
        //tmp.add(arr[0].getNumber(i), arr[1].getNumber(i));
        //dataset.addSeries(tmp);
    }/*  w  w w .ja va2  s. c  om*/
    dataset.addSeries(correlation);
    XYSeries regr = StaticFunctions.drawRegressionLine(arr[0], arr[1]);
    dataset.addSeries(regr);

    XYSeries ConfidenceIntervalMax = StaticFunctions.drawConfidenceIntervalMax(arr[0], arr[1]);
    dataset.addSeries(ConfidenceIntervalMax);
    XYSeries ConfidenceIntervalMin = StaticFunctions.drawConfidenceIntervalMin(arr[0], arr[1]);
    dataset.addSeries(ConfidenceIntervalMin);

    XYSeries Confidence2IntervalMax = StaticFunctions.drawConfidence2IntervalMax(arr[0], arr[1]);
    dataset.addSeries(Confidence2IntervalMax);
    XYSeries Confidence2IntervalMin = StaticFunctions.drawConfidence2IntervalMin(arr[0], arr[1]);
    dataset.addSeries(Confidence2IntervalMin);

    XYSeries TolerantIntervalMax = StaticFunctions.drawTolerantIntervalMax(arr[0], arr[1]);
    dataset.addSeries(TolerantIntervalMax);
    XYSeries TolerantIntervalMin = StaticFunctions.drawTolerantIntervalMin(arr[0], arr[1]);
    dataset.addSeries(TolerantIntervalMin);
    JFreeChart chart = ChartFactory.createXYLineChart("Relation", "X", "Y", dataset, PlotOrientation.VERTICAL,
            true, true, false);
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesShapesVisible(3, false);
    renderer.setSeriesShapesVisible(4, false);
    renderer.setSeriesShapesVisible(5, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChP = new ChartPanel(chart);
    ChP.setSize(jSPanelChart.getWidth(), jSPanelChart.getHeight());
    jSPanelChart.removeAll();
    jSPanelChart.revalidate();
    jSPanelChart.add(ChP);
    jSPanelChart.repaint();
}

From source file:KIDLYFactory.java

/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).//from w w  w  .jav  a2 s.  c  o m
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel,
        OHLCDataset dataset, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:no.ntnu.mmfplanner.ui.graph.SaNpvChart.java

/**
 * Creates the chart//from w ww  .ja  v a 2  s. c o  m
 */
private void createChart() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            "Period", // x axis label
            "Discounted Cash", // y axis label
            null, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    setChart(chart);
    setMouseZoomable(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLegendLine(new Rectangle2D.Double(0.0, 0.0, 6.0, 0.0));
    renderer.setUseFillPaint(true);

    // the x=0 line
    renderer.setSeriesPaint(0, Color.GRAY);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesVisibleInLegend(0, new Boolean(false));

    plot.setRenderer(renderer);
}

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

/**
 * Creates an overlaid chart./*from ww w  .  jav  a  2  s  .  c o  m*/
 *
 * @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:KIDLYFactory.java

/**
 * Creates a stepped XY plot with default settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A chart./*from  w w  w.ja  va  2  s.  c  om*/
 */
public static JFreeChart createXYStepChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    DateAxis xAxis = new DateAxis(xAxisLabel);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}

From source file:KIDLYFactory.java

/**
 * Creates a filled stepped XY plot with default settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A chart.//w  w  w .  j  av a2 s.  com
 */
public static JFreeChart createXYStepAreaChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = new StandardXYToolTipGenerator();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }
    XYItemRenderer renderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator,
            urlGenerator);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}

From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java

/**
 * Create a SNP block graph for the given parameters. This graph
 * will show where the intervals do and don't exist. Interval lists
 * are organized with the X axis label matching the list's key
 * @param snpIntervals//from w w w .j a v  a2 s.  c  o m
 *          the blocks
 * @param startInBasePairs
 *          the x location to start the graph at
 * @param extentInBasePairs
 *          the extent to use for the graph
 * @param maximumImageBlockCount
 *          the max # of separate image blocks to use
 * @param renderAxes
 *          if true render the axes... otherwise dont
 * @param legendText
 *          the text to use for the legend
 * @param yAxisText
 *          the text to use for the y axis
 * @param trueColor
 *          the color to use for true
 * @param falseColor
 *          the color to use for false 
 * @return
 *          the graph
 */
public JFreeChart createSnpIntervalGraph(
        final Map<String, ? extends List<? extends BasePairInterval>> snpIntervals, final long startInBasePairs,
        final long extentInBasePairs, final int maximumImageBlockCount, final boolean renderAxes,
        final String legendText, final String yAxisText, final Color trueColor, final Color falseColor) {
    XYDataset dataset = snpIntervalsToDataset(snpIntervals, startInBasePairs, extentInBasePairs,
            maximumImageBlockCount);

    NumberAxis xAxis = new NumberAxis("SNP Position (Base Pairs)");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs));
    String[] sortedStrainNames = extractSortedStrainNames(snpIntervals);
    for (int strainIndex = 0; strainIndex < sortedStrainNames.length; strainIndex++) {
        LOG.info("Strain Name: " + sortedStrainNames[strainIndex]);
    }
    SymbolAxis yAxis = new SymbolAxis(yAxisText == null ? "" : yAxisText, sortedStrainNames);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    LegendItemCollection items = new LegendItemCollection();
    if (legendText != null) {
        items.add(new LegendItem(legendText, null, null, null, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0),
                trueColor, new BasicStroke(), Color.BLACK));
    }
    plot.setFixedLegendItems(items);

    XYBlockRenderer r = new XYBlockRenderer();
    SmoothPaintScale ps = new SmoothPaintScale(0.0, 1.0, falseColor, trueColor);

    r.setPaintScale(ps);
    r.setBlockHeight(1.0);
    r.setBlockWidth(1.0);
    plot.setRenderer(r);

    final JFreeChart chart;
    if (renderAxes) {
        chart = new JFreeChart("Identical By State Blocks", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        xAxis.setVisible(false);
        yAxis.setVisible(false);
        plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
        chart = new JFreeChart(plot);
    }

    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:JDAC.JDAC.java

public JDAC() {
    setTitle("JDAC");

    ImageIcon img = new ImageIcon("logo.png");
    setIconImage(img.getImage());/* ww  w . j ava 2s . c  o m*/

    //setLayout(new FlowLayout());

    mDataset = createDataset("A");

    mChart = ChartFactory.createXYLineChart("Preview", "Time (ms)", "Value", mDataset, PlotOrientation.VERTICAL,
            false, true, false);

    mLastChart = ChartFactory.createXYLineChart("Last n values", "Time (ms)", "Value", createLastDataset("B"),
            PlotOrientation.VERTICAL, false, true, false);
    mChart.getXYPlot().getDomainAxis().setLowerMargin(0);
    mChart.getXYPlot().getDomainAxis().setUpperMargin(0);
    mLastChart.getXYPlot().getDomainAxis().setLowerMargin(0);
    mLastChart.getXYPlot().getDomainAxis().setUpperMargin(0);

    ChartPanel chartPanel = new ChartPanel(mChart);
    ChartPanel chartLastPanel = new ChartPanel(mLastChart);
    //chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );

    XYPlot plot = mChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    plot.setRenderer(renderer);

    XYPlot lastPlot = mLastChart.getXYPlot();
    XYLineAndShapeRenderer lastRenderer = new XYLineAndShapeRenderer();
    lastRenderer.setSeriesPaint(0, Color.RED);
    lastRenderer.setSeriesStroke(0, new BasicStroke(1.0f));
    lastPlot.setRenderer(lastRenderer);

    resetChartButton = new JButton("Reset");
    resetChartButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetChart();
        }
    });

    mMenuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenu sensorMenu = new JMenu("Sensor");
    JMenu deviceMenu = new JMenu("Device");
    portSubMenu = new JMenu("Port");
    JMenu helpMenu = new JMenu("Help");

    serialStatusLabel = new JLabel("Disconnected");
    statusLabel = new JLabel("Ready");
    clearStatus = new LabelClear(statusLabel);
    clearStatus.resetTime();

    connectButton = new JMenuItem("Connect");
    disconnectButton = new JMenuItem("Disconnect");
    startButton = new JButton("Start");
    stopButton = new JButton("Stop");
    scanButton = new JMenuItem("Refresh port list");
    exportCSVButton = new JMenuItem("Export data to CSV");
    exportCSVButton.setAccelerator(KeyStroke.getKeyStroke("control S"));
    exportCSVButton.setMnemonic(KeyEvent.VK_S);
    exportPNGButton = new JMenuItem("Export chart to PNG");

    JPanel optionsPanel = new JPanel(new BorderLayout());

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setAccelerator(KeyStroke.getKeyStroke("control X"));
    exitItem.setMnemonic(KeyEvent.VK_X);

    JMenuItem aboutItem = new JMenuItem("About");
    JMenuItem helpItem = new JMenuItem("Help");
    JMenuItem quickStartItem = new JMenuItem("Quick start");

    lastSpinner = new JSpinner(new SpinnerNumberModel(10, 0, 1000, 1));

    ActionListener mSensorListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setSensor(e.getActionCommand());
        }
    };
    ButtonGroup sensorGroup = new ButtonGroup();
    JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem("Temperature");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Distance");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Voltage");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Generic");
    tmpRadioButton.setSelected(true);
    setSensor("Generic");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);

    connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (selectedPortName == null) {
                setStatus("No port selected");
                return;
            }
            connect(selectedPortName);
        }
    });
    disconnectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            serialStatusLabel.setText("Disconnecting...");
            if (serialPort == null) {
                serialStatusLabel.setText("Disconnected");
                serialConnected = false;
                return;
            }

            stopCollect();
            disconnect();
        }
    });
    scanButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            searchForPorts();
        }
    });
    exportCSVButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveData();
        }
    });
    exportPNGButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            exportPNG();
        }
    });
    startButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            startCollect();
        }
    });
    stopButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            stopCollect();
        }
    });
    lastSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            numLastValues = (Integer) lastSpinner.getValue();
            updateLastTitle();
        }
    });
    updateLastTitle();
    exitItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    helpItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new HelpFrame();
        }
    });
    aboutItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new AboutFrame();
        }
    });
    quickStartItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new StartFrame();
        }
    });

    fileMenu.add(exportCSVButton);
    fileMenu.add(exportPNGButton);
    fileMenu.addSeparator();
    fileMenu.add(exitItem);
    deviceMenu.add(connectButton);
    deviceMenu.add(disconnectButton);
    deviceMenu.addSeparator();
    deviceMenu.add(portSubMenu);
    deviceMenu.add(scanButton);
    helpMenu.add(quickStartItem);
    helpMenu.add(helpItem);
    helpMenu.add(aboutItem);

    mMenuBar.add(fileMenu);
    mMenuBar.add(sensorMenu);
    mMenuBar.add(deviceMenu);
    mMenuBar.add(helpMenu);

    JPanel controlsPanel = new JPanel();
    controlsPanel.add(startButton);
    controlsPanel.add(stopButton);
    controlsPanel.add(resetChartButton);
    optionsPanel.add(controlsPanel, BorderLayout.LINE_START);

    JPanel lastPanel = new JPanel(new FlowLayout());
    lastPanel.add(new JLabel("Shown values: "));
    lastPanel.add(lastSpinner);
    optionsPanel.add(lastPanel);

    JPanel serialPanel = new JPanel(new FlowLayout());
    serialPanel.add(serialStatusLabel);
    optionsPanel.add(serialPanel, BorderLayout.LINE_END);

    add(optionsPanel, BorderLayout.PAGE_START);

    JPanel mainPanel = new JPanel(new GridLayout(0, 2));
    mainPanel.add(chartPanel);
    mainPanel.add(chartLastPanel);
    add(mainPanel);

    add(statusLabel, BorderLayout.PAGE_END);
    setJMenuBar(mMenuBar);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            dispose();
        }
    });

    setSize(800, 800);
    pack();
    new StartFrame();

    //center on screen
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((dimension.getWidth() - getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - getHeight()) / 2);
    setLocation(x, y);

    setVisible(true);
}

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

private Editable getEditable(IType type) {
    Editable editable = null;/*from   w ww  .j  a  va2s. co 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;
}