Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30841/src/net/sourceforge/bprocessor/gui
Modified Files:
GUI.java
Log Message:
Refactoring
Index: GUI.java
===================================================================
RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/GUI.java,v
retrieving revision 1.113
retrieving revision 1.114
diff -C2 -d -r1.113 -r1.114
*** GUI.java 14 Sep 2009 16:22:52 -0000 1.113
--- GUI.java 12 Nov 2009 15:27:24 -0000 1.114
***************
*** 8,11 ****
--- 8,12 ----
import net.sourceforge.bprocessor.gui.actions.AboutActionListener;
+ import net.sourceforge.bprocessor.gui.actions.BProcessorFileFilter;
import net.sourceforge.bprocessor.gui.actions.EditMenuListener;
import net.sourceforge.bprocessor.gui.actions.FileCloseActionListener;
***************
*** 26,30 ****
import net.sourceforge.bprocessor.gui.treeview.SpaceTreeView;
import net.sourceforge.bprocessor.model.Geometric;
- import net.sourceforge.bprocessor.model.Persistence;
import net.sourceforge.bprocessor.model.Project;
import net.sourceforge.bprocessor.model.Selection;
--- 27,30 ----
***************
*** 63,66 ****
--- 63,67 ----
import javax.swing.JMenu;
import javax.swing.JMenuItem;
+ import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
***************
*** 164,167 ****
--- 165,241 ----
}
+ public static int confirm(String message) {
+ Component parent = getInstance();
+ int type = JOptionPane.YES_NO_CANCEL_OPTION;
+ System.out.println("Confirm Dialog.");
+ int result = JOptionPane.showConfirmDialog(parent, message, "", type);
+ System.out.println("Result from the dialog.");
+
+ return result;
+ }
+ public static int confirmSave() {
+ String message = "Do you want to save the changes you made in project \""
+ + Project.getInstance().getName()
+ + "\"?";
+ return GUI.confirm(message);
+ }
+
+ public static File chooseFile(String message) {
+ String path = Project.getInstance().getDefaultPath();
+ JFileChooser chooser = new JFileChooser(path);
+ chooser.addChoosableFileFilter(new BProcessorFileFilter());
+ int state = chooser.showDialog(GUI.getInstance(), message);
+ if (state == JFileChooser.APPROVE_OPTION) {
+ return chooser.getSelectedFile();
+ } else {
+ return null;
+ }
+ }
+
+ public static boolean userSave() throws Exception {
+ if (Project.getInstance().getSavePath() == null) {
+ return userSaveAs();
+ } else {
+ Project.getInstance().save();
+ }
+ return true;
+ }
+
+ public static boolean userSaveAs() throws Exception {
+ File file = GUI.chooseFile("Save");
+
+ if (file != null) {
+ if (file.getName().lastIndexOf('.') != -1) {
+ Project.getInstance().saveAs(file);
+ } else {
+ Project.getInstance().saveAs(new File(file.getCanonicalFile() + ".bp"));
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean userClose() throws Exception {
+ if (Project.getInstance().isDirty()) {
+ int result = GUI.confirmSave();
+
+ if (result == JOptionPane.YES_OPTION) {
+ if (userSave()) {
+ Project.getInstance().close();
+ } else {
+ return false;
+ }
+ } else if (result == JOptionPane.CANCEL_OPTION) {
+ return false;
+ } else {
+ Project.getInstance().close();
+ }
+ } else {
+ Project.getInstance().close();
+ }
+ return true;
+ }
+
/**
*
***************
*** 505,523 ****
fileSaveAs.setEnabled(true);
file.add(fileSaveAs);
-
- JMenuItem saveDBK = new JMenuItem("Save DBK");
- saveDBK.addActionListener(new AbstractAction() {
- public void actionPerformed(ActionEvent e) {
- try {
- Persistence.saveDBK(Project.getConstructionClas(),
- Project.getFunctionalClas(), Project.getClassificationTypes(),
- new File("Classification.xml"));
- } catch (Exception e1) {
- log.error("Error when saving DBK : " + e1.getMessage());
- }
- }
- });
- saveDBK.setEnabled(true);
- file.add(saveDBK);
file.addSeparator();
--- 579,582 ----
***************
*** 752,755 ****
--- 811,822 ----
menu.registerMenu(extraMenu);
}
+
+
+ public void doNew() {
+
+ }
+
+
+
/**
|