GXT Window AutoHide Listener - gxt

I am trying to trap the GXT Window hide event. Below is my code, but it does not work. The Log statement never get called.
myGXTWindowObject.addListener(Events.AutoHide, new Listener<WindowEvent>()
{
#Override
public void handleEvent(WindowEvent arg0) {
Log.info("handle Window AutoHide event");
}
});
Thanks for help!

If myGXTWindowObject is of type com.extjs.gxt.ui.client.widget.Window, it does not actually fire the Events.AutoHide event which you are Listening for, only Events.Hide. See the events section at the end of the docs:
com.extjs.gxt.ui.client.widget.Window

I found the answer. Below is how I did:
this.addWindowListener(new WindowListener() {
public void windowHide(WindowEvent we) {
System.out.println("windowHide");
}
});
Cheers

Related

What's the alternative of onAfterLayout() of GXT2 in GXT3?

I migrate a project from GXT2 to GXT3. I can't find an alternative of the method onAfterLayout(). Any one have an idea please?
One option is to onAttach handler with a schedule deferred wrapped around a function should provide the behavior you want in the next event loop.
final GridWithRadiosWidget grid = new GridWithRadiosWidget();
grid.asWidget().addAttachHandler(new Handler() {
#Override
public void onAttachOrDetach(AttachEvent event) {
if (grid.asWidget().isAttached()) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
// Do something in the next event loop after it's rendered
}
});
}
}
});
And another option is to extend the layout container and extend onResize.

Action listeners not firing

I've been developing with codenameone for over a year, and I never ran into this problem before, I feel like I'm losing my mind. I just redesigned one part of an app I'm working on, and now the ActionListeners aren't firing. I'm attaching them to a Button and a SpanButton in the code:
ActionListener goToDoc = new ActionListener() {
String mDocId = docId;
#Override
public void actionPerformed(ActionEvent evt) {
mStateMachine.currentExpertId = mDocId;
mStateMachine.showForm("DoctorDetails", null);
}
};
name.addActionListener(goToDoc);
Util.downloadImageToStorage(mStateMachine.URL_PREFIX+"images/doctors/"+(String)value.get("doc_pic"),
"doc_post_pic_"+(String)value.get("doc_id")+".png", new Callback<Image>() {
#Override
public void onSucess(Image img) {
pic.setIcon(img.scaledWidth(mStateMachine.getProportionalWidth(.23)));
StateMachine.applyGreenBorder(pic);
pic.addActionListener(goToDoc);
pic.getParent().revalidate();
}
#Override
public void onError(Object sender, Throwable err, int errorCode, String errorMessage) {
System.out.println("Unable to download expert profile picture");
}
});
When I debug the code, the components do show that the ActionListener is attached, but the actionPerformed method is never reached, no matter how many times I click on the buttons. I experience this problem both on the simulator and on an Android device. I have yet to test on an iPhone.
Did you set a parent to be a lead component or focusable?
The reason the click event wasn't firing was because the Components weren't enabled, possibly a bug in the BUI Builder. After checking off the 'Enabled' and 'Focusable' checkboxes in the GUI Builder, and seeing they were unchecked every time I went back to that form, I just used component.setFocusable(true) and component.setEnabled(true) in the code, and it worked fine after that.

onClick event with delay

