Wasn't firing action performed; simplified selection management by letting
the model do the work. git-svn-id: https://samskivert.googlecode.com/svn/trunk@645 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ComboButtonBox.java,v 1.1 2002/03/10 05:10:37 mdb Exp $
|
// $Id: ComboButtonBox.java,v 1.2 2002/03/10 05:27:35 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.swing;
|
package com.samskivert.swing;
|
||||||
|
|
||||||
@@ -231,8 +231,13 @@ public class ComboButtonBox extends JPanel
|
|||||||
{
|
{
|
||||||
// keep track of the selected button
|
// keep track of the selected button
|
||||||
_selectedButton = (JLabel)e.getSource();
|
_selectedButton = (JLabel)e.getSource();
|
||||||
_selectedButton.setBorder(SELECTED_BORDER);
|
// if the selected button is already selected, ignore the click
|
||||||
_selectedButton.repaint();
|
if (_selectedButton.getBorder() == SELECTED_BORDER) {
|
||||||
|
_selectedButton = null;
|
||||||
|
} else {
|
||||||
|
_selectedButton.setBorder(SELECTED_BORDER);
|
||||||
|
_selectedButton.repaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface
|
// documentation inherited from interface
|
||||||
@@ -242,26 +247,10 @@ public class ComboButtonBox extends JPanel
|
|||||||
// ahead and select it properly
|
// ahead and select it properly
|
||||||
if (_selectedButton != null) {
|
if (_selectedButton != null) {
|
||||||
if (_selectedButton.contains(e.getX(), e.getY())) {
|
if (_selectedButton.contains(e.getX(), e.getY())) {
|
||||||
// figure out which button this is
|
// tell the model that the selection has changed (and
|
||||||
int selidx = -1;
|
// we'll respond and do our business
|
||||||
int ccount = getComponentCount();
|
Object elem = _selectedButton.getClientProperty("element");
|
||||||
for (int i = 0; i < ccount; i++) {
|
_model.setSelectedItem(elem);
|
||||||
if (_selectedButton == getComponent(i)) {
|
|
||||||
selidx = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// sanity check
|
|
||||||
if (selidx == -1) {
|
|
||||||
Log.warning("Got action from non-button component!? " +
|
|
||||||
"[event=" + e + "].");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// if the selection changed, update our display and
|
|
||||||
// the model
|
|
||||||
setSelectedIndex(selidx);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_selectedButton.setBorder(DESELECTED_BORDER);
|
_selectedButton.setBorder(DESELECTED_BORDER);
|
||||||
@@ -300,6 +289,7 @@ public class ComboButtonBox extends JPanel
|
|||||||
} else {
|
} else {
|
||||||
ibut = new JLabel(elem.toString());
|
ibut = new JLabel(elem.toString());
|
||||||
}
|
}
|
||||||
|
ibut.putClientProperty("element", elem);
|
||||||
ibut.addMouseListener(this);
|
ibut.addMouseListener(this);
|
||||||
ibut.setBorder((_selectedIndex == i) ?
|
ibut.setBorder((_selectedIndex == i) ?
|
||||||
SELECTED_BORDER : DESELECTED_BORDER);
|
SELECTED_BORDER : DESELECTED_BORDER);
|
||||||
@@ -355,6 +345,10 @@ public class ComboButtonBox extends JPanel
|
|||||||
but.setBorder(SELECTED_BORDER);
|
but.setBorder(SELECTED_BORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fire an action performed to let listeners know about our
|
||||||
|
// changed selection
|
||||||
|
fireActionPerformed();
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user