//Titel:            SDI-Fenster
//Version:          1.0
//Copyright:
//Autor:
//Firma:
//Beschreibung:


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;  // Exception

// Opendialog
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.*;
//import java.util.Hashtable;  // Filter
//import java.util.Enumeration; // Filter
import javax.swing.tree.*;
import javax.swing.tree.DefaultMutableTreeNode;

// InternalFrame
import javax.swing.event.*;


public class framework1 extends JFrame {
    // Menü Variablen
  private JMenuBar menuBar1;
  private JMenu MainFile;
  private JMenuItem MnNew;
  private JMenuItem MnOpen;
  private JMenuItem MnClose;

  private JMenu MainEdit;
  private JMenuItem MnCut;
  private JMenuItem MnCopy;
  private JMenuItem MnInsert;
  private JMenu MainHelp;
  private JMenuItem MnInfo;

  private JTree jtreeL;
  private JPanel jpanelR;
  private DefaultMutableTreeNode rootNode;

   // Konstruktor
  public framework1() {
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  public void setGUI() {
    this.getContentPane().setLayout( new BorderLayout() );
    this.setSize(new Dimension(600, 400));
    this.setVisible(true);

    rootNode = BuildTree();
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    jtreeL = new javax.swing.JTree(treeModel);  //  kein Root !!!
    jtreeL.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jtreeL.addMouseListener(
            new java.awt.event.MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
          jTreeL_mouseClicked(e);
        }
    });
    jpanelR = new JPanel();
    jpanelR.setBackground(Color.red);
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,false,
      new JScrollPane(jtreeL) , jpanelR);
    split.setDividerLocation(150);
    this.getContentPane().add(split, BorderLayout.CENTER);


    setMenus();
  }  // setGUI

  private void jTreeL_mouseClicked(MouseEvent e) {
    if(e.getClickCount() == 2) {
      System.out.println("in TreeL Click");
    }
  }
 DefaultMutableTreeNode BuildTree() {
   DefaultMutableTreeNode root;
   DefaultMutableTreeNode kn1, kn2, kn3;
   root = new DefaultMutableTreeNode("root");

   kn1 = new DefaultMutableTreeNode(  new CTreeNodeRec(1,"1. Stufe")  );
   root.add( kn1 );
   kn2 = new DefaultMutableTreeNode(  new CTreeNodeRec(2,"2. Stufe")  );
   kn1.add( kn2 );
   kn1 = new DefaultMutableTreeNode(  new CTreeNodeRec(3,"1. Stufe")  );
   root.add( kn1 );

   kn2 = new DefaultMutableTreeNode(  new CTreeNodeRec(4,"2. Stufe")  );
   kn1.add( kn2 );
   kn2 = new DefaultMutableTreeNode(  new CTreeNodeRec(4,"2. Stufe")  );
   kn1.add( kn2 );
   return root;
   }

    // setzt die Menüs
  private void setMenus() {
    menuBar1 = new JMenuBar();

      // DATEI
    MainFile = new JMenu("Datei");
    MnNew = new JMenuItem("Neu");
    MnOpen = new JMenuItem("Öffnen");
    MnClose = new JMenuItem("Schließen");

    MnNew.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnNew_click();
      }
    });
    MnNew.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    MainFile.add(MnNew);

    MnOpen.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnOpen_click();
      }
    });
    MnOpen.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    MainFile.add(MnOpen);
    MainFile.addSeparator();

    // --------------------------
    MnClose.addActionListener(new ActionListener()  {

      public void actionPerformed(ActionEvent e) {
        MnClose_click();
      }
    });
    MainFile.add(MnClose);

    menuBar1.add(MainFile);

    // EDIT
    MainEdit = new JMenu("Bearbeiten");
    MnCut = new JMenuItem("Ausschneiden");
    MnCopy = new JMenuItem("Kopieren");
    MnInsert = new JMenuItem("Einfügen");

    MnCut.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnCut_click();
      }
    });
    MainEdit.add(MnCut);

    MnCopy.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnCopy_click();
      }
    });
    MainEdit.add(MnCopy);
    // MainFile.addSeparator();

    // --------------------------
    MnInsert.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnInsert_click();
      }
    });
    MainEdit.add(MnInsert);
    menuBar1.add(MainEdit);
    MainHelp = new JMenu("Hilfe");
    MnInfo = new JMenuItem("Info");
    MnInfo.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnInfo_click();
      }
    });
    MainHelp.add(MnInfo);
    menuBar1.add(MainHelp);


    this.setJMenuBar(menuBar1);
  } // setMenus








  void MnNew_click() {
	  System.out.println("Neue Datei");
  }

  void MnOpen_click() {
   JFileChooser jFileChooser1 = new JFileChooser();
   String sFileName;

   jFileChooser1.setMultiSelectionEnabled(false);
   jFileChooser1.setCurrentDirectory( new File("C:\\DATEN") );
   if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this)) {
		sFileName = jFileChooser1.getSelectedFile().getPath();
	  System.out.println("Neue Datei");
    }
  }  // MnOpen

  void MnClose_click() {
    System.exit(0);
  }

   // -----------------
  void MnCut_click() {
    System.out.println("Menüeintrag Cut");
  }
  void MnCopy_click() {
    System.out.println("Menüeintrag Copy");
  }
  void MnInsert_click() {
    System.out.println("Menüeintrag Insert");
  }

  void MnInfo_click() {
    System.out.println("Info");
    JProgInfo frame = new JProgInfo(this);
    frame.setVisible(true);
  }


  static public void main(String[] args) {
    framework1 frame = new framework1();
    frame.setVisible(true);
  }

}  // framework1


