208 int getItemCount() {
209 return items.size();
210 }
211
212 String getItem(int index) {
213 return items.get(index);
214 }
215
216 /**********************************************************************/
217 /* GUI-related methods */
218 /**********************************************************************/
219
220 void setFocusedIndex(int index) {
221 focusedIndex = index;
222 }
223
224 private boolean isFocusedIndex(int index) {
225 return index == focusedIndex;
226 }
227
228 void setFont(Font newFont) {
229 if (newFont != font) {
230 font = newFont;
231 fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
232 // Also cache stuff like fontHeight?
233 }
234 }
235
236 /*
237 * Returns width of the text of the longest item
238 */
239 int getMaxItemWidth() {
240 int m = 0;
241 int end = getItemCount();
242 for(int i = 0 ; i < end ; i++) {
243 int l = fm.stringWidth(getItem(i));
244 m = Math.max(m, l);
245 }
246 return m;
247 }
|
208 int getItemCount() {
209 return items.size();
210 }
211
212 String getItem(int index) {
213 return items.get(index);
214 }
215
216 /**********************************************************************/
217 /* GUI-related methods */
218 /**********************************************************************/
219
220 void setFocusedIndex(int index) {
221 focusedIndex = index;
222 }
223
224 private boolean isFocusedIndex(int index) {
225 return index == focusedIndex;
226 }
227
228 @SuppressWarnings("deprecation")
229 void setFont(Font newFont) {
230 if (newFont != font) {
231 font = newFont;
232 fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
233 // Also cache stuff like fontHeight?
234 }
235 }
236
237 /*
238 * Returns width of the text of the longest item
239 */
240 int getMaxItemWidth() {
241 int m = 0;
242 int end = getItemCount();
243 for(int i = 0 ; i < end ; i++) {
244 int l = fm.stringWidth(getItem(i));
245 m = Math.max(m, l);
246 }
247 return m;
248 }
|