/*=========================================================================

  Program:   Orbit Visualization Tool
  Source:    $Source: /stor/devel/ovt2g/ovt/object/editor/SettingsEditor.java,v $
  Date:      $Date: 2003/09/28 17:52:53 $
  Version:   $Revision: 2.3 $


Copyright (c) 2000-2003 OVT Team (Kristof Stasiewicz, Mykola Khotyaintsev, 
Yuri Khotyaintsev)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification is permitted provided that the following conditions are met:

 * No part of the software can be included in any commercial package without
written consent from the OVT team.

 * Redistributions of the source or binary code must retain the above
copyright notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT OR
INDIRECT DAMAGES  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.

OVT Team (http://ovt.irfu.se)   K. Stasiewicz, M. Khotyaintsev, Y.
Khotyaintsev

=========================================================================*/
/*
 * Settings.java
 *
 * Created on den 8 juni 2000, 17:24
 */
 
package ovt.object.editor;

import ovt.*;

import java.awt.*;

/** 
 *
 * @author  yuri
 * @version 
 */
public class SettingsEditor extends javax.swing.JDialog {

  public ovt.XYZWindow xyzwin =null;
  /** Creates new form Settings */
  public SettingsEditor(ovt.XYZWindow parent,boolean modal) {
    super (parent, modal);
    xyzwin = parent;
    initComponents ();
    setLocationRelativeTo(xyzwin);
    pack ();
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the FormEditor.
   */
    private void initComponents() {//GEN-BEGIN:initComponents
        btnPanel = new javax.swing.JPanel();
        okBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();
        
        //mainPane = new javax.swing.JTabbedPane();
        sizePanel = new javax.swing.JPanel();
        heightLbl = new javax.swing.JLabel();
        IntegerStyledDocument isd = new IntegerStyledDocument();
        heightTextField = new javax.swing.JTextField(isd,"",4);
        widthLbl = new javax.swing.JLabel();
        IntegerStyledDocument isd1 = new IntegerStyledDocument();
        widthTextField = new javax.swing.JTextField(isd1,"",4);

        setTitle("Settings");
        setName("settingsDialog");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        okBtn.setText("OK");
        getRootPane().setDefaultButton(okBtn);
        okBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okBtnPressed(evt);
            }
        });

        btnPanel.add(okBtn);

        cancelBtn.setText("Cancel");
        cancelBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBtnPressed(evt);
            }
        });

	btnPanel.add(cancelBtn);
        

        heightLbl.setText("Height");
        heightLbl.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        sizePanel.add(heightLbl);

        heightTextField.setText(OVTCore.getGlobalSetting(XYZWindow.SETTING_VISUALIZATION_PANEL_HEIGHT,
		""+xyzwin.getVisualizationPanel().getHeight()));
        sizePanel.add(heightTextField);

        widthLbl.setText("Width");
        widthLbl.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        sizePanel.add(widthLbl);

        widthTextField.setText(OVTCore.getGlobalSetting(XYZWindow.SETTING_VISUALIZATION_PANEL_WIDTH,
		""+xyzwin.getVisualizationPanel().getWidth()));
        sizePanel.add(widthTextField);

	//mainPane.add(sizePanel);
	getContentPane().setLayout(new BorderLayout());
        getContentPane().add(sizePanel, BorderLayout.CENTER);
	getContentPane().add(btnPanel, BorderLayout.SOUTH);
    }//GEN-END:initComponents

  public void setVisible(boolean visible) {
  	if (visible) {
		widthTextField.setText(OVTCore.getGlobalSetting(XYZWindow.SETTING_VISUALIZATION_PANEL_WIDTH,
		""+xyzwin.getVisualizationPanel().getWidth()));
		heightTextField.setText(OVTCore.getGlobalSetting(XYZWindow.SETTING_VISUALIZATION_PANEL_HEIGHT,
		""+xyzwin.getVisualizationPanel().getHeight()));
	}
	super.setVisible(visible);
  }

  private void cancelBtnPressed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnPressed
    setVisible (false);
    
  }//GEN-LAST:event_cancelBtnPressed

  private void okBtnPressed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnPressed
    
      int x = 400;
      int y = 400;
      try{
        x = new Integer(widthTextField.getText()).intValue();
        y = new Integer(heightTextField.getText()).intValue();
      
      if ( x < 100 || x > 1600 || y < 100 || y > 1600) {
        xyzwin.getCore().sendErrorMessage("InputError", "Value should be in range 100-1600");
        return;
      } 
      OVTCore.setGlobalSetting(XYZWindow.SETTING_VISUALIZATION_PANEL_WIDTH, ""+x);
      OVTCore.setGlobalSetting(XYZWindow.SETTING_VISUALIZATION_PANEL_HEIGHT, ""+y);
      
      setVisible (false);
      javax.swing.JOptionPane.showMessageDialog(this, "Please restart OVT for changes to take effect", 
      "Please Restart OVT",
      javax.swing.JOptionPane.INFORMATION_MESSAGE);
      
      } catch (NumberFormatException e){
        getToolkit().beep();
      }
    
  }//GEN-LAST:event_okBtnPressed


  /** Closes the dialog */
  private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
    setVisible (false);
    
  }//GEN-LAST:event_closeDialog

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel sizePanel;
    private javax.swing.JPanel btnPanel;
    private javax.swing.JLabel heightLbl;
    private javax.swing.JTextField heightTextField;
    private javax.swing.JLabel widthLbl;
    private javax.swing.JButton cancelBtn;
    private javax.swing.JTextField widthTextField;

    private javax.swing.JTabbedPane mainPane;
    private javax.swing.JButton okBtn;
    // End of variables declaration//GEN-END:variables

}
