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 */
019
020/*
021 * IndexedMetaData.java
022 *
023 * Created on Feb 19, 2010, 6:39:59 PM
024 */
025
026package pt.ua.dicoogle.rGUI.client.windows;
027
028import java.rmi.RemoteException;
029import org.slf4j.LoggerFactory;
030import java.awt.Dimension;
031import java.awt.Image;
032import java.awt.Toolkit;
033import java.awt.datatransfer.Clipboard;
034import java.util.ArrayList;
035import java.util.Collections;
036import java.util.HashMap;
037import java.util.Iterator;
038import java.util.List;
039import javax.swing.TransferHandler;
040import javax.swing.table.AbstractTableModel;
041import pt.ua.dicoogle.Main;
042import pt.ua.dicoogle.rGUI.client.UserRefs;
043import pt.ua.dicoogle.sdk.datastructs.SearchResult;
044
045
046
047/**
048 *
049 * @author Luís A. Bastião Silva <bastiao@ua.pt>
050 */
051@Deprecated
052public class IndexedMetaData extends javax.swing.JFrame
053{
054
055    /*********************
056     * Private attributes
057     *********************/
058     private SearchResult searchResult ;
059     private MainWindow main ;
060
061     private MetaDataModel model;
062
063
064    /** Creates new form IndexedMetaData */
065    public IndexedMetaData(SearchResult searchResult, MainWindow main)
066    {
067        this.main = main;
068        this.searchResult = searchResult;
069        initComponents();
070
071        Image image = Toolkit.getDefaultToolkit().getImage(Thread.currentThread().getContextClassLoader().getResource("trayicon.gif"));
072        this.setIconImage(image);
073        
074        // Get the size of the screen
075        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
076        
077        // Determine the new location of the window
078        int w = this.getSize().width;
079        int h = this.getSize().height;
080        int x = (dim.width - w) / 2;
081        int y = (dim.height - h) / 2;
082
083        // Move the window
084        this.setLocation(x, y);
085
086        String PatientName = (String) searchResult.getExtraData().get("PatientName");
087
088        this.setTitle(PatientName + " - " + searchResult.getURI());
089        fill();
090        
091    }
092
093
094
095
096    /***************************
097     * Private Methods
098     ***************************/
099
100
101
102
103    private void fill()
104    {
105
106        TransferHandler th = jTableMetaData.getTransferHandler();
107        if (th != null) {
108            Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
109            th.exportToClipboard(jTableMetaData, cb, TransferHandler.COPY);
110        }
111
112        fillTitle();
113    }
114
115    private void fillTitle()
116    {
117        jLabelTitle.setText(searchResult.getURI().toString());
118    }
119    
120    /***************************
121     * Private Classes
122     ***************************/
123    
124    class MetaData implements Comparable
125    {
126        private String name  = "" ;
127        private String value = "" ;
128
129        public MetaData(String name, String value )
130        {
131            this.name = name ;
132            this.value = value ;
133        }
134
135        /**
136         * @return the value
137         */
138        public String getValue()
139        {
140            return value;
141        }
142
143        /**
144         * @param value the value to set
145         */
146        public void setValue(String value)
147        {
148            this.value = value;
149        }
150
151
152        /**
153         * @return the name
154         */
155        public String getName()
156        {
157            return name;
158        }
159
160        /**
161         * @param name the name to set
162         */
163        public void setName(String name)
164        {
165            this.name = name;
166        }
167
168        
169
170        @Override
171        public int compareTo(Object o)
172        {
173
174            MetaData meta = (MetaData) o;
175            return this.name.compareTo(meta.getName());
176
177        }
178
179        
180
181    }
182
183
184    class MetaDataModel extends AbstractTableModel
185    {
186
187        static final int NAME = 0 ;
188        static final int VALUE = 1 ;
189
190        private String[] headers = { "Name", "Value", };
191        private ArrayList<MetaData> metaData = new ArrayList<MetaData>();
192
193        public MetaDataModel()
194        {            
195            try {
196                HashMap resultFields = searchResult.getExtraData();
197
198                List resultList = UserRefs.getInstance().getSearch().SearchIndexedMetaData(searchResult);
199                
200
201                if (resultList.size() > 0) {
202                    //DebugManager.getInstance().debug("Found results (In Meta)");
203                    
204                    SearchResult r = (SearchResult) resultList.get(0);
205                    resultFields = r.getExtraData();
206                }
207
208                Iterator it = resultFields.keySet().iterator();
209                while (it.hasNext()) {
210                    String key = (String) it.next();
211                    metaData.add(new MetaData(key, (String) resultFields.get(key)));
212                }
213                
214                Collections.sort(metaData);
215            } catch (RemoteException ex) {
216                LoggerFactory.getLogger(IndexedMetaData.class).error(ex.getMessage(), ex);
217            }
218        }
219
220        public String getColumnName(int c)
221        {
222            return headers[c];
223        }
224
225
226        @Override
227        public int getRowCount()
228        {
229            return metaData.size();
230        }
231
232        @Override
233        public int getColumnCount()
234        {
235            return headers.length ;
236        }
237
238        @Override
239        public Object getValueAt(int rowIndex, int columnIndex)
240        {
241            String result = "";
242            MetaData m = this.metaData.get(rowIndex);
243            if (columnIndex==NAME)
244            {
245                result = m.getName();
246            }
247            else if (columnIndex==VALUE)
248            {
249                result = m.getValue();
250            }
251            else
252            {
253                boolean cond = (columnIndex!=NAME||columnIndex!=VALUE);
254                assert cond ;
255            }
256            
257            return result ;
258
259        }
260
261
262        
263    }
264
265
266
267    /** This method is called from within the constructor to
268     * initialize the form.
269     * WARNING: Do NOT modify this code. The content of this method is
270     * always regenerated by the Form Editor.
271     */
272    @SuppressWarnings("unchecked")
273    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
274    private void initComponents() {
275
276        jSplitPane1 = new javax.swing.JSplitPane();
277        jPanel1 = new javax.swing.JPanel();
278        jLabelTitle = new javax.swing.JLabel();
279        jPanel2 = new javax.swing.JPanel();
280        jScrollPane1 = new javax.swing.JScrollPane();
281        model = new MetaDataModel();
282        jTableMetaData = new javax.swing.JTable(model);
283
284        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
285        setName("Meta-data fields"); // NOI18N
286        addWindowListener(new java.awt.event.WindowAdapter() {
287            public void windowClosing(java.awt.event.WindowEvent evt) {
288                formWindowClosing(evt);
289            }
290        });
291        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
292
293        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
294
295        jPanel1.setFont(new java.awt.Font("Lucida Grande", 1, 18));
296        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));
297
298        jLabelTitle.setFont(new java.awt.Font("Lucida Grande", 1, 18));
299        jLabelTitle.setText("jLabelTitle");
300        jPanel1.add(jLabelTitle);
301
302        jSplitPane1.setTopComponent(jPanel1);
303
304        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));
305
306        jTableMetaData.setModel(model);
307        jScrollPane1.setViewportView(jTableMetaData);
308
309        jPanel2.add(jScrollPane1);
310
311        jSplitPane1.setRightComponent(jPanel2);
312
313        getContentPane().add(jSplitPane1);
314
315        pack();
316    }// </editor-fold>//GEN-END:initComponents
317
318    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
319        this.setVisible(false);
320
321        main.setEnabled(true);
322        main.toFront();
323
324    }//GEN-LAST:event_formWindowClosing
325
326    
327
328    // Variables declaration - do not modify//GEN-BEGIN:variables
329    private javax.swing.JLabel jLabelTitle;
330    private javax.swing.JPanel jPanel1;
331    private javax.swing.JPanel jPanel2;
332    private javax.swing.JScrollPane jScrollPane1;
333    private javax.swing.JSplitPane jSplitPane1;
334    private javax.swing.JTable jTableMetaData;
335    // End of variables declaration//GEN-END:variables
336
337}