Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
XChart
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Brady James Garvin
XChart
Commits
13bf0bd8
Commit
13bf0bd8
authored
10 years ago
by
Tim Molter
Browse files
Options
Downloads
Plain Diff
Merge pull request #101 from niklaspolke/nodoublefileextensions
avoid duplicate file extensions
parents
73d5bf1a
5341759f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java
+20
-2
20 additions, 2 deletions
xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
+1
-1
1 addition, 1 deletion
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
with
21 additions
and
3 deletions
xchart/src/main/java/com/xeiam/xchart/BitmapEncoder.java
+
20
−
2
View file @
13bf0bd8
...
...
@@ -53,6 +53,23 @@ public final class BitmapEncoder {
public
enum
BitmapFormat
{
PNG
,
JPG
,
BMP
,
GIF
;
}
/**
* Only adds the extension of the BitmapFormat to the filename if the filename doesn't already have it.
*
* @param fileName
* @param bitmapFormat
* @return filename (if extension already exists), otherwise;: filename + "." + extension
*/
public
static
String
addFileExtension
(
String
fileName
,
BitmapFormat
bitmapFormat
)
{
String
fileNameWithFileExtension
=
fileName
;
final
String
newFileExtension
=
"."
+
bitmapFormat
.
toString
().
toLowerCase
();
if
(
fileName
.
length
()
<=
newFileExtension
.
length
()
||
!
fileName
.
substring
(
fileName
.
length
()-
newFileExtension
.
length
(),
fileName
.
length
()).
equalsIgnoreCase
(
newFileExtension
))
{
fileNameWithFileExtension
=
fileName
+
newFileExtension
;
}
return
fileNameWithFileExtension
;
}
/**
* Save a Chart as an image file
...
...
@@ -66,7 +83,7 @@ public final class BitmapEncoder {
BufferedImage
bufferedImage
=
getBufferedImage
(
chart
);
OutputStream
out
=
new
FileOutputStream
(
fileName
+
"."
+
bitmapFormat
.
toString
().
toLowerCase
(
));
OutputStream
out
=
new
FileOutputStream
(
addFileExtension
(
fileName
,
bitmapFormat
));
ImageIO
.
write
(
bufferedImage
,
bitmapFormat
.
toString
().
toLowerCase
(),
out
);
out
.
close
();
}
...
...
@@ -108,7 +125,7 @@ public final class BitmapEncoder {
setDPI
(
metadata
,
DPI
);
File
file
=
new
File
(
fileName
+
"."
+
bitmapFormat
.
toString
().
toLowerCase
(
));
File
file
=
new
File
(
addFileExtension
(
fileName
,
bitmapFormat
));
FileImageOutputStream
output
=
new
FileImageOutputStream
(
file
);
writer
.
setOutput
(
output
);
IIOImage
image
=
new
IIOImage
(
bufferedImage
,
null
,
metadata
);
...
...
@@ -150,6 +167,7 @@ public final class BitmapEncoder {
*
* @param chart
* @param fileName
* @param bitmapFormat
* @param quality - a float between 0 and 1 (1 = maximum quality)
* @throws FileNotFoundException
* @throws IOException
...
...
This diff is collapsed.
Click to expand it.
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
+
1
−
1
View file @
13bf0bd8
...
...
@@ -130,7 +130,7 @@ public class XChartPanel extends JPanel {
if
(
fileChooser
.
getFileFilter
()
==
null
)
{
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.jpg,*.JPG"
))
{
BitmapEncoder
.
saveJPGWithQuality
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
()
+
".jpg"
,
1.0f
);
BitmapEncoder
.
saveJPGWithQuality
(
chart
,
BitmapEncoder
.
addFileExtension
(
theFileToSave
.
getCanonicalPath
().
toString
()
,
BitmapFormat
.
JPG
)
,
1.0f
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.png,*.PNG"
))
{
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.bmp,*.BMP"
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment