Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Tested the Close action. Drafted the Close dialog.
authorpreecej <preecej@localhost>
Thu, 4 Oct 2012 00:59:25 +0000 (00:59 +0000)
committerpreecej <preecej@localhost>
Thu, 4 Oct 2012 00:59:25 +0000 (00:59 +0000)
Save action from Close action works, but only when hard-wired.

Next: Return user choice from SaveReminder dialog to Close action.

svn path=/; revision=387

Annotation/resources/config/application.mac.properties
Annotation/resources/config/application.properties
Annotation/src/ie/dcu/apps/ist/actions/CloseAction.java
Annotation/src/ie/dcu/apps/ist/actions/SaveAction.java
Annotation/src/ie/dcu/apps/ist/dialogs/PrefsDialog.java
Annotation/src/ie/dcu/apps/ist/dialogs/SaveReminderDialog.java

index 5bea2223f386cc76593ed38ab00aad0bf2c36fcc..b4ddf8a15b4e3dfbfa56f678c00510bee4e06223 100644 (file)
@@ -18,6 +18,11 @@ PrefsDialog.experiment-embedded.text=Show experiment panel embedded in main wind
 PrefsDialog.confirm-exit.text=Confirm exit when application is closed
 PrefsDialog.confirm-close.text=Remind to save current work when closing file
 
+# Save Reminder Dialog
+SaveReminderDialog.save.text=&Save
+SaveReminderDialog.no-save.text=&Don't Save
+SaveReminderDialog.cancel.text=&Cancel
+
 # Experiment Panel
 ExperimentPanel.description.title=Task Description 
 ExperimentPanel.timeout-message=The time allocated for this task is up!
index ec7e641d1d8264a10c8486d869f1411f12c8cfc0..a5cde027f920853b4bb5a7ea90b75163fb6f91cd 100644 (file)
@@ -20,6 +20,14 @@ PrefsDialog.experiment-embedded.text=Show experiment panel embedded in main wind
 PrefsDialog.confirm-exit.text=Confirm exit when application is closed
 PrefsDialog.confirm-close.text=Remind to save current work when closing file
 
+# Save Reminder Dialog
+SaveReminderDialog.save.text=&Save
+SaveReminderDialog.save.icon=file:resources/icons/save.png
+SaveReminderDialog.no-save.text=&Don't Save
+SaveReminderDialog.no-save.icon=file:resources/icons/reset.png
+SaveReminderDialog.cancel.text=&Cancel
+SaveReminderDialog.cancel.icon=file:resources/icons/close.png
+
 # Experiment Panel
 ExperimentPanel.description.title=Task Description 
 ExperimentPanel.timeout-message=The time allocated for this task is up!
index 433c88adbdda137e196a1d017245c44853bfe9c8..5b749d1fd293cc9a2173b0f4cd5d3a23c1699cba 100644 (file)
@@ -2,7 +2,12 @@ package ie.dcu.apps.ist.actions;
 
 import ie.dcu.apps.ist.*;
 import ie.dcu.apps.ist.dialogs.SaveReminderDialog;
+
+import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.widgets.MenuItem;
 
 /**
  * Close current image annotation file
@@ -10,22 +15,29 @@ import org.eclipse.jface.dialogs.MessageDialog;
  * @author Justin Preece
  */
 public class CloseAction extends AppAction {
+
        public CloseAction(ActionManager m) {
                super(m);
        }
 
        @Override 
        public void run() {
+               // TODO: add a call to check the confirm close app preference 
+               
                // call Save Reminder dialog
-               SaveReminderDialog dialog = new SaveReminderDialog(window.getShell());
+               SaveReminderDialog dialog = new SaveReminderDialog(window);
                SaveReminderDialog.ResultChoice result = dialog.open();
                
                if (result != null) {
                        // check return choice in result here and fire appropriate action:
                        switch (result) {
                                case SAVE: // save now and then close file ("Save now")
-                                       //TODO: trigger Save dialog to save the file
-                                       window.getView().resetView(); // clear current data and work
+                                       // trigger Save dialog to save the file
+                                       ActionManager actions = window.getActions();
+                                       if (actions != null) {
+                                               SaveAction saveAction = actions.get(SaveAction.class);
+                                               saveAction.runSaveAndClose();
+                                       }
                                        break;
                                case NOSAVE: // do not save and then close file ("I've already saved my work")
                                        window.getView().resetView(); // clear current data and work
@@ -37,7 +49,7 @@ public class CloseAction extends AppAction {
                        }
                }
        }
-       
+
        public static boolean confirmClose(AppWindow window) {
                boolean confirm = window.getPrefs().get(
                                Boolean.class, AppPrefs.Keys.CONFIRM_CLOSE, true);
@@ -50,4 +62,4 @@ public class CloseAction extends AppAction {
                
                return true;
        }
-}
+}
\ No newline at end of file
index a716699b0bfdfc3ef3dd4905465786da441a7a81..47fa3a51273ead44a632546c10d0f977843833cc 100644 (file)
@@ -85,6 +85,59 @@ public class SaveAction extends AppAction {
                }
        }
        
