[Schmitzm-commits] r1098 - in trunk: src/skrueger/geotools/labelsearch src/skrueger/i8n src_junit/schmitzm/swing src_junit/skrueger/i8n
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Oct 11 00:52:17 CEST 2010
Author: alfonx
Date: 2010-10-11 00:52:16 +0200 (Mon, 11 Oct 2010)
New Revision: 1098
Modified:
trunk/src/skrueger/geotools/labelsearch/SearchMapDialog.java
trunk/src/skrueger/geotools/labelsearch/SearchResultTableModel.java
trunk/src/skrueger/i8n/SwitchLanguageDialog.java
trunk/src_junit/schmitzm/swing/TestingUtil.java
trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java
Log:
More cleanup around the GUI tests
Modified: trunk/src/skrueger/geotools/labelsearch/SearchMapDialog.java
===================================================================
--- trunk/src/skrueger/geotools/labelsearch/SearchMapDialog.java 2010-10-10 21:14:05 UTC (rev 1097)
+++ trunk/src/skrueger/geotools/labelsearch/SearchMapDialog.java 2010-10-10 22:52:16 UTC (rev 1098)
@@ -64,7 +64,7 @@
import schmitzm.swing.SwingUtil;
/**
- * @author Stefan A. Krueger
+ * @author Stefan A. Tzeggai
*/
public class SearchMapDialog extends javax.swing.JDialog {
final static private Logger LOGGER = Logger
Modified: trunk/src/skrueger/geotools/labelsearch/SearchResultTableModel.java
===================================================================
--- trunk/src/skrueger/geotools/labelsearch/SearchResultTableModel.java 2010-10-10 21:14:05 UTC (rev 1097)
+++ trunk/src/skrueger/geotools/labelsearch/SearchResultTableModel.java 2010-10-10 22:52:16 UTC (rev 1098)
@@ -42,7 +42,7 @@
* The three columns of this {@link TableModel} are: result number, full name,
* name of layer containing the result
*
- * @author Stefan A. Krueger
+ * @author Stefan A. Tzeggai
*
*/
public class SearchResultTableModel extends AbstractTableModel implements
Modified: trunk/src/skrueger/i8n/SwitchLanguageDialog.java
===================================================================
--- trunk/src/skrueger/i8n/SwitchLanguageDialog.java 2010-10-10 21:14:05 UTC (rev 1097)
+++ trunk/src/skrueger/i8n/SwitchLanguageDialog.java 2010-10-10 22:52:16 UTC (rev 1098)
@@ -43,13 +43,13 @@
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
-import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import schmitzm.swing.SwingUtil;
+import skrueger.swing.AtlasDialog;
import skrueger.swing.OkButton;
import skrueger.swing.TranslationEditJPanel;
@@ -57,9 +57,9 @@
* This dialog ask the user to select one of list of given languages. The dialog
* is modal and not visible after construction.
*
- * @author Stefan A. Krueger
+ * @author Stefan A. Tzeggai
*/
-public class SwitchLanguageDialog extends JDialog {
+public class SwitchLanguageDialog extends AtlasDialog {
protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);
private JPanel jContentPane = null;
@@ -79,30 +79,54 @@
private final List<String> languages;
/**
+ * if <code>true</code>, the default locale will also be changed during a
+ * language selection
+ **/
+ protected boolean setLocale;
+
+ /**
* A dialog to select one of the available languages. If only one language
* is available, select it directly. Creating this object automatically
* makes it visible, unless there is only one language to choose from.. it
* that case it disposes itself automatically.
+ *
+ * @param setLocale
+ * if <code>true</code>, the default locale will also be changed
+ * during a language selection
*/
public SwitchLanguageDialog(final Component owner,
- final List<String> languages) {
- super(SwingUtil.getParentWindow(owner));
+ final List<String> languages, boolean setLocale) {
+ super(owner);
this.languages = languages;
+ this.setLocale = setLocale;
- Translation.setActiveLang(languages.get(0));
+ if (languages == null || languages.size() == 0) {
+ // No language is available.
+ return;
+ }
+ Translation.setActiveLang(languages.get(0), setLocale);
if (languages.size() == 1) {
- LOGGER.debug("Only language '" + languages.get(0)
- + "' is available. It has been selected automatically.");
- // dispose();
- setModal(false);
+ // Only language one language is available. It has been selected
+ // automatically.
return;
}
initialize();
}
+ @Override
/**
+ * This modal dialog will not appear if there is <= one language to select from.
+ */
+ public void setVisible(boolean b) {
+ if (b == true && (languages == null || languages.size() <= 1)) {
+ return;
+ }
+ super.setVisible(b);
+ }
+
+ /**
* This method initializes this
*
* @return void
@@ -110,15 +134,20 @@
private void initialize() {
this.setContentPane(getJContentPane());
- setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
-
pack();
SwingUtil.centerFrameOnScreenRandom(this);
setModal(true);
- setVisible(true);
}
+ public boolean close() {
+ // Only close by ESC and window-close if a valid selection is made
+ if (jComboBox.getSelectedIndex() == languages.size())
+ return false;
+ else
+ return super.close();
+ }
+
/**
* This method initializes jContentPane
*
@@ -271,7 +300,7 @@
String l = languages.get(jComboBox.getSelectedIndex());
try {
- Translation.setActiveLang(l);
+ Translation.setActiveLang(l, setLocale);
getJButton().setEnabled(true);
} catch (java.lang.IllegalArgumentException ee) {
Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-10-10 21:14:05 UTC (rev 1097)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-10-10 22:52:16 UTC (rev 1098)
@@ -47,6 +47,11 @@
public class TestingUtil {
/**
+ * Number of seconds to wait until a GUI should be closed by default. Can be
+ * set to -1 to always wait forever.
+ */
+ private static final int WAIT_MAX_DEFAULT = 3;
+ /**
* All these GUI-initiating testGui(...) methods are only executed if the
* system is not running in headless mode.
*/
@@ -106,8 +111,10 @@
int countWait = 0;
while (w.isVisible() && !stopFlag.get()) {
LangUtil.sleepExceptionless(100);
- if (waitMax > 0 && countWait++ > waitMax * 10)
+ if (waitMax >= 0 && countWait++ > waitMax * 10) {
+ // waitMax < 0 will never brake the waiting and never increase the countWait
break;
+ }
}
w.dispose();
@@ -181,7 +188,7 @@
}
public static void testGui(Component gui) throws Throwable {
- testGui(gui, 3);
+ testGui(gui, WAIT_MAX_DEFAULT);
}
public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
@@ -289,13 +296,32 @@
chartFrame.pack();
testGui(chartFrame);
+ }
+ }
- // chartFrame.pack();
- // chartFrame.setVisible(true);
+ /**
+ * Returns the percentage of the possible maximum head size used (0 to 100)
+ */
+ public static double getHeapUsedPercentageOfMax() {
- // while (chartFrame.isVisible()) {
- // Thread.sleep(100);
- // }
- }
+ // Get current size of heap in bytes
+ long heapSize = Runtime.getRuntime().totalMemory();
+
+ // Get maximum size of heap in bytes. The heap cannot grow beyond this
+ // size.
+ // Any attempt will result in an OutOfMemoryException.
+ long heapMaxSize = Runtime.getRuntime().maxMemory();
+
+ // Get amount of free memory within the heap in bytes. This size will
+ // increase
+ // after garbage collection and decrease as new objects are created.
+ long heapFreeSize = Runtime.getRuntime().freeMemory();
+
+ long used = (heapSize - heapFreeSize);
+
+ double perc = (used * 100. / heapMaxSize);
+
+ return perc;
}
+
}
Modified: trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java
===================================================================
--- trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java 2010-10-10 21:14:05 UTC (rev 1097)
+++ trunk/src_junit/skrueger/i8n/SwitchLanguageDialogTest.java 2010-10-10 22:52:16 UTC (rev 1098)
@@ -33,13 +33,30 @@
import junit.framework.TestCase;
+import org.junit.Test;
+
+import schmitzm.swing.TestingUtil;
+
public class SwitchLanguageDialogTest extends TestCase {
- public void testDialog() {
- ArrayList<String> langsa = new ArrayList<String>();
- langsa.add("fr");
- langsa.add("tr");
- // INteractive test diabled
- // new SwitchLanguageDialog(null, langsa).setModal(false);
+ @Test
+ public void testDialog() throws Throwable {
+ ArrayList<String> langs = new ArrayList<String>();
+ langs.add("fr");
+ langs.add("tr");
+
+ TestingUtil.testGui(new SwitchLanguageDialog(null, langs, false), 10);
}
+
+ @Test
+ public void testDialogDoesntAppearIf0OrOneLangOnly() throws Throwable {
+ ArrayList<String> langs = new ArrayList<String>();
+ langs.add("fr");
+
+ long startTime = System.currentTimeMillis();
+ TestingUtil.testGui(new SwitchLanguageDialog(null, langs, false), 2);
+ assertTrue("dialog did pop up incorrectly", System.currentTimeMillis()
+ - startTime < 1000);
+ }
+
}
More information about the Schmitzm-commits
mailing list