Source code: com/paradoxpoint/libitina/monument/TransformableImageItem.java
1 /*
2 * Libitina - Funeral Monument Image Compositor
3 * Copyright (C) 2003,2004 Luke Imhoff
4 *
5 * Contact Info:
6 * luke@paradoxpoint.com
7 * Luke Imhoff
8 * 2514 Pied Piper Lane
9 * Wausau, WI 54403
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 *
25 * ImageItem.java
26 *
27 * Created on March 30, 2003, 9:35 PM
28 */
29
30 /**
31 *
32 * @author Luke Imhoff
33 */
34
35 package com.paradoxpoint.libitina.monument;
36
37 import java.awt.Point;
38
39 import javax.swing.*;
40
41 /** <CODE>Item</CODE> capable of storing information for an image including size, position and
42 * rotation. (<B>NOTE:</B> this is a property archive class and methods do not
43 * affect the visual images that the items represent in anyway.)
44 */
45 public class TransformableImageItem extends ImageItem implements Transformable {
46
47 /** Holds value of property x. */
48 private int x;
49
50 /** Holds value of property y. */
51 private int y;
52
53 /** Holds value of property width. */
54 private int width;
55
56 /** Holds value of property height. */
57 private int height;
58
59 /** Holds value of property rotation. */
60 private double rotation;
61
62 /** Dimensions of image before sizing */
63 int sourceWidth;
64 int sourceHeight;
65
66 private boolean mirrored;
67
68 /** Creates a new instance of ImageItem
69 * @param name name of item
70 * @param src source of image
71 */
72 public TransformableImageItem(String name, java.net.URL src) {
73 super(name,src);
74 sizeToImage();
75 }
76
77 public TransformableImageItem(String name, java.net.URL src, int preferredPosition) {
78 super(name, src, preferredPosition);
79 sizeToImage();
80 }
81
82 private void sizeToImage() {
83 ImageIcon ico = new ImageIcon(getSource());
84 setWidth(ico.getIconWidth());
85 setHeight(ico.getIconHeight());
86 }
87
88 /** Getter for property x.
89 * @return Value of property x.
90 *
91 */
92 public int getX() {
93 return this.x;
94 }
95
96 /** Setter for property x.
97 * @param x New value of property x.
98 *
99 */
100 public void setX(int x) {
101 int oldX = this.x;
102 this.x = x;
103 firePropertyChange("x", oldX, x);
104 }
105
106 /** Getter for property y.
107 * @return Value of property y.
108 *
109 */
110 public int getY() {
111 return this.y;
112 }
113
114 /** Setter for property y.
115 * @param y New value of property y.
116 *
117 */
118 public void setY(int y) {
119 int oldY = this.y;
120 this.y = y;
121 firePropertyChange("y", oldY, y);
122 }
123
124 /** Getter for property width.
125 * @return Value of property width.
126 *
127 */
128 public int getWidth() {
129 return this.width;
130 }
131
132 /** Setter for property width.
133 * @param width New value of property width.
134 *
135 */
136 public void setWidth(int width) {
137 int oldWidth = this.width;
138 this.width = width;
139 firePropertyChange("width", oldWidth, width);
140 }
141
142 /** Getter for property height.
143 * @return Value of property height.
144 *
145 */
146 public int getHeight() {
147 return this.height;
148 }
149
150 /** Setter for property height.
151 * @param height New value of property height.
152 *
153 */
154 public void setHeight(int height) {
155 int oldHeight = this.height;
156 this.height = height;
157 firePropertyChange("height", oldHeight, height);
158 }
159
160 /** Getter for property rotation.
161 * @return Value of property rotation.
162 *
163 */
164 public double getRotation() {
165 return this.rotation;
166 }
167
168 /** Setter for property rotation.
169 * @param rotation New value of property rotation.
170 *
171 */
172 public void setRotation(double rotation) {
173 double oldRotation = this.rotation;
174 this.rotation = rotation%360;
175 firePropertyChange("rotation", new Double(oldRotation), new Double(rotation));
176 }
177
178 public boolean isMirrored() {
179 return mirrored;
180 }
181
182 public void setMirrored(boolean b) {
183 boolean oldMirrored = this.mirrored;
184 this.mirrored = b;
185 firePropertyChange("mirrored", oldMirrored, mirrored);
186 }
187
188 }