01: package jimm.datavision.gui.cmd;
02:
03: import jimm.datavision.Point;
04: import jimm.datavision.field.Field;
05: import jimm.datavision.field.Rectangle;
06: import jimm.datavision.field.ImageField;
07: import jimm.datavision.ErrorHandler;
08: import jimm.datavision.gui.SectionWidget;
09: import jimm.datavision.gui.FieldWidget;
10: import jimm.datavision.gui.ImageFieldWidget;
11: import jimm.util.I18N;
12: import javax.swing.ImageIcon;
13:
14: /**
15: * Inserts a new image field.
16: *
17: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
18: */
19: public class NewImageFieldCommand extends InsertFieldCommand {
20:
21: protected String imageURL;
22:
23: public NewImageFieldCommand(SectionWidget sw, String url) {
24: super (sw, "image", new Point(0, 0));
25: imageURL = url;
26: }
27:
28: public void perform() {
29: super .perform();
30:
31: if (!((ImageField) fw.getField()).canLoad()) {
32: ErrorHandler.error(I18N.get("DesignWin.image_load_err_1")
33: + ' ' + imageURL + ' '
34: + I18N.get("DesignWin.image_load_err_2"), I18N
35: .get("DesignWin.image_load_err_title"));
36: }
37:
38: }
39:
40: protected Rectangle initialFieldBounds() {
41: ImageIcon imageIcon = ((ImageField) fw.getField())
42: .getImageIcon();
43: return new Rectangle(insertLoc.x, insertLoc.y, imageIcon
44: .getIconWidth(), imageIcon.getIconHeight());
45: }
46:
47: protected Object initialFieldValue() {
48: return imageURL;
49: }
50:
51: protected FieldWidget createFieldWidget(Field f) {
52: return new ImageFieldWidget(null, (ImageField) f);
53: }
54:
55: }
|