NXvalidate  1
 All Classes Namespaces Files Functions Variables
NXLoadFilesDialog.java
Go to the documentation of this file.
1 /* NeXus - Neutron & X-ray Common Data Format
2  *
3  * NeXus file validation GUI tool.
4  *
5  * Copyright (C) 2010 Stephen Rankin
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * For further information, see <http://www.nexusformat.org/>
22  *
23  * NXLoadFilesDialog.java
24  *
25  * Created on 16-Jun-2010, 11:56:31
26  */
27 package org.nexusformat.nxvalidate;
28 
29 import java.io.File;
30 import java.util.ResourceBundle;
31 
36 public class NXLoadFilesDialog extends javax.swing.JDialog {
37 
38  private File nxs = null;
39  private File nxdl = null;
40  private boolean OKButtonUsed = false;
41  private CheckNexusFileType check = null;
42  private ResourceBundle bundle = null;
44  public NXLoadFilesDialog(java.awt.Frame parent, boolean modal) {
45  super(parent, modal);
46  initComponents();
47  check = new CheckNexusFileType();
48  bundle = ResourceBundle.getBundle(
49  "org/nexusformat/nxvalidate/resources/nxvalidate");
50  }
51 
57  @SuppressWarnings("unchecked")
58  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
59  private void initComponents() {
60 
61  jFileChooser1 = new javax.swing.JFileChooser();
62  messageOptionPane = new javax.swing.JOptionPane();
63  jPanel1 = new javax.swing.JPanel();
64  nxsLabel = new javax.swing.JLabel();
65  nxsTextField = new javax.swing.JTextField();
66  openButton1 = new javax.swing.JButton();
67  nxdlLabel = new javax.swing.JLabel();
68  nxdcTextField = new javax.swing.JTextField();
69  openButton2 = new javax.swing.JButton();
70  cancelButton = new javax.swing.JButton();
71  OKButton = new javax.swing.JButton();
72 
73  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
74  setTitle("Open Files");
75  setResizable(false);
76 
77  jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
78 
79  nxsLabel.setText("Load NXS:");
80 
81  nxsTextField.setEditable(false);
82 
83  openButton1.setText("Open");
84  openButton1.addActionListener(new java.awt.event.ActionListener() {
85  public void actionPerformed(java.awt.event.ActionEvent evt) {
86  openButton1ActionPerformed(evt);
87  }
88  });
89 
90  nxdlLabel.setText("Load NXDL:");
91 
92  nxdcTextField.setEditable(false);
93 
94  openButton2.setText("Open");
95  openButton2.addActionListener(new java.awt.event.ActionListener() {
96  public void actionPerformed(java.awt.event.ActionEvent evt) {
97  openButton2ActionPerformed(evt);
98  }
99  });
100 
101  cancelButton.setText("CANCEL");
102  cancelButton.addActionListener(new java.awt.event.ActionListener() {
103  public void actionPerformed(java.awt.event.ActionEvent evt) {
104  cancelButtonActionPerformed(evt);
105  }
106  });
107 
108  OKButton.setText("OK");
109  OKButton.addActionListener(new java.awt.event.ActionListener() {
110  public void actionPerformed(java.awt.event.ActionEvent evt) {
111  OKButtonActionPerformed(evt);
112  }
113  });
114 
115  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
116  jPanel1.setLayout(jPanel1Layout);
117  jPanel1Layout.setHorizontalGroup(
118  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
119  .addGroup(jPanel1Layout.createSequentialGroup()
120  .addContainerGap()
121  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
122  .addGroup(jPanel1Layout.createSequentialGroup()
123  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
124  .addComponent(nxsLabel)
125  .addComponent(nxdlLabel))
126  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
127  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
128  .addComponent(nxdcTextField)
129  .addComponent(nxsTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)))
130  .addComponent(cancelButton))
131  .addGap(15, 15, 15)
132  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
133  .addComponent(openButton1)
134  .addComponent(openButton2)
135  .addComponent(OKButton))
136  .addContainerGap())
137  );
138  jPanel1Layout.setVerticalGroup(
139  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
140  .addGroup(jPanel1Layout.createSequentialGroup()
141  .addContainerGap()
142  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
143  .addComponent(nxsLabel)
144  .addComponent(nxsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
145  .addComponent(openButton1))
146  .addGap(28, 28, 28)
147  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
148  .addComponent(nxdlLabel)
149  .addComponent(nxdcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
150  .addComponent(openButton2))
151  .addGap(27, 27, 27)
152  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
153  .addComponent(cancelButton)
154  .addComponent(OKButton))
155  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
156  );
157 
158  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
159  getContentPane().setLayout(layout);
160  layout.setHorizontalGroup(
161  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162  .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
163  );
164  layout.setVerticalGroup(
165  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
167  );
168 
169  pack();
170  }// </editor-fold>//GEN-END:initComponents
171 
172  private void openButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButton1ActionPerformed
173 
174  if (evt.getSource() == openButton1) {
175 
176  int returnVal = jFileChooser1.showOpenDialog(this);
177 
178  if (returnVal == jFileChooser1.APPROVE_OPTION) {
179  nxs = jFileChooser1.getSelectedFile();
180 
181  if(check.checkNexusFile(nxs)){
182  nxsTextField.setText(nxs.getAbsolutePath());
183  nxsTextField.setToolTipText(nxs.getAbsolutePath());
184  } else{
185  nxs = null;
186  messageOptionPane.showMessageDialog(this,
187  bundle.getString("notNXDLFileMessage"));
188  }
189 
190 
191  } else {
192  nxs = null;
193  }
194 
195  }
196 }//GEN-LAST:event_openButton1ActionPerformed
197 
198  private void openButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButton2ActionPerformed
199 
200  if (evt.getSource() == openButton2) {
201 
202  int returnVal = jFileChooser1.showOpenDialog(this);
203 
204  if (returnVal == jFileChooser1.APPROVE_OPTION) {
205  nxdl = jFileChooser1.getSelectedFile();
206 
207  if(check.checkNXDLFile(nxdl)){
208  nxdcTextField.setText(nxdl.getAbsolutePath());
209  nxdcTextField.setToolTipText(nxdl.getAbsolutePath());
210  } else{
211  nxdl = null;
212  messageOptionPane.showMessageDialog(this,
213  bundle.getString("notNXDLFileMessage"));
214  }
215 
216 
217  } else {
218  nxdl = null;
219  }
220 
221  }
222 }//GEN-LAST:event_openButton2ActionPerformed
223 
224  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
225  if (evt.getSource() == cancelButton) {
226  OKButtonUsed = false;
227  this.setVisible(false);
228  }
229 }//GEN-LAST:event_cancelButtonActionPerformed
230 
231  private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
232  if (evt.getSource() == OKButton) {
233  OKButtonUsed = true;
234  this.setVisible(false);
235  }
236  }//GEN-LAST:event_OKButtonActionPerformed
237 
238  public File getNXSFile() {
239  return nxs;
240  }
241 
242  public File getNXDLFile() {
243  return nxdl;
244  }
245 
246  public boolean OKButtonUsed() {
247  return OKButtonUsed;
248  }
249 
253  public static void main(String args[]) {
254  java.awt.EventQueue.invokeLater(new Runnable() {
255 
256  public void run() {
257  NXLoadFilesDialog dialog = new NXLoadFilesDialog(new javax.swing.JFrame(), true);
258  dialog.addWindowListener(new java.awt.event.WindowAdapter() {
259 
260  public void windowClosing(java.awt.event.WindowEvent e) {
261  System.exit(0);
262  }
263  });
264  dialog.setVisible(true);
265  }
266  });
267  }
268  // Variables declaration - do not modify//GEN-BEGIN:variables
269  private javax.swing.JButton OKButton;
270  private javax.swing.JButton cancelButton;
271  private javax.swing.JFileChooser jFileChooser1;
272  private javax.swing.JPanel jPanel1;
273  private javax.swing.JOptionPane messageOptionPane;
274  private javax.swing.JTextField nxdcTextField;
275  private javax.swing.JLabel nxdlLabel;
276  private javax.swing.JLabel nxsLabel;
277  private javax.swing.JTextField nxsTextField;
278  private javax.swing.JButton openButton1;
279  private javax.swing.JButton openButton2;
280  // End of variables declaration//GEN-END:variables
281 }