/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * XmlPExportDialog.java * * Created on 3 déc. 2010, 22:45:16 */ package feuille.karaoke.dialog; import javax.swing.DefaultListModel; import javax.swing.JFileChooser; import feuille.lib.Language; /** * <p>This is a dialog for the choice of collection to export.<br /> * C'est une boîte de dialogue pour le choix de collection à exporter.</p> * @author The Wingate 2940 */ public class XmlPExportDialog extends javax.swing.JDialog { private ButtonPressed bp; private DefaultListModel dtm; private String[] pack = new String[2]; private Language localeLanguage = feuille.MainFrame.getLanguage(); public enum ButtonPressed{ NONE, OK_BUTTON, CANCEL_BUTTON; } /** <p>Creates new form XmlPExportDialog.<br /> * Crée un nouveau formulaire XmlPExportDialog.</p> */ public XmlPExportDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); dtm = new DefaultListModel(); lstExport.setModel(dtm); if(localeLanguage.getValueOf("titleXPED")!=null){setTitle(localeLanguage.getValueOf("titleXPED"));} if(localeLanguage.getValueOf("buttonOk")!=null){OK_Button.setText(localeLanguage.getValueOf("buttonOk"));} if(localeLanguage.getValueOf("buttonCancel")!=null){Cancel_Button.setText(localeLanguage.getValueOf("buttonCancel"));} if(localeLanguage.getValueOf("buttonChange")!=null){btnFileSave.setText(localeLanguage.getValueOf("buttonChange"));} if(localeLanguage.getValueOf("messExport")!=null){lblExport.setText(localeLanguage.getValueOf("messExport"));} if(localeLanguage.getValueOf("messExportSave")!=null){lblFileSave.setText(localeLanguage.getValueOf("messExportSave"));} } /** 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() { fcFileSave = new javax.swing.JFileChooser(); lblExport = new javax.swing.JLabel(); spExport = new javax.swing.JScrollPane(); lstExport = new javax.swing.JList(); lblFileSave = new javax.swing.JLabel(); tfFileSave = new javax.swing.JTextField(); btnFileSave = new javax.swing.JButton(); OK_Button = new javax.swing.JButton(); Cancel_Button = new javax.swing.JButton(); fcFileSave.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Collection exporter"); lblExport.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblExport.setText("<html><h3>Please select the collection to export."); lstExport.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); spExport.setViewportView(lstExport); lblFileSave.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblFileSave.setText("<html><h3>Please select where the file must be saved."); btnFileSave.setText("Change"); btnFileSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFileSaveActionPerformed(evt); } }); OK_Button.setText("OK"); OK_Button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { OK_ButtonActionPerformed(evt); } }); Cancel_Button.setText("Cancel\n"); Cancel_Button.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Cancel_ButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblFileSave, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE) .addComponent(spExport, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE) .addComponent(lblExport, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(btnFileSave, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tfFileSave, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(OK_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Cancel_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(lblExport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(spExport, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblFileSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnFileSave) .addComponent(tfFileSave, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Cancel_Button) .addComponent(OK_Button)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void OK_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OK_ButtonActionPerformed bp = ButtonPressed.OK_BUTTON; dispose(); }//GEN-LAST:event_OK_ButtonActionPerformed private void Cancel_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cancel_ButtonActionPerformed bp = ButtonPressed.CANCEL_BUTTON; dispose(); }//GEN-LAST:event_Cancel_ButtonActionPerformed private void btnFileSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFileSaveActionPerformed int z = fcFileSave.showOpenDialog(this); if(z==JFileChooser.APPROVE_OPTION){ tfFileSave.setText(fcFileSave.getSelectedFile().getPath()); pack[1] = fcFileSave.getSelectedFile().getPath(); } }//GEN-LAST:event_btnFileSaveActionPerformed /** <p>Show the dialog and wait for a font choosen by user.<br /> * Montre la dialogue et attent une police choisit par l'utilisateur.</p> */ public String[] showDialog(java.util.List<String> lstr){ for(String se : lstr){ if(!dtm.contains(se)){ dtm.addElement(se); } } setVisible(true); if(bp.equals(ButtonPressed.OK_BUTTON)){ pack[0] = (String)lstExport.getSelectedValue(); return pack; }else{ return new String[2]; } } /** <p>Return the selected collection.<br /> * Retourne la collection selectionnée.</p> */ public String getSelectedCollection(){ return (String)lstExport.getSelectedValue(); } /** <p>Return a path for saving.<br /> * Retourne un chemin de sauvegarde.</p> */ public String getSavePath(){ return tfFileSave.getText(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { XmlPExportDialog dialog = new XmlPExportDialog(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.JButton Cancel_Button; private javax.swing.JButton OK_Button; private javax.swing.JButton btnFileSave; private javax.swing.JFileChooser fcFileSave; private javax.swing.JLabel lblExport; private javax.swing.JLabel lblFileSave; private javax.swing.JList lstExport; private javax.swing.JScrollPane spExport; private javax.swing.JTextField tfFileSave; // End of variables declaration//GEN-END:variables }