Package clips.dicom.panels

Source Code of clips.dicom.panels.PanelDicomServer

/*
* PanelDicomServer.java
*
* Created on 23 Сентябрь 2008 г., 12:06
*/

package clips.dicom.panels;

import clips.delegate.doctor.checkup.CheckupDICOMLocal;
import clips.delegate.doctor.checkup.CheckupLocal;
import cli_fmw.delegate.DelegateLine2;
import clips.dicom.dicombaseclass.DICOMChekup;
import clips.dicom.dicombaseclass.DICOMException;
import clips.dicom.dicomdataimpl.DicomFileInput;
import clips.dicom.model.Agregator;
import clips.dicom.model.AgregatorItem;
import clips.dicom.model.AgregatorListener;
import clips.dicom.model.ChangeType;
import clips.dicom.model.ItemEvent;
import cli_fmw.main.ClipsException;
import cli_fmw.main.OpenCloseSensitive;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.utils.ConfigGui;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.main.ClipsConfig;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author  vip
*/
public class PanelDicomServer extends PageGeneric implements Persistentable, AgregatorListener, OpenCloseSensitive {
    DicomBasePanel innerPanel;
    ArrayList<AgregatorItem> agregItems = new ArrayList<AgregatorItem>();
    DefaultListModel modelAgreg = new DefaultListModel();
    DefaultListModel modelCDL = new DefaultListModel();
    CheckupLocal checkup;
    CheckupDICOMLocal currentCdl;

    public PanelDicomServer(PageContainer container) throws ClipsException {
        this(container, null);
    }
   
  /** Creates new form PanelDicomServer
   * @param container
   * @param checkup
   * @throws ClipsException `
   */
    private PanelDicomServer(PageContainer container, CheckupLocal checkup) throws ClipsException {
        super(container);
        initComponents();
        this.checkup = checkup;
        refreshItemListAgregator();
        refreshItemListCheckup();
   
        if (checkup == null) {
      panelLeft.add(pAgregatorItemList);
        }
    else {
      pSplitedPanel.add(pAgregatorItemList);
      panelLeft.add(spLeftSplit);
    }
    StateSaver.attachTo(this);
    }

    private void refreshItemListAgregator() {
        //Синхронизация итемов
        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);
            }
        }
        jListAgregator.setModel(modelAgreg);
    ubpdateButtons();
    }
   
    private void refreshItemListCheckup() {
        //Синхронизация итемов
        List<CheckupDICOMLocal> list = null;
        try {
            if (checkup == null) {
                list = new ArrayList<CheckupDICOMLocal>();
            } else {
                list = checkup.getChildren();
            }
            for (int i = 0; i < list.size(); i++) {
                CheckupDICOMLocal cdl = list.get(i);
                boolean founded = false;
                for (int j = 0; j < modelCDL.getSize(); j++) {
                    CheckupDICOMLocal cdl1 = (CheckupDICOMLocal) modelCDL.getElementAt(j);
                    if (cdl1 == cdl) {
                        founded = true;
                    }
                }
                if (!founded) {
                    modelCDL.addElement(cdl);
                }
            }
            for (int i = modelCDL.getSize() - 1; i >= 0; i--) {
                CheckupDICOMLocal cdl1 = (CheckupDICOMLocal) modelCDL.get(i);
                boolean founded = false;
                for (int j = 0; j < list.size(); j++) {
                    CheckupDICOMLocal cdl = list.get(j);
                    if (cdl == cdl1) {
                        founded = true;
                    }
                }
                if (!founded) {
                    modelCDL.removeElementAt(i);
                }
            }
            jListCheckup.setModel(modelCDL);
      ubpdateButtons();
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }

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

        spLeftSplit = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        btAdd = new javax.swing.JButton();
        btRemove = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListCheckup = new javax.swing.JList();
        pSplitedPanel = new javax.swing.JPanel();
        pAgregatorItemList = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        addFile = new javax.swing.JButton();
        btRemoveAgregator = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListAgregator = new javax.swing.JList();
        jSplitPane1 = new javax.swing.JSplitPane();
        panelLeft = new javax.swing.JPanel();
        panelRight = new javax.swing.JPanel();

        spLeftSplit.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        spLeftSplit.setResizeWeight(0.5);

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

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

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

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(btAdd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btRemove)
                .addGap(106, 106, 106))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btAdd, btRemove});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btAdd)
                    .addComponent(btRemove)))
        );

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

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("В осмотре"));

        jListCheckup.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListCheckupValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jListCheckup);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        spLeftSplit.setTopComponent(jPanel1);

        pSplitedPanel.setLayout(new javax.swing.BoxLayout(pSplitedPanel, javax.swing.BoxLayout.LINE_AXIS));
        spLeftSplit.setRightComponent(pSplitedPanel);

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

        addFile.setText("Загрузить из файла");
        addFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addFileActionPerformed(evt);
            }
        });

        btRemoveAgregator.setText(" Удалить ");
        btRemoveAgregator.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRemoveAgregatorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(addFile)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btRemoveAgregator)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {addFile, btRemoveAgregator});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(addFile)
                .addComponent(btRemoveAgregator))
        );

        pAgregatorItemList.add(jPanel4, java.awt.BorderLayout.SOUTH);

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

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

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

        jSplitPane1.setDividerLocation(300);

        panelLeft.setLayout(new javax.swing.BoxLayout(panelLeft, javax.swing.BoxLayout.LINE_AXIS));
        jSplitPane1.setLeftComponent(panelLeft);

        panelRight.setLayout(new javax.swing.BoxLayout(panelRight, javax.swing.BoxLayout.LINE_AXIS));
        jSplitPane1.setRightComponent(panelRight);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 687, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void jListCheckupValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListCheckupValueChanged
        try {
            if (currentCdl != null) {
                currentCdl.removeContentStateListener(getContainer());
            }
            if (innerPanel == null) {
                innerPanel = new DicomBasePanel();
                panelRight.add(innerPanel);
            }
            currentCdl = (CheckupDICOMLocal) jListCheckup.getSelectedValue();
            if (currentCdl != null) {
                currentCdl.addContentStateListener(getContainer());
                innerPanel.setAgregator(currentCdl.getObjects());
            }
            ubpdateButtons();
            panelRight.revalidate();//GEN-LAST:event_jListCheckupValueChanged
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
}

