source: domaineditor/src/main/java/geniusweb/actions/SaveDomainAction.java@ 53

Last change on this file since 53 was 52, checked in by ruud, 21 months ago

Fixed small issues in domaineditor.

File size: 1.6 KB
Line 
1package geniusweb.actions;
2
3import java.awt.event.ActionEvent;
4import java.awt.event.KeyEvent;
5import java.io.File;
6import java.util.logging.Level;
7
8import javax.swing.JFileChooser;
9import javax.swing.KeyStroke;
10import javax.swing.filechooser.FileNameExtensionFilter;
11
12import geniusweb.domaineditor.ProfileEditor;
13import geniusweb.domaineditor.model.profile.LinearAdditiveUtilitySpaceModel;
14import geniusweb.issuevalue.Domain;
15import tudelft.utilities.logging.Reporter;
16
17public class SaveDomainAction extends GuiAction {
18
19 public SaveDomainAction(Reporter log) {
20 super("Save Domain", log);
21 putValue(SHORT_DESCRIPTION, "Save the domain only");
22 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S,
23 ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
24 }
25
26 @Override
27 public void actionPerformed(ActionEvent e) {
28 save(ProfileEditor.getInstance().getModel());
29 }
30
31 /**
32 * Save a model.
33 *
34 * @param model the {@link LinearAdditiveUtilitySpaceModel} to be saved
35 */
36 protected void save(LinearAdditiveUtilitySpaceModel model) {
37
38 try {
39 Domain domain = model.getCurrentValue().getDomain();
40 JFileChooser chooser = new JFileChooser();
41 chooser.setSelectedFile(new File(domain.getName() + ".json"));
42 FileNameExtensionFilter filter = new FileNameExtensionFilter(
43 "JSON file", "json");
44 chooser.setFileFilter(filter);
45 int selection = chooser.showSaveDialog(null);
46 if (selection != JFileChooser.APPROVE_OPTION)
47 return;
48 File file = chooser.getSelectedFile();
49 jackson.writeValue(file, domain);
50 } catch (Exception e) {
51 log.log(Level.WARNING, "Failed to save:" + e.getMessage());
52 e.printStackTrace();
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.