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 * QRSettings.java 021 * 022 * Created on 15/Dez/2009, 11:34:31 023 */ 024 025package pt.ua.dicoogle.rGUI.client.windows; 026 027import java.rmi.RemoteException; 028import org.slf4j.Logger; 029import org.slf4j.LoggerFactory; 030import org.slf4j.Logger; 031import org.slf4j.LoggerFactory; 032import java.awt.Image; 033import java.awt.Toolkit; 034import java.net.URL; 035 036import java.util.Hashtable; 037import java.util.concurrent.Semaphore; 038 039import javax.swing.DefaultListModel; 040import javax.swing.ImageIcon; 041import javax.swing.JList; 042import javax.swing.JOptionPane; 043import javax.swing.JTextField; 044 045import pt.ua.dicoogle.rGUI.interfaces.controllers.IQRServers; 046import pt.ua.dicoogle.Main; 047import pt.ua.dicoogle.sdk.datastructs.MoveDestination; 048import pt.ua.dicoogle.rGUI.client.AdminRefs; 049import pt.ua.dicoogle.rGUI.client.UIHelper.AllowBlankMaskFormatter; 050 051/** 052 * Query/Retrieve Storage Servers configuration 053 * 054 * @author Samuel Campos <samuelcampos@ua.pt> 055 */ 056@Deprecated 057public class QRServers extends javax.swing.JFrame { 058 059 private static Semaphore sem = new Semaphore(1, true); 060 private static QRServers instance = null; 061 private static IQRServers qrserv; 062 063 private Hashtable<String, MoveDestination> listMove = new Hashtable<String, MoveDestination>(); 064 065 066 public static synchronized QRServers getInstance() { 067 try { 068 sem.acquire(); 069 if (instance == null) { 070 instance = new QRServers(); 071 } 072 sem.release(); 073 } catch (InterruptedException ex) { 074// LoggerFactory.getLogger(MainWindow.class.getName()).log(Level.FATAL, null, ex); 075 } 076 return instance; 077 } 078 079 080 /** Creates new form QRSettings */ 081 private QRServers() { 082 initComponents(); 083 084 Image image = Toolkit.getDefaultToolkit().getImage(Thread.currentThread().getContextClassLoader().getResource("trayicon.gif")); 085 this.setIconImage(image); 086 087 QRServers.qrserv = AdminRefs.getInstance().getQRservers(); 088 089 loadMove(); 090 } 091 092 public static Image getImage(final String pathAndFileName) { 093 final URL url = Thread.currentThread().getContextClassLoader().getResource(pathAndFileName); 094 return Toolkit.getDefaultToolkit().getImage(url); 095 } 096 097 /** This method is called from within the constructor to 098 * initialize the form. 099 * WARNING: Do NOT modify this code. The content of this method is 100 * always regenerated by the Form Editor. 101 */ 102 @SuppressWarnings("unchecked") 103 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 104 private void initComponents() { 105 106 jPanel5 = new javax.swing.JPanel(); 107 jButtonQRAddEntry = new javax.swing.JButton(); 108 jButtonQRRemoveEntry = new javax.swing.JButton(); 109 jScrollPane5 = new javax.swing.JScrollPane(); 110 DefaultListModel modelQRMoveDest = new DefaultListModel(); 111 jListQRMoveDest = new JList(modelQRMoveDest); 112 jLabel1 = new javax.swing.JLabel(); 113 jTextFieldQRAETitle = new javax.swing.JTextField(); 114 jLabel2 = new javax.swing.JLabel(); 115 jLabel3 = new javax.swing.JLabel(); 116 AllowBlankMaskFormatter maskSub = null; 117 try 118 { 119 maskSub = new AllowBlankMaskFormatter("###.###.###.###"); 120 maskSub.setPlaceholderCharacter(' '); 121 maskSub.setAllowBlankField(true); 122 //maskSub.setValidCharacters("0123456789"); 123 //maskSub.setInvalidCharacters("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"); 124 } 125 catch (java.text.ParseException e) 126 { 127 String pass = null ; 128 } 129 //jTextFieldQRIP = new JFormattedTextField(maskSub); 130 jTextFieldQRIP = new JTextField(); 131 jTextFieldQRPort = new javax.swing.JTextField(); 132 jButtonWrite = new javax.swing.JButton(); 133 134 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 135 setTitle("Query/Retrieve Storage Servers"); 136 setResizable(false); 137 addWindowListener(new java.awt.event.WindowAdapter() { 138 public void windowClosing(java.awt.event.WindowEvent evt) { 139 formWindowClosing(evt); 140 } 141 }); 142 143 jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Storage Servers Destinations")); 144 145 jButtonQRAddEntry.setIcon(new ImageIcon(getImage("add.png"))); 146 jButtonQRAddEntry.setText("Add Entry"); 147 jButtonQRAddEntry.addActionListener(new java.awt.event.ActionListener() { 148 public void actionPerformed(java.awt.event.ActionEvent evt) { 149 jButtonQRAddEntryActionPerformed(evt); 150 } 151 }); 152 153 jButtonQRRemoveEntry.setIcon(new ImageIcon(getImage("remove.png"))); 154 jButtonQRRemoveEntry.setText("Remove"); 155 jButtonQRRemoveEntry.addActionListener(new java.awt.event.ActionListener() { 156 public void actionPerformed(java.awt.event.ActionEvent evt) { 157 jButtonQRRemoveEntryActionPerformed(evt); 158 } 159 }); 160 161 jListQRMoveDest.addMouseListener(new java.awt.event.MouseAdapter() { 162 public void mouseClicked(java.awt.event.MouseEvent evt) { 163 jListQRMoveDestMouseClicked(evt); 164 } 165 }); 166 jListQRMoveDest.addListSelectionListener(new javax.swing.event.ListSelectionListener() { 167 public void valueChanged(javax.swing.event.ListSelectionEvent evt) { 168 jListQRMoveDestValueChanged(evt); 169 } 170 }); 171 jScrollPane5.setViewportView(jListQRMoveDest); 172 173 jLabel1.setText("AETitle:"); 174 175 jLabel2.setText("IP:"); 176 177 jLabel3.setText("Port:"); 178 179 jButtonWrite.setIcon(new ImageIcon(getImage("floopy-icon.png"))); 180 jButtonWrite.setText("Save Configurations"); 181 jButtonWrite.addActionListener(new java.awt.event.ActionListener() { 182 public void actionPerformed(java.awt.event.ActionEvent evt) { 183 jButtonWriteActionPerformed(evt); 184 } 185 }); 186 187 javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); 188 jPanel5.setLayout(jPanel5Layout); 189 jPanel5Layout.setHorizontalGroup( 190 jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 191 .addGroup(jPanel5Layout.createSequentialGroup() 192 .addContainerGap() 193 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 194 .addGroup(jPanel5Layout.createSequentialGroup() 195 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 196 .addComponent(jLabel1) 197 .addComponent(jLabel3) 198 .addComponent(jLabel2)) 199 .addGap(24, 24, 24) 200 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 201 .addGroup(jPanel5Layout.createSequentialGroup() 202 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 203 .addComponent(jTextFieldQRAETitle, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE) 204 .addComponent(jTextFieldQRIP, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)) 205 .addGap(18, 18, 18) 206 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) 207 .addComponent(jButtonQRRemoveEntry, 0, 1, Short.MAX_VALUE) 208 .addComponent(jButtonQRAddEntry, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))) 209 .addComponent(jTextFieldQRPort, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)) 210 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 211 .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)) 212 .addComponent(jButtonWrite, javax.swing.GroupLayout.Alignment.TRAILING)) 213 .addGap(20, 20, 20)) 214 ); 215 jPanel5Layout.setVerticalGroup( 216 jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 217 .addGroup(jPanel5Layout.createSequentialGroup() 218 .addContainerGap() 219 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 220 .addGroup(jPanel5Layout.createSequentialGroup() 221 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 222 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 223 .addComponent(jLabel1) 224 .addComponent(jTextFieldQRAETitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 225 .addGroup(jPanel5Layout.createSequentialGroup() 226 .addComponent(jButtonQRAddEntry) 227 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 228 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 229 .addComponent(jButtonQRRemoveEntry) 230 .addComponent(jTextFieldQRIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 231 .addComponent(jLabel2)))) 232 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 233 .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 234 .addComponent(jLabel3) 235 .addComponent(jTextFieldQRPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) 236 .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)) 237 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE) 238 .addComponent(jButtonWrite)) 239 ); 240 241 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 242 getContentPane().setLayout(layout); 243 layout.setHorizontalGroup( 244 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 245 .addGroup(layout.createSequentialGroup() 246 .addContainerGap() 247 .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 248 .addContainerGap()) 249 ); 250 layout.setVerticalGroup( 251 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 252 .addGroup(layout.createSequentialGroup() 253 .addContainerGap() 254 .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 255 .addContainerGap()) 256 ); 257 258 pack(); 259 }// </editor-fold>//GEN-END:initComponents 260 261 262 public void loadMove() 263 { 264 try { 265 266 DefaultListModel m = (DefaultListModel) jListQRMoveDest.getModel(); 267 m.clear(); 268 269 for (MoveDestination s : qrserv.getMoves()) { 270 //DebugManager.getInstance().debug(s.getAETitle()); 271 272 int pos = jListQRMoveDest.getModel().getSize(); 273 m.add(pos, s.getAETitle()); 274 listMove.put(s.getAETitle(), s); 275 } 276 277 } catch (RemoteException ex) { 278 LoggerFactory.getLogger(QRServers.class).error(ex.getMessage(), ex); 279 } 280 281 } 282 283 private void jButtonQRAddEntryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQRAddEntryActionPerformed 284 if (jTextFieldQRAETitle.getText().equals("") || jTextFieldQRIP.getText().equals("") || jTextFieldQRPort.getText().equals("")) { 285 JOptionPane.showMessageDialog(this, "Please, fill all fields!", 286 "Missing fields", JOptionPane.WARNING_MESSAGE); 287 288 } else { 289 String aeTitleDest = jTextFieldQRAETitle.getText(); 290 if (!listMove.containsKey(aeTitleDest)) { 291 DefaultListModel m = (DefaultListModel) jListQRMoveDest.getModel(); 292 m.addElement(aeTitleDest); 293 294 MoveDestination tmpMove = new MoveDestination(aeTitleDest, 295 jTextFieldQRIP.getText(), Integer.parseInt(jTextFieldQRPort.getText())); 296 297 listMove.put(aeTitleDest, tmpMove); 298 299 try { 300 qrserv.AddEntry(tmpMove); 301 302 } catch (RemoteException ex) { 303 LoggerFactory.getLogger(QRServers.class).error(ex.getMessage(), ex); 304 } 305 306 307 } else { 308 JOptionPane.showMessageDialog(this, "The AETtitle already exists in the list", 309 "AETitle", JOptionPane.WARNING_MESSAGE); 310 } 311 312 } 313}//GEN-LAST:event_jButtonQRAddEntryActionPerformed 314 315 private void jButtonQRRemoveEntryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonQRRemoveEntryActionPerformed 316 317 318 // Remove Destination 319 320 if (jListQRMoveDest.getSelectedIndex() == -1 ) { 321 JOptionPane.showMessageDialog(this, "Please select an AETitle in the list", 322 "No selected item", JOptionPane.WARNING_MESSAGE); 323 } else { 324 String aeTitleSelected = null; 325 aeTitleSelected = (String) jListQRMoveDest.getSelectedValue(); 326 DefaultListModel m = (DefaultListModel) jListQRMoveDest.getModel(); 327 328 m.removeElement(jListQRMoveDest.getSelectedValue()); 329 MoveDestination tmp = listMove.get(aeTitleSelected); 330 listMove.remove(aeTitleSelected); 331 332 try { 333 qrserv.RemoveEntry(tmp); 334 } catch (RemoteException ex) { 335 LoggerFactory.getLogger(QRServers.class).error(ex.getMessage(), ex); 336 } 337 338 } 339}//GEN-LAST:event_jButtonQRRemoveEntryActionPerformed 340 341 private void jListQRMoveDestValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListQRMoveDestValueChanged 342 // Show ip address and port number ; 343 344 if (jListQRMoveDest.getSelectedIndex() == -1 ) 345 return ; 346 String sel = (String) jListQRMoveDest.getSelectedValue(); 347 MoveDestination tmp = listMove.get(sel); 348 349 jTextFieldQRAETitle.setText(tmp.getAETitle()); 350 jTextFieldQRIP.setText(tmp.getIpAddrs()); 351 jTextFieldQRPort.setText(String.valueOf(tmp.getPort())); 352 }//GEN-LAST:event_jListQRMoveDestValueChanged 353 354 private void jListQRMoveDestMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListQRMoveDestMouseClicked 355 356}//GEN-LAST:event_jListQRMoveDestMouseClicked 357 358 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing 359 Services services = Services.getInstance(); 360 361 //if(services != null && services.isVisible()){ 362 services.toFront(); 363 services.setEnabled(true); 364 /* 365 } 366 else{ 367 ServerOptions serverOptions = ServerOptions.getInstance(); 368 369 serverOptions.toFront(); 370 serverOptions.setEnabled(true); 371 } 372 * 373 */ 374 375 this.dispose(); 376 }//GEN-LAST:event_formWindowClosing 377 378 private void jButtonWriteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWriteActionPerformed 379 AdminRefs.getInstance().saveSettings(); 380}//GEN-LAST:event_jButtonWriteActionPerformed 381 382 383 // Variables declaration - do not modify//GEN-BEGIN:variables 384 private javax.swing.JButton jButtonQRAddEntry; 385 private javax.swing.JButton jButtonQRRemoveEntry; 386 private javax.swing.JButton jButtonWrite; 387 private javax.swing.JLabel jLabel1; 388 private javax.swing.JLabel jLabel2; 389 private javax.swing.JLabel jLabel3; 390 private javax.swing.JList jListQRMoveDest; 391 private javax.swing.JPanel jPanel5; 392 private javax.swing.JScrollPane jScrollPane5; 393 private javax.swing.JTextField jTextFieldQRAETitle; 394 private javax.swing.JTextField jTextFieldQRIP; 395 private javax.swing.JTextField jTextFieldQRPort; 396 // End of variables declaration//GEN-END:variables 397 398}