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: ElementDialog.java,v 1.2 2004/02/12 00:17:55 bradford Exp $
 */

import java.awt.*;
import java.awt.event.ActionEvent;

import javax.swing.*;

/**
 * ElementDialog
 */

public class ElementDialog extends JDialog {
   private ImageIcon imgElement;
   private GridBagLayout thisLayout = new GridBagLayout();
   private JLabel lblElement = new JLabel();
   private JPanel pnlElement = new JPanel();
   private CardLayout pnlElementLayout = new CardLayout();
   private JTextField txtElement = new JTextField();
   private JComboBox cmbElement = new JComboBox();
   private JLabel lblAttributes = new JLabel();
   private JScrollPane paneAttributes = new JScrollPane();
   private JTable tblAttributes = new JTable();
   private JPanel pnlButtons = new JPanel();
   private JButton btnCancel = new JButton();
   private JButton btnCreate = new JButton();
   private BorderLayout pnlButtonsLayout = new BorderLayout();
   private JLabel lblImage = new JLabel();

   public ElementDialog(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 ElementDialog() {
      this(null, "", false);
   }

   private void jbInit() throws Exception {
      imgElement = new ImageIcon(ElementDialog.class.getResource("create-element.jpg"));
      lblElement.setText("Element Name");
      this.getContentPane().setLayout(thisLayout);
      this.getContentPane().setBackground(Color.white);
      this.setModal(true);
      this.setResizable(false);
      this.setTitle("Create Element");
      pnlElement.setLayout(pnlElementLayout);
      lblAttributes.setText("Attributes");
      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);
      paneAttributes.setOpaque(false);
      paneAttributes.setPreferredSize(new Dimension(200, 100));
      lblImage.setIcon(imgElement);
      pnlElement.setMinimumSize(new Dimension(200, 25));
      pnlElement.setPreferredSize(new Dimension(200, 25));
      this.getContentPane().add(lblElement,     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(pnlElement,      new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0));
      pnlElement.add(txtElement,   "text");
      pnlElement.add(cmbElement,   "combo");
      pnlElementLayout.show(pnlElement, "text");
      this.getContentPane().add(lblAttributes,      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(paneAttributes,       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(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(lblImage,    new GridBagConstraints(0, 0, 1, 3, 0.0, 0.0
            ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 0), 0, 0));
      paneAttributes.getViewport().add(tblAttributes, null);

   }

   void btnCreate_actionPerformed(ActionEvent e) {

   }

   void btnCancel_actionPerformed(ActionEvent e) {

   }
}
