1 /*
2 *
3 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
333 update();
334 }
335
336 public int getSize() {
337 return prefix.size() * suffix.size();
338 }
339
340 public Object getElementAt(int index) {
341 if(permuter == null) {
342 update();
343 }
344 // morph the index to another int -- this has the benefit of
345 // causing the list to look random.
346 int j = permuter.map(index);
347 int ps = prefix.size();
348 int ss = suffix.size();
349 return (String) prefix.elementAt(j%ps) + (String) suffix.elementAt((j/ps)%ss);
350 }
351 }
352
353 ImageIcon images[] = new ImageIcon[7];
354 void loadImages() {
355 images[0] = createImageIcon("list/red.gif", getString("ListDemo.red"));
356 images[1] = createImageIcon("list/blue.gif", getString("ListDemo.blue"));
357 images[2] = createImageIcon("list/yellow.gif", getString("ListDemo.yellow"));
358 images[3] = createImageIcon("list/green.gif", getString("ListDemo.green"));
359 images[4] = createImageIcon("list/gray.gif", getString("ListDemo.gray"));
360 images[5] = createImageIcon("list/cyan.gif", getString("ListDemo.cyan"));
361 images[6] = createImageIcon("list/magenta.gif", getString("ListDemo.magenta"));
362 }
363
364 class CompanyLogoListCellRenderer extends DefaultListCellRenderer {
365 public Component getListCellRendererComponent(
366 JList list,
367 Object value,
368 int index,
369 boolean isSelected,
370 boolean cellHasFocus)
371 {
372 Component retValue = super.getListCellRendererComponent(
373 list, value, index, isSelected, cellHasFocus
|
1 /*
2 *
3 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Oracle nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
333 update();
334 }
335
336 public int getSize() {
337 return prefix.size() * suffix.size();
338 }
339
340 public Object getElementAt(int index) {
341 if(permuter == null) {
342 update();
343 }
344 // morph the index to another int -- this has the benefit of
345 // causing the list to look random.
346 int j = permuter.map(index);
347 int ps = prefix.size();
348 int ss = suffix.size();
349 return (String) prefix.elementAt(j%ps) + (String) suffix.elementAt((j/ps)%ss);
350 }
351 }
352
353 ImageIcon[] images = new ImageIcon[7];
354 void loadImages() {
355 images[0] = createImageIcon("list/red.gif", getString("ListDemo.red"));
356 images[1] = createImageIcon("list/blue.gif", getString("ListDemo.blue"));
357 images[2] = createImageIcon("list/yellow.gif", getString("ListDemo.yellow"));
358 images[3] = createImageIcon("list/green.gif", getString("ListDemo.green"));
359 images[4] = createImageIcon("list/gray.gif", getString("ListDemo.gray"));
360 images[5] = createImageIcon("list/cyan.gif", getString("ListDemo.cyan"));
361 images[6] = createImageIcon("list/magenta.gif", getString("ListDemo.magenta"));
362 }
363
364 class CompanyLogoListCellRenderer extends DefaultListCellRenderer {
365 public Component getListCellRendererComponent(
366 JList list,
367 Object value,
368 int index,
369 boolean isSelected,
370 boolean cellHasFocus)
371 {
372 Component retValue = super.getListCellRendererComponent(
373 list, value, index, isSelected, cellHasFocus
|