KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > image > ImageDataLoader


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.image;
21
22 import javax.imageio.ImageIO JavaDoc;
23 import org.openide.filesystems.FileObject;
24 import org.openide.loaders.DataObjectExistsException;
25 import org.openide.loaders.ExtensionList;
26 import org.openide.loaders.MultiDataObject;
27 import org.openide.loaders.UniFileLoader;
28 import org.openide.util.NbBundle;
29
30 /**
31  * Data loader which recognizes image files.
32  * @author Petr Hamernik, Jaroslav Tulach
33  * @author Marian Petras
34  */

35 public class ImageDataLoader extends UniFileLoader {
36
37     /** Generated serial version UID. */
38     static final long serialVersionUID =-8188309025795898449L;
39     
40     /** MIME-type of BMP files */
41     private static final String JavaDoc BMP_MIME_TYPE = "image/bmp"; //NOI18N
42
/** is BMP format support status known? */
43     private static boolean bmpSupportStatusKnown = false;
44     
45     /** Creates new image loader. */
46     public ImageDataLoader() {
47         // Set the representation class.
48
super("org.netbeans.modules.image.ImageDataObject"); // NOI18N
49

50         ExtensionList ext = new ExtensionList();
51         ext.addMimeType("image/gif"); //NOI18N
52
ext.addMimeType("image/jpeg"); //NOI18N
53
ext.addMimeType("image/png"); //NOI18N
54
setExtensions(ext);
55     }
56     
57     protected FileObject findPrimaryFile(FileObject fo){
58         FileObject primFile = super.findPrimaryFile(fo);
59         
60         if ((primFile == null)
61                 && !bmpSupportStatusKnown
62                 && !fo.isFolder()
63                 && fo.getMIMEType().equals(BMP_MIME_TYPE)) {
64             try {
65                 if (ImageIO.getImageReadersByMIMEType(BMP_MIME_TYPE).hasNext()){
66                     getExtensions().addMimeType(BMP_MIME_TYPE);
67                     primFile = fo;
68                 }
69             } finally {
70                 bmpSupportStatusKnown = true;
71             }
72         }
73         
74         return primFile;
75     }
76     
77     /** Gets default display name. Overrides superclass method. */
78     protected String JavaDoc defaultDisplayName() {
79         return NbBundle.getBundle(ImageDataLoader.class).getString("PROP_ImageLoader_Name");
80     }
81     
82     /**
83      * This methods uses the layer action context so it returns
84      * a non-<code>null</code> value.
85      *
86      * @return name of the context on layer files to read/write actions to
87      */

88     protected String JavaDoc actionsContext () {
89         return "Loaders/image/png-gif-jpeg-bmp/Actions/"; //NOI18N
90
}
91     
92     /** Create the image data object.
93      * @param primaryFile the primary file (e.g. <code>*.gif</code>)
94      * @return the data object for this file
95      * @exception DataObjectExistsException if the primary file already has a data object
96      * @exception java.io.IOException should not be thrown
97      */

98     protected MultiDataObject createMultiObject (FileObject primaryFile)
99     throws DataObjectExistsException, java.io.IOException JavaDoc {
100         return new ImageDataObject(primaryFile, this);
101     }
102
103 }
104
Popular Tags