// Einfache Klasse für jeden Knoten
class CTreeNodeRec  {
    public static int nr=0;
    private int _id = 0; // Id des Knotens  z.B. als ID

    private int _myData;
    public String _nodeString;

   public CTreeNodeRec(int myData,  String nodeString) {
      _myData = myData;
      _nodeString = nodeString;  // für JTree;
      nr++;
      _id = nr;  // setzt eindeutige Nummer
   }

   public int getID() {
     return _id;
   }

   public int getData() {
     return _myData;
   }

   public void setData(int myData) {
     _myData = myData;
   }


   // sehr wichtig
   public String toString() {
     return _nodeString;
   }


}  // MyTreeNodeRec





class JProgInfo extends JDialog{
    final String C_Copyright = "Andrea Musterfrau";
    final String C_Version = "Version 0.01, Build 1, 02.10.2010";

    JFrame _parent;

      JLabel label6;
      JLabel label7;

    /** Creates a new instance of CProgInfo */
    public JProgInfo(JFrame parent) {
        super(parent);
        _parent = parent;
        setGUI();
        // CBasis.centerScreen(this,null);
        this.setModal(true);
    }

    private void setGUI() {
        setSize(600,470);
        setTitle("Info über SDI");
        this.getContentPane().setLayout( new GridBagLayout() );

        JLabel label1 = new JLabel("Programm-Info");
        label1.setIcon( loadIcon("SDI-Programm.gif","speichern")  );
        label1.setFont( new Font("Arial", Font.BOLD,28) );
        this.getContentPane().add(label1,
                new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(0,0,0,0), 0, 0));

        JLabel label2 = new JLabel("SDI-Beispiel");
        label2.setFont( new Font("Arial", Font.BOLD,22) );
        this.getContentPane().add(label2,
                new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(30,10,0,0), 0, 0));

        JLabel label3 = new JLabel( C_Version );
        label3.setFont( new Font("Arial", Font.BOLD,18) );
        this.getContentPane().add(label3,
                new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(20,10,0,0), 0, 0));

        JLabel label4 = new JLabel( C_Copyright );
        label4.setFont( new Font("Arial", Font.BOLD,18) );
        this.getContentPane().add(label4,
                new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(40,10,0,0), 0, 0));

        JLabel label5 = new JLabel("HS Harz, FB AI");
        label5.setFont( new Font("Arial", Font.BOLD,18) );
        this.getContentPane().add(label5,
                new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(10,10,0,0), 0, 0));

        label6 = new JLabel("http://mwilhelm.hs-harz.de");
        label6.setFont( new Font("Arial", Font.BOLD,18) );
        this.getContentPane().add(label6,
                new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(50,10,0,0), 0, 0));

        label7 = new JLabel("u12345@hs-harz.de");
        label7.setFont( new Font("Arial", Font.BOLD,18) );
        this.getContentPane().add(label7,
                new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
                new Insets(10,10,0,10), 0, 0));

        // versuch eine kleine horizontale Linie zu erzeugen
        // Ein JPanel "pnLinie" wird ins Hauptpanel eingetragen
        // dieses Panel hat aber kein Layout
        // deshalb kann ein zweites Panel mit setBound gesetzt werden
        JPanel pnLinie = new JPanel();
        pnLinie.setBackground( Color.GRAY);
        pnLinie.setBackground( Color.RED);
        pnLinie.setLayout( null );

        JPanel pnLinie2 = new JPanel();
        pnLinie.add( pnLinie2 );
        // ohne setBounds wird es auf die gesamte Breite gezogen
        // pnLinie2.setBounds(0,0, 500,50);
        pnLinie2.setBackground( Color.GRAY);

        this.getContentPane().add(pnLinie,
                new GridBagConstraints(0, 7, 1, 1, 1.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
                new Insets(10,10,0,10), 0, 0));

        JButton BnESC = new JButton("Ok");
        BnESC.setFont( new Font("Arial", Font.BOLD,18)  );
        JPanel pn = new JPanel();
        pn.setLayout( new FlowLayout() );
        pn.add( BnESC);

        this.getContentPane().add(BnESC,
            new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE,
                new Insets(20,0,0,10), 40, 0));

          BnESC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              BnESC_Click();
            }
          });

        label1.setForeground(Color.blue);
        label6.setForeground(Color.blue);
        label7.setForeground(Color.blue);
        label6.addMouseListener(new java.awt.event.MouseAdapter() {

          public void mouseClicked(MouseEvent e) {
            www_Clicked();
          }
        });
        label7.addMouseListener(new java.awt.event.MouseAdapter() {

          public void mouseClicked(MouseEvent e) {
            email_Clicked();
          }
        });
        this.setBackground( Color.orange);
        this.setForeground(Color.orange);

    }

      // ButtonImage
  private ImageIcon loadIcon(String name, String description) {
   	// String path = "images" + name;
   	String path = name;  // Hier eventuell den path eintragen
    return new ImageIcon(path, description);
  }

    private void www_Clicked() {
       System.out.println("www") ;
       String s= "cmd /c start  "+label6.getText();
      try {
         Runtime.getRuntime().exec(s);
      }
      catch (IOException e) {
          System.out.println(e);
      }
    }

    // funktioniert noch nicht
    private void  email_Clicked() {
       System.out.println("email") ;
       String s= "cmd /c start "+label7.getText();
       s= "outlook.exe "+label7.getText();
      try {
         Runtime.getRuntime().exec(s);
      }
      catch (IOException e) {
          System.out.println(e);
      }
    }

    private void BnESC_Click() {
        setVisible(false);
        System.exit(0);
    }


} // JProgInfo
