Add gui components from bottom up instead of top down - blackberry

Is it possible to add gui components to blackberry screen beginning from the bottom instead of the top ?
Thanks

A quick response would be no but let me explain why and suggest afew work arounds;
Screens don't actually handle the laying out of fields onto themselves, to do this they delcare a delegate manager which can be any type of manager, vertical, horizontal etc. The problem is all managers begin painting themselves from the top left. For a manager to paint fields starting from the bottom it would have to know exaclty where the bottom is located and add components up rather than down which goes against all the low level code inside the manager class. You can read more on managers in the BlackBerry API documentation.
You could still achieve an effect similar to this though by tweaking how you add fields and playing with field styles. For example consider this code:
add(new LabelField("field 1"));
add(new LabelField("field 2"));
This would give us the results;
field 1
field 2
because field 1 is drawn then field 2 below it. However if we were always to insert fields at the begining of our manager e.g. position 0 like so:
insert(new LabelField("field 1", FIELD_BOTTOM), 0);
insert(new LabelField("field 2", FIELD_BOTTOM), 0);
We would get the results;
field 2
field 1
Which is the results you'd expect from a screen described in your question.
I'm not really sure how you'd get the fields to paint to the bottom of a screen though, you could try researching the "position relative bottom" styles but I'm honestly unsure.

You are probably using a VerticalFieldManager, and the documentation on that says:
A vertical field manager lays out
fields top to bottom in a single
column.
So if you
manager.add(field1);
manager.add(field2);
manager.add(field3);
The order of the fields on the screen will be just that.
But you could do something like this:
Vector v = new Vector();
v.add(field1);
v.add(field2);
v.add(field3);
for(int i=v.size()-1;i>=0;i--) {
manager.add((Field)v.elementAt(i));
}

Sort of. You can use the Manager#insert(Field, int) method and always insert at the zero index. If you do this with a VerticalFieldManager, it would simulate a bottom-up adding of Fields to the Manager.

Some of the answers so far are to use Manager.insert(Field, int), and keep inserting at position 0. This will work, but the running time of the insert is linear in the number of elements already added to the manager. Meaning this solution will have an overall quadratic running time. Not a big deal if you're adding under 10 fields, but if you're planning on adding more than that, the insert overhead will be substantial.
If you can do the inserts top to bottom, by reordering the fields as Muger's solution suggests, the running time will be much improved.
Finally, you can write your own BottomUpVerticalFieldManager that does the layout the way you want. When you write your own manager, you can layout the fields in whatever way pleases you. In this case, it would be bottom to top. Writing your own manager may seem daunting, but it will give you considerable freedom in the future when trying to solve layout issues.

Related

Get items visible in viewport of Grid in Vaadin 8 & 10

