Example usage for javax.swing JTabbedPane add

List of usage examples for javax.swing JTabbedPane add

Introduction

In this page you can find the example usage for javax.swing JTabbedPane add.

Prototype

public void add(Component component, Object constraints, int index) 

Source Link

Document

Adds a component at the specified tab index.

Usage

From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java

/**
 * Creates a panel displaying the distribution chart of certain selected
 * statistical values./*from w w  w  .  java 2 s  .  c om*/
 * 
 * @param title
 *          The headline of the chart. Will be hidden if set to null.
 * @param statistics
 *          The selected statistics of a campaign containing all needed
 *          values.
 * @param roomType
 *          The room type to determine the colour of the chart.
 * @param preview
 *          Will hide annotations, labels and headlines if set true.
 * @param fullscreen
 *          Will correctly adjust the preferred size to screen resolution if
 *          true.
 * @param mouseEvent
 *          Will enable mouseClickedEvent if set true. Use with care, and only
 *          inside the results panel. Set to false if you are unsure what you
 *          are doing.
 * @return A chart displaying the distribution of certain selected statistical
 *         values.
 */
public JPanel createDistributionPanel(String title, DescriptiveStatistics statistics, OMRoomType roomType,
        boolean preview, boolean fullscreen, boolean mouseEvent) {
    JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, preview);
    ChartPanel chartPanel = new ChartPanel(chart);
    Dimension dim;
    if (fullscreen) {
        dim = Toolkit.getDefaultToolkit().getScreenSize();
    } else {
        dim = new Dimension(730, 347);
    }
    chartPanel.setPreferredSize(dim);
    if (mouseEvent) {
        chartPanel.addChartMouseListener(new ChartMouseListener() {
            @Override
            public void chartMouseClicked(ChartMouseEvent e) {
                OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem();
                OMCampaign[] campaigns = simulation.getCampaigns();
                try {
                    XYItemEntity entity = (XYItemEntity) e.getEntity();
                    XYDataset dataset = entity.getDataset();
                    int item = entity.getItem();
                    double x = dataset.getXValue(0, item);
                    double comparable = 0.0;
                    OMCampaign result = null;
                    OMStatistics selectedType = (OMStatistics) comboBoxStatistics.getSelectedItem();
                    for (int i = 0; i < campaigns.length; i++) {
                        switch (selectedType) {
                        case RoomArithmeticMeans:
                            comparable = campaigns[i].getRoomAverage();
                            break;
                        case RoomGeometricMeans:
                            comparable = campaigns[i].getRoomLogAverage();
                            break;
                        case RoomMedianQ50:
                            comparable = campaigns[i].getRoomMedian();
                            break;
                        case RoomMaxima:
                            comparable = campaigns[i].getRoomMaximum();
                            break;
                        case CellarArithmeticMeans:
                            comparable = campaigns[i].getCellarAverage();
                            break;
                        case CellarGeometricMeans:
                            comparable = campaigns[i].getCellarLogAverage();
                            break;
                        case CellarMedianQ50:
                            comparable = campaigns[i].getCellarMedian();
                            break;
                        case CellarMaxima:
                            comparable = campaigns[i].getCellarMaximum();
                            break;
                        default:
                            comparable = campaigns[i].getRoomAverage();
                            break;
                        }
                        if (comparable == x) {
                            result = campaigns[i];
                        }
                    }
                    if (result != null) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ie) {
                            ie.printStackTrace();
                        }
                        JTabbedPane tab = (JTabbedPane) getParent();
                        tab.remove(tab.getComponentAt(4));
                        JPanel jpanelTesting = new OMPanelTesting(simulation, result);
                        tab.add(jpanelTesting, "Analyse", 4);
                        tab.updateUI();
                        tab.setSelectedIndex(4);
                    }
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }

            @Override
            public void chartMouseMoved(ChartMouseEvent ignore) {
            }
        });
    }
    JPanel distPanel = (JPanel) chartPanel;
    return distPanel;
}