/*
 *  iReport  --  Visual designer for generating JasperReports Documents
 *  Copyright (C) 2002  Giulio Toffoli gt@businesslogic.it
 *
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Giulio Toffoli
 *  Via T.Aspetti, 233
 *  35100 Padova ITALY
 *  gt@businesslogic.it
 */
package com.businesslogic.ireport;

import com.businesslogic.ireport.ui.*;
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import com.ms.xml.om.*;
import com.ms.xml.util.*;

import java.util.*;
import java.io.*;


/**
 * Questa classe puņ accettare un numero variabile di parametri sulla riga
 * di comando. L'esecuzione del programma inizia con il metodo main(). Il costruttore
 * della classe non viene richiamato fino a quando un oggetto di tipo "Form1"
 * non viene creato nel metodo main().
 */
public class MainForm extends Form
{
	public ElementProperties ep=null;
	boolean propertiesOpened = false;
	public ElementsBrowser bf=null;
	public VariablesForm  vf=null;
	public GroupsForm gf=null;
	public FontsForm fontf=null;
	public DBConnectionsForm cf=null;
	public QueryForm qf=null;
	boolean browserOpened = false;
	boolean variablesFormOpened = false;
	boolean groupsFormOpened = false;
	boolean connectionsFormOpened = false;
	boolean queryFormOpened = false;
	boolean fontsOpened = false;
	public String programDir="";
	
	public Properties connProperties;
	public Properties ireportProperties;
	Vector clipboardObjects;
	public String propfile_name="";
	public String config_name="";
	boolean wait=false;
	
	 
		
	
	
	public Vector fonts;
	public java.util.Hashtable fontsht;
	

	public MainForm(String args[])
	{
		// Necessario per il supporto della finestra di progettazione form di Visual J++
		initForm();	
		StringBuffer str = new StringBuffer(1024);
		this.GetModuleFileName( GetModuleHandle(null),str,1024);
		
		programDir = com.ms.wfc.io.File.getDirectory(""+str);
		com.ms.wfc.io.File.setCurrentDirectory(	programDir );		
			
		
		clipboardObjects = new Vector();
		fontsht = new java.util.Hashtable();
		fonts = new Vector();
		loadFonts();
		TextReportElement.mf = this;

		Application.addOnIdle( new EventHandler(MainForm_Idle));
		
		// TODO: aggiungere il codice del costruttore dopo la chiamata di initForm.
		numberComboBox1.addItem(new NumberComboValue("25%",25));
		numberComboBox1.addItem(new NumberComboValue("50%",50));
		numberComboBox1.addItem(new NumberComboValue("100%",100));
		numberComboBox1.addItem(new NumberComboValue("150%",150));
		numberComboBox1.addItem(new NumberComboValue("200%",200));
		numberComboBox1.addItem(new NumberComboValue("Fit to page",-5));
		
		numberComboBox1.setText("100%");
			
		connProperties = new Properties();
		propfile_name= com.ms.wfc.io.File.combine(programDir,"connections.properties");
		try {
			FileInputStream fio = new FileInputStream(propfile_name);
			connProperties.load(fio);
			fio.close();
		} catch (Exception ex)
		{
		}
		
		
		ireportProperties = new Properties();
		config_name= com.ms.wfc.io.File.combine(programDir,"ireport.properties");
		try {
			FileInputStream fio = new FileInputStream(config_name);
			ireportProperties.load(fio);
			fio.close();
		} catch (FileNotFoundException ex)
		{
		} catch (Exception ex)
		{
		}
		
		String cp = (String)connProperties.get("CLASSPATH");
		if (cp==null) cp="";
		if (cp.indexOf(";.;") < 0) cp += ";.";
		if (cp.indexOf(programDir+";") < 0) cp += ";"+programDir;
		if (cp.indexOf(com.ms.wfc.io.File.combine(programDir,"libs")+";") < 0) cp += ";"+com.ms.wfc.io.File.combine(programDir,"libs");
		
		// Add to path all jar files in libs...
		String[] jars;
		try {
			jars = com.ms.wfc.io.File.getFiles( com.ms.wfc.io.File.combine(programDir,"libs\\*.jar"));
			for (int ji = 0; ji < jars.length; ++ji)
			{
				cp += ";"+com.ms.wfc.io.File.combine(programDir,"libs\\"+jars[ji]);
			}
		} catch (Exception ex){}
		
		try {
			jars = com.ms.wfc.io.File.getFiles( com.ms.wfc.io.File.combine(programDir,"..\\libs\\*.jar"));
			for (int ji = 0; ji < jars.length; ++ji)
			{
				cp += ";"+com.ms.wfc.io.File.combine(programDir,"..\\libs\\"+jars[ji]);
			}
		} catch (Exception ex){}
		// Setting classpath....
		ClasspathForm.SetEnvironmentVariable("classpath",cp);
		updateRecentFileList();		
		
		// if it is the first start open welcome document...
		if (ireportProperties.getProperty("WELCOME") == null)
		{
			ireportProperties.put("WELCOME","NO");
			saveProperties();
			openDocument( com.ms.wfc.io.File.getCurrentDirectory() +"\\welcome.xml");
		}
		
		if (args.length>0)
		{
			if (com.ms.wfc.io.File.exists(args[0]))
				openDocument(args[0]);
		}
		
	}
	
	public void loadFonts()
	{
		com.ms.wfc.app.RegistryKey  ks =  com.ms.wfc.app.Registry.LOCAL_MACHINE;
		ks = ks.getSubKey("Software\\Microsoft\\windows\\CurrentVersion\\Fonts");
		if (ks == null)
		{
			ks = com.ms.wfc.app.Registry.LOCAL_MACHINE;
			ks = ks.getSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
		}
		if (ks == null)
		{
			return;
		}
		String[] vals = ks.getValueNames();
		for (int i=0; i< vals.length; ++i)
		{
			String fname = vals[i];
			if (fname.indexOf("(TrueType)") > 0)
			{
				FontFile f = new FontFile();
				
				f.filename = (String)ks.getValue(fname);
				f.fontname = fname.substring(0, fname.indexOf("(TrueType)")).trim();
				fonts.addElement(f);
				fontsht.put( f.filename, f.fontname);
			}
		}
	}
	
	public String getFontName(String filename)
	{
		if (fontsht.containsKey(filename))
		{
		  return (String)fontsht.get(filename);
		}
		return null;
	}
	
	public void updateRecentFileList()
	{
		
		if (ireportProperties == null) return; 
		
		//Clear actual list...
		
		
		int i=0;
		boolean find = false;
		for (i=0; i <menuItem1.getMenuItemCount(); ++i)
		{
			char c = menuItem1.getMenuItem(i).getText().charAt(0);
			if (c >= '0' && c <='9')
			{
				find = true;
				menuItem1.remove(i);
				i--;
			}
		}
		if (find)
			menuItem1.remove( menuItem1.getMenuItemCount()-2);
		
		for (i=0;; ++i)
		{
			if (ireportProperties.getProperty("MRU"+i+"_NAME") == null)
				break;  	
			else
			{
				String filename =ireportProperties.getProperty("MRU"+i+"_NAME");
				String n = filename.substring( filename.lastIndexOf('\\'));
				if (filename.substring(0, filename.lastIndexOf('\\')).length() > 10)
					filename = filename.substring(0, filename.indexOf("\\",10)+1 )+"..."+n;
				MenuItem menuItem = new MenuItem((i+1) + " " + filename,new EventHandler(menuItemMRU_click) );
				menuItem1.add( menuItem);
				menuItem.setIndex(menuItem1.getMenuItemCount()-2);
			}
		}
		if (i>0)
		{
			MenuItem menuItem = new MenuItem("-");
			menuItem1.add( menuItem);
			menuItem.setIndex(menuItem1.getMenuItemCount()-2);
		}
	}
	
	public void addToRecentFileList(String file_name)
	{
		// 1. Modify properties...
		Vector v = new Vector();
		int i=0;
		for (i=0;; ++i)
		{
			if (ireportProperties.getProperty("MRU"+i+"_NAME") == null)
				break;  	
			else
			{
				v.addElement(ireportProperties.getProperty("MRU"+i+"_NAME"));
				ireportProperties.remove(ireportProperties.getProperty("MRU"+i+"_NAME"));
			}
		}
		
		// 2. Save properties...
		int max = 4;
		if (ireportProperties.getProperty("MAX_MRU") != null)
		{
				max = Integer.parseInt(ireportProperties.getProperty("MAX_MRU")+"");
		}
		
		Enumeration enum = v.elements();
		i=0;
		if (max > 0)
		{
			ireportProperties.put("MRU0_NAME", file_name);
			i=1;
		}
		while (enum.hasMoreElements())
		{
			if (i >= max)
			{
				if (ireportProperties.containsKey("MRU"+i+"_NAME"))
					ireportProperties.remove("MRU"+i+"_NAME");
				else
					break;
				continue;
			}
			
			String item = (String)enum.nextElement();
			if (item.equalsIgnoreCase(file_name)) continue;
			ireportProperties.put("MRU"+i+"_NAME", item);
			i++;
		}
	}
	
	private void menuItemMRU_click(Object source, Event e)
	{
		if (source instanceof MenuItem)
		{
			String cod = ((MenuItem)source).getText();
			cod = cod.substring(0,cod.indexOf(" "));
			cod = ""+(Integer.parseInt(cod)-1);
			String filename = (String)ireportProperties.get("MRU"+cod+"_NAME");
			//MessageBox.show("Open file:" + filename +" ("+  cod +")" );
			if (filename != null &&	com.ms.wfc.io.File.exists(filename))
				openDocument(filename);
			else MessageBox.show(filename+ " not found!");
		}	
	}
		
