summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorCalixte DENIZET <calixte@contrib.scilab.org>2011-04-10 17:46:15 +0200
committerVincent COUVERT <vincent.couvert@scilab.org>2011-05-06 14:33:56 +0200
commita0b16b26e51a9be1729af83f74cb8162e115203a (patch)
tree218e5cd7f7f69068b569d7d5a4bd5a2c3239d516 /scilab/modules
parent5496e8202d59d86db0ba66e83acfa4d0c571fd32 (diff)
downloadscilab-a0b16b26e51a9be1729af83f74cb8162e115203a.zip
scilab-a0b16b26e51a9be1729af83f74cb8162e115203a.tar.gz
Bug 8595 fixed: The Options Dialogbox when exporting did not appear to front with several screen
Change-Id: I043802572dddb47bf540cb6ee1fa63f09eda6d71
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/graphic_export/src/c/xs2file.c29
-rw-r--r--scilab/modules/graphic_export/src/cpp/exportToFile.cpp10
-rw-r--r--scilab/modules/graphic_export/src/cpp/exportToFile.hxx10
-rw-r--r--scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportBitmap.java46
-rw-r--r--scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportRenderer.java408
-rw-r--r--scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/FileExporter.java39
-rw-r--r--scilab/modules/graphic_export/src/jni/FileExporter.cpp28
-rw-r--r--scilab/modules/graphic_export/src/jni/FileExporter.giws.xml2
-rw-r--r--scilab/modules/graphic_export/src/jni/FileExporter.hxx4
-rw-r--r--scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/ExportOptionWindow.java234
-rw-r--r--scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/SwingScilabExportFileChooser.java492
11 files changed, 669 insertions, 633 deletions
diff --git a/scilab/modules/graphic_export/src/c/xs2file.c b/scilab/modules/graphic_export/src/c/xs2file.c
index e317873..e38e9aa 100644
--- a/scilab/modules/graphic_export/src/c/xs2file.c
+++ b/scilab/modules/graphic_export/src/c/xs2file.c
@@ -67,7 +67,7 @@ int xs2file(char * fname, ExportFileType fileType )
67 int m1 = 0, n1 = 0, l1 = 0; 67 int m1 = 0, n1 = 0, l1 = 0;
68 int figurenum = -1; 68 int figurenum = -1;
69 sciPointObj* figurePtr = NULL; 69 sciPointObj* figurePtr = NULL;
70 int status = 0; 70 char *status = NULL;
71 71
72 /* get handle by figure number */ 72 /* get handle by figure number */
73 if(GetType(1) == sci_matrix) 73 if(GetType(1) == sci_matrix)
@@ -203,30 +203,11 @@ int xs2file(char * fname, ExportFileType fileType )
203 freeArrayOfString(fileName,m1*n1); 203 freeArrayOfString(fileName,m1*n1);
204 204
205 /* treat errors */ 205 /* treat errors */
206 switch(status) 206 if (strlen(status) != 0)
207 { 207 {
208 case EXPORT_UNKNOWN_GLEXCEPTION_ERROR : 208 Scierror(999,_("%s: %s\n"), fname, status);
209 Scierror(999,_("%s: OpenGL error during export.\n"),fname);
210 return 0;
211 case EXPORT_IOEXCEPTION_ERROR :
212 Scierror(999,_("%s: Unable to create export file, permission denied.\n"),fname);
213 return 0;
214 case EXPORT_INVALID_FILE :
215 Scierror(999,_("%s: Unable to create export file, invalid file.\n"),fname);
216 return 0;
217 case EXPORT_GL2PS_ERROR :
218 Scierror(999,_("%s: GL2PS error during export.\n"),fname);
219 return 0; 209 return 0;
220 case EXPORT_GL2PS_OVERFLOW : 210 }
221 Scierror(999,_("%s: Unable to create export file, figure is too big.\n"),fname);
222 return 0;
223 case EXPORT_GL2PS_UNINITIALIZED :
224 Scierror(999,_("%s: GL2PS error during export.\n"),fname);
225 return 0;
226 default :
227 // NO ERROR
228 break;
229 }
230 } 211 }
231 else 212 else
232 { 213 {
diff --git a/scilab/modules/graphic_export/src/cpp/exportToFile.cpp b/scilab/modules/graphic_export/src/cpp/exportToFile.cpp
index 834fd0a..7a0164d 100644
--- a/scilab/modules/graphic_export/src/cpp/exportToFile.cpp
+++ b/scilab/modules/graphic_export/src/cpp/exportToFile.cpp
@@ -24,11 +24,11 @@ extern "C"
24 24
25 25
26/*---------------------------------------------------------------------------------*/ 26/*---------------------------------------------------------------------------------*/
27int exportToFile(sciPointObj * pFigure, 27char * exportToFile(sciPointObj * pFigure,
28 const char * fileName, 28 const char * fileName,
29 ExportFileType fileType, 29 ExportFileType fileType,
30 const float jpegCompressionQuality, 30 const float jpegCompressionQuality,
31 ExportOrientation orientation) 31 ExportOrientation orientation)
32{ 32{
33 return org_scilab_modules_graphic_export::FileExporter::fileExport(getScilabJavaVM(), 33 return org_scilab_modules_graphic_export::FileExporter::fileExport(getScilabJavaVM(),
34 sciGetNum(pFigure), 34 sciGetNum(pFigure),
diff --git a/scilab/modules/graphic_export/src/cpp/exportToFile.hxx b/scilab/modules/graphic_export/src/cpp/exportToFile.hxx
index c7207fc..fc3e240 100644
--- a/scilab/modules/graphic_export/src/cpp/exportToFile.hxx
+++ b/scilab/modules/graphic_export/src/cpp/exportToFile.hxx
@@ -52,11 +52,11 @@ typedef enum
52 EXPORT_LANDSCAPE = 1 52 EXPORT_LANDSCAPE = 1
53} ExportOrientation; 53} ExportOrientation;
54 54
55int exportToFile(sciPointObj * pFigure, 55char * exportToFile(sciPointObj * pFigure,
56 const char * fileName, 56 const char * fileName,
57 ExportFileType fileType, 57 ExportFileType fileType,
58 const float jpegCompressionQuality, 58 const float jpegCompressionQuality,
59 ExportOrientation orientation); 59 ExportOrientation orientation);
60 60
61#ifdef __cplusplus 61#ifdef __cplusplus
62} 62}
diff --git a/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportBitmap.java b/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportBitmap.java
index 20aef46..89f6ae4 100644
--- a/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportBitmap.java
+++ b/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportBitmap.java
@@ -59,7 +59,7 @@ public class ExportBitmap extends ExportToFile {
59 */ 59 */
60 public ExportBitmap(String filename, int filetype, float jpegCompressionQuality) { 60 public ExportBitmap(String filename, int filetype, float jpegCompressionQuality) {
61 super(filename, filetype); 61 super(filename, filetype);
62 this.jpegCompressionQuality = jpegCompressionQuality; 62 this.jpegCompressionQuality = jpegCompressionQuality;
63 } 63 }
64 64
65 /** 65 /**
@@ -136,13 +136,13 @@ public class ExportBitmap extends ExportToFile {
136 ImageUtil.flipImageVertically(dump); 136 ImageUtil.flipImageVertically(dump);
137 } 137 }
138 try { 138 try {
139 if (jpegCompressionQuality != -1) { 139 if (jpegCompressionQuality != -1) {
140 if (!writeJPEG(dump, jpegCompressionQuality, file)) { 140 if (!writeJPEG(dump, jpegCompressionQuality, file)) {
141 return ExportRenderer.IOEXCEPTION_ERROR; 141 return ExportRenderer.IOEXCEPTION_ERROR;
142 } 142 }
143 } else { 143 } else {
144 ImageIO.write(dump, getFileExtension(), file); 144 ImageIO.write(dump, getFileExtension(), file);
145 } 145 }
146 } catch (IOException e) { 146 } catch (IOException e) {
147 return ExportRenderer.IOEXCEPTION_ERROR; 147 return ExportRenderer.IOEXCEPTION_ERROR;
148 } 148 }
@@ -165,20 +165,20 @@ public class ExportBitmap extends ExportToFile {
165 * @param file the output file 165 * @param file the output file
166 */ 166 */
167 private boolean writeJPEG(BufferedImage image, float compressionQuality, File file) throws IOException { 167 private boolean writeJPEG(BufferedImage image, float compressionQuality, File file) throws IOException {
168 Iterator iter = ImageIO.getImageWritersByFormatName("jpeg"); 168 Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
169 ImageWriter writer; 169 ImageWriter writer;
170 if (iter.hasNext()) { 170 if (iter.hasNext()) {
171 writer = (ImageWriter) iter.next(); 171 writer = (ImageWriter) iter.next();
172 } else { 172 } else {
173 return false; 173 return false;
174 } 174 }
175 ImageWriteParam param = writer.getDefaultWriteParam(); 175 ImageWriteParam param = writer.getDefaultWriteParam();
176 param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); 176 param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
177 param.setCompressionQuality(compressionQuality); 177 param.setCompressionQuality(compressionQuality);
178 FileImageOutputStream output = new FileImageOutputStream(file); 178 FileImageOutputStream output = new FileImageOutputStream(file);
179 writer.setOutput(output); 179 writer.setOutput(output);
180 writer.write(null, new IIOImage(image, null, null), param); 180 writer.write(null, new IIOImage(image, null, null), param);
181 writer.dispose(); 181 writer.dispose();
182 return true; 182 return true;
183 } 183 }
184} 184}
diff --git a/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportRenderer.java b/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportRenderer.java
index bca66fb..6bcd979 100644
--- a/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportRenderer.java
+++ b/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportRenderer.java
@@ -1,11 +1,11 @@
1/* 1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Sylvestre Koumar 3 * Copyright (C) 2009 - DIGITEO - Sylvestre Koumar
4 * 4 *
5 * This file must be used under the terms of the CeCILL. 5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which 6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms 7 * you should have received as part of this distribution. The terms
8 * are also available at 8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 * 10 *
11 */ 11 */
@@ -14,6 +14,8 @@ package org.scilab.modules.graphic_export;
14 14
15import java.util.ArrayList; 15import java.util.ArrayList;
16import java.util.Arrays; 16import java.util.Arrays;
17import java.util.HashMap;
18import java.util.Map;
17 19
18import javax.media.opengl.GLEventListener; 20import javax.media.opengl.GLEventListener;
19import com.sun.opengl.util.FileUtil; 21import com.sun.opengl.util.FileUtil;
@@ -25,193 +27,217 @@ import com.sun.opengl.util.FileUtil;
25 */ 27 */
26public abstract class ExportRenderer implements GLEventListener { 28public abstract class ExportRenderer implements GLEventListener {
27 29
28 /** Code-number for the function statue */ 30 /** Code-number for the function statue */
29 public static final int SUCCESS = 0; 31 public static final int SUCCESS = 0;
30 public static final int UNKNOWN_GLEXCEPTION_ERROR = 1; 32 public static final int UNKNOWN_GLEXCEPTION_ERROR = 1;
31 public static final int IOEXCEPTION_ERROR = 2; 33 public static final int IOEXCEPTION_ERROR = 2;
32 public static final int INVALID_FILE = 3; 34 public static final int INVALID_FILE = 3;
33 public static final int GL2PS_ERROR = 4; 35 public static final int GL2PS_ERROR = 4;
34 public static final int GL2PS_OVERFLOW = 5; 36 public static final int GL2PS_OVERFLOW = 5;
35 public static final int GL2PS_UNINITIALIZED = 6; 37 public static final int GL2PS_UNINITIALIZED = 6;
36 38
37 /** Code-number for each bitmap format */ 39 public static final Map<Integer, String> errors = new HashMap<Integer, String>();
38 public static final int BMP_EXPORT = 1; 40 static {
39 public static final int GIF_EXPORT = 2; 41 errors.put(ExportRenderer.SUCCESS, "");
40 public static final int JPG_EXPORT = 3; 42 errors.put(ExportRenderer.UNKNOWN_GLEXCEPTION_ERROR, "OpenGL error during export.");
41 public static final int PNG_EXPORT = 4; 43 errors.put(ExportRenderer.IOEXCEPTION_ERROR, "Unable to create export file, permission denied.");
42 public static final int PPM_EXPORT = 5; 44 errors.put(ExportRenderer.INVALID_FILE, "Unable to create export file, invalid file.");
43 45 errors.put(ExportRenderer.GL2PS_ERROR, "GL2PS error during export.");
44 /** Code-number for each postscript format */ 46 errors.put(ExportRenderer.GL2PS_OVERFLOW, "Unable to create export file, figure is too big.");
45 public static final int EPS_EXPORT = 6; 47 errors.put(ExportRenderer.GL2PS_UNINITIALIZED, "GL2PS error during export.");
46 public static final int PDF_EXPORT = 7; 48 }
47 public static final int SVG_EXPORT = 8; 49
48 public static final int PS_EXPORT = 9; 50 /** Code-number for each bitmap format */
49 51 public static final int BMP_EXPORT = 1;
50 /** Orientation of the exported figure */ 52 public static final int GIF_EXPORT = 2;
51 public static final int PORTRAIT = 0; 53 public static final int JPG_EXPORT = 3;
52 public static final int LANDSCAPE = 1; 54 public static final int PNG_EXPORT = 4;
53 55 public static final int PPM_EXPORT = 5;
54 /** File name & file type */ 56
55 private static String fileName; 57 /** Code-number for each postscript format */
56 private static int fileType; 58 public static final int EPS_EXPORT = 6;
57 private static int fileOrientation; 59 public static final int PDF_EXPORT = 7;
58 60 public static final int SVG_EXPORT = 8;
59 /** File extension */ 61 public static final int PS_EXPORT = 9;
60 private static String fileExtension; 62
61 63 public static final Map<String, Integer> types = new HashMap<String, Integer>();
62 /** give the type of the error */ 64 static {
63 private static int errorNumber; 65 types.put("bmp", BMP_EXPORT);
64 66 types.put("gif", GIF_EXPORT);
65 /** 67 types.put("jpg", JPG_EXPORT);
66 * Constructor 68 types.put("png", PNG_EXPORT);
67 * @param fileName name of the file 69 types.put("ppm", PPM_EXPORT);
68 * @param fileType type of the file 70 types.put("eps", EPS_EXPORT);
69 * @param fileOrientation orientation of the file 71 types.put("pdf", PDF_EXPORT);
70 */ 72 types.put("svg", SVG_EXPORT);
71 protected ExportRenderer(String fileName, int fileType, int fileOrientation) { 73 types.put("ps", PS_EXPORT);
72 this.fileName = fileName; 74 }
73 this.fileType = fileType; 75
74 this.fileOrientation = fileOrientation; 76 /** Orientation of the exported figure */
75 this.fileExtension = ""; 77 public static final int PORTRAIT = 0;
76 removeExtension(); 78 public static final int LANDSCAPE = 1;
77 } 79
78 80 /** File name & file type */
79 /** 81 private static String fileName;
80 * Choose which kind of filetype will be exported 82 private static int fileType;
81 * @param figureIndex type of the file 83 private static int fileOrientation;
82 * @param fileName name of the file 84
83 * @param fileType type of the file 85 /** File extension */
84 * @param fileOrientation orientation of the file 86 private static String fileExtension;
85 * @return GL2PSRenderer export a postscript screen-shot 87
86 */ 88 /** give the type of the error */
87 public static ExportRenderer createExporter(int figureIndex, String fileName, int fileType, float jpegCompressionQuality, int fileOrientation) { 89 private static int errorNumber;
88 90
89 GL2PS gl2ps = new GL2PS(); 91 /**
90 92 * Constructor
91 /** Select in which type the file will be exported */ 93 * @param fileName name of the file
92 switch (fileType) { 94 * @param fileType type of the file
93 case BMP_EXPORT: 95 * @param fileOrientation orientation of the file
94 case GIF_EXPORT: 96 */
95 case JPG_EXPORT: 97 protected ExportRenderer(String fileName, int fileType, int fileOrientation) {
96 case PNG_EXPORT: 98 this.fileName = fileName;
97 case PPM_EXPORT: 99 this.fileType = fileType;
98 return new BitmapRenderer(fileName, fileType, jpegCompressionQuality, fileOrientation); 100 this.fileOrientation = fileOrientation;
99 case EPS_EXPORT: 101 this.fileExtension = "";
100 case PDF_EXPORT: 102 removeExtension();
101 case SVG_EXPORT: 103 }
102 case PS_EXPORT: 104
103 return new GL2PSRenderer(figureIndex, fileName, fileType, fileOrientation); 105 /**
104 default: System.err.println(ExportRenderer.INVALID_FILE); 106 * Choose which kind of filetype will be exported
105 } 107 * @param figureIndex type of the file
106 return null; 108 * @param fileName name of the file
107 } 109 * @param fileType type of the file
108 110 * @param fileOrientation orientation of the file
109 /** 111 * @return GL2PSRenderer export a postscript screen-shot
110 * getter 112 */
111 * @return fileName get the file name 113 public static ExportRenderer createExporter(int figureIndex, String fileName, int fileType, float jpegCompressionQuality, int fileOrientation) {
112 */ 114
113 public static String getFileName() { 115 GL2PS gl2ps = new GL2PS();
114 return fileName; 116
115 } 117 /** Select in which type the file will be exported */
116 118 switch (fileType) {
117 /** 119 case BMP_EXPORT:
118 * setter 120 case GIF_EXPORT:
119 * @param fileName set the file name 121 case JPG_EXPORT:
120 */ 122 case PNG_EXPORT:
121 public void setFileName(String fileName) { 123 case PPM_EXPORT:
122 this.fileName = fileName; 124 return new BitmapRenderer(fileName, fileType, jpegCompressionQuality, fileOrientation);
123 } 125 case EPS_EXPORT:
124 126 case PDF_EXPORT:
125 /** 127 case SVG_EXPORT:
126 * getter 128 case PS_EXPORT:
127 * @return fileType get the file type 129 return new GL2PSRenderer(figureIndex, fileName, fileType, fileOrientation);
128 */ 130 default: System.err.println(ExportRenderer.INVALID_FILE);
129 public static int getFileType() { 131 }
130 return fileType; 132 return null;
131 } 133 }
132 134
133 /** 135 /**
134 * setter 136 * getter
135 * @param fileType set the file name 137 * @return fileName get the file name
136 */ 138 */
137 public void setFileType(int fileType) { 139 public static String getFileName() {
138 this.fileType = fileType; 140 return fileName;
139 } 141 }
140 142
141 /** 143 /**
142 * @return the fileOrientation 144 * setter
143 */ 145 * @param fileName set the file name
144 public static int getFileOrientation() { 146 */
145 return fileOrientation; 147 public void setFileName(String fileName) {
146 } 148 this.fileName = fileName;
147 149 }
148 /** 150
149 * @param fileOrientation the fileOrientation to set 151 /**
150 */ 152 * getter
151 public static void setFileOrientation(int fileOrientation) { 153 * @return fileType get the file type
152 ExportRenderer.fileOrientation = fileOrientation; 154 */
153 } 155 public static int getFileType() {
154 156 return fileType;
155 /** 157 }
156 * getter 158
157 * @return the fileExtension 159 /**
158 */ 160 * setter
159 public static String getFileExtension() { 161 * @param fileType set the file name
160 return fileExtension; 162 */
161 } 163 public void setFileType(int fileType) {
162 164 this.fileType = fileType;
163 /** 165 }
164 * setter 166
165 * @param fileExtension the fileExtension to set 167 /**
166 */ 168 * @return the fileOrientation
167 public void setFileExtension(String fileExtension) { 169 */
168 this.fileExtension = fileExtension; 170 public static int getFileOrientation() {
169 } 171 return fileOrientation;
170 172 }
171 /** 173
172 * Function allowing to format the extension of the screen-shot file 174 /**
173 */ 175 * @param fileOrientation the fileOrientation to set
174 public void removeExtension() { 176 */
175 String suffix = FileUtil.getFileSuffix(this.fileName); //get the suffix(extension) of the file name 177 public static void setFileOrientation(int fileOrientation) {
176 int pos = this.fileName.lastIndexOf('.'); // position of the dot 178 ExportRenderer.fileOrientation = fileOrientation;
177 179 }
178 if (suffix != null) { 180
179 181 /**
180 String[] extensionsAllowed = {"bmp", "gif", "jpg", "jpeg", "png", "ppm", "eps", "pdf", "svg", "ps"}; 182 * getter
181 183 * @return the fileExtension
182 Integer[] fileTypeAllowed = {ExportRenderer.BMP_EXPORT, ExportRenderer.GIF_EXPORT, 184 */
183 ExportRenderer.JPG_EXPORT, ExportRenderer.PNG_EXPORT, 185 public static String getFileExtension() {
184 ExportRenderer.PPM_EXPORT, ExportRenderer.EPS_EXPORT, 186 return fileExtension;
185 ExportRenderer.PDF_EXPORT, ExportRenderer.SVG_EXPORT, 187 }
186 ExportRenderer.PS_EXPORT}; 188
187 189 /**
188 suffix = suffix.toLowerCase(); 190 * setter
189 191 * @param fileExtension the fileExtension to set
190 /* Transform the array to vector to have access to search methods*/ 192 */
191 193 public void setFileExtension(String fileExtension) {
192 ArrayList<String> extensionsAllowedV = new ArrayList<String>(Arrays.asList(extensionsAllowed)); 194 this.fileExtension = fileExtension;
193 ArrayList<Integer> fileTypeAllowedV = new ArrayList<Integer>(Arrays.asList(fileTypeAllowed)); 195 }
194 196
195 if (extensionsAllowedV.contains(suffix) && fileTypeAllowedV.contains(this.fileType)){ 197 /**
196 this.fileName = this.fileName.substring(0, pos); /* Physically removed the extension */ 198 * Function allowing to format the extension of the screen-shot file
197 this.fileExtension = suffix; /* Store the extension... we want the same as used initially (ex: jpeg) */ 199 */
198 } 200 public void removeExtension() {
199 } 201 String suffix = FileUtil.getFileSuffix(this.fileName); //get the suffix(extension) of the file name
200 } 202 int pos = this.fileName.lastIndexOf('.'); // position of the dot
201 203
202 /** 204 if (suffix != null) {
203 * get the number of the error 205
204 * @return errorNumber the number of the error 206 String[] extensionsAllowed = {"bmp", "gif", "jpg", "jpeg", "png", "ppm", "eps", "pdf", "svg", "ps"};
205 */ 207
206 public static int getErrorNumber() { 208 Integer[] fileTypeAllowed = {ExportRenderer.BMP_EXPORT, ExportRenderer.GIF_EXPORT,
207 return errorNumber; 209 ExportRenderer.JPG_EXPORT, ExportRenderer.PNG_EXPORT,
208 } 210 ExportRenderer.PPM_EXPORT, ExportRenderer.EPS_EXPORT,
209 211 ExportRenderer.PDF_EXPORT, ExportRenderer.SVG_EXPORT,
210 /** 212 ExportRenderer.PS_EXPORT};
211 * set the number of the error 213
212 * @param errorNumber the number of the error 214 suffix = suffix.toLowerCase();
213 */ 215
214 public static void setErrorNumber(int errorNumber) { 216 /* Transform the array to vector to have access to search methods*/
215 ExportRenderer.errorNumber = errorNumber; 217
216 } 218 ArrayList<String> extensionsAllowedV = new ArrayList<String>(Arrays.asList(extensionsAllowed));
219 ArrayList<Integer> fileTypeAllowedV = new ArrayList<Integer>(Arrays.asList(fileTypeAllowed));
220
221 if (extensionsAllowedV.contains(suffix) && fileTypeAllowedV.contains(this.fileType)){
222 this.fileName = this.fileName.substring(0, pos); /* Physically removed the extension */
223 this.fileExtension = suffix; /* Store the extension... we want the same as used initially (ex: jpeg) */
224 }
225 }
226 }
227
228 /**
229 * get the number of the error
230 * @return errorNumber the number of the error
231 */
232 public static int getErrorNumber() {
233 return errorNumber;
234 }
235
236 /**
237 * set the number of the error
238 * @param errorNumber the number of the error
239 */
240 public static void setErrorNumber(int errorNumber) {
241 ExportRenderer.errorNumber = errorNumber;
242 }
217} 243}
diff --git a/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/FileExporter.java b/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/FileExporter.java
index 980aa63..78889c6 100644
--- a/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/FileExporter.java
+++ b/scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/FileExporter.java
@@ -3,11 +3,11 @@
3 * Copyright (C) 2007 - INRIA - Jean-Baptiste Silvy 3 * Copyright (C) 2007 - INRIA - Jean-Baptiste Silvy
4 * Copyright (C) 2009 - Calixte Denizet 4 * Copyright (C) 2009 - Calixte Denizet
5 * desc : Static class used to create file export of graphic figures 5 * desc : Static class used to create file export of graphic figures
6 * 6 *
7 * This file must be used under the terms of the CeCILL. 7 * This file must be used under the terms of the CeCILL.
8 * This source file is licensed as described in the file COPYING, which 8 * This source file is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms 9 * you should have received as part of this distribution. The terms
10 * are also available at 10 * are also available at
11 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 11 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 * 12 *
13 */ 13 */
@@ -45,19 +45,20 @@ public class FileExporter {
45 * @param figureIndex index of the figure to export 45 * @param figureIndex index of the figure to export
46 * @param fileName name of the file to create 46 * @param fileName name of the file to create
47 * @param fileType kind of the file 47 * @param fileType kind of the file
48 * @param jpegCompressionQuality the JPEG compression quality
48 * @param fileOrientation orientation of the file 49 * @param fileOrientation orientation of the file
49 * @return 0 if everything worked fine, a non null integer if an exception occured 50 * @return 0 if everything worked fine, a non null integer if an exception occured
50 * depending on the kind of error 51 * depending on the kind of error
51 */ 52 */
52 public static int fileExport(int figureIndex, String fileName, int fileType, float jpegCompressionQuality, int fileOrientation) { 53 public static String fileExport(int figureIndex, String fileName, int fileType, float jpegCompressionQuality, int fileOrientation) {
53 int saveFileType = -1; 54 int saveFileType = -1;
54 String saveFileName = ""; 55 String saveFileName = "";
55 56
56 DrawableFigureGL exportedFig = FigureMapper.getCorrespondingFigure(figureIndex); 57 DrawableFigureGL exportedFig = FigureMapper.getCorrespondingFigure(figureIndex);
57 58
58 if (exportedFig == null) { 59 if (exportedFig == null) {
59 // figure no longer exists 60 // figure no longer exists
60 return ExportRenderer.IOEXCEPTION_ERROR; 61 return ExportRenderer.errors.get(ExportRenderer.IOEXCEPTION_ERROR);
61 } 62 }
62 63
63 //When the graphic-export is too long, we inform the user that the figure is exporting 64 //When the graphic-export is too long, we inform the user that the figure is exporting
@@ -91,17 +92,17 @@ public class FileExporter {
91 String ext = ""; 92 String ext = "";
92 93
93 switch (fileType) { 94 switch (fileType) {
94 case ExportRenderer.PDF_EXPORT: 95 case ExportRenderer.PDF_EXPORT:
95 ext = ".pdf"; 96 ext = ".pdf";
96 break; 97 break;
97 case ExportRenderer.EPS_EXPORT: 98 case ExportRenderer.EPS_EXPORT:
98 ext = ".eps"; 99 ext = ".eps";
99 break; 100 break;
100 case ExportRenderer.PS_EXPORT: 101 case ExportRenderer.PS_EXPORT:
101 ext = ".ps"; 102 ext = ".ps";
102 break; 103 break;
103 default: /* Do not the extension. Probably an error */ 104 default: /* Do not the extension. Probably an error */
104 return ExportRenderer.IOEXCEPTION_ERROR; 105 return ExportRenderer.errors.get(ExportRenderer.IOEXCEPTION_ERROR);
105 } 106 }
106 107
107 String name = new File(fileName).getName(); 108 String name = new File(fileName).getName();
@@ -117,7 +118,7 @@ public class FileExporter {
117 /* Temporary SVG file which will be used to convert to PDF */ 118 /* Temporary SVG file which will be used to convert to PDF */
118 /* fileName prefix must be at least 3 characters */ 119 /* fileName prefix must be at least 3 characters */
119 while (name.length() < 3) { 120 while (name.length() < 3) {
120 name = "_" + name; 121 name = "_" + name;
121 } 122 }
122 fileName = File.createTempFile(name,".svg").getAbsolutePath(); 123 fileName = File.createTempFile(name,".svg").getAbsolutePath();
123 } catch (IOException e) { 124 } catch (IOException e) {
@@ -127,7 +128,7 @@ public class FileExporter {
127 saveFileType = fileType; 128 saveFileType = fileType;
128 fileType = ExportRenderer.SVG_EXPORT; 129 fileType = ExportRenderer.SVG_EXPORT;
129 } 130 }
130 131
131 ExportRenderer export; 132 ExportRenderer export;
132 export = ExportRenderer.createExporter(figureIndex, fileName, fileType, jpegCompressionQuality, fileOrientation); 133 export = ExportRenderer.createExporter(figureIndex, fileName, fileType, jpegCompressionQuality, fileOrientation);
133 134
@@ -146,6 +147,6 @@ public class FileExporter {
146 new File(fileName).delete(); 147 new File(fileName).delete();
147 } 148 }
148 149
149 return ExportRenderer.getErrorNumber(); 150 return ExportRenderer.errors.get(ExportRenderer.getErrorNumber());
150 } 151 }
151} 152}
diff --git a/scilab/modules/graphic_export/src/jni/FileExporter.cpp b/scilab/modules/graphic_export/src/jni/FileExporter.cpp
index 39af3fd..97dc96f 100644
--- a/scilab/modules/graphic_export/src/jni/FileExporter.cpp
+++ b/scilab/modules/graphic_export/src/jni/FileExporter.cpp
@@ -104,7 +104,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
104curEnv->DeleteLocalRef(localInstance); 104curEnv->DeleteLocalRef(localInstance);
105 105
106 /* Methods ID set to NULL */ 106 /* Methods ID set to NULL */
107jintfileExportjintjstringjintjfloatjintID=NULL; 107jstringfileExportjintjstringjintjfloatjintID=NULL;
108 108
109 109
110} 110}
@@ -127,7 +127,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
127throw GiwsException::JniObjectCreationException(curEnv, this->className()); 127throw GiwsException::JniObjectCreationException(curEnv, this->className());
128 } 128 }
129 /* Methods ID set to NULL */ 129 /* Methods ID set to NULL */
130 jintfileExportjintjstringjintjfloatjintID=NULL; 130 jstringfileExportjintjstringjintjfloatjintID=NULL;
131 131
132 132
133} 133}
@@ -147,14 +147,14 @@ throw GiwsException::JniMonitorException(getCurrentEnv(), "FileExporter");
147} 147}
148// Method(s) 148// Method(s)
149 149
150int FileExporter::fileExport (JavaVM * jvm_, int figureIndex, char * fileName, int fileType, float jpegCompressionQuality, int orientation){ 150char * FileExporter::fileExport (JavaVM * jvm_, int figureIndex, char * fileName, int fileType, float jpegCompressionQuality, int orientation){
151 151
152JNIEnv * curEnv = NULL; 152JNIEnv * curEnv = NULL;
153jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL); 153jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
154jclass cls = curEnv->FindClass( className().c_str() ); 154jclass cls = curEnv->FindClass( className().c_str() );
155 155
156jmethodID jintfileExportjintjstringjintjfloatjintID = curEnv->GetStaticMethodID(cls, "fileExport", "(ILjava/lang/String;IFI)I" ) ; 156jmethodID jstringfileExportjintjstringjintjfloatjintID = curEnv->GetStaticMethodID(cls, "fileExport", "(ILjava/lang/String;IFI)Ljava/lang/String;" ) ;
157if (jintfileExportjintjstringjintjfloatjintID == NULL) { 157if (jstringfileExportjintjstringjintjfloatjintID == NULL) {
158throw GiwsException::JniMethodNotFoundException(curEnv, "fileExport"); 158throw GiwsException::JniMethodNotFoundException(curEnv, "fileExport");
159} 159}
160 160
@@ -165,13 +165,23 @@ throw GiwsException::JniBadAllocException(curEnv);
165} 165}
166 166
167 167
168 jint res = static_cast<jint>( curEnv->CallStaticIntMethod(cls, jintfileExportjintjstringjintjfloatjintID ,figureIndex, fileName_, fileType, jpegCompressionQuality, orientation)); 168 jstring res = static_cast<jstring>( curEnv->CallStaticObjectMethod(cls, jstringfileExportjintjstringjintjfloatjintID ,figureIndex, fileName_, fileType, jpegCompressionQuality, orientation));
169 curEnv->DeleteLocalRef(fileName_); 169 if (curEnv->ExceptionCheck()) {
170throw GiwsException::JniCallMethodException(curEnv);
171}
172
173const char *tempString = curEnv->GetStringUTFChars(res, 0);
174char * myStringBuffer = new char[strlen(tempString) + 1];
175strcpy(myStringBuffer, tempString);
176curEnv->ReleaseStringUTFChars(res, tempString);
177curEnv->DeleteLocalRef(res);
178curEnv->DeleteLocalRef(fileName_);
170curEnv->DeleteLocalRef(cls); 179curEnv->DeleteLocalRef(cls);
171if (curEnv->ExceptionCheck()) { 180if (curEnv->ExceptionCheck()) {
172throw GiwsException::JniCallMethodException(curEnv); 181delete[] myStringBuffer;
182 throw GiwsException::JniCallMethodException(curEnv);
173} 183}
174return res; 184return myStringBuffer;
175 185
176} 186}
177 187
diff --git a/scilab/modules/graphic_export/src/jni/FileExporter.giws.xml b/scilab/modules/graphic_export/src/jni/FileExporter.giws.xml
index ad08169..d0a3b44 100644
--- a/scilab/modules/graphic_export/src/jni/FileExporter.giws.xml
+++ b/scilab/modules/graphic_export/src/jni/FileExporter.giws.xml
@@ -12,7 +12,7 @@
12 12
13<package name="org.scilab.modules.graphic_export"> 13<package name="org.scilab.modules.graphic_export">
14 <object name="FileExporter"> 14 <object name="FileExporter">
15 <method name="fileExport" returnType="int" modifier="static"> 15 <method name="fileExport" returnType="String" modifier="static">
16 <parameter name="figureIndex" type="int"/> 16 <parameter name="figureIndex" type="int"/>
17 <parameter name="fileName" type="String"/> 17 <parameter name="fileName" type="String"/>
18 <parameter name="fileType" type="int"/> 18 <parameter name="fileType" type="int"/>
diff --git a/scilab/modules/graphic_export/src/jni/FileExporter.hxx b/scilab/modules/graphic_export/src/jni/FileExporter.hxx
index 12f92a7..8bed854 100644
--- a/scilab/modules/graphic_export/src/jni/FileExporter.hxx
+++ b/scilab/modules/graphic_export/src/jni/FileExporter.hxx
@@ -64,7 +64,7 @@ private:
64JavaVM * jvm; 64JavaVM * jvm;
65 65
66protected: 66protected:
67jmethodID jintfileExportjintjstringjintjfloatjintID; // cache method id 67jmethodID jstringfileExportjintjstringjintjfloatjintID; // cache method id
68 68
69 69
70 70
@@ -121,7 +121,7 @@ void synchronize();
121void endSynchronize(); 121void endSynchronize();
122 122
123// Methods 123// Methods
124static int fileExport(JavaVM * jvm_, int figureIndex, char * fileName, int fileType, float jpegCompressionQuality, int orientation); 124static char * fileExport(JavaVM * jvm_, int figureIndex, char * fileName, int fileType, float jpegCompressionQuality, int orientation);
125 125
126 126
127 /** 127 /**
diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/ExportOptionWindow.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/ExportOptionWindow.java
index ee8bd7e..27e6373 100644
--- a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/ExportOptionWindow.java
+++ b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/ExportOptionWindow.java
@@ -1,18 +1,21 @@
1/* 1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Sylvestre Koumar 3 * Copyright (C) 2008 - INRIA - Sylvestre Koumar
4 * 4 * Copyright (C) 2011 - Calixte DENIZET
5 *
5 * This file must be used under the terms of the CeCILL. 6 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which 7 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms 8 * you should have received as part of this distribution. The terms
8 * are also available at 9 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 * 11 *
11 */ 12 */
12package org.scilab.modules.gui.bridge.filechooser; 13package org.scilab.modules.gui.bridge.filechooser;
13 14
14import java.awt.BorderLayout; 15import java.awt.BorderLayout;
16import java.awt.Cursor;
15import java.awt.GridLayout; 17import java.awt.GridLayout;
18import java.awt.Window;
16import java.awt.event.ActionEvent; 19import java.awt.event.ActionEvent;
17import java.awt.event.ActionListener; 20import java.awt.event.ActionListener;
18import java.util.Vector; 21import java.util.Vector;
@@ -21,131 +24,140 @@ import javax.swing.BorderFactory;
21import javax.swing.ButtonGroup; 24import javax.swing.ButtonGroup;
22import javax.swing.ImageIcon; 25import javax.swing.ImageIcon;
23import javax.swing.JButton; 26import javax.swing.JButton;
24import javax.swing.JFrame; 27import javax.swing.JComponent;
28import javax.swing.JDialog;
25import javax.swing.JPanel; 29import javax.swing.JPanel;
26import javax.swing.JRadioButton; 30import javax.swing.JRadioButton;
31import javax.swing.SwingUtilities;
27 32
28import org.scilab.modules.action_binding.InterpreterManagement; 33import org.scilab.modules.action_binding.InterpreterManagement;
34import org.scilab.modules.graphic_export.ExportRenderer;
35import org.scilab.modules.graphic_export.FileExporter;
36import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
37import org.scilab.modules.gui.messagebox.ScilabModalDialog;
38import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
39import org.scilab.modules.gui.tab.Tab;
29 40
30/** 41/**
31 * Window in which we can configure option for the selected format 42 * Window in which we can configure option for the selected format
32 * @author Sylvestre Koumar 43 * @author Sylvestre Koumar
44 * @author Calixte DENIZET
33 * 45 *
34 */ 46 */
35public class ExportOptionWindow extends JFrame implements ActionListener { 47public class ExportOptionWindow extends JDialog implements ActionListener {
36 48
37 private static final long serialVersionUID = 1L; 49 private static final long serialVersionUID = 1L;
38 50
39 private ExportData exportData; 51 private ExportData exportData;
40 private JFrame optionFrame; 52 private Window parentWindow;
53 private Tab parentTab;
54 private JDialog optionDialog;
41 private JRadioButton portrait; 55 private JRadioButton portrait;
42 private JRadioButton landscape; 56 private JRadioButton landscape;
43 private JButton confirmOption; 57 private JButton confirmOption;
44 private JButton abortOption; 58 private JButton abortOption;
45 59
46
47 /** 60 /**
48 * Default constructor 61 * Default constructor
49 * @param exportData information about the export 62 * @param exportData information about the export
50 */ 63 */
51 public ExportOptionWindow(ExportData exportData) { 64 public ExportOptionWindow(ExportData exportData) {
52 this.exportData = exportData; 65 this.exportData = exportData;
53 } 66 }
54 67
55 /** 68 /**
56 * Display the option window 69 * Display the option window
57 */ 70 */
58 public void displayOptionWindow() { 71 public void displayOptionWindow(Tab tab) {
59 optionFrame = new JFrame("Option for " + exportData.getExportExtension().toUpperCase() + " format"); 72 parentTab = tab;
60 optionFrame.setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/scilab.png").getImage()); 73 parentWindow = (Window) SwingUtilities.getAncestorOfClass(Window.class, (JComponent) tab.getAsSimpleTab());
61 //Center the frame 74 optionDialog = new JDialog(parentWindow);
62 optionFrame.setLocationRelativeTo(optionFrame.getParent()); 75 optionDialog.setTitle("Option for " + exportData.getExportExtension().toUpperCase() + " format");
63 76 optionDialog.setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/scilab.png").getImage());
64 optionFrame.setResizable(false); 77 //Center the frame
65 optionFrame.setVisible(true); 78 optionDialog.setLocationRelativeTo(parentWindow);
66 } 79 }
67 80
68 /** 81 /**
69 * Selection between portrait or landscape option 82 * Selection between portrait or landscape option
70 */ 83 */
71 public void landscapePortraitOption() { 84 public void landscapePortraitOption() {
72 85 portrait = new JRadioButton("Portrait", true);
73 portrait = new JRadioButton("Portrait", true); 86 landscape = new JRadioButton("Landscape", false);
74 landscape = new JRadioButton("Landscape", false); 87
75 88 ButtonGroup bgroup = new ButtonGroup();
76 ButtonGroup bgroup = new ButtonGroup(); 89 bgroup.add(portrait);
77 bgroup.add(portrait); 90 bgroup.add(landscape);
78 bgroup.add(landscape); 91
79 92 confirmOption = new JButton("Confirm");
80 confirmOption = new JButton("Confirm"); 93 abortOption = new JButton("Abort");
81 abortOption = new JButton("Abort"); 94
82 95
83 96 JPanel mainPanel = new JPanel();
84 JPanel mainPanel = new JPanel(); 97 BorderLayout layout = new BorderLayout();
85 BorderLayout layout = new BorderLayout(); 98 mainPanel.setLayout(layout);
86 mainPanel.setLayout(layout); 99
87 100 JPanel center = new JPanel();
88 JPanel center = new JPanel(); 101 center.setLayout(new GridLayout(2, 1));
89 center.setLayout(new GridLayout(2, 1)); 102 center.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Orientation "));
90 center.setBorder(BorderFactory.createTitledBorder( 103
91 BorderFactory.createEtchedBorder(), " Orientation ")); 104 center.add(portrait);
92 105 center.add(landscape);
93 center.add(portrait); 106
94 center.add(landscape); 107 JPanel south = new JPanel();
95 108
96 JPanel south = new JPanel(); 109 south.add(confirmOption);
97 110 south.add(abortOption);
98 south.add(confirmOption); 111
99 south.add(abortOption); 112 mainPanel.add(center, BorderLayout.CENTER);
100 113 mainPanel.add(south, BorderLayout.EAST);
101 mainPanel.add(center, BorderLayout.CENTER); 114
102 mainPanel.add(south, BorderLayout.EAST); 115 optionDialog.add(mainPanel);
103 116 optionDialog.pack();
104 optionFrame.add(mainPanel); 117
105 optionFrame.pack(); 118 portrait.addActionListener(this);
106 119 landscape.addActionListener(this);
107 portrait.addActionListener(this); 120 confirmOption.addActionListener(this);
108 landscape.addActionListener(this); 121 abortOption.addActionListener(this);
109 confirmOption.addActionListener(this); 122
110 abortOption.addActionListener(this); 123 optionDialog.setModal(true);
111 124 optionDialog.setResizable(false);
112 } 125 optionDialog.setVisible(true);
113 126 }
114 /** 127
115 * Action manager 128 /**
116 * @param evt ActionEvent 129 * Action manager
117 */ 130 * @param evt ActionEvent
131 */
118 public void actionPerformed(ActionEvent evt) { 132 public void actionPerformed(ActionEvent evt) {
119 133 boolean b = portrait.isSelected();
120 boolean b = portrait.isSelected(); 134 Vector<String> properties = new Vector<String>();
121 Vector<String> properties = new Vector<String>(); 135
122 136 if (evt.getSource() == confirmOption) {
123 137 if (b) {
124 if (evt.getSource() == confirmOption) { 138 properties.add(portrait.getText().toLowerCase());
125 if (b) { 139 } else {
126 properties.add(portrait.getText().toLowerCase()); 140 properties.add(landscape.getText().toLowerCase());
127 } else { 141 }
128 properties.add(landscape.getText().toLowerCase()); 142 exportData.setExportProperties(properties);
129 } 143 optionDialog.dispose();
130 exportData.setExportProperties(properties); 144
131 optionFrame.dispose(); 145 int figId = exportData.getFigureId();
132 146 String fileName = exportData.getExportName();
133 147 int fileType = ExportRenderer.types.get(exportData.getExportExtension());
134 //now we manage only one option (portrait/landscape) 148 int orientation = exportData.getExportProperties().elementAt(0).equalsIgnoreCase("landscape") ? ExportRenderer.LANDSCAPE : ExportRenderer.PORTRAIT;
135 //later we will have to manage more options (Vector<String> properties) 149
136 String exportcmd = "xs2" + exportData.getExportExtension() 150 parentWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
137 + "(" + exportData.getFigureId() + ", '" + exportData.getExportName() 151 String err = FileExporter.fileExport(figId, fileName, fileType, 1f, orientation);// 1f is the jpeg quality compression and it is useless here
138 + "', '" + exportData.getExportProperties().elementAt(0) + "');"; 152 parentWindow.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
139 153
140 InterpreterManagement.putCommandInScilabQueue(exportcmd); 154 if (err.length() != 0) {
141 } 155 ScilabModalDialog.show(parentTab, "An error occurred during export: " + err, "Export error", IconType.ERROR_ICON);
142 156 }
143 if (evt.getSource() == abortOption) { 157 }
144 optionFrame.dispose(); 158
145 } 159 if (evt.getSource() == abortOption) {
146 160 optionDialog.dispose();
147 161 }
148 } 162 }
149
150
151} 163}
diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/SwingScilabExportFileChooser.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/SwingScilabExportFileChooser.java
index 5f79d9f..9effc04 100644
--- a/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/SwingScilabExportFileChooser.java
+++ b/scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/filechooser/SwingScilabExportFileChooser.java
@@ -1,30 +1,38 @@
1/* 1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Sylvestre Koumar 3 * Copyright (C) 2008 - INRIA - Sylvestre Koumar
4 * 4 * Copyright (C) 2011 - Calixte DENIZET
5 *
5 * This file must be used under the terms of the CeCILL. 6 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which 7 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms 8 * you should have received as part of this distribution. The terms
8 * are also available at 9 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 * 11 *
11 */ 12 */
12package org.scilab.modules.gui.bridge.filechooser; 13package org.scilab.modules.gui.bridge.filechooser;
13 14
15import java.awt.Component;
16import java.awt.Window;
14import java.io.File; 17import java.io.File;
15import java.util.ArrayList; 18import java.util.ArrayList;
16 19
17import javax.swing.BorderFactory; 20import javax.swing.BorderFactory;
18import javax.swing.ImageIcon; 21import javax.swing.ImageIcon;
22import javax.swing.JComponent;
19import javax.swing.JFileChooser; 23import javax.swing.JFileChooser;
20import javax.swing.JFrame; 24import javax.swing.JFrame;
21import javax.swing.JOptionPane; 25import javax.swing.JOptionPane;
22import javax.swing.JPanel; 26import javax.swing.JPanel;
27import javax.swing.SwingUtilities;
23import javax.swing.border.TitledBorder; 28import javax.swing.border.TitledBorder;
24 29
25import org.scilab.modules.action_binding.InterpreterManagement; 30import org.scilab.modules.action_binding.InterpreterManagement;
31import org.scilab.modules.gui.graphicWindow.ScilabRendererProperties;
32import org.scilab.modules.gui.tab.Tab;
26import org.scilab.modules.gui.utils.ConfigManager; 33import org.scilab.modules.gui.utils.ConfigManager;
27import org.scilab.modules.localization.Messages; 34import org.scilab.modules.localization.Messages;
35import org.scilab.modules.renderer.FigureMapper;
28 36
29/** 37/**
30 * This is the son of the usual Scilab file chooser, 38 * This is the son of the usual Scilab file chooser,
@@ -33,251 +41,249 @@ import org.scilab.modules.localization.Messages;
33 * 41 *
34 */ 42 */
35public class SwingScilabExportFileChooser extends SwingScilabFileChooser { 43public class SwingScilabExportFileChooser extends SwingScilabFileChooser {
36 44
37 private static final int NB_FILE_MASKS = 12; 45 private static final int NB_FILE_MASKS = 12;
38 46
39 private final String bmpDesc = Messages.gettext("Windows BMP image"); 47 private final String bmpDesc = Messages.gettext("Windows BMP image");
40 private final String gifDesc = Messages.gettext("GIF image"); 48 private final String gifDesc = Messages.gettext("GIF image");
41 private final String jpgDesc = Messages.gettext("JPEG image"); 49 private final String jpgDesc = Messages.gettext("JPEG image");
42 private final String pngDesc = Messages.gettext("PNG image"); 50 private final String pngDesc = Messages.gettext("PNG image");
43 private final String ppmDesc = Messages.gettext("PPM image"); 51 private final String ppmDesc = Messages.gettext("PPM image");
44 private final String emfDesc = Messages.gettext("Enhanced Metafile image (EMF)"); 52 private final String emfDesc = Messages.gettext("Enhanced Metafile image (EMF)");
45 private final String epsDesc = Messages.gettext("Encapsulated PostScript image (EPS)"); 53 private final String epsDesc = Messages.gettext("Encapsulated PostScript image (EPS)");
46 private final String figDesc = Messages.gettext("FIG image"); 54 private final String figDesc = Messages.gettext("FIG image");
47 private final String pdfDesc = Messages.gettext("PDF image"); 55 private final String pdfDesc = Messages.gettext("PDF image");
48 private final String svgDesc = Messages.gettext("SVG image"); 56 private final String svgDesc = Messages.gettext("SVG image");
49 private final String allFilesDesc = Messages.gettext("All files"); 57 private final String allFilesDesc = Messages.gettext("All files");
50 58
51 private final String bmp = "bmp"; 59 private final String bmp = "bmp";
52 private final String gif = "gif"; 60 private final String gif = "gif";
53 private final String[] jpg = {"jpg", "jpeg"}; 61 private final String[] jpg = {"jpg", "jpeg"};
54 private final String png = "png"; 62 private final String png = "png";
55 private final String ppm = "ppm"; 63 private final String ppm = "ppm";
56 private final String emf = "emf"; 64 private final String emf = "emf";
57 private final String eps = "eps"; 65 private final String eps = "eps";
58 private final String fig = "fig"; 66 private final String fig = "fig";
59 private final String pdf = "pdf"; 67 private final String pdf = "pdf";
60 private final String svg = "svg"; 68 private final String svg = "svg";
61 private final String allFiles = "*"; 69 private final String allFiles = "*";
62 70
63 private String exportName; 71 private String exportName;
64 private String extensionSelected; 72 private String extensionSelected;
65 private int figureId; 73 private int figureId;
66 74
67 /** 75 /**
68 * Default constructor 76 * Default constructor
69 * @param figureId id of the exported figure 77 * @param figureId id of the exported figure
70 */ 78 */
71 public SwingScilabExportFileChooser(int figureId) { 79 public SwingScilabExportFileChooser(int figureId) {
72 super(); 80 super();
73 this.figureId = figureId; 81 this.figureId = figureId;
74 exportCustomFileChooser(figureId); 82 exportCustomFileChooser(figureId);
75 } 83 }
76 84
77 /** 85 /**
78 * We customize the file chooser for the graphic export 86 * We customize the file chooser for the graphic export
79 * by adding format selection 87 * by adding format selection
80 * @param figureId exported figure number 88 * @param figureId exported figure number
81 */ 89 */
82 public void exportCustomFileChooser(int figureId) { 90 public void exportCustomFileChooser(int figureId) {
83 ArrayList<FileMask> v = new ArrayList<FileMask>(NB_FILE_MASKS); /* The order does matter */ 91 ArrayList<FileMask> v = new ArrayList<FileMask>(NB_FILE_MASKS); /* The order does matter */
84 v.add(new FileMask(bmp, bmpDesc)); 92 v.add(new FileMask(bmp, bmpDesc));
85 v.add(new FileMask(gif, gifDesc)); 93 v.add(new FileMask(gif, gifDesc));
86 v.add(new FileMask(jpg, jpgDesc)); 94 v.add(new FileMask(jpg, jpgDesc));
87 v.add(new FileMask(png, pngDesc)); 95 v.add(new FileMask(png, pngDesc));
88 v.add(new FileMask(ppm, ppmDesc)); 96 v.add(new FileMask(ppm, ppmDesc));
89 v.add(new FileMask(emf, emfDesc)); 97 v.add(new FileMask(emf, emfDesc));
90 v.add(new FileMask(eps, epsDesc)); 98 v.add(new FileMask(eps, epsDesc));
91 v.add(new FileMask(fig, figDesc)); 99 v.add(new FileMask(fig, figDesc));
92 v.add(new FileMask(pdf, pdfDesc)); 100 v.add(new FileMask(pdf, pdfDesc));
93 v.add(new FileMask(svg, svgDesc)); 101 v.add(new FileMask(svg, svgDesc));
94 v.add(new FileMask(allFiles, allFilesDesc)); // should always be at the last position 102 v.add(new FileMask(allFiles, allFilesDesc)); // should always be at the last position
95 103
96 super.setDialogTitle(Messages.gettext("Export")); 104 super.setDialogTitle(Messages.gettext("Export"));
97 super.setApproveButtonText(Messages.gettext("Export")); 105 super.setApproveButtonText(Messages.gettext("Export"));
98 File exportFile = new File(Messages.gettext("Untitled-export")); 106 File exportFile = new File(Messages.gettext("Untitled-export"));
99 super.setSelectedFile(exportFile); 107 super.setSelectedFile(exportFile);
100 super.setAcceptAllFileFilterUsed(false); 108 super.setAcceptAllFileFilterUsed(false);
101 109
102 this.figureId = figureId; 110 this.figureId = figureId;
103 111
104 for (int i = 0; i < v.size(); i++) { 112 for (int i = 0; i < v.size(); i++) {
105 FileMask fm = (FileMask) v.get(i); 113 FileMask fm = (FileMask) v.get(i);
106 if (i == v.size() - 1) { /* Last case ... all files, remove the extension */ 114 if (i == v.size() - 1) { /* Last case ... all files, remove the extension */
107 fm.clearExtensions(); 115 fm.clearExtensions();
108 } 116 }
109 super.addChoosableFileFilter(fm); 117 super.addChoosableFileFilter(fm);
110 } 118 }
111 119
112 //Preview panel 120 //Preview panel
113 JPanel panelPreview = new JPanel(); 121 JPanel panelPreview = new JPanel();
114 122
115 //Title for preview panel 123 //Title for preview panel
116 TitledBorder titlePreview; 124 TitledBorder titlePreview;
117 titlePreview = BorderFactory.createTitledBorder(Messages.gettext("Preview")); 125 titlePreview = BorderFactory.createTitledBorder(Messages.gettext("Preview"));
118 panelPreview.setBorder(titlePreview); 126 panelPreview.setBorder(titlePreview);
119 127
120 //add preview image 128 //add preview image
121 panelPreview.add(new ImagePreview(this)); 129 panelPreview.add(new ImagePreview(this));
122 130
123 //Main panel contains extensionTable panel & preview panel 131 //Main panel contains extensionTable panel & preview panel
124 JPanel accessoryPanel = new JPanel(); 132 JPanel accessoryPanel = new JPanel();
125 133
126 //accessoryPanel.add(scrollPane); 134 //accessoryPanel.add(scrollPane);
127 accessoryPanel.add(panelPreview); 135 accessoryPanel.add(panelPreview);
128 accessoryPanel.setVisible(true); 136 accessoryPanel.setVisible(true);
129 super.setAccessory(accessoryPanel); 137 super.setAccessory(accessoryPanel);
130 138
131 JFrame frame = new JFrame(); 139 Tab tab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureId).getRendererProperties()).getParentTab();
132 frame.setIconImage(new ImageIcon(System.getenv("SCI") + "/modules/gui/images/icons/scilab.png").getImage()); 140 Window parentWindow = (Window) SwingUtilities.getAncestorOfClass(Window.class, (JComponent) tab.getAsSimpleTab());
133 int selection = super.showSaveDialog(frame); 141
134 if (selection == JFileChooser.APPROVE_OPTION) { 142 int selection = super.showSaveDialog((Component) parentWindow);
135 143 if (selection == JFileChooser.APPROVE_OPTION) {
136 this.exportName = super.getSelectedFile().getAbsolutePath(); 144
137 145 this.exportName = super.getSelectedFile().getAbsolutePath();
138 //Test if there is a file with the same name 146
139 if (new File(this.exportName).exists()) { 147 //Test if there is a file with the same name
140 int actionDialog = JOptionPane.showConfirmDialog( 148 if (new File(this.exportName).exists()) {
141 this, Messages.gettext("Replace existing file?"), 149 int actionDialog = JOptionPane.showConfirmDialog(
142 Messages.gettext("File already exists"), 150 this, Messages.gettext("Replace existing file?"),
143 JOptionPane.YES_NO_OPTION); 151 Messages.gettext("File already exists"),
144 152 JOptionPane.YES_NO_OPTION);
145 if (actionDialog == JOptionPane.YES_OPTION) { 153
146 154 if (actionDialog == JOptionPane.YES_OPTION) {
147 } else { 155
148 return; 156 } else {
149 } 157 return;
150 } 158 }
151 159 }
152 /* Bug 3849 fix */ 160
153 ConfigManager.saveLastOpenedDirectory(new File(exportName).getParentFile().getPath()); 161 /* Bug 3849 fix */
154 162 ConfigManager.saveLastOpenedDirectory(new File(exportName).getParentFile().getPath());
155 String extensionCombo = new String(); 163
156 try { 164 String extensionCombo = new String();
157 // The try catch is necessary here when the user input the full 165 try {
158 // filename (foo.jpg) and press tab. It is going to update 166 // The try catch is necessary here when the user input the full
159 // the filter causing the following line to fail (cannot cast) 167 // filename (foo.jpg) and press tab. It is going to update
160 // Therefor, we switch back to the allFiles (*) case. 168 // the filter causing the following line to fail (cannot cast)
161 FileMask ft = (FileMask) super.getFileFilter(); 169 // Therefor, we switch back to the allFiles (*) case.
162 //get the extension from the Filter 170 FileMask ft = (FileMask) super.getFileFilter();
163 extensionCombo = ft.getExtensionFromFilter(); 171 //get the extension from the Filter
164 if (extensionCombo == null) { extensionCombo = allFiles; } 172 extensionCombo = ft.getExtensionFromFilter();
165 } catch (java.lang.ClassCastException e) { 173 if (extensionCombo == null) { extensionCombo = allFiles; }
166 extensionCombo = allFiles; 174 } catch (java.lang.ClassCastException e) {
167 } 175 extensionCombo = allFiles;
168 176 }
169 if (extensionCombo.equals(allFiles)) { 177
170 exportManager(); 178 if (extensionCombo.equals(allFiles)) {
171 } else if (extensionCombo.equals(emf) || extensionCombo.equals(eps) || extensionCombo.equals(fig) 179 exportManager();
172 || extensionCombo.equals(pdf) || extensionCombo.equals(svg)) { 180 } else if (extensionCombo.equals(emf) || extensionCombo.equals(eps) || extensionCombo.equals(fig)
173 vectorialExport(extensionCombo); 181 || extensionCombo.equals(pdf) || extensionCombo.equals(svg)) {
174 182 vectorialExport(extensionCombo);
175 } else { 183
176 bitmapExport(extensionCombo); 184 } else {
177 } 185 bitmapExport(extensionCombo);
178 } else ; // no file chosen 186 }
179 187 } else ; // no file chosen
180 } 188 }
181 189
182 190 /**
183 /** 191 * Return the file extension
184 * Return the file extension 192 * @param fileName Name of the file
185 * @param fileName Name of the file 193 * @return the extension
186 * @return the extension 194 */
187 */ 195 public String getExtension(String fileName) {
188 public String getExtension(String fileName) { 196 if (fileName != null) {
189 if (fileName != null) { 197 int i = fileName.lastIndexOf('.');
190 int i = fileName.lastIndexOf('.'); 198 if (i > 0 && i < fileName.length() - 1) {
191 if (i > 0 && i < fileName.length() - 1) { 199 return fileName.substring(i + 1).toLowerCase();
192 return fileName.substring(i + 1).toLowerCase(); 200 }
193 } 201 }
194 } 202 return null;
195 return null; 203 }
196 } 204
197 205 /**
198 /** 206 * Manage the export (bitmap/vectorial format) and export errors
199 * Manage the export (bitmap/vectorial format) and export errors 207 */
200 */ 208 public void exportManager() {
201 public void exportManager() { 209 //get the extension of the fileName chosen by the user (can be 'null')
202 210 String userExtension = getExtension(this.exportName);
203 //get the extension of the fileName chosen by the user (can be 'null') 211
204 String userExtension = getExtension(this.exportName); 212 if (userExtension == null) {
205 213 //fileName without extension + "by extension (.*)" selected
206 if (userExtension == null) { 214 JOptionPane.showMessageDialog(
207 //fileName without extension + "by extension (.*)" selected 215 this, Messages.gettext("Please specify a file format"),
208 JOptionPane.showMessageDialog( 216 Messages.gettext("Error on export"), JOptionPane.ERROR_MESSAGE);
209 this, Messages.gettext("Please specify a file format"), 217 return;
210 Messages.gettext("Error on export"), JOptionPane.ERROR_MESSAGE); 218 } else if (userExtension.equals(bmp)) {
211 return; 219 bitmapExport(userExtension);
212 } else if (userExtension.equals(bmp)) { 220
213 bitmapExport(userExtension); 221 } else if (userExtension.equals(gif)) {
214 222 bitmapExport(userExtension);
215 } else if (userExtension.equals(gif)) { 223
216 bitmapExport(userExtension); 224 } else if (userExtension.equals(jpg[0]) || userExtension.equals(jpg[1])) {
217 225 bitmapExport(userExtension);
218 } else if (userExtension.equals(jpg[0]) || userExtension.equals(jpg[1])) { 226
219 bitmapExport(userExtension); 227 } else if (userExtension.equals(png)) {
220 228 bitmapExport(userExtension);
221 } else if (userExtension.equals(png)) { 229
222 bitmapExport(userExtension); 230 } else if (userExtension.equals(ppm)) {
223 231 bitmapExport(userExtension);
224 } else if (userExtension.equals(ppm)) { 232
225 bitmapExport(userExtension); 233 } else if (userExtension.equals(emf)) {
226 234 vectorialExport(userExtension);
227 } else if (userExtension.equals(emf)) { 235
228 vectorialExport(userExtension); 236 } else if (userExtension.equals(eps)) {
229 237 vectorialExport(userExtension);
230 } else if (userExtension.equals(eps)) { 238
231 vectorialExport(userExtension); 239 } else if (userExtension.equals(fig)) {
232 240 vectorialExport(userExtension);
233 } else if (userExtension.equals(fig)) { 241
234 vectorialExport(userExtension); 242 } else if (userExtension.equals(pdf)) {
235 243 vectorialExport(userExtension);
236 } else if (userExtension.equals(pdf)) { 244
237 vectorialExport(userExtension); 245 } else if (userExtension.equals(svg)) {
238 246 vectorialExport(userExtension);
239 } else if (userExtension.equals(svg)) { 247
240 vectorialExport(userExtension); 248 } else {
241 249 //fileName with a wrong extension + "by extension (.*)" selected
242 } else { 250 JOptionPane.showMessageDialog(
243 //fileName with a wrong extension + "by extension (.*)" selected 251 this, Messages.gettext("Unrecognized extension '")
244 JOptionPane.showMessageDialog( 252 + userExtension + Messages.gettext("'.\n Please specify a valid file format."),
245 this, Messages.gettext("Unrecognized extension '") 253 Messages.gettext("Error on export"), JOptionPane.ERROR_MESSAGE);
246 + userExtension + Messages.gettext("'.\n Please specify a valid file format."), 254 return;
247 Messages.gettext("Error on export"), JOptionPane.ERROR_MESSAGE); 255 }
248 return; 256 }
249 } 257
250 } 258 /**
251 259 * Export an bitmap file
252 /** 260 * @param userExtension extension caught by the user
253 * Export an bitmap file 261 */
254 * @param userExtension extension caught by the user 262 public void bitmapExport(String userExtension) {
255 */ 263 ExportData exportData = new ExportData(figureId, this.exportName, userExtension, null);
256 public void bitmapExport(String userExtension) { 264
257 ExportData exportData = new ExportData(figureId, this.exportName, userExtension, null); 265 String actualFilename = exportData.getExportName();
258 266 if (this.getExtension(actualFilename) == null) {
259 String actualFilename = exportData.getExportName(); 267 // Could not get the extension from the user input
260 if (this.getExtension(actualFilename) == null) { 268 // take the one from the list
261 // Could not get the extension from the user input 269 actualFilename += "." + userExtension;
262 // take the one from the list 270 }
263 actualFilename += "." + userExtension; 271
264 } 272 //the export instruction for the selected format
265 273 String exportcmd = "xs2" + exportData.getExportExtension()
266 //the export instruction for the selected format 274 + "(" + figureId + ", '" + actualFilename + "');";
267 String exportcmd = "xs2" + exportData.getExportExtension() 275 InterpreterManagement.putCommandInScilabQueue(exportcmd);
268 + "(" + figureId + ", '" + actualFilename + "');"; 276 }
269 InterpreterManagement.putCommandInScilabQueue(exportcmd);
270 }
271
272 /**
273 * Export an bitmap file
274 * @param userExtension extension caught by the user
275 */
276 public void vectorialExport(String userExtension) {
277 ExportData exportData = new ExportData(figureId, this.exportName, userExtension, null);
278 ExportOptionWindow exportOptionWindow = new ExportOptionWindow(exportData);
279 exportOptionWindow.displayOptionWindow();
280 exportOptionWindow.landscapePortraitOption();
281 }
282 277
278 /**
279 * Export an bitmap file
280 * @param userExtension extension caught by the user
281 */
282 public void vectorialExport(String userExtension) {
283 Tab parentTab = ((ScilabRendererProperties) FigureMapper.getCorrespondingFigure(figureId).getRendererProperties()).getParentTab();
284 ExportData exportData = new ExportData(figureId, this.exportName, userExtension, null);
285 ExportOptionWindow exportOptionWindow = new ExportOptionWindow(exportData);
286 exportOptionWindow.displayOptionWindow(parentTab);
287 exportOptionWindow.landscapePortraitOption();
288 }
283} 289}