How do I alter the text property of my label to display my "if" statements? - flash-builder

What do I need to place in my SLabel text=" " to display what is defined with my if statements?
Here is my code so far:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.SliderEvent;
protected function ValueSlider_changeHandler(event:SliderEvent):void
{
ValueLabel.text = String(ValueSlider.value);
if(String(ValueSlider.value) == "0")
ValueLabel.text = "150";
if(String(ValueSlider.value) == "1")
ValueLabel.text = "333";
if(String(ValueSlider.value) == "2")
ValueLabel.text = "543";
if(String(ValueSlider.value) == "3")
ValueLabel.text = "9342";
}
]]>
</fx:Script>
<s:Panel x="199" y="141" width="250" height="200">
<s:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" stepSize="1" value="1"/>
<s:Label id="ValueLabel" x="109" y="38" text= "{ValueLabel.text}"/>
</s:Panel>

import mx.events.SliderEvent;
<s:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" stepSize="1" value="1"/>
s:HSlider spark has no SliderEvent
s:HSlider should bind to mx:HSlider. mx:HSlider has no stepSize so remove it.
so that the "ValueSlider_changeHandler(event)" to be effective, it must be set to:
change="ValueSlider_changeHandler(event)"
The complete Line:
<mx:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" value="1" change="ValueSlider_changeHandler(event)"/>
Now it should look like:
<fx:Script>
<![CDATA[
import mx.events.SliderEvent;
private var slvalue:int = 0;
protected function ValueSlider_changeHandler(event:SliderEvent):void
{
slvalue = ValueSlider.value;
if(slvalue == 0)
ValueLabel.text = "150";
if(slvalue == 1)
ValueLabel.text = "333";
if(slvalue == 2)
ValueLabel.text = "543";
if(slvalue == 3)
ValueLabel.text = "9342";
}
]]>
</fx:Script>
<s:Panel x="199" y="141" width="250" height="200">
<mx:HSlider id="ValueSlider" x="78" y="69" maximum="3" minimum="0" value="1" change="ValueSlider_changeHandler(event)"/>
<s:Label id="ValueLabel" x="109" y="38" text= "{ValueLabel.text}"/>
</s:Panel>
You can NOT test it like :
ValueLabel.text = String(ValueSlider.value);
if(String(ValueSlider.value) == "0")
ValueLabel.text = "150";
ValueLabel.text = "150" is immediately overwritten by the next event !!!
Store it in a local variable! Above: slvalue

Related

Why we should write List and DetailedUser in the variable <variable type = "list<DetailedUser" name="">

I don't understand this line of the code why we have list and DetailedUser?
<data>
//app class
<import type = "com.androidistanbul.databindingdemo.layoutdetails.DetailedUser/>
// java class
<import type= "java.util.List"/>
<variable
name = "userList"
type = "detailedUser" /> // import class
<variable
name="userList"
type = "list<DetailedUser" />
</data>
// List index
<TextView
// android:layout_midth = "wrap_content"
// android:layout_height= "wrap_content"
// android:layout_marginTop = "8dp"
android:text="#{userList[index].name + "" + userList[index].surnane}"/>
< and > are html entities and they represent < and >, respectively.
So List<DetailedUser> translates to List<DetailedUser>

extracting values from awk array in one line

