Changeset 9185 for trunk/gli/src/org/greenstone/gatherer/util
- Timestamp:
- 2005-02-25T14:24:48+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/CheckList.java
r8884 r9185 66 66 setModel(new DefaultListModel()); 67 67 setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 68 addMouseListener(new CheckList Listener());68 addMouseListener(new CheckListMouseListener()); 69 69 } 70 70 … … 153 153 154 154 155 private void selectionChanged(int index) {156 fireSelectionValueChanged(index, index, false);157 }158 159 160 155 /** A custom list cell renderer for producing rows which contain clickable check boxes. */ 161 156 protected class CheckListCellRenderer 162 implements ListCellRenderer {163 157 implements ListCellRenderer 158 { 164 159 /** Return a component that has been configured to display the specified value. That component's paint method is then called to "render" the cell. If it is necessary to compute the dimensions of a list because the list cells do not have a fixed size, this method is called to generate a component on which getPreferredSize can be invoked. 165 160 * @param list The </strong>JList</strong> we're painting. … … 172 167 public Component getListCellRendererComponent(JList list, Object value, int index, boolean is_selected, boolean cell_has_focus) { 173 168 JCheckBox checkbox = (JCheckBox) value; 174 if (show_selected_row) {169 if (show_selected_row) { 175 170 checkbox.setBackground(is_selected ? list.getSelectionBackground() : list.getBackground()); 176 171 checkbox.setForeground(is_selected ? list.getSelectionForeground() : list.getForeground()); … … 192 187 193 188 /** Listens for clicks apon the checks within the list, and updates as necessary. */ 194 private class CheckList Listener195 extends MouseAdapter {196 189 private class CheckListMouseListener 190 extends MouseAdapter 191 { 197 192 /** Called whenever the mouse is clicked over our list. We find the nearest checkbox and change its state. 198 193 * @param e A <strong>MouseEvent</strong> containing everything you ever wanted to know about the mouse event but were afraid to ask. 199 194 */ 200 public void mousePressed(MouseEvent e) { 195 public void mousePressed(MouseEvent e) 196 { 201 197 JList list = (JList) e.getSource(); 202 198 int index = list.locationToIndex(e.getPoint()); 203 CheckListEntry checkbox = (CheckListEntry) list.getModel().getElementAt(index);204 if (!checkbox.isFixed()) {199 CheckListEntry checkbox = (CheckListEntry) list.getModel().getElementAt(index); 200 if (!checkbox.isFixed()) { 205 201 checkbox.setSelected(!checkbox.isSelected()); 206 202 } 207 203 checkbox.grabFocus(); 208 // Fire a selection changed event 209 selectionChanged(index); 204 205 // This is necessary to get the checkbox to repaint in Java 1.5.0 206 list.getSelectionModel().clearSelection(); 210 207 } 211 208 }
Note:
See TracChangeset
for help on using the changeset viewer.