KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > apps > rasterizer > DestinationType


1 /*
2
3    Copyright 2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.apps.rasterizer;
19
20 import org.apache.batik.transcoder.Transcoder;
21 import org.apache.batik.transcoder.image.JPEGTranscoder;
22 import org.apache.batik.transcoder.image.PNGTranscoder;
23 import org.apache.batik.transcoder.image.TIFFTranscoder;
24
25 /**
26  * Describes the type of destination for an <tt>SVGConverter</tt>
27  * operation.
28  *
29  * @author Henri Ruini
30  * @author <a HREF="mailto:vhardy@apache.org">Vincent Hardy</a>
31  * @version $Id: DestinationType.java,v 1.6 2005/03/27 08:58:29 cam Exp $
32  */

33 public final class DestinationType {
34     public static final String JavaDoc PNG_STR = "image/png";
35     public static final String JavaDoc JPEG_STR = "image/jpeg";
36     public static final String JavaDoc TIFF_STR = "image/tiff";
37     public static final String JavaDoc PDF_STR = "application/pdf";
38
39     public static final int PNG_CODE = 0;
40     public static final int JPEG_CODE = 1;
41     public static final int TIFF_CODE = 2;
42     public static final int PDF_CODE = 3;
43         
44     public static final String JavaDoc PNG_EXTENSION = ".png";
45     public static final String JavaDoc JPEG_EXTENSION = ".jpg";
46     public static final String JavaDoc TIFF_EXTENSION = ".tif";
47     public static final String JavaDoc PDF_EXTENSION = ".pdf";
48
49     public static final DestinationType PNG
50         = new DestinationType(PNG_STR, PNG_CODE, PNG_EXTENSION);
51     public static final DestinationType JPEG
52         = new DestinationType(JPEG_STR, JPEG_CODE, JPEG_EXTENSION);
53     public static final DestinationType TIFF
54         = new DestinationType(TIFF_STR, TIFF_CODE, TIFF_EXTENSION);
55     public static final DestinationType PDF
56         = new DestinationType(PDF_STR, PDF_CODE, PDF_EXTENSION);
57
58     private String JavaDoc type;
59     private int code;
60     private String JavaDoc extension;
61
62     private DestinationType(String JavaDoc type, int code, String JavaDoc extension){
63         this.type = type;
64         this.code = code;
65         this.extension = extension;
66     }
67     
68     public String JavaDoc getExtension(){
69         return extension;
70     }
71
72     public String JavaDoc toString(){
73         return type;
74     }
75
76     public int toInt(){
77         return code;
78     }
79
80     /**
81      * Returns a transcoder object of the result image type.
82      *
83      * @return Transcoder object or <tt>null</tt> if there isn't a proper transcoder.
84      */

85     protected Transcoder getTranscoder(){
86         switch(code) {
87             case PNG_CODE:
88                 return new PNGTranscoder();
89             case JPEG_CODE:
90                 return new JPEGTranscoder();
91             case TIFF_CODE:
92                 return new TIFFTranscoder();
93             case PDF_CODE:
94                 try {
95                     Class JavaDoc pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder");
96                     return (Transcoder)pdfClass.newInstance();
97                 } catch(Exception JavaDoc e) {
98                     return null;
99                 }
100             default:
101                 return null;
102         }
103
104     }
105
106     /**
107      * Defines valid image types.
108      *
109      * @return Array of valid values as strings.
110      */

111     public DestinationType[] getValues() {
112         return new DestinationType[]{PNG, JPEG, TIFF, PDF};
113     }
114
115     public Object JavaDoc readResolve(){
116         switch(code){
117         case PNG_CODE:
118             return PNG;
119         case JPEG_CODE:
120             return JPEG;
121         case TIFF_CODE:
122             return TIFF;
123         case PDF_CODE:
124             return PDF;
125         default:
126             throw new Error JavaDoc();
127         }
128     }
129 }
130
Popular Tags