This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: BasicComboBoxUI - updated tests
- From: David Gilbert <david dot gilbert at object-refinery dot com>
- To: mauve-patches at sources dot redhat dot com
- Date: Mon, 07 Nov 2005 21:44:50 +0000
- Subject: FYI: BasicComboBoxUI - updated tests
I committed this patch to extend the tests for the BasicComboBoxUI class:
2005-11-07 David Gilbert <david.gilbert@object-refinery.com>
*
gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createArrowButton.java
(test): set look and feel and added new checks,
* gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createEditor.java
(test): added new checks,
* gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getDisplaySize.java
New test,
* gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getMinimumSize.java
(test): Use MyBasicComboBoxUI,
*
gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getPreferredSize.java
(test): Move code to new method testNonEditable(), replace with calls
to new test methods,
(testNonEditable): New method,
(testEditable): New method,
* gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/layout.java:
New test,
*
gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/MyBasicComboBoxUI.java
(getArrowButton): new method.
Regards,
Dave
Index: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/MyBasicComboBoxUI.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/MyBasicComboBoxUI.java,v
retrieving revision 1.1
diff -u -r1.1 MyBasicComboBoxUI.java
--- gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/MyBasicComboBoxUI.java 18 Oct 2005 21:31:52 -0000 1.1
+++ gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/MyBasicComboBoxUI.java 7 Nov 2005 21:26:50 -0000
@@ -69,4 +69,9 @@
{
return this.popup;
}
+
+ public JButton getArrowButton()
+ {
+ return this.arrowButton;
+ }
}
Index: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createArrowButton.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createArrowButton.java,v
retrieving revision 1.1
diff -u -r1.1 createArrowButton.java
--- gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createArrowButton.java 18 Oct 2005 21:31:52 -0000 1.1
+++ gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createArrowButton.java 7 Nov 2005 21:26:50 -0000
@@ -24,7 +24,12 @@
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
+import java.awt.Insets;
+
import javax.swing.JButton;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
+import javax.swing.plaf.BorderUIResource.CompoundBorderUIResource;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxUI;
@@ -42,9 +47,25 @@
*/
public void test(TestHarness harness)
{
+ try
+ {
+ UIManager.setLookAndFeel(new MyBasicComboBoxUILAF());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
MyBasicComboBoxUI ui = new MyBasicComboBoxUI();
JButton b = ui.createArrowButton();
- harness.check(b instanceof BasicArrowButton);
+ harness.check(b instanceof BasicArrowButton);
+ Border border = b.getBorder();
+ harness.check(border instanceof CompoundBorderUIResource);
+ // the insets and margin are presumably ignored when this button is
+ // drawn...
+ Insets insets = b.getInsets();
+ harness.check(insets, new Insets(4, 17, 5, 17));
+ Insets margin = b.getMargin();
+ harness.check(margin, new Insets(2, 14, 2, 14));
}
}
Index: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createEditor.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createEditor.java,v
retrieving revision 1.1
diff -u -r1.1 createEditor.java
--- gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createEditor.java 18 Oct 2005 21:31:52 -0000 1.1
+++ gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/createEditor.java 7 Nov 2005 21:26:50 -0000
@@ -24,7 +24,10 @@
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
+import java.awt.Component;
+
import javax.swing.ComboBoxEditor;
+import javax.swing.JTextField;
import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboBoxEditor.UIResource;
@@ -44,7 +47,11 @@
{
MyBasicComboBoxUI ui = new MyBasicComboBoxUI();
ComboBoxEditor editor = ui.createEditor();
- harness.check(editor instanceof UIResource);
+ harness.check(editor instanceof UIResource);
+ Component comp = editor.getEditorComponent();
+ harness.check(comp instanceof JTextField);
+ JTextField tf = (JTextField) comp;
+ harness.check(tf.getColumns(), 9);
}
}
Index: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getDisplaySize.java
===================================================================
RCS file: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getDisplaySize.java
diff -N gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getDisplaySize.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getDisplaySize.java 7 Nov 2005 21:26:50 -0000
@@ -0,0 +1,143 @@
+// Tags: JDK1.2
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301 USA.
+
+package gnu.testlet.javax.swing.plaf.basic.BasicComboBoxUI;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+import gnu.testlet.javax.swing.plaf.TestLookAndFeel;
+
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+
+import javax.swing.JComboBox;
+import javax.swing.JTextField;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.plaf.basic.BasicComboBoxUI;
+
+/**
+ * Some checks for the getDisplaySize() method in the
+ * {@link BasicComboBoxUI} class.
+ */
+public class getDisplaySize implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ testNotEditable(harness);
+ testEditable(harness);
+ }
+
+ /**
+ * Run some checks for a JComboBox that is not editable.
+ *
+ * @param harness the test harness.
+ */
+ private void testNotEditable(TestHarness harness)
+ {
+ try
+ {
+ UIManager.setLookAndFeel(new TestLookAndFeel());
+ }
+ catch (UnsupportedLookAndFeelException e)
+ {
+ e.printStackTrace();
+ }
+ JComboBox cb = new JComboBox();
+ MyBasicComboBoxUI ui = new MyBasicComboBoxUI();
+ cb.setUI(ui);
+ int additionalHeight = 2; // margin? border?
+ int additionalWidth = 2;
+ FontMetrics fm = cb.getFontMetrics(cb.getFont());
+
+ // the following width calculation is a guess. We know the value
+ // depends on the font size, and that it is relatively small, so after
+ // trying out a few candidates this one seems to give the right result
+ int width = fm.charWidth(' ') + additionalWidth;
+ int height = fm.getHeight() + additionalHeight;
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+
+ cb.addItem("ABC");
+ width = fm.stringWidth("ABC") + additionalWidth;
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+
+ cb.addItem("A longer item");
+ width = fm.stringWidth("A longer item") + additionalWidth;
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+
+ cb.setPrototypeDisplayValue("Prototype");
+ width = fm.stringWidth("Prototype") + additionalWidth;
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+ }
+
+ /**
+ * Run some checks for a JComboBox that is editable.
+ *
+ * @param harness the test harness.
+ */
+ private void testEditable(TestHarness harness)
+ {
+ try
+ {
+ UIManager.setLookAndFeel(new TestLookAndFeel());
+ }
+ catch (UnsupportedLookAndFeelException e)
+ {
+ e.printStackTrace();
+ }
+ JComboBox cb = new JComboBox();
+ cb.setEditable(true);
+ MyBasicComboBoxUI ui = new MyBasicComboBoxUI();
+ cb.setUI(ui);
+ JTextField tf = (JTextField) cb.getEditor().getEditorComponent();
+ int columns = tf.getColumns();
+ FontMetrics fm = cb.getFontMetrics(cb.getFont());
+
+ // for an editable JComboBox the display size is calculated from the
+ // preferred size of the JTextField it seems, or the prototype display
+ // value in some cases...
+ int width = fm.charWidth('m') * columns;
+ int height = fm.getHeight() + 2; // the 2 seems to be a fixed margin
+
+ // not sure why the width here needs + 1..
+ harness.check(ui.getDisplaySize(), new Dimension(width + 1, height));
+
+ cb.addItem("ABC");
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+
+ cb.addItem("A longer item");
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+
+ cb.setPrototypeDisplayValue("Prototype");
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+
+ cb.setPrototypeDisplayValue("Long Prototype Display Value");
+ width = fm.stringWidth("Long Prototype Display Value") + 2;
+ harness.check(ui.getDisplaySize(), new Dimension(width, height));
+ }
+
+}
Index: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getMinimumSize.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getMinimumSize.java,v
retrieving revision 1.1
diff -u -r1.1 getMinimumSize.java
--- gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getMinimumSize.java 18 Oct 2005 21:31:52 -0000 1.1
+++ gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getMinimumSize.java 7 Nov 2005 21:26:50 -0000
@@ -46,7 +46,7 @@
public void test(TestHarness harness)
{
JComboBox cb = new JComboBox();
- BasicComboBoxUI ui = new BasicComboBoxUI();
+ MyBasicComboBoxUI ui = new MyBasicComboBoxUI();
cb.setUI(ui);
int additionalHeight = 2; // margin? border?
int additionalWidth = 2;
Index: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getPreferredSize.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getPreferredSize.java,v
retrieving revision 1.1
diff -u -r1.1 getPreferredSize.java
--- gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getPreferredSize.java 18 Oct 2005 21:31:52 -0000 1.1
+++ gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/getPreferredSize.java 7 Nov 2005 21:26:50 -0000
@@ -25,10 +25,12 @@
import gnu.testlet.Testlet;
import java.awt.Dimension;
+import java.awt.Font;
import java.awt.FontMetrics;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
+import javax.swing.JTextField;
import javax.swing.plaf.basic.BasicComboBoxUI;
/**
@@ -45,6 +47,12 @@
*/
public void test(TestHarness harness)
{
+ testNonEditable(harness);
+ testEditable(harness);
+ }
+
+ private void testNonEditable(TestHarness harness)
+ {
JComboBox cb = new JComboBox();
BasicComboBoxUI ui = new BasicComboBoxUI();
cb.setUI(ui);
@@ -73,4 +81,24 @@
new Dimension(width + height, height));
}
+ private void testEditable(TestHarness harness)
+ {
+ harness.checkPoint("testEditable()");
+ JComboBox cb = new JComboBox();
+ BasicComboBoxUI ui = new BasicComboBoxUI();
+ cb.setUI(ui);
+ JTextField tf = (JTextField) cb.getEditor().getEditorComponent();
+ cb.setEditable(true);
+ Font font = cb.getFont();
+ System.out.println(font);
+ FontMetrics fm = cb.getFontMetrics(font);
+ int height = fm.getHeight() + 2;
+ int width = fm.stringWidth("m") * tf.getColumns() + height;
+ harness.check(ui.getPreferredSize(cb), new Dimension(width + 1, height));
+ cb.setModel(new DefaultComboBoxModel(new Object[] {"X"}));
+ harness.check(ui.getPreferredSize(cb), new Dimension(width, height));
+ cb.setPrototypeDisplayValue("XX");
+ harness.check(ui.getPreferredSize(cb), new Dimension(width, height));
+ }
+
}
\ No newline at end of file
Index: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/layout.java
===================================================================
RCS file: gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/layout.java
diff -N gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/layout.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/plaf/basic/BasicComboBoxUI/layout.java 7 Nov 2005 21:26:50 -0000
@@ -0,0 +1,75 @@
+// Tags: JDK1.2
+
+// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING. If not, write to
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301 USA.
+
+package gnu.testlet.javax.swing.plaf.basic.BasicComboBoxUI;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Rectangle;
+
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.UIManager;
+import javax.swing.plaf.basic.BasicComboBoxUI;
+
+/**
+ * Some checks for the layout in the {@link BasicComboBoxUI} class.
+ */
+public class layout implements Testlet
+{
+
+ /**
+ * Runs the test using the specified harness.
+ *
+ * @param harness the test harness (<code>null</code> not permitted).
+ */
+ public void test(TestHarness harness)
+ {
+ try
+ {
+ UIManager.setLookAndFeel(new MyBasicComboBoxUILAF());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ JComboBox cb = new JComboBox();
+ cb.setEditable(true);
+ JFrame frame = new JFrame();
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.add(cb);
+ frame.setContentPane(panel);
+ frame.pack();
+ JTextField tf = (JTextField) cb.getEditor().getEditorComponent();
+ Font font = cb.getFont();
+ FontMetrics fm = cb.getFontMetrics(font);
+ int height = fm.getHeight() + 2;
+ int width = fm.stringWidth("m") * tf.getColumns() + 1;
+ harness.check(tf.getBounds(), new Rectangle(0, 0, width, height));
+ }
+
+}