package com.dbxml.db.admin.dialogs;

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

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

import com.dbxml.db.admin.Admin;
import com.dbxml.db.server.dbXML;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;

/**
 * AboutDialog
 */

public final class AboutDialog extends JDialog {
   ImageIcon imgLogo;
   GridBagLayout thisLayout = new GridBagLayout();
   JButton btnOK = new JButton();
   JLabel lblCredit3 = new JLabel();
   JLabel lblCredit2 = new JLabel();
   JLabel lblCredit1 = new JLabel();
   JLabel lblCreditsStart = new JLabel();
   JLabel lblCreditsEnd = new JLabel();
   JLabel lblVersion = new JLabel();
   JLabel lblTitle = new JLabel();
   JLabel lblRights = new JLabel();
   JLabel lblCopyright = new JLabel();
   JLabel lblLogo = new JLabel();
   JPanel pnlDialog = new JPanel();
   private JLabel lblLicense = new JLabel();
   private JLabel lblLicenseStart = new JLabel();
   private JLabel lblLicenseEnd = new JLabel();
   private JLabel lblInfoStart = new JLabel();
   private JLabel lblInfoEnd = new JLabel();
   private JLabel lblAboutEnd = new JLabel();
   private JLabel lblInfoStart2 = new JLabel();

   public AboutDialog(Frame owner) {
      super(owner, true);
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      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 e ) {
         Admin.getInstance().addMessage(e.toString());
      }
   }

   private void jbInit() throws Exception {
      imgLogo = new ImageIcon(AboutDialog.class.getResource("dbxml_mini.png"));
      this.setModal(true);
      this.setResizable(false);
      this.setTitle("About...");
      lblCredit2.setToolTipText("");
      lblLicense.setText("See docs/LICENSE for the dbXML license");
      lblLicense.setFont(new Font("Dialog", 0, 12));
      lblLicenseStart.setText("<license>");
      lblLicenseEnd.setText("</license>");
      lblInfoStart.setText("<info>");
      lblInfoEnd.setText("</info>");
      lblAboutEnd.setText("</about>");
      lblInfoStart2.setText("</dbXML>");
      this.getContentPane().add(pnlDialog);
      pnlDialog.setLayout(thisLayout);

      btnOK.setFont(new Font("Dialog", 0, 12));
      btnOK.setActionCommand("ok");
      btnOK.setText("ok");
      btnOK.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            btnOK_actionPerformed(e);
         }
      });
      lblCredit3.setFont(new Font("Dialog", 0, 12));
      lblCredit3.setText("Foundation (http://www.apache.org/)");
      lblCredit2.setFont(new Font("Dialog", 0, 12));
      lblCredit2.setText("developed by the Apache Software");
      lblCredit1.setFont(new Font("Dialog", 0, 12));
      lblCredit1.setText("This product includes software");
      lblCreditsStart.setText("<credits>");
      lblCreditsEnd.setText("</credits>");
      lblVersion.setFont(new Font("Dialog", 0, 12));
      lblVersion.setHorizontalAlignment(SwingConstants.LEFT);
      lblVersion.setText("Version " + dbXML.Version + " (" + dbXML.Codename + ")");
      lblTitle.setFont(new Font("Dialog", 0, 12));
      lblTitle.setForeground(new Color(0, 0, 127));
      lblTitle.setHorizontalAlignment(SwingConstants.LEFT);
      lblTitle.setText(dbXML.Title + " Administrator");
      lblRights.setFont(new Font("Dialog", 0, 12));
      lblRights.setText("All Rights Reserved");
      lblCopyright.setFont(new Font("Dialog", 0, 12));
      lblCopyright.setHorizontalAlignment(SwingConstants.LEFT);
      lblCopyright.setText("(c) " + dbXML.Year + " " + dbXML.Company);
      lblLogo.setBackground(SystemColor.window);
      lblLogo.setHorizontalAlignment(SwingConstants.CENTER);
      lblLogo.setIcon(imgLogo);
      lblLogo.setVerticalAlignment(SwingConstants.TOP);
      pnlDialog.add(lblCredit3, new GridBagConstraints(0, 13, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(btnOK, new GridBagConstraints(0, 17, 1, 1, 0.0, 0.0
            ,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 30, 10, 10), 0, 0));
      pnlDialog.add(lblCreditsEnd, new GridBagConstraints(0, 14, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 0, 10), 0, 0));
      pnlDialog.add(lblRights, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(lblCopyright, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(lblTitle, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(lblVersion, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(lblCredit1, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(lblCredit2, new GridBagConstraints(0, 12, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(lblLogo, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(10, 10, 0, 10), 0, 0));
      pnlDialog.add(lblLicense, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 10), 0, 0));
      pnlDialog.add(lblLicenseStart, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 0, 10), 0, 0));
      pnlDialog.add(lblLicenseEnd, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 20, 10), 0, 0));
      pnlDialog.add(lblInfoStart, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 0, 10), 0, 0));
      pnlDialog.add(lblInfoEnd, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 20, 10), 0, 0));
      pnlDialog.add(lblCreditsStart, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 30, 0, 10), 0, 0));
      pnlDialog.add(lblInfoStart2, new GridBagConstraints(0, 15, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 20, 10), 0, 0));
   }

   protected void processWindowEvent(WindowEvent e) {
      super.processWindowEvent(e);
      if ( e.getID() == WindowEvent.WINDOW_CLOSING ) {
         hide();
      }
   }

   public void btnOK_actionPerformed(ActionEvent e) {
      hide();
   }
}

