Package periman

Source Code of periman.OpenDocumentState

package periman;

import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JOptionPane;

public class OpenDocumentState extends DocumentState {
 
  private MainWindow mainWindow;
  OpenDocumentState(MainWindow mw)
  {
    mainWindow = mw;
    mainWindow.enableNewMenuItem(false);
    mainWindow.enableOpenMenuItem(false);
   
    mainWindow.enableCloseMenuItem(true);
    mainWindow.enableSaveMenuItem(true);
    mainWindow.enableSaveAsMenuItem(true);
    mainWindow.setThingsEnabled(true);
  }

  @Override
  void close() {
    if(mainWindow.closing()== false)
      return;
     
    mainWindow.setLastSavedConfToNew();
    mainWindow.setConfigurationFileName("");
    mainWindow.changeDocState( new NoDocumentState(mainWindow));
   
  }

  @Override
  void exit() {
    mainWindow.windowClosing(new WindowEvent(mainWindow, WindowEvent.WINDOW_CLOSING));
  }

  @Override
  void newDoc() {
    JOptionPane.showMessageDialog( null, "Should be impossible");
  }

  @Override
  void open() {
    JOptionPane.showMessageDialog( null, "Should be impossible");

  }

  @Override
  void save() {
    saveConfiguration();
  }
 
  @Override
  void saveAs() {
    String r =
      JOptionPane.showInputDialog(mainWindow,
          "Enter configuration name (omit the extension, it  will be added later).",
          "Periman - Save As",
          JOptionPane.QUESTION_MESSAGE);
   
    if(r== null || r.isEmpty())
      return;
   
    mainWindow.getConfiguration().setFileName(r+".periman");
    saveConfiguration();
  }
 
  // create the configuration file in the workspace by serializing it using xstream
  private void saveConfiguration()
  {
    
    String p = mainWindow.getWorkingDir() +
            File.separator +
            mainWindow.getConfiguration().getFileName();
   
    if(true == mainWindow.getConfiguration().save( p ) )
    {
          //! set the title of the window.
          mainWindow.setConfigurationFileName(mainWindow.getConfiguration().getFileName());
         
          mainWindow.setLastSavedConfToOpened();
    }
       
  }
 
 

}
TOP

Related Classes of periman.OpenDocumentState

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.