Skip to main content
added 131 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings

That's called a doubly linked list.

Now, the app requirements include transferring focus between Rows on arrow key events. For example, if I press Up, the row that is above the focused one should gain focus instead.

That's called traversing a doubly linked list.

But how should a "composite" Row process its focus gain? It could theoretically memoize its last focused nested row, then focus it. However, a "composite" row may have never been in focus in the first place, so it doesn't appear to be the right approach.

The doubly linked list doesn't care. You can compose and structure your rows any fancy way you like. The doubly linked list just needs references to them in the order you want them traversed. This way up always goes to one place and down always goes to one place. Do it that way and it's stateless. No need to remember where the user left off last time they were here.

Image of rows linked to their neighbors in a flat structure

Each actual row (not composite) has an up and a down link to another row. You're free to keep them in the composite structure if you have some need for it. But for input focus it just seems to be getting in the way. If you don't need it for this don't use it for this. A flat structure works fine here. One of the cool things about references is they let you keep the same objects in different collections. So doing both is no biggy.

Done this way, the hard part is just building it. If you're lazy, like me, you'll teach the composite to add its children to the linked list during construction, so you don't have to.

By the way, I'm used to using tab and shift tab rather than up and down.

I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings

That's called a doubly linked list.

Now, the app requirements include transferring focus between Rows on arrow key events. For example, if I press Up, the row that is above the focused one should gain focus instead.

That's called traversing a doubly linked list.

But how should a "composite" Row process its focus gain? It could theoretically memoize its last focused nested row, then focus it. However, a "composite" row may have never been in focus in the first place, so it doesn't appear to be the right approach.

The doubly linked list doesn't care. You can compose and structure your rows any fancy way you like. The doubly linked list just needs references to them in the order you want them traversed. This way up always goes to one place and down always goes to one place. Do it that way and it's stateless. No need to remember where the user left off last time they were here.

Image of rows linked to their neighbors in a flat structure

Each actual row (not composite) has an up and a down link to another row. You're free to keep them in the composite structure if you have some need for it. But for input focus it just seems to be getting in the way. If you don't need it for this don't use it for this. A flat structure works fine here.

Done this way, the hard part is just building it. If you're lazy, like me, you'll teach the composite to add its children to the linked list during construction, so you don't have to.

By the way, I'm used to using tab and shift tab rather than up and down.

I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings

That's called a doubly linked list.

Now, the app requirements include transferring focus between Rows on arrow key events. For example, if I press Up, the row that is above the focused one should gain focus instead.

That's called traversing a doubly linked list.

But how should a "composite" Row process its focus gain? It could theoretically memoize its last focused nested row, then focus it. However, a "composite" row may have never been in focus in the first place, so it doesn't appear to be the right approach.

The doubly linked list doesn't care. You can compose and structure your rows any fancy way you like. The doubly linked list just needs references to them in the order you want them traversed. This way up always goes to one place and down always goes to one place. Do it that way and it's stateless. No need to remember where the user left off last time they were here.

Image of rows linked to their neighbors in a flat structure

Each actual row (not composite) has an up and a down link to another row. You're free to keep them in the composite structure if you have some need for it. But for input focus it just seems to be getting in the way. If you don't need it for this don't use it for this. A flat structure works fine here. One of the cool things about references is they let you keep the same objects in different collections. So doing both is no biggy.

Done this way, the hard part is just building it. If you're lazy, like me, you'll teach the composite to add its children to the linked list during construction, so you don't have to.

By the way, I'm used to using tab and shift tab rather than up and down.

added 5 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings

That's called a doubly linked list.

Now, the app requirements include transferring focus between Rows on arrow key events. For example, if I press Up, the row that is above the focused one should gain focus instead.

That's called traversing a doubly linked list.

But how should a "composite" Row process its focus gain? It could theoretically memoize its last focused nested row, then focus it. However, a "composite" row may have never been in focus in the first place, so it doesn't appear to be the right approach.

The doubly linked list doesn't care. You can compose and structure your rows any fancy way you like. The doubly linked list just needs references to them in the order you want them traversed. This way up always goes to one place and down always goes to one place. Do it that way and it's stateless. No need to remember where the user left off last time they were here.

Image of rows linked to their neighbors in a flat structure

Each actual row (not composite) has an up and a down link to another row. You're free to keep them in the composite structure if you have some need for it. But for input focus it just seems to be getting in the way. If you don't need it for this don't use it for this. A flat structure works fine here.

Done this way, the hard part is just building it. If you're lazy, like me, you'll teach the composite to add its children to the linked list during construction, so you don't have to.

By the way, I'm used to using tab and shift tab rather than up and down.

I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings

That's called a doubly linked list.

Now, the app requirements include transferring focus between Rows on arrow key events. For example, if I press Up, the row that is above the focused one should gain focus instead.

That's called traversing a doubly linked list.

But how should a "composite" Row process its focus gain? It could theoretically memoize its last focused nested row, then focus it. However, a "composite" row may have never been in focus in the first place, so it doesn't appear to be the right approach.

The doubly linked list doesn't care. You can compose and structure your rows any fancy way you like. The doubly linked list just needs references to them in the order you want them traversed. This way up always goes to one place and down always goes to one place. Do it that way and it's stateless. No need to remember where the user left off last time they were here.

Image of rows linked to their neighbors in a flat structure

Each actual row (not composite) has an up and a down link to another row. You're free keep them in the composite structure if you have some need for it. But for input focus it just seems to be getting in the way. If you don't need it for this don't use it for this. A flat structure works fine here.

Done this way, the hard part is just building it. If you're lazy, like me, you'll teach the composite to add its children to the linked list during construction, so you don't have to.

By the way, I'm used to using tab and shift tab rather than up and down.

I have a stack of custom Row widgets. Each of them is a label with some editComponent (often a JTextComponent). Rows are aware of their previous and next siblings

That's called a doubly linked list.

Now, the app requirements include transferring focus between Rows on arrow key events. For example, if I press Up, the row that is above the focused one should gain focus instead.

That's called traversing a doubly linked list.

But how should a "composite" Row process its focus gain? It could theoretically memoize its last focused nested row, then focus it. However, a "composite" row may have never been in focus in the first place, so it doesn't appear to be the right approach.

The doubly linked list doesn't care. You can compose and structure your rows any fancy way you like. The doubly linked list just needs references to them in the order you want them traversed. This way up always goes to one place and down always goes to one place. Do it that way and it's stateless. No need to remember where the user left off last time they were here.

Image of rows linked to their neighbors in a flat structure

Each actual row (not composite) has an up and a down link to another row. You're free to keep them in the composite structure if you have some need for it. But for input focus it just seems to be getting in the way. If you don't need it for this don't use it for this. A flat structure works fine here.

Done this way, the hard part is just building it. If you're lazy, like me, you'll teach the composite to add its children to the linked list during construction, so you don't have to.

By the way, I'm used to using tab and shift tab rather than up and down.

[Edit removed during grace period]
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
added 3 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369
Loading