I've got an ImageButton which is declared in my layout xml. I've told it when it is clicked, to call a certain method, playSound.
Inside of playSound, the phone plays a sound which lasts for a certain amount of time, 5277 ms to be precise. I want playSound to be able to change the ImageResource of the ImageButton for a certain amount of time (5400 ms), and then change it back.
Here's my code:
ImageButton dBellButt;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
dBellButt.setImageResource(R.drawable.doorbell2);
public void playSound(View view) {
dBellButt.setImageResource(R.drawable.doorbell);
dBell.start();
if (vibeOn) {
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(500);
} else {
// No vibration
}
try {
Thread.sleep(5400);
} catch (InterruptedException e) {
}
dBellButt.setImageResource(R.drawable.doorbell2);
}
doorbell2 is an image of a lit doorbell. doorbell is an image of an unlit doorbell.
I can switch the position of the two images and it'll work just fine, ie: if I have the doorbell created lit, when the button is pressed, it'll stay lit until 5400 ms, after which the image changes. If I create the application with the doorbell 'lit,' I cannot change it at all.
Hopefully that made sense.
In short, I cannot get the ImageButton to change ImageResource. The setImageResource after the Thread.sleep(); works fine, but the one before it does not.
How come this isn't working?
Thanks!
Nathan
EDIT:
Figured I would attach my xml just in case.
<ImageButton
android:id="#+id/dBellButton"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:scaleType="fitCenter"
android:padding="0dp"
android:background="#null"
android:onClick="playSound"
android:contentDescription="#string/ImgDesc" />
Cheers
I found a solution. I ended up using the timer class.
Here's my code:
public void playSound(View view) {
dBell.start();
if (vibeOn) {
Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibe.vibrate(500);
} else {
// No vibration
}
Timer timer = new Timer();
TimerTask picSwitch1 = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
dBellButt.setImageResource(R.drawable.doorbell);
}
});
}
};
TimerTask picSwitch2 = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
dBellButt.setImageResource(R.drawable.doorbell2);
}
});
}
};
timer.schedule(picSwitch1, 10);
timer.schedule(picSwitch2, 5400);
}
Using this allows the picture to switch after the delayed time.
The problem I was having with the sleep function was it would cause the application to freeze up (duh...). I couldn't use any of the other given interface. This solution fixes that problem. I'll attach the links I used to solve this.
http://developer.android.com/reference/java/util/Timer.html
http://blog.redkitmedia.com/timer-android-example/
Android timer/timertask causing my app to crash?

Post render event in JavaFX

I'm trying to add a click event listener to the label of all column-headers of a TableView, as follows:
for (final Node header : tblView.lookupAll(".column-header > .label")) {
if ((header != null) && (header instanceof Label)) {
final Label headerLabel = (Label) header;
// ...
}
}
Now, the problem is that if I do this in the initialize()-function of the Controller, the Scenegraph is not yet rendered and the above code won't work. Hence my question: Is there some kind of a post-render event?
many thanks in advance.
There is a WINDOW_SHOWN event in javafx.stage.WindowEvents. That is not (imo) "Post render event" but you can utilize it in similar manner, by adding an event handler to the Stage (which extends from Window).
In the initialize method of controller class, get the primary stage and then:
stage.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent window) {
Platform.runLater(new Runnable() {
#Override
public void run() {
addListenerToColumnHeaders();
}
});
}
});
Hope this helps, since didn't try myself.

Creating a JavaFX Dialog Box

I am coding a javafx program and i need to create and use my own Stage based (Javafx.Stage) dialog box for showing messages and confirmations. I have written all the necessary code by now but i have a problem:
A dialog box must stop execution of rest of the code until a respond is given like "yes" or "no" or "retry". When i use my dialog box like "DialogBox.ShowMessage", a stage appears with message and buttons. But, as you may think, the rest of the code continues to execute. How can i get around this? When i create the stage, it must stop the other threads or the thread that it depends on. I have searched through internet and here, but i can not find exact solution. One idea is using "javafx.event.EventDispatcher" or "javafx.event.EventDispatchChain" but i couldn't figure out how to use them. And another idea is using "java.awt.EventQueue". And here is somthing that can help: I have a control of stage show and hide events and showing or hiding eventhandlers. I think som sort of thread queue can be used in one of these spesific sections.
I hope i clarified the situation enough. Briefly, ı need to manage threads while using another stage with my own code.
Thank you.
About execution suspending there is a Jira issue for it http://javafx-jira.kenai.com/browse/RT-19783.
As a workaround, I have no idea how to use EventDispatcher and EventDispatchChain to overcome this problem but you can send the EventHandlers as parameter. For instance,
public static void ShowMessage(final EventHandler<ActionEvent> okAction, final EventHandler<ActionEvent> cancelAction){
// Define and add buttons to the "view" and show message
btnOk.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
okAction.handle(null);
}
});
btnCancel.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
cancelAction.handle(null);
}
});
}
and use it as,
DialogBox.ShowMessage(
new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent arg0) {
// Do stuff when "ok" clicked.
},
new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent arg0) {
// Do stuff when "cancel" clicked.
});
I agree with this is a kind of "winding" way however.
Siteye hoş geldin ve kolay gelsin.

Resources