I have an array like this ,for each package it hold of count of fail ,testcount,error. or each package i want to extract the values of fail , test count and error and print in one line
test_result["012_project_y2014","fails"] = 1;
test_result["012_project_y2014","testcount"] =3;
test_result["012_project_y2014", "error"] = 1;
test_result["012_project_y2013","fails"] = 0;
test_result["012_project_y2013","testcount"]=1;
test_result["012_project_y2013", "error"] = 1;
for (y in test_result){
split(y,sep1,SUBSEP);
pkg = sep1[1];
result = sep1[2];
if (result == "testcase")
{
ptest = test_result[sep1[1],sep1[2]];
}
if (result == "fail")
{
pfail = test_result[sep1[1],sep1[2]];
}
if(result == "error")
{
perror = test_result[sep1[1],sep1[2]];
}
count = test_result[sep1[1],sep1[2]];
print "<testsuite errors=\42"perror"\42"" " "failures=\42"pfail"\42"" " "hostname=\42localhost\42 id=\"0\42 name=\42"pkg"\42"" ""package=\42"pkg"\42"" " "tests=\42"ptest"\42"" " "timestamp=\42"date"\42"">\n";
}
the output which i am getting is as below where it prints the testsuite for each each count ie fail , test count , error it prints one line
<testsuite errors="" failures="" hostname="localhost" id="0"
name="012_project_y2014 " package="012_project_y2014 " tests="1"
timestamp="">
<testsuite errors="" failures="0" hostname="localhost" id="0"
name="012_project_y2014 " package="012_project_y2014 " tests="1"
timestamp="">
<testsuite errors="" failures="1" hostname="localhost" id="0"
name="012_project_y2013 " package="012_project_y2013 " tests="1"
timestamp="">
<testsuite errors="1" failures="1" hostname="localhost" id="0"
name="012_project_y2014 " package="012_project_y2014 " tests="1"
timestamp="">
<testsuite errors="1" failures="1" hostname="localhost" id="0"
name="012_project_y2013 " package="012_project_y2013 " tests="3"
timestamp="">
<testsuite errors="1" failures="1" hostname="localhost" id="0"
name="012_project_y2013 " package="012_project_y2013 " tests="3"
timestamp="">
the expected output is as below where i can access all the fail , testscase, error of package in one line and print
<testsuite errors="" failures="1" hostname="localhost" id="0" name="012_project_y2013 " package="012_project_y2013 " tests="1" timestamp="">
<testsuite errors="1" failures="1" hostname="localhost" id="0" name="012_project_y2013 " package="012_project_y2013 " tests="3" timestamp="">
or is there a way i can handle this array in a different way where i can get the expected result . i think of a lot nothing worked the above one is getting close for my result but printing 3 lines where i need the results in one line.
any help is appreciated
you would be better off separating the conditions into their own arrays, but lacking that you can have a more systematic approach
test_result["012_project_y2014","fails"] = 1;
test_result["012_project_y2014","testcount"] = 3;
test_result["012_project_y2014","error"] = 1;
test_result["012_project_y2013","fails"] = 0;
test_result["012_project_y2013","testcount"] = 1;
test_result["012_project_y2013","error"] = 1;
for (y in test_result) {
split(y,ss,SUBSEP);
names[ss[1]]; status[ss[2]];
}
for(n in names) {
printf "name=%s", n;
for(s in status) printf "%s=%s", OFS s, test_result[n,s];
print "";
}
...
will give you
name=012_project_y2013 fails=0 error=1 testcount=1
name=012_project_y2014 fails=1 error=1 testcount=3
you can further format the result as your needs...

How to position a Rectangle in Embedded Silverlight?

