I am wondering if I can achieve something like this in Vaadin 8:
The orange bar represents one progress and the green represents another one, which is subset of the orange. Basically, the green bar can be smaller or equal to the orange.
Right now, I have only
Following is the code:
AbstractLayout progressBarInformationLayout =
VaadinLayoutUtility.getInstance().generateHLayout();
progressBarInformationLayout.setStyleName("dashboard_progress_bar_info_layout");
layout.addComponent(progressBarInformationLayout);
float progressBarValue = actualIncludeTotal / (float) predictedInclude;
ProgressBar progressBar = new ProgressBar(progressBarValue);
progressBar.setId("dashboard_progress_bar");
progressBar.setWidth("230px");
progressBar.setStyleName("progress_bar");
progressBarInformationLayout.addComponent(progressBar);
Label progressLabel = new Label(df2.format(progressBarValue * 100) + "%");
progressLabel.setStyleName("progress_label");
progressBarInformationLayout.addComponent(progressLabel);
I haven't tried this, but I'd assume it's semi-easily doable by extending/overriding ProgressBar and its related classes to have two or more progress indicators.
See the handling of indicator variable in VProgressBar, calling of getWidget().setState(getState().state); in ProgressBarConnector, variable state in ProgressBarState, and the getValue and setValue handling in ProgressBar -- you are going to need to duplicate all of those. You'll also need styling for the extra indicators (see Valo styles for ProgressBar).
Given that three of the above are client-side classes, take a look at the Client-Side Development documentation if you aren't familiar with it from before, and remember to recompile your widgetset after every change.
If you ever want a version where the second bar isn't a subset of the first one but a completely different progress, and don't know upfront which task is slowest, I suppose you'll also need extra logic for determining which bar is underneath (otherwise the faster one might hide the slower one), and possibly for swapping the colors of the bars if their relative speed changes. Or you could tweak the design so that both bars are always visible.
Related
I have a Java Swing App which adds JInternalPanes on button click into a JDesktopPane. However, everytime I add a new JInternalPane to the DesktopPane, they all are overlapping and I always have to move the newest one to the side in order to see the previous one again.
Is there any way I can set the position of the newest one slightly to the right of the previous one?
I came up with this workarround but this just looks weird and there is probably a better alternative.
public void createMarket() {
this.appWindow.getDesktopPane().add(new Market(this.restClient, this.websocketClient, this.appWindow.getSymbolTextField().getText(), this.appWindow.getSelectedInterval()));
if (this.appWindow.getDesktopPane().getAllFrames().length > 1) {
JInternalFrame previousFrame = this.appWindow.getDesktopPane().getAllFrames()[this.appWindow.getDesktopPane().getAllFrames().length - 2];
this.appWindow.getDesktopPane().getAllFrames()[this.appWindow.getDesktopPane().getAllFrames().length - 1].setLocation((int)(previousFrame.getLocation().getX() + 100), (int)(previousFrame.getLocation().getY()+100));
}
}
There is no code in the Java platform that would tile or cascade JInternalFrames - you will have to write that yourself.
Here is some example of cascading internal frames:
http://www.java2s.com/Code/Java/Swing-JFC/JDesktopPaneCascadeDemo.htm
Note that the frames are placed using setBounds(). For tiling them, you'd have to check how many there are, decide about the amount of rows and columns, calculate the coordinates and call setBounds() again.
I'm having trouble with a JProgressBar in a Matlab figure. My code is as follows:
figure('color',[1 1 1]);
plot(gca, [0 1],[0 1])
pb = javaObjectEDT('javax.swing.JProgressBar');
javacomponent(pb, [0 0 300 30], gcf);
pb.setVisible(false)
When the progress bar's visibility is set to false, what remains is a gray rectangle that covers the plot. I tried disabling the progress bar or removing it, but couldn't do it with the object methods. Does anybody have any ideas on how to remove it when it's not visible?
Found a couple of possible fixes in case anybody encounters the same issue:
For the example I provided, the progressbar can be found in the figure's children property, and it can be deleted by, once it has been found, using delete(fig.Children(1)) or whatever the index of the progressbar is. It seems that despite the order of adding to the figure, the JavaWrapper object is always the first child, so maybe this is why it's prominent even when invisible.
If using this with a UIFigure or other UI components, the order of components depends on the order of component creation and the order can be modified afterwards. One can use uistack(uicomp, 'top') to move components to the front (but not to move the progress bar to the back; matlab says the 'Parent' of the progress bar is not accessible)
I have a screen in my LibGDX game that will be essentially two columns, the first being 75% of the real estate and containing labels/buttons, and the next being 25% that will contain text and images. It is pretty complicated to include all of the code directly in the screen itself for this.
What I would like to do is to have one object contain the logic for the left side of the screen, and one for the right. This would be similar to ASP.NET, where I have a page, with one user control for the left content, and one for the right.
How can this be setup in a LibGDX screen?
I recommend you use scene2D and create new class for each element.
For example, you can create one class that extends Group for each side. Then you can add a ClickListener to group or to each Actor of the group with your logic.
Actually there are alot of ways you could do this. You can handle the events yourself by checking the if something is touched and if so, you do handle it yourself by the position.
On the other side you can use the scene2D system by creating Actors inside of a Stage and set the inputprocessor to the stage. In that case every event is given to the actors and if its inside of his bounds he does handle it depending on the implemented way (Take a look at this: ActionListenes).
So in your case you could create 2 Actors which are invisible
and everyone of it has its side.
You could also use the Button
from libgdx and use this without a background/foreground or such. Simply set the right sizes and make it invisible by the alpha or no background.
or you do check in every cycle of the gameloop if something is touched and if so you do handle the event as you whish. Take a look at this: input polling and creating an input processor
I'm doing a path-finding project as part of my 4th year software engineering degree.
We're suppose to give visual representation to a bunch of multi-agent pathfinding algorithm. The simplest one is A* adapted for multiagents.
Anyway our environment is a grid map where every cell can be either blocked or used as part of an agent's path. What I want to do is use animation to give a good representation of the final movement of the agent, but animating color change in my grid.
I.E paint every step in the path for a second or so with some color to show how the agent moves.
And the other thing I want to do is to represent the way the algorithm works by painting the changes in the open list and closed list of the A* algorithm while its doing its calculation.
I'm using an adapted version of the observer design pattern to send events from my algorithm layer to my controller and GUI layer.
What I want to do in the GUI layer is every time a tile is added to the open list, I want to have that cell painted in some color and then have it fade away according to a predefined timer or maybe later add a slider to control this timer.
I looked at the code here. It seems pretty simple, the problem is that every tile animation has to be independent of the others to allow the algorithm and everything to keep running and different animations to start.
So what's the best way to achieve the results I'm looking for? Should I just open a different thread for each animation or have a pre-made thread for each cell?
Would that be an overkill for the application, since there can be up to 1000 cells and therefore close to 1000 threads performing animation.
Another issue I think I might encounter is the fact that it might happen that a cell will start its color fading animation and then will have to restart and I don't want the two animations to go at the same time (only one thread performing animation for the same cell at the same time).
I hope I was clear enough with what I'm trying to achieve, if someone has any ideas or thought it could really help me with my project.
You can find Trident animation library useful. More information at http://kenai.com/projects/trident/pages/Home
I would consider a scenario with a single animation thread only. You might e.g. try the following strategy:
standard event thread for swing events
one worker thread for your logic
only one additional for all animations
This third thread manages all animation within your gui. Therefore it maintains a list of animation actions to perform together with their timestamp. Such an action can be e.g. "set color of cell [1,2] to CF0000 # 17:01:00" in an approriate data structure. This list of actions is then filled by the worker thread with the animation actions (e.g. you may add several actions at once for a fading cell - 1) set to 100% # now; 2) set to 75% # now+10s; 3) set to 50% # now+20s ...). Make sure that this list is properly synchronized since it will be accessed from both threads.
If you keep this list sorted by timestamp it is quite easy to determine the which actions this thread has to do at any time. This thread has then a quite simple loop, e.g. something like
while(true) {
AnimationAction action = list.get(0);
if(action!=null && action.timestamp <= now()) {
action.perform(); // <= be sure that paint events occur in the edt
list.remove(0);
continue;
}
sleep(...);
}
Note that you can determine the time to sleep from the timestamp of the next action but consider that a new animation event arriving might have to interrupt this. Otherwise you can also sleep for some short amount of time.
Regarding your second question this thread might remove any actions from this list on demand for a special cell if a new action arrives. Therefore you might also maintain a secondary data structure in order to do this efficiently.
I'd use javax.swing.Timer and AlphaComposite, as demonstrated here.
Sorry for the odd choice of words for the title, however, "border" seems to be the inappropriate term. While it is true that the visible line surrounding an icon in a JToggleButton can be made invisible by using setBorderPainted(false), the same is not true for JCheckBox and JRadioButton.
I can not use the JToggleButton and therefore need to use either the JCheckBox or JRadioButton (or some derivative of JToggleButton I am not aware of), but need the square or circle, respectively, to be non-visible when there is no icon on the button. Also, using setVisible(false) eliminates the button from the layout, however, I need the space to be reserved and not have the component layout change (using GroupLayout).
Any suggestions? Am I going to have to create a custom renderer? I will be looking at that in the mean time.
The route into this would be through customising the look at feel by changing some of the UI properties in the UImanager (the sort of thing that allows you to make simple tweaks with fonts and colours and presumably the images used for the checkboxes or radiobuttons) -- but it's many years since I last did that sort of thing and can't remember the details.
A little Googling turned up this project to inspect current property values, so might at least help with indicating the right part of the APIs to be looking at.
You have to choices here:
1) Customize Look and Feel as described in previous entry.
2) Create your own custom controls by inheriting from existing ones and overriding component painting.
I found a cheap and easy (read hack) for this. I created an empty transparent icon and used it when I didn't want any item to be displayed.