Package clips.dicom.dicom_emc

Source Code of clips.dicom.dicom_emc.DialogSelectDicomObjects

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

/*
* DialogSelectDicomObjects.java
*
* Created on 12.09.2009, 9:43:46
*/

package clips.dicom.dicom_emc;

import cli_fmw.main.ClipsException;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.doctor.checkup.CheckupDICOMLocal;
import clips.delegate.doctor.checkup.CheckupLocal;
import clips.dicom.dicombaseclass.DICOMChekup;
import clips.dicom.dicomdataimpl.DicomFileInput;
import clips.dicom.model.Agregator;
import clips.dicom.model.AgregatorItem;
import clips.dicom.model.AgregatorListener;
import clips.dicom.model.ItemEvent;
import clips.dicom.panels.DicomBasePanel;
import clips.main.ClipsConfig;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author petr
*/
public class DialogSelectDicomObjects extends ModalDialog implements AgregatorListener {
    private ArrayList<AgregatorItem> agregItems = new ArrayList<AgregatorItem>();
    private DefaultListModel modelAgreg = new DefaultListModel();
//    private DICOMView pnlDICOMView = new DICOMView();
    private DicomBasePanel pnlDICOMView;
    private List<AgregatorItem> agregatorItems = new ArrayList<AgregatorItem>();
   
  /** Creates new form PanelDicomServer
   * @param container
   * @param checkup
   * @throws ClipsException `
   */
    public DialogSelectDicomObjects(Frame frame) throws ClipsException{
        super(frame, "Объекты DICOM", null);
        initComponents();
        pnlDICOMView = new DicomBasePanel(true);
        Agregator.addListener(this);
        refreshItemListAgregator();
//        refreshItemListCheckup();
        pnlPreview.add(pnlDICOMView, BorderLayout.CENTER);
        StateSaver.attachTo(this);
    }

    private void refreshItemListAgregator() {
        agregItems = Agregator.getItems();
        //Синхронизация итемов
        for (int i = 0; i < agregItems.size(); i++) {
            AgregatorItem agregatorItem = agregItems.get(i);
            boolean founded = false;
            for (int j = 0; j < modelAgreg.getSize(); j++) {
                AgregatorItem agregatorItem1 = (AgregatorItem) modelAgreg.getElementAt(j);
                if (agregatorItem1 == agregatorItem) {
                    founded = true;
                }
            }

            if (!founded) {
                modelAgreg.addElement(agregatorItem);
            }
        }
        for (int i = modelAgreg.getSize() - 1; i >= 0; i--) {
            AgregatorItem agregatorItem1 = (AgregatorItem) modelAgreg.get(i);
            boolean founded = false;
            for (int j = 0; j < agregItems.size(); j++) {
                AgregatorItem agregatorItem = agregItems.get(j);
                if (agregatorItem == agregatorItem1) {
                    founded = true;
                }
            }
            if (!founded) {
                modelAgreg.removeElementAt(i);
            }
        }
        lstAgregator.setModel(modelAgreg);
    ubpdateButtons();
    }