I'm trying to position a Rectangle on a Canvas but can't figure out what the correct syntax is to do this. In C# I would write
rect = new Rectangle();
rect.Width = 100D;
rect.Height = 50D;
rect.Fill = new SolidColorBrush(Colors.Red);
rect.StrokeThickness = 2;
rect.Stroke = new SolidColorBrush(Colors.Black);
Canvas.SetLeft(rect,5);
Canvas.SetTop(rect,5);
DrawCanvas.Children.Add(rect);
I try to do the same thing with the embedded code but have trouble with positioning the Rectangle. What is the correct way to create and position a shape on a Canvas programatically in embedded Silverlight? This is what I have so far but when running it nothing shows on the Canvas.
HRESULT MainPage::BtnOk_Click (IXRDependencyObject* pSender, XRMouseButtonEventArgs* ? pArgs)
{
HRESULT hr = E_NOTIMPL;
if ((NULL == pSender) || (NULL == pArgs))
{
hr = E_INVALIDARG;
}
IXRApplicationPtr pApplication;
if (FAILED(hr = App::GetApplication(&pApplication)))
return hr;
IXRVisualHostPtr pVisualHost;
if (FAILED(hr = App::GetVisualHost(&pVisualHost)))
return hr;
//Create Brush
IXRSolidColorBrushPtr pPaintBrushRed;
IXRSolidColorBrushPtr pPaintBrushBlack;
COLORREF brushColorRed = RGB(255,0,0);
COLORREF brushColorBlack = RGB(0,0,0);
pApplication->CreateObject(&pPaintBrushRed);
pPaintBrushRed->SetColor(brushColorRed);
pApplication->CreateObject(&pPaintBrushBlack);
pPaintBrushBlack->SetColor(brushColorBlack);
IXRRectanglePtr pRectangle;
IXRFrameworkElementPtr pRootElement;
IXRCanvasPtr pCanvasPanel;
IXRUIElementCollectionPtr pChildrenCollection;
pApplication->CreateObject(IID_IXRRectangle, &pRectangle);
pRectangle->SetWidth(100);
pRectangle->SetHeight(50);
pRectangle->SetFill(pPaintBrushRed);
pRectangle->SetStroke(pPaintBrushBlack);
pRectangle->SetStrokeThickness(2);
pRectangle->SetName(TEXT("MyRect"));
pVisualHost->GetRootElement(&pRootElement);
pRootElement->FindName(TEXT("DrawCanvas"), &pCanvasPanel);
pCanvasPanel->GetChildren(&pChildrenCollection);
pChildrenCollection->Add(pRectangle, NULL);
pCanvasPanel->SetAttachedProperty(L"MyRect.Left",NULL,5);
pCanvasPanel->SetAttachedProperty(L"MyRect.Top",NULL,5);
/*rect = new Rectangle();
rect.Width = 100D;
rect.Height = 50D;
rect.Fill = new SolidColorBrush(Colors.Red);
rect.StrokeThickness = 2;
rect.Stroke = new SolidColorBrush(Colors.Black);
Canvas.SetLeft(rect,5);
Canvas.SetTop(rect,5);
DrawCanvas.Children.Add(rect);*/
return hr;
}
The XAML Code:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ChartApplication"
x:Class="ChartApplication.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White">
<local:ChartControl Margin="97,58,82,89"/>
<Rectangle Fill="#FFE25E5E" Stroke="Black" Height="133" Margin="97,98,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="217"/>
<Ellipse Fill="#FFB7E25E" Stroke="Black" Height="105" HorizontalAlignment="Right" Margin="0,0,41,78" VerticalAlignment="Bottom" Width="235"/>
<Button x:Name="BtnOk" Height="85" HorizontalAlignment="Left" Margin="113,0,0,89" VerticalAlignment="Bottom" Width="155" Content="Ok" Click="BtnOk_Click"/>
<Canvas x:Name="DrawCanvas" HorizontalAlignment="Right" Margin="0,98,41,198" Width="240" Background="#FFE4E4F2"/>
</Grid>
canvas may not support in embedded silverlight.
You can add directly to Grid
IXRUIElementCollectionPtr pElementCollection;
m_pLayoutRoot->GetChildren(&pElementCollection);
int nIndex=0;
pChildrenCollection->Add(pRectangle, &nIndex);
nIndex++;

How to Upload a file using JSF/Primefaces?

