Listfield focus issue in blackberry - java

I am using list-field in a BlackBerry application. In each list-field item, I have a bitmap-field at the left, text at center and again a bitmap-field at the right.
Can I determine whether the fields are focusable inside the list-field rows for keypad versions of BlackBerry Devices for e.g BlackBery Tour?

No in list field no control except whole row is focusable explicitly. If you want to perform any click events you can use touchEvent() but the calculation will be too complex and not so reliable.
If you want to have separate clickable items in one row you must use HorizontalFieldManager each time.
Update: : I have come across this scenario twice, and if I were in place of you I will consider what exactly the feature is about, If you are concerned about UI and there is not any heavy functionality behind focusing you can try touchEvent or navigationClick but using both will be cumbersome. Too much logic, too much thinking, hard to test.
If there is any functionality, you have an option to add them on menu, It will be more convenient way than using horizontal field manager or the above mentioned methods.

Related

Java GUI architecture for larger project

I want to make an app, which will work as interface to several servers.
Why: In web iface provided by default (and we cannot change it) are few things we miss, few could be done better and for sure automation of some stuff would make the job easier.
What do I have: almost finished classes for communication with web interface of a server app.
GUI description:
For some kind of version 0.1: text field for username, radio button to select server and one "go" button. Then several (4-12) action buttons to operate on data, 2x text area with results, one label with some text data - I can manage this.
Then I need to view the data - grid MxN which will load the data, expected size: 7-15 columns, usually 10 rows or less, but rarely it can go over 1k (or even more, but I don't need all to be visible to the user in that case).
What I need: simply an advice.
I wish to start with a simple version (and I'm working on that already, but I'm stuck on too many things - 95% cos and absolutely new to GUI and 5% cos I'm new to java).
I've checked many tutorials, but they're all simple.
Real questions:
1) Verify. In MVC controller should handle all user actions - is it done by view's method which is something like button.addActionListener(param); anotherButton.addActionListener(paramp; ...?
1b) I've seen all implemented via one (nested) class, which was then checking source or smth - is that ok? There will be a lots of buttons etc.
2) How to implement the data grid, when I need to take actions on click / dbl click?
4) First row is header, the rest should be scroll able - should it be in the grid or outside (its own grid):
4a) How to make sure header's size (width) will be the same as in data (I don't want to set up straight size)
4b) I failed to create anything scrollable so far, but thats my bad I guess. How to ensure header will hold on a place and the rest can be scrolled?
5) How should be "data update" implemented? I've got JPanel from which I remove grid component and then I make new one and add data into it (simple, but perhapss there is another way). One of first enhancements will be sorting - use the same way I used for new content?
Thanks a lot for any answer, I know this is not very specific, but example I've found are too simple.
I plan a lots of enhancements, but thats in the future and I don't mind to rework GUI/Controller several times, at least, I'll practise, but I don't want to finish one part of the code and realise I've got to rewrite half of a controller and 1/4 of a view to make it possible.
Note: I plan to use this at work as my tool (if things go right, I could make 25-50% of my work by few clicks :-)
So I really mean this).
Note#2: I'm not new to programing, but I've never created GUI (which is why I've got GUI with menu bar with 2 items and 3 components and almost done web-iface connections).
Note#:3 dragable data header, tabbed data view - thats the plan for the future :-)
MVC in Swing is examined here; use nested classes for ease in prototyping and creating an mcve for future questions; as the need arises, nested classes can be promoted to separate classes having package-private access.
Use JTable; its flyweight implementation of renderers is good for organizing data by row and column.
Item three does not exist, but "always remember to translate cell coordinates" if you plan to drag columns or sort rows.
Use a JScrollPane to keep the table header stationary.
Update the TableModel, and the listening view will update itself in response.
If you are interested not only from the event/messaging architecture, but also on handling mouse/keyboard input, hovering detection, widgets, temporary menus, form re-sizing with widget alignment, dragging and dropping etc. I can advice you to look at this question and my answer with helpful resources.

