commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1489144 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide: ClusterAlgorithmComparison.java ExampleUtils.java LowDiscrepancyGeneratorComparison.java
Date Mon, 03 Jun 2013 20:12:21 GMT
Author: tn
Date: Mon Jun  3 20:12:20 2013
New Revision: 1489144

URL: http://svn.apache.org/r1489144
Log:
Small improvements to the examples.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusterAlgorithmComparison.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/LowDiscrepancyGeneratorComparison.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusterAlgorithmComparison.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusterAlgorithmComparison.java?rev=1489144&r1=1489143&r2=1489144&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusterAlgorithmComparison.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusterAlgorithmComparison.java
Mon Jun  3 20:12:20 2013
@@ -32,7 +32,6 @@ import java.util.Collections;
 import java.util.List;
 
 import javax.swing.JComponent;
-import javax.swing.JFrame;
 import javax.swing.JLabel;
 
 import org.apache.commons.math3.distribution.NormalDistribution;
@@ -49,6 +48,7 @@ import org.apache.commons.math3.random.R
 import org.apache.commons.math3.random.RandomGenerator;
 import org.apache.commons.math3.random.SobolSequenceGenerator;
 import org.apache.commons.math3.random.Well19937c;
+import org.apache.commons.math3.userguide.ExampleUtils.ExampleFrame;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.util.Pair;
 
@@ -180,10 +180,10 @@ public class ClusterAlgorithmComparison 
     }
     
     @SuppressWarnings("serial")
-    public static class Display extends JFrame {
+    public static class Display extends ExampleFrame {
         
         public Display() {
-            setTitle("Clustering examples");
+            setTitle("Commons-Math: Cluster algorithm comparison");
             setSize(800, 800);
             
             setLayout(new GridBagLayout());
@@ -231,6 +231,7 @@ public class ClusterAlgorithmComparison 
                 c.gridy++;
             }            
         }
+
     }
 
     @SuppressWarnings("serial")

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java?rev=1489144&r1=1489143&r2=1489144&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java
Mon Jun  3 20:12:20 2013
@@ -35,7 +35,23 @@ import javax.swing.SwingUtilities;
 
 public class ExampleUtils {
 
-    public static void showExampleFrame(final JFrame frame) {
+    @SuppressWarnings("serial")
+    public static class ExampleFrame extends JFrame {
+        
+        /**
+         * Returns the main panel which should be printed by the screenshot action.
+         * <p>
+         * By default, it returns the content pane of this frame, but can be overriden
+         * in case the frame has a global scroll pane which would cut off any offscreen content.

+         *
+         * @return the main panel to print
+         */
+        public Component getMainPanel() {
+            return getContentPane();
+        }
+    }
+
+    public static void showExampleFrame(final ExampleFrame frame) {
         Runnable r = new Runnable() {
             public void run() {
                 JMenuItem screenshot = new JMenuItem("Screenshot (png)");
@@ -45,7 +61,7 @@ public class ExampleUtils {
                         JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir"));
                         if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION)
{
                           File file = fileChooser.getSelectedFile();
-                          BufferedImage img = getScreenShot(frame.getContentPane());
+                          BufferedImage img = getScreenShot(frame.getMainPanel());
                           try {
                               // write the image as a PNG
                               ImageIO.write(img, "png", file);
@@ -55,8 +71,17 @@ public class ExampleUtils {
                         }
                     }
                 });
+                
+                JMenuItem exit = new JMenuItem("Exit");
+                exit.addActionListener(new ActionListener() {
+                    public void actionPerformed(ActionEvent e) {
+                        System.exit(0);
+                    }
+                });
+                
                 JMenu menu = new JMenu("File");
                 menu.add(screenshot);
+                menu.add(exit);
                 JMenuBar mb = new JMenuBar();
                 mb.add(menu);
                 frame.setJMenuBar(mb);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/LowDiscrepancyGeneratorComparison.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/LowDiscrepancyGeneratorComparison.java?rev=1489144&r1=1489143&r2=1489144&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/LowDiscrepancyGeneratorComparison.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/LowDiscrepancyGeneratorComparison.java
Mon Jun  3 20:12:20 2013
@@ -29,7 +29,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import javax.swing.JComponent;
-import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JTextArea;
 
@@ -42,6 +41,7 @@ import org.apache.commons.math3.random.R
 import org.apache.commons.math3.random.SobolSequenceGenerator;
 import org.apache.commons.math3.random.UncorrelatedRandomVectorGenerator;
 import org.apache.commons.math3.random.UniformRandomGenerator;
+import org.apache.commons.math3.userguide.ExampleUtils.ExampleFrame;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.util.Pair;
 
@@ -118,10 +118,10 @@ public class LowDiscrepancyGeneratorComp
     }
     
     @SuppressWarnings("serial")
-    public static class Display extends JFrame {
+    public static class Display extends ExampleFrame {
         
         public Display() {
-            setTitle("Pseudo/Quasi-random examples");
+            setTitle("Commons-Math: Pseudo/Quasi-random examples");
             setSize(800, 800);
             
             setLayout(new GridBagLayout());



Mime
View raw message