Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B2953D1E6 for ; Wed, 22 May 2013 21:32:24 +0000 (UTC) Received: (qmail 1060 invoked by uid 500); 22 May 2013 21:32:24 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 994 invoked by uid 500); 22 May 2013 21:32:24 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 987 invoked by uid 99); 22 May 2013 21:32:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 May 2013 21:32:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 May 2013 21:32:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DB8C32388A39; Wed, 22 May 2013 21:32:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1485435 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide: ClusteringExamples.java ExampleUtils.java RandomVectorGeneratorExamples.java Date: Wed, 22 May 2013 21:32:02 -0000 To: commits@commons.apache.org From: tn@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130522213202.DB8C32388A39@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tn Date: Wed May 22 21:32:02 2013 New Revision: 1485435 URL: http://svn.apache.org/r1485435 Log: Add support for creating screenshots. Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java (with props) Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusteringExamples.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/RandomVectorGeneratorExamples.java Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusteringExamples.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusteringExamples.java?rev=1485435&r1=1485434&r2=1485435&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusteringExamples.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ClusteringExamples.java Wed May 22 21:32:02 2013 @@ -33,8 +33,7 @@ import java.util.List; import javax.swing.JComponent; import javax.swing.JFrame; -import javax.swing.JTextArea; -import javax.swing.SwingUtilities; +import javax.swing.JLabel; import org.apache.commons.math3.distribution.NormalDistribution; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; @@ -180,15 +179,12 @@ public class ClusteringExamples { return points; } + @SuppressWarnings("serial") public static class Display extends JFrame { - private static final long serialVersionUID = -8846964550416589808L; - public Display() { setTitle("Clustering examples"); setSize(800, 800); - setLocationRelativeTo(null); - setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new GridBagLayout()); @@ -217,9 +213,7 @@ public class ClusteringExamples { c.insets = new Insets(2, 2, 2, 2); for (Pair> pair : algorithms) { - JTextArea text = new JTextArea(pair.getFirst()); - text.setEditable(false); - text.setOpaque(false); + JLabel text = new JLabel("" + pair.getFirst().replace("\n", "
")); add(text, c); c.gridx++; } @@ -239,10 +233,9 @@ public class ClusteringExamples { } } + @SuppressWarnings("serial") public static class ClusterPlot extends JComponent { - private static final long serialVersionUID = 4546352048750419587L; - private static double PAD = 10; private List> clusters; @@ -274,7 +267,7 @@ public class ClusteringExamples { for (DoublePoint point : cluster.getPoints()) { Clusterable p = transform(point, w, h); double[] arr = p.getPoint(); - g2.fill(new Ellipse2D.Double(arr[0] - 2, arr[1] - 2, 4, 4)); + g2.fill(new Ellipse2D.Double(arr[0] - 1, arr[1] - 1, 3, 3)); } if (cluster instanceof CentroidCluster) { @@ -304,11 +297,6 @@ public class ClusteringExamples { } public static void main(String[] args) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - Display d = new Display(); - d.setVisible(true); - } - }); + ExampleUtils.showExampleFrame(new Display()); } } Added: 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=1485435&view=auto ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java (added) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java Wed May 22 21:32:02 2013 @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math3.userguide; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.image.BufferedImage; +import java.io.File; + +import javax.imageio.ImageIO; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; + +public class ExampleUtils { + + public static void showExampleFrame(final JFrame frame) { + Runnable r = new Runnable() { + public void run() { + JMenuItem screenshot = new JMenuItem("Screenshot (png)"); + screenshot.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, InputEvent.CTRL_DOWN_MASK)); + screenshot.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + JFileChooser fileChooser = new JFileChooser(System.getProperty("user.dir")); + if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { + File file = fileChooser.getSelectedFile(); + BufferedImage img = getScreenShot(frame.getContentPane()); + try { + // write the image as a PNG + ImageIO.write(img, "png", file); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + JMenu menu = new JMenu("File"); + menu.add(screenshot); + JMenuBar mb = new JMenuBar(); + mb.add(menu); + frame.setJMenuBar(mb); + + frame.setLocationRelativeTo(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + }; + SwingUtilities.invokeLater(r); + } + + private static BufferedImage getScreenShot(Component component) { + BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB); + // call the Component's paint method, using the Graphics object of the image. + component.paint(image.getGraphics()); + return image; + } + +} Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java ------------------------------------------------------------------------------ svn:keywords = Id Revision HeadURL Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/ExampleUtils.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/RandomVectorGeneratorExamples.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/RandomVectorGeneratorExamples.java?rev=1485435&r1=1485434&r2=1485435&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/RandomVectorGeneratorExamples.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/userguide/RandomVectorGeneratorExamples.java Wed May 22 21:32:02 2013 @@ -32,7 +32,6 @@ import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; -import javax.swing.SwingUtilities; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; import org.apache.commons.math3.random.HaltonSequenceGenerator; @@ -118,15 +117,12 @@ public class RandomVectorGeneratorExampl return points; } + @SuppressWarnings("serial") public static class Display extends JFrame { - private static final long serialVersionUID = -8846964550416589808L; - public Display() { setTitle("Pseudo/Quasi-random examples"); setSize(800, 800); - setLocationRelativeTo(null); - setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new GridBagLayout()); @@ -206,10 +202,9 @@ public class RandomVectorGeneratorExampl } } + @SuppressWarnings("serial") public static class Plot extends JComponent { - private static final long serialVersionUID = 4546352048750419587L; - private static double PAD = 10; private List points; @@ -252,11 +247,6 @@ public class RandomVectorGeneratorExampl } public static void main(String[] args) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - Display d = new Display(); - d.setVisible(true); - } - }); + ExampleUtils.showExampleFrame(new Display()); } }