Package reportgen.gui.genepanel.formatpanel.dlg

Source Code of reportgen.gui.genepanel.formatpanel.dlg.ChildRangePanel

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* ChildRangePanel.java
*
* Created on 23.06.2009, 10:54:26
*/

package reportgen.gui.genepanel.formatpanel.dlg;

import java.awt.Window;
import javax.swing.AbstractListModel;
import javax.swing.JOptionPane;
import reportgen.utils.ReportException;
import reportgen.ren.report.extendedformat.range.ColRowRange;
import reportgen.ren.report.extendedformat.range.ColRowRangeList;
import reportgen.ren.report.extendedformat.range.RangeContext;
import reportgen.ren.report.extendedformat.range.cross.ColRowRangeCrossReport;
import reportgen.ren.report.extendedformat.range.generic.ColRowRangeGeneric;
import reportgen.ren.report.extendedformat.range.group.ColRowRangeGroup;
import reportgen.utils.Message;

/**
*
* @author axe
*/
public class ChildRangePanel extends javax.swing.JPanel {

    public final static String GENERIC = "Обычный диапазон";
    public final static String GROUP = "Группировка";
    public final static String CROSS = "Кросс-отчет";

    private final ColRowRangeList list;
    private final Window parent;
    private final TableListener tableListener;

    public ChildRangePanel(ColRowRangeList aList, Window parent, TableListener tableListener) {
        initComponents();
        this.list = aList;
        this.parent = parent;
        this.tableListener = tableListener;

        mainList.setModel(new AbstractListModel() {
            @Override
            public int getSize() {
                return list.size();
            }
            @Override
            public Object getElementAt(int index) {
                return list.get(index);
            }
        });
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rowsPanel = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        addBtn = new javax.swing.JButton();
        delBtn = new javax.swing.JButton();
        upBtn = new javax.swing.JButton();
        downBtn = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        mainList = new javax.swing.JList();

        rowsPanel.setLayout(new java.awt.BorderLayout(5, 5));

        jPanel6.setLayout(new java.awt.GridLayout(1, 0));

        addBtn.setText("Добавить");
        addBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addBtnActionPerformed(evt);
            }
        });
        jPanel6.add(addBtn);

        delBtn.setText("Удалить");
        delBtn.setEnabled(false);
        delBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delBtnActionPerformed(evt);
            }
        });
        jPanel6.add(delBtn);

        upBtn.setText("Вверх");
        upBtn.setEnabled(false);
        upBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                upBtnActionPerformed(evt);
            }
        });
        jPanel6.add(upBtn);

        downBtn.setText("Вниз");
        downBtn.setEnabled(false);
        downBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downBtnActionPerformed(evt);
            }
        });
        jPanel6.add(downBtn);

        rowsPanel.add(jPanel6, java.awt.BorderLayout.SOUTH);

        mainList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                mainListValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(mainList);

        rowsPanel.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 634, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(rowsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 610, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(rowsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                    .addContainerGap()))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void mainListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_mainListValueChanged
        boolean selected = mainList.getSelectedIndex() != -1;
        delBtn.setEnabled(selected);
        downBtn.setEnabled(selected);
        upBtn.setEnabled(selected);
    }//GEN-LAST:event_mainListValueChanged

    private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed
        Object[] options = new Object[] {
            GENERIC, GROUP, CROSS
        };

        Object type = JOptionPane.showInputDialog(parent, "Тип диапазона",
                "Выберите тип диапазона", JOptionPane.QUESTION_MESSAGE, null, options, null);
        if(type == null) {
            return;
        }

        String newName = JOptionPane.showInputDialog(
                parent, "Название ", "Вставка нового элемента", JOptionPane.QUESTION_MESSAGE);
        if(newName == null) {
            return;
        }

        ColRowRange range = null;
        if(type == GENERIC) {
            range = new ColRowRangeGeneric(newName, list.getContext());
        } else if(type == GROUP) {
            range = new ColRowRangeGroup(newName, list.getContext());
        } else if(type == CROSS) {
            range = new ColRowRangeCrossReport(newName, list.getContext());
        } else {
            return;
        }
        list.add(range);
        mainList.updateUI();
        mainList.setSelectedIndex(list.size() - 1);
        tableListener.dataChanged();
    }//GEN-LAST:event_addBtnActionPerformed

    private void delBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delBtnActionPerformed
        int selected = mainList.getSelectedIndex();
        if(selected != -1) {
            try {
                list.remove(selected);
                mainList.updateUI();
                tableListener.dataChanged();
                if(selected < list.size()) {
                    mainList.setSelectedIndex(list.size()-1);
                }
            } catch (ReportException ex) {
                Message.error(this, ex);
            }
        }
    }//GEN-LAST:event_delBtnActionPerformed

    private void upBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upBtnActionPerformed
        int selected = mainList.getSelectedIndex();
        if(selected == -1) {
            return;
        }
       
        int pos = list.moveUp(selected);
        mainList.setSelectedIndex(pos);
        mainList.updateUI();
        tableListener.dataChanged();
}//GEN-LAST:event_upBtnActionPerformed

    private void downBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downBtnActionPerformed
        int selected = mainList.getSelectedIndex();
        if(selected != -1) {
            int pos = list.moveDown(selected);
            mainList.setSelectedIndex(pos);
            mainList.updateUI();
            tableListener.dataChanged();
        }
    }//GEN-LAST:event_downBtnActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addBtn;
    private javax.swing.JButton delBtn;
    private javax.swing.JButton downBtn;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList mainList;
    private javax.swing.JPanel rowsPanel;
    private javax.swing.JButton upBtn;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of reportgen.gui.genepanel.formatpanel.dlg.ChildRangePanel

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.