	public ReportForm openDocument(String filename)
	{
			String cd = com.ms.wfc.io.File.getCurrentDirectory();
			try {
				com.ms.wfc.io.File.setCurrentDirectory(com.ms.wfc.io.File.getDirectory( filename ));
			} catch (Exception ex)
			{
				MessageBox.show("Error changing directory to: "+com.ms.wfc.io.File.getDirectory( filename ));
			}
			this.setCursor(Cursor.WAIT);
			
			addToRecentFileList( filename );
			updateRecentFileList();
			saveProperties();

			try {
				java.io.FileInputStream fis = new java.io.FileInputStream(filename);
				// Modify intestation...
				String xml_file  = "";
				byte[] buffer = new byte[1024*512];
				int dim=0;
				while ((dim = fis.read(buffer))>0)
				{
					xml_file += new String(buffer,0,dim);
				}
				fis.close();
				// Strip <!DOCTYPE...> directive....
				int begin = xml_file.indexOf("<!DOCTYPE");
				if (begin > -1)
				{
					int end  = xml_file.substring(begin+1).indexOf(">");
				
					xml_file = xml_file.substring(0,begin)+xml_file.substring(begin+end+2);
					//MessageBox.show(xml_file.substring(0,300));
				}
				
				java.io.StringBufferInputStream sbis = new java.io.StringBufferInputStream(xml_file);
				
				com.ms.xml.om.Document doc = new com.ms.xml.om.Document();
				doc.load( sbis);
				
				fis.close();
				//loadXMLTree(doc);	
				Report r = new Report(doc,filename);
				r.encoding = doc.getEncoding();
				ReportForm rf = new ReportForm(r);
				rf.setMDIParent(this);
				rf.show();
				rf.refreshAll();
				
				this.addToRecentFileList(filename);
				saveProperties();
				this.updateRecentFileList();
				
				this.setCursor(Cursor.DEFAULT);
				return rf;
			} catch (Exception ex)
			{
				this.setCursor(Cursor.DEFAULT);
				MessageBox.show(ex.getMessage());
				java.io.StringWriter s = new java.io.StringWriter();
				ex.printStackTrace(new java.io.PrintWriter(s));
				MessageBox.show(ex.getMessage()+" "+s);
				
			}
			this.setCursor(Cursor.DEFAULT);
			return null;
	}
	
	public void saveProperties()
	{
		try {
			FileOutputStream fio = new FileOutputStream(config_name);
			ireportProperties.save(fio,"");
			fio.close();
		} catch (Exception ex)
		{
		}
	}

	/**
	 * Form1 esegue l'overriding di dispose e quindi puņ svuotare
	 * l'elenco dei componenti.
	 */
	public void dispose()
	{
		super.dispose();
		components.dispose();
	}
	
	private void menuItem2_click(Object source, Event e)
	{
		Vector no_valid_names = new Vector();
		
		ReportPropertiesForm rpf = new ReportPropertiesForm(this);
		
		Form[] forms =  this.getMDIChildren();
		for (int i=0; i<forms.length; ++i)
		{
			if (forms[i] instanceof ReportForm)
			{
				no_valid_names.addElement( ((ReportForm)forms[i]).getReport().getReportName() );
			}
		}
		boolean valid_name = false;
		for (int i=1;; ++i)
		{
			String name = "Untitled_report_" + i;
			if (!no_valid_names.contains(name))
			{
				rpf.setReportName(name);
				break;
			}
		}	
		
		if (rpf.showDialog() == DialogResult.OK)
		{
			Point  size = rpf.getPageSize();
			String name = rpf.getReportName();
			String format = rpf.getReportFormat();
			Report rep = new Report(name,size,format);
			rep.topMargin =  rpf.margin_top;
			rep.leftMargin =  rpf.margin_left;
			rep.bottomMargin =  rpf.margin_bottom;
			rep.rightMargin =  rpf.margin_right;
			rep.columnCount =  rpf.columns;
			rep.columnSpacing =  rpf.column_spacig;
			rep.columnWidth =  rpf.column_width;
			rep.setReportFormat(rpf.format);
			rep.setReportName( rpf.name );
			
			rep.orientation = rpf.orientation;
			rep.whenNoDataType = rpf.whenNoDataType;
			rep.scriptletClass = rpf.scriptletClass;
			rep.printOrder = rpf.printOrder;
			rep.isSummaryNewPage = rpf.isSummaryNewPage;
			rep.isTitleNewPage = rpf.isTitleNewPage;
			
			rep.encoding = rpf.encoding;
			
			ReportForm rf = new ReportForm(rep);
			rf.setMDIParent(this);
			rf.show();
		}
	}

