AcopIcon is a displayer which can show imageable value. In general, this displayer can receive long values or double values which are then converted into predefined images, which are visible to the user.
For proper display, user has to load ValueIconPairs which describe each of the values that the displayer can be updated with. AcopIcon can only show readable values.
The following lines show an example how to use the features of the AcopIcon.
For features shared with other ACOP Beans see this page.
The icons used to render the values received can be set as
ValueIconPair[] valueIconPairs = new ValueIconPair[] { new ValueIconPair(0L, IconHelper.createIcon("icons/navigation/ArrowLeftLeft16.gif")), new ValueIconPair(1L, IconHelper.createIcon("icons/navigation/ArrowLeft16.gif")), new ValueIconPair(2L, IconHelper.createIcon("icons/navigation/ArrowRight16.gif")), new ValueIconPair(3L, IconHelper.createIcon("icons/navigation/ArrowRightRight16.gif")) }; icon.setIcons(valueIconPairs);
Value icon pairs can be added also later or in the runtime
icon.addIcon(new ValueIconPair(4L, IconHelper.createIcon("icons/navigation/Plus16.gif")));
When using the IconHelper to generate icons there are several ways how to create an icon. The above code, where string parameters are supplied will search for the given path in the classpath of the project and create an icon if the path exists. If we want to use a local image file for the icon, we can generate the File pointing to that location and pass it to the IconHelper
File file = new File("C:/foo.png"); ValueIconPair pair = new ValueIconPair(5L, file); icon.addIcon(pair);
We want to be notified when value is out of bounds. In Icon displayer this means that a displayer will be updated with a value, which doesn't have any icon assigned to (the ValueIconPair for that value was never added). Therefore, we set a default icon to the IconDisplayer, which will be shown in these cases:
icon.setDefaultIcon(IconHelper.createIcon("icons/media/Stop16.gif"));
All icons are not the same size as the component is, which can result in only a part of the icon being visible in the displayer, or only a part of the displayer is filled with icon. We can force the displayer to scale all icons to fit its size:
icon.setScaleIcons(true);
The icons will now be the size of the displayer but they might look strange because the displayer does not have the aspect ration of the icon. Therefore, we will set the displayer to preserve the aspect ratio of icons:
icon.setKeepRatio(true);
Other properties of the icon can also simply be adjusted by calling the appropriate setter methods. These properties include background/foreground color, title etc.:
icon.setBackground(Color.RED); icon.setForeground(Color.GREEN);
See the complete source code used in this examples.