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
|
protected void saveProjectAsMenuItem_action(ActionEvent e)
{
// opens the file chooser
JFileChooser fc = new JFileChooser(".");
fc.setFileFilter(new DaresProjectFilter());
fc.setDialogType(JFileChooser.SAVE_DIALOG );
fc.showSaveDialog(null);
File selectedFile = fc.getSelectedFile();
fc = null;
if (selectedFile != null && selectedFile.getName().endsWith(".rpj"))
{
System.out.println("Début enregistrement");
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try
{
//opening of output stream
FileOutputStream fos = new FileOutputStream(selectedFile);
// creation of object stream starting from output sream
ObjectOutputStream oos= new ObjectOutputStream(fos);
try
{
// sérialization : writing of binary data
oos.writeObject(this);
// Emptying of the plug
oos.flush();
}
finally
{
//closing of streams
try
{
oos.close();
}
finally
{
fos.close();
}
}
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
this.project = selectedFile;
this.saveSelectionMenuItem.setEnabled(true);
this.infoLabel.setText("Saved project : " + selectedFile.getName());
System.out.println("Fin enregistrement");
setCursor(null);
}
} |
Partager