Code Search for Developers
 
 
  

SaveGameAction.java from The Geronimo Project at Krugle


Show SaveGameAction.java syntax highlighted

package geronimo.hoshigo.control.game;

import geronimo.hoshigo.model.game.Game;
import geronimo.hoshigo.view.IconRegistry;
import geronimo.hoshigo.view.IconRegistry.IconSize;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.action.Action;

/**
 * Action d'enregistrement (sous) d'une partie.
 * @author Geronimo
 */
public class SaveGameAction extends Action
{
	private static SaveGameAction instance;
	
	private Game selectedGame;
	
	private final Map<Game,String> savedGames;
	
	/**
	 * Création de l'action. Privé car on n'autorise qu'une seule instance
	 * de la classe.
	 */
	private SaveGameAction()
	{
		super();
		this.setText("&Enregistrer@Ctrl+O");
		this.setToolTipText("Enregistrer la partie");
		this.setImageDescriptor( IconRegistry.getDescriptor("save_game",IconSize.SMALL) );
		this.setEnabled(false);
		
		this.savedGames = new HashMap<Game,String>();
	}
	
	/**
	 * Changement de partie active
	 * @param game Partie active
	 */
	public void setActiveGame(Game game)
	{
		this.selectedGame = game;
		this.setEnabled(    this.selectedGame != null
						 && this.savedGames.containsKey(this.selectedGame) );
	}
	
	/**
	 * Ajout d'une partie dans la liste des parties dont le fichier est connu
	 * @param game Partie enregistrée
	 * @param path Chemin du fichier 
	 */
	public void addGame(Game game, String path)
	{
		this.savedGames.put(game, path);
		if( this.selectedGame == game )
		{
			this.setEnabled(true);
		}
	}
	
	/**
	 * Accès à l'instance de la classe.
	 * @return Retourne l'instance
	 */
	public synchronized static SaveGameAction getInstance()
	{
		// Creation de l'instance au premier appel
		if(instance == null)
		{
			instance = new SaveGameAction();
		}
		return instance;
	}

	/**
	 * Lancement de l'action. Supprime la partie
	 */
	public void run()
	{
		if( this.selectedGame != null && this.savedGames.containsKey(this.selectedGame) )
		{
			System.out.println("<SaveGameAction> Enregistrement de la partie" +
				this.selectedGame + " => " + this.savedGames.get(this.selectedGame) );
			// TODO implémenter
		}
	}
}




See more files for this project here

The Geronimo Project

The Geronimo project concists of two software :\n- Geronimo Hoshigo : a playable graphical user interface to play Go\n- Geronimo Margo : a artificial intelligence program which plays Go

Project homepage: http://sourceforge.net/projects/geronimo
Programming language(s): Java,Pascal,Perl,PHP
License: gpl2

  CloseGameAction.java
  GameActionManager.java
  NewGameAction.java
  OpenGameAction.java
  SaveGameAction.java
  SaveGameAsAction.java