Tracking data offset of data in a table to retrieve the previous/next subset on table scroll

I am writing a browser based application using GWT and making use of websql (yes, I know it is deprecated). I have created a custom table widget (based on FlexTable) and enabled it to scroll with the help of some CSS trickery. What I am striving to achieve (without much success) is that when the user scrolls to the start/end of the current data in the table, an event is fired and the next subset of X rows is returned from the websql DB and replaces the data currently in the table. In order for this to work, I need to keep track of the data offset in the table widget so that I can pass this to the query and use the limit and offset functions of SQL to return the required data. However, I just cannot seem to get the logic right to implement the data offset tracker within the widget. Another complication is that I need the table to be able to scroll 'into the past' (so to speak), so that it can retrieve data from before the initial start point when the table loads.
I have been at this for a number of days now and just cannot seem to get it right. So I was wondering/hoping that someone might be able to point me in the right direction (PLEASE!).
Thanks in advance
Tim
I am not sure why this is causing a problem.
int page = 0;
// when you hit the bottom
page++;
loadData(page);
// when you hit the top
if (page > 0) {
page--;
loadData(page);
}
Tim I think it is not a good idea controlling the scroll with CSS trickery.
I have done something similar soon and controlling all the logic (pagination, scroll positions,...).
What I suggest to use is a gwt's scrollPanel, a HasData widget (like a cellList) your custom AbstractCell (class which is rendered for each row of your list) and asyncDataProvider ( which gives you the onRangeChange handler for asking to your server when the range data display has changed).
You can force/fire that event when in scrollPanel.addScrollHandler detects you are arriving to the end.
If you want to see all of this in action have a look into (click on source code): http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellList
EDIT [according comment below]:
A. If you want to override the data (in the example is X+X+X...) with the new retrieved just maintain always the same range of data displayed [display.setVisibleRange(0, newPageSize);], and start from 0 when you render the new data (on your RangeChange listener).
B. If you need to have control over up and down scrolls instead of taking advantage of the used events internally on the cellList (basically onRangeChange), you can create your custom events and fire them (this option could be easier for your colleagues for understanding everything). And do not worry about controlling up and down scrolls, inside the ShowMorePagerPanel.java you can see a simple example of knowing up and down controls.
Anyway, I did not explain more detailed because I did not see you very convinced to use CellList approach (and I was using my tablet :D ).
If you change your mind, just let me know and I write for you a proper example step by step (this part could be tricky, so if you are lost it is normal ;) ).

stackPanel expanding?

I have a normal stackpanel like http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwStackLayoutPanel
but no i dont want, that my other widget collapse when i expand an other one.
like in smartgwt :
http://www.smartclient.com/smartgwt/showcase/#layout_sections_expand_collapse
Unfortunately there is no easy solution that meets all your needs. I have recently looked into this exact same issue in depth and these are the options I came up with.
Write/Modify your own component
You can try extending StackLayoutPanel to add the functionality you require. The animate method is public in the latest version (it's not in 2.0) but you would have to add a bit of tweaking to keep track of which panels are expanded. It may be easier to simply use it as a base for a new widget. Source code here.
Pros: Can guarantee exact functionality and modify it on demand.
Cons: Requires in depth knowledge and development time.
DisclosurePanels stacked in a VerticalPanel
This is the closest GWT has to offer if you need to use standard widgets. DisclosurePanels allow you to have a header widget that, when clicked, expands or hides the content widget. With multiple stacked on top of each other you can have multiple opened at once.
Disclosure panels will not resize their content to fit a constrained space however. If they are too big for the space provided they will push further DisclosurePanels out of view. This is fine if you don't mind having to scroll to see other headers.
Pros: Uses standard GWT components and easy to implement.
Cons: Not all headers may be visible at the same time depending on the length of the content of expanded sections.
Use StackLayoutPanel
Pros: Uses standard GWT components and easy to implement. All headers visible at all times.
Cons: Only one section visible at a time.
Use a third-party component
SmartGWT springs to mind. ;)
Pros: You may be able to get the exact functionality you are after.
Cons: Have to use a third-party component that may be buggy or add other unnecessary bloat to your code.

