Monday, 28 March 2011

Form Designing In Flex I


<?xml version="1.0" encoding="utf-8"?>

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:Charts="Charts.*"
xmlns:UserForm="UserForm.*"
layout="absolute" minWidth="955" minHeight="600"
creationPolicy="all">

<mx:Binding source="this.newForm._userCount" destination="this.userCountDP"/>

<mx:Script>
<![CDATA[
import mx.charts.*;
import mx.collections.ArrayCollection;
import mx.controls.*;
import mx.effects.AddItemAction;
import mx.events.*;

import org.alivepdf.display.Display;
import org.alivepdf.layout.Layout;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.pages.Page;
import org.alivepdf.pdf.PDF;
import org.alivepdf.saving.Method;

[Bindable] private var userCountDP:ArrayCollection;
[Bindable] private var isOptionEnabled:Boolean;
private var desktopFile:File = File.desktopDirectory.resolvePath("USER_DATABASE.txt");

public function takeSnapshot(evt:Event):void
{
var userPDF:PDF;
userPDF = new PDF(Orientation.PORTRAIT, Unit.MM, Size.A4 );
userPDF.setDisplayMode(Display.FULL_PAGE, Layout.SINGLE_PAGE );

var newPage:Page = new Page(Orientation.PORTRAIT, Unit.MM, Size.A4 );
userPDF.addPage(newPage);

userPDF.setFontSize(14);
userPDF.addText("USER DATABASE",15, 15);
userPDF.addImage(this.newForm.dataGridID,null,5.90,15.05);

userPDF.addPage();
userPDF.addText("COLUMN CHART",15, 15);
userPDF.addImage(this.newColumnChart ,null ,5.90,15.05);

userPDF.addPage();
userPDF.addText("PIE CHART",15, 15);
userPDF.addImage(this.newPieChart ,null ,5.90,15.05);

userPDF.addPage();
userPDF.addText("LINE CHART",15, 15);
userPDF.addImage(this.newLineChart ,null ,5.90,15.05);

userPDF.addPage();
userPDF.addText("PLOT CHART",15, 15);
userPDF.addImage(this.newPlotChart ,null ,5.90,15.05);

var pdfFileStream:FileStream = new FileStream();
var pdfFile:File;

pdfFile = File.desktopDirectory.resolvePath("Data.pdf");  
pdfFileStream.open( pdfFile, FileMode.APPEND);  

var pdfBytes:ByteArray = userPDF.save(Method.LOCAL);  
pdfFileStream.writeBytes(pdfBytes);  
pdfFileStream.close();
}

private function onClickingItem(event:MenuEvent):void
{
var stringMenu:String = event.item.@label.toString();

switch(stringMenu)
{
case "Open":
this.desktopFile.openWithDefaultApplication();
isOptionEnabled = true;
break;

case "Save":
var desktopFileStream:FileStream = new FileStream();
desktopFileStream.open(this.desktopFile, FileMode.APPEND);
desktopFileStream.writeUTFBytes("\n This file was saved from AIR application without any dialog");
desktopFileStream.addEventListener(Event.CLOSE, fileClosed);
desktopFileStream.close();
break;

case "Exit":
applicationExit();
break;

   /* case "Open PDF":
var pdfFile:File = File.desktopDirectory.resolvePath("Data.pdf");

if( isPDFExist == true)
{
pdfFile.openWithDefaultApplication();
}
else
{
Alert.show("No PDF File to open");
}
break; */

case "Column Chart":
tabNav.selectedIndex = 1;
this.newColumnChart.setFocus();
break;

case "Pie Chart":
tabNav.selectedIndex = 1;
this.newPieChart.setFocus();
break;

case "Line Chart":
tabNav.selectedIndex = 1;
this.newLineChart.setFocus();
break;

case "Plot Chart":
tabNav.selectedIndex = 1;
this.newPlotChart.setFocus();
break;

default:
break;
}
}

private function fileClosed(event:Event):void
{

}

private function applicationExit():void
{  
var exitingEvent:Event = new Event(Event.EXITING, false, true);  

NativeApplication.nativeApplication.dispatchEvent(exitingEvent);  

if (!exitingEvent.isDefaultPrevented())
{      
NativeApplication.nativeApplication.exit();  
}
}

]]>
</mx:Script>

<mx:Form x="10" y="10">
<mx:MenuBar id="myMenuBar" labelField="@label" itemClick="onClickingItem(event)" dataProvider="{MenubarList}" width="214"/>

<mx:TabNavigator width="1133" height="700" label="Details" tabWidth="80" id="tabNav">

<mx:Form label="Details" height="700">
<mx:FormHeading label="Registeration Form" textAlign="left" />
<UserForm:newForm id="newForm" _userCount="{this.userCountDP}" referenceToMainApplicationWindow="{this}"/>
</mx:Form>

<mx:Form label="Charts">
<mx:FormItem>
<mx:HBox>
<Charts:newColumnChart id="newColumnChart" _chartDataProvider="{this.userCountDP}"/>
<Charts:newPieChart id="newPieChart" _chartDataProvider="{this.userCountDP}"/>
</mx:HBox>
<mx:HBox>
<Charts:newLineChart id="newLineChart" _chartDataProvider="{this.userCountDP}"/>
<Charts:newPlotChart id="newPlotChart" _chartDataProvider="{this.userCountDP}"/>
</mx:HBox>
</mx:FormItem>
</mx:Form>

</mx:TabNavigator>
</mx:Form>

<mx:XMLList id="MenubarList">
<menuitem label="File" id="fileID">
<menuitem label="Open" enabled="true" id="2"/>
<menuitem label="Save" enabled="{isOptionEnabled}" id="3"/>
<menuitem label="Exit" enabled="true" id="4"/>
</menuitem>
<menuitem label="PDF" enabled="true" id="10">
<menuitem label="Open PDF" enabled="true" id="11"/>
</menuitem>
<menuitem label="Charts">
<menuitem label="Column Chart" enabled="true" id="5"/>
<menuitem label="Pie Chart" enabled="true" id="6"/>
<menuitem label="Line Chart" enabled="true" id="7"/>
<menuitem label="Plot Chart" enabled="true" id="8"/>
</menuitem>
<menuitem label="Help" id="9">
<menuitem label="About" enabled="true" id="1"/>
</menuitem>
</mx:XMLList>

</mx:WindowedApplication>

No comments:

Post a Comment