Author: pwang
Date: 2011-07-28 13:57:00 -0700 (Thu, 28 Jul 2011)
New Revision: 26319

Modified:
   
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
Log:
Use provideGUI instead of Tunable to get input from user

Modified: 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
===================================================================
--- 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
        2011-07-28 20:50:53 UTC (rev 26318)
+++ 
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/write/graphics/BitmapWriter.java
        2011-07-28 20:57:00 UTC (rev 26319)
@@ -10,16 +10,19 @@
 import java.util.Set;
 
 import javax.imageio.ImageIO;
+import javax.swing.JPanel;
 
 import org.cytoscape.io.write.CyWriter;
 import org.cytoscape.view.presentation.RenderingEngine;
 import org.cytoscape.work.AbstractTask;
+import org.cytoscape.work.ProvidesGUI;
 import org.cytoscape.work.TaskMonitor;
 import org.cytoscape.work.Tunable;
 import org.cytoscape.work.util.BoundedDouble;
 import org.cytoscape.work.util.BoundedInteger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.cytoscape.io.internal.ui.ExportBitmapOptionsPanel;
 
 /**
  */
@@ -29,36 +32,50 @@
        
        private static final int MAX_SIZE = 50000;
 
-       @Tunable(description = "Image scale")
-       public BoundedDouble scaleFactor;
+       private ExportBitmapOptionsPanel exportBitmapOptionsPanel = null;
+
+       //@Tunable(description = "Image scale")
+       //public BoundedDouble scaleFactor;
        
-       @Tunable(description = "Original Width (px)")
-       public BoundedInteger width;
+       //@Tunable(description = "Original Width (px)")
+       //public BoundedInteger width;
        
-       @Tunable(description = "Original Height (px)")
-       public BoundedInteger height;
+       //@Tunable(description = "Original Height (px)")
+       //public BoundedInteger height;
 
        private final OutputStream outStream;
        private final RenderingEngine<?> re;
        private String extension = null;
+       private int w, h; 
 
        public BitmapWriter(final RenderingEngine<?> re, OutputStream outStream,
                        Set<String> extensions) {
                this.re = re;
                this.outStream = outStream;
                setExtension(extensions);
-               scaleFactor = new BoundedDouble(0.0, 1.0, 50.0, false, false);
                
-               final int w = (int) (re.getViewModel()
+               w = (int) (re.getViewModel()
                                
.getVisualProperty(NETWORK_WIDTH).doubleValue());
-               final int h = (int) (re.getViewModel()
+               h = (int) (re.getViewModel()
                                
.getVisualProperty(NETWORK_HEIGHT).doubleValue());
-               
-               width = new BoundedInteger(1, w, MAX_SIZE, false, false);
-               height = new BoundedInteger(1, h, MAX_SIZE, false, false);
        }
+       
+       
+       @ProvidesGUI
+       public JPanel getGUI() {                
+               if (exportBitmapOptionsPanel == null) {
+                       try {
+                               this.exportBitmapOptionsPanel = 
+                                       new ExportBitmapOptionsPanel(w, h);
+                       } catch (Exception e) {
+                               throw new IllegalStateException("Could not 
initialize BitmapWriterPanel.", e);
+                       }
+               }
 
+               return exportBitmapOptionsPanel;
+       }
        
+       
        private void setExtension(Set<String> extensions) {
 
                for (String format : ImageIO.getWriterFormatNames()) {
@@ -77,12 +94,16 @@
        @Override
        public void run(TaskMonitor tm) throws Exception {
                logger.debug("Bitmap image rendering start.");
-               
+                               
                // Extract size
-               final double scale = scaleFactor.getValue().doubleValue();
-               final int finalW = 
((Number)(width.getValue()*scale)).intValue();
-               final int finalH = 
((Number)(height.getValue()*scale)).intValue();
+               //final double scale = scaleFactor.getValue().doubleValue();
+               //final int finalW = 
((Number)(width.getValue()*scale)).intValue();
+               //final int finalH = 
((Number)(height.getValue()*scale)).intValue();
 
+               final double scale =exportBitmapOptionsPanel.getZoom();
+               final int finalW = exportBitmapOptionsPanel.getWidthPixels();
+               final int finalH = exportBitmapOptionsPanel.getHeightPixels();
+               
                final BufferedImage image = new BufferedImage(finalW, finalH, 
BufferedImage.TYPE_INT_RGB);
                Graphics2D g = (Graphics2D) image.getGraphics();
                g.scale(scale, scale);
@@ -96,5 +117,5 @@
                }
                
                logger.debug("Bitmap image rendering finished.");
-       }
+       }       
 }

-- 
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