mirror of https://github.com/apache/jmeter.git
Add tests for original code - which did not use a special icon - for comparison
Bugzilla Id: 54251 git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1417789 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bfc9e01d33
commit
2ca600dc56
|
|
@ -61,12 +61,21 @@ public final class TristateCheckBox extends JCheckBox {
|
||||||
this(text, null, TristateState.DESELECTED);
|
this(text, null, TristateState.DESELECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TristateCheckBox(String text, Icon icon,
|
// For testing only at present
|
||||||
TristateState initial) {
|
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);
|
super(text, icon);
|
||||||
|
|
||||||
//Set default single model
|
//Set default single model
|
||||||
setModel(new TristateButtonModel(initial, this));
|
setModel(new TristateButtonModel(initial, this, original));
|
||||||
|
|
||||||
// override action behaviour
|
// override action behaviour
|
||||||
super.addMouseListener(new MouseAdapter() {
|
super.addMouseListener(new MouseAdapter() {
|
||||||
|
|
@ -148,12 +157,14 @@ public final class TristateCheckBox extends JCheckBox {
|
||||||
private TristateState state = TristateState.DESELECTED;
|
private TristateState state = TristateState.DESELECTED;
|
||||||
private final TristateCheckBox tristateCheckBox;
|
private final TristateCheckBox tristateCheckBox;
|
||||||
private final Icon icon;
|
private final Icon icon;
|
||||||
|
private final boolean original;
|
||||||
|
|
||||||
public TristateButtonModel(TristateState initial,
|
public TristateButtonModel(TristateState initial,
|
||||||
TristateCheckBox tristateCheckBox) {
|
TristateCheckBox tristateCheckBox, boolean original) {
|
||||||
setState(TristateState.DESELECTED);
|
setState(TristateState.DESELECTED);
|
||||||
this.tristateCheckBox = tristateCheckBox;
|
this.tristateCheckBox = tristateCheckBox;
|
||||||
icon = new TristateCheckBoxIcon(tristateCheckBox);
|
icon = new TristateCheckBoxIcon(tristateCheckBox);
|
||||||
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndeterminate() {
|
public void setIndeterminate() {
|
||||||
|
|
@ -211,15 +222,17 @@ public final class TristateCheckBox extends JCheckBox {
|
||||||
|
|
||||||
private void displayState() {
|
private void displayState() {
|
||||||
super.setSelected(state != TristateState.DESELECTED);
|
super.setSelected(state != TristateState.DESELECTED);
|
||||||
// original used:
|
if (original) {
|
||||||
// super.setArmed(state == TristateState.INDETERMINATE);
|
super.setArmed(state == TristateState.INDETERMINATE);
|
||||||
if (state == TristateState.INDETERMINATE) {
|
} else {
|
||||||
tristateCheckBox.setIcon(icon); // Needed for all but Nimbus
|
if (state == TristateState.INDETERMINATE) {
|
||||||
tristateCheckBox.setSelectedIcon(icon); // Nimbus works - after a fashion - with this
|
tristateCheckBox.setIcon(icon); // Needed for all but Nimbus
|
||||||
} else { // reset
|
tristateCheckBox.setSelectedIcon(icon); // Nimbus works - after a fashion - with this
|
||||||
if (tristateCheckBox!= null){
|
} else { // reset
|
||||||
tristateCheckBox.setIcon(null);
|
if (tristateCheckBox!= null){
|
||||||
tristateCheckBox.setSelectedIcon(null);
|
tristateCheckBox.setIcon(null);
|
||||||
|
tristateCheckBox.setSelectedIcon(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.setPressed(state == TristateState.INDETERMINATE);
|
super.setPressed(state == TristateState.INDETERMINATE);
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,38 @@ public class TristateCheckBoxTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JPanel makePanel(String name) {
|
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() {
|
tristateBox.addItemListener(new ItemListener() {
|
||||||
@Override
|
@Override
|
||||||
public void itemStateChanged(ItemEvent e) {
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue