@Override
    public void acceptButtonActionPerformed() {

        String selectedNames[] = ds.getSelectedData();

        String[] v = predLevel.getText().split(" ");

        double [] confidence = new double[v.length];

        for(int i=0;i<v.length;i++) confidence[i] = Double.parseDouble(v[i]);

        if(selectedNames.length == 3){// || selectedNames.length == 4){
            DataFrame df = mainApplication.getActiveDataFrame();
            boolean[] selection = getValidComposition(df, selectedNames);
            int [] mapping = df.getMapingToData(selectedNames, selection);
            double[][] data = df.getNumericalData(selectedNames, mapping);         

            String groupedBy = ds.getSelectedGroup();
            int[] groups = null;
            String[] categories = null;


            CoDaPackMain.outputPanel.addOutput(
                    new OutputPlotHeader("Confidence region", selectedNames));

            if(groupedBy != null){
                /*
                 * Obtaining the groups and the categories for non lost data
                 */
                groups  = coda.Utils.reduceData(df.getDefinedGroup(groupedBy), selection);
                categories =  coda.Utils.getCategories(df.getCategoricalData(groupedBy), selection);

            }            
            if(selectedNames.length == 3){

                TernaryPlot2dDisplay display = new TernaryPlot2dDisplay(selectedNames);

                double definedGrid[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
                Ternary2dObject gridObject = new Ternary2dGridObject(display, definedGrid);
                display.addCoDaObject(gridObject);

                double xdata[][] = null;

                int limit = categories == null ? 1 : categories.length;
                for(int gr=0;gr<limit;gr++){

                    if(categories == null) xdata = data;
                    else xdata = coda.Utils.reduceData(data, groups, gr);

                    double transData[][] = new Matrix(xdata).transpose().getArray();
                    Ternary2dObject dataObject = new Ternary2dDataObject(display, transData);
                    dataObject.setColor(new coda.plot.CoDaDisplayConfiguration().getColor("data",gr));
                    display.addCoDaObject(dataObject);

                    for(int i=0;i<confidence.length;i++){
                        Ternary2dObject curveObject = new Ternary2dCurveObject(display,
                                PlotUtils.confidenceRegion2d(xdata, confidence[i]));
                        curveObject.setColor(Color.red);//coda.plot.CoDaDisplayConfiguration.getColor("data",gr));
                        display.addCoDaObject(curveObject);
                    }
                }
                TernaryPlot2dWindow plot = new TernaryPlot2dWindow(df, display, "Center Confidence Region");
                plot.setCenter(CoDaStats.center(data));
                plot.setVisible(true);
            }else{// selectedNames.length == 4
                TernaryPlot3dDisplay display = new TernaryPlot3dDisplay(selectedNames);


                double transData[][] = new Matrix(data).transpose().getArray();
                Ternary3dObject dataObject = new Ternary3dDataObject(display, transData);
                dataObject.setColor(new Color(70, 70, 200));
                display.addCoDaObject(dataObject);

                for(int i=0;i<confidence.length;i++){
                    Ternary3dObject ellipsoid3 = new Ternary3dSurfaceObject(display,
                            PlotUtils.predictiveRegion3d(transData, confidence[i]));
                    ellipsoid3.setColor(new Color(230, 200, 200));
                    display.addCoDaObject(ellipsoid3);
                    /*
                    Ternary3dObject curveObject = new Ternary2dCurveObject(display,
                            PlotUtils.predictiveRegion2d(data, confidence[i]));
                    curveObject.setColor(Color.black);
                    display.addCoDaObject(curveObject);
                     * */
                }


                /*
                TernaryPlot3dBuilder builder = new TernaryPlot3dBuilder(selectedNames, data);
                builder.mapping(mapping);

                if(groupedBy != null){
                    builder.groups(coda.Utils.reduceData(
                            df.getDefinedGroup(groupedBy),
                            selection), coda.Utils.getCategories(
                            df.getCategoricalData(groupedBy),selection));
                }
                TernaryPlot3dDisplay display = builder.build();
                plot = new TernaryPlot3dWindow(display, "Ternary Plot 3d");
                 * */

            }
            
            setVisible(false);
        }else{
            JOptionPane.showMessageDialog(this, "<html>Select <b>three</b> variables</html>");
        }
        
    }