com.alee.extended.list.WebCheckBoxList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weblaf-ui Show documentation
Show all versions of weblaf-ui Show documentation
WebLaf is a Java Swing Look and Feel and extended components library for cross-platform applications
/*
* This file is part of WebLookAndFeel library.
*
* WebLookAndFeel library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebLookAndFeel library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WebLookAndFeel library. If not, see .
*/
package com.alee.extended.list;
import com.alee.laf.list.WebList;
import com.alee.laf.list.editor.ListCellEditor;
import com.alee.managers.hotkey.Hotkey;
import com.alee.managers.style.StyleId;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
/**
* This component offers a checkbox list functionality.
* Each cell acts as a separate checkbox, but it could be selected like the elements in simple list.
* You can also perform mass check/uncheck operations by selection more than one checkbox and pressing space.
*
* @author Mikle Garin
*/
public class WebCheckBoxList extends WebList
{
/**
* Whether checkbox selection should be performed only when user clicks exactly on the check icon or not.
*/
protected boolean checkOnIconOnly = true;
/**
* Constructs empty checkbox list.
*/
public WebCheckBoxList ()
{
this ( StyleId.checkboxlist, new CheckBoxListModel () );
}
/**
* Constructs checkbox list with a specified model.
*
* @param model checkbox list model
*/
public WebCheckBoxList ( final CheckBoxListModel model )
{
this ( StyleId.checkboxlist, model );
}
/**
* Constructs empty checkbox list.
*
* @param id style ID
*/
public WebCheckBoxList ( final StyleId id )
{
this ( id, new CheckBoxListModel () );
}
/**
* Constructs checkbox list with a specified model.
*
* @param id style ID
* @param model checkbox list model
*/
public WebCheckBoxList ( final StyleId id, final CheckBoxListModel model )
{
super ( id, model );
// Custom checkbox list cell renderer
setCellRenderer ( new WebCheckBoxListCellRenderer () );
// Checkbox selection change listeners
addMouseListener ( new CheckBoxListMouseAdapter () );
addKeyListener ( new CheckBoxListKeyAdapter () );
}
/**
* Returns custom checkbox list cell renderer.
*
* @return custom checkbox list cell renderer
*/
public WebCheckBoxListCellRenderer getWebCheckBoxListCellRenderer ()
{
final ListCellRenderer renderer = getCellRenderer ();
return renderer instanceof WebCheckBoxListCellRenderer ? ( WebCheckBoxListCellRenderer ) renderer : null;
}
/**
* Returns custom checkbox list cell model.
*
* @return custom checkbox list cell model
*/
public CheckBoxListModel getCheckBoxListModel ()
{
return ( CheckBoxListModel ) getModel ();
}
/**
* Returns default list cell editor for this list.
*
* @return default list cell editor for this list
*/
@Override
protected ListCellEditor createDefaultCellEditor ()
{
return new WebCheckBoxListCellEditor ();
}
/**
* Returns whether checkbox under the specified cell index is selected or not.
*
* @param index cell index
* @return true if checkbox at the specified cell index is selected, false otherwise
*/
public boolean isCheckBoxSelected ( final int index )
{
return getCheckBoxListModel ().isCheckBoxSelected ( index );
}
/**
* Inverts checkbox selection at the specified cell index.
*
* @param index cell index
*/
public void invertCheckBoxSelection ( final int index )
{
getCheckBoxListModel ().invertCheckBoxSelection ( index );
performAnimation ( index );
}
/**
* Sets whether checkbox at the specified cell index is selected or not.
*
* @param index cell index
* @param selected whether checkbox is selected or not
*/
public void setCheckBoxSelected ( final int index, final boolean selected )
{
if ( getCheckBoxListModel ().setCheckBoxSelected ( index, selected ) )
{
performAnimation ( index );
}
}
/**
* Returns list of values from checked cells.
*
* @return list of values from checked cells
*/
public List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy