are scala's mouse events working? how? - swing

I'm trying to create link-like label in scala. But no mouse events works for me. How are they supposed to work?
class Hyperlink extends Label{
text = "hyperlink"
reactions += {
case MouseClicked(_,_,_,_,_) =>
println("mouse clicked")}}
I put this in some panel and click over the label like a pro minesweeper player... and nothing shows up in console. Why?

You need to listenTo the relevant thing, something like:
listenTo(this.mouse.clicks)
Edit: since 2.8.0 Mouse is deprecated, use mouse instead

Maybe this should have been a comment to the previous answer, but due to my rep, i cant add comments.
this.Mouse is deprecated and this.mouse should be used instead. Also, this might be a good resource: http://www.scala-lang.org/sid/8

Related

Currency converter - Nothing happens when I press the button

I am trying to make a currency converter. When I type in a number in the input box and then press one off the buttons nothing happens. Does anyone know why?
When checking if a button is clicked in Javascript, it uses a function callback to do so. So, where you have:
if (KnappBL.onclick) {...}
Javascript is looking for:
KnappBL.onclick = function() {...}
Then, inside of the function callback, you can execute your code to show that the currency has changed.
EDIT: You can find more information about the onClick callback on Mozilla's website here.
The thing that stands out the most at a glance would be the absence of a function in your javascript. Try adding something along the lines of the code below (fyi I have not tested this so you may need to tweak it to fit your application). :) hope this leads you in the right direction.
function convert(amount, convertfrom, convertTo) {
if ***********************
else if ************************
else if ************************
}

How to create a MenuItemImage with a callback function in stead of selected image?

