summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/visualization/savedialog/SVGSaveDialog.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/visualization/savedialog/SVGSaveDialog.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/visualization/savedialog/SVGSaveDialog.java79
1 files changed, 31 insertions, 48 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/visualization/savedialog/SVGSaveDialog.java b/src/de/lmu/ifi/dbs/elki/visualization/savedialog/SVGSaveDialog.java
index f895c46e..8f56c562 100644
--- a/src/de/lmu/ifi/dbs/elki/visualization/savedialog/SVGSaveDialog.java
+++ b/src/de/lmu/ifi/dbs/elki/visualization/savedialog/SVGSaveDialog.java
@@ -57,10 +57,10 @@ import de.lmu.ifi.dbs.elki.visualization.svg.SVGPlot;
*/
public class SVGSaveDialog {
/** The default title. "Save as ...". */
- public final static String DEFAULT_TITLE = "Save as ...";
+ public static final String DEFAULT_TITLE = "Save as ...";
/** Static logger reference */
- private final static Logging logger = Logging.getLogger(SVGSaveDialog.class);
+ private static final Logging LOG = Logging.getLogger(SVGSaveDialog.class);
/** Automagic file format */
final static String automagic_format = "automatic";
@@ -73,11 +73,10 @@ public class SVGSaveDialog {
static {
// FOP installed?
- if(SVGPlot.hasFOPInstalled()) {
+ if (SVGPlot.hasFOPInstalled()) {
formats = new String[] { "svg", "png", "jpeg", "jpg", "pdf", "ps", "eps" };
visibleformats = new String[] { automagic_format, "svg", "png", "jpeg", "pdf", "ps", "eps" };
- }
- else {
+ } else {
formats = new String[] { "svg", "png", "jpeg", "jpg" };
visibleformats = new String[] { automagic_format, "svg", "png", "jpeg" };
}
@@ -95,7 +94,7 @@ public class SVGSaveDialog {
double quality = 1.0;
int ret = -1;
- JFileChooser fc = new JFileChooser();
+ JFileChooser fc = new JFileChooser(new File("."));
fc.setDialogTitle(DEFAULT_TITLE);
// fc.setFileFilter(new ImageFilter());
SaveOptionsPanel optionsPanel = new SaveOptionsPanel(fc, width, height);
@@ -103,70 +102,54 @@ public class SVGSaveDialog {
ret = fc.showSaveDialog(null);
fc.setDialogTitle("Saving... Please wait.");
- if(ret == JFileChooser.APPROVE_OPTION) {
+ if (ret == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
String format = optionsPanel.getSelectedFormat();
- if(format == null || format == automagic_format) {
+ if (format == null || automagic_format.equals(format)) {
format = guessFormat(file.getName());
}
try {
- if(format == null) {
+ if (format == null) {
showError(fc, "Error saving image.", "File format not recognized.");
- }
- else if(format.equals("jpeg") || format.equals("jpg")) {
+ } else if ("jpeg".equals(format) || "jpg".equals(format)) {
quality = optionsPanel.getJPEGQuality();
plot.saveAsJPEG(file, width, height, quality);
- }
- else if(format.equals("png")) {
+ } else if ("png".equals(format)) {
plot.saveAsPNG(file, width, height);
- }
- else if(format.equals("ps")) {
+ } else if ("ps".equals(format)) {
plot.saveAsPS(file);
- }
- else if(format.equals("eps")) {
+ } else if ("eps".equals(format)) {
plot.saveAsEPS(file);
- }
- else if(format.equals("pdf")) {
+ } else if ("pdf".equals(format)) {
plot.saveAsPDF(file);
- }
- else if(format.equals("svg")) {
+ } else if ("svg".equals(format)) {
plot.saveAsSVG(file);
- }
- else {
+ } else {
showError(fc, "Error saving image.", "Unsupported format: " + format);
}
- }
- catch(java.lang.IncompatibleClassChangeError e) {
+ } catch (java.lang.IncompatibleClassChangeError e) {
showError(fc, "Error saving image.", "It seems that your Java version is incompatible with this version of Batik and Jpeg writing. Sorry.");
- }
- catch(ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
showError(fc, "Error saving image.", "A class was not found when saving this image. Maybe installing Apache FOP will help (for PDF, PS and EPS output).\n" + e.toString());
- }
- catch(IOException e) {
- logger.exception(e);
+ } catch (IOException e) {
+ LOG.exception(e);
showError(fc, "Error saving image.", e.toString());
- }
- catch(TranscoderException e) {
- logger.exception(e);
+ } catch (TranscoderException e) {
+ LOG.exception(e);
showError(fc, "Error saving image.", e.toString());
- }
- catch(TransformerFactoryConfigurationError e) {
- logger.exception(e);
+ } catch (TransformerFactoryConfigurationError e) {
+ LOG.exception(e);
showError(fc, "Error saving image.", e.toString());
- }
- catch(TransformerException e) {
- logger.exception(e);
+ } catch (TransformerException e) {
+ LOG.exception(e);
showError(fc, "Error saving image.", e.toString());
- }
- catch(Exception e) {
- logger.exception(e);
+ } catch (Exception e) {
+ LOG.exception(e);
showError(fc, "Error saving image.", e.toString());
}
- }
- else if(ret == JFileChooser.ERROR_OPTION) {
+ } else if (ret == JFileChooser.ERROR_OPTION) {
showError(fc, "Error in file dialog.", "Unknown Error.");
- }
- else if(ret == JFileChooser.CANCEL_OPTION) {
+ } else if (ret == JFileChooser.CANCEL_OPTION) {
// do nothing - except return result
}
return ret;
@@ -180,8 +163,8 @@ public class SVGSaveDialog {
*/
public static String guessFormat(String name) {
String ext = FileUtil.getFilenameExtension(name);
- for(String format : formats) {
- if(format.equals(ext)) {
+ for (String format : formats) {
+ if (format.equals(ext)) {
return ext;
}
}