Limiting a window drag movement in Vaadin - java

I have a Vaadin application which contains a header and a menu bar as well. The menu bar provides options where some of which opens up a new Window much similar to a desktop MIDI application. However the window can be moved above the menu and over the header. Does anyone know how it is possible to limit the view movement to within the content area. This content area is currently a VerticalLayout.

There is no built-in way for doing this. I think you have couple of options:
Implement a callback that moves the window to right place after the drag. This is not optimal for usability as it makes the window jump around.
Create / extend the Vaadin's (sub-)Window drag handler to and apply limits there. Unfortunately, this is not as easy as it could be, because you have to tinker with the browser's events directly.

Related

Java Swing - What's the proper way of doing a stage based GUI?

I'm currently developing the menu of my application and I would like to know what's the proper way of coding a "stage based menu". What I mean by stage based menu is that, user clicks a button, the entire interface changes to the next "stage". Here are the pictures I designed in Photoshop in order to explain my idea:
First picture would be the first stage and the second picture the second.
Each round looking thing is a JButton
So far I got the main menu (fist picture) made on eclipse using WindowBuilder, made it as a JPanel and then I instantiate it on the window class.
My idea was to have an event listener listen for clicks on each button and then once the even is triggered, have the JPanel variable on the frame change to the next "stage". So I was wondering if this is actually the proper way of doing this or are there any better ways?
You could use a Card Layout to make it easy to swap panels.
Check out the section from the Swing tutorial on How to Use Card Layout for more information and examples.

Shrink browser content to browser window size

am wondering, if there is a solution for shrinking a charts within browser window, i.a if i resize my browser window my application with highcharts do it well to, it's also resized to the browser window size, but if i shrink my browser window, the app with charts doesn't shrink in size to the browser window size, it only do it when refresh the whole web page, but i need it to be able to do it automatically when you shrink the browser window, the window content also shrinks to the browser sizes, am using java with UiBinder DockLayoutPanel inside RootLayoutPanel. Would be very thankful for any suggestions.
Without specific code examples a specific answer is difficult to give. But to react to browser resize you need to implement the onResize() method. The layout panels you name call this method on children that implement the interface RequireResize. So the panel with the chart should implement the onResize(), and resize the chart. Make sure the parent tree of this widget all implement onResize() or else the method won't be called.
Yes it is possible example (note that I am not using moxie but another wrapper ) : http://data-dragon-766.appspot.com/
You can find the class responsible for rendering the chart.
https://github.com/highcharts4gwt/highcharts/blob/master/src/main/java/com/github/highcharts4gwt/client/view/widget/HighchartsLayoutPanel.java

Draggable border to resize view

The past few months I've been on a mission to implement widget support in my home screen replacement for Android, and it's proving rather difficult. I can now add and remove widgets to/from the home screen, but they can't be resized or moved yet. Currently what I'm trying to achieve is to resize them. To do this I have every widget embedded in a View, over which I put an overlay to make sure the touch events don't get caught by the widget underneath it (which caused trouble in past attempts).
What I have now is this layout for the container; http://www.hastebin.com/uwocaxukel.xml
The widget is put in the FrameLayout with id widgetContainer. As you can see in the screenshot below there is an orange dot in the middle of every border.
Now what I've always tried to do so far is catch touch events, figure out whether the user is trying to drag one of the borders (MotionEvent.ACTION_MOVE), and if he is, change the required properties in the LayoutParams object and call this.requestLayout () on the view. This is finicky, and less than ideal. Very often the touch events would stop registering because the user dragged faster than the view could refresh = user is no longer on the view which is listening for touch events, or the border would be too thin to hit.
So far it's all been very finicky. But there are other apps which seem to do this pretty much perfectly. Is there a library, a class I've overlooked, or something else I can use to achieve my goal?
This is an example of something that kind of worked, but was very finicky and just not remotely user-friendly; https://github.com/RobinJ1995/be.robinj.ubuntu/blob/869d48af2e7a3d8f0332f84edd2a8cd28564424a/UbuntuLauncher/app/src/main/java/be/robinj/ubuntu/widgets/WidgetHostView.java#L75

Java Swing - user alerts

I am trying to build a user alert mechanism by bringing up the window to the front and then flashing the icon on the screen for the user. I have two questions with regards to this approach:
How can you find the current window you are at in Java and then de-minimize it and bring to front?
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
Thanks a lot for any replies.
How can you find the current window you are at in Java and then de-minimize it and bring to front
Window[] allWindows = Window.getWindows();
returns arrays of all Top-Level Containers from current JVM e.g. J/Frame, J/Dialog(JOptionPane), J/Window,
you can to test for (example) if (allWindows[i] instanceof JFrame) {
then WindowState returned WindowEvent
by bringing up the window to the front and then flashing the icon on the screen for the user
use undecodated JDialog (works toFront, toBack) with
create only once time
setDefaultCloseOperations(HIDE_ON_CLOSE)
use Swing Timer for hide JDialog
Is there a mechanism in Java that would enable me to simply show the icon for a second or two and then hide it, in the middle of the screen? If not, what would be the way to achieve that?
have look at Java Translucent Window, put there Icon to the JLabel (or to the JButton)
use Swing Timer for flashing by hiding Icon or swithing bewtween two or more Icons (three or four is good)
I think the simplest way to get the window ancestor is :
SwingUtilities.getWindowAncestor(yourComponent);

Layout for touch screen application

I have to develop a touch screen application based on swing for the GUI part.
The application will have to be displayed on different screen, one 15" 4/3 screen and one 20".
What kind of layout stategy should i go for, to keep the same proportion in my components from one screen to another ?
The application will have a kind of status bar at the top displaying some information coming from a server, a menu bar at the bottom, the main central part of the application will display graphs, and on the right an area that will display the same information as the graphs, but in digital format. Buttons from the menu bar and labels in display/status bar have to be quite big as the users that will play with the screen may wear gloves...
Thanks you for help.
any specific layout manager is not gonna do the trick....Handling the window size is not a problem as that can be taken care of (use ToolKit for that). Only problem is that u gotta make sure that, the component sizes are not fixed, cos when screen size changes that gotta change as well. This is a peculiar problem, lot of trail and testing may be required.

Categories