1 27 28 package org.nightlabs.editor2d.command; 29 30 import java.awt.image.BufferedImage ; 31 import java.io.FileInputStream ; 32 import java.io.FileNotFoundException ; 33 import java.io.IOException ; 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 image; 56 57 protected String fileName; 58 public void setFileName(String fileName) { 59 this.fileName = fileName; 60 } 61 62 protected String simpleFileName; 63 public void setSimpleFileName(String simpleFileName) { 64 this.simpleFileName = simpleFileName; 65 } 66 67 public void execute() 68 { 69 super.execute(); 70 try { 71 image = JPEGCodec.createJPEGDecoder(new FileInputStream (fileName)).decodeAsBufferedImage(); 72 getImageDrawComponent().setImage(image); 73 getImageDrawComponent().setName(simpleFileName); 74 } catch (ImageFormatException e) { 75 throw new RuntimeException (e); 76 } catch (FileNotFoundException e) { 77 throw new RuntimeException (e); 78 } catch (IOException e) { 79 throw new RuntimeException (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 |