Saturday, December 6, 2014

Question about design strategy for UIs


OK this question is not Swing specific, but since I'm using Swing I figured people might have some insight into good design practices.


I have written a CAD system in Swing/Java. This involves placing, moving, deleting and connecting blocks.


I generally process MousePressed and MouseMoved events. I also have several different states that the UI can be in.


For example, if I left-click in the middle of a block, I switch to "BLOCKMOVE" mode and then I'm moving it around until I left-click again to drop it. If I right-clicked while in BLOCKMOVE mode then I'd cancel the operation.


The logic I'm writing to handle all this is starting to look ridiculous and I'm curious if there's a standard strategy for designing these types of UIs.


As I said before, I track MousePressed events.

When this happens, I want to know:

1) Which mouse button was it? (L or R)

2) What mode am I in? (DRAGMODE or GROUPDRAGMODE or GROUPSELECTMODE or CONNECT or NONE)

3) Did I hit a block? or did I hit a pin? or did I hit nothing? (3 choices)


As you can see, for each question, I have to ask the subsequent questions for each possible answer to the first question, and so forth.


Mouse Button = 2 choices

What Mode = 5 choices

What did I hit? = 3 choices


So for this simplified system, there are already 30 possible code paths (probably reduced because some combinations are not used). And the number of possibilities doesn't depend on which order I ask the questions in.


I could see putting all this into a table, which certainly helps with the design and understanding, but I'm unaware of any code structures that would allow me to leverage that to any extent.


Is there a "recommended" way to handle this?


Thanks,


DL



No comments:

Post a Comment