Author: kono
Date: 2010-07-16 15:54:38 -0700 (Fri, 16 Jul 2010)
New Revision: 20954

Modified:
   cytoscape/trunk/src/cytoscape/actions/ExportAsGraphicsAction.java
   cytoscape/trunk/src/cytoscape/dialogs/ExportAsGraphicsFileChooser.java
   cytoscape/trunk/src/cytoscape/dialogs/ExportBitmapOptionsDialog.java
   cytoscape/trunk/src/cytoscape/util/CyFileFilter.java
   cytoscape/trunk/src/cytoscape/util/export/BitmapExporter.java
   cytoscape/trunk/src/cytoscape/view/CyMenus.java
Log:
Bug ID 0002281: "Image Export UI should provide default file name" was fixed.  
Also, for Camera icon, PNG will be selected as default format.

Modified: cytoscape/trunk/src/cytoscape/actions/ExportAsGraphicsAction.java
===================================================================
--- cytoscape/trunk/src/cytoscape/actions/ExportAsGraphicsAction.java   
2010-07-16 22:13:06 UTC (rev 20953)
+++ cytoscape/trunk/src/cytoscape/actions/ExportAsGraphicsAction.java   
2010-07-16 22:54:38 UTC (rev 20954)
@@ -6,6 +6,7 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Set;
 
 import javax.swing.JOptionPane;
 import javax.swing.event.MenuEvent;
@@ -51,16 +52,35 @@
 
        private static final String TITLE = "Current Network View as Graphics";
 
