Get x/y location of URL/browser bar - gwt

I have a GWT widget that is a Window. The user can drag/drop the Window. I am using an old API called GWT-Ext. It has the ability to implement a listener to detect when the Window has been moved. I want to prevent the Window from being hidden under the browser bar by detecting the XY coordinates of the Window and putting the Window back to the original location if it goes "out of bounds". How can I determine the XY coordinate of the browser bar so I know if my Window is obscured by the browser bar or not?

The browser bar is always at 0. You have to account for the scroll position of the document though, so in effect it's at Document.get().getScrollTop().

I determined that the browser bar was located at 0. So I check if my Y position is less than 0 then call .setPagePosition.
this.addListener(new PanelListenerAdapter()
{
#Override
public void onMove(BoxComponent component, int x, int y)
{
// prevent user from accidentally dragging window under browser bar
if (y <= 0)
{
component.setPagePosition(DEFAULT_X_POS, DEFAULT_Y_POS);
}
}
});

Related

Is it possible to set Ion-Slides to only move in 1 direction?

Once I get to the final slide I want to disable the bounce effect that happens when you try and swipe further. I have ion-option-buttons on the final page and swiping them causes the screen to wobble due to the slides.
I still want to be able to move back to the left / previous slide
If you aren't using the Swiper widget I would recommend it because it offers a lot more flexibility/options with your slide boxes. (Ionic documention on it here, as well).
All you need to do is watch the slide delegate, if you hit the last slide, lock sliding to next (stops the bouncy effect you mentioned). Then unlock sliding if you are not on the last slide.
$scope.$watch('data.sliderDelegate', function(newVal, oldVal) {
if (newVal != null) {
$scope.data.sliderDelegate.on('slideChangeEnd', function() {
$scope.data.currentPage = $scope.data.sliderDelegate.activeIndex;
if($scope.data.currentPage == $scope.data.lastSlide){
$scope.data.sliderDelegate.lockSwipeToNext();
}
else{
$scope.data.sliderDelegate.unlockSwipeToNext();
}
$scope.$apply();
});
}
});
Here is a codepen for the exmaple.
I know this is an old post, but I just managed this in Ionic 4.0, and though that someone might find some value in it.
You can use the command:
this.slides.lockSwipeToNext(true);
To prevent the user from swiping right. There is similarly another command to prevent it going left:
this.slides.lockSwipeToPrev(true);
I placed it in the " ionViewWillEnter()" function to initially disable the swiping, then created a function that I call whenever I want to manually move to the next slide like this:
ionViewWillEnter(){
this.slides.lockSwipeToNext(true);
}
nextSlide(){
this.slides.lockSwipeToNext(false);
this.slides.slideNext();
this.slides.lockSwipeToNext(true);
}
Hope this helps someone looking for a similar soution.

Determine external screen connected to the MacBook computer using NSScreen

I need to show a window on the external screen (e.g. monitor connected to the Macbook). But I don't know how to distinguish between internal MacBook screen and external one. Calling of NSScreen.screens() returns list of all screens and in my case screen with index 0 is my connected external screen and screen with index 1 is my internal (built in) MacBook screen. But documentation says:
The screen at index 0 in the returned array corresponds to the primary screen of the user’s system.
So why is my connected screen marked as primary? Is external screen on all systems is marked as primary => can I suppose that on all systems with connected external screen is this screen on 0 position?
Also, OS X dock is visible only on my internal screen and I thought that dock is by default visible on the primary screen, but that is not true.
Is there a way to reliable determine the correct external screen?
July 2022 Update: Updated the below code to remove the guard statement since NSScreen.screens no longer returns an optional.
To expand on werediver's answer, here's one implementation:
extension NSScreen {
class func externalScreens() -> [NSScreen] {
let description: NSDeviceDescriptionKey = NSDeviceDescriptionKey(rawValue: "NSScreenNumber")
return screens.filter {
guard let deviceID = $0.deviceDescription[description] as? NSNumber else { return false }
print(deviceID)
return CGDisplayIsBuiltin(deviceID.uint32Value) == 0
}
}
}
Usage is simple:
let externalScreens = NSScreen.externalScreens()
You might want to adjust the behavior in the guard statements' else blocks depending on your needs.
There is a note in the beginning of NSScreen Class Reference page:
NOTE
The NSScreen class is for getting information about the available displays only. If you need additional information or want to change the attributes relating to a display, you must use Quartz Services. For more information, see Quartz Display Services Reference.
From Quartz Display Services Reference we can learn that the main screen is not necessary the built-in one. From CGMainDisplayID() description:
The main display is the display with its screen location at (0,0) in
the global display coordinate space. In a system without display
mirroring, the display with the menu bar is typically the main
display.
If mirroring is enabled and the menu bar appears on more than one
display, this function provides a reliable way to find the main
display.
In case of hardware mirroring, the drawable display becomes the main
display. In case of software mirroring, the display with the highest
resolution and deepest pixel depth typically becomes the main display.
So, if you can use Quartz Display Services directly, use CGDisplayIsBuiltin() function to determine whether the display is built-in or not.