    /** 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() {

        jPanel1 = new javax.swing.JPanel();
        btOK = new javax.swing.JButton();
        btCancel = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        pnlPreview = new javax.swing.JPanel();
        lblTitle = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstAgregator = new javax.swing.JList();
        jPanel2 = new javax.swing.JPanel();
        addFile = new javax.swing.JButton();
        btRemove = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(600, 400));

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        btOK.setText("Принять");
        btOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOKActionPerformed(evt);
            }
        });
        jPanel1.add(btOK);

        btCancel.setText("Отмена");
        btCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelActionPerformed(evt);
            }
        });
        jPanel1.add(btCancel);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        pnlPreview.setLayout(new java.awt.BorderLayout());

        lblTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblTitle.setText(" ");
        pnlPreview.add(lblTitle, java.awt.BorderLayout.SOUTH);

        jSplitPane1.setRightComponent(pnlPreview);

        jPanel3.setLayout(new java.awt.BorderLayout());

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder("С оборудования"));

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

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

        addFile.setText("из файла...");
        addFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addFileActionPerformed(evt);
            }
        });
        jPanel2.add(addFile);

        btRemove.setText("удалить");
        btRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoveActionPerformed(evt);
            }
        });
        jPanel2.add(btRemove);

        jPanel3.add(jPanel2, java.awt.BorderLayout.PAGE_END);

        jSplitPane1.setLeftComponent(jPanel3);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

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

    private void addFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFileActionPerformed
        JFileChooser      dlg = new JFileChooser();
        ClipsConfig        cfg = ClipsConfig.getInstance();
        dlg.setCurrentDirectory(cfg.getLastOpenDialogPath());
        FileNameExtensionFilter    filter = new FileNameExtensionFilter("Файлы DICOM(*.dcm)", new String[]{"dcm", "dicm", "dicom"});
        dlg.addChoosableFileFilter(filter);
        dlg.setMultiSelectionEnabled(true);
        int          res = dlg.showOpenDialog(this);
        if (res == JFileChooser.APPROVE_OPTION){
            cfg.setLastOpenDialogPath(dlg.getCurrentDirectory());
            File[]        files = dlg.getSelectedFiles();
            if (files == null) {
                return;
            }
            DicomFileInput      input = new DicomFileInput();
            for (File file : files) {
                try {
                    ArrayList<DICOMChekup>        obj = input.decode(file, true);
                    Agregator.onAccept(obj);
                } catch (Exception ex) {
                    MessageBox.showExceptionOnly(new ClipsException("При открытии файла \"" + file + "\" произошла ошибка, возможно файл поврежден или имеет низвестный формат", ex));
                    input = new DicomFileInput();
                }
            }
        }
}//GEN-LAST:event_addFileActionPerformed

    private void lstAgregatorValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstAgregatorValueChanged
        int sel = lstAgregator.getLeadSelectionIndex();
        int[] selectedIndices = lstAgregator.getSelectedIndices();
        boolean focusOnSelectedItem = false;
        for (int i = 0; i < selectedIndices.length && !focusOnSelectedItem; i++) {
            focusOnSelectedItem = selectedIndices[i] == sel;
        }
        if (focusOnSelectedItem && lstAgregator.getModel().getSize() > 0 && lstAgregator.getModel().getElementAt(sel) instanceof AgregatorItem){
            AgregatorItem item = (AgregatorItem) lstAgregator.getModel().getElementAt(sel);
            pnlDICOMView.setAgregator(item);
            lblTitle.setText(item.getName());
        }else{
            pnlDICOMView.setAgregator(null);
            lblTitle.setText("");
        }
    }//GEN-LAST:event_lstAgregatorValueChanged

    private void btRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveActionPerformed
        for (Object object : lstAgregator.getSelectedValues()) {
            Agregator.removeItem((AgregatorItem) object);
        }
    }//GEN-LAST:event_btRemoveActionPerformed

    private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
        setDlgResult(ModalDialog.DLG_CANCEL);
        this.dispose();
    }//GEN-LAST:event_btCancelActionPerformed

    private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
        setDlgResult(ModalDialog.DLG_OK);
        for (Object object : lstAgregator.getSelectedValues()) {
            agregatorItems.add((AgregatorItem) object);
        }
        this.dispose();
    }//GEN-LAST:event_btOKActionPerformed

    public List<AgregatorItem> getItems(){
        return agregatorItems;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addFile;
    private javax.swing.JButton btCancel;
    private javax.swing.JButton btOK;
    private javax.swing.JButton btRemove;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JList lstAgregator;
    private javax.swing.JPanel pnlPreview;
    // End of variables declaration//GEN-END:variables

    private void ubpdateButtons() {
       
    }

    @Override
    public void agregatorItemsChanged(ItemEvent e) {
        refreshItemListAgregator();
    }

}
TOP

Related Classes of clips.dicom.dicom_emc.DialogSelectDicomObjects

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.