View Javadoc

1   package nl.tudelft.goal.ut2004.visualizer.gui.action;
2   
3   import java.awt.Component;
4   import java.awt.Graphics;
5   import java.awt.event.ActionEvent;
6   
7   import javax.swing.AbstractAction;
8   import javax.swing.Action;
9   import javax.swing.Icon;
10  import javax.swing.JDialog;
11  
12  import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
13  import nl.tudelft.goal.ut2004.visualizer.gui.dialogs.ChangeGameSpeedDialog;
14  
15  import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
16  import cz.cuni.amis.utils.flag.FlagListener;
17  
18  /**
19   * Action that is active or inactive depending on the state of the connection to
20   * the server. When the action is active it will launch a dialoque. This
21   * dialoque will be hidden when the connection to the server is lost.
22   * 
23   * @author mpkorstanje
24   * 
25   */
26  public class ShowServerDependentDialogueAction extends ShowDialogueAction {
27  
28  	/**
29  	 * Constructs the action.
30  	 * 
31  	 * @param dialog
32  	 *            to show when the action is used.
33  	 * @param name
34  	 *            this action.
35  	 * @param description
36  	 *            to show when a user hovers on this action.
37  	 */
38  	public ShowServerDependentDialogueAction(final JDialog dialog, String name,
39  			String description) {
40  		super(dialog, name, description);
41  
42  		ServerController controller = ServerController.getInstance();
43  		controller.getServerDefinition().getServerFlag()
44  				.addListener(new FlagListener<IUT2004Server>() {
45  
46  					@Override
47  					public void flagChanged(IUT2004Server changedValue) {
48  						if (changedValue == null) {
49  							setEnabled(false);
50  							dialog.setVisible(false);
51  						} else {
52  							setEnabled(true);
53  						}
54  					}
55  				});
56  
57  		setEnabled(controller.getServer() != null);
58  	}
59  
60  }