/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import ilog.views.util.IlvImageUtil;
import shared.BaseDemo;
import shared.MapBuilder;

/**
 * This example shows how to extend or restrict the map builder to use the FME
 * bridge. Using this example requires installing FME product on your machine.
 * for more information, go to http://www.safe.com/
 * 
 * @since JViews 7.5
 */
public class FMEDemo extends MapBuilder {

  /**
   * Overridden method to change the menu buttons available to the user
   * 
   */
  public FMEDemo() {
    super();
  }

  /**
   * Overridden method to change the preference file name.
   * 
   * @return the name of the preference file.
   */
  Override
  protected String getPreferenceFileName() {
    return "FMEDemo.settings";//$NON-NLS-1$
  }

  /**
   * Overridden method to change formats available in the import menu.
   * 
   * @see shared.MapBuilder#getImportActionClassNames()
   */
  Override
  protected List<String> getImportActionClassNames() {
    List<String> list = new ArrayList<String>();// super.getImportActionClassNames();
    // add my import format
    list.add("fme.FMEShapeLoadAction");//$NON-NLS-1$
    list.add("fme.FMEKMLLoadAction");//$NON-NLS-1$
    list.add("fme.FMESDTSLoadAction");//$NON-NLS-1$
    return list;
  }

  /**
   * Main method: creates an FMEDemo in a JFrame.
   * 
   * @param args
   *          (ignored)
   */
  public static void main(String[] args) {
    BaseDemo.showSplashScreen();
    // Sun recommends that to put the entire GUI initialization into the
    // AWT thread
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      Override
      public void run() {
        final JFrame frame = new JFrame();
        final FMEDemo app = new FMEDemo();
        frame.getContentPane().add(app);

        // change the frame title
        frame.setTitle("FME Demo");//$NON-NLS-1$
        // Change the frame icon
        try {
          frame.setIconImage(IlvImageUtil.getImageFromFile(BaseDemo.class, "/icons/default_frame_icon.gif"));//$NON-NLS-1$
        } catch (IOException e1) {
          // ignore
        }
        // Manage application exit when we close its window.
        frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
          Override
          public void windowClosing(WindowEvent e) {
            app.exitApplication();
          }
        });
        frame.pack();
        frame.setVisible(true);
      }
    });
  }
}