How to globally modify/access widget in GWT?

I just started yesterday using GWT, so maybe I'm not using the proper mechanism to solve that problem. So, I will try to explain exactly what I'm trying to do (with a simple problem) and 2 solutions I came up with to address that problem.
Problem:
Remember an index that can be updated via other widgets. Let's use focus to represent it.
[button 1]
[button 2] [button A]
[button 3]
The buttons [1..3] and [A] are not in the same class and need to find the element using the id using the DOM. The reason is that those 2 views needs to be orthogonal.
We can use up/down key to move the focus from button 1 to 3.
If we are on the buttons [1..3] and press right, we go to button A.
If we are on the button A and press left, we go to button previously focused.
What we want to do is save or set the focus index when pressing right.
Solution 1: Global variables
I'm not usually fond of global variables, but in some case it's handy. By using, for instance, a dictionary (Dictionary.getDictionary) defined globally in the javascript, I could save the current index in it using the "Focus Event" in that case.
So, in the key press event, when left would be fired, I would just read the value in the dictionary.
I haven't tested yet, but I think it should work.
Solution 2: Set the value with the Element
Element element = DOM.getElementById("button id A");
element.<setFocusLeftKey>("button id [1..3]");
Here what I would like to achieve is just in the "onFocus" Event, I would simply set the value of that button.
So is it possible to cast/find the object with the Element? I think that if there is no easy way, it's probably because it's not recommended.
Is there a simpler way/other method to achieve that?
So, any thought or solutions?
Thanks in advance.
P.S. I haven't found a better title for that, so if any suggestion, just put it in the comments and I'll update it.
Using ID is definitely not the suggested way to do this in GWT. You say you need this mechanism to keep your views orthogonal to one another. This is noble, but in GWT you would achieve by using another resource (an EventBus, implemented in SimpleEventBus) that hides the different components from one another. In fact, I would argue that looking up the element by ID strongly couples the two views and is smelly.
Armed your EventBus you simply create and fire custom events that let the views (or, better, their presenters) communcate with one another. For example here you could have: NavigateRightFromButtonsEvent and NavigagteLeftFromButtonA event.
However, depending on the size of your app (or as a first experiment) you could decide to couple your two views. In this case simply pass the view for the button list into the one for button A and vice-versa. This is not really worse than relying on a global ID.
No matter which mechanism you choose (event bus or wiring the views together), you should now have access directly to the instance of the widget you want to highlight. To focus, just call setFocus(true) on it.

Overlay multiple JSliders in Swing

Is it possible to overlay multiple JSliders so I can see the "thumbs" on both (I've tried disabling the painting of the track and setting opacity to false but one still hides the other)? Basically I'd like to create a component that allows the user to define a range (and I didn't really want to write a custom one since it has most of the attributes of a slider). If there is another way I could do that with a slider, that would work too.
thanks,
Jeff
Ah, I found it (i must not have been seraching on the right terms). Swing labs as a JXMultiThumbSlider that I think will do the trick.
http://swinglabs.org/hudson/job/SwingX%20Weekly%20Build/javadoc/org/jdesktop/swingx/JXMultiThumbSlider.html
I recently had the same problem, I wanted a slider with two thumbs. I didn't get into it too much, and what I ended up doing to get the range is simply putting two sliders and in the "onSliderChange" event listener prevented one beeing smaller than the other and the other bigger than the one. I don't beleive Swing has a two-thumb-Slider, although it might be a cool new feature to add, so I think this is your best bet.
JIDE has a RangeSlider with 2 thumbs (and a nice extra one on top to move both thumbs at once (e.g. drag the range around) in their open source common layer: http://www.jidesoft.com/products/oss.htm

Categories

Resources