source: domaineditor/src/main/java/geniusweb/actions/LoadAction.java

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

Fixed small issues in domaineditor.

File size: 1.5 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.profile.utilityspace.LinearAdditiveUtilitySpace;
15import tudelft.utilities.logging.Reporter;
16
17public class LoadAction extends GuiAction {
18
19 public LoadAction(Reporter log) {
20 super("Open", log);
21 putValue(SHORT_DESCRIPTION, "Load the profile");
22 putValue(ACCELERATOR_KEY,
23 KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
24 }
25
26 @Override
27 public void actionPerformed(ActionEvent e) {
28 load(ProfileEditor.getInstance().getModel());
29 }
30
31 public void load(LinearAdditiveUtilitySpaceModel model) {
32 try {
33 JFileChooser chooser = new JFileChooser();
34 FileNameExtensionFilter filter = new FileNameExtensionFilter(
35 "JSON file", "json");
36 chooser.setFileFilter(filter);
37 int selection = chooser.showOpenDialog(null);
38 if (selection != JFileChooser.APPROVE_OPTION)
39 return;
40 File file = chooser.getSelectedFile();
41
42 LinearAdditiveUtilitySpace profi = jackson.readValue(file,
43 LinearAdditiveUtilitySpace.class);
44 model.setCurrentValue(profi);
45 } catch (Exception e1) {
46 log.log(Level.WARNING,
47 "Failed to read file " + ": " + e1.getMessage());
48 e1.printStackTrace();
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.