Location: PHPKode > scripts > UML 2 Classes > uml-2-classes/src/Classes/GUI/UML2Classes.class.php
<?
class UML2Classes{

	var $window;
	var $xmiFileEntry;
	var $outputDirEntry;
	var $generateButton;
	var $radioButtons;
	var $checkBoxes;
	var $xmiFileSelectionButton;
	var $outputDirSelectionButton;
	
	function UML2Classes(){
		
		$this->radioButtons[0] = new GtkRadioButton(null,'PHP4');
		$this->radioButtons[1] = new GtkRadioButton($this->radioButtons[0],'PHP5');
		$this->radioButtons[1]->set_active(true);
		
		$this->radioButtons[2] = new GtkRadioButton(null,'Empty');
		$this->radioButtons[3] = new GtkRadioButton($this->radioButtons[2],'Optional');
		$this->radioButtons[4] = new GtkRadioButton($this->radioButtons[3],'Full');
		
		$this->radioButtons[5] = new GtkRadioButton(null," ' ");
		$this->radioButtons[6] = new GtkRadioButton($this->radioButtons[5],' " ');
		
		$this->checkBoxes[0] = new GtkCheckButton('Getters and Setters');
		$this->checkBoxes[1] = new GtkCheckButton('Constructors and Destructors');
		
		$this->xmiFileEntry = new GtkEntry();
		$this->xmiFileSelectionButton = new GtkButton('...');
		$this->xmiFileSelectionButton->connect_object('clicked',array($this,'selectFile'));
		
		$this->outputDirEntry = new GtkEntry();
		$this->outputDirSelectionButton = new GtkButton('...');
		$this->outputDirSelectionButton->connect_object('clicked',array($this,'selectOutputDir'));
		
		$this->window = new GtkWindow();
		$this->window->set_title("UML2Classes");
		$this->window->set_border_width(10);
		$this->window->add($this->notebook());
	}
	
	function notebook(){
		$notebook = new GtkNotebook();
		$notebook->set_tab_pos(GTK_POS_TOP);
		
		$frame1 = new GtkFrame('Set the XMI File and the Output directory');
		$frame2 = new GtkFrame('Choose the best options for your classes');
		$frame3 = new GtkFrame('About the UML2Classes Software');
		
		$frame1->add($this->fileMenu());
		$frame2->add($this->optionsMenu());
		$frame3->add($this->aboutMenu());
		
		$notebook->append_page($frame1,new GtkLabel('File'));
		$notebook->append_page($frame2,new GtkLabel('Options'));
		$notebook->append_page($frame3,new GtkLabel('About'));
		
		return $notebook;
	}
	
	function fileMenu(){
		$vBox = new GtkVBox();
		
		$label1 = new GtkLabel('XMI File');
		$label1->set_alignment(0,0);
		$label2 = new GtkLabel('Output Directory');
		$label2->set_alignment(0,0);
		
		$hBox1 = new GtkHBox();
		$hBox1->pack_start($this->xmiFileEntry);
		$hBox1->pack_start($this->xmiFileSelectionButton);
		
		$this->outputDirEntry->set_text('C:\\UML2Classes\\Output');
		$hBox2 = new GtkHBox();
		$hBox2->pack_start($this->outputDirEntry);
		$hBox2->pack_start($this->outputDirSelectionButton);
		
		$this->generateButton = new GtkButton('Generate Classes');
		$this->generateButton->connect_object('clicked',array($this,'generate'));
		
		$vBox->pack_start(new GtkLabel(''));
		$vBox->pack_start($label1);
		$vBox->pack_start($hBox1);
		$vBox->pack_start(new GtkLabel(''));
		$vBox->pack_start(new GtkLabel(''));
		$vBox->pack_start($label2);
		$vBox->pack_start($hBox2);
		$vBox->pack_start(new GtkLabel(''));
		$vBox->pack_start(new GtkLabel(''));
		$vBox->pack_start($this->generateButton);
		
		return $vBox;
	}
	
