File: VerificationDialog.java

package info (click to toggle)
dicomscope 3.6.0-28
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,256 kB
  • sloc: java: 22,911; cpp: 5,957; sh: 270; makefile: 45
file content (564 lines) | stat: -rw-r--r-- 19,326 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/*
 *
 *  Copyright (C) 1999, Institute for MicroTherapy
 *
 *  This software and supporting documentation were developed by
 *
 *    University of Witten/Herdecke
 *    Department of Radiology and MicroTherapy
 *    Institute for MicroTherapy
 *    Medical computer science
 *
 *    Universitaetsstrasse 142
 *    44799 Bochum, Germany
 *
 *    http://www.microtherapy.de/go/cs
 *    mailto:computer.science@microtherapy.de
 *
 *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND THE INSTITUTE MAKES  NO
 *  WARRANTY REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY
 *  OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES
 *  OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY
 *  AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
 *
 *  Author :      $Author: kleber $
 *  Last update : $Date: 2001/06/06 10:32:30 $
 *  Revision :    $Revision: 1.1.1.1 $
 *  State:        $State: Exp $
*/
package viewer.sr;
import viewer.gui.*;
import java.util.*;
import java.net.*;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.table.*;

import main.*;
import J2Ci.*;
/**
 * This class contains the GUI the verification of a
 * a Dicom Structured Report
 * @author Klaus Kleber
 * @since 11.11.200
 */
  public class VerificationDialog extends JDialog
  {
        boolean holdVerifyingObserver = true;
        boolean holdPreDocuments = true;


        /**
        * Current DVI Interface
        */
        private jDVInterface dvi;

        /**
        * Parent
        */
        private  MainImageViewerPanel mainView;

        /**
        * Table for seleting an user
        */
        private JTable table;

        /**
        *Model for the Tabel
        */
        private TableData tableData; // die Tabellendaten

        /**
        * If true at least one user has verified the document
        */
        private boolean verified = false;

        private boolean sortUp = false;
        /**
        * column identifies
        */
        private static Vector  columnIdentifiers;


        private JRadioButton verifyRadioButton = new JRadioButton("Verify",true);
        private JRadioButton signContentRadioButton = new JRadioButton("Verify and Sign");
        private JRadioButton signAllRadioButton = new JRadioButton("Verify and Sign (finalize)");

        private boolean isRevised = false;
        static
        {
            columnIdentifiers = new Vector();
            columnIdentifiers.add("Login");
            columnIdentifiers.add("Name");
            columnIdentifiers.add("Organization");
            columnIdentifiers.add("Code Value");
            columnIdentifiers.add("Code Meaning");
            columnIdentifiers.add("Coding Scheme Designator");
            columnIdentifiers.add("Coding Scheme Version");
            columnIdentifiers.add("DICOM Name");
            columnIdentifiers.add("Id");
        }

        /**
        * Constructor
        * @param dvi Current jDVInterface.
        * @param mainView Parent component.
        */
        public VerificationDialog(jDVInterface dvi, MainImageViewerPanel mainView,boolean isRevised)
        {
            super(mainView.parent, "Verify Document", true);
            this.dvi = dvi;
            this.mainView = mainView;
            this.isRevised = isRevised;

            getContentPane().setLayout(new BorderLayout(5,5));
            setLocationRelativeTo(mainView.parent);

            //Verify Button
            JButton okButton = new JButton("Verify");
            okButton.setToolTipText ("Verification");
            okButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {

                    verify();

                }
            });


            //Close
            JButton closeButton = new JButton("Close");
            closeButton.setToolTipText ("Close");
            closeButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    setVisible(false);
                    dispose();
                }
            });
            JPanel centerPanel = new JPanel(new BorderLayout(5,5));



        //init model
        tableData = new TableData( getUserData(),columnIdentifiers); // Konstruktion der zuflligen Tabellendaten

        // init table
        table = new JTable(tableData); // Konstruktion der sichtbaren Tabelle
        table.getTableHeader().getColumnModel().removeColumn(table.getColumn("Login"));
        table.getTableHeader().getColumnModel().removeColumn(table.getColumn("Code Value"));
        table.getTableHeader().getColumnModel().removeColumn(table.getColumn("Code Meaning"));
        table.getTableHeader().getColumnModel().removeColumn(table.getColumn("Coding Scheme Designator"));
        table.getTableHeader().getColumnModel().removeColumn(table.getColumn("Coding Scheme Version"));
        table.getTableHeader().getColumnModel().removeColumn(table.getColumn("Id"));
        table.getTableHeader().getColumnModel().removeColumn(table.getColumn("DICOM Name"));
    table.setAutoResizeMode (table.AUTO_RESIZE_LAST_COLUMN);
    table.setAutoCreateColumnsFromModel (false);


    //table.getColumnModel ().getColumn (0).setPreferredWidth (150);
    table.getColumnModel ().getColumn (0).setPreferredWidth (200);
    table.getColumnModel ().getColumn (1).setPreferredWidth (300);
    //table.getColumnModel ().getColumn (3).setPreferredWidth (100);
    //table.getColumnModel ().getColumn (4).setPreferredWidth (100);
    //table.getColumnModel ().getColumn (5).setPreferredWidth (100);
    //table.getColumnModel ().getColumn (6).setPreferredWidth (50);


        // init selection
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // immer nur eine Zeile auswhlbar
        table.addMouseListener(new VerifyMouseAdapter());

        // init Mouse Listener
        table.getTableHeader().addMouseListener(new TableMouseListener()); // Mausaktion im Header abfangen

        centerPanel.add(new JScrollPane(table), BorderLayout.CENTER);

            JPanel typePanel = new JPanel();
            typePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
            typePanel.setBorder(new EtchedBorder());
            ButtonGroup bg = new ButtonGroup();
            bg.add(verifyRadioButton);
            bg.add(signContentRadioButton);
            bg.add(signAllRadioButton);

            JPanel gridPanel = new JPanel (new GridLayout(3,1));
            gridPanel.add(verifyRadioButton);
            gridPanel.add(signContentRadioButton);
            gridPanel.add(signAllRadioButton);
            typePanel.add(gridPanel, BorderLayout.CENTER);
            centerPanel.add(typePanel, BorderLayout.SOUTH);



            getContentPane().add(centerPanel, BorderLayout.CENTER);

            JPanel bPanel = new JPanel();
            bPanel.add(okButton);
            bPanel.add(closeButton);

            getContentPane().add(bPanel, BorderLayout.SOUTH);

            setSize(450,300);
        }
    /**
    * This class extends the DefaultTableModel do that the needed
    * columnIdentifiers
    *
    */
    private class TableData extends DefaultTableModel
    {

        int[][] sortMatrix = {
            { 0, 0, 0, 0, 0,0,0,0,0 }  /* second column: second sort criterion */
        };

        /**
        * Checks if row1< row2. The type of comparison is defined by cols.
        * @return 0 if equals, -1 if row1 < row2, 1 if row1>row2.
        */
        public int compareTo(int col, int row1, int row2)
        {
            int secondCriterion=sortMatrix[0][col];

            int result = ((Comparable)tableData.getValueAt(row1, col)).compareTo((tableData.getValueAt(row2, col)));
            if (result == 0) result = ((Comparable)tableData.getValueAt(row1, secondCriterion)).compareTo((tableData.getValueAt(row2, secondCriterion)));
            return result;
        }

        /**
        * Constructor. Sets the colum identifiers.
        * @param columnIdentifiers column identifiers
        */
        public TableData(Vector dataValues,Vector columnIdentifiers)
        {
            super(dataValues, columnIdentifiers);
        }

        /**
        * Sets an editable
        */
        public boolean isCellEditable(int row, int cols)
        {
            return false;
        }

        /**
        * Returns the index of the invislibe cols
        */
        public int[] getInvisibleColumns()
        {

            //Number of cols in the model
            int cols = getColumnCount(); // Anzahl der Spalten merken

            //init array with size of invisible cols
            //( cols of the modle - cols of the table
            int[] invisible = new int[cols - table.getColumnCount()];

            //Fills array
            for(int i = 0, j = 0; i < cols; i++) //
            {
                if(table.convertColumnIndexToView(i) < 0)
                {
                    invisible[j++] = i;
                }
            }
            return invisible;
        }

        public void setRowCount(int index)
        {
            super.setRowCount(index);
        }

        /**
        * Swaps the rows.
        * @param row1 First row
        * @param row2 Secound row
        */
        public void swapRows(int row1, int row2)
        {
            Vector dummy = (Vector)dataVector.elementAt(row1);
            dataVector.setElementAt(dataVector.elementAt(row2), row1);
            dataVector.setElementAt(dummy, row2);
        }
    }



      /**
      * Gets the User Data form the interface
      */
      private Vector getUserData()
      {
            //jDSRDocument sr = dvi.getCurrentReport();
            int numberOfUsers = dvi.getNumberOfUsers();
            Vector list = new Vector();
            for (int i = 0; i< numberOfUsers; i++)
            {
                //Load ID
                String id = dvi.getUserID(i);

                //Init User Data
                Vector  user = new Vector();
                user.add(dvi.getUserLogin(id));
                user.add(dvi.getUserName(id));
                user.add(dvi.getUserOrganization(id));
                user.add(dvi.getUserCodeValue(id));
                user.add(dvi.getUserCodeMeaning(id));
                user.add(dvi.getUserCodingSchemeDesignator(id));
                user.add(dvi.getUserCodingSchemeVersion(id));
                user.add(dvi.getUserDICOMName(id));

                user.add(id);

                list.add(user);

            }
            return list;

      }

       public void verify()
       {
            int index = table.getSelectedRow();
            if (index == -1)    JOptionPane.showMessageDialog (   this,
                                                                "Please select User",
                                        "ERROR",
                                                            JOptionPane.ERROR_MESSAGE);
        else
        {
            String pwd = login((String)tableData.getValueAt(index, tableData. getColumnCount()-1),(String)tableData.getValueAt(index, 0));
            if (pwd!=null)
            {

                jDSRDocument sr = dvi.getCurrentReport();
                String name = (String)tableData.getValueAt(index,7);
                if (name == null) name = "";

                String organisation = (String)tableData.getValueAt(index,2);
                if (organisation == null) organisation = "";

                String codeValue = (String)tableData.getValueAt(index,3);
                if (codeValue == null) codeValue = "";

                String codeMeaning = (String)tableData.getValueAt(index,4);
                if (codeMeaning == null) codeMeaning = "";

                String codingSchemeDesignator = (String)tableData.getValueAt(index,5);
                if (codingSchemeDesignator == null) codingSchemeDesignator = "";

                String codingSchemeVersion = (String)tableData.getValueAt(index,6);
                if (codingSchemeVersion == null) codingSchemeVersion = "";
                int status=0;
        //verifyRadioButton
        //signContentRadioButton
        //signAllRadioButton
                /*status = sr.verifyDocument(name,
                                        codeValue,
                                        codingSchemeDesignator,
                                        codingSchemeVersion,
                                        codeMeaning,
                                        organisation);
                                        */
                 int mode = 0;;
                 if (verifyRadioButton.isSelected())mode = jDVPSVerifyAndSignMode.DVPSY_verify;
                 else if (signContentRadioButton.isSelected())mode = jDVPSVerifyAndSignMode.DVPSY_verifyAndSign;
                 else if (signAllRadioButton.isSelected())mode = jDVPSVerifyAndSignMode.DVPSY_verifyAndSign_finalize;
                 System.err.println("isFinalized (before): " + sr.isFinalized());
                 if (sr.isFinalized())
                 {
                    int result = JOptionPane.showConfirmDialog (this,"This operation destroys all current digital signatures. \n Do you really want this?", "Warning",
                    JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE);
                    if (result != JOptionPane.OK_OPTION)return;
                 }

                 if (!isRevised)
                 {
                    sr.createNewSOPInstance();
                    sr.setSpecificCharacterSetType(jDSRE_CharacterSet.CS_Latin1);
                 }
                 //System.err.println("UID: " +sr.getSOPInstanceUID());

                 status = dvi.verifyAndSignStructuredReport((String)tableData.getValueAt(index, tableData. getColumnCount()-1),
                                                            pwd,
                                                            mode);
                 // NB: a new sr object has been created internally
                 sr = dvi.getCurrentReport();
                 System.err.println("isFinalized (after): " + sr.isFinalized());
                 
                 Controller.instance().fireStatus(new SignedStatusEvent(this,
                            SignedStatusEvent.LOADSR,
                            dvi.getCombinedImagePStateSignatureStatus(),
                            dvi.getCurrentSignatureStatus(jDVPSObjectType.DVPSS_structuredReport)));
                 System.err.println("signed: " + dvi.getCurrentSignatureStatus(jDVPSObjectType.DVPSS_structuredReport));

                 if (status != 0)
                    System.err.println("Can't verify document. Status:  " +status);
                 else
                 {                   
                    verified = true;
                    setVisible(false);
                    dispose();
                 }
            }
        }

       }


    /**
    * This class listens for the selelction of rows and set the
    * text of the specified row (which presents a DicomScopeMessage)
    * to a TextField
    */
    private  class VerifyMouseAdapter extends MouseAdapter
    {

        public void mouseClicked(MouseEvent e)
        {
            if (e.getClickCount()== 2)
            {
                verify();
            }
        }

   }



       /**
       * Opens a password dialog and verifies the given password for the given user ID.
       * Returns true if the user was verified. This function returns false only if the user has
       * select the cancel button
       */
       public String login(String login, String name)
       {
        String pwd;

            while (true)
            {
            JPanel p = new JPanel (new BorderLayout ());

            JPanel westPanel = new JPanel (new GridLayout (2, 1));
            JPanel centerPanel = new JPanel (new GridLayout (2, 1));

            westPanel.add (new JLabel("Login: "));
            westPanel.add (new JLabel("Password: "));

            JLabel loginTxt = new JLabel(name);
            JPasswordField pw = new JPasswordField ();

            centerPanel.add (loginTxt);
            centerPanel.add (pw);

            p.add ("West", westPanel);
            p.add ("Center", centerPanel);

            int res = JOptionPane.showConfirmDialog (this,
                             p,
                             "Login",
                             JOptionPane.OK_CANCEL_OPTION,
                             JOptionPane.PLAIN_MESSAGE);

            if (res ==  JOptionPane.CANCEL_OPTION) return null;


           // if (( pw == null) || (pw.getPassword ().length ==0))
           // JOptionPane.showMessageDialog (this, "Please type your password");
           // else
            {
            pwd =new String(pw.getPassword());
            if (!dvi.verifyUserPassword(login, pwd))JOptionPane.showMessageDialog (this, "Wrong Password");
            else return pwd;
        }
        }

       }
       public boolean isVerified()
       {
            return verified;
       }
    /**
    * Testet auf Klicks in den Tabellenheader
    */
    private class TableMouseListener extends MouseAdapter

    {
        public void mouseClicked(MouseEvent e)
        {

            if(SwingUtilities.isRightMouseButton(e)) // nur mit der rechten Maustaste zulassen
            {
                TableColumnModel tcm = table.getTableHeader().getColumnModel(); // schon mal das Spaltenmodell holen
                int index = tcm.getColumnIndexAtX(e.getX()); // Index der angeklickten Spalte ermitteln

                if(index >= 0) // wurde tatschlich eine Spalte angeklickt...
                {
                    int modelIndex =  table.convertColumnIndexToModel(index); // ...hole Spaltenindex des Modells

                    sort(modelIndex);
                }
            }
        }
    }
    /**
    * Sort the table.
    * @param index Specifies the colum to be sorted
    */
    private void sort (int index)
    {
            if (sortUp)
            {// Bubblesort
                for(int i = 0; i < tableData.getRowCount(); i++)
                {
                    for(int j = i + 1; j < tableData.getRowCount(); j++)
                    {
                        if (tableData.compareTo(index, i, j) > 0)
                        {
                            tableData.swapRows(i, j);
                        }
                    }
                }
                sortUp = false;
            }
             else
             {
                for(int i = 0; i < tableData.getRowCount(); i++)
                {
                    for(int j = i + 1; j < tableData.getRowCount(); j++)
                    {
                        if (tableData.compareTo(index, i, j) < 0)
                        {
                            tableData.swapRows(i, j);
                        }
                    }
                }
                sortUp = true;

             }
            repaint(); // Tabelle neuzeichnen

    }

}
/*
 *  CVS Log
 *  $Log: VerificationDialog.java,v $
 *  Revision 1.1.1.1  2001/06/06 10:32:30  kleber
 *  Init commit for DICOMscope 3.5
 *  Create new CVS
 *
*/