Sunday, 15 February 2009

Right click on Tree component, Flex 2

When we bind context menu to Tree component in Flex 2 and click on it with right mouse, we don't know which item has been picked by clicking right mouse button on it. There is a small workaround to solve the problem:

We have
<< mx:Tree id="myXMLTree" width="100%" height="100%" itemRollOver="updateCurrentSelectedItem(event)">>
component.

First of all we bind context menu to it by: myXMLTree.contextMenu = m_menu; Second, the idea is to hande itemRollOver event on a tree, to know on which item the cursor is pointed right now. So "itemRollOver" event handler hold it's value in global variable "selectedTreeItem" every time we roll mouse over any item of the tree we update
selectedTreeItem variable with current item.

public function updateCurrentSelectedItem(le:ListEvent):void {
selectedTreeItem = (le.itemRenderer.data as XML);
}

So when we handle rightClick on tree, we use selectedTreeItem global variable to know which item has been clicked when context menu has been called.

Sunday, 1 February 2009

Flex 2, setting caret (cursor) in TextArea component

When you append text to TextArea component, that doesn't fit TextArea window, you want to move caret (cursor) to the end of the text, but it doesn't happen automaticly. There is a little work around to solve this problem:

Lets assume we have a function that adds text to existing text in TextArea component:

public function appendText(str:String):void {
textAreaComp.text = textAreaComp.text+str;
callLater(setCaretToLastLine);
}

We call to the following function:

private function setCaretToLastLine():void {
textAreaComp.verticalScrollPosition = textAreaComp.maxVerticalScrollPosition;
}

Тhe "setCaretToLastLine()" function moves scroller to the bottom of TextArea component by pointing to the last line of the text. The function called by callLater() because when updating text property of TextArea, "update event" dispatched and could be handled after "setCaretToLastLine()" function, causing maxVerticalScrollPosition property to hold not updated value.

Calling external application through java

We are interested in launching windows application (say telnet) from our java program. There are 2 approved ways to do this:
1) Runtime.getRuntime().exec
("rundll32 SHELL32.DLL,ShellExec_RunDLL C:\\WINDOWS\\system32\\telnet.exe");
or
2) Runtime.getRuntime().exec("cmd.exe /c start C:\\WINDOWS\\system32\\telnet.exe");

test 1 2 3

Posting first message in blog