	function optionsMenu(){
		
		$label1 = new GtkLabel('PHP Version:');
		$label1->set_alignment(0,0);
		$label2 = new GtkLabel('Constructor:');
		$label2->set_alignment(0,0);
		$label3 = new GtkLabel('Generate:');
		$label3->set_alignment(0,0);
				
		$vBox = new GtkVBox();
		$vBox->pack_start($label1);
		$vBox->pack_start($this->radioButtons[0]);
		$vBox->pack_start($this->radioButtons[1]);
		$vBox->pack_start(new GtkHSeparator());
		$vBox->pack_start($label2);
		$vBox->pack_start($this->radioButtons[2]);
		$vBox->pack_start($this->radioButtons[3]);
		$vBox->pack_start($this->radioButtons[4]);
		$vBox->pack_start(new GtkHSeparator());
		$vBox->pack_start($label3);
		$vBox->pack_start($this->checkBoxes[0]);
		$vBox->pack_start($this->checkBoxes[1]);
		
		return $vBox;	
	}
	
	function aboutMenu(){
		$aboutText = "   UML2Classes - A PHPTool for UML addicts   \n\n";
		$aboutText .= "Author: Teoni Valois\n";
		$aboutText .= "e-mail: hide@address.com\n";
		$aboutText .= "web: http://www.teoni.jpb.com.br\n";
		$about = new GtkLabel($aboutText);
		return $about;
	}
	
	function selectFile(){
		$fileSelection = new GtkFileSelection('Select the XMI file');
		$fileSelection->complete('*.xmi');
		$ok_button = $fileSelection->ok_button;
		$ok_button->connect_object('clicked',array($this,'fileSelected'),$fileSelection);
		$cancel_button = $fileSelection->cancel_button;
		$cancel_button->connect_object('clicked',array($fileSelection,'hide'));
		$fileSelection->show();
	}
	
	function selectOutputDir(){
		$fileSelection = new GtkFileSelection('Select the Output Directory');
		$ok_button = $fileSelection->ok_button;
		$ok_button->connect_object('clicked',array($this,'outputDirSelected'),$fileSelection);
		$cancel_button = $fileSelection->cancel_button;
		$cancel_button->connect_object('clicked',array($fileSelection,'hide'));
		$fileSelection->show();
	}
	
	function outputDirSelected($fileSelection){
		$this->outputDirEntry->set_text($fileSelection->get_filename());
		$fileSelection->hide();
	}
	
	function fileSelected($fileSelection){
		$this->xmiFileEntry->set_text($fileSelection->get_filename());
		$fileSelection->hide();
	}

	function generate(){

		if($this->xmiFileEntry->get_text()==''){
			$this->messageWindow("No XMI file were selected!\nSelect one and try again.");
			return null;
		}

		if($this->outputDirEntry->get_text()==''){
			$this->messageWindow("No output directory were selected!\nSelect one and try again.");
			return null;
		}

		if($this->radioButtons[2]->get_active()){
			$typeOfConstructor = 0;
		}elseif($this->radioButtons[3]->get_active()){
			$typeOfConstructor = 1;
		}elseif($this->radioButtons[4]->get_active()){
			$typeOfConstructor = 2;
		}
		
		require_once('src/Generator.class.php');
		$Generator = new Generator($this->xmiFileEntry->get_text(),$this->outputDirEntry->get_text(),($this->radioButtons[0]->get_active())?4:5,$this->checkBoxes[0]->get_active(),$this->checkBoxes[1]->get_active(),$typeOfConstructor);
		$total = $Generator->generate();
		$this->messageWindow($total." classes were found in the XMI file and were\ncreated in the specified output directory.");
	}
	
	function messageWindow($text){
		$messageWindow = new GtkWindow();
		$messageWindow->set_border_width(10);
		$messageWindow->set_position(GTK_WIN_POS_CENTER);
		$messageWindow->set_title('Message');
		
		$label = new GtkLabel($text);
		
		$button = new GtkButton('OK');
		$button->connect_object('clicked',array($messageWindow,'hide'));
		
		$vBox = new GtkVBox();
		$vBox->pack_start($label);
		$vBox->pack_start(new GtkLabel(''));
		$vBox->pack_start(new GtkHSeparator());
		$vBox->pack_start(new GtkLabel(''));
		$vBox->pack_start($button);
		
		$messageWindow->add($vBox);
		$messageWindow->show_all();
	}
	
	function run(){
		$this->window->show_all();
		Gtk::main();
	}

}
?>
Return current item: UML 2 Classes