1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
* MainFrame.java
*
* Created on 19 déc. 2010, 17:26:21
*/
package monPackage;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
/**
*
* @author
*/
public class MainFrame extends javax.swing.JFrame
{
private myJFileChooser fc = new myJFileChooser();
/** Creates new form MainFrame */
public MainFrame()
{
Dimension screenSize;
int H, W;
initComponents();
fc.searchApproveButton(fc);
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
H = getBounds().height;
W = getBounds().width;
setBounds((screenSize.width-W)/2, (screenSize.height-H)/2, W, H);
}
/** 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")
private void initComponents()
{
}
private void jBtnExportActionPerformed(java.awt.event.ActionEvent evt)
{
int response;
boolean flag;
String extension = "";
String fileName = "";
File file = null, srcFile = null;
myFileReader myF = new myFileReader();
response = fc.showOpenDialog(this);
srcFile = fc.getSelectedFile();
flag = true;
if (srcFile!=null)
{
if (srcFile.exists())
{
flag = false;
}
}
if (flag)
return;
flag = true;
do
{
if (response==JFileChooser.APPROVE_OPTION)
{
extension = fc.getSelectedExtension();
fileName = fc.removeExtension(srcFile.getPath());
file = new File(fileName + extension);
if (file.exists())
{
response = JOptionPane.showConfirmDialog(this, "<html>The file "
+ "<font color='#0000FF'>" + file.getName() + "</font>"
+ " already exists. Overwrite ?</html>",
"Title", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
}
if (response==JOptionPane.YES_OPTION || response==JFileChooser.APPROVE_OPTION)
{
flag = false;
try
{
myF.readmyFile(srcFile);
myF.setOutputFile(file);
myF.exportFile(fc.getTitle(), fc.getComments(), fc.getSelectedType());
JOptionPane.showMessageDialog(this,
"Conversion complete !", "Export file",
JOptionPane.INFORMATION_MESSAGE);
}
catch (IOException ex)
{
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(this,
"Error !\n" + ex.getMessage(), "Export file",
JOptionPane.WARNING_MESSAGE);
}
}
}
else
{
flag = false;
}
}while (flag);
file = null;
srcFile = null;
}
private void jBtnQuitActionPerformed(java.awt.event.ActionEvent evt)
{
this.dispose();
}
// Variables declaration - do not modify
private javax.swing.JButton jBtnExport;
private javax.swing.JButton jBtnQuit;
// End of variables declaration
} |
Partager