From 552f747694885fc366393bdea4b49a60fb494a8c Mon Sep 17 00:00:00 2001 From: mdb Date: Sun, 10 Mar 2002 05:27:35 +0000 Subject: [PATCH] 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 --- .../com/samskivert/swing/ComboButtonBox.java | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java b/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java index 0661ccde..a88c910e 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java +++ b/projects/samskivert/src/java/com/samskivert/swing/ComboButtonBox.java @@ -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; @@ -231,8 +231,13 @@ public class ComboButtonBox extends JPanel { // keep track of the selected button _selectedButton = (JLabel)e.getSource(); - _selectedButton.setBorder(SELECTED_BORDER); - _selectedButton.repaint(); + // if the selected button is already selected, ignore the click + if (_selectedButton.getBorder() == SELECTED_BORDER) { + _selectedButton = null; + } else { + _selectedButton.setBorder(SELECTED_BORDER); + _selectedButton.repaint(); + } } // documentation inherited from interface @@ -242,26 +247,10 @@ public class ComboButtonBox extends JPanel // ahead and select it properly if (_selectedButton != null) { if (_selectedButton.contains(e.getX(), e.getY())) { - // figure out which button this is - int selidx = -1; - int ccount = getComponentCount(); - for (int i = 0; i < ccount; i++) { - 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); - } + // tell the model that the selection has changed (and + // we'll respond and do our business + Object elem = _selectedButton.getClientProperty("element"); + _model.setSelectedItem(elem); } else { _selectedButton.setBorder(DESELECTED_BORDER); @@ -300,6 +289,7 @@ public class ComboButtonBox extends JPanel } else { ibut = new JLabel(elem.toString()); } + ibut.putClientProperty("element", elem); ibut.addMouseListener(this); ibut.setBorder((_selectedIndex == i) ? SELECTED_BORDER : DESELECTED_BORDER); @@ -355,6 +345,10 @@ public class ComboButtonBox extends JPanel but.setBorder(SELECTED_BORDER); } + // fire an action performed to let listeners know about our + // changed selection + fireActionPerformed(); + repaint(); }