Package caterpillarssa

Source Code of caterpillarssa.GroupingDialog$CancelListener

package caterpillarssa;

import Jama.Matrix;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;

/**
*
* @author Васькин Александр
*/
public class GroupingDialog extends javax.swing.JDialog implements Dialog {

    private Dimension frameSize;
    private UIManager.LookAndFeelInfo l[];
    private SSAData data;
    private JDesktopPane desctop;
    private DefaultListModel unselectedModel;
    private DefaultListModel groupsModel;
    private JInternalFrame reconstructionFrame;
    public GroupingDialog(java.awt.Frame parent, boolean modal, SSAData data, JDesktopPane desctop) {
        super(parent, modal);
        initComponents();
        this.data = data;
        this.desctop = desctop;
        centered();
        unselectedModel = new DefaultListModel();
        groupsModel = new DefaultListModel();
        for (int i = 0; i < data.getPercentList().size(); i++) {
            unselectedModel.addElement(new UnselectListObject(i, data.getPercentList().get(i)));
        }
        unselectedList.setModel(unselectedModel);
        unselectedList.setCellRenderer(new CellRenderer());
        cancelButton.addActionListener(new CancelListener());
    }

    public void centered() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frameSize = this.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        this.setLocation((screenSize.width - frameSize.width) / 2,
                (screenSize.height - frameSize.height) / 2);
    }

    private class CancelListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            GroupingDialog.this.setVisible(false);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        groupList = new javax.swing.JList();
        unselectedPane = new javax.swing.JPanel();
        unselectedScroll = new javax.swing.JScrollPane();
        unselectedList = new javax.swing.JList();
        addGroup = new javax.swing.JButton();
        removeGroup = new javax.swing.JButton();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        jButton2.setText("<<");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Параметры группировки");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Группы"));

        jScrollPane2.setViewportView(groupList);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
        );

        unselectedPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Свободные"));
        unselectedPane.setPreferredSize(new java.awt.Dimension(170, 189));

        unselectedScroll.setViewportView(unselectedList);

        javax.swing.GroupLayout unselectedPaneLayout = new javax.swing.GroupLayout(unselectedPane);
        unselectedPane.setLayout(unselectedPaneLayout);
        unselectedPaneLayout.setHorizontalGroup(
            unselectedPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(unselectedPaneLayout.createSequentialGroup()
                .addComponent(unselectedScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        unselectedPaneLayout.setVerticalGroup(
            unselectedPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(unselectedScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        addGroup.setText("Добавить группу");
        addGroup.setActionCommand("");
        addGroup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addGroupActionPerformed(evt);
            }
        });

        removeGroup.setText("Удалить группу");
        removeGroup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeGroupActionPerformed(evt);
            }
        });

        okButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/tick.png"))); // NOI18N
        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/cancel.png"))); // NOI18N
        cancelButton.setText("Отмена");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(unselectedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(removeGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(addGroup, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(182, 182, 182)
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(addGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(removeGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(unselectedPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(okButton)
                            .addComponent(cancelButton))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        //восстановление временного ряда (группировка)
        SpectrumAnalysis.grouping(groupsModel, data);
        //восстановление временного ряда (диагональное усреднение)
        SpectrumAnalysis.diagonalAveraging(data);
        GroupingDialog.this.setVisible(false);
        if(reconstructionFrame != null) {
            reconstructionFrame.dispose();
        }
        List listSeries = new ArrayList();
        List<String> seriesTitle = new ArrayList<String>();
        listSeries.add(data.getTimeSeries());
        listSeries.add(data.getReconstructionList());
        seriesTitle.add("Исходный");
        seriesTitle.add("Восстановленный");
        ChartPanel reconstructionChart = XYChart.createChart(listSeries, "Исходный и восстановленный ряд", seriesTitle, "", true);
        final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        final XYPlot plot = reconstructionChart.getChart().getXYPlot();
        renderer.setSeriesShapesVisible(0, false);
        renderer.setSeriesShapesVisible(1, false);
        plot.setRenderer(renderer);
        reconstructionFrame = InternalFrame.createInternalFrame(reconstructionChart, "Исходный и восстановленный ряд");
        reconstructionFrame.setName("reconstruction");
        desctop.add(reconstructionFrame);
        FrameParams.setInternalFrameParams(reconstructionFrame, desctop, data);
        try {
            reconstructionFrame.setMaximum(true);
        } catch (PropertyVetoException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void addGroupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGroupActionPerformed
        List<Object> list = unselectedList.getSelectedValuesList();
        for (int i = 0; i < list.size(); i++) {
            unselectedModel.removeElement(list.get(i));
        }
        if (!list.isEmpty()) {
            groupsModel.addElement(new GroupListObject(list));
            groupList.setModel(groupsModel);
            groupList.setCellRenderer(new CellRenderer());
        }
    }//GEN-LAST:event_addGroupActionPerformed

    private void removeGroupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeGroupActionPerformed
        List<Object> list = groupList.getSelectedValuesList();
        for (int i = 0; i < list.size(); i++) {
            groupsModel.removeElement(list.get(i));
            GroupListObject obj = (GroupListObject) list.get(i);
            for (int j = 0; j < obj.getGroups().size(); j++) {
                //UnselectListObject unselect = (UnselectListObject)obj.getGroups().get(j);
                unselectedModel.addElement(obj.getGroups().get(j));
            }
        }
    }//GEN-LAST:event_removeGroupActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addGroup;
    private javax.swing.JButton cancelButton;
    private javax.swing.JList groupList;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton okButton;
    private javax.swing.JButton removeGroup;
    private javax.swing.JList unselectedList;
    private javax.swing.JPanel unselectedPane;
    private javax.swing.JScrollPane unselectedScroll;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of caterpillarssa.GroupingDialog$CancelListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.