	private void menuItem7_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			menuItem7.setChecked(!menuItem7.getChecked());
			((ReportForm)form).setRighelloVisible( menuItem7.getChecked() );
			
		}
	}
	
	public void loadXMLTree(Document doc)
	{
		//treeView1.removeAll();
		ElementCollection ec = doc.getChildren();
		TreeNode tn = new TreeNode("XML document");
		for (int i=0; i<ec.getLength(); i++)
		{
			Element el = ec.getChild(i);
			addTreeElement(el, tn);
		}
		//treeView1.addNode(tn);
	}
	
	public void addTreeElement(Element el, TreeNode parent)
	{
		String name = ""+el.getTagName();
		if (name.equalsIgnoreCase("text"))
		{
			name += " ("+el.getText()+")";
		}
		TreeNode tn = new TreeNode(name);
		
		// Add attributes...
		Enumeration enum = el.getAttributes();
		while (enum.hasMoreElements())
		{
			Attribute a = (Attribute)enum.nextElement();
			tn.addNode(a.getName()+"="+a.getValue());
			
		}
		ElementCollection ec = el.getChildren();
		for (int i=0; i<ec.getLength(); i++)
		{
			Element el2 = ec.getChild(i);
			addTreeElement(el2, tn);
		}
		parent.addNode(tn);
	}

	private void menuItem4_click(Object source, Event e)
	{
		// Scelta file XML...
		OpenFileDialog ofd = new OpenFileDialog();
		ofd.setCheckFileExists(true);
		ofd.setFilter("Jasper XML Report *.xml|*.xml");
		ofd.setDefaultExt("xml");
		int result = ofd.showDialog();
		if (result == DialogResult.OK)
		{
			openDocument(ofd.getFileName());
			
		}
	}

	private void menuItem9_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.NULL_ELEMENT  );	
		}
	}

	private void MainForm_keyPress(Object source, KeyPressEvent e)
	{
		
	}

	private void menuItem10_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			ReportPropertiesForm rpf = new ReportPropertiesForm(this);
			rpf.setReport( ((ReportForm)form).getReport() );
			if (rpf.showDialog() == DialogResult.OK)
			{
				Report rep =  ((ReportForm)form).getReport();
				rep.setPagesize( rpf.getPageSize());
				rep.topMargin =  rpf.margin_top;
				rep.leftMargin =  rpf.margin_left;
				rep.bottomMargin =  rpf.margin_bottom;
				rep.rightMargin =  rpf.margin_right;
				rep.columnCount =  rpf.columns;
				rep.columnSpacing =  rpf.column_spacig;
				rep.columnWidth =  rpf.column_width;
				rep.setReportFormat(rpf.format);
				rep.setReportName( rpf.name );
				
				rep.orientation = rpf.orientation;
				rep.whenNoDataType = rpf.whenNoDataType;
				rep.scriptletClass = rpf.scriptletClass;
				rep.printOrder = rpf.printOrder;
				rep.isSummaryNewPage = rpf.isSummaryNewPage;
				rep.isTitleNewPage = rpf.isTitleNewPage;
				
				rep.encoding = rpf.encoding;
			
				((ReportForm)form).refreshAll();
			}
		}
	}

	private void menuItem11_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.RECTANGLE_ELEMENT);	
		}
	}

	private void menuItem13_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.IMAGE_ELEMENT);	
		}
	}

	private void menuItem14_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.STATICTEXT_ELEMENT);	
		}
	}

	private void menuItem16_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			if (((ReportForm)form).selectedElements.size()>0)
			{
				initReportForm();
				ep.setEelement((ReportForm)form, (ReportElement)((ReportForm)form).selectedElements.firstElement() );
				ep.setOwner(this);
				ep.show();
			}
		}
		
	}
	
	public void initReportForm()
	{
		if (ep == null)
		{
			ep = new  ElementProperties();
			ep.setOwner(this);
			ep.setFonts(fonts);
			ep.addOnDispose(new EventHandler(ElementProprties_dispose));
			propertiesOpened = true;
		}
	}
	
	public void initFontsForm(Report report)
	{
		if (fontf == null)
		{
			fontf = new FontsForm(this);
			fontf.setReport(report);
			fontf.setOwner(this);
			fontf.addOnDispose(new EventHandler(FontsForm_dispose));
			fontsOpened = true;
		}
	}
	
	public void initBrowserForm()
	{
		if (bf == null)
		{
			bf = new  ElementsBrowser();
			bf.addOnDispose(new EventHandler(ElementsBrowser_dispose));
			browserOpened = true;
		}
	}
	
	public void initVariablesForm()
	{
		if (vf == null)
		{
			vf = new  VariablesForm();
			vf.addOnDispose(new EventHandler(VariablesForm_dispose));
			variablesFormOpened  = true;
		}
	}
	
	public void initGroupsForm()
	{
		if (gf == null)
		{
			gf = new  GroupsForm();
			gf.addOnDispose(new EventHandler(GroupsForm_dispose));
			groupsFormOpened = true;
		}
	}
	
	public void initQueryForm()
	{
		if (qf == null)
		{
			qf = new  QueryForm();
			qf.fillConnectionCombo(getConnectionEntries());
			qf.addOnDispose(new EventHandler(QueryForm_dispose));
			queryFormOpened = true;
		}
	}
	
	public void initDBConnectionsForm()
	{
		if (cf == null)
		{
			cf = new  DBConnectionsForm(this);
			cf.addOnDispose(new EventHandler(DBConnectionsForm_dispose));
			connectionsFormOpened = true;
		}
	}

	private void ElementProprties_dispose(Object source, Event e)
	{
		
		ep = null;
		propertiesOpened = false;
	}
	
	private void FontsForm_dispose(Object source, Event e)
	{
		
		fontf = null;
		fontsOpened = false;
	}
	
	private void ElementsBrowser_dispose(Object source, Event e)
	{
		bf = null;
		browserOpened = false;
	}
	
	private void GroupsForm_dispose(Object source, Event e)
	{
		gf = null;
		groupsFormOpened = false;
	}
	
	private void QueryForm_dispose(Object source, Event e)
	{
		qf = null;
		queryFormOpened = false;
	}
	
	private void DBConnectionsForm_dispose(Object source, Event e)
	{
		cf = null;
		connectionsFormOpened = false;
	}
	
	public boolean isPropertiesOpened()
	{
		return propertiesOpened;
	}
	
	public boolean isVariablesFormOpened()
	{
		return variablesFormOpened;
	}
	
	public boolean isGroupsFormOpened()
	{
		return groupsFormOpened;
	}
	
	public boolean isDBConnectionsFormOpened()
	{
		return connectionsFormOpened;
	}
	
	public boolean isQueryFormOpened()
	{
		return queryFormOpened;
	}
	
	public boolean isFontsFormOpened()
	{
		return fontsOpened;
	}

	private void VariablesForm_dispose(Object source, Event e)
	{
		
		vf = null;
		variablesFormOpened = false;
	}
	private void menuItem17_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
				initBrowserForm();
				bf.setReportForm((ReportForm)form );
				bf.setOwner(this);
				bf.show();
		}
	}

	private void menuItem18_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
				ReportElement re = new ReportElement(10,10,100,100,new Brush(Color.RED));
				((ReportForm)form).getReport().getElements().addElement(re);
				((ReportForm)form).refreshAll();
		}
	}
	
	
	// Add LINE
	private void menuItem19_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.LINE_ELEMENT);	
		}
	}

	private void menuItem3_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			Report rp = ((ReportForm)form).getReport();
			if (rp.filename == null)
			{
				
				 menuItem20_click(source,e);
			}
			else
			{
				
				saveBackup( rp.filename); 
				rp.saveXMLFile();
				this.addToRecentFileList(rp.filename);
				saveProperties();
				this.updateRecentFileList();
			}
				
		}
	}

	private void menuItem20_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			Report rp = ((ReportForm)form).getReport();
			SaveFileDialog sfd = new SaveFileDialog();
			sfd.setFilter("Jasper XML Report *.xml|*.xml");
			sfd.setDefaultExt("xml");
			sfd.setFileName(""+rp.getReportName());
			if (sfd.showDialog() == DialogResult.OK)
			{
				rp.filename = sfd.getFileName();
				saveBackup( rp.filename); 
				rp.saveXMLFile();
				this.addToRecentFileList(rp.filename);
				saveProperties();
				this.updateRecentFileList();
			}
		}
	}
	
	public void saveBackup(String filename)
	{
		if (com.ms.wfc.io.File.exists(filename))
		{
			String path = com.ms.wfc.io.File.getDirectory(filename);
			String file = com.ms.wfc.io.File.getName(filename);
			
			if (ireportProperties.getProperty("BACKUP_DIR") != null &&
				(""+ireportProperties.getProperty("BACKUP_DIR")).length()>0)
					path = ireportProperties.getProperty("BACKUP_DIR");
			
			if (ireportProperties.getProperty("BACKUP_MODE") != null &&
				(""+ireportProperties.getProperty("BACKUP_MODE")).equalsIgnoreCase("0"))
			{
				return;
			} else if (ireportProperties.getProperty("BACKUP_MODE") != null &&
				(""+ireportProperties.getProperty("BACKUP_MODE")).equalsIgnoreCase("1"))
			{
				if (file.indexOf(".") > 0 && file.substring(file.indexOf(".")).length()>=3)
					file = file.substring(0,file.length()-3)+"bak";	
				else
					file += ".bak";
			} else {
				file += ".bak";
			}	
			try {
				com.ms.wfc.io.File.copyOver( filename, com.ms.wfc.io.File.combine(path,file)); 
			} catch (Exception ex)
			{
				MessageBox.show("Errore saving backup copy.\n"+ex.getMessage(),"",MessageBox.ICONERROR); 
			}
		}
	}

	private void menuItem21_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.TEXTFIELD_ELEMENT);	
		}
	}

	private void menuItem22_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			int i=1;
			String grpname = "mygroup";
			boolean newgrp=false;
			while (!newgrp)
			{
				grpname = "mygroup"+i;
				i++;
				boolean found = false;
				Enumeration enum = ((ReportForm)form).getReport().groups.elements();
				while (enum.hasMoreElements())
				{
					Group grp = (Group)enum.nextElement();
					if (grp.name.equalsIgnoreCase(grpname))
					{
						found = true;
						break;
					}
				}
				if (!found)
				{
					newgrp = true;
					break;
				}
			}
			
			((ReportForm)form).getReport().addGroup(new Group(grpname,30,30)); 	
			((ReportForm)form).refreshAll();
		}
	}

	private void numberEdit1_valueChanged(Object source, Event e)
	{

	}

	private void numberComboBox1_valueChanged(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			
			if (numberComboBox1.getValue() == -5)
			{
				int w = ((ReportForm)form).getReport().getPagesize().x+20;
				double s = (double)((ReportForm)form).getDisplayWidth()/(double)w;
				//MessageBox.show(""+w+" "+(double)((ReportForm)form).getDisplayWidth());
				numberComboBox1.setValue(s*100);
				numberComboBox1.setText(numberComboBox1.doubleToString(s*100));
				//setZoomFactor(numberComboBox1.getValue()/100);
				((ReportForm)form).setZoomFactor(s);
				return;
			}
			else if (numberComboBox1.getValue()<10 || numberComboBox1.getValue()>1000)
			{
				MessageBox.show("Min: 10 Max: 1000");
				return;	
			}
			
			((ReportForm)form).setZoomFactor(numberComboBox1.getValue()/100);	
		}
	}

	private void panel1_paint(Object source, PaintEvent e)
	{
		
	}
	
	public void setPressed(int element)
	{
		buttonPointer.setPressed((element == 0 ));
		buttonLine.setPressed((element == 1));
		buttonRectangle.setPressed((element == 2));
		buttonField.setPressed((element == 5));
		buttonText.setPressed((element == 4));
		buttonImage.setPressed((element == 3));
		//buttonImage.setPressed((element == 3));
		buttonLens.setPressed((element == 7));
		buttonSR.setPressed((element == 8));
	}

	private void buttonLine_stateChanged(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).setLensMode(	false );
			((ReportForm)form).prepareForNewElement(ReportElementType.LINE_ELEMENT);	
			setPressed(1);
		}
		else
		{
			 setPressed(0);
		}
	}

	private void buttonRectangle_click(Object source, Event e)
	{
				Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).setLensMode(	false );
			((ReportForm)form).prepareForNewElement(ReportElementType.RECTANGLE_ELEMENT);	
			setPressed(2);
		}
		else
		{
			 setPressed(0);
		}
	}

	private void buttonImage_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.IMAGE_ELEMENT);	
			setPressed(3);
		}
		else
		{
			 setPressed(0);
		}
	}

	private void buttonText_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).setLensMode(	false );
			((ReportForm)form).prepareForNewElement(ReportElementType.STATICTEXT_ELEMENT);	
			setPressed(4);
		}
		else
		{
			 setPressed(0);
		}
	}

	private void buttonField_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).setLensMode(	false );
			((ReportForm)form).prepareForNewElement(ReportElementType.TEXTFIELD_ELEMENT );	
			setPressed(5);
		}
		else
		{
			 setPressed(0);
		}
	}

	public void MainForm_MDIChildActivate(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			setPressed(0);
			this.buttonCopy.setEnabled(true);
			this.buttonCut.setEnabled(true);
			this.buttonPaste.setEnabled(true);
			this.buttonPointer.setEnabled(true);
			this.buttonLine.setEnabled(true);
			this.buttonRectangle.setEnabled(true);
			this.buttonImage.setEnabled(true);
			this.buttonText.setEnabled(true);
			this.buttonField.setEnabled(true);
			this.buttonVariables.setEnabled(true);
			this.buttonLens.setEnabled(true);
			this.buttonGroups.setEnabled(true);
			this.buttonSR.setEnabled(true);
			
			// Set undo menu....
			updateUndoMenuState((ReportForm)form);
			
			/*
			if (((ReportForm)form).getReport().filename != null)
			{	
				com.ms.wfc.io.File f = new com.ms.wfc.io.File( ((ReportForm)form).getReport().filename, com.ms.wfc.io.FileMode.OPEN);
				if (((ReportForm)form).getReport().loadTime < f.getLastWriteTime().toLong())
				{
					if ( MessageBox.show(((ReportForm)form).getReport().filename+"\n\nThis file has been modified outside iReport.Do you want reload it?","iReport",MessageBox.ICONQUESTION|MessageBox.YESNO)==DialogResult.YES)
					{
						String filename = ((ReportForm)form).getReport().filename;
						ReportForm rf = openDocument(filename);
						form.dispose();
						rf.focus(); 
					}
				}
			}
			*/
		}
		else
		{
			this.buttonCopy.setEnabled(false);
			this.buttonCut.setEnabled(false);
			this.buttonPaste.setEnabled(false);
			this.buttonPointer.setEnabled(false);
			this.buttonLine.setEnabled(false);
			this.buttonRectangle.setEnabled(false);
			this.buttonText.setEnabled(false);
			this.buttonField.setEnabled(false);
			this.buttonImage.setEnabled(false);
			this.buttonVariables.setEnabled(false);
			this.buttonLens.setEnabled(false);
			this.buttonGroups.setEnabled(false);
			this.buttonSR.setEnabled(false);
			
			
		}
	}

	private void buttonPointer_stateChanged(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).cancelNewObject();
			((ReportForm)form).setLensMode(	false );
		}
		setPressed(0);
	}

	private void buttonNew_buttonClick(Object source, Event e)
	{
		if (ireportProperties.getProperty("TEMPLATE_FILE") != null
			&& com.ms.wfc.io.File.exists(ireportProperties.getProperty("TEMPLATE_FILE")) )
		{
				
					
			ReportForm rpf = openDocument(ireportProperties.getProperty("TEMPLATE_FILE"));
			if (rpf == null) 
			{
				menuItem2_click(source, e);
				return;
			}
			Vector no_valid_names = new Vector();
			Form[] forms =  this.getMDIChildren();
			for (int i=0; i<forms.length; ++i)
			{
				if (forms[i] instanceof ReportForm)
				{
					no_valid_names.addElement( ((ReportForm)forms[i]).getReport().getReportName() );
				}
			}
			boolean valid_name = false;
			for (int i=1;; ++i)
			{
				String name = "Untitled_report_" + i;
				if (!no_valid_names.contains(name))
				{
					rpf.getReport().setReportName(name);
					break;
				}
			}
			rpf.getReport().filename = null;
		}
		else	
			menuItem2_click(source, e);
	}


	private void buttonCut_buttonClick(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).cut(clipboardObjects);
		}
	}

	private void buttonPaste_buttonClick(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).paste(clipboardObjects );
		}
	}

	private void buttonCopy_buttonClick(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).copy(clipboardObjects );
		}
	}

	private void GTImageButton1_buttonClick(Object source, Event e)
	{
		menuItem4_click(source, e);
	}

	private void GTImageButton2_buttonClick(Object source, Event e)
	{
		menuItem3_click(source, e);
	}

	private void menuItem23_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			this.initVariablesForm();
			vf.setReport(((ReportForm)form).getReport());
			vf.setOwner(this);
			vf.show();
		}
	}

	private void buttonLens_stateChanged(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm)
		{
			((ReportForm)form).setLensMode(	buttonLens.getPressed());
			
			setPressed((buttonLens.getPressed()) ? 7 : 0);
		}
		else
		{
			 setPressed(0);
		}
	}

	private void buttonVariables_buttonClick(Object source, Event e)
	{
		menuItem23_click(source, e);
	}

	private void panel2_paint(Object source, PaintEvent e)
	{
		
	}

	private void menuItem24_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			this.initGroupsForm();
			gf.setReport(((ReportForm)form).getReport());
			gf.setOwner(this);
			gf.show();
		}
	}

	private void buttonGroups_buttonClick(Object source, Event e)
	{
		menuItem24_click(source, e);
	}


	private void menuItemCut_click(Object source, Event e)
	{
		
	}

	private void menuItem5_click(Object source, Event e)
	{
		// See if they are open documents....
		// ...
		System.exit(0);
		
	}

	private void menuItem28_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_LEFT );
		}
	}
	

	private void menuItem29_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_RIGHT );
		}
	}

	private void menuItem30_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_TOP );
		}
	}

	private void menuItem31_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_BOTTOM );
		}
	}

	private void menuItem34_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_CENTER_HORIZONTALLY);
		}
	}

	private void menuItem35_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_CENTER_VERTICALLY);
		}
	}

	private void menuItem36_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_CENTER);
		}
	}

	private void menuItem32_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.SAME_WIDTH);
		}
	}

	private void menuItem37_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.SAME_HEIGHT);
		}
	}

	private void menuItem38_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.SAME_SIZE);
		}
	}

	private void menuItem46_click(Object source, Event e)
	{
		this.initDBConnectionsForm();
		cf.setOwner(this);
		cf.show();
	}

	private void menuItem45_click(Object source, Event e)
	{
		
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			this.initQueryForm();
			qf.setReport(((ReportForm)form).getReport() );
			qf.setOwner(this);
			qf.show();
		}
	}

	public Vector getConnectionEntries()
	{
		Vector v = new Vector();
		if (connProperties == null) return v; 
		for (int i=0; ; ++i)
		{
			if (connProperties.getProperty("CON"+i+"_NAME") == null)
				break;  	
			
			ConnectionEntry ce = new ConnectionEntry();
			ce.loadFromProperties(connProperties, i); 
			v.addElement(ce);
		}
		return v;
	}
	private void menuItem42_click(Object source, Event e)
	{
		ClasspathForm cp = new ClasspathForm(this);
		cp.showDialog();
	}
	
	public void updateUndoMenuState(ReportForm rf)
	{
		
		menuItemUndo.setEnabled( rf.undoIndex > 0);
		if (menuItemUndo.getEnabled())
		{
			menuItemUndo.setText("Undo "+ rf.undoOperations.elementAt(rf.undoIndex-1));
		}
		else
			menuItemUndo.setText("Undo");
		
		menuItemRedo.setEnabled( rf.undoIndex < rf.undoOperations.size());
		if (menuItemRedo.getEnabled())
		{
			menuItemRedo.setText("Redo "+ rf.undoOperations.elementAt(rf.undoIndex));
		}
		else
			menuItemRedo.setText("Redo");
		
	}

	private void menuItemUndo_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).undo();
		}
	}

	private void menuItemRedo_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).redo();
		}
	}

	private void menuItem47_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.ALIGN_TOP_TO_BAND);
		}
	}

	private void MainForm_activate(Object source, Event e)
	{
		if (wait) return;
		wait = true;
		Form[] forms = this.getMDIChildren();
		for (int i=0; i<forms.length; ++i)
		{
			Form form = forms[i];
			if (form instanceof ReportForm) 
			{
				if (((ReportForm)form).getReport().filename != null)
				{	
					try {
						com.ms.wfc.io.File f = new com.ms.wfc.io.File(((ReportForm)form).getReport().filename, com.ms.wfc.io.FileMode.OPEN);
						long time = f.getLastWriteTime().toLong();
						f.close();
						if (((ReportForm)form).getReport().loadTime < time)
						{
							if ( MessageBox.show(((ReportForm)form).getReport().filename+"\n\nThis file has been modified outside iReport.Do you want reload it?","iReport",MessageBox.ICONQUESTION|MessageBox.YESNO)==DialogResult.YES)
							{
								String filename = ((ReportForm)form).getReport().filename;
								ReportForm rf = openDocument(filename);
								form.dispose();
								rf.focus(); 
							}
							else
							{
								((ReportForm)form).getReport().loadTime = time;
							}
						}
					} catch (Exception ex) {}
				}
			}
		}
		wait = false;
	}

	private void menuItem49_click(Object source, Event e)
	{
		AboutForm af = new AboutForm();
		af.showDialog();
			
	}
	
	protected void onCreateHandle(Event e)   
	{  
        super.onCreateHandle(e);  
        this.setWindowState(this.getWindowState());  
	}   



	private void menuItem50_click(Object source, Event e)
	{
		String filename="";
		String query="";
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			filename = ((ReportForm)form).getReport().filename; 
			query = ((ReportForm)form).getReport().query; 
		}
		
		JasperReportForm jrf = new JasperReportForm( this);
		jrf.setOwner(this);
		jrf.setFileName(filename);
		jrf.fillConnectionCombo(getConnectionEntries());
		jrf.setQuery(query);
		jrf.show();
	}


	private void menuItem51_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.BRING_TO_FRON);
		}
	}

	private void menuItem53_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.SEND__TO_BACK);
		}
	}

	private void GTImageButtonSR_buttonClick(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).setLensMode(	false );
			((ReportForm)form).prepareForNewElement(ReportElementType.SUBREPORT_ELEMENT );	
			setPressed(8);
		}
		else
		{
			 setPressed(0);
		}
	}

	private void menuItem52_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).prepareForNewElement(ReportElementType.SUBREPORT_ELEMENT);	
		}
	}

	private void menuItem55_click(Object source, Event e)
	{
		OptionsForm of = new OptionsForm(this);
		of.showDialog();
		
	}

	private void compilerButton_buttonClick(Object source, Event e)
	{
		menuItem50_click(source, e);
	}



	private void GTImageButton1_click(Object source, Event e)
	{
		
	}

	private void menuItem63_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.HSPACE_MAKE_EQUAL);
		}
	}

	private void menuItem65_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.HSPACE_INCREASE );
		}
	}

	private void menuItem64_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.HSPACE_DECREASE);
		}
	}

	private void menuItem66_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.HSPACE_REMOVE );
		}
	}

	private void menuItem67_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.VSPACE_MAKE_EQUAL);
		}
	}

	private void menuItem68_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.VSPACE_INCREASE);
		}
	}

	private void menuItem69_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.VSPACE_DECREASE );
		}
	}

	private void menuItem70_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			((ReportForm)form).makeOperation( OperationType.VSPACE_REMOVE);
		}
	}

	private void menuItem72_click(Object source, Event e)
	{
		this.layoutMDI(MDILayout.CASCADE);
	}

	private void menuItem73_click(Object source, Event e)
	{
		this.layoutMDI(MDILayout.TILE_HORIZONTAL);
	}

	private void menuItem74_click(Object source, Event e)
	{
		this.layoutMDI(MDILayout.TILE_VERTICAL);
	}

	private void menuItem75_click(Object source, Event e)
	{
		this.layoutMDI(MDILayout.ARRANGE_ICONS);
	}

	private void GTImageButton2_click(Object source, Event e)
	{
		
	}

	private void menuItem76_click(Object source, Event e)
	{
		ReportWizardForm rw = new ReportWizardForm(this);
		rw.fillConnectionCombo(getConnectionEntries());
		rw.setOwner(this);
		rw.showDialog();
	}

	
	public String getUntitledName()
	{
			Vector no_valid_names = new Vector();
			Form[] forms =  this.getMDIChildren();
			for (int i=0; i<forms.length; ++i)
			{
				if (forms[i] instanceof ReportForm)
				{
					no_valid_names.addElement( ((ReportForm)forms[i]).getReport().getReportName() );
				}
			}
			boolean valid_name = false;
			for (int i=1;; ++i)
			{
				String name = "Untitled_report_" + i;
				if (!no_valid_names.contains(name))
				{
					return name;
				}
			}
	}
	private void menuItem78_click(Object source, Event e)
	{
		// Save file in tmp file...
		wait  = true;
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			if ( ((ReportForm)form).getReport().filename == null )
			{
				if (MessageBox.show("You must save your file before editing it with an external editor!\nSave it now ?","", MessageBox.ICONWARNING|MessageBox.YESNO) == DialogResult.YES) 
				{
					menuItem3_click(source,e);
				}
				else
					return;
			}
			else
			{
				if (MessageBox.show("The document has been modified!\nWould you like to save it before to lunching external editor ?","", MessageBox.ICONQUESTION|MessageBox.YESNO) == DialogResult.YES) 
				{
					menuItem3_click(source,e);
				}
			}
			if (((ReportForm)form).getReport().filename == null) return;
			
			Runtime rt = Runtime.getRuntime(); 
			try {
			//MessageBox.show("notepad.exe "+ ((ReportForm)form).getReport().filename);
			String editor = "notepad.exe";
			if (this.ireportProperties.getProperty("EDITOR")!=null)
			 editor = (String)this.ireportProperties.getProperty("EDITOR");
				
			rt.exec(editor+ " \"" +((ReportForm)form).getReport().filename+"\"");
			} catch (Exception ex)
			{}
		}
		wait  = false;
		// Lunch texteditor...
	}

	private void MainForm_keyDown(Object source, KeyEvent e)
	{
		this.setText(""+e.getKeyCode());
	}

	private void MainForm_Idle(Object sender, Event e)
	{
		// Imposta statusBarStates
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm && 
			(((ReportForm)form).panel9.getFocused() ||
			 ((ReportForm)form).panel8.getFocused() ||
			 ((ReportForm)form).panel7.getFocused() ||
			 ((ReportForm)form).panel6.getFocused() ||
			 ((ReportForm)form).panel5.getFocused() ||
			 ((ReportForm)form).panel4.getFocused() ||
			 ((ReportForm)form).panel3.getFocused() ||
			 ((ReportForm)form).panel2.getFocused() ||
			 ((ReportForm)form).panel1.getFocused()))
		{
			
			if ((GetAsyncKeyState(VK_UP) & 1) == 1)
				((ReportForm)form).panel9_keyDown(this, new KeyEvent(VK_UP));
			else if ((GetAsyncKeyState(VK_DOWN) & 1) == 1)
				((ReportForm)form).panel9_keyDown(this, new KeyEvent(VK_DOWN));
			else if ((GetAsyncKeyState(VK_LEFT) & 1) == 1)
				((ReportForm)form).panel9_keyDown(this, new KeyEvent(VK_LEFT));
			else if ((GetAsyncKeyState(VK_RIGHT) & 1) == 1)
				((ReportForm)form).panel9_keyDown(this, new KeyEvent(VK_RIGHT));
			else if ((GetAsyncKeyState(VK_SHIFT) & 1) == 1)
				((ReportForm)form).panel9_keyDown(this, new KeyEvent(VK_SHIFT));
			
			((ReportForm)form).panel9.focus();
			
		}
	}

	public static final int VK_CAPITAL = 0x14;
	public static final int VK_NUMLOCK = 0x90;
	public static final int VK_UP = 0x26;
	public static final int VK_RIGHT = 0x27;
	public static final int VK_DOWN = 0x28;
	public static final int VK_LEFT = 0x25;
	public static final int VK_SHIFT = 0x10;
	/**
	 * @dll.import("USER32",auto) 
	 */
	public static native short GetKeyState(int nVirtKey);
	
	/**
	 * @dll.import("USER32",auto) 
	 */
	public static native short GetAsyncKeyState(int nVirtKey);
	
	private void menuItem79_click(Object source, Event e)
	{
		Form form = this.getActiveMDIChild();
		if (form instanceof ReportForm) 
		{
			this.initFontsForm( ((ReportForm)form).getReport() );
			fontf.setOwner(this);
			fontf.show();
		}
	}

	private void menuItem80_click(Object source, Event e)
	{
		this.menuItemLock.setChecked(!menuItemLock.getChecked());
	}
	
	public boolean getLockElement()
	{
		return menuItemLock.getChecked();
	}
	
	
	
	public void saveReport(String filename)
	{
		Form[] forms =  this.getMDIChildren();
		for (int i=0; i<forms.length; ++i)
		{
			if (forms[i] instanceof ReportForm)
			{
				if (((ReportForm)forms[i]).getReport().filename != null &&
					((ReportForm)forms[i]).getReport().filename.equals(""+filename))
				{
					
					Report rp = ((ReportForm)forms[i]).getReport();
					saveBackup( rp.filename); 
					rp.saveXMLFile();
					this.addToRecentFileList(rp.filename);
					saveProperties();
					this.updateRecentFileList();
				}
			}
		}
	}

	/**
	 * NOTA: il seguente codice č richiesto dalla finestra di progettazione form 
	 * di Visual J++. Č possibile modificarlo con l'Editor di form.  Non modificarlo
	 * con l'Editor del codice.
	 */
	Container components = new Container();
	MainMenu mainMenu1 = new MainMenu();
	RebarBand rebarBand1 = new RebarBand();
	MenuItem menuItem1 = new MenuItem();
	MenuItem menuItem2 = new MenuItem();
	MenuItem menuItem3 = new MenuItem();
	MenuItem menuItem4 = new MenuItem();
	MenuItem menuItem5 = new MenuItem();
	MenuItem menuItem6 = new MenuItem();
	MenuItem menuItem7 = new MenuItem();
	MenuItem menuItem10 = new MenuItem();
	MenuItem menuItem8 = new MenuItem();
	MenuItem menuItem9 = new MenuItem();
	MenuItem menuItem11 = new MenuItem();
	MenuItem menuItem12 = new MenuItem();
	MenuItem menuItem13 = new MenuItem();
	MenuItem menuItem14 = new MenuItem();
	MenuItem menuItem15 = new MenuItem();
	MenuItem menuItem16 = new MenuItem();
	MenuItem menuItem17 = new MenuItem();
	MenuItem menuItem18 = new MenuItem();
	MenuItem menuItem19 = new MenuItem();
	MenuItem menuItem20 = new MenuItem();
	MenuItem menuItem21 = new MenuItem();
	MenuItem menuItem22 = new MenuItem();
	NumberComboBox numberComboBox1 = new NumberComboBox();
	Rebar srebar1 = new Rebar();
	GTImageButton GTImageButton1 = new GTImageButton();
	GTImageButton buttonCut = new GTImageButton();
	GTImageButton buttonPaste = new GTImageButton();
	GTImageButton buttonLine = new GTImageButton();
	GTImageButton buttonImage = new GTImageButton();
	GTImageButton buttonField = new GTImageButton();
	Panel panel2 = new Panel();
	GTImageButton buttonNew = new GTImageButton();
	GTImageButton GTImageButton2 = new GTImageButton();
	GTImageButton buttonCopy = new GTImageButton();
	GTImageButton buttonPointer = new GTImageButton();
	GTImageButton buttonRectangle = new GTImageButton();
	GTImageButton buttonText = new GTImageButton();
	MenuItem menuItem23 = new MenuItem();
	GTImageButton buttonVariables = new GTImageButton();
	GTImageButton buttonLens = new GTImageButton();
	GTImageButton buttonGroups = new GTImageButton();
	GroupBox groupBox1 = new GroupBox();
	MenuItem menuItem24 = new MenuItem();
	MenuItem menuItemCopy = new MenuItem();
	MenuItem menuItemCut = new MenuItem();
	MenuItem menuItemPaste = new MenuItem();
	MenuItem menuItem25 = new MenuItem();
	MenuItem menuItem26 = new MenuItem();
	MenuItem menuItem27 = new MenuItem();
	MenuItem menuItem28 = new MenuItem();
	MenuItem menuItem29 = new MenuItem();
	MenuItem menuItem30 = new MenuItem();
	MenuItem menuItem31 = new MenuItem();
	MenuItem menuItem32 = new MenuItem();
	MenuItem menuItem33 = new MenuItem();
	MenuItem menuItem34 = new MenuItem();
	MenuItem menuItem35 = new MenuItem();
	MenuItem menuItem36 = new MenuItem();
	MenuItem menuItem37 = new MenuItem();
	MenuItem menuItem38 = new MenuItem();
	MenuItem menuItem39 = new MenuItem();
	MenuItem menuItem40 = new MenuItem();
	MenuItem menuItem41 = new MenuItem();
	MenuItem menuItem45 = new MenuItem();
	MenuItem menuItem46 = new MenuItem();
	MenuItem menuItem42 = new MenuItem();
	MenuItem menuItem43 = new MenuItem();
	MenuItem menuItemUndo = new MenuItem();
	MenuItem menuItemRedo = new MenuItem();
	MenuItem menuItem48 = new MenuItem();
	MenuItem menuItem47 = new MenuItem();
	MenuItem menuItem44 = new MenuItem();
	MenuItem menuItem49 = new MenuItem();
	MenuItem menuItem50 = new MenuItem();
	MenuItem menuItem51 = new MenuItem();
	MenuItem menuItem53 = new MenuItem();
	GTImageButton buttonSR = new GTImageButton();
	MenuItem menuItem52 = new MenuItem();
	ToolTip toolTip1 = new ToolTip(components);
	MenuItem menuItem54 = new MenuItem();
	MenuItem menuItem55 = new MenuItem();
	GTImageButton compilerButton = new GTImageButton();
	MenuItem menuItem56 = new MenuItem();
	MenuItem menuItem57 = new MenuItem();
	MenuItem menuItem58 = new MenuItem();
	MenuItem menuItem59 = new MenuItem();
	MenuItem menuItem60 = new MenuItem();
	MenuItem menuItem61 = new MenuItem();
	MenuItem menuItem62 = new MenuItem();
	MenuItem menuItem63 = new MenuItem();
	MenuItem menuItem64 = new MenuItem();
	MenuItem menuItem65 = new MenuItem();
	MenuItem menuItem66 = new MenuItem();
	MenuItem menuItem67 = new MenuItem();
	MenuItem menuItem68 = new MenuItem();
	MenuItem menuItem69 = new MenuItem();
	MenuItem menuItem70 = new MenuItem();
	MenuItem menuItem71 = new MenuItem();
	MenuItem menuItem72 = new MenuItem();
	MenuItem menuItem73 = new MenuItem();
	MenuItem menuItem74 = new MenuItem();
	MenuItem menuItem75 = new MenuItem();
	MenuItem menuItem76 = new MenuItem();
	MenuItem menuItem77 = new MenuItem();
	MenuItem menuItem78 = new MenuItem();
	MenuItem menuItem79 = new MenuItem();
	MenuItem menuItemLock = new MenuItem();
	MenuItem menuItem80 = new MenuItem();
	public RichEdit richEdit1 = new RichEdit();

	private void initForm()
	{
		// NOTA: questo form contiene informazioni relative alle risorse in
		// un file esterno. Non modificare il parametro di tipo String delle
		// chiamate alla funzione resources.getObject(). Ad esempio, non
		// modificare"foo1_location" nella seguente riga di codice,
		// nemmeno se il nome dell'oggetto Foo viene modificato: 
		//	 foo1.setLocation((Point)resources.getObject("foo1_location"));

		IResourceManager resources = new ResourceManager(this, "MainForm");
		menuItem2.setShortcut(Shortcut.CTRL_N);
		menuItem2.setText("New");
		menuItem2.addOnClick(new EventHandler(this.menuItem2_click));

		menuItem3.setShortcut(Shortcut.CTRL_S);
		menuItem3.setText("Save XML Jasper Report");
		menuItem3.addOnClick(new EventHandler(this.menuItem3_click));

		menuItem4.setShortcut(Shortcut.CTRL_O);
		menuItem4.setText("Load XML Jasper Report");
		menuItem4.addOnClick(new EventHandler(this.menuItem4_click));

		menuItem5.setText("&Quit");
		menuItem5.addOnClick(new EventHandler(this.menuItem5_click));

		menuItem7.setChecked(true);
		menuItem7.setText("Rules");
		menuItem7.addOnClick(new EventHandler(this.menuItem7_click));

		menuItem10.setShortcut(Shortcut.CTRL_R);
		menuItem10.setText("Report properties");
		menuItem10.addOnClick(new EventHandler(this.menuItem10_click));

		menuItem9.setText("Generic element (for debug use only)");
		menuItem9.addOnClick(new EventHandler(this.menuItem9_click));

		menuItem11.setText("Rectangle");
		menuItem11.addOnClick(new EventHandler(this.menuItem11_click));

		menuItem12.setText("-");

		menuItem13.setText("Image");
		menuItem13.addOnClick(new EventHandler(this.menuItem13_click));

		menuItem14.setText("Static text");
		menuItem14.addOnClick(new EventHandler(this.menuItem14_click));

		menuItem15.setText("-");

		menuItem16.setShortcut(Shortcut.CTRL_E);
		menuItem16.setText("Element properties");
		menuItem16.addOnClick(new EventHandler(this.menuItem16_click));

		menuItem17.setShortcut(Shortcut.CTRL_B);
		menuItem17.setText("Elements browser");
		menuItem17.addOnClick(new EventHandler(this.menuItem17_click));

		menuItem18.setText("-");

		menuItem19.setText("Line");
		menuItem19.addOnClick(new EventHandler(this.menuItem19_click));

		menuItem20.setText("Save XML Jasper Report as...");
		menuItem20.addOnClick(new EventHandler(this.menuItem20_click));

		menuItem21.setText("Text field");
		menuItem21.addOnClick(new EventHandler(this.menuItem21_click));

		numberComboBox1.setCursor(Cursor.DEFAULT);
		numberComboBox1.setLocation(new Point(6, 12));
		numberComboBox1.setSize(new Point(72, 21));
		numberComboBox1.setTabIndex(0);
		numberComboBox1.setText("0");
		numberComboBox1.setIsDouble(false);
		numberComboBox1.setDecimals(0);
		numberComboBox1.setValue(0.0d);
		numberComboBox1.setViewPlus(false);
		numberComboBox1.setSeparatoreMigliaia(false);
		numberComboBox1.addOnValueChanged(new EventHandler(this.numberComboBox1_valueChanged));

		GTImageButton1.setEnabled(true);
		GTImageButton1.setLocation(new Point(32, 0));
		GTImageButton1.setSize(new Point(32, 32));
		GTImageButton1.setTabIndex(1);
		GTImageButton1.setText("buttonNew");
		GTImageButton1.setImg1((Bitmap)resources.getObject("GTImageButton1_img1"));
		GTImageButton1.setImg2((Bitmap)resources.getObject("GTImageButton1_img2"));
		GTImageButton1.setImg3(null);
		GTImageButton1.setToggle(false);
		GTImageButton1.addOnClick(new EventHandler(this.GTImageButton1_click));
		GTImageButton1.addOnButtonClick(new EventHandler(this.GTImageButton1_buttonClick));

		buttonCut.setEnabled(false);
		buttonCut.setLocation(new Point(104, 0));
		buttonCut.setSize(new Point(32, 32));
		buttonCut.setTabIndex(10);
		buttonCut.setText("GTImageButton3");
		buttonCut.setImg1((Bitmap)resources.getObject("buttonCut_img1"));
		buttonCut.setImg2((Bitmap)resources.getObject("buttonCut_img2"));
		buttonCut.setImg3((Bitmap)resources.getObject("buttonCut_img3"));
		buttonCut.setToggle(false);
		buttonCut.addOnButtonClick(new EventHandler(this.buttonCut_buttonClick));

		buttonPaste.setEnabled(false);
		buttonPaste.setLocation(new Point(168, 0));
		buttonPaste.setSize(new Point(36, 32));
		buttonPaste.setTabIndex(12);
		buttonPaste.setText("GTImageButton3");
		buttonPaste.setImg1((Bitmap)resources.getObject("buttonPaste_img1"));
		buttonPaste.setImg2((Bitmap)resources.getObject("buttonPaste_img2"));
		buttonPaste.setImg3((Bitmap)resources.getObject("buttonPaste_img3"));
		buttonPaste.setToggle(false);
		buttonPaste.addOnButtonClick(new EventHandler(this.buttonPaste_buttonClick));

		buttonLine.setEnabled(false);
		buttonLine.setLocation(new Point(236, 0));
		buttonLine.setSize(new Point(36, 32));
		buttonLine.setTabIndex(4);
		buttonLine.setText("GTImageButton9");
		buttonLine.setImg1((Bitmap)resources.getObject("buttonLine_img1"));
		buttonLine.setImg2((Bitmap)resources.getObject("buttonLine_img2"));
		buttonLine.setImg3((Bitmap)resources.getObject("buttonLine_img3"));
		buttonLine.setToggle(true);
		buttonLine.addOnStateChanged(new EventHandler(this.buttonLine_stateChanged));

		buttonImage.setEnabled(false);
		buttonImage.setLocation(new Point(300, 0));
		buttonImage.setSize(new Point(32, 32));
		buttonImage.setTabIndex(8);
		buttonImage.setText("GTImageButton11");
		buttonImage.setImg1((Bitmap)resources.getObject("buttonImage_img1"));
		buttonImage.setImg2((Bitmap)resources.getObject("buttonImage_img2"));
		buttonImage.setImg3((Bitmap)resources.getObject("buttonImage_img3"));
		buttonImage.setToggle(true);
		buttonImage.addOnClick(new EventHandler(this.buttonImage_click));

		buttonField.setEnabled(false);
		buttonField.setLocation(new Point(364, 0));
		buttonField.setSize(new Point(32, 32));
		buttonField.setTabIndex(7);
		buttonField.setText("GTImageButton13");
		buttonField.setImg1((Bitmap)resources.getObject("buttonField_img1"));
		buttonField.setImg2((Bitmap)resources.getObject("buttonField_img2"));
		buttonField.setImg3((Bitmap)resources.getObject("buttonField_img3"));
		buttonField.setToggle(true);
		buttonField.addOnClick(new EventHandler(this.buttonField_click));

		panel2.setLocation(new Point(9, 2));
		panel2.setSize(new Point(710, 32));
		panel2.setTabIndex(0);
		panel2.setText("panel2");
		panel2.addOnPaint(new PaintEventHandler(this.panel2_paint));

		rebarBand1.setBandBreak(true);
		rebarBand1.setChildControl(panel2);
		rebarBand1.setChildEdge(false);
		rebarBand1.setIdealWidth(710);
		rebarBand1.setInitialHeight(100);
		rebarBand1.setMaxInitialHeight(32);
		rebarBand1.setMinChildHeight(32);
		rebarBand1.setWidth(200);

		srebar1.setSize(new Point(727, 40));
		srebar1.setTabIndex(0);
		srebar1.setText("rebar1");
		srebar1.setBands(new RebarBand[] {
						 rebarBand1});
		srebar1.setImageList(null);

		buttonNew.setEnabled(true);
		buttonNew.setSize(new Point(32, 32));
		buttonNew.setTabIndex(0);
		buttonNew.setText("");
		buttonNew.setImg1((Bitmap)resources.getObject("buttonNew_img1"));
		buttonNew.setImg2((Bitmap)resources.getObject("buttonNew_img2"));
		buttonNew.setImg3(null);
		buttonNew.setToggle(false);
		buttonNew.addOnButtonClick(new EventHandler(this.buttonNew_buttonClick));

		GTImageButton2.setEnabled(true);
		GTImageButton2.setLocation(new Point(64, 0));
		GTImageButton2.setSize(new Point(32, 32));
		GTImageButton2.setTabIndex(2);
		GTImageButton2.setText("buttonSave");
		GTImageButton2.setImg1((Bitmap)resources.getObject("GTImageButton2_img1"));
		GTImageButton2.setImg2((Bitmap)resources.getObject("GTImageButton2_img2"));
		GTImageButton2.setImg3(null);
		GTImageButton2.setToggle(false);
		GTImageButton2.addOnClick(new EventHandler(this.GTImageButton2_click));
		GTImageButton2.addOnButtonClick(new EventHandler(this.GTImageButton2_buttonClick));

		buttonCopy.setEnabled(false);
		buttonCopy.setLocation(new Point(136, 0));
		buttonCopy.setSize(new Point(32, 32));
		buttonCopy.setTabIndex(11);
		buttonCopy.setText("");
		buttonCopy.setImg1((Bitmap)resources.getObject("buttonCopy_img1"));
		buttonCopy.setImg2((Bitmap)resources.getObject("buttonCopy_img2"));
		buttonCopy.setImg3((Bitmap)resources.getObject("buttonCopy_img3"));
		buttonCopy.setToggle(false);
		buttonCopy.addOnButtonClick(new EventHandler(this.buttonCopy_buttonClick));

		buttonPointer.setEnabled(false);
		buttonPointer.setLocation(new Point(204, 0));
		buttonPointer.setSize(new Point(32, 32));
		buttonPointer.setTabIndex(3);
		buttonPointer.setText("");
		buttonPointer.setImg1((Bitmap)resources.getObject("buttonPointer_img1"));
		buttonPointer.setImg2((Bitmap)resources.getObject("buttonPointer_img2"));
		buttonPointer.setImg3((Bitmap)resources.getObject("buttonPointer_img3"));
		buttonPointer.setToggle(true);
		buttonPointer.addOnStateChanged(new EventHandler(this.buttonPointer_stateChanged));

		buttonRectangle.setEnabled(false);
		buttonRectangle.setLocation(new Point(268, 0));
		buttonRectangle.setSize(new Point(32, 32));
		buttonRectangle.setTabIndex(5);
		buttonRectangle.setText("GTImageButton10");
		buttonRectangle.setImg1((Bitmap)resources.getObject("buttonRectangle_img1"));
		buttonRectangle.setImg2((Bitmap)resources.getObject("buttonRectangle_img2"));
		buttonRectangle.setImg3((Bitmap)resources.getObject("buttonRectangle_img3"));
		buttonRectangle.setToggle(true);
		buttonRectangle.addOnClick(new EventHandler(this.buttonRectangle_click));

		buttonText.setEnabled(false);
		buttonText.setLocation(new Point(332, 0));
		buttonText.setSize(new Point(32, 32));
		buttonText.setTabIndex(9);
		buttonText.setText("GTImageButton12");
		buttonText.setImg1((Bitmap)resources.getObject("buttonText_img1"));
		buttonText.setImg2((Bitmap)resources.getObject("buttonText_img2"));
		buttonText.setImg3((Bitmap)resources.getObject("buttonText_img3"));
		buttonText.setToggle(true);
		buttonText.addOnClick(new EventHandler(this.buttonText_click));

		menuItem23.setText("Values form");
		menuItem23.addOnClick(new EventHandler(this.menuItem23_click));

		buttonVariables.setEnabled(false);
		buttonVariables.setLocation(new Point(436, 0));
		buttonVariables.setSize(new Point(32, 32));
		buttonVariables.setTabIndex(15);
		buttonVariables.setText("GTImageButton3");
		buttonVariables.setImg1((Bitmap)resources.getObject("buttonVariables_img1"));
		buttonVariables.setImg2((Bitmap)resources.getObject("buttonVariables_img2"));
		buttonVariables.setImg3((Bitmap)resources.getObject("buttonVariables_img3"));
		buttonVariables.setToggle(false);
		buttonVariables.addOnButtonClick(new EventHandler(this.buttonVariables_buttonClick));

		buttonLens.setEnabled(false);
		buttonLens.setLocation(new Point(500, 0));
		buttonLens.setSize(new Point(32, 32));
		buttonLens.setTabIndex(14);
		buttonLens.setText("GTImageButton3");
		buttonLens.setImg1((Bitmap)resources.getObject("buttonLens_img1"));
		buttonLens.setImg2((Bitmap)resources.getObject("buttonLens_img2"));
		buttonLens.setImg3((Bitmap)resources.getObject("buttonLens_img3"));
		buttonLens.setToggle(true);
		buttonLens.addOnStateChanged(new EventHandler(this.buttonLens_stateChanged));

		buttonGroups.setEnabled(false);
		buttonGroups.setLocation(new Point(468, 0));
		buttonGroups.setSize(new Point(32, 32));
		buttonGroups.setTabIndex(16);
		buttonGroups.setText("");
		buttonGroups.setImg1((Bitmap)resources.getObject("buttonGroups_img1"));
		buttonGroups.setImg2((Bitmap)resources.getObject("buttonGroups_img2"));
		buttonGroups.setImg3((Bitmap)resources.getObject("buttonGroups_img3"));
		buttonGroups.setToggle(false);
		buttonGroups.addOnButtonClick(new EventHandler(this.buttonGroups_buttonClick));

		groupBox1.setLocation(new Point(536, -6));
		groupBox1.setSize(new Point(84, 38));
		groupBox1.setTabIndex(17);
		groupBox1.setTabStop(false);
		groupBox1.setText("");

		menuItem24.setShortcut(Shortcut.CTRL_G);
		menuItem24.setText("Groups");
		menuItem24.addOnClick(new EventHandler(this.menuItem24_click));

		menuItemCopy.setShortcut(Shortcut.CTRL_C);
		menuItemCopy.setText("Copy");
		menuItemCopy.addOnClick(new EventHandler(this.buttonCopy_buttonClick));

		menuItemCut.setShortcut(Shortcut.CTRL_X);
		menuItemCut.setText("Cut");
		menuItemCut.addOnClick(new EventHandler(this.buttonCut_buttonClick));

		menuItemPaste.setShortcut(Shortcut.CTRL_V);
		menuItemPaste.setText("Paste");
		menuItemPaste.addOnClick(new EventHandler(this.buttonPaste_buttonClick));

		menuItem28.setText("Align Left");
		menuItem28.addOnClick(new EventHandler(this.menuItem28_click));

		menuItem29.setText("Align Right");
		menuItem29.addOnClick(new EventHandler(this.menuItem29_click));

		menuItem30.setText("Align Top");
		menuItem30.addOnClick(new EventHandler(this.menuItem30_click));

		menuItem31.setText("Align Bottom");
		menuItem31.addOnClick(new EventHandler(this.menuItem31_click));

		menuItem32.setText("Same Width");
		menuItem32.addOnClick(new EventHandler(this.menuItem32_click));

		menuItem34.setText("Center Horizontally");
		menuItem34.addOnClick(new EventHandler(this.menuItem34_click));

		menuItem35.setText("Center Vertically (band based)");
		menuItem35.addOnClick(new EventHandler(this.menuItem35_click));

		menuItem36.setText("Center in band");
		menuItem36.addOnClick(new EventHandler(this.menuItem36_click));

		menuItem37.setText("Same Height");
		menuItem37.addOnClick(new EventHandler(this.menuItem37_click));

		menuItem38.setText("Same Size");
		menuItem38.addOnClick(new EventHandler(this.menuItem38_click));

		menuItem27.setMenuItems(new MenuItem[] {
								menuItem32, 
								menuItem37, 
								menuItem38});
		menuItem27.setText("Size...");

		menuItem39.setText("Align vertical axis");

		menuItem40.setText("Align horizontal axis");

		menuItem45.setText("Report query");
		menuItem45.addOnClick(new EventHandler(this.menuItem45_click));

		menuItem46.setText("Connections");
		menuItem46.addOnClick(new EventHandler(this.menuItem46_click));

		menuItem42.setText("Classpath...");
		menuItem42.addOnClick(new EventHandler(this.menuItem42_click));

		menuItem43.setText("-");

		menuItem41.setMenuItems(new MenuItem[] {
								menuItem46, 
								menuItem42, 
								menuItem43, 
								menuItem45});
		menuItem41.setText("Database");

		menuItemUndo.setEnabled(false);
		menuItemUndo.setShortcut(Shortcut.CTRL_Z);
		menuItemUndo.setText("Undo");
		menuItemUndo.addOnClick(new EventHandler(this.menuItemUndo_click));

		menuItemRedo.setEnabled(false);
		menuItemRedo.setShortcut(Shortcut.CTRL_Y);
		menuItemRedo.setText("Redo ");
		menuItemRedo.addOnClick(new EventHandler(this.menuItemRedo_click));

		menuItem48.setText("-");

		menuItem47.setText("Align Top to band");
		menuItem47.addOnClick(new EventHandler(this.menuItem47_click));

		menuItem26.setMenuItems(new MenuItem[] {
								menuItem28, 
								menuItem29, 
								menuItem30, 
								menuItem31, 
								menuItem39, 
								menuItem40, 
								menuItem47});
		menuItem26.setText("Align...");

		menuItem49.setText("About iReport");
		menuItem49.addOnClick(new EventHandler(this.menuItem49_click));

		menuItem44.setMenuItems(new MenuItem[] {
								menuItem49});
		menuItem44.setText("&?");

		menuItem50.setText("IReportCompiler...");
		menuItem50.addOnClick(new EventHandler(this.menuItem50_click));

		menuItem51.setText("Bring to front");
		menuItem51.addOnClick(new EventHandler(this.menuItem51_click));

		menuItem53.setText("Send to back");
		menuItem53.addOnClick(new EventHandler(this.menuItem53_click));

		buttonSR.setEnabled(false);
		buttonSR.setLocation(new Point(396, 0));
		buttonSR.setSize(new Point(32, 32));
		buttonSR.setTabIndex(6);
		buttonSR.setText("");
		buttonSR.setImg1((Bitmap)resources.getObject("buttonSR_img1"));
		buttonSR.setImg2((Bitmap)resources.getObject("buttonSR_img2"));
		buttonSR.setImg3((Bitmap)resources.getObject("buttonSR_img3"));
		buttonSR.setToggle(true);
		buttonSR.addOnClick(new EventHandler(this.GTImageButtonSR_buttonClick));

		menuItem52.setText("Subreport");
		menuItem52.addOnClick(new EventHandler(this.menuItem52_click));

		menuItem22.setMenuItems(new MenuItem[] {
								menuItem9, 
								menuItem11, 
								menuItem13, 
								menuItem14, 
								menuItem19, 
								menuItem21, 
								menuItem52});
		menuItem22.setText("Add");

		toolTip1.setActivate(true);
		toolTip1.setToolTip(GTImageButton1, "Open a report");
		toolTip1.setToolTip(buttonCut, "Cut");
		toolTip1.setToolTip(buttonPaste, "Paste");
		toolTip1.setToolTip(buttonLine, "Line tool");
		toolTip1.setToolTip(buttonImage, "Image tool");
		toolTip1.setToolTip(buttonField, "Field Tool");
		toolTip1.setToolTip(buttonNew, "New report");
		toolTip1.setToolTip(GTImageButton2, "Save the report");
		toolTip1.setToolTip(buttonCopy, "Copy");
		toolTip1.setToolTip(buttonPointer, "Selection tool");
		toolTip1.setToolTip(buttonRectangle, "Rectangle tool");
		toolTip1.setToolTip(buttonText, "StaticText tool");
		toolTip1.setToolTip(buttonVariables, "Open variables window");
		toolTip1.setToolTip(buttonLens, "Lens tool");
		toolTip1.setToolTip(buttonGroups, "Open groups window");
		toolTip1.setToolTip(buttonSR, "Subreport tool");
		toolTip1.setToolTip(compilerButton, "IReportCompiler");
		/* @designTimeOnly toolTip1.setLocation(new Point(196, 104)); */

		menuItem55.setText("Options...");
		menuItem55.addOnClick(new EventHandler(this.menuItem55_click));

		menuItem54.setMenuItems(new MenuItem[] {
								menuItem50, 
								menuItem55});
		menuItem54.setText("Tools");

		compilerButton.setEnabled(true);
		compilerButton.setLocation(new Point(624, 0));
		compilerButton.setSize(new Point(32, 32));
		compilerButton.setTabIndex(13);
		compilerButton.setText("buttonCompiler");
		compilerButton.setImg1((Bitmap)resources.getObject("compilerButton_img1"));
		compilerButton.setImg2((Bitmap)resources.getObject("compilerButton_img2"));
		compilerButton.setImg3((Bitmap)resources.getObject("compilerButton_img3"));
		compilerButton.setToggle(false);
		compilerButton.addOnButtonClick(new EventHandler(this.compilerButton_buttonClick));

		menuItem56.setText("IReportCompiler...");
		menuItem56.addOnClick(new EventHandler(this.menuItem50_click));

		menuItem57.setText("Join sides left");

		menuItem58.setText("Join sides right");

		menuItem33.setMenuItems(new MenuItem[] {
								menuItem34, 
								menuItem35, 
								menuItem36, 
								menuItem57, 
								menuItem58});
		menuItem33.setText("Position...");

		menuItem59.setText("-");

		menuItem62.setText("-");

		menuItem63.setText("Make equal");
		menuItem63.addOnClick(new EventHandler(this.menuItem63_click));

		menuItem64.setText("Decrease");
		menuItem64.addOnClick(new EventHandler(this.menuItem64_click));

		menuItem65.setText("Increase");
		menuItem65.addOnClick(new EventHandler(this.menuItem65_click));

		menuItem66.setText("Remove");
		menuItem66.addOnClick(new EventHandler(this.menuItem66_click));

		menuItem61.setMenuItems(new MenuItem[] {
								menuItem63, 
								menuItem65, 
								menuItem64, 
								menuItem66});
		menuItem61.setText("Horizontal Spacing");

		menuItem67.setText("Make equal");
		menuItem67.addOnClick(new EventHandler(this.menuItem67_click));

		menuItem68.setText("Increase");
		menuItem68.addOnClick(new EventHandler(this.menuItem68_click));

		menuItem69.setText("Decrease");
		menuItem69.addOnClick(new EventHandler(this.menuItem69_click));

		menuItem70.setText("Remove");
		menuItem70.addOnClick(new EventHandler(this.menuItem70_click));

		menuItem60.setMenuItems(new MenuItem[] {
								menuItem67, 
								menuItem68, 
								menuItem69, 
								menuItem70});
		menuItem60.setText("Vertical spacing");

		menuItem25.setMenuItems(new MenuItem[] {
								menuItem26, 
								menuItem27, 
								menuItem33, 
								menuItem59, 
								menuItem61, 
								menuItem60, 
								menuItem62, 
								menuItem51, 
								menuItem53});
		menuItem25.setText("Format");

		menuItem72.setText("Cascade");
		menuItem72.addOnClick(new EventHandler(this.menuItem72_click));

		menuItem73.setText("Tile horizontal");
		menuItem73.addOnClick(new EventHandler(this.menuItem73_click));

		menuItem74.setText("Tile vertical");
		menuItem74.addOnClick(new EventHandler(this.menuItem74_click));

		menuItem75.setText("Arrange Icons");
		menuItem75.addOnClick(new EventHandler(this.menuItem75_click));

		menuItem71.setMenuItems(new MenuItem[] {
								menuItem72, 
								menuItem73, 
								menuItem74, 
								menuItem75});
		menuItem71.setMDIList(true);
		menuItem71.setText("Window");

		menuItem76.setShortcut(Shortcut.CTRL_W);
		menuItem76.setText("Report Wizard");
		menuItem76.addOnClick(new EventHandler(this.menuItem76_click));

		menuItem1.setMenuItems(new MenuItem[] {
							   menuItem2, 
							   menuItem76, 
							   menuItem4, 
							   menuItem3, 
							   menuItem20, 
							   menuItem15, 
							   menuItem5});
		menuItem1.setText("File");

		menuItem77.setText("-");

		menuItem78.setText("Edit XML source...");
		menuItem78.addOnClick(new EventHandler(this.menuItem78_click));

		menuItem79.setText("Fonts");
		menuItem79.addOnClick(new EventHandler(this.menuItem79_click));

		menuItem6.setMenuItems(new MenuItem[] {
							   menuItem7, 
							   menuItem18, 
							   menuItem10, 
							   menuItem16, 
							   menuItem17, 
							   menuItem23, 
							   menuItem24, 
							   menuItem79});
		menuItem6.setText("View");

		menuItemLock.setText("Disable elements mouse move");
		menuItemLock.addOnClick(new EventHandler(this.menuItem80_click));

		menuItem80.setText("-");

		menuItem8.setMenuItems(new MenuItem[] {
							   menuItemUndo, 
							   menuItemRedo, 
							   menuItem12, 
							   menuItemCut, 
							   menuItemCopy, 
							   menuItemPaste, 
							   menuItem48, 
							   menuItemLock, 
							   menuItem80, 
							   menuItem22, 
							   menuItem56, 
							   menuItem77, 
							   menuItem78});
		menuItem8.setText("Edit");

		mainMenu1.setMenuItems(new MenuItem[] {
							   menuItem1, 
							   menuItem8, 
							   menuItem6, 
							   menuItem25, 
							   menuItem41, 
							   menuItem54, 
							   menuItem71, 
							   menuItem44});
		/* @designTimeOnly mainMenu1.setLocation(new Point(296, 72)); */

		this.setText("iReport (c) 2002 by Giulio Toffoli");
		this.setAutoScaleBaseSize(new Point(5, 13));
		this.setClientSize(new Point(727, 490));
		this.setIcon((Icon)resources.getObject("this_icon"));
		this.setIsMDIContainer(true);
		this.setMenu(mainMenu1);
		this.setStartPosition(FormStartPosition.CENTER_SCREEN);
		this.setWindowState(FormWindowState.MAXIMIZED);
		this.addOnKeyDown(new KeyEventHandler(this.MainForm_keyDown));
		this.addOnActivate(new EventHandler(this.MainForm_activate));
		this.addOnMDIChildActivate(new EventHandler(this.MainForm_MDIChildActivate));

		richEdit1.setFont(Font.DEFAULT_GUI);
		richEdit1.setForeColor(Color.WINDOWTEXT);
		richEdit1.setLocation(new Point(8, 48));
		richEdit1.setSize(new Point(36, 32));
		richEdit1.setTabIndex(4);
		richEdit1.setText("richEdit1");
		richEdit1.setVisible(false);

		this.setNewControls(new Control[] {
							richEdit1, 
							srebar1});
		srebar1.setNewControls(new Control[] {
							   panel2});
		panel2.setNewControls(new Control[] {
							  compilerButton, 
							  buttonSR, 
							  groupBox1, 
							  buttonGroups, 
							  buttonLens, 
							  buttonVariables, 
							  buttonPaste, 
							  buttonCopy, 
							  buttonCut, 
							  buttonField, 
							  buttonText, 
							  buttonImage, 
							  buttonRectangle, 
							  buttonLine, 
							  buttonPointer, 
							  GTImageButton2, 
							  GTImageButton1, 
							  buttonNew});
		groupBox1.setNewControls(new Control[] {
								 numberComboBox1});
	}

	/**
	 * Punto di ingresso principale per l'applicazione. 
	 *
	 * @param args Matrice di parametri passata all'applicazione
	 * tramite la riga di comando.
	 */
	public static void main(String args[])
	{
		//MessageBox.show("I'st incredible, but this message box solve a very strange bug\n"
		//				+"on creating an MDI application in VisualJ++.\n\nWelcome to iReport.","Welcome to iReport",MessageBox.ICONINFORMATION);
		Application.run(new MainForm(args));
	}

	/**
	 * @dll.import("KERNEL32", auto) 
	 */
	public static native int GetModuleFileName(int hModule, StringBuffer lpFilename, int nSize);
	

	/**
	 * @dll.import("KERNEL32", auto) 
	 */
	public static native int GetModuleHandle(String lpModuleName);
}
