NXvalidate  1
 All Classes Namespaces Files Functions Variables
NXValidateDialog.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 
28 package org.nexusformat.nxvalidate;
29 
30 import java.io.File;
31 
36 public class NXValidateDialog extends javax.swing.JDialog {
37 
38  private File nxs = null;
39  private File nxdl = null;
40  private boolean OKButtonUsed = false;
42  public NXValidateDialog(java.awt.Frame parent, boolean modal) {
43  super(parent, modal);
44  initComponents();
45  }
46 
52  @SuppressWarnings("unchecked")
53  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
54  private void initComponents() {
55 
56  jFileChooser1 = new javax.swing.JFileChooser();
57  jPanel1 = new javax.swing.JPanel();
58  nxdcLabel = new javax.swing.JLabel();
59  nxdcTextField = new javax.swing.JTextField();
60  openButton2 = new javax.swing.JButton();
61  cancelButton = new javax.swing.JButton();
62  OKButton = new javax.swing.JButton();
63 
64  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
65  setTitle("Open Files");
66  setResizable(false);
67 
68  jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
69 
70  nxdcLabel.setText("Load NXDC:");
71 
72  nxdcTextField.setEditable(false);
73 
74  openButton2.setText("Open");
75  openButton2.addActionListener(new java.awt.event.ActionListener() {
76  public void actionPerformed(java.awt.event.ActionEvent evt) {
77  openButton2ActionPerformed(evt);
78  }
79  });
80 
81  cancelButton.setText("CANCEL");
82  cancelButton.addActionListener(new java.awt.event.ActionListener() {
83  public void actionPerformed(java.awt.event.ActionEvent evt) {
84  cancelButtonActionPerformed(evt);
85  }
86  });
87 
88  OKButton.setText("Validate");
89  OKButton.addActionListener(new java.awt.event.ActionListener() {
90  public void actionPerformed(java.awt.event.ActionEvent evt) {
91  OKButtonActionPerformed(evt);
92  }
93  });
94 
95  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
96  jPanel1.setLayout(jPanel1Layout);
97  jPanel1Layout.setHorizontalGroup(
98  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
99  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
100  .addContainerGap()
101  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
102  .addGroup(jPanel1Layout.createSequentialGroup()
103  .addComponent(cancelButton)
104  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 482, Short.MAX_VALUE)
105  .addComponent(OKButton))
106  .addGroup(jPanel1Layout.createSequentialGroup()
107  .addComponent(nxdcLabel)
108  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
109  .addComponent(nxdcTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)
110  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
111  .addComponent(openButton2)))
112  .addGap(23, 23, 23))
113  );
114  jPanel1Layout.setVerticalGroup(
115  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
116  .addGroup(jPanel1Layout.createSequentialGroup()
117  .addGap(10, 10, 10)
118  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
119  .addComponent(nxdcLabel)
120  .addComponent(nxdcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
121  .addComponent(openButton2))
122  .addGap(18, 18, 18)
123  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
124  .addComponent(OKButton)
125  .addComponent(cancelButton))
126  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
127  );
128 
129  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
130  getContentPane().setLayout(layout);
131  layout.setHorizontalGroup(
132  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
133  .addGroup(layout.createSequentialGroup()
134  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
135  .addContainerGap())
136  );
137  layout.setVerticalGroup(
138  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
139  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
140  );
141 
142  pack();
143  }// </editor-fold>//GEN-END:initComponents
144 
145  private void openButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButton2ActionPerformed
146 
147  if(evt.getSource() == openButton2){
148 
149  int returnVal = jFileChooser1.showOpenDialog(this);
150 
151  if (returnVal == jFileChooser1.APPROVE_OPTION) {
152  nxdl = jFileChooser1.getSelectedFile();
153  nxdcTextField.setText(nxdl.getAbsolutePath());
154  nxdcTextField.setToolTipText(nxdl.getAbsolutePath());
155  } else {
156  nxdl = null;
157  }
158 
159  }
160 }//GEN-LAST:event_openButton2ActionPerformed
161 
162  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
163  if(evt.getSource() == cancelButton){
164  OKButtonUsed = false;
165  this.setVisible(false);
166  }
167 }//GEN-LAST:event_cancelButtonActionPerformed
168 
169  private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
170 
171  if(evt.getSource() == OKButton){
172  OKButtonUsed = true;
173  this.setVisible(false);
174  }
175  }//GEN-LAST:event_OKButtonActionPerformed
176 
177 
178  public File getNXDLFile(){
179  return nxdl;
180  }
181 
182  public void setNXDLFile(File file){
183  nxdl = file;
184  nxdcTextField.setText(nxdl.getAbsolutePath());
185  }
186 
187  public boolean OKButtonUsed(){
188  return OKButtonUsed;
189  }
190 
194  public static void main(String args[]) {
195  java.awt.EventQueue.invokeLater(new Runnable() {
196  public void run() {
197  NXValidateDialog dialog = new NXValidateDialog(new javax.swing.JFrame(), true);
198  dialog.addWindowListener(new java.awt.event.WindowAdapter() {
199  public void windowClosing(java.awt.event.WindowEvent e) {
200  System.exit(0);
201  }
202  });
203  dialog.setVisible(true);
204  }
205  });
206  }
207 
208  // Variables declaration - do not modify//GEN-BEGIN:variables
209  private javax.swing.JButton OKButton;
210  private javax.swing.JButton cancelButton;
211  private javax.swing.JFileChooser jFileChooser1;
212  private javax.swing.JPanel jPanel1;
213  private javax.swing.JLabel nxdcLabel;
214  private javax.swing.JTextField nxdcTextField;
215  private javax.swing.JButton openButton2;
216  // End of variables declaration//GEN-END:variables
217 
218 }