117
118 /**
119 * <p>Convenience method to inform if the given index is currently focused
120 * in this SelectionModel. Is functionally equivalent to calling
121 * <pre><code>getFocusedIndex() == index</code></pre>.
122 *
123 * @param index The index to check as to whether it is currently focused
124 * or not.
125 * @return True if the given index is focused, false otherwise.
126 */
127 public boolean isFocused(int index) {
128 if (index < 0 || index >= getItemCount()) return false;
129
130 return getFocusedIndex() == index;
131 }
132
133 /**
134 * Causes the item at the given index to receive the focus. This does not
135 * cause the current selection to change. Updates the focusedItem and
136 * focusedIndex properties such that <code>focusedIndex = -1</code> unless
137 * <code>0 <= index < model size</code>.
138 *
139 * @param index The index of the item to get focus.
140 */
141 public void focus(int index) {
142 if (index < 0 || index >= getItemCount()) {
143 setFocusedIndex(-1);
144 } else {
145 int oldFocusIndex = getFocusedIndex();
146 setFocusedIndex(index);
147
148 if (oldFocusIndex == index) {
149 // manually update the focus item to ensure consistency
150 setFocusedItem(getModelItem(index));
151 }
152 }
153 }
154
155 /**
156 * Attempts to give focus to the row previous to the currently focused row.
157 * If the current focus owner is the first row, or is -1 (representing that
|
117
118 /**
119 * <p>Convenience method to inform if the given index is currently focused
120 * in this SelectionModel. Is functionally equivalent to calling
121 * <pre><code>getFocusedIndex() == index</code></pre>.
122 *
123 * @param index The index to check as to whether it is currently focused
124 * or not.
125 * @return True if the given index is focused, false otherwise.
126 */
127 public boolean isFocused(int index) {
128 if (index < 0 || index >= getItemCount()) return false;
129
130 return getFocusedIndex() == index;
131 }
132
133 /**
134 * Causes the item at the given index to receive the focus. This does not
135 * cause the current selection to change. Updates the focusedItem and
136 * focusedIndex properties such that <code>focusedIndex = -1</code> unless
137 * <code>0 <= index < model size</code>.
138 *
139 * @param index The index of the item to get focus.
140 */
141 public void focus(int index) {
142 if (index < 0 || index >= getItemCount()) {
143 setFocusedIndex(-1);
144 } else {
145 int oldFocusIndex = getFocusedIndex();
146 setFocusedIndex(index);
147
148 if (oldFocusIndex == index) {
149 // manually update the focus item to ensure consistency
150 setFocusedItem(getModelItem(index));
151 }
152 }
153 }
154
155 /**
156 * Attempts to give focus to the row previous to the currently focused row.
157 * If the current focus owner is the first row, or is -1 (representing that
|