001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: import thinwire.util.ImageInfo;
031:
032: /**
033: * A component that displays an image. Only PNG, JPEG or GIF are supported.
034: * <p>
035: * The format for the image name can be one of the following:
036: * <ol>
037: * <li>A file that is pathed relative to the context.</li>
038: * <li>A file that is fully pathed.</li>
039: * <li>A file that is loaded as a class resource. Syntax:
040: * class:///[fully-qualified-classname]/[folder-under-class-pacakge]/[image-name]
041: * example: class:///thinwire.ui.layout.SplitLayout/resources/Image.png</li>
042: * </ol>
043: * <p>
044: * <b>Example:</b> <br>
045: * <img src="doc-files/Image-1.png"> <br>
046: *
047: * <pre>
048: * Dialog dlg = new Dialog("Image Test");
049: * dlg.setBounds(25, 25, 300, 140);
050: *
051: * for (int i = 0; i < 10; i++) {
052: * Image img = new Image("resources/ngLF/star.png");
053: * img.setBounds(25 + (i * 21), 25, 20, 20);
054: * dlg.getChildren().add(img);
055: * }
056: * for (int i = 0; i < 10; i++) {
057: * Image img = new Image("resources/ngLF/bolt.png");
058: * img.setBounds(25 + (i * 21), 46, 20, 20);
059: * dlg.getChildren().add(img);
060: * }
061: * Button btn = new Button("Ok", "resources/ngLF/ok.png");
062: * btn.setBounds(110, 70, 80, 30);
063: * dlg.getChildren().add(btn);
064: * dlg.setVisible(true);
065: * </pre>
066: *
067: * </p>
068: * <p>
069: * <b>Keyboard Navigation:</b><br>
070: * <table border="1">
071: * <tr>
072: * <td>KEY</td>
073: * <td>RESPONSE</td>
074: * <td>NOTE</td>
075: * </tr>
076: * </table>
077: * </p>
078: *
079: * @author Joshua J. Gertzen
080: */
081: public class Image extends AbstractComponent implements ImageComponent {
082: private ImageInfo imageInfo = new ImageInfo(null);
083:
084: /**
085: * Constructs a new Image with no image fileName.
086: */
087: public Image() {
088: this (null);
089: }
090:
091: /**
092: * Constructs a new Image with the specified fileName as its image.
093: * @param fileName a file name that specifies an image to display.
094: */
095: public Image(String fileName) {
096: if (fileName != null) {
097: setImage(fileName);
098: if (imageInfo.getWidth() >= 0 && imageInfo.getHeight() >= 0)
099: setSize(imageInfo.getWidth(), imageInfo.getHeight());
100: }
101:
102: setFocusCapable(false);
103: }
104:
105: public String getImage() {
106: return imageInfo.getName();
107: }
108:
109: public void setImage(String image) {
110: String oldImage = this .imageInfo.getName();
111: imageInfo = new ImageInfo(image);
112: firePropertyChange(this , PROPERTY_IMAGE, oldImage,
113: this .imageInfo.getName());
114: }
115:
116: public ImageInfo getImageInfo() {
117: return imageInfo;
118: }
119: }
|