/* j-Algo - j-Algo is an algorithm visualization tool, especially useful for
 * students and lecturers of computer science. It is written in Java and
 * platform independent. j-Algo is developed with the help of Dresden
 * University of Technology.
 *
 * Copyright (C) 2004-2005 j-Algo-Team, j-algo-development@lists.sourceforge.net
 *
 * 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
 */
package org.jalgo.module.ebnf.gui.ebnf;

import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

import org.jalgo.main.util.Messages;


/**
 * 
 * @author Tom
 *
 */public class ChoicePanel extends JPanel {
	    
	 
	 	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private GuiController guiController;
	private ImageIcon redLightIcon;
	private ImageIcon greenLightIcon;
	private JLabel infoLight;
	private JLabel infoLabel;
		//	 Variables declaration - do not modify//GEN-BEGIN:variables
	    private javax.swing.JPanel ChoicePanel;
	    private javax.swing.JPanel buttonPanel;
	    private javax.swing.JButton editButton;
	    private javax.swing.JButton transButton;
	    private JToggleButton strictButton;
	    // End of variables declaration//GEN-END:variables

	    public ChoicePanel(GuiController guicontroller) {
	    	this.guiController = guicontroller;
	        initComponents();
	        initActionListeners();
	    }
	    
	    public void checkIfDefIsStrict() {
	    	
			if (!guiController.getEbnfController().getDefinition().isStrict() && !guiController.getStrictMode()) {
				//the definition is not strict
				infoLight.setIcon(redLightIcon);
				infoLabel.setText(Messages.getString("ebnf", "Ebnf.ChoicePanel_EbnfNotBinary"));
				infoLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
				transButton.setEnabled(false);
			} else {
				// the definition is strict
				infoLight.setIcon(greenLightIcon);
				infoLabel.setText(Messages.getString("ebnf", "Ebnf.ChoicePanel_EbnfIsBinary"));
				infoLabel.setFont(new java.awt.Font("Tahoma", 0, 14));
				transButton.setEnabled(true);
	    	}
			buttonPanel.validate();
		}

		/** This method is called from within the constructor to
	     * initialize the form.
	     * WARNING: Do NOT modify this code. The content of this method is
	     * always regenerated by the Form Editor.
	     */
	    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
	    private void initComponents() {
	    	initializeButtons();
	    	
	    	redLightIcon = new ImageIcon(Messages.getResourceURL("ebnf", "Light_Red"));
	    	greenLightIcon = new ImageIcon(Messages.getResourceURL("ebnf", "Light_Green"));

	    	infoLabel = new JLabel();
	    	infoLight = new JLabel();
	    	
	    	checkIfDefIsStrict();
	    	
	        ChoicePanel = new javax.swing.JPanel();

	        org.jdesktop.layout.GroupLayout buttonPanelLayout = new org.jdesktop.layout.GroupLayout(buttonPanel);
	        buttonPanel.setLayout(buttonPanelLayout);
	        buttonPanelLayout.setHorizontalGroup(
	            buttonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
	            .add(org.jdesktop.layout.GroupLayout.TRAILING, buttonPanelLayout.createSequentialGroup()
	            	.add(infoLight)
	            	.add(5,5,5)
	            	.add(infoLabel)
	            	.addContainerGap(0, Short.MAX_VALUE)
	                .add(editButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
	                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
	                .add(strictButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
	                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
	                .add(transButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 155, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
	                .addContainerGap(5,5)
	                )
	        );
	        buttonPanelLayout.setVerticalGroup(
	            buttonPanelLayout.createSequentialGroup()
	                .add(buttonPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
	                    .add(buttonPanelLayout.createSequentialGroup()
	                    		.add(5,5,5)
	                    		.add(infoLight))
	                    .add(buttonPanelLayout.createSequentialGroup()
	                    		.add(5,5,5)
	                    		.add(infoLabel))
	                	.add(transButton)
	                    .add(strictButton)
	                    .add(editButton))
	                .addContainerGap(5, 5)
	        );

	        org.jdesktop.layout.GroupLayout ChoicePanelLayout = new org.jdesktop.layout.GroupLayout(ChoicePanel);
	        ChoicePanel.setLayout(ChoicePanelLayout);
	        ChoicePanelLayout.setHorizontalGroup(
	            ChoicePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
	            .add(ChoicePanelLayout.createSequentialGroup()
	                .addContainerGap()
	                .add(buttonPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
	        );
	        ChoicePanelLayout.setVerticalGroup(
	            ChoicePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
	            .add(ChoicePanelLayout.createSequentialGroup()
	                .addContainerGap()
	                .add(buttonPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
	                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
	        );

	        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
	        setLayout(layout);
	        layout.setHorizontalGroup(
	            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
	            .add(layout.createSequentialGroup()
	                .add(ChoicePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	                .addContainerGap())
	        );
	        layout.setVerticalGroup(
	            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
	            .add(ChoicePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
	        );
	    }
	    
	    private void initializeButtons() {
	    	buttonPanel = new javax.swing.JPanel();
	        transButton = new javax.swing.JButton();
	        editButton = new javax.swing.JButton();
	        strictButton = new JToggleButton();
	        
	        buttonPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getString("ebnf", "Ebnf.ChoicePanel_Border"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12)));
	        transButton.setFont(new java.awt.Font("Tahoma", 0, 14));
	        setTransButtonText();	        
	        editButton.setFont(new java.awt.Font("Tahoma", 0, 14));
	        editButton.setText(Messages.getString("ebnf", "Ebnf.ChoicePanel_editButton"));

	        strictButton.setFont(new java.awt.Font("Tahoma", 0, 14));
	        strictButton.setText(Messages.getString("ebnf", "Ebnf.ChoicePanel_strictButton"));
		}
	    
	    public void setTransButtonText() {
	    	if (guiController.getEbnfController().isTransActive())
	        	transButton.setText(Messages.getString("ebnf", "Ebnf.ChoicePanel_transActiveButton"));
	        else
	        	transButton.setText(Messages.getString("ebnf", "Ebnf.ChoicePanel_transNotActiveButton"));

	    }
		private void initActionListeners() {
			transButton.addActionListener(guiController.choicePanelActionListener);
			transButton.setActionCommand("switchtotransgui");
			strictButton.addActionListener(guiController.choicePanelActionListener);
			strictButton.setActionCommand("strictdefinition");
			editButton.addActionListener(guiController.choicePanelActionListener);
			editButton.setActionCommand("editdefinition");
		}
	    
	    @Override
		public void paintComponent(Graphics g) {
	        super.paintComponent(g);
	    }

}
