jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1417789 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/util/TristateCheckBox.java test/src/org/apache/jmeter/gui/util/TristateCheckBoxTest.java
Date Thu, 06 Dec 2012 10:05:43 GMT
Author: sebb
Date: Thu Dec  6 10:05:42 2012
New Revision: 1417789

URL: http://svn.apache.org/viewvc?rev=1417789&view=rev
Log:
Add tests for original code - which did not use a special icon - for comparison
Bugzilla Id: 54251

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/TristateCheckBox.java
    jmeter/trunk/test/src/org/apache/jmeter/gui/util/TristateCheckBoxTest.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/TristateCheckBox.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/TristateCheckBox.java?rev=1417789&r1=1417788&r2=1417789&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/TristateCheckBox.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/TristateCheckBox.java Thu Dec  6 10:05:42
2012
@@ -61,12 +61,21 @@ public final class TristateCheckBox exte
         this(text, null, TristateState.DESELECTED);
     }
 
-    public TristateCheckBox(String text, Icon icon,
-            TristateState initial) {
+    // For testing only at present
+    TristateCheckBox(String text, boolean original) {
+        this(text, null, TristateState.DESELECTED, original);
+    }
+
+    public TristateCheckBox(String text, Icon icon, TristateState initial) {
+        this(text, icon, initial, false);
+    }
+
+    // For testing only at present
+    TristateCheckBox(String text, Icon icon, TristateState initial, boolean original) {
         super(text, icon);
 
         //Set default single model
-        setModel(new TristateButtonModel(initial, this));
+        setModel(new TristateButtonModel(initial, this, original));
 
         // override action behaviour
         super.addMouseListener(new MouseAdapter() {
@@ -148,12 +157,14 @@ public final class TristateCheckBox exte
         private TristateState state = TristateState.DESELECTED;
         private final TristateCheckBox tristateCheckBox;
         private final Icon icon;
+        private final boolean original;
 
         public TristateButtonModel(TristateState initial,
-                TristateCheckBox tristateCheckBox) {
+                TristateCheckBox tristateCheckBox, boolean original) {
             setState(TristateState.DESELECTED);
             this.tristateCheckBox = tristateCheckBox;
             icon = new TristateCheckBoxIcon(tristateCheckBox);
+            this.original = original;
         }
 
         public void setIndeterminate() {
@@ -211,15 +222,17 @@ public final class TristateCheckBox exte
 
         private void displayState() {
             super.setSelected(state != TristateState.DESELECTED);
-            //    original used:
-//            super.setArmed(state == TristateState.INDETERMINATE);
-            if (state == TristateState.INDETERMINATE) {
-                tristateCheckBox.setIcon(icon); // Needed for all but Nimbus
-                tristateCheckBox.setSelectedIcon(icon); // Nimbus works - after a fashion
- with this
-            } else { // reset
-                if (tristateCheckBox!= null){
-                    tristateCheckBox.setIcon(null);
-                    tristateCheckBox.setSelectedIcon(null);
+            if (original) {
+                super.setArmed(state == TristateState.INDETERMINATE);
+            } else {
+                if (state == TristateState.INDETERMINATE) {
+                    tristateCheckBox.setIcon(icon); // Needed for all but Nimbus
+                    tristateCheckBox.setSelectedIcon(icon); // Nimbus works - after a fashion
- with this
+                } else { // reset
+                    if (tristateCheckBox!= null){
+                        tristateCheckBox.setIcon(null);
+                        tristateCheckBox.setSelectedIcon(null);
+                    }
                 }
             }
             super.setPressed(state == TristateState.INDETERMINATE);

Modified: jmeter/trunk/test/src/org/apache/jmeter/gui/util/TristateCheckBoxTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/gui/util/TristateCheckBoxTest.java?rev=1417789&r1=1417788&r2=1417789&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/gui/util/TristateCheckBoxTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/gui/util/TristateCheckBoxTest.java Thu Dec  6
10:05:42 2012
@@ -50,7 +50,38 @@ public class TristateCheckBoxTest {
     }
 
     private static JPanel makePanel(String name) {
-        final TristateCheckBox tristateBox = new TristateCheckBox("Tristate checkbox");
+        final TristateCheckBox tristateBox = new TristateCheckBox("Tristate checkbox (icon)",
false);
+        createTristate(tristateBox);
+        final TristateCheckBox tristateBoxorig = new TristateCheckBox("Tristate checkbox
(original)", true);
+        createTristate(tristateBoxorig);
+        final JCheckBox normalBox = new JCheckBox("Normal checkbox");
+        normalBox.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                System.out.println(e);
+            }
+        });
+
+        final JCheckBox enabledBox = new JCheckBox("Enable", true);
+        enabledBox.addItemListener(new ItemListener() {
+            @Override
+            public void itemStateChanged(ItemEvent e) {
+                tristateBox.setEnabled(enabledBox.isSelected());
+                normalBox.setEnabled(enabledBox.isSelected());
+            }
+        });
+
+        JPanel panel = new JPanel(new GridLayout(0, 1, 5, 5));
+        panel.add(new JLabel(name));
+        panel.add(tristateBox);
+        panel.add(tristateBoxorig);
+        panel.add(normalBox);
+        panel.add(enabledBox);
+        return panel;
+    }
+
+    private static void createTristate(final TristateCheckBox tristateBox) {
+        tristateBox.setIndeterminate(); // start in new state
         tristateBox.addItemListener(new ItemListener() {
             @Override
             public void itemStateChanged(ItemEvent e) {
@@ -79,28 +110,5 @@ public class TristateCheckBoxTest {
                 }
             }
         });
-        final JCheckBox normalBox = new JCheckBox("Normal checkbox");
-        normalBox.addActionListener(new ActionListener() {
-            @Override
-            public void actionPerformed(ActionEvent e) {
-                System.out.println(e);
-            }
-        });
-
-        final JCheckBox enabledBox = new JCheckBox("Enable", true);
-        enabledBox.addItemListener(new ItemListener() {
-            @Override
-            public void itemStateChanged(ItemEvent e) {
-                tristateBox.setEnabled(enabledBox.isSelected());
-                normalBox.setEnabled(enabledBox.isSelected());
-            }
-        });
-
-        JPanel panel = new JPanel(new GridLayout(0, 1, 5, 5));
-        panel.add(new JLabel(name));
-        panel.add(tristateBox);
-        panel.add(normalBox);
-        panel.add(enabledBox);
-        return panel;
     }
 }
\ No newline at end of file



Mime
View raw message