I want to upload a file using JSF2.0/Primefaces using <p:fileUpload>. I haven't found any documentation that can help me.
I have two tables: Person(name,lastnam....) and file(id,path,name,size)
The scenario that I want to achieve is:
A user subscribe into my website, I save his information including the files uploaded
When the file is uploaded, I want to save it on my disk and save the
path into my database
(to keep the relation between a user and his files)
So when the user press the button Save button, I save all this information.
Here is my index.xhtml
<h:form >
<p:panel header="Add User" style="width: 500px; font-size: 14px">
<h:panelGrid width="width: 300px;" columns="2">
<h:outputLabel style="font-size: 13px" value="Name" /> <h:inputText value="#{AddPerson.lastname}" />
<h:outputLabel value="LastName"/> <h:inputText value="#{AddPerson.name}" />
<h:outputLabel value="Marital Status"/>
<h:selectOneMenu id="status" value="#{AddPerson.status}">
<f:selectItem itemValue="Single" itemLabel="Single"/>
<f:selectItem itemValue="Married" itemLabel="Married"/>
</h:selectOneMenu>
<h:outputLabel value="Bith date "/> <p:calendar value="#{AddPerson.birthdate}" id="popupButtonCal" showOn="button" />
<h:outputLabel value="email"/><h:inputText value="#{AddPerson.email}" />
<h:outputLabel value="mobile"/><h:inputText value="#{AddPerson.mobile}" />
<h:outputLabel value="fax"/><h:inputText value="#{AddPerson.fax}" />
<h:outputLabel value="Job"/><h:inputText value="#{AddPerson.Job}" />
<h:outputLabel value="addresse"/><h:inputText value="#{AddPerson.addresse}" />
<h:outputLabel value="code"/><h:inputText value="#{AddPerson.code}" />
<h:outputLabel value="Country"/><h:inputText value="#{AddPerson.country}" />
<h:outputLabel value="login"/><h:inputText value="#{AddPerson.login}" />
<h:outputLabel value="password"/><h:inputText value="#{AddPerson.password}" />
<h:outputLabel value="CV"/> <input type="file" name="uploaded_file"/>
<p:fileUpload fileUploadListener="#{AddPerson...." update="messages" sizeLimit="500000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
<p:growl id="messages" showDetail="true"/> // **example :taken from primefaces showcases**
<h:commandButton action="#{AddPerson.addUserDB}" value="Add User" />
</h:panelGrid>
</p:panel>
</h:form>
and here is My bean
public void addUserDB() {
try {
EntityTransaction entr = em.getTransaction();
entr.begin();
Person user = new Person();
user.setNom(lastname);
user.setPrenom(name);
user.setCodepostal(code);
user.setEmail(email);
user.setEtatCivil(status);
user.setFax(fax);
user.setDateNaissance(birthdate);
user.setMobile(mobile);
user.setAdresse(addresse);
user.setPays(country);
user.setLogin(login);
user.setPassword(password);
//**I should also add here the path of the file to the table and save the file on the disc !!!!**
em.persist(user);
entr.commit();
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("Failed");
} finally {
em.close();
}
}
where's the implementation of the fileUploadListener? I normally just do this:
<p:fileUpload cancelLabel="#{msg['cancel']}" update="someComponent"
fileUploadListener="#{someBean.uploadListener}"
multiple="false" sizeLimit="1000000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
Then my bean has a method that handles the file upload event. Something like this:
public void fileUpload(FileUploadEvent event) throws IOException {
String path = FacesContext.getCurrentInstance().getExternalContext()
.getRealPath("/");
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");
String name = fmt.format(new Date())
+ event.getFile().getFileName().substring(
event.getFile().getFileName().lastIndexOf('.'));
File file = new File(path + "catalogo_imagens/temporario/" + nome);
InputStream is = event.getFile().getInputstream();
OutputStream out = new FileOutputStream(file);
byte buf[] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0)
out.write(buf, 0, len);
is.close();
out.close();
}
Keep a reference to the file path that has just been saved and use that for setting the corresponding user property in your addUserDB() method. So it's really a two step process. You first save the file somewhere in the server, then you save your user.
fileUpload has fileUploadListener. Note that, you should implement the logic to save the file contents yourself in your backing bean.
<p:fileUpload fileUploadListener="#{fileBean.handleFileUpload}">
public class FileBean {
public void handleFileUpload(FileUploadEvent event) {
UploadedFile file = event.getFile();
String fileName = file.getFileName();
long fileSize = file.getSize();
InputStream myInputStream = file.getInputstream();
//Save myInputStream in a directory of your choice and store that path in DB
}
}

Identification of objects in Flash Builder 4

I have a very simple question, but I do not know how to do that i can handle in AS script object identifier.
For example, I have a few pictures:
<mx:Image x="125" y="262" source="card/1.jpg" width="98" height="165" id="card1"/>
<mx:Image x="247" y="262" source="card/1.jpg" width="98" height="165" id="card2"/>
<mx:Image x="379" y="262" source="card/1.jpg" width="98" height="165" id="card3"/>
I need to give them a variety of sources taken from the array:
card1.source = "http://***/gallery/7/"+String(arrayOfNumber[0])+".jpg";
card2.source = "http://***/gallery/7/"+String(arrayOfNumber[1])+".jpg";
card3.source = "http://***/gallery/7/"+String(arrayOfNumber[2])+".jpg";
But this is the wrong decision and need the cycle:
for (var i:uint=0; i<=arrayOfNumber.lenght; i++){
card[i].source = "http://***/gallery/7/"+String(arrayOfNumber[i])+".jpg";
}
But that i must use instead of card[i]?
If you place all the images inside a container such as Group (flex 4.x) or Box (Flex 3), you could cycle through the children / elements of that container:
<fx:Script>
<![CDATA[
private var arrayOfNumber:Array = []; // Place your image file names here
private function loopThroughImages():void
{
var n:int = imageContainer.numElements;
for (var i:int = 0; i < n; i++)
{
Image(imageContainer.getElementAt(i)).source = "http://***/gallery/7/"+arrayOfNumber[i]+".jpg";
}
}
]]>
</fx:Script>
<s:Group id="imageContainer">
<mx:Image x="125" y="262" width="98" height="165"/>
<mx:Image x="247" y="262" width="98" height="165"/>
<mx:Image x="379" y="262" width="98" height="165"/>
<s:Group />
[Edit: Wow just realized I'm a year too late.]