1 23 24 package org.objectweb.fractal.gui.menu.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.UserData; 29 import org.objectweb.fractal.gui.model.Configuration; 30 import org.objectweb.fractal.swing.AbstractAction; 31 32 import java.awt.event.ActionEvent ; 33 import java.net.URL ; 34 35 import javax.swing.ImageIcon ; 36 import javax.swing.KeyStroke ; 37 import javax.swing.JOptionPane ; 38 import java.io.File ; 39 40 import javax.swing.JFileChooser ; 41 42 45 46 public class ChangeExecDirAction extends AbstractAction 47 implements BindingController 48 { 49 50 54 55 public final static String CONFIGURATION_BINDING = "configuration"; 56 57 public final static String USER_DATA_BINDING = "user-data"; 58 59 62 63 private Configuration configuration; 64 65 private UserData userData; 66 67 70 71 public ChangeExecDirAction () { 72 putValue(NAME, "Storage..."); 73 putValue(SHORT_DESCRIPTION, "Storage..."); 74 URL url = getClass().getResource( 75 "/org/objectweb/fractal/gui/resources/empty.gif"); 76 putValue(SMALL_ICON, new ImageIcon (url)); 77 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control E")); 78 } 79 80 84 public String [] listFc () { 85 return new String [] { CONFIGURATION_BINDING, USER_DATA_BINDING }; 86 } 87 88 public Object lookupFc (final String clientItfName) { 89 if (CONFIGURATION_BINDING.equals(clientItfName)) { 90 return configuration; 91 } else if (USER_DATA_BINDING.equals(clientItfName)) { 92 return userData; 93 } 94 return null; 95 } 96 97 public void bindFc (final String clientItfName, final Object serverItf) { 98 if (CONFIGURATION_BINDING.equals(clientItfName)) { 99 configuration = (Configuration)serverItf; 100 } else if (USER_DATA_BINDING.equals(clientItfName)) { 101 userData = (UserData)serverItf; 102 } 103 } 104 105 public void unbindFc (final String clientItfName) { 106 if (CONFIGURATION_BINDING.equals(clientItfName)) { 107 configuration = null; 108 } else if (USER_DATA_BINDING.equals(clientItfName)) { 109 userData = null; 110 } 111 } 112 113 117 public void actionPerformed (final ActionEvent e) { 118 File f = null; 119 String UD = System.getProperty("user.dir"); 120 File fud = new File (UD); 121 JFileChooser fileChooser = new JFileChooser (); 122 String dir = null; 123 if (userData != null) { 124 try { 125 dir = userData.getStringData(UserData.LAST_EXEC_DIR); 126 } catch (Exception ignored) { 127 } 128 } 129 fileChooser.setCurrentDirectory(dir == null ? fud : new File (dir)); 130 fileChooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); 131 fileChooser.setDialogTitle ("Please, select the storage directory"); 132 if (fileChooser.showOpenDialog (null) != JFileChooser.APPROVE_OPTION) { 133 return; 134 } 135 f = fileChooser.getSelectedFile(); 136 if (!f.isDirectory()) { 137 JOptionPane.showMessageDialog (null, 138 f.getName()+": Invalid directory!", 139 "Alert ...", JOptionPane.ERROR_MESSAGE); 140 return; 141 } 142 configuration.setStorage(f.getPath()); 143 if (userData != null) { 144 try { 145 userData.setStringData(UserData.LAST_EXEC_DIR, f.getAbsolutePath()); 146 userData.save(); 147 } catch (Exception ignored) { 148 } 149 } 150 } 151 } 152 | Popular Tags |