@@ -1,5 +1,7 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* La classe principale du logiciel AppThinker.
|
||||
@@ -32,34 +34,143 @@ public class AppThinker {
|
||||
*/
|
||||
public static void newProject(){
|
||||
_project = new Project();
|
||||
_window.setTitle("AppThinker | " + _project.getName());
|
||||
_window.getMenubar().setProjectEnable(true);
|
||||
_project.getUmlDiagram().getToolbar().setEnabled(true);
|
||||
_window.getStatusbar().setStatusMessage("The project was created.");
|
||||
displayProject();
|
||||
_window.getStatusbar().setFileMessage(_project.getName());
|
||||
_window.setProject(_project);
|
||||
AppThinker.getProject().getUmlDiagram().displayDiagram();
|
||||
_project.getUmlDiagram().displayDiagram();
|
||||
_window.getStatusbar().setStatusMessage("The project was created.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Opère les modifications nécessaires sur la fenêtre pour accueillir le projet.
|
||||
*/
|
||||
public static void displayProject(){
|
||||
|
||||
_window.setTitle((_project.getPath() == null) ? "AppThinker - " + _project.getName() + "*" : "AppThinker - " + _project.getName() + " (" + _project.getPath() + ")");
|
||||
_window.getMenubar().setProjectEnable(true);
|
||||
_project.getUmlDiagram().getToolbar().setEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ouvre un projet existant dans la fenêtre.
|
||||
*/
|
||||
public static void openProject(){
|
||||
//_window.getGrid().repaint();
|
||||
FileNameExtensionFilter fileFilter = new FileNameExtensionFilter("AppThinker project", "appt");
|
||||
JFileChooser dialog = new JFileChooser();
|
||||
dialog.setDialogType(JFileChooser.OPEN_DIALOG);
|
||||
dialog.setDialogTitle("Open an AppThinker project");
|
||||
dialog.setFileFilter(fileFilter);
|
||||
dialog.setAcceptAllFileFilterUsed(false);
|
||||
if(dialog.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
|
||||
ObjectInputStream ois = null;
|
||||
Project project = null;
|
||||
try {
|
||||
final FileInputStream fichier = new FileInputStream(dialog.getSelectedFile().getPath());
|
||||
ois = new ObjectInputStream(fichier);
|
||||
project = (Project) ois.readObject();
|
||||
} catch (final java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (ois != null) {
|
||||
ois.close();
|
||||
_project = project;
|
||||
_window.getStatusbar().setFileMessage(_project.getName());
|
||||
_window.setProject(_project);
|
||||
_project.getUmlDiagram().displayDiagram();
|
||||
displayProject();
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sauvegarde le projet en cours.
|
||||
*/
|
||||
public static void saveProject(){
|
||||
|
||||
//Si le projet ne contient pas de path, on demande à l'enregistrer dans un emplacement
|
||||
FileNameExtensionFilter fileFilter = new FileNameExtensionFilter("AppThinker project", "appt");
|
||||
String path = _project.getPath();
|
||||
if(path == null){
|
||||
JFileChooser dialog = new JFileChooser();
|
||||
dialog.setDialogTitle("Save an AppThinker project");
|
||||
dialog.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
dialog.setFileFilter(fileFilter);
|
||||
dialog.setAcceptAllFileFilterUsed(false);
|
||||
if(dialog.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
|
||||
String filePath = dialog.getSelectedFile().getPath();
|
||||
path = (filePath.contains(".appt")) ? filePath : filePath + ".appt";
|
||||
}
|
||||
}
|
||||
//On serialize le projet dans un fichier
|
||||
_project.setPath(path);
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
final FileOutputStream fichier = new FileOutputStream(path);
|
||||
oos = new ObjectOutputStream(fichier);
|
||||
oos.writeObject(_project);
|
||||
oos.flush();
|
||||
} catch (final java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (oos != null) {
|
||||
oos.flush();
|
||||
oos.close();
|
||||
displayProject();
|
||||
_window.getStatusbar().setStatusMessage("The project was saved successfully.");
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sauvegarde le projet en cours à un autre emplacement.
|
||||
*/
|
||||
public static void saveAsProject(){
|
||||
//Enregistrer le projet sous un autre emplacement
|
||||
FileNameExtensionFilter fileFilter = new FileNameExtensionFilter("AppThinker project", "appt");
|
||||
String path = _project.getPath();
|
||||
|
||||
JFileChooser dialog = new JFileChooser();
|
||||
dialog.setDialogTitle("Save an AppThinker project");
|
||||
dialog.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
dialog.setFileFilter(fileFilter);
|
||||
dialog.setAcceptAllFileFilterUsed(false);
|
||||
if(dialog.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
|
||||
String filePath = dialog.getSelectedFile().getPath();
|
||||
path = (filePath.contains(".appt")) ? filePath : filePath + ".appt";
|
||||
}
|
||||
|
||||
//On serialize le projet dans un fichier
|
||||
_project.setPath(path);
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
final FileOutputStream fichier = new FileOutputStream(path);
|
||||
oos = new ObjectOutputStream(fichier);
|
||||
oos.writeObject(_project);
|
||||
oos.flush();
|
||||
} catch (final java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (oos != null) {
|
||||
oos.flush();
|
||||
oos.close();
|
||||
displayProject();
|
||||
_window.getStatusbar().setStatusMessage("The project was saved on a new location.");
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +181,7 @@ public class AppThinker {
|
||||
_window.getMenubar().setProjectEnable(false);
|
||||
_project.getUmlDiagram().getToolbar().setEnabled(false);
|
||||
_window.getStatusbar().setStatusMessage("The project has been closed.");
|
||||
_window.getStatusbar().setFileMessage("No open project.");
|
||||
_window.getStatusbar().setFileMessage("No project opened.");
|
||||
_window.clearProject();
|
||||
_project = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user