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
2e07f581
Commit
2e07f581
authored
10 years ago
by
Tim Molter
Browse files
Options
Downloads
Patches
Plain Diff
improved FileFilter code as Benedikt Bünz's PR #85 demonstrated
parent
13bf0bd8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
+22
-75
22 additions, 75 deletions
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
with
22 additions
and
75 deletions
xchart/src/main/java/com/xeiam/xchart/XChartPanel.java
+
22
−
75
View file @
2e07f581
...
@@ -113,11 +113,11 @@ public class XChartPanel extends JPanel {
...
@@ -113,11 +113,11 @@ public class XChartPanel extends JPanel {
private
void
showSaveAsDialog
()
{
private
void
showSaveAsDialog
()
{
JFileChooser
fileChooser
=
new
JFileChooser
();
JFileChooser
fileChooser
=
new
JFileChooser
();
fileChooser
.
addChoosableFileFilter
(
new
JPG
SaveFilter
());
fileChooser
.
addChoosableFileFilter
(
new
Suffix
SaveFilter
(
"jpg"
));
FileFilter
pngFileFilter
=
new
PNG
SaveFilter
();
FileFilter
pngFileFilter
=
new
Suffix
SaveFilter
(
"png"
);
fileChooser
.
addChoosableFileFilter
(
pngFileFilter
);
fileChooser
.
addChoosableFileFilter
(
pngFileFilter
);
fileChooser
.
addChoosableFileFilter
(
new
BMP
SaveFilter
());
fileChooser
.
addChoosableFileFilter
(
new
Suffix
SaveFilter
(
"bmp"
));
fileChooser
.
addChoosableFileFilter
(
new
GIF
SaveFilter
());
fileChooser
.
addChoosableFileFilter
(
new
Suffix
SaveFilter
(
"gif"
));
fileChooser
.
setAcceptAllFileFilterUsed
(
false
);
fileChooser
.
setAcceptAllFileFilterUsed
(
false
);
fileChooser
.
setFileFilter
(
pngFileFilter
);
fileChooser
.
setFileFilter
(
pngFileFilter
);
...
@@ -130,7 +130,8 @@ public class XChartPanel extends JPanel {
...
@@ -130,7 +130,8 @@ public class XChartPanel extends JPanel {
if
(
fileChooser
.
getFileFilter
()
==
null
)
{
if
(
fileChooser
.
getFileFilter
()
==
null
)
{
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.jpg,*.JPG"
))
{
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.jpg,*.JPG"
))
{
BitmapEncoder
.
saveJPGWithQuality
(
chart
,
BitmapEncoder
.
addFileExtension
(
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
JPG
),
1.0f
);
BitmapEncoder
.
saveJPGWithQuality
(
chart
,
BitmapEncoder
.
addFileExtension
(
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
JPG
),
1.0f
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.png,*.PNG"
))
{
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.png,*.PNG"
))
{
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
BitmapEncoder
.
saveBitmap
(
chart
,
theFileToSave
.
getCanonicalPath
().
toString
(),
BitmapFormat
.
PNG
);
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.bmp,*.BMP"
))
{
}
else
if
(
fileChooser
.
getFileFilter
().
getDescription
().
equals
(
"*.bmp,*.BMP"
))
{
...
@@ -146,92 +147,38 @@ public class XChartPanel extends JPanel {
...
@@ -146,92 +147,38 @@ public class XChartPanel extends JPanel {
}
}
}
}
private
class
JPGSaveFilter
extends
FileFilter
{
/**
* File filter based on the suffix of a file. This file filter accepts all files that end with .suffix or the capitalized suffix.
@Override
*
public
boolean
accept
(
File
f
)
{
* @author Benedikt Bünz
*/
if
(
f
.
isDirectory
())
{
private
class
SuffixSaveFilter
extends
FileFilter
{
return
true
;
private
final
String
suffix
;
}
String
s
=
f
.
getName
();
return
s
.
endsWith
(
".jpg"
)
||
s
.
endsWith
(
".JPG"
);
}
@Override
public
String
getDescription
()
{
return
"*.jpg,*.JPG"
;
}
}
private
class
BMPSaveFilter
extends
FileFilter
{
@Override
public
boolean
accept
(
File
f
)
{
if
(
f
.
isDirectory
())
{
return
true
;
}
String
s
=
f
.
getName
();
return
s
.
endsWith
(
".bmp"
)
||
s
.
endsWith
(
".BMP"
);
}
@Override
public
String
getDescription
()
{
return
"*.bmp,*.BMP"
;
}
}
private
class
GIFSaveFilter
extends
FileFilter
{
@Override
public
boolean
accept
(
File
f
)
{
if
(
f
.
isDirectory
())
{
return
true
;
}
String
s
=
f
.
getName
();
return
s
.
endsWith
(
".gif"
)
||
s
.
endsWith
(
".GIF"
);
}
@Override
public
String
getDescription
()
{
return
"*.gif,*.GIF"
;
}
/**
* @param suffix This file filter accepts all files that end with .suffix or the capitalized suffix.
*/
public
SuffixSaveFilter
(
String
suffix
)
{
this
.
suffix
=
suffix
;
}
}
private
class
PNGSaveFilter
extends
FileFilter
{
@Override
@Override
public
boolean
accept
(
File
f
)
{
public
boolean
accept
(
File
f
)
{
if
(
f
.
isDirectory
())
{
if
(
f
.
isDirectory
())
{
return
tru
e
;
return
fals
e
;
}
}
String
s
=
f
.
getName
();
String
s
=
f
.
getName
();
return
s
.
endsWith
(
".
png"
)
||
s
.
endsWith
(
".
PNG"
);
return
s
.
endsWith
(
".
"
+
suffix
)
||
s
.
endsWith
(
".
"
+
suffix
.
toUpperCase
()
);
}
}
@Override
@Override
public
String
getDescription
()
{
public
String
getDescription
()
{
return
"*.
png,*.PNG"
;
return
"*.
"
+
suffix
+
",*."
+
suffix
.
toUpperCase
()
;
}
}
}
}
private
class
PopUpMenuClickListener
extends
MouseAdapter
{
private
class
PopUpMenuClickListener
extends
MouseAdapter
{
...
...
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