NXvalidate  1
 All Classes Namespaces Files Functions Variables
NXSettingsDialog.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 NXSettingsDialog extends javax.swing.JDialog {
37 
38 
39  private String nxconvert = null;
40  private boolean OKButtonUsed = false;
42  public NXSettingsDialog(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("Location of nxconvert binary file:");
71 
72  openButton2.setText("Open");
73  openButton2.addActionListener(new java.awt.event.ActionListener() {
74  public void actionPerformed(java.awt.event.ActionEvent evt) {
75  openButton2ActionPerformed(evt);
76  }
77  });
78 
79  cancelButton.setText("CANCEL");
80  cancelButton.addActionListener(new java.awt.event.ActionListener() {
81  public void actionPerformed(java.awt.event.ActionEvent evt) {
82  cancelButtonActionPerformed(evt);
83  }
84  });
85 
86  OKButton.setText("OK");
87  OKButton.addActionListener(new java.awt.event.ActionListener() {
88  public void actionPerformed(java.awt.event.ActionEvent evt) {
89  OKButtonActionPerformed(evt);
90  }
91  });
92 
93  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
94  jPanel1.setLayout(jPanel1Layout);
95  jPanel1Layout.setHorizontalGroup(
96  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
97  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
98  .addContainerGap()
99  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
100  .addGroup(jPanel1Layout.createSequentialGroup()
101  .addComponent(cancelButton)
102  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 655, Short.MAX_VALUE)
103  .addComponent(OKButton))
104  .addGroup(jPanel1Layout.createSequentialGroup()
105  .addComponent(nxdcLabel)
106  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
107  .addComponent(nxdcTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
108  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
109  .addComponent(openButton2)))
110  .addGap(23, 23, 23))
111  );
112  jPanel1Layout.setVerticalGroup(
113  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
114  .addGroup(jPanel1Layout.createSequentialGroup()
115  .addGap(10, 10, 10)
116  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
117  .addComponent(nxdcLabel)
118  .addComponent(nxdcTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
119  .addComponent(openButton2))
120  .addGap(18, 18, 18)
121  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
122  .addComponent(OKButton)
123  .addComponent(cancelButton))
124  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
125  );
126 
127  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
128  getContentPane().setLayout(layout);
129  layout.setHorizontalGroup(
130  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131  .addGroup(layout.createSequentialGroup()
132  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
133  .addContainerGap())
134  );
135  layout.setVerticalGroup(
136  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
138  );
139 
140  pack();
141  }// </editor-fold>//GEN-END:initComponents
142 
143  private void openButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButton2ActionPerformed
144 
145  if(evt.getSource() == openButton2){
146 
147  int returnVal = jFileChooser1.showOpenDialog(this);
148 
149  if (returnVal == jFileChooser1.APPROVE_OPTION) {
150  nxconvert = jFileChooser1.getSelectedFile().getAbsolutePath();
151  nxdcTextField.setText(nxconvert);
152  nxdcTextField.setToolTipText(nxconvert);
153  } else {
154  nxconvert = null;
155  }
156 
157  }
158 }//GEN-LAST:event_openButton2ActionPerformed
159 
160  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
161  if(evt.getSource() == cancelButton){
162  OKButtonUsed = false;
163  this.setVisible(false);
164  }
165 }//GEN-LAST:event_cancelButtonActionPerformed
166 
167  private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
168 
169  if(evt.getSource() == OKButton){
170  OKButtonUsed = true;
171  nxconvert = nxdcTextField.getText();
172  this.setVisible(false);
173  }
174  }//GEN-LAST:event_OKButtonActionPerformed
175 
176 
177  public String getNXConvertFile(){
178  return nxconvert;
179  }
180 
181  public void setNXConvertCommand(String nxconvert){
182  nxconvert = nxconvert;
183  nxdcTextField.setText(nxconvert);
184  }
185 
186  public boolean OKButtonUsed(){
187  return OKButtonUsed;
188  }
189 
193  public static void main(String args[]) {
194  java.awt.EventQueue.invokeLater(new Runnable() {
195  public void run() {
196  NXSettingsDialog dialog = new NXSettingsDialog(new javax.swing.JFrame(), true);
197  dialog.addWindowListener(new java.awt.event.WindowAdapter() {
198  public void windowClosing(java.awt.event.WindowEvent e) {
199  System.exit(0);
200  }
201  });
202  dialog.setVisible(true);
203  }
204  });
205  }
206 
207  // Variables declaration - do not modify//GEN-BEGIN:variables
208  private javax.swing.JButton OKButton;
209  private javax.swing.JButton cancelButton;
210  private javax.swing.JFileChooser jFileChooser1;
211  private javax.swing.JPanel jPanel1;
212  private javax.swing.JLabel nxdcLabel;
213  private javax.swing.JTextField nxdcTextField;
214  private javax.swing.JButton openButton2;
215  // End of variables declaration//GEN-END:variables
216 
217 }