001: /*
002: * Copyright (C) 2007 Jared Alexander Spigner
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * jspigner@openjx.org
019: *
020: * JXImage.java
021: *
022: * Created on June 8, 2007, 10:35 PM
023: *
024: */
025:
026: package org.openjx.jx;
027:
028: import java.awt.Image;
029:
030: import javax.swing.JComponent;
031: import javax.swing.ImageIcon;
032:
033: import java.beans.PropertyChangeListener;
034: import java.beans.PropertyChangeSupport;
035:
036: /**
037: * This class represents an image component for use in OpenJX.
038: *
039: * @author Jared Spigner
040: */
041: public class JXImage extends JComponent {
042: /** This is the identifier of the class. */
043: private static final long serialVersionUID = 1998L;
044:
045: /** This is the image contained in the class. */
046: private ImageIcon image;
047:
048: /** This is used to make the class's properties available. */
049: private final PropertyChangeSupport pcs = new PropertyChangeSupport(
050: this );
051:
052: /**
053: * This the constructor for the JXTranslator class. It creates a new
054: * instance of JXImage.
055: */
056: public JXImage() {
057: }
058:
059: /**
060: * This method returns the actual image.
061: *
062: * @return the image.
063: */
064: public Image getImage() {
065: return this .image.getImage();
066: }
067:
068: /**
069: * This method returns the image icon.
070: *
071: * @return the image icon.
072: */
073: public ImageIcon getImageIcon() {
074: return this .image;
075: }
076:
077: /**
078: * This method sets the image based on a file name.
079: *
080: * @param fileName is the name of the image file.
081: */
082: public void setImage(String fileName) {
083: ImageIcon newImage = new ImageIcon(fileName);
084: ImageIcon oldImage = this .image;
085: this .image = newImage;
086: this .pcs.firePropertyChange("cdata", oldImage, newImage);
087: }
088:
089: /**
090: * This method sets the image with an image icon.
091: *
092: * @param newImage is the image icon we want to use.
093: */
094: public void setImage(ImageIcon newImage) {
095: ImageIcon oldImage = this .image;
096: this .image = newImage;
097: this .pcs.firePropertyChange("cdata", oldImage, newImage);
098: }
099:
100: /**
101: * This method is required to make this a bean.
102: *
103: * @param listener is the listener we want to add.
104: */
105: public void addPropertyChangeListener(
106: PropertyChangeListener listener) {
107: this .pcs.addPropertyChangeListener(listener);
108: }
109:
110: /**
111: * This method is required to make this a bean.
112: *
113: * @param listener is the listener we want to remove.
114: */
115: public void removePropertyChangeListener(
116: PropertyChangeListener listener) {
117: this.pcs.removePropertyChangeListener(listener);
118: }
119:
120: }
|