-       public static ExportFilter[] getFilters() {
-               return FILTERS;
+       private ExportAsGraphicsFileChooser chooser;
+       private String defaultFileExt;
+
+       public ExportAsGraphicsAction() {
+               this("PDF");
        }
        
-       public ExportAsGraphicsAction() {
+       
+       public ExportAsGraphicsAction(final String fileExtension) {
                super(TITLE + "...");
                setPreferredMenu("File.Export");
                setAcceleratorCombo(KeyEvent.VK_P, ActionEvent.CTRL_MASK
                                | ActionEvent.SHIFT_MASK);
+               
+               this.defaultFileExt = fileExtension;
        }
+       
+       
+       private ExportFilter getFilter(final String ext) {
+               for(ExportFilter filter: FILTERS) {
+                       final Set<String> exts = filter.getExtensionSet();
+                       for(String ex: exts) {
+                               if(ex.equalsIgnoreCase(ext))
+                                       return filter;
+                       }
+               }
+               
+               return null;
+       }
 
        
        public void menuSelected(MenuEvent e) {
@@ -76,12 +96,16 @@
                        return;
                }
 
-               final ExportAsGraphicsFileChooser chooser = new 
ExportAsGraphicsFileChooser(FILTERS, JPG_FILTER);
+               final ExportFilter filter = getFilter(defaultFileExt);
+               if(filter == null)
+                       chooser = new ExportAsGraphicsFileChooser(FILTERS, 
PDF_FILTER);
+               else
+                       chooser = new ExportAsGraphicsFileChooser(FILTERS, 
filter);
+               
 
                final ActionListener listener = new ActionListener() {
                        public void actionPerformed(ActionEvent event) {
-                               ExportFilter filter = (ExportFilter) chooser
-                                               .getSelectedFormat();
+                               ExportFilter filter = (ExportFilter) 
chooser.getSelectedFormat();
                                
filter.setExportTextAsFont(chooser.getExportTextAsFont());
 
                                File file = chooser.getSelectedFile();
@@ -200,22 +224,24 @@
 }
 
 class BitmapExportFilter extends ExportFilter {
-       private String extension;
-
+       
+       private final String extension;
+       
        public BitmapExportFilter(String extension, String description) {
                super(extension, description);
                this.extension = extension;
        }
 
        public void export(final CyNetworkView view, final FileOutputStream 
stream) {
+               
+               
                final InternalFrameComponent ifc = Cytoscape.getDesktop()
                                
.getNetworkViewManager().getInternalFrameComponent(view);
-               final ExportBitmapOptionsDialog dialog = new 
ExportBitmapOptionsDialog(
-                               ifc.getWidth(), ifc.getHeight());
+               final ExportBitmapOptionsDialog dialog = new 
ExportBitmapOptionsDialog(ifc.getWidth(), ifc.getHeight());
+               
                ActionListener listener = new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
-                               BitmapExporter exporter = new 
BitmapExporter(extension,
-                                               dialog.getZoom());
+                               BitmapExporter exporter = new 
BitmapExporter(extension, dialog.getZoom());
                                dialog.dispose();
                                ExportTask.run("Exporting to " + extension, 
exporter, view,
                                                stream);

Modified: cytoscape/trunk/src/cytoscape/dialogs/ExportAsGraphicsFileChooser.java
===================================================================
--- cytoscape/trunk/src/cytoscape/dialogs/ExportAsGraphicsFileChooser.java      
2010-07-16 22:13:06 UTC (rev 20953)
+++ cytoscape/trunk/src/cytoscape/dialogs/ExportAsGraphicsFileChooser.java      
2010-07-16 22:54:38 UTC (rev 20954)
@@ -23,6 +23,7 @@
 import cytoscape.CytoscapeInit;
 import cytoscape.util.CyFileFilter;
 import cytoscape.util.FileUtil;
+import cytoscape.view.CyNetworkView;
 import cytoscape.visual.VisualStyle;
 import cytoscape.visual.calculators.Calculator;
 
@@ -34,6 +35,8 @@
        
        private static final long serialVersionUID = 4895622023575071394L;
        
+       private final String SEPARATOR = System.getProperty("file.separator");
+       
        private static final Dimension DIALOG_SIZE = new Dimension(650, 165);
 
        private File selectedFile;
@@ -41,6 +44,7 @@
 
        private boolean exportTextAsFont = 
!(Boolean.getBoolean(CytoscapeInit.getProperties().getProperty("exportTextAsShape")));
        
+       @Deprecated
        public ExportAsGraphicsFileChooser(final CyFileFilter[] formats) {
                this(formats, null);
        }
@@ -75,10 +79,26 @@
                formatComboBox.addItemListener(new FormatItemListener());
                
                removeFile();
+               
+               setDefaultFileName();
 
                setLocationRelativeTo(Cytoscape.getDesktop());
                pack();
+               okButton.requestFocusInWindow();
        }
+       
+       
+       private void setDefaultFileName() {
+               final File recentDir = CytoscapeInit.getMRUD();
+               final CyNetworkView view = Cytoscape.getCurrentNetworkView();
+               
+               final String title = view.getTitle();
+               
+               this.selectedFile = new File(recentDir.toString() + SEPARATOR + 
title);
+               this.updateExtension();
+               this.filePathField.setText(selectedFile.toString());
+       }
+       
 
        // This is a work-around, because ItemEvent is received twice in 
MyItemListener.
        private static int eventCount =0;
@@ -99,12 +119,11 @@
                                        chooseFileButton.setEnabled(false);
                        }
                        else {
-                               if (selectedFile !=null) {
-                                       okButton.setEnabled(true);              
                        
-                               }
-                               else {
+                               if (selectedFile !=null)
+                                       okButton.setEnabled(true);
+                               else
                                        okButton.setEnabled(false);
-                               }
+                               
                                chooseFileButton.setEnabled(true);
                        }
                }               
@@ -180,8 +199,7 @@
        }
 
        
-       protected void assignFile(File file)
-       {
+       protected void assignFile(File file) {
                selectedFile = file;
                filePathField.setText(selectedFile.getPath());
                okButton.setEnabled(true);
@@ -190,15 +208,15 @@
                }
        }
 
-       protected void removeFile()
-       {
+       
+       protected void removeFile() {
                selectedFile = null;
                filePathField.setText("");
                okButton.setEnabled(false);
        }
 
-       protected void updateExtension()
-       {
+       
+       private void updateExtension() {
                if (selectedFile == null)
                        return;
 
@@ -220,6 +238,7 @@
                }
        }
 
+       
        public void actionPerformed(ActionEvent e) {
                Object obj = e.getSource();
                if (obj instanceof JButton) {
@@ -231,7 +250,7 @@
                                this.dispose();
                        }
                        else if (btn == chooseFileButton) {
-                               CyFileFilter filter = getSelectedFormat();
+                               final CyFileFilter filter = getSelectedFormat();
                                String extension = "." + (String) 
filter.getExtensionSet().iterator().next();
                                CyFileFilter[] filters = new CyFileFilter[1];
                                filters[0] = filter;
@@ -269,10 +288,12 @@
                }
        }
        
+       
        public boolean getExportTextAsFont() {
                return exportTextAsFont;
        }
        
+       
     /** This method is called from within the constructor to
      * initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is

Modified: cytoscape/trunk/src/cytoscape/dialogs/ExportBitmapOptionsDialog.java
===================================================================
--- cytoscape/trunk/src/cytoscape/dialogs/ExportBitmapOptionsDialog.java        
2010-07-16 22:13:06 UTC (rev 20953)
+++ cytoscape/trunk/src/cytoscape/dialogs/ExportBitmapOptionsDialog.java        
2010-07-16 22:54:38 UTC (rev 20954)
@@ -12,8 +12,9 @@
  * Options dialog for exporting to bitmap images.
  * @author Samad Lotia
  */
-public class ExportBitmapOptionsDialog extends JDialog
-{
+public class ExportBitmapOptionsDialog extends JDialog {
+       
+       private static final long serialVersionUID = 5333484131669731753L;
        private JFormattedTextField zoomField;
        private JFormattedTextField widthInPixelsField;
        private JFormattedTextField heightInPixelsField;
@@ -32,11 +33,12 @@
         * @param imageHeight The image height to be exported
         * @param listener The action will be called when the "OK" button is 
clicked
         */
-       public ExportBitmapOptionsDialog(int imageWidth, int imageHeight)
-       {
+       public ExportBitmapOptionsDialog(int imageWidth, int imageHeight) {
                super(Cytoscape.getDesktop(), "Export Bitmap Options");
+               
                this.originalWidth = imageWidth;
                this.originalHeight = imageHeight;
+               
                setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                Container content = getContentPane();
 
@@ -183,7 +185,7 @@
                c.fill = GridBagConstraints.NONE;
                sizePanel.add(resolutionLabel, c);
 
-               Integer[] resolutions = { new Integer(72), new Integer(100), 
new Integer(150), new Integer(300) };
+               final Integer[] resolutions = { 72, 100, 150, 300, 600 };
                resolutionComboBox = new JComboBox(resolutions);
                resolutionComboBox.addActionListener(zoomListener);
                c.gridx = 1;                    c.gridy = 7;
@@ -224,7 +226,8 @@
                setLocationRelativeTo(Cytoscape.getDesktop());
                pack();
        }
-
+       
+       
        public double getZoom()
        {
                return ((Number) zoomField.getValue()).doubleValue() / 100.0;
@@ -245,9 +248,9 @@
                int newHeight = (int) (newZoom * originalHeight);
                widthInPixelsField.setValue(new Integer(newWidth));
                heightInPixelsField.setValue(new Integer(newHeight));
-               double dpi = ((Number) 
resolutionComboBox.getSelectedItem()).doubleValue();
-               double newWidthInches = newWidth / dpi;
-               double newHeightInches = newHeight / dpi;
+               final double dpi = ((Number) 
resolutionComboBox.getSelectedItem()).doubleValue();
+               final double newWidthInches = newWidth / dpi;
+               final double newHeightInches = newHeight / dpi;
                widthInInchesField.setValue(new Double(newWidthInches));
                heightInInchesField.setValue(new Double(newHeightInches));
        }

Modified: cytoscape/trunk/src/cytoscape/util/CyFileFilter.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/CyFileFilter.java        2010-07-16 
22:13:06 UTC (rev 20953)
+++ cytoscape/trunk/src/cytoscape/util/CyFileFilter.java        2010-07-16 
22:54:38 UTC (rev 20954)
@@ -412,7 +412,7 @@
        /**
         * Returns the Set of file extension names.
         */
-       public Set getExtensionSet() {
+       public Set<String> getExtensionSet() {
                return filters.keySet();
        }
 

Modified: cytoscape/trunk/src/cytoscape/util/export/BitmapExporter.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/export/BitmapExporter.java       
2010-07-16 22:13:06 UTC (rev 20953)
+++ cytoscape/trunk/src/cytoscape/util/export/BitmapExporter.java       
2010-07-16 22:54:38 UTC (rev 20954)
@@ -14,13 +14,12 @@
  * Bitmap exporter by the ImageIO class.
  * @author Samad Lotia
  */
-public class BitmapExporter implements Exporter
-{
+public class BitmapExporter implements Exporter {
+       
        private String extension;
        private double scale;
 
-       public BitmapExporter(String extension, double scale)
-       {
+       public BitmapExporter(String extension, double scale) {
                this.extension = extension;
                this.scale = scale;
 

Modified: cytoscape/trunk/src/cytoscape/view/CyMenus.java
===================================================================
--- cytoscape/trunk/src/cytoscape/view/CyMenus.java     2010-07-16 22:13:06 UTC 
(rev 20953)
+++ cytoscape/trunk/src/cytoscape/view/CyMenus.java     2010-07-16 22:54:38 UTC 
(rev 20954)
@@ -389,7 +389,7 @@
                addAction(new ExportNodeAttributesAction());
                addAction(new ExportEdgeAttributesAction());
                addAction(new ExportVizmapAction());
-               addAction(new ExportAsGraphicsAction());
+               addAction(new ExportAsGraphicsAction("PDF"));
 
                fileMenu.add(new JSeparator());
                addAction(new PrintAction());
@@ -609,7 +609,7 @@
 
                toolBar.addSeparator();
 
-               final ExportAsGraphicsAction eag = new ExportAsGraphicsAction();
+               final ExportAsGraphicsAction eag = new 
ExportAsGraphicsAction("PNG");
                eag.putValue(Action.NAME, null);
                snapshotButton = toolBar.add(eag);
                snapshotButton.setToolTipText("Export current network view as 
graphics");

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to