source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/search/tree/MyTreeCellRenderer.java @ 8834

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

New feature
Not totally implemented. This feature will allow the user to browse his system, searching for image files, to send them.
This is a new Panel where the user can choose the folder he wants to browse. Then a (recursive) tree of this folder is display so that the user can browse it. Only images (currently jpg and png) are displayed. When the user clicks on a file, the image is displayed in a panel. He can right click on the file to send the image to piwigo.

At the moment, the first part of the feature is implemented (but not fully tested) : the display of the file tree and the display of the image on click. (the images cannot be sent).

File size: 3.1 KB
Line 
1package fr.mael.jiwigo.ui.search.tree;
2
3import java.awt.Component;
4
5import javax.swing.ImageIcon;
6import javax.swing.JTree;
7import javax.swing.tree.DefaultMutableTreeNode;
8import javax.swing.tree.DefaultTreeCellRenderer;
9
10import fr.mael.jiwigo.transverse.util.Outil;
11import fr.mael.jiwigo.ui.search.File;
12
13/**
14Copyright (c) 2010, Mael
15All rights reserved.
16
17Redistribution and use in source and binary forms, with or without
18modification, are permitted provided that the following conditions are met:
19 * Redistributions of source code must retain the above copyright
20   notice, this list of conditions and the following disclaimer.
21 * Redistributions in binary form must reproduce the above copyright
22   notice, this list of conditions and the following disclaimer in the
23   documentation and/or other materials provided with the distribution.
24 * Neither the name of jiwigo nor the
25   names of its contributors may be used to endorse or promote products
26   derived from this software without specific prior written permission.
27
28THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
32DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39* @author mael
40* Cell renderer. Allows to display a specific image for a png or a jpg image
41* And allows to display "leaf" folders with a folder gui
42*/
43public class MyTreeCellRenderer extends DefaultTreeCellRenderer {
44
45    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
46            boolean leaf, int row, boolean hasFocus) {
47
48        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
49
50        DefaultMutableTreeNode theNode = (DefaultMutableTreeNode) value;
51        //only if it's a file : the value can be a string and it's not interesting
52        if (theNode.getUserObject() instanceof File) {
53            File file = (File) theNode.getUserObject();
54            //if it's a directory and a leaf, the default icon is overriden with the
55            //"openIcon", which shows to the users that it's a folder. Otherwise it can be confusing
56            //and if it's a png or jpg files (which means everything excepts the folders), specific icons
57            //are setted
58            if (file.isDirectory() && leaf) {
59                setIcon(openIcon);
60            } else if (file.isFile() && file.getName().toLowerCase().endsWith(".png")) {
61                setIcon(new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/png.png")));
62            } else if (file.isFile()
63                    && (file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".jpeg"))) {
64                setIcon(new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/jpg.png")));
65            }
66        }
67        return this;
68    }
69
70}
Note: See TracBrowser for help on using the repository browser.