Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* @(#)CheckBoxList.java 4/21/2005
*
* Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
*/
package com.jidesoft.swing;
import javax.swing.*;
import javax.swing.text.Position;
import java.awt.*;
import java.awt.event.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
/**
* CheckBoxListWithSelectable is a special JList which uses JCheckBox as the list element. In addition to
* regular JList feature, it also allows you select any number of elements in the list by selecting the check boxes.
*
* The element is ListModel should be an instance of {@link Selectable}. If you have your own class that represents the
* element in the list, you can implement Selectable and implements a few very simple methods. If your
* elements are already in an array or Vector that you pass in to the constructor of JList, we will convert them to
* {@link DefaultSelectable} which implements Selectable interface.
*
* To select an element, user can mouse click on the check box, or highlight the rows and press SPACE key to toggle the
* selections.
*
* To listen to the check box selection change, you can call addItemListener to add an ItemListener.
*
* Please note, there are two implementations of CheckBoxList. CheckBoxListWithSelectable is one. There is also another
* one call CheckBoxList. CheckBoxListWithSelectable is actually the old implementation. In 1.9.2, we introduced a new
* implementation and renamed the old implementation to CheckBoxListWithSelectable. The main difference between the two
* implementation is at how the selection state is kept. In new implementation, the selection state is kept at a
* separate ListSelectionModel which you can get using {@link CheckBoxList#getCheckBoxListSelectionModel()}. The old
* implementation kept the selection state at Selectable object in the ListModel.
*/
public class CheckBoxListWithSelectable extends JList implements ItemSelectable {
protected CheckBoxListCellRenderer _listCellRenderer;
public static final String PROPERTY_CHECKBOX_ENABLED = "checkBoxEnabled";
public static final String PROPERTY_CLICK_IN_CHECKBOX_ONLY = "clickInCheckBoxOnly";
private boolean _checkBoxEnabled = true;
private boolean _clickInCheckBoxOnly = true;
/**
* Constructs a CheckBoxList with an empty model.
*/
public CheckBoxListWithSelectable() {
init();
}
/**
* Constructs a CheckBoxList that displays the elements in the specified Vector. If the
* Vector contains elements which is not an instance of {@link Selectable}, it will wrap it automatically into
* {@link DefaultSelectable} and add to ListModel.
*
* @param listData the Vector to be loaded into the data model
*/
public CheckBoxListWithSelectable(final Vector> listData) {
super(wrap(listData));
init();
}
/**
* Constructs a CheckBoxList that displays the elements in the specified Object[]. If the
* Object array contains elements which is not an instance of {@link Selectable}, it will wrap it automatically into
* {@link DefaultSelectable} and add to ListModel.
*
* @param listData the array of Objects to be loaded into the data model
*/
public CheckBoxListWithSelectable(final Object[] listData) {
super(wrap(listData));
init();
}
/**
* Constructs a CheckBoxList that displays the elements in the specified, non-null model.
* All CheckBoxList constructors delegate to this one.
*
* Please note, if you are using this constructor, please make sure all elements in dataModel are instance of {@link
* Selectable}.
*
* @param dataModel the data model for this list
* @throws IllegalArgumentException if dataModel is null
*/
public CheckBoxListWithSelectable(ListModel dataModel) {
super(wrap(dataModel));
init();
}
/**
* Initialize the CheckBoxList.
*/
protected void init() {
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
_listCellRenderer = createCellRenderer();
Handler handle = createHandler();
addMouseListener(handle);
addKeyListener(handle);
}
/**
* Creates the cell renderer.
*
* @return the cell renderer.
*/
protected CheckBoxListCellRenderer createCellRenderer() {
return new CheckBoxListCellRenderer();
}
/**
* Creates the mouse listener and key listener used by CheckBoxList.
*
* @return the Handler.
*/
protected Handler createHandler() {
return new Handler(this);
}
/**
* Sets the selected elements.
*
* @param elements the elements to be selected
*/
public void setSelectedObjects(Object[] elements) {
Map