package hirondelle.stocks.file;

import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import hirondelle.stocks.util.Args;
import hirondelle.stocks.util.ui.UiUtil;
import hirondelle.stocks.portfolio.CurrentPortfolio;
import hirondelle.stocks.portfolio.EditSaver;
import java.util.logging.Logger;
import hirondelle.stocks.util.Util;

 * Close the {@link CurrentPortfolio}, and display to the user an empty untitled portfolio,
 * which does not need a save.
 * <P>
 * If the <tt>CurrentPortfolio</tt> needs to be saved, then the user is offered the
 * option of saving its edits.
public final class FileCloseAction extends AbstractAction implements Observer {

   * Constructor.
   * @param aCurrentPortfolio will be updated by this action to be untitled and empty of
   * stocks.
   * @param aEditSaver if <tt>aCurrentPortfolio</tt> has any unsaved edits, then
   * <tt>aEditSaver</tt> will offer the user the option of saving the edits.
  public FileCloseAction(CurrentPortfolio aCurrentPortfolio, EditSaver aEditSaver) {
    super("Close", UiUtil.getEmptyIcon());
    fCurrentPortfolio = aCurrentPortfolio;
    fEditSaver = aEditSaver;
    putValue(SHORT_DESCRIPTION, "Close the current portfolio");
      ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK)
      LONG_DESCRIPTION, "Close the current portfolio and display an empty set of stocks"
    putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_C));

  @Override public void actionPerformed(ActionEvent event) {"Closing the current portfolio, and starting empty.");, event);

   * Synchronize the state of this object with the state of the {@link CurrentPortfolio}
   * passed to the constructor. This action is disabled only when the
   * <tt>CurrentPortfolio</tt> is untitled and does not need a save.
  public void update(Observable aPublisher, Object aData) {
    boolean noClose = fCurrentPortfolio.isUntitled() && !fCurrentPortfolio.getNeedsSave();

  private CurrentPortfolio fCurrentPortfolio;
  private EditSaver fEditSaver;
  private static final Logger fLogger = Util.getLogger(FileCloseAction.class);