private void jListAgregatorValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListAgregatorValueChanged
    if (jListAgregator.getSelectedValue() != null && jListAgregator.getSelectedValue() instanceof AgregatorItem) {
        if (innerPanel == null) {
            innerPanel = new DicomBasePanel();
            panelRight.add(innerPanel);
        }
        innerPanel.setAgregator((AgregatorItem) jListAgregator.getSelectedValue());
         panelRight.revalidate();
    ubpdateButtons();
    } else {
        if (innerPanel == null) {
            innerPanel = new DicomBasePanel();
        }
        innerPanel.setAgregator(null);
    }
}//GEN-LAST:event_jListAgregatorValueChanged

private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
    try {
        AgregatorItem item = (AgregatorItem) jListAgregator.getSelectedValue();
        if (item != null) {
            CheckupDICOMLocal cdl = new CheckupDICOMLocal(checkup, item);
            Agregator.removeItem(item);
        }
        //refreshItemListAgregator(); пнется листенером
        refreshItemListCheckup();
    getContainer().contentStateChanged();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }

}//GEN-LAST:event_btAddActionPerformed

private void btRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveActionPerformed
    try {
        CheckupDICOMLocal cdl = (CheckupDICOMLocal) jListCheckup.getSelectedValue();
        if (cdl != null) {
            AgregatorItem item = cdl.getObjects();
            Agregator.addItem(item);
      if (cdl.isNewlyCreated()) {
                cdl.afterRemove();
            } else {
                cdl.remove();
            }
        }
        //refreshItemListAgregator(); пнется листенером
        refreshItemListCheckup();
     getContainer().contentStateChanged();
   } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_btRemoveActionPerformed

private void btRemoveAgregatorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoveAgregatorActionPerformed
    AgregatorItem cdl = (AgregatorItem) jListAgregator.getSelectedValue();
    if (cdl != null){
      if (MessageBox.showConfirmYesNo(MessageBox.C_DEL_OBJECT) == MessageBox.ANSWER_YES){
        Agregator.removeItem(cdl);
        Agregator.finallyRemoveItem(cdl);
      }
    }
}//GEN-LAST:event_btRemoveAgregatorActionPerformed

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

    @Override
    public String getPageTitle() {
        return "DICOM";
    }

    @Override
    public DelegateLine2 getDelegate() {
        return checkup;
    }

    @Override
    public void agregatorItemsChanged(ItemEvent e) {
         agregItems = Agregator.getItems();
         refreshItemListAgregator();
         if (e != null && e.getChangeType() == ChangeType.modifedItems){
             jListAgregator.revalidate();
         }
    }

    @Override
    public void beforeOpen() {
        Agregator.addListener(this);
        agregatorItemsChanged(new ItemEvent(this, ChangeType.addedItems));
    }

    @Override
    public void beforeClose() {
        if (innerPanel != null) {
      innerPanel.dispose();
    }
        Agregator.removeListener(this);
    }

   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addFile;
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btRemove;
    private javax.swing.JButton btRemoveAgregator;
    private javax.swing.JList jListAgregator;
    private javax.swing.JList jListCheckup;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JPanel pAgregatorItemList;
    private javax.swing.JPanel pSplitedPanel;
    private javax.swing.JPanel panelLeft;
    private javax.swing.JPanel panelRight;
    private javax.swing.JSplitPane spLeftSplit;
    // End of variables declaration//GEN-END:variables

    @Override
    public boolean isDirty() {
    if (checkup == null) {
      return false;
        }
    else {
      try {
        for (CheckupDICOMLocal delegate : checkup.getChildren()) {
          if (delegate.isDirty()) {
            return true;
          }
        }
        return false;
      } catch (ClipsException ex) {
        MessageBox.showException(ex);
        return true;
      }
        }
    }

 
  void ubpdateButtons(){
    btAdd.setEnabled(jListAgregator.getSelectedValue() != null);
    btRemoveAgregator.setEnabled(jListAgregator.getSelectedValue() != null);
    btRemove.setEnabled(jListCheckup.getSelectedValue() != null);
  }
 
    @Override
    public void save() throws ClipsException {
    if (checkup != null){
      for (CheckupDICOMLocal delegate : checkup.getChildren()){
        delegate.save1();
      }
    }
    fireContainerEventStateChanged();
    }

    @Override
    public void restore() {
    if (checkup != null){
            try{
                ArrayList<CheckupDICOMLocal> list = new ArrayList<CheckupDICOMLocal>(checkup.getChildren());
                for (CheckupDICOMLocal delegate : list) {
                    delegate.restore();
                }
                refreshItemListCheckup();
                fireContainerEventStateChanged();
        if (jListCheckup.isFocusOwner()) {
          jListCheckupValueChanged(null);
        }
        else {
          jListAgregatorValueChanged(null);
        }
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
    }
    }
}
TOP

Related Classes of clips.dicom.panels.PanelDicomServer

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.