woolfel 2004/06/17 05:38:07
Modified: src/core/org/apache/jmeter/gui/action SaveGraphics.java
Log:
updated the class to create a JFileChooser with the right filters
peter
Revision Changes Path
1.3 +93 -88
jakarta-jmeter/src/core/org/apache/jmeter/gui/action/SaveGraphics.java
Index: SaveGraphics.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/SaveGraphics.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SaveGraphics.java 16 Jun 2004 20:53:30 -0000 1.2
+++ SaveGraphics.java 17 Jun 2004 12:38:06 -0000 1.3
@@ -42,93 +42,98 @@
* PNG file if no extension is provided. If either .png or .tif is in the
* filename, it will call SaveGraphicsService to save in the format.
*/
-public class SaveGraphics implements Command
-{
- transient private static Logger log = LoggingManager.getLoggerForClass();
- public final static String SAVE_GRAPHICS = "save_graphics";
-
- private static Set commands = new HashSet();
- static
- {
- commands.add(SAVE_GRAPHICS);
- }
-
- /**
- * Constructor for the Save object.
- */
- public SaveGraphics()
- {
- }
-
- /**
- * Gets the ActionNames attribute of the Save object.
- *
- * @return the ActionNames value
- */
- public Set getActionNames()
- {
- return commands;
- }
-
- public void doAction(ActionEvent e) throws IllegalUserActionException
- {
- JMeterGUIComponent component = null;
- JComponent comp = null;
- if (!commands.contains(e.getActionCommand())) { throw new
IllegalUserActionException(
- "Invalid user command:" + e.getActionCommand()); }
- if (e.getActionCommand().equals(SAVE_GRAPHICS))
- {
- component = GuiPackage.getInstance().getCurrentGui();
- // System.out.println("visualizer: " +
- // component.getClass().getName());
- // get the JComponent from the visualizer
- if (component instanceof Printable)
- {
- comp = ((Printable) component).getPrintableComponent();
-
- String filename;
- JFileChooser chooser = FileDialoger.promptToSaveFile(GuiPackage
- .getInstance().getTreeListener().getCurrentNode().getName());
- if (chooser == null) { return; }
- // Get the string given from the choose and check
- // the file extension.
- filename = chooser.getSelectedFile().getAbsolutePath();
- if (filename != null)
- {
- SaveGraphicsService save = new SaveGraphicsService();
- String ext = filename.substring(filename.length() - 4);
- String name = filename.substring(0, filename.length() - 4);
- if (ext.equals(SaveGraphicsService.PNG_EXTENSION))
- {
- save.saveJComponent(name, SaveGraphicsService.PNG, comp);
- }
- else if (ext.equals(SaveGraphicsService.TIFF_EXTENSION))
- {
- save.saveJComponent(name, SaveGraphicsService.TIFF, comp);
- }
- else
- {
- save.saveJComponent(filename, SaveGraphicsService.PNG, comp);
- }
- }
- }
- }
- }
-
- public static class Test extends junit.framework.TestCase
- {
- SaveGraphics save;
-
- public Test(String name)
- {
- super(name);
- }
-
- public void setUp()
- {
- save = new SaveGraphics();
- }
+public class SaveGraphics implements Command {
+ transient private static Logger log = LoggingManager.getLoggerForClass();
+ public final static String SAVE_GRAPHICS = "save_graphics";
+
+ private static Set commands = new HashSet();
+ static {
+ commands.add(SAVE_GRAPHICS);
+ }
+ public static String[] extensions =
+ {
+ SaveGraphicsService.TIFF_EXTENSION,
+ SaveGraphicsService.PNG_EXTENSION};
+
+ /**
+ * Constructor for the Save object.
+ */
+ public SaveGraphics() {
+ }
+
+ /**
+ * Gets the ActionNames attribute of the Save object.
+ *
+ * @return the ActionNames value
+ */
+ public Set getActionNames() {
+ return commands;
+ }
+
+ public void doAction(ActionEvent e) throws IllegalUserActionException {
+ JMeterGUIComponent component = null;
+ JComponent comp = null;
+ if (!commands.contains(e.getActionCommand())) {
+ throw new IllegalUserActionException(
+ "Invalid user command:" + e.getActionCommand());
+ }
+ if (e.getActionCommand().equals(SAVE_GRAPHICS)) {
+ component = GuiPackage.getInstance().getCurrentGui();
+ // get the JComponent from the visualizer
+ if (component instanceof Printable) {
+ comp = ((Printable) component).getPrintableComponent();
+
+ String filename;
+ JFileChooser chooser =
+ FileDialoger.promptToSaveFile(
+ GuiPackage
+ .getInstance()
+ .getTreeListener()
+ .getCurrentNode()
+ .getName(),extensions);
+ if (chooser == null) {
+ return;
+ }
+ // Get the string given from the choose and check
+ // the file extension.
+ filename = chooser.getSelectedFile().getAbsolutePath();
+ if (filename != null) {
+ SaveGraphicsService save = new
SaveGraphicsService();
+ String ext =
filename.substring(filename.length() - 4);
+ String name = filename.substring(0,
filename.length() - 4);
+ if
(ext.equals(SaveGraphicsService.PNG_EXTENSION)) {
+ save.saveJComponent(
+ name,
+ SaveGraphicsService.PNG,
+ comp);
+ } else if (
+
ext.equals(SaveGraphicsService.TIFF_EXTENSION)) {
+ save.saveJComponent(
+ name,
+ SaveGraphicsService.TIFF,
+ comp);
+ } else {
+ save.saveJComponent(
+ filename,
+ SaveGraphicsService.PNG,
+ comp);
+ }
+ }
+ }
+ }
+ }
+
+ public static class Test extends junit.framework.TestCase {
+ SaveGraphics save;
+
+ public Test(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ save = new SaveGraphics();
+ }
- }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]