The Grid widget in Vaadin 8 & 10 offers a method to get a Set of the currently selected items: Grid::getSelectedItems.
In a similar vein, I would like to get a collection of the items that are currently visible to the user in the Grid. Say my Grid widget holds 10 items, but only 5 are viewable because the Grid widget is too short to display them all. I want to know which of the five can be seen by the user.
This is not trivial task, I have something similar, but not exactly this case before. First of all, I would I would create custom Layout component, e.g. by extending CssLayout in similar fashion as has been discussed here ( How to make UI receive scroll events ) in addition to reporting scroll events I would report the position of the layout on the viewport (see http://www.gwtproject.org/javadoc/latest/com/google/gwt/dom/client/Element.html ). Yes GWT and client side development is required.
I would use this layout as wrapper for the Grid, i.e. Grid would be in the layout. You could extend the Grid component as well. But I think doing the layout wrapper gives you nice tool that you can use with other components as well for which you need to determine, whether they are actually visible or not.
This way I can then calculate which portion of the layout is in the viewport. As you see, there are number of cases here, e.g. only bottom of the Grid or top of the Grid is visible. Then I need to know row-height, header height, etc. That enables me to calculate how many rows there are visible. I hope you get the idea. The outcome for the generic case will be rather lengthy piece of code when all possibilities are enumerated. This calculation you can do on server side.

Creating a signup form using a tableview in xcode (like SnapChat)

I am looking to improve my app's signup and login form from standard text boxes to using table rows (or something similar).
I am pretty much inspired by the forms which SnapChat have created, which you can see below...
I'm trying to figure out how they accomplished this, and am thinking it must be a table view with 3 cells (Static?), and the text below is part of the footer of that selection of cells.
How is one able to then capture data into it directly?
Am I right in maybe assuming that each cell is 'custom' with a text field in each one (with placeholder text) with a no-borders style on the text field?
Or has this been achieved via some other way?
Keen to hear your thoughts. Thanks!
You absolutely could do that with a table view. But I don't think this one is. Notice the divider lines start at the far left rather than at 15 pixels in (with the text). The separator lines are also two pixels tall rather than one. So I'd say it's a safe bet that it's just a simple view with 1 pixel tall UIView's for lines.

Is there a text editor with columns instead of scrolling?

Is there a text editor which offers horizontal, rather than vertical, scrolling (showing two pages side by side)?
I currently use TextMate, but would switch to any editor which offers this layout. I'm getting really bored of scrolling up and down, over and over.
I've attached a screenshot of MS Word, which has a side-by-side horizontal scroll view for documents longer than a page.
I want something like that, Any recommendations?
Emacs offers a follow-mode which you might find helpful ( see for instance here http://www.emacswiki.org/emacs/FollowMode).
A short description of how it is used and what it does:
You need to open a buffer in two windows and enter follow-mode using M-x follow-mode. This is actually a bit of a drawback, because you need to learn how to use emacs, if you don't know it already (imho learning how to use emacs is worth spending some time).
After entering follow-mode the second buffer will skip to the place where the first buffer ends, similar to the page-by-page view offered by Microsoft Word. Now if you move the cursor down one line at a time and you leave the first buffer window at the bottom, the cursor will appear at the top of the second. If you move further down and you are at the bottom of the second window, both buffers will scroll simultaneously, the same holds for page-wise scrolling using C-v and M-v.
If your monitor screen is wide enough, you can open a third window to further increase number of lines being displayed.
I have made a screenshot, which shows a text file opened in this mode: Screenshot auf Follow mode
Hmmm, it seems you are looking for layout features which you aren't likely to find in a text editor. Text editors are generally line based and don't understand the concept of pages. Text editors do things like code folding and allow lines to be wrapped or not. That is why text editors scroll in the vertical direction. These factors would affect pagination.
The concept of a page (and being able to lay them out side by side) doesn't really exist unless you are using a presentation manager such as a word processor or a desktop publishing package.
In vim: <Esc>:vsplit will open a second column for the file.
In all fairness, I should warn you that Vim has a steep learning curve, and will force you to wrap your head around new concepts like command mode / edit mode / visual mode. The results are definitely worth it, if you have the time to learn it.
I'm not sure if I know exactly what you want. Does Sublime Text 2's two-column layout with File > New View Into File do what you want?
A change on one side is reflected instantly in the other side, and you can scroll them independently. You can have up to four columns per window.
In LibreOffice Writer, go to View -> Zoom... and set Zoom factor to Fit width and height, and set View layout to Automatic. You can also set the number of columns manually, and if you choose two columns, you can use Book Mode.
With scroll-binding in vim, you can edit two files side by side: scroll-binding in Vim.
Show a text file with two columns in vim: http://vim.wikia.com/wiki/View_text_file_in_two_columns

Blackberry complex list

I've got an interesting problem that I'd like some advice and opinions on if you would be so kind. I'm not after code as I prefer to write that for myself. My background is J2ME and Android but I've recently taken up Blackberry.
What I need to write is something akin to the Android ListView albeit a little simpler.
Each row consists of 3 items. There's an image/icon, a multi-line (2 or 3 row) text element and an imagebutton of some form.
However, each row has only 2 columns. The icon/image & multi-line text are combined for the first column and are clickable (with both the column (0) plus the row ID identifiable). The next element in the row (1) is a clickable image (common to all rows - this also needs to have an identifiable row ID). There must be different actions for each column/row cell.
There is a need for multiple rows to be scrollable vertically and there may well be a lot of items.Each row needs to fit the screen width with the icon/multi-line text justified to the left and the clickable image justified to the right. Each row needs all of its components vertically justified (possibly centred) for neatness.
So what we have (for a row) is:
[clickable image/multi-line text combo][clickable image]
Ideally there will be a common background (gradient shaded) for each row once focussed. This should span both columns seamlessly.
Any thoughts would be most appreciated.
The simplest approach is probably to have a VerticalFieldManager for the list, populated by HorizontalFieldManagers for the row.
As for the inner part of the row (the columns) you can pass FIELD_LEFT to the first field and FIELD_RIGHT for the second for alignment. The image-multitext field you can create yourself by extending ButtonField and overriding the paint method. You can use the Graphics object to draw your image and text. A different approach (and perhaps a simpler one) is to extend the HorizontalFieldManager, add your components and make it clickable by capturing the click events.
One thing to realize about Blackberry is that there are many ways to do something, if one thing doesn't work quite the way you want it to, try something different. Hope this help you get started!

Blackberry listfield item adding to a horizontal manager

i have a listfield where i am adding the contents in a horizontal field manager first and then adding the manager to a vertical manager. Visually:
----Image ---Text ----Image
---Text ----Image
---Image
How can i achieve this using a horizontal field manager
You might want to clear up the question a bit, but I'll try to answer what I think you're asking. ListFields don't support (natively) drawing a Manager as its row -- or a Field for that matter. What you'll need to do is in your ListFieldCallback's drawListRow() method, emulate this by doing the painting the way you want it to look. It would end up being measurements with bitmap.getWidth() and font.getAdvance(text) to figure out where to draw the images and text, but it should be a simple enough process.

Resources