I have a MenuItemImage here:
auto myImage = MenuItemImage::create("image.png","image_selected.png",
CC_CALLBACK_1(HelloWorld::onImageClicked,this));
It allow me to input a image.png, which will be changed to image_selected.png on selected when I navigate between items in my menu with keyboard. However, I want to perform some actions when select it with myImage->selected(); (NOT activate it by clicking/touching or calling for myImage->activate(); function), not just a boring image_selected.png.
Now, I'm thinking about set up all of those action in:
keyBoardListener->onKeyPressed = [&](cocos2d::EventKeyboard::KeyCode keycode, Event* event)
{ // Setting up actions on KEY_RIGHT_ARROW or KEY_LEFT_ARROW pressed};
However this way makes things complicated. Therefore, I want to ask if there's any way that I could set up all of my actions as myImage being creating so I could call all of those action with a simple myImage->selected() or stop them with myImage->unselected() later?
Your attention and help is very much appreciated :D
Simply do this:
auto myImage = MenuItemImage::create("image.png", "image_selected.png", [&](Ref* ref){
//your code here
//by ref you can access "myImage" object
});
edit:
I'm not sure what are you trying to achieve. Do you want to have a few buttons in menu, which always one of the is selected and change them using arrows? (so menu navigation is like on console games).
edit2:
After watch a sample yt video I don't think you can achieve this relying only on MenuItemImage. Instead I'd create a ui::Button (if you need clicking/touching as well) or Sprite. Then I'd handle button states by myself. As for glowing frame you probably need some fancy shader or create it in photoshop and add to it an action with constantly fading out and in.

Unable to Access DIV element using Watir

Hi I am trying to access the DIV element using watir but I am unable to do that,I have tried in different ways but couldn't access it,may be I think it need to be access through some parent element can anyone help me out?
My system Configurations
IE-8
Windows 7
I tried with the below command
#ie.div(:text,'COMPOSE').click
the command gets execute with no errors but no action is performed on the UI
The best solution appears to be switching to Watir-Webdriver. With Watir-Webdriver, #ie.div(:text,'COMPOSE').click will work as expected.
Assuming that is not an option, there are a couple of reasons why that same command does not work with Watir(-Classic) v1.6.7:
The first problem is that #ie.div(:text,'COMPOSE').click will find the first div that contains this text. This would be one of the ancestors of the div you want. As a result, Watir will send the click event against the wrong element.
The second problem is that the div is not responding to the onclick event fired by Watir. I am not sure why this problem exists.
To solve the first problem, you will need to be more specific when locating the div. In this case, the "role" attribute can be used since none of the ancestor elements have this attribute. Watir-Classic does not support using the role attribute as a locator. As a result, you will need to create a custom locator using an element collection and the find method:
#ie.divs.find{ |div| div.attribute_value('role') == 'button' && div.text == 'COMPOSE' }
To solve the second problem, it turns out that double clicking does work. While newer versions of Watir-Classic have a double_click method implemented, it does not exist in 1.6.7. You can replicate the method by calling the fire_event method:
.fire_event('ondblclick')
Putting it all together, the following will click the compose button:
#ie.divs.find{ |div| div.attribute_value('role') == 'button' && div.text == 'COMPOSE' }.fire_event('ondblclick')
There may be more than one element on the page with the text 'COMPOSE', some may be hidden. Try:
#ie.divs(:text,'COMPOSE').size
That is divs with an s.
Then you can try something like the following and see if you get a change in the UI:
#ie.divs(:text,'COMPOSE').each { |b| b.fire_event('click') }
I remember that fire_event works better, but would recommend consulting the docs for the difference between .click and fire_event.

ColorPicker not editable in Form -> FormItem

Please note the remark mentioned WORKAROUND at the end of this question.
Based on a Dictionary based specification, one of my classes creates a Form programmatically.
Adding TextInput or DatePicker to FormItemss works as expected.
Unfortunately, the following code just creates a colored rectangle, not the actual picker:
ti = new ColorPicker();
ColorPicker( ti ).selectedColor = TAColor( _spec[ key ].value ).color;
and later on
formItem.addElement( ti );
The Form is embedded in a TitleWindow component presented using
PopUpManager.addPopUp(...);
When added to TitleWindow, it shows up correctly, within Form->FormItem not:
I can't image, why the picker doesn't appear. Do you?
WORKAROUND:
If I wrap the ColorPicker inside a Group things work:
ti = new Group();
Group( ti ).addElement( new ColorPicker() );
In this case, the ColorPicker appears as editable.
Still, I'd be too happy to learn what the problem with my initial solution. Bug?
A DateField (which extends ComboBase like ColorPicker) behaves properly in a spark Form. But in the ColorPicker, the mouse down handler of the button never gets called. I think that maybe the skin part that handles the mouse clicks (it must be a button) is not properly dimensionned, and the result is it is not shown. I've come to this conclusion because within an mx Form, the ColorPicker doesn't display as it does when it is added to the regular displaylist...
Hope this helps...
In the code you've provided, you never add the colorPicker as a child to any parent container; as such it will never show up anywhere.
You probably need to do something like:
formItem.addChild(ti );
[or for a Spark formItem]:
formItem.addElement(ti );
I'm confused as to why you're seeing a rectangle.

Giving/obtaining a reference to (or the name of) a UIScrollBar in a TextArea

This is such a mindnumbingly simple question, but apparently all the forums where actionscript is discussed (or at least all the ones on google) aren't very well managed.
I have a textArea. It has a UIScrollbar. I want to be able to reference that scrollbar. I heard there's an update() function, and that may be able to save me from the inexplicable things this damnable UIScrollbar is doing on its own.
(btw, actionscript = joke language)
When scrollbar is added to TextArea, it dispatches event ADDED. You can catch its scrollbar like this:
textArea.addEventListener(Event.ADDED, onTextAreaChildAdded);
private function onTextAreaChildAdded(event:Event):void {
if (event.target is UIScrollBar) {
//you got it
var scrollBar:UIScrollBar = event.target as UIScrollBar;
}
}
Event with scrollbar will be fired once. There is also many other stuff that adds into TextArea, so type check is needed.
Know ya jokes and be cool ^_^
Edit: wrong... Real solution seems to be just textArea.verticalScrollBar.
In your class just write:
private var usb:UIScrollBar = new UIScrollBar();
and voilá, usb is your reference.