KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > command > CreateImageCommand


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.command;
29
30 import java.awt.image.BufferedImage JavaDoc;
31 import java.io.FileInputStream JavaDoc;
32 import java.io.FileNotFoundException JavaDoc;
33 import java.io.IOException JavaDoc;
34
35 import org.nightlabs.editor2d.EditorPlugin;
36 import org.nightlabs.editor2d.ImageDrawComponent;
37 import com.sun.image.codec.jpeg.ImageFormatException;
38 import com.sun.image.codec.jpeg.JPEGCodec;
39
40 public class CreateImageCommand
41 extends CreateDrawComponentCommand
42 {
43
44   public CreateImageCommand()
45   {
46     super();
47     setLabel(EditorPlugin.getResourceString("command.create.image"));
48   }
49   
50   public ImageDrawComponent getImageDrawComponent()
51   {
52     return (ImageDrawComponent) getChild();
53   }
54   
55   protected BufferedImage JavaDoc image;
56   
57   protected String JavaDoc fileName;
58   public void setFileName(String JavaDoc fileName) {
59     this.fileName = fileName;
60   }
61   
62   protected String JavaDoc simpleFileName;
63   public void setSimpleFileName(String JavaDoc simpleFileName) {
64     this.simpleFileName = simpleFileName;
65   }
66   
67   public void execute()
68   {
69     super.execute();
70     try {
71       image = JPEGCodec.createJPEGDecoder(new FileInputStream JavaDoc(fileName)).decodeAsBufferedImage();
72       getImageDrawComponent().setImage(image);
73       getImageDrawComponent().setName(simpleFileName);
74     } catch (ImageFormatException e) {
75         throw new RuntimeException JavaDoc(e);
76     } catch (FileNotFoundException JavaDoc e) {
77         throw new RuntimeException JavaDoc(e);
78     } catch (IOException JavaDoc e) {
79         throw new RuntimeException JavaDoc(e);
80     }
81   }
82   
83   public void redo()
84   {
85     super.redo();
86   }
87   
88   public void undo()
89   {
90     super.undo();
91   }
92   
93   
94 }
95
Popular Tags