Scroll chart with mouse wheel in TeeChart

Default way to scroll chart is to drag mouse holding right button. I need to scroll with mouse wheel. I haven't found any API to enable/disable mouse wheel scrolling.
I also tried to add MouseWheelListener to the chart itself, but it never gets called.
Is it possible to use mouse wheel in TeeChart lib?
My application is Eclipse RCP using SWT.
The following code works fine for me with TeeChart Java SWT in Eclipse:
Bar bar1 = new Bar(tChart1.getChart());
bar1.fillSampleValues();
tChart1.addMouseWheelListener(new MouseWheelListener() {
#Override
public void mouseScrolled(MouseEvent arg0) {
Axis tmpA = tChart1.getAxes().getLeft();
double tmpInc = tmpA.getRange()/10;
if (arg0.count>0)
tmpA.setMinMax(tmpA.getMinimum()+tmpInc, tmpA.getMaximum()+tmpInc);
else
tmpA.setMinMax(tmpA.getMinimum()-tmpInc, tmpA.getMaximum()-tmpInc);
}
});

How to implement dragging in LWUIT?

My LWUIT application has 3 Forms:
1) FormA
2) FormB
3) FormC
The current form being displayed on the screen is FormB.
Case 1:
If the user swipes his finger LEFT on his touch screen phone, I want LWUIT to capture that
event and display FormC
Case2:
If the user swipes his finger RIGHT on his touch screen phone, I want LWUIT to capture that
event and display FormA
How do I do this? I think it has to do something with drag event but not sure how to implement it.
Thanks.
just need to override pointerDragged method in form and get/cal its X,Y positions and display another form.
new Form()
{
protected void pointerDragged(int x, int y) {
if(x,y....)
{
form3.show();
}else
{
from1.show();
}
super.pointerDragged(x,y);
}
};
here x,y can be calculated based on screen resolutions and components u have added to it.
Use the Tabs component with 3 Containers, it supports Swipe. You can set the Tabs themselves to be hidden.
instead of taking 3 forms use 3 containers under 1 form and setScrollableX(true) and add all components in appropriate containers.

Determining the location of a GTK widget on-screen to create a relevant popup window

I have a button labeled import (down arrow) and I am trying to determine it's location so I can create a popup menu to say 1. from device 2. from folder.
I can't seem to find anymore than allocation in the api docs, which is relative to the application window. Please help, I will send imaginary cookies ^_^.
using PyGI if it matters.
I figured out the answer before but couldn't self answer yet.
The process is as follows:
determine the location of the GdkWindow, which does not contain the window decorations.
: gdk_window_x, gdk_window_y
determine the location of the widget relative to it's GdkWindow
: widget_x, widget_y
x = gdk_window_x + widget_x
y = gdk_window_y + widget_y
as everything in the graphics world measures from top left (unless your weird :-)), you now have the location of the top left pixel of your widget.
You can get the position of the window relative to the screen using window.get_position(). Since you already know how to get the position of the button relative to the window, it should be a matter of adding up both to get the coordinates (relative to the screen) in which to place the popup.