package com.dbxml.db.admin.xmleditor;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: AttributeDialog.java,v 1.2 2004/02/12 00:17:55 bradford Exp $
 */

import java.awt.*;
import javax.swing.*;

import java.awt.event.ActionEvent;

/**
 * AttributeDialog
 */

public class AttributeDialog extends JDialog {
   private ImageIcon imgAttribute;
   private GridBagLayout thisLayout = new GridBagLayout();
   private JLabel lblAttribute = new JLabel();
   private JPanel pnlAttribute = new JPanel();
   private CardLayout pnlAttributeLayout = new CardLayout();
   private JTextField txtAttribute = new JTextField();
   private JComboBox cmbAttribute = new JComboBox();
   private JLabel lblValue = new JLabel();
   private JPanel pnlButtons = new JPanel();
   private JButton btnCancel = new JButton();
   private JButton btnCreate = new JButton();
   private BorderLayout pnlButtonsLayout = new BorderLayout();
   private JTextField txtValue = new JTextField();
   private JLabel lblImage = new JLabel();

   public AttributeDialog(Frame frame, String title, boolean modal) {
      super(frame, title, modal);
      try {
         jbInit();
         pack();

         // Center the Dialog
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
         Dimension frameSize = getSize();
         if (frameSize.height > screenSize.height)
           frameSize.height = screenSize.height;
         if (frameSize.width > screenSize.width)
           frameSize.width = screenSize.width;
         setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
      }
      catch(Exception ex) {
         ex.printStackTrace();
      }
   }

   public AttributeDialog() {
      this(null, "", false);
   }

   private void jbInit() throws Exception {
      imgAttribute = new ImageIcon(ElementDialog.class.getResource("create-attribute.jpg"));
      lblAttribute.setText("Attribute Name");
      lblImage.setIcon(imgAttribute);
      this.getContentPane().setLayout(thisLayout);
      this.getContentPane().setBackground(Color.white);
      this.setModal(true);
      this.setResizable(false);
      this.setTitle("Create Attribute");
      pnlAttribute.setLayout(pnlAttributeLayout);
      lblValue.setText("Value");
      btnCancel.setText("Cancel");
      btnCancel.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            btnCancel_actionPerformed(e);
         }
      });
      btnCreate.setText("Create");
      btnCreate.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            btnCreate_actionPerformed(e);
         }
      });
      pnlButtons.setLayout(pnlButtonsLayout);
      pnlButtonsLayout.setHgap(5);
      pnlButtons.setOpaque(false);
      pnlAttribute.setMinimumSize(new Dimension(200, 19));
      pnlAttribute.setPreferredSize(new Dimension(200, 19));
      txtValue.setMinimumSize(new Dimension(200, 19));
      txtValue.setPreferredSize(new Dimension(200, 19));
      this.getContentPane().add(lblAttribute,     new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(10, 10, 10, 0), 0, 0));
      this.getContentPane().add(pnlAttribute,      new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
      pnlAttribute.add(txtAttribute,   "text");
      pnlAttribute.add(cmbAttribute,   "combo");
      pnlAttributeLayout.show(pnlAttribute, "text");
      this.getContentPane().add(lblValue,      new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 10, 10, 0), 0, 0));
      this.getContentPane().add(pnlButtons,     new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0
            ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 10, 10), 0, 0));
      pnlButtons.add(btnCreate, BorderLayout.CENTER);
      pnlButtons.add(btnCancel,  BorderLayout.EAST);
      this.getContentPane().add(txtValue,    new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 10), 0, 0));
      this.getContentPane().add(lblImage,      new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0
            ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 0), 0, 0));
   }

   void btnCreate_actionPerformed(ActionEvent e) {

   }

   void btnCancel_actionPerformed(ActionEvent e) {

   }
}