+       public void runSaveAndClose() {
+
+               SegmentationContext ctx = window.getContext();
+               List<SegmentationMask> masks = ctx.getSegmentationMasks();
+               if (ctx.hasSegmentationMasks()) {
+                       
+                       // Get options from user
+                       ExportDialog dialog = new ExportDialog(window.getShell());
+                       ExportDialog.Result result = dialog.open();
+                       
+                       if (result != null) {
+                               // Grab image and mask
+                               BufferedImage image = ImageConverter.convert(ctx.getImageData());
+
+                               // Setup exporter
+                               Exporter exporter = new Exporter(image);
+
+                               // save the annotated zip file
+                               String zipFile = result.zipFile; 
+                               exporter.setZipFile(zipFile+IMGMAP_EXTENSION);
+
+                               exporter.setImageFile(result.image);
+                               exporter.setEffect(result.effect);
+                               exporter.setHtmlFile(zipFile+".html");
+                               exporter.setExportShape(result.shape);
+                               //exporter.setObjectLink(result.link);
+                               //exporter.setObjectDescription(result.description);
+                               
+                               // Export
+                               try {
+                                       exporter.export(result.folder,result.open,result.exportFolder,masks);
+                               } catch (IOException e) {
+                                       handleError(e);
+                                       return;
+                               } catch (ExportException e) {
+                                       handleError(e);
+                                       return;
+                               } 
+                                       
+                               // for opening the image after saving as ImageMap
+                               if (result.open) {
+                                       File file = new File(result.exportFolder, result.html);
+                                       Program program = Program.findProgram(".html");
+                                       if (program != null) {
+                                               program.execute(file.getAbsolutePath());
+                                       }
+                               }
+                               window.getView().resetView(); // clear current data and work
+                       }
+               }
+       }
+
+       
        private void handleError(Exception e) {
                log(Level.WARNING, "Error exporting view as HTML image map", e);
                
index e2d453af48598c3ce34de4faa7201fcb6b5eaf8d..7102e0a8e54a3070420f74863e49f5e0d43b4791 100644 (file)
@@ -178,7 +178,6 @@ public class PrefsDialog {
                return control;
        }
        
-       
        private Button createResetButton() {
                // Create button
                Button bt = createButton(buttonBar, RESET, SWT.PUSH);
index 5f2e16f9bb691d5a3a982b6c5bfac82cb9000294..ea2252b1343be451096449b92a7fb7a83b0963a5 100644 (file)
 package ie.dcu.apps.ist.dialogs;
 
-import ie.dcu.apps.ist.dialogs.ExportDialog.Result;
-import ie.dcu.apps.ist.export.imagemap.AreaShape;
-import ie.dcu.apps.ist.export.imagemap.RolloverEffect;
-
-import java.io.File;
-
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
+import ie.dcu.apps.ist.*;
+import ie.dcu.apps.ist.AppPrefs.Keys;
+import ie.dcu.apps.ist.widgets.ColorSelector;
+import ie.dcu.swt.SwtUtils;
+import ie.dcu.swt.layout.LayoutFactory;
+
+import java.util.*;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+
+public class SaveReminderDialog {
+       private static final String QUESTION = "Do you wish to save your work before closing this file?";
+       private static final String SAVE_TEXT = "Save now and then close this file.";
+       private static final String NOSAVE_TEXT = "Do NOT save this file; just close it.";
+       private static final String CANCEL_TEXT = "Do not close this file.";
+
+       private final AppWindow window;
+       private final Shell shell;
+       private final Composite content;
+       private final Composite buttonBar;
+       private final Button saveButton;
+       private final Button noSaveButton;
+       private final Button cancelButton;
+       private final HashMap<String, Object> controls;
+       private ResultChoice choice;
+       
+       private transient GridData gd;
+
+       public SaveReminderDialog(AppWindow window) {
+               this.window = window;
+               this.shell = createShell();
+               this.content = createContent();
 
-public class SaveReminderDialog extends Dialog {
+               createControls();
 
-       public SaveReminderDialog(Shell shell) {
-               super(shell);
-               setText(TITLE);
+               this.buttonBar = createButtonBar();
+               this.saveButton = createSaveButton();
+               this.noSaveButton = createNoSaveButton();
+               this.cancelButton = createCancelButton();
+               this.controls = new HashMap<String, Object>();
+               
+               SwtUtils.center(window.getShell(), shell);
        }
 
        public enum ResultChoice {
                SAVE, NOSAVE, CANCEL
        }
        
-       // Default title
-       private static final String TITLE = "Save Reminder";
-
        public ResultChoice open() {
-               //TODO: build dialog UI here
-               return ResultChoice.SAVE;
+               shell.setVisible(true);
+               // TODO: can't return this early; look at ExportDialog for example; need to return choice via close 
+               // or remove close and return here AFTER choice is made
+               return choice;
+       }
+
+       public void close() {
+               shell.setVisible(false);
+       }
+
+       private void createControls() {
+               createBanner(content, QUESTION);
+               // TODO: replace "button bar" with 2-col grid...labels on the left, buttons on the right in 3 rows
+       }
+
+       private Shell createShell() {
+               Shell s = new Shell(window.getShell(), SWT.SHELL_TRIM | SWT.SHEET);
+               
+               // Add listener
+               s.addListener(SWT.Close, adapter);
+               
+               // Use a fill layout
+               s.setLayout(new FillLayout());
+               
+               // Set size and title
+               s.setSize(420, 250);
+               s.setText(property("save-reminder", "Save Reminder"));
+               
+               return s;
+       }
+       
+       
+       private Composite createContent() {
+               
+               // Create content pane with grid layout
+               Composite c = new Composite(shell, 0);
+               c.setLayout(new GridLayout());
+               return c;
+       }
+       
+       private Label createBanner(Composite comp, String key) {
+               // Create label
+               Label lb = new Label(comp, SWT.NONE);
+               lb.setText(property(key, key));
+               lb.setFont(JFaceResources.getBannerFont());
+               
+               // Layout label
+               gd = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1);
+               gd.verticalIndent = 5;
+               lb.setLayoutData(gd);
+               
+               return lb;
+       }
+       
+       private Composite createButtonBar() {
+               // Create bar
+               Composite bar = new Composite(content, SWT.NONE);
+               
+               // Layout bar
+               bar.setLayout(LayoutFactory.createGridLayout(0, 0, 3, true));
+               bar.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
+               
+               return bar;
+       }
+       
+       private Button createSaveButton() {
+               // Create button
+               Button bt = createButton(buttonBar, "save", SWT.PUSH);
+               
+               // Layout button
+               gd = new GridData(SWT.LEFT, SWT.BOTTOM, true, false);
+               gd.minimumWidth = 85;
+               bt.setLayoutData(gd);
+               
+               // Done
+               return bt;
        }
-}
+       
+       private Button createNoSaveButton() {
+               // Create button
+               Button bt = createButton(buttonBar, "no-save", SWT.PUSH);
+               
+               // Layout button
+               gd = new GridData(SWT.CENTER, SWT.BOTTOM, true, false);
+               gd.minimumWidth = 85;
+               bt.setLayoutData(gd);
+               
+               // Done
+               return bt;
+       }
+
+       private Button createCancelButton() {
+               // Create button
+               Button bt = createButton(buttonBar, "cancel", SWT.PUSH);
+               
+               // Layout button
+               gd = new GridData(SWT.RIGHT, SWT.BOTTOM, true, false);
+               gd.minimumWidth = 85;
+               bt.setLayoutData(gd);
+               
+               // Done
+               return bt;
+       }
+
+       private Label createLabel(Composite content, String key) {
+               // Create label
+               Label lb = new Label(content, SWT.NONE);
+               lb.setText(property(key, "text", key));
+               
+               // Layout label
+               gd = new GridData(SWT.LEFT, SWT.CENTER, true, false);
+               gd.horizontalIndent = 5;
+               lb.setLayoutData(gd);
+               
+               return lb;
+       }
+       
+       private Button createButton(Composite parent, String key, int style) {
+               Button bt = new Button(parent, style);
+               
+               // Configure button
+               configure(bt, key);
+               
+               // Add listener
+               bt.addListener(SWT.Selection, adapter);
+               
+               // Done
+               return bt;
+       }       
+       
+       protected void handleEvent(Event event) {
+               switch (event.type) {
+               case SWT.Close:
+                       handleClose(event);
+                       break;
+               case SWT.Selection:
+                       handleSelection(event);
+                       break;
+               }
+               
+       }
+
+       private void handleClose(Event event) {
+               // Prevent the shell from disposing on close
+               event.doit = false;
+               close();
+       }
+
+       private void handleSelection(Event event) {
+               if (event.widget == saveButton) {
+                       choice = ResultChoice.SAVE;
+                       close();
+               } else if (event.widget == noSaveButton) {
+                       this.choice = ResultChoice.NOSAVE;
+                       close();
+               } else if (event.widget == cancelButton) {
+                       this.choice = ResultChoice.CANCEL;
+                       close();
+               }
+       }
+       
+       private void configure(Button bt, String key) {
+               // Read properties
+               String text = property(key, "text", "");
+               String icon = property(key, "icon", null);
+               String ttip = property(key, "ttip", null);
+               
+               // Set values
+               bt.setText(text);
+               bt.setImage(image(icon));
+               bt.setToolTipText(ttip);
+               bt.setData(key);
+       }
+       
+       private <T> T control(Class<T> clazz, String key) {
+               return clazz.cast(controls.get(key));
+       }
+
+       private String property(String key, String def) {
+               Properties p = window.getProperties();
+               return p.getProperty(String.format("SaveReminderDialog.%s", key), def);
+       }
+       
+       private String property(String key, String type, String def) {
+               Properties p = window.getProperties();
+               String prop = String.format("SaveReminderDialog.%s.%s", key, type);
+               return p.getProperty(prop, def);
+       }
+       
+       private Image image(String url) {
+               return (url != null) ? window.getIcon(url) :  null;
+       }
+
+       private final Listener adapter = new Listener() {
+               public void handleEvent(Event event) {
+                       SaveReminderDialog.this.handleEvent(event);
+               }               
+       };
+}
\ No newline at end of file