[Polycasso-commit] SF.net SVN: polycasso:[225] trunk/polycasso/src/com/mebigfatguy/polycasso
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-09-29 04:05:26
|
Revision: 225
http://polycasso.svn.sourceforge.net/polycasso/?rev=225&view=rev
Author: dbrosius
Date: 2010-09-29 04:05:19 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
start adding genetic settings
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java
trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
Added Paths:
-----------
trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java
Added: trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java (rev 0)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -0,0 +1,59 @@
+/*
+ * polycasso - Cubism Artwork generator
+ * Copyright 2009-2010 MeBigFatGuy.com
+ * Copyright 2009-2010 Dave Brosius
+ * Inspired by work by Roger Alsing
+ *
+ * Licensed 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 com.mebigfatguy.polycasso;
+
+import java.awt.Toolkit;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.PlainDocument;
+
+/**
+ * a Document model class for text components to only allow
+ * integer values
+ */
+public class DoubleDocument extends PlainDocument {
+
+ private static final long serialVersionUID = -6755728406523769124L;
+
+ /**
+ * intercepts string insertions to make sure that the values to be put into
+ * a text component is only a positive double value
+ *
+ * @param pos where the text is being inserted
+ * @param insertStr the new text that was typed
+ * @param atts the attributes for the text (unused)
+ */
+ @Override
+ public void insertString(int pos, String insertStr, AttributeSet atts) throws BadLocationException {
+ StringBuilder text = new StringBuilder(getText(0, getLength()));
+ try {
+ text.insert(pos, insertStr);
+ double value = Double.parseDouble(text.toString());
+ if (value < 0) {
+ Toolkit.getDefaultToolkit().beep();
+ } else {
+ super.insertString(pos, insertStr, atts);
+ }
+ } catch (Exception e) {
+ Toolkit.getDefaultToolkit().beep();
+ }
+ }
+
+}
Property changes on: trunk/polycasso/src/com/mebigfatguy/polycasso/DoubleDocument.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/IntegerDocument.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -26,7 +26,7 @@
/**
* a Document model class for text components to only allow
- * integer values
+ * positive integer values
*/
public class IntegerDocument extends PlainDocument {
@@ -45,8 +45,12 @@
StringBuilder text = new StringBuilder(getText(0, getLength()));
try {
text.insert(pos, insertStr);
- Integer.parseInt(text.toString());
- super.insertString(pos, insertStr, atts);
+ int value = Integer.parseInt(text.toString());
+ if (value < 0) {
+ Toolkit.getDefaultToolkit().beep();
+ } else {
+ super.insertString(pos, insertStr, atts);
+ }
} catch (Exception e) {
Toolkit.getDefaultToolkit().beep();
}
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/PolycassoBundle.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -50,6 +50,13 @@
Settings("pc.settings"),
About("pc.about"),
AboutPolycasso("pc.aboutpolycasso"),
+ GeneticsOptions("pc.geneticsoptions"),
+ GenerationSize("pc.generationsize"),
+ EliteSize("pc.elitesize"),
+ UseAnnealing("pc.useannealing"),
+ StartTemperature("pc.starttemperature"),
+ CoolingRate("pc.coolingrate"),
+ ImageOptions("pc.imageoptions"),
MaxImageSize("pc.maximagesize"),
Width("pc.width"),
Height("pc.height"),
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/Settings.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -26,9 +26,14 @@
* Polycasso runs
*/
public class Settings implements Cloneable, Serializable {
-
- private static final long serialVersionUID = -8827208887550245450L;
+ private static final long serialVersionUID = 8021543124907733235L;
+
+ private int generationSize;
+ private int eliteSize;
+ private boolean useAnnealing;
+ private double startTemperature;
+ private double coolingRate;
private Dimension maxImageSize;
private int numCompetingImages;
private int maxPolygons;
@@ -40,6 +45,11 @@
* constructs a settings object with rational defaults
*/
public Settings() {
+ generationSize = 50;
+ eliteSize = 10;
+ useAnnealing = true;
+ startTemperature = 20;
+ coolingRate = 0.1;
maxImageSize = new Dimension(800, 600);
maxPolygons = 100;
numCompetingImages = 20;
@@ -62,7 +72,58 @@
}
}
+
+ public void setGenerationSize(int generationSz) {
+ generationSize = generationSz;
+ }
+
+ public int getGenerationSize() {
+ return generationSize;
+ }
+
+ public void setEliteSize(int eliteSz) {
+ eliteSize = eliteSz;
+ }
+
+ public int getEliteSize() {
+ return eliteSize;
+ }
+
/**
+ * sets whether to use simulated annealing
+ *
+ * @param annealing whether to use annealing
+ */
+ public void setUseAnnealing(boolean annealing) {
+ useAnnealing = annealing;
+ }
+
+ /**
+ * gets whether to use simulating annealing
+ *
+ * @return whether to use simulating annealing
+ */
+ public boolean isUseAnnealing() {
+ return useAnnealing;
+ }
+
+ public void setStartTemperature(double startTemp) {
+ startTemperature = startTemp;
+ }
+
+ public double getStartTemperature() {
+ return startTemperature;
+ }
+
+ public void setCoolingRate(double coolRate) {
+ coolingRate = coolRate;
+ }
+
+ public double getCoolingRate() {
+ return coolingRate;
+ }
+
+ /**
* sets the maximum image size
*
* @param imageSize the image size
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/SettingsDialog.java 2010-09-29 04:05:19 UTC (rev 225)
@@ -30,6 +30,7 @@
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
+import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
@@ -52,6 +53,11 @@
private JButton resetButton;
private JButton okButton;
private JButton cancelButton;
+ private JTextField generationSizeField;
+ private JTextField eliteSizeField;
+ private JCheckBox useAnnealingButton;
+ private JTextField startTemperatureField;
+ private JTextField coolingRateField;
private JTextField widthField;
private JTextField heightField;
private JTextField maxPolygonField;
@@ -59,8 +65,10 @@
private JTextField maxPolygonPointsField;
private JTextField maxPtMoveField;
private JTextField maxColorChangeField;
+ private SelectAllFocuser focuser;
private boolean isOK;
+
/**
* constructs the dialog using the passed in settings to set default values
*
@@ -99,7 +107,16 @@
Container cp = getContentPane();
cp.setLayout(new BorderLayout(4, 4));
- cp.add(createOptionsPanel(), BorderLayout.CENTER);
+ focuser = new SelectAllFocuser();
+
+ JPanel centerPanel = new JPanel();
+ centerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
+ centerPanel.add(createGeneticsPanel());
+ centerPanel.add(Box.createVerticalStrut(10));
+ centerPanel.add(createOptionsPanel());
+
+ cp.add(centerPanel, BorderLayout.CENTER);
cp.add(createControlPanel(), BorderLayout.SOUTH);
pack();
}
@@ -110,10 +127,9 @@
* @return the options panel
*/
private JPanel createOptionsPanel() {
-
- SelectAllFocuser focuser = new SelectAllFocuser();
JPanel optPanel = new JPanel();
- optPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ optPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(PolycassoBundle.getString(PolycassoBundle.Key.ImageOptions)),
+ BorderFactory.createEmptyBorder(10, 10, 10, 10)));
optPanel.setLayout(new FormLayout("pref, 3dlu, 100px, 5dlu, pref, 3dlu, 100px", "pref, 1dlu, pref, 15dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
CellConstraints cc = new CellConstraints();
@@ -181,7 +197,66 @@
return optPanel;
}
+ private JPanel createGeneticsPanel() {
+
+ JPanel geneticsPanel = new JPanel();
+ geneticsPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(PolycassoBundle.getString(PolycassoBundle.Key.GeneticsOptions)),
+ BorderFactory.createEmptyBorder(10, 10, 10, 10)));
+
+ geneticsPanel.setLayout(new FormLayout("6dlu, pref, 3dlu, 100px, 3dlu", "pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref, 1dlu, pref"));
+ CellConstraints cc = new CellConstraints();
+
+ JLabel generationSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.GenerationSize));
+ geneticsPanel.add(generationSizeLabel, cc.xyw(1, 1, 2));
+
+ generationSizeField = new JTextField(4);
+ generationSizeField.setDocument(new IntegerDocument());
+ generationSizeLabel.setLabelFor(generationSizeField);
+ geneticsPanel.add(generationSizeField, cc.xy(4, 1));
+ generationSizeField.addFocusListener(focuser);
+
+ JLabel eliteSizeLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.EliteSize));
+ geneticsPanel.add(eliteSizeLabel, cc.xyw(1, 3, 2));
+
+ eliteSizeField = new JTextField(4);
+ eliteSizeField.setDocument(new IntegerDocument());
+ eliteSizeLabel.setLabelFor(eliteSizeField);
+ geneticsPanel.add(eliteSizeField, cc.xy(4, 3));
+ eliteSizeField.addFocusListener(focuser);
+
+ useAnnealingButton = new JCheckBox(PolycassoBundle.getString(PolycassoBundle.Key.UseAnnealing));
+ geneticsPanel.add(useAnnealingButton, cc.xyw(1, 5, 5));
+
+ JLabel startTemperatureLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.StartTemperature));
+ geneticsPanel.add(startTemperatureLabel, cc.xy(2, 7));
+
+ startTemperatureField = new JTextField(4);
+ startTemperatureField.setDocument(new DoubleDocument());
+ startTemperatureLabel.setLabelFor(startTemperatureField);
+ geneticsPanel.add(startTemperatureField, cc.xy(4, 7));
+ startTemperatureField.addFocusListener(focuser);
+
+ JLabel coolingRateLabel = new JLabel(PolycassoBundle.getString(PolycassoBundle.Key.CoolingRate));
+ geneticsPanel.add(coolingRateLabel, cc.xy(2, 9));
+
+ coolingRateField = new JTextField(4);
+ coolingRateField.setDocument(new DoubleDocument());
+ coolingRateLabel.setLabelFor(coolingRateField);
+ geneticsPanel.add(coolingRateField, cc.xy(4, 9));
+ coolingRateField.addFocusListener(focuser);
+
+ return geneticsPanel;
+ }
+
private void populateValues() {
+ generationSizeField.setText(String.valueOf(dlgSettings.getGenerationSize()));
+ eliteSizeField.setText(String.valueOf(dlgSettings.getEliteSize()));
+ boolean enable = dlgSettings.isUseAnnealing();
+ useAnnealingButton.setSelected(enable);
+ startTemperatureField.setEnabled(enable);
+ startTemperatureField.setText(String.valueOf(dlgSettings.getStartTemperature()));
+ coolingRateField.setEnabled(enable);
+ coolingRateField.setText(String.valueOf(dlgSettings.getCoolingRate()));
widthField.setText(String.valueOf(dlgSettings.getMaxImageSize().width));
heightField.setText(String.valueOf(dlgSettings.getMaxImageSize().height));
maxPolygonField.setText(String.valueOf(dlgSettings.getMaxPolygons()));
@@ -189,7 +264,6 @@
maxPolygonPointsField.setText(String.valueOf(dlgSettings.getMaxPoints()));
maxPtMoveField.setText(String.valueOf(dlgSettings.getMaxPtMovement()));
maxColorChangeField.setText(String.valueOf(dlgSettings.getMaxColorChange()));
-
}
/**
@@ -221,6 +295,16 @@
* sets up all the control listeners for the dialog
*/
private void initListeners() {
+
+ useAnnealingButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ boolean enable = useAnnealingButton.isSelected();
+ startTemperatureField.setEnabled(enable);
+ coolingRateField.setEnabled(enable);
+ }
+ });
+
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
@@ -286,7 +370,19 @@
* @return whether the settings are valid
*/
private boolean validateSettings() {
- if (dlgSettings.getMaxImageSize().width < 10) {
+ if (dlgSettings.getGenerationSize() < 10) {
+ generationSizeField.setText("10");
+ generationSizeField.requestFocus();
+ } else if (dlgSettings.getEliteSize() < 2) {
+ eliteSizeField.setText("2");
+ eliteSizeField.requestFocus();
+ } else if (dlgSettings.getStartTemperature() > 255) {
+ startTemperatureField.setText("255.0");
+ startTemperatureField.requestFocus();
+ } else if (dlgSettings.getCoolingRate() > 40) {
+ coolingRateField.setText("40.0");
+ coolingRateField.requestFocus();
+ } else if (dlgSettings.getMaxImageSize().width < 10) {
widthField.setText("10");
widthField.requestFocus();
} else if (dlgSettings.getMaxImageSize().height < 10) {
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2010-06-09 06:11:13 UTC (rev 224)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/resource.properties 2010-09-29 04:05:19 UTC (rev 225)
@@ -37,6 +37,13 @@
pc.settings = Settings
pc.about = About
pc.aboutpolycasso = About Polycasso
+pc.geneticsoptions = Genetics Options
+pc.generationsize = Generation Size
+pc.elitesize = Elite Size
+pc.useannealing = Use Annealing
+pc.starttemperature = Annealing Starting Temperature
+pc.coolingrate = Annealing cooling rate
+pc.imageoptions = Image Options
pc.maximagesize = Maximum Image Size
pc.width = Width
pc.height = Height
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|