/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   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, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   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.

   $Project: polymake $$Id: JRealityHelpFrame.java 6700 2006-01-06 17:04:44Z wotzlaw $
*/

package de.tuberlin.polymake.common;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class JRealityHelpFrame extends JFrame 
	implements ItemListener,  ActionListener {
    
    /** Area to display help text. */
    protected JTextArea textArea = new JTextArea();
    
    /** Button to close Help. */
    protected JButton hideButton = new JButton("Close");
    
    /** To choose between Javaview and Schlegel interactive help.*/
    //protected Choice whichHelp = new Choice();
    
    /** Bottom Panel to display buttons. */
    protected JPanel panel = new JPanel();
    
    /** String holding the help text. */
    protected String text = new String();
    
    /** Panel holding the title of the help text. */
    protected JPanel titlePanel = new JPanel();
    
    /** Title of help. */
    protected JLabel titleLabel = new JLabel();

    /**
	 * Create a new frame to display the contents of
	 * the Help.txt file.
	 */
	public JRealityHelpFrame() {
		super("polymake help");
		setBounds(new Rectangle(30,30,450,500)); 
		addWindowListener( new WindowAdapter() {
			public void windowClosing( WindowEvent e ) {
			    setVisible(false);
			}
		});
		setLayout(new BorderLayout());
		textArea.setEditable(false);
		
		textArea.setBackground(Color.WHITE);
	
		titlePanel.setLayout(new BorderLayout());
		//titleLabel.setFont(new Font("Arial",Font.BOLD,15));
		titleLabel.setText("jReality help");
		titlePanel.add(titleLabel,BorderLayout.CENTER);
	
		hideButton.setActionCommand("hide");
		hideButton.addActionListener(this);
		
		//whichHelp.add("jReality");
		//whichHelp.addItemListener(this);
		
		hideButton.setAlignmentY(Component.CENTER_ALIGNMENT);
		hideButton.setMinimumSize(new Dimension(20,20));
		hideButton.setPreferredSize(new Dimension(70,20));
	
		panel.setLayout(new BorderLayout());
		panel.add(hideButton, BorderLayout.EAST);
		//panel.add(whichHelp,BorderLayout.WEST);
		try{
		    BufferedInputStream in = new BufferedInputStream(getClass().getResource("JRealityHelp.txt").openStream());
		    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		    String line = new String();
		    while(( line = reader.readLine()) != null) text += line + "\n";
		} catch( IOException e ) {System.err.println(e.getMessage());}
		textArea.setText(text);
	
		add(titlePanel, BorderLayout.NORTH);
		add(textArea,BorderLayout.CENTER);
		add(panel,BorderLayout.SOUTH);
    }
    
    /** Process Button events. */
    public void actionPerformed(ActionEvent e) {
    	if(e.getActionCommand().equals("hide")) {
    		this.setVisible(false);
    	}
    }
    
    /** Process the changes of the Choice menu. */
	public void itemStateChanged( ItemEvent e ) {
		if(e.getItem().equals("jReality")) {
			titleLabel.setText("jReality help");
			textArea.setText(text);
		} 
	}

}


syntax highlighted by Code2HTML, v. 0.9.1