001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.rGUI.client.windows;
020
021import java.awt.Image;
022import java.awt.Toolkit;
023import java.rmi.RemoteException;
024import java.util.ArrayList;
025import java.util.Hashtable;
026import java.util.Iterator;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029import org.slf4j.Logger;
030import org.slf4j.LoggerFactory;
031
032import javax.swing.DefaultListModel;
033import javax.swing.JOptionPane;
034import javax.swing.tree.DefaultMutableTreeNode;
035import javax.swing.tree.TreePath;
036
037import pt.ua.dicoogle.Main;
038import pt.ua.dicoogle.sdk.datastructs.MoveDestination;
039import pt.ua.dicoogle.rGUI.client.UserRefs;
040import pt.ua.dicoogle.rGUI.interfaces.controllers.IDicomSend;
041
042/**
043 *
044 * @author Luís A. Bastião Silva <bastiao@ua.pt>
045 * @author Samuel Campos <samuelcampos@ua.pt>
046 */
047@Deprecated
048public class DicomSend extends javax.swing.JFrame {
049
050    private ArrayList<String> filePaths;
051    private ArrayList<MoveDestination> dest;
052    private Hashtable<String, MoveDestination> destHash = new Hashtable<String, MoveDestination>();
053
054    private IDicomSend dmSend;
055
056    /** Creates new form DicomSend */
057    public DicomSend(ArrayList<String> filePaths) {
058        initComponents();
059
060        Image image = Toolkit.getDefaultToolkit().getImage(Thread.currentThread().getContextClassLoader().getResource("trayicon.gif"));
061        this.setIconImage(image);
062
063        this.filePaths = filePaths;
064
065        dmSend = UserRefs.getInstance().getDicomSend();
066        
067        jLabel1.setText(filePaths.size() + " DICOM Files to be send:");
068
069        fillStorageServerTree();
070
071        if (filePaths != null)
072            fillList();
073    }
074
075    /* Fill the Storage Server Tree */
076    private void fillStorageServerTree() {
077        try {
078            /* Uses the Storage Server Destinations of Query/Retrive System*/
079            dest = dmSend.getDestinations();
080
081            DefaultMutableTreeNode treeNodeRoot = new DefaultMutableTreeNode("Storage Servers");
082
083            if (dest.size() != 0) {
084                Iterator<MoveDestination> itDest = dest.iterator();
085
086                MoveDestination m;
087                DefaultMutableTreeNode treeNode;
088
089                while (itDest.hasNext()) {
090                    m = itDest.next();
091                    destHash.put(m.getAETitle(), m);
092
093                    treeNode = new DefaultMutableTreeNode(m.getAETitle());
094
095                    treeNode.add(new DefaultMutableTreeNode("AETitle: " + m.getAETitle()));
096                    treeNode.add(new DefaultMutableTreeNode("IP: " + m.getIpAddrs()));
097                    treeNode.add(new DefaultMutableTreeNode("Port: " + m.getPort()));
098                    
099                    treeNodeRoot.add(treeNode);
100                }
101            }
102
103            jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNodeRoot));
104        } catch (RemoteException ex) {
105            LoggerFactory.getLogger(DicomSend.class).error(ex.getMessage(), ex);
106        }
107
108    }
109
110    /** Fill the Objects to Send Tree with patients, studies, series and images */
111    private void fillList() {
112        DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode("root");
113
114        DefaultListModel model = (DefaultListModel) jListFiles.getModel();
115
116        Iterator<String> it = filePaths.iterator();
117
118        while(it.hasNext())
119            model.addElement(it.next());
120
121        jListFiles.setModel(model);
122    }
123
124    /**
125     * @return the selcted Server to move data
126     */
127    private MoveDestination getSelectedDestination() {
128        TreePath path = jTree1.getSelectionPath();
129
130        if (path != null && path.getPathCount() > 1) {
131            return destHash.get(path.getPathComponent(1).toString());
132        }
133
134        return null;
135    }
136
137    /*
138    private ArrayList<String> getAllImages() {
139        if (dimGen == null) {
140            return null;
141        }
142
143        ArrayList<String> images = new ArrayList<String>();
144
145        Iterator<Patient> it = dimGen.getPatients().iterator();
146
147        while (it.hasNext()) {
148            Patient patient = it.next();
149
150            Iterator<Study> itStudy = patient.getStudies().iterator();
151
152            while (itStudy.hasNext()) {
153                Study study = itStudy.next();
154
155                Iterator<Serie> itSerie = study.getSeries().iterator();
156
157                while (itSerie.hasNext()) {
158                    Serie serie = itSerie.next();
159
160                    images.addAll(serie.getImageList());
161                }
162            }
163        }
164
165        return images;
166    }
167     *
168     */
169
170    /** This method is called from within the constructor to
171     * initialize the form.
172     * WARNING: Do NOT modify this code. The content of this method is
173     * always regenerated by the Form Editor.
174     */
175    @SuppressWarnings("unchecked")
176    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
177    private void initComponents() {
178
179        jPanelVBox = new javax.swing.JPanel();
180        jPanelSenderBox = new javax.swing.JPanel();
181        jPanelfields = new javax.swing.JPanel();
182        jLabelAETitle = new javax.swing.JLabel();
183        jTextFieldAETitle = new javax.swing.JTextField();
184        jLabelIP = new javax.swing.JLabel();
185        jTextFieldIP = new javax.swing.JTextField();
186        jLabelPort = new javax.swing.JLabel();
187        jTextFieldPort = new javax.swing.JTextField();
188        jScrollPane2 = new javax.swing.JScrollPane();
189        jTree1 = new javax.swing.JTree();
190        jLabel1 = new javax.swing.JLabel();
191        jPanelDICOMObjects = new javax.swing.JPanel();
192        jPanelButtons = new javax.swing.JPanel();
193        jScrollPane1 = new javax.swing.JScrollPane();
194        DefaultListModel model = new DefaultListModel();
195        jListFiles = new javax.swing.JList(model);
196        jButtonSend = new javax.swing.JButton();
197
198        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
199        setTitle("Send");
200        setResizable(false);
201
202        jPanelVBox.setLayout(new javax.swing.BoxLayout(jPanelVBox, javax.swing.BoxLayout.PAGE_AXIS));
203
204        jPanelfields.setLayout(new java.awt.GridLayout(3, 2));
205
206        jLabelAETitle.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
207        jLabelAETitle.setText("AETitle");
208        jPanelfields.add(jLabelAETitle);
209
210        jTextFieldAETitle.setEditable(false);
211        jPanelfields.add(jTextFieldAETitle);
212
213        jLabelIP.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
214        jLabelIP.setText("IP:");
215        jPanelfields.add(jLabelIP);
216
217        jTextFieldIP.setEditable(false);
218        jPanelfields.add(jTextFieldIP);
219
220        jLabelPort.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
221        jLabelPort.setText("Port:");
222        jPanelfields.add(jLabelPort);
223
224        jTextFieldPort.setEditable(false);
225        jPanelfields.add(jTextFieldPort);
226
227        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
228        jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
229        jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
230            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
231                jTree1ValueChanged(evt);
232            }
233        });
234        jScrollPane2.setViewportView(jTree1);
235
236        jLabel1.setText("DICOM Files to be send:");
237
238        javax.swing.GroupLayout jPanelSenderBoxLayout = new javax.swing.GroupLayout(jPanelSenderBox);
239        jPanelSenderBox.setLayout(jPanelSenderBoxLayout);
240        jPanelSenderBoxLayout.setHorizontalGroup(
241            jPanelSenderBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242            .addGroup(jPanelSenderBoxLayout.createSequentialGroup()
243                .addGroup(jPanelSenderBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244                    .addGroup(jPanelSenderBoxLayout.createSequentialGroup()
245                        .addContainerGap()
246                        .addComponent(jPanelfields, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
247                    .addComponent(jLabel1))
248                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
249                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
250                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
251        );
252        jPanelSenderBoxLayout.setVerticalGroup(
253            jPanelSenderBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
254            .addGroup(jPanelSenderBoxLayout.createSequentialGroup()
255                .addComponent(jPanelfields, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
256                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
257                .addComponent(jLabel1))
258            .addGroup(jPanelSenderBoxLayout.createSequentialGroup()
259                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
260                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
261        );
262
263        jPanelVBox.add(jPanelSenderBox);
264
265        jPanelDICOMObjects.setLayout(new javax.swing.BoxLayout(jPanelDICOMObjects, javax.swing.BoxLayout.Y_AXIS));
266        jPanelVBox.add(jPanelDICOMObjects);
267
268        jPanelButtons.setLayout(new javax.swing.BoxLayout(jPanelButtons, javax.swing.BoxLayout.LINE_AXIS));
269        jPanelVBox.add(jPanelButtons);
270
271        jScrollPane1.setViewportView(jListFiles);
272
273        jPanelVBox.add(jScrollPane1);
274
275        jButtonSend.setText("Send");
276        jButtonSend.addActionListener(new java.awt.event.ActionListener() {
277            public void actionPerformed(java.awt.event.ActionEvent evt) {
278                jButtonSendActionPerformed(evt);
279            }
280        });
281        jPanelVBox.add(jButtonSend);
282
283        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
284        getContentPane().setLayout(layout);
285        layout.setHorizontalGroup(
286            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
287            .addGroup(layout.createSequentialGroup()
288                .addContainerGap()
289                .addComponent(jPanelVBox, javax.swing.GroupLayout.PREFERRED_SIZE, 567, javax.swing.GroupLayout.PREFERRED_SIZE)
290                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
291        );
292        layout.setVerticalGroup(
293            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294            .addGroup(layout.createSequentialGroup()
295                .addGap(7, 7, 7)
296                .addComponent(jPanelVBox, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
297                .addContainerGap(24, Short.MAX_VALUE))
298        );
299
300        pack();
301    }// </editor-fold>//GEN-END:initComponents
302
303    private void jButtonSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSendActionPerformed
304        try {
305            MoveDestination destination = getSelectedDestination();
306
307            if (destination == null || filePaths.isEmpty()) {
308                JOptionPane.showMessageDialog(this, "You need to choose a destination.", "Destination", JOptionPane.INFORMATION_MESSAGE);
309                return;
310            }
311
312            if (dmSend.sendFiles(destination, filePaths))
313                JOptionPane.showMessageDialog(this, "Sending files to choosed destination.", "Sending files", JOptionPane.INFORMATION_MESSAGE);
314            else
315                JOptionPane.showMessageDialog(this, "Error sending files to choosed destination.", "Error sending files", JOptionPane.ERROR_MESSAGE);
316            
317        } catch (RemoteException ex) {
318            LoggerFactory.getLogger(DicomSend.class).error(ex.getMessage(), ex);
319        }
320    }//GEN-LAST:event_jButtonSendActionPerformed
321
322    private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTree1ValueChanged
323        MoveDestination tmp = getSelectedDestination();
324
325        if (tmp != null) {
326            jTextFieldAETitle.setText(tmp.getAETitle());
327            jTextFieldIP.setText(tmp.getIpAddrs());
328            jTextFieldPort.setText(String.valueOf(tmp.getPort()));
329        } else {
330            jTextFieldAETitle.setText("");
331            jTextFieldIP.setText("");
332            jTextFieldPort.setText("");
333        }
334
335    }//GEN-LAST:event_jTree1ValueChanged
336
337    // Variables declaration - do not modify//GEN-BEGIN:variables
338    private javax.swing.JButton jButtonSend;
339    private javax.swing.JLabel jLabel1;
340    private javax.swing.JLabel jLabelAETitle;
341    private javax.swing.JLabel jLabelIP;
342    private javax.swing.JLabel jLabelPort;
343    private javax.swing.JList jListFiles;
344    private javax.swing.JPanel jPanelButtons;
345    private javax.swing.JPanel jPanelDICOMObjects;
346    private javax.swing.JPanel jPanelSenderBox;
347    private javax.swing.JPanel jPanelVBox;
348    private javax.swing.JPanel jPanelfields;
349    private javax.swing.JScrollPane jScrollPane1;
350    private javax.swing.JScrollPane jScrollPane2;
351    private javax.swing.JTextField jTextFieldAETitle;
352    private javax.swing.JTextField jTextFieldIP;
353    private javax.swing.JTextField jTextFieldPort;
354    private javax.swing.JTree jTree1;
355    // End of variables declaration//GEN-END:variables
356}