/**
* Copyright (c) 2014, the Temporal Random Indexing AUTHORS.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Bari nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007
*
*/
package di.uniba.it.tri.shell.gui;
import di.uniba.it.tri.shell.gui.data.Options;
import javax.swing.JFileChooser;
/**
*
* @author pierpaolo
*/
public class OptionsDialog extends javax.swing.JDialog {
private Options options;
/**
* Creates new form Options
*/
public OptionsDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
searchOptionPanel = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
tfIndex = new javax.swing.JTextField();
openIndexButton = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
tfId = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
tfText = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
tfSource = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
tfPub = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
tfDateformat = new javax.swing.JTextField();
triOptionPanel = new javax.swing.JPanel();
lTri = new javax.swing.JLabel();
tfTri = new javax.swing.JTextField();
openTriButton = new javax.swing.JButton();
bottonPanel = new javax.swing.JPanel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Options");
setPreferredSize(new java.awt.Dimension(500, 400));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.PAGE_AXIS));
searchOptionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Search"));
searchOptionPanel.setPreferredSize(new java.awt.Dimension(400, 300));
searchOptionPanel.setLayout(new java.awt.GridBagLayout());
jLabel1.setText("Index");
searchOptionPanel.add(jLabel1, new java.awt.GridBagConstraints());
tfIndex.setColumns(20);
tfIndex.setText("<empty>");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 2;
searchOptionPanel.add(tfIndex, gridBagConstraints);
openIndexButton.setText("Open...");
openIndexButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openIndexButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 0;
searchOptionPanel.add(openIndexButton, gridBagConstraints);
jLabel2.setText("Doc id field");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
searchOptionPanel.add(jLabel2, gridBagConstraints);
tfId.setColumns(20);
tfId.setText("id");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
searchOptionPanel.add(tfId, gridBagConstraints);
jLabel3.setText("Text fields");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
searchOptionPanel.add(jLabel3, gridBagConstraints);
tfText.setColumns(20);
tfText.setText("title:content");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 2;
searchOptionPanel.add(tfText, gridBagConstraints);
jLabel4.setText("Source field");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
searchOptionPanel.add(jLabel4, gridBagConstraints);
tfSource.setColumns(20);
tfSource.setText("source");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
searchOptionPanel.add(tfSource, gridBagConstraints);
jLabel5.setText("Published field");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
searchOptionPanel.add(jLabel5, gridBagConstraints);
tfPub.setColumns(20);
tfPub.setText("published");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 2;
searchOptionPanel.add(tfPub, gridBagConstraints);
jLabel6.setText("Date format");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
searchOptionPanel.add(jLabel6, gridBagConstraints);
tfDateformat.setColumns(20);
tfDateformat.setText("EEE MMM dd HH:mm:ss 'CEST' yyyy");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = 2;
searchOptionPanel.add(tfDateformat, gridBagConstraints);
getContentPane().add(searchOptionPanel);
triOptionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Temporal RI"));
triOptionPanel.setPreferredSize(new java.awt.Dimension(400, 120));
triOptionPanel.setLayout(new java.awt.GridBagLayout());
lTri.setText("TRI folder");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
triOptionPanel.add(lTri, gridBagConstraints);
tfTri.setColumns(20);
tfTri.setText("<empty>");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
triOptionPanel.add(tfTri, gridBagConstraints);
openTriButton.setText("Open...");
openTriButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openTriButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 4);
triOptionPanel.add(openTriButton, gridBagConstraints);
getContentPane().add(triOptionPanel);
bottonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
okButton.setText("Ok");
okButton.setPreferredSize(new java.awt.Dimension(64, 31));
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
bottonPanel.add(okButton);
cancelButton.setText("Cancel");
cancelButton.setPreferredSize(new java.awt.Dimension(64, 31));
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
bottonPanel.add(cancelButton);
getContentPane().add(bottonPanel);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void openIndexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openIndexButtonActionPerformed
JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
fc.setDialogTitle("Open index...");
fc.setDialogType(JFileChooser.OPEN_DIALOG);
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
tfIndex.setText(fc.getSelectedFile().getAbsolutePath());
}
}//GEN-LAST:event_openIndexButtonActionPerformed
private void openTriButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openTriButtonActionPerformed
JFileChooser fc = new JFileChooser(System.getProperty("user.home"));
fc.setDialogTitle("Open TRI space...");
fc.setDialogType(JFileChooser.OPEN_DIALOG);
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
tfTri.setText(fc.getSelectedFile().getAbsolutePath());
}
}//GEN-LAST:event_openTriButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
options = null;
this.dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
options = new Options();
options.setId(tfId.getText());
if (tfIndex.getText().equals("<empty>")) {
options.setIndex(null);
} else {
options.setIndex(tfIndex.getText());
}
options.setPublished(tfPub.getText());
options.setSource(tfSource.getText());
options.setText(tfText.getText().split(":"));
if (tfTri.getText().equals("<empty>")) {
options.setTriFolder(null);
} else {
options.setTriFolder(tfTri.getText());
}
options.setDateFormat(tfDateformat.getText());
this.dispose();
}//GEN-LAST:event_okButtonActionPerformed
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
options = null;
}//GEN-LAST:event_formWindowClosing
public Options getOptions() {
return options;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(OptionsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(OptionsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(OptionsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(OptionsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
OptionsDialog dialog = new OptionsDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel bottonPanel;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel lTri;
private javax.swing.JButton okButton;
private javax.swing.JButton openIndexButton;
private javax.swing.JButton openTriButton;
private javax.swing.JPanel searchOptionPanel;
private javax.swing.JTextField tfDateformat;
private javax.swing.JTextField tfId;
private javax.swing.JTextField tfIndex;
private javax.swing.JTextField tfPub;
private javax.swing.JTextField tfSource;
private javax.swing.JTextField tfText;
private javax.swing.JTextField tfTri;
private javax.swing.JPanel triOptionPanel;
// End of variables declaration//GEN-END:variables
}