1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.gui.platform.swing.builder.components;
17
18 import javax.swing.JList;
19
20 import net.sf.jguiraffe.gui.builder.components.model.ListModel;
21 import net.sf.jguiraffe.gui.builder.components.tags.ListModelUtils;
22
23 /**
24 * <p>
25 * A Swing specific component handler implementation that deals with multi
26 * selection lists.
27 * </p>
28 * <p>
29 * A multi selection list can have multiple items selected at the same time. So
30 * the component's data is an array of selected objects.
31 * </p>
32 *
33 * @author Oliver Heger
34 * @version $Id: SwingMultiListBoxHandler.java 205 2012-01-29 18:29:57Z oheger $
35 */
36 class SwingMultiListBoxHandler extends SwingListBoxHandler
37 {
38 /**
39 * Creates a new instance of {@code SwingMultiListBoxHandler}.
40 *
41 * @param list the list component
42 * @param listModel the model
43 * @param scrollWidth the preferred scroll width
44 * @param scrollHeight the preferred scroll height
45 */
46 public SwingMultiListBoxHandler(JList list, ListModel listModel,
47 int scrollWidth, int scrollHeight)
48 {
49 super(list, listModel, scrollWidth, scrollHeight);
50 }
51
52 /**
53 * Returns this component's data. Based on the selection objects from the
54 * list model will be returned.
55 *
56 * @return the component's data
57 */
58 @Override
59 public Object getData()
60 {
61 return ListModelUtils.getValues(getListModel(), getList()
62 .getSelectedIndices());
63 }
64
65 /**
66 * Sets the data of this component.
67 *
68 * @param data the new data (which should be an array with items of the list
69 * model)
70 */
71 @Override
72 public void setData(Object data)
73 {
74 getList().setSelectedIndices(
75 ListModelUtils.getIndices(getListModel(), (Object[]) data));
76 }
77
78 /**
79 * Returns this component's data type. This is a generic array type.
80 *
81 * @return the data type of this component
82 */
83 @Override
84 public Class<?> getType()
85 {
86 return Object[].class;
87 }
88 }