source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/search/ComboCategoryRenderer.java @ 8838

Last change on this file since 8838 was 8838, checked in by mlg, 13 years ago

Images can be sent from the file new file browser.

File size: 2.3 KB
Line 
1package fr.mael.jiwigo.ui.search;
2
3import java.awt.Component;
4
5import javax.swing.JLabel;
6import javax.swing.JList;
7import javax.swing.ListCellRenderer;
8
9import fr.mael.jiwigo.om.Category;
10
11/**
12 *
13   Copyright (c) 2010, Mael
14   All rights reserved.
15
16   Redistribution and use in source and binary forms, with or without
17   modification, are permitted provided that the following conditions are met:
18    * Redistributions of source code must retain the above copyright
19      notice, this list of conditions and the following disclaimer.
20    * Redistributions in binary form must reproduce the above copyright
21      notice, this list of conditions and the following disclaimer in the
22      documentation and/or other materials provided with the distribution.
23    * Neither the name of jiwigo nor the
24      names of its contributors may be used to endorse or promote products
25      derived from this software without specific prior written permission.
26
27   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
31   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37   
38 * @author mael
39 * Renderer used to display the category list with a hierarchy
40 *
41 */
42public class ComboCategoryRenderer extends JLabel implements ListCellRenderer {
43
44    @Override
45    public Component getListCellRendererComponent(JList arg0, Object arg1, int arg2, boolean arg3, boolean arg4) {
46        Category category = (Category) arg1;
47        String toAdd = "";
48        //the indentation depends on the level of the category
49        for (int i = 0; i < category.getLevel(); i++) {
50            toAdd += " ";
51        }
52        //if it's not a "root" category, an arrow is added
53        if (category.getLevel() != 0) {
54            toAdd += "-> ";
55        }
56        this.setText(toAdd + category);
57        return this;
58    }
59
60}
Note: See TracBrowser for help on using the repository browser.