GWT: How to center element containing CellTable? - gwt

I'm trying to center an element that contains a CellTable. The actual
centering logic works okay, but I'm having problems with all those
attaching/detaching events. Basically, I'm doing this in my container
widget:
#Override
public void onLoad() {
super.onLoad();
center();
}
However, it seems that onLoad on the container does not mean that all
children have loaded, so... the actual centering routine is called too
early and Element.getOffsetWidth/getOffsetHeight are both returning 0.
This results in the container being displayed with the left upper corner
in the center of the screen.
Same thing happens if I use an AttachEvent.Handler on the CellTable.
So... is there any event on CellTable, or on Widget or whatever that
allows me to trigger an action when the DOM subtree has been attached to
the DOM?
Thanks in advance.

Take a look at scheduleDeferred. A deferred command is executed after the browser event loop returns.
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
center();
}
});

Override onAttach instead of onLoad. onAttach default implementation calls onLoad followed by doAttachChildren (which calls onAttach on each child widget), so the following code should call center after the children have been attached:
#Override
public void onAttach() {
super.onAttach();
center();
}
(BTW, the default implementation of onLoad is a no-op)

Related

Android Frame animation does not proceed more than one image

I have created a folder called anim inside res folder. I have put 9 consequtive images in a folder called drawable inside res folder. Now I have created this:
public class AndroidAnimationActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_screen);
ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
final AnimationDrawable myAnimationDrawable= (AnimationDrawable)myAnimation.getDrawable();
myAnimation.post(new Runnable(){
public void run() {
myAnimationDrawable.start();
}
});
}
}
As you see I am trying to display this animation on a page called about_screen. It only shows the first frame and the rest of the frames are not shown (as animation). I have seen several people having similar problem like me but not exactly the same. I hope someone can help me with this. Please be specific. I am a new android learner. Thanks
Even I faced this problem, and the solution is simple.
The problem is, you are calling myAnimationDrawable.start() inside the onCreate() function.
You have two possible alternatives...
First one, make the animation interactive, so that you can call myAnimationDrawable.start()
inside some onClick() function.
Second option is to call myAnimationDrawable.start() inside View.OnFocusChangeListener(). In this case you don't have to make it interactive.

GWT Google Map Api V3 - broken when changing it

It is working fine for me for the first time it is rendered.
But, If I change anything over the map or recreate it, its broken.
Here is the screen shot for how it looks.
Here is a screen shot after I changed the results per page value.
This is my code.
#UiField DivElement mapPanel;
private GoogleMap googleMap;
public void loadAllMarkers(final List<LatLng> markers)
{
if(!markers.isEmpty())
{
final MapOptions options = MapOptions.create();
options.setMapTypeId(MapTypeId.ROADMAP);
googleMap = GoogleMap.create(mapPanel, options);
final LatLngBounds latLngBounds = LatLngBounds.create();
for(LatLng latLng : markers)
{
final MarkerOptions markerOptions = MarkerOptions.create();
markerOptions.setPosition(latLng);
markerOptions.setMap(googleMap);
final Marker marker = Marker.create(markerOptions);
latLngBounds.extend(marker.getPosition());
}
googleMap.setCenter(latLngBounds.getCenter());
googleMap.fitBounds(latLngBounds);
}
}
I am calling the loadAllMarkers() method whenever new results needs to be loaded.
Can someone point out what I am doing wrong here.
This seems to come from the following (which I pulled from a Google+ Community - GWT Maps V3 API):
Brandon DonnelsonMar 5, 2013
I've had this happen and forgotten why it is, but
mapwidget.triggerResize() will reset the tiles. This seems to happen
when the onAttach occurs and animation exists meaning that the div
started smaller and increases in side, but the map has already
attached. At the end of the animation, the map doesn't auto resize.
I'v been meaning to investigate auto resize but I haven't had time to
attack it yet.
In your case, you would call googleMap.triggerResize() after you finish your changes. this solved my problem when I had the exact same issue. I know it's a little late, but I hope it helps!
Another answer there was to extend the Map widget with the following:
#Override
protected void onAttach() {
super.onAttach();
Timer timer = new Timer() {
#Override
public void run() {
resize();
}
};
timer.schedule(5);
}
/*
* This method is called to fix the Map loading issue when opening
* multiple instances of maps in different tabs
* Triggers a resize event to be consumed by google api in order to resize view
* after attach.
*
*/
public void resize() {
LatLng center = this.getCenter();
MapHandlerRegistration.trigger(this, MapEventType.RESIZE);
this.setCenter(center);
}

GWT - event.getX() and event.getClientX()

I added click handler to flowpanel as follows
this.addDomHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
Window.alert("event.getX()="+event.getX()+" event.getY()="+event.getY());
Window.alert("event.getClientX()="+event.getClientX()+" event.getClientY()="+event.getClientY());
}
},ClickEvent.getType());
... as I could get it getX() returns mouse position within flowpanel but getClientX() returns another value and I couldn't get the value is coming from. So my question is what is the getClientXY() methods are used for?
P.S
GWT 2.2/2.3
The javadoc is clear:
getClientX: Gets the mouse x-position within the browser window's client area.
getX: Gets the mouse x-position relative to the event's current target element.
So, you can use getClientX to get the absolute left position of some element.

How to set the Droppable/Draggable Event on the mouse cursor

I've implemented the Drag-n-Drop effects in Wicket using the Ajax Behavior. If I dragg the Image over the tree nodes, the position of droppable accept is in the middle of image. How to set this position (event) on the cursor?
Thank you.
Also I found it. The solution is:
DroppableAjaxBehavior b = new DroppableAjaxBehavior() {
#Override
public void onDrop(Component droppedComponent, AjaxRequestTarget target) {
//do something to handle event
}
};
b.setTolerance(ToleranceEnum.POINTER);

Catching the scrolling event in gtk#

Which event from which widget should I catch when I need to run some code when ScrolledWindow is scrolled?
Ths widgets tree I am using is:
(my widget : Gtk.Container) > Viewport > ScrolledWindow
I tried many combinations of ScrollEvent, ScrollChild, etc. event handlers connected to all of them, but the only one that runs anything is an event from Viewport that about SetScrollAdjutstments being changed to (x=0,y=0) when the application starts.
You should attach to the GtkAdjustment living in the relevant scrollbar, and react to its "changed" event. Since Scrollbars are Ranges, you use the gtk_range_get_adjustment() call to do this.
unwind's answer was correct.
Just posting my code in case someone needs a full solution:
// in the xxx : Gtk.Container class:
protected override void OnParentSet(Widget previous_parent) {
Parent.ParentSet += HandleParentParentSet;
}
void HandleParentParentSet(object o, ParentSetArgs args) {
ScrolledWindow swn = (o as Widget).Parent as ScrolledWindow;
swn.Vadjustment.ValueChanged += HandleScrollChanged;
}
void HandleScrollChanged(object sender, EventArgs e) {
// vertical value changed
}
If you need to change the parent of any of those widgets, or may need to change the types and change the hardcoded types and handle disconnecting from the previous parent.