package com.compomics.util.gui;
import com.compomics.util.io.export.ExportFormat;
import javax.swing.JDialog;
import javax.swing.JFrame;
/**
* Simple dialog for selecting the format type to export to.
*
* @author Harald Barsnes
*/
public class ExportFormatSelectionDialog extends javax.swing.JDialog {
/**
* True if the user canceled the dialog.
*/
private boolean canceled = false;
/**
* Create and open a new ExportFormatSelectionDialog.
*
* @param frame the parent frame
* @param modal if the dialog is modal or not
*/
public ExportFormatSelectionDialog(JFrame frame, boolean modal) {
super(frame, modal);
initComponents();
setLocationRelativeTo(frame);
setVisible(true);
}
/**
* Create and open a new ExportFormatSelectionDialog.
*
* @param dialog the parent dialog (has to have a parent JFrame)
* @param modal if the dialog is modal or not
*/
public ExportFormatSelectionDialog(JDialog dialog, boolean modal) {
super(dialog, modal);
initComponents();
setLocationRelativeTo(dialog);
setVisible(true);
}
/**
* Returns true of the user canceled the dialog.
*
* @return true of the user canceled the dialog
*/
public boolean isCanceled() {
return canceled;
}
/**
* Returns the selected format.
*
* @return the selected format
*/
public ExportFormat getFormat() {
if (textJRadioButton.isSelected()) {
return ExportFormat.text;
} else {
return ExportFormat.excel;
}
}
/**
* 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() {
buttonGroup = new javax.swing.ButtonGroup();
backgroundPanel = new javax.swing.JPanel();
formatTypeJPanel = new javax.swing.JPanel();
textJRadioButton = new javax.swing.JRadioButton();
excelJRadioButton = new javax.swing.JRadioButton();
exportJButton = new javax.swing.JButton();
cancelJButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Export Format");
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
backgroundPanel.setBackground(new java.awt.Color(230, 230, 230));
formatTypeJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Format"));
formatTypeJPanel.setOpaque(false);
buttonGroup.add(textJRadioButton);
textJRadioButton.setSelected(true);
textJRadioButton.setText("Tab Separated Text File");
textJRadioButton.setIconTextGap(15);
textJRadioButton.setOpaque(false);
buttonGroup.add(excelJRadioButton);
excelJRadioButton.setText("Excel Workbook");
excelJRadioButton.setIconTextGap(15);
excelJRadioButton.setOpaque(false);
javax.swing.GroupLayout formatTypeJPanelLayout = new javax.swing.GroupLayout(formatTypeJPanel);
formatTypeJPanel.setLayout(formatTypeJPanelLayout);
formatTypeJPanelLayout.setHorizontalGroup(
formatTypeJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(formatTypeJPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(formatTypeJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(excelJRadioButton)
.addComponent(textJRadioButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
formatTypeJPanelLayout.setVerticalGroup(
formatTypeJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(formatTypeJPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(textJRadioButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(excelJRadioButton)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
exportJButton.setText("OK");
exportJButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exportJButtonActionPerformed(evt);
}
});
cancelJButton.setText("Cancel");
cancelJButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelJButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel);
backgroundPanel.setLayout(backgroundPanelLayout);
backgroundPanelLayout.setHorizontalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(formatTypeJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addGap(0, 133, Short.MAX_VALUE)
.addComponent(exportJButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelJButton)))
.addContainerGap())
);
backgroundPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelJButton, exportJButton});
backgroundPanelLayout.setVerticalGroup(
backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(backgroundPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(formatTypeJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelJButton)
.addComponent(exportJButton))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Close the dialog.
*
* @param evt
*/
private void exportJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportJButtonActionPerformed
canceled = false;
this.setVisible(false);
this.dispose();
}//GEN-LAST:event_exportJButtonActionPerformed
/**
* Close the dialog.
*
* @param evt
*/
private void cancelJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelJButtonActionPerformed
canceled = true;
this.setVisible(false);
this.dispose();
}//GEN-LAST:event_cancelJButtonActionPerformed
/**
* Cancel the dialog.
*
* @param evt
*/
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
canceled = true;
}//GEN-LAST:event_formWindowClosing
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel backgroundPanel;
private javax.swing.ButtonGroup buttonGroup;
private javax.swing.JButton cancelJButton;
private javax.swing.JRadioButton excelJRadioButton;
private javax.swing.JButton exportJButton;
private javax.swing.JPanel formatTypeJPanel;
private javax.swing.JRadioButton textJRadioButton;
// End of variables declaration//GEN-END:variables
}