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.model.Configuration; 29 import org.objectweb.fractal.gui.UserData; 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 javax.swing.Action ; 39 40 43 44 public class QuitAction extends AbstractAction 45 implements BindingController 46 { 47 48 52 53 public final static String CONFIGURATION_BINDING = "configuration"; 54 55 60 61 public final static String USER_DATA_BINDING = "user-data"; 62 63 68 69 public final static String SAVE_ACTION_BINDING = "save-action"; 70 71 74 75 private Configuration configuration; 76 77 80 81 private UserData userData; 82 83 86 87 private Action save; 88 89 92 93 public QuitAction () { 94 putValue(NAME, "Quit"); 95 putValue(SHORT_DESCRIPTION, "Quit"); 96 URL url = getClass().getResource( 97 "/org/objectweb/fractal/gui/resources/empty.gif"); 98 putValue(SMALL_ICON, new ImageIcon (url)); 99 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Q")); 100 } 101 102 106 public String [] listFc () { 107 return new String [] { 108 CONFIGURATION_BINDING, 109 USER_DATA_BINDING, 110 SAVE_ACTION_BINDING 111 }; 112 } 113 114 public Object lookupFc (final String clientItfName) { 115 if (CONFIGURATION_BINDING.equals(clientItfName)) { 116 return configuration; 117 } else if (USER_DATA_BINDING.equals(clientItfName)) { 118 return userData; 119 } else if (SAVE_ACTION_BINDING.equals(clientItfName)) { 120 return save; 121 } 122 return null; 123 } 124 125 public void bindFc ( 126 final String clientItfName, 127 final Object serverItf) { 128 if (CONFIGURATION_BINDING.equals(clientItfName)) { 129 configuration = (Configuration)serverItf; 130 } else if (USER_DATA_BINDING.equals(clientItfName)) { 131 userData = (UserData)serverItf; 132 } else if (SAVE_ACTION_BINDING.equals(clientItfName)) { 133 save = (Action)serverItf; 134 } 135 } 136 137 public void unbindFc (final String clientItfName) { 138 if (CONFIGURATION_BINDING.equals(clientItfName)) { 139 configuration = null; 140 } else if (USER_DATA_BINDING.equals(clientItfName)) { 141 userData = null; 142 } else if (SAVE_ACTION_BINDING.equals(clientItfName)) { 143 save = null; 144 } 145 } 146 147 151 public void actionPerformed (final ActionEvent e) { 152 try { 153 if (configuration.getChangeCount() > 0) { 154 Object [] options = { "Yes", "No", "Cancel" }; 155 int n = JOptionPane.showOptionDialog ( 156 null, 157 "Do you want to save the current configuration before exit ?", 158 "Warning", 159 JOptionPane.YES_NO_CANCEL_OPTION, 160 JOptionPane.QUESTION_MESSAGE, 161 null, 162 options, 163 options[0]); 164 if (n == 0) { 165 save.actionPerformed(e); 166 } 167 else if (n == 2) return; 168 } 169 172 } catch (Exception ex) { } 173 if (userData != null) { 174 userData.save(); 175 } 176 System.exit(0); 177 } 178 } 179 | Popular Tags |