/*
 * 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.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import ilog.views.IlvManager;
import ilog.views.IlvManagerView;
//import ilog.views.util.IlvProductUtil;
import ilog.views.interactor.IlvSelectInteractor;
import ilog.views.swing.IlvJScrollManagerView;

/**
 * A small JViews example.
 */
public class Sample2 extends JFrame
{
  IlvManager manager;
  IlvManagerView mgrview;
  IlvSelectInteractor selectInteractor;
  JButton button;

  public Sample2()
  {
    // Creates the manager object and reads an IVL file.
    manager = new IlvManager();
    try {
      manager.read("data/lou.ivl");
    } catch (Exception e) {}

    // Creates a view associated to the manager
    mgrview = new IlvManagerView(manager);
    mgrview.setAntialiasing(true);
    mgrview.setBackground(Color.white);

    // Creates the necessary swing components
    getContentPane().setLayout(new BorderLayout(0,0));
    getContentPane().add(new IlvJScrollManagerView(mgrview), 
                         BorderLayout.CENTER);

    // Creates additional buttons
    createButtons();
  }

  /**
   * Creates some swing buttons.
   */  
  void createButtons()
  {
    // A button to install a select interactor
    button = new JButton("Select");
    button.addActionListener(new ActionListener() {
      Override
      public void actionPerformed(ActionEvent evt) {
        if (selectInteractor == null)
          selectInteractor = new IlvSelectInteractor();
        if (mgrview.getInteractor() != selectInteractor) 
          mgrview.setInteractor(selectInteractor);
      }
    });    
    getContentPane().add(button, BorderLayout.SOUTH);
  }

  public static void main(String[] args) 
  {
    // This sample uses JViews Diagrammer features. When deploying an
    // application that includes this code, you need to be in possession
    // of a Perforce JViews Diagrammer Deployment license.
//    IlvProductUtil.DeploymentLicenseRequired(
//        IlvProductUtil.JViews_Diagrammer_Deployment);

    // Sun recommends that to put the entire GUI initialization into the
    // AWT thread
    SwingUtilities.invokeLater(
      new Runnable() {
        Override
        public void run() {
          JFrame frame = new Sample2();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(450,350);
          frame.setVisible